Polyline.qo.h

Go to the documentation of this file.
00001 //# Copyright (C) 2011
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This library is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU Library General Public License as published by
00006 //# the Free Software Foundation; either version 2 of the License, or (at your
00007 //# option) any later version.
00008 //#
00009 //# This library is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012 //# License for more details.
00013 //#
00014 //# You should have received a copy of the GNU Library General Public License
00015 //# along with this library; if not, write to the Free Software Foundation,
00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 //#
00025 //# $Id$
00026 
00027 
00028 #ifndef REGION_POLYLINE_H_
00029 #define REGION_POLYLINE_H_
00030 
00031 #include <display/region/Region.qo.h>
00032 #include <display/region/QtRegionSource.qo.h>
00033 #include <casa/BasicSL/String.h>
00034 #include <vector>
00035 
00036 namespace casa {
00037 
00038         class AnnotationBase;
00039         class DisplayData;
00040         class SlicePlot;
00041 
00042         namespace viewer {
00043 
00044                 class Polyline : public Region {
00045                         Q_OBJECT
00046                 public:
00047                         typedef std::pair<double,double> pt;
00048                         typedef std::vector<pt> point_list;
00049 
00050                         //Construction
00051                         Polyline( WorldCanvas *wc, QtRegionDock *d, double x1, double y1 );
00052                         Polyline( WorldCanvas *wc, QtRegionDock *d, const std::vector<std::pair<double,double> > &pts );
00053                         // carry over from QtRegion... hopefully, removed soon...
00054                         Polyline( QtRegionSourceKernel *, WorldCanvas *wc, const std::vector<std::pair<double,double> > &pts, bool hold_signals=false );
00055                         Polyline( QtRegionSourceKernel *rs, WorldCanvas *wc, double x1, double y1, bool hold_signals=false );
00056 
00057                         virtual ~Polyline( );
00058 
00059                         bool clickWithin( double x, double y ) const;
00060                         int clickHandle( double x, double y ) const;
00061 
00062                         int moveHandle( int handle, double x, double y );
00063                         void move( double dx, double dy );
00064                         void resize( double /*width_delta*/, double /*height_delta*/ );
00065                         bool valid_translation( double dx, double dy, double width_delta, double height_delta );
00066 
00067                         // returns point state (Region::PointLocation)
00068                         region::PointInfo checkPoint( double x, double y ) const;
00069 
00070                         // returns mouse state (Region::MouseState)
00071                         unsigned int mouseMovement( double x, double y, bool other_selected );
00072 
00073                         void linearCenter( double &x, double &y ) const;
00074                         void pixelCenter( double &x, double &y ) const;
00075 
00076 
00077                         void polylineComplete( );
00078 
00079                         void addVertex( double x, double y, bool rewrite_last_point=false );
00080 
00081                         AnnotationBase *annotation( ) const;
00082 
00083                         // return the *drawing* bounding rectangle...
00084                         // in "linear" coordinates...
00085                         void boundingRectangle( double &blcx, double &blcy, double &trcx, double &trcy ) const;
00086 
00087                         int numVertices( ) const {
00088                                 return drawing_points( ).size( );
00089                         }
00090 
00091                         void output( ds9writer &out ) const;
00092 
00093                         // fetch region type...
00094                         region::RegionTypes type( ) const {
00095                                 return region::PolylineRegion;
00096                         }
00097 
00098                         void addPlot( QWidget* parent, string label );
00099 
00100 
00101 
00102                 signals:
00103                         void show1DSliceTool();
00104 
00105                 public slots:
00106                         //Position marker
00107                         void setMarkerPosition( int regionId, int segmentIndex, float percentage );
00108                         void setShowMarkerPosition( int regionId, bool show );
00109 
00110                 protected:
00111                         virtual RegionInfo *newInfoObject(ImageInterface<Float>* image, PrincipalAxesDD * );
00112                         unsigned int check_handle( double x, double y ) const;
00113 
00114                         enum YScaleTo { ScaleTop, ScaleBottom };
00115                         enum XScaleTo { ScaleLeft, ScaleRight };
00116                         enum Tranformations { FLIP_X = 1 << 0, FLIP_Y = 1 << 1 };
00117                         std::list<SHARED_PTR<RegionInfo> > *generate_dds_centers( );
00118                         ImageRegion *get_image_region( DisplayData* ) const;
00119 
00120                         void drawRegion( bool );
00121                         void drawText( );
00122 
00123                         virtual void fetch_region_details( region::RegionTypes &type, std::vector<std::pair<int,int> > &pixel_pts,
00124                                                            std::vector<std::pair<double,double> > &world_pts ) const;
00125 
00126                         const point_list &drawing_points( ) const {
00127                                 return _drawing_points_;
00128                         }
00129 
00130                 private slots:
00131                         void updatePolyLine(int regionId, viewer::region::RegionChanges,
00132                                             const QList<double> & worldX, const QList<double>& worldY,
00133                                             const QList<int> & pixelX, const QList<int> & pixelY);
00134                         void polyLineRegionChanged( viewer::Region* region, std::string changeType);
00135                         void polyLineRegionUpdate(int regionId, viewer::region::RegionChanges change,
00136                                                   const QList<double> & worldX, const QList<double>& worldY,
00137                                                   const QList<int> & pixelX, const QList<int> & pixelY);
00138 
00139 
00140 
00141                 private:
00142                         bool within_vertex_handle( double x, double y ) const;
00143                         int move_sizing_rectangle_handle( int handle, double x, double y );
00144                         int move_vertex( int handle, double x, double y );
00145 
00146                         void update_drawing_bounds_rectangle( );
00147                         void update_reference_bounds_rectangle( );
00148 
00149                         void update_drawing_state( );
00150                         void update_reference_state( int transformations, int handle, int new_handle );
00151 
00152                         virtual void setCenter(double &x, double &y, double &deltx, double &delty);
00153                         void initPlot( );
00154                         void setPlotLineColor();
00155                         void setPlotLineColor( SlicePlot* plot );
00156 
00157                         double handle_delta_x, handle_delta_y;
00158 
00159                         point_list _ref_points_;
00160                         double _ref_blc_x_, _ref_blc_y_;
00161                         double _ref_trc_x_, _ref_trc_y_;
00162                         double _ref_width_, _ref_height_;
00163 
00164                         point_list _drawing_points_;
00165                         double _drawing_blc_x_, _drawing_blc_y_;
00166                         double _drawing_trc_x_, _drawing_trc_y_;
00167                         double _drawing_width_, _drawing_height_;
00168 
00169                         double _center_x, _center_y;
00170                         double _center_delta_x, _center_delta_y;
00171 
00172                         XScaleTo _x_origin_;
00173                         YScaleTo _y_origin_;
00174 
00175                         //Slice functionality
00176                         void drawPositionMarker();
00177                         QMap<QString,SlicePlot*> slicePlots;
00178                         int markerSegmentIndex;
00179                         float markerPercentage;
00180                         bool showPositionMarker;
00181                 };
00182         }
00183 }
00184 
00185 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1