00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef REGION_POLYGON_H_
00030 #define REGION_POLYGON_H_
00031
00032 #include <display/region/Region.qo.h>
00033 #include <display/region/QtRegionSource.qo.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <vector>
00036
00037 namespace casa {
00038
00039 class AnnotationBase;
00040 class DisplayData;
00041
00042 namespace viewer {
00043
00044
00045 class QtRegionSourceKernel;
00046
00047 class Polygon : public Region {
00048 public:
00049 typedef std::pair<double,double> pt;
00050 typedef std::vector<pt> point_list;
00051
00052 Polygon( WorldCanvas *wc, QtRegionDock *d, double x1, double y1 );
00053 Polygon( WorldCanvas *wc, QtRegionDock *d, const std::vector<std::pair<double,double> > &pts );
00054
00055 Polygon( QtRegionSourceKernel *, WorldCanvas *wc,
00056 const std::vector<std::pair<double,double> > &pts,
00057 bool hold_signals=false );
00058 Polygon( QtRegionSourceKernel *rs, WorldCanvas *wc, double x1,
00059 double y1, bool hold_signals=false );
00060
00061
00062 ~Polygon( ) { }
00063
00064 bool clickWithin( double x, double y ) const;
00065 int clickHandle( double x, double y ) const;
00066
00067
00068 int moveHandle( int handle, double x, double y );
00069 void move( double dx, double dy );
00070 void resize( double , double );
00071 bool valid_translation( double dx, double dy, double width_delta, double height_delta );
00072
00073
00074 region::PointInfo checkPoint( double x, double y ) const;
00075
00076
00077 unsigned int mouseMovement( double x, double y, bool other_selected );
00078
00079 void linearCenter( double &x, double &y ) const;
00080 void pixelCenter( double &x, double &y ) const;
00081
00082 void closeFigure( bool signal_complete=true );
00083 void polygonComplete( );
00084
00085 void addVertex( double x, double y, bool rewrite_last_point=false );
00086
00087 AnnotationBase *annotation( ) const;
00088
00089
00090
00091 void boundingRectangle( double &blcx, double &blcy, double &trcx, double &trcy ) const;
00092
00093 int numVertices( ) const {
00094 return drawing_points( ).size( );
00095 }
00096
00097 void output( ds9writer &out ) const;
00098
00099
00100 region::RegionTypes type( ) const {
00101 return region::PolyRegion;
00102 }
00103
00104 protected:
00105 unsigned int check_handle( double x, double y ) const;
00106
00107 enum YScaleTo { ScaleTop, ScaleBottom };
00108 enum XScaleTo { ScaleLeft, ScaleRight };
00109 enum Tranformations { FLIP_X = 1 << 0, FLIP_Y = 1 << 1 };
00110 std::list<SHARED_PTR<RegionInfo> > *generate_dds_centers( );
00111 ImageRegion *get_image_region( DisplayData* ) const;
00112
00113 void drawRegion( bool );
00114
00115 virtual void fetch_region_details( region::RegionTypes &type, std::vector<std::pair<int,int> > &pixel_pts,
00116 std::vector<std::pair<double,double> > &world_pts ) const;
00117
00118 const point_list &drawing_points( ) const {
00119 return _drawing_points_;
00120 }
00121
00122 private:
00123 bool within_vertex_handle( double x, double y ) const;
00124
00125 int move_sizing_rectangle_handle( int handle, double x, double y );
00126 int move_vertex( int handle, double x, double y );
00127
00128 void update_drawing_bounds_rectangle( );
00129 void update_reference_bounds_rectangle( );
00130
00131 void update_drawing_state( );
00132 void update_reference_state( int transformations, int handle, int new_handle );
00133
00134 virtual void setCenter(double &x, double &y, double &deltx, double &delty) {
00135 _center_x=x;
00136 _center_y=y;
00137 _center_delta_x=deltx;
00138 _center_delta_y=delty;
00139 };
00140
00141 double handle_delta_x, handle_delta_y;
00142
00143 point_list _ref_points_;
00144 double _ref_blc_x_, _ref_blc_y_;
00145 double _ref_trc_x_, _ref_trc_y_;
00146 double _ref_width_, _ref_height_;
00147
00148 point_list _drawing_points_;
00149 double _drawing_blc_x_, _drawing_blc_y_;
00150 double _drawing_trc_x_, _drawing_trc_y_;
00151 double _drawing_width_, _drawing_height_;
00152
00153 double _center_x, _center_y;
00154 double _center_delta_x, _center_delta_y;
00155
00156 XScaleTo _x_origin_;
00157 YScaleTo _y_origin_;
00158 };
00159 }
00160 }
00161
00162 #endif