casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Polygon.h
Go to the documentation of this file.
00001 //# polygon.h: base class for statistical regions
00002 //# Copyright (C) 2011
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
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                 // carry over from QtRegion... hopefully, removed soon...
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                         // carry over from QtRegion... hopefully, removed soon...
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                         // for rectangles, resizing can change the handle...
00067                         // for rectangles, moving a handle is resizing...
00068                         int moveHandle( int handle, double x, double y );
00069                         void move( double dx, double dy );
00070                         void resize( double /*width_delta*/, double /*height_delta*/ );
00071                         bool valid_translation( double dx, double dy, double width_delta, double height_delta );
00072 
00073                         // returns point state (Region::PointLocation)
00074                         region::PointInfo checkPoint( double x, double y ) const;
00075 
00076                         // returns mouse state (Region::MouseState)
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                         // return the *drawing* bounding rectangle...
00090                         // in "linear" coordinates...
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                         // fetch region type...
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<std::tr1::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