casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Polygon.h
Go to the documentation of this file.
1 //# polygon.h: base class for statistical regions
2 //# Copyright (C) 2011
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 
29 #ifndef REGION_POLYGON_H_
30 #define REGION_POLYGON_H_
31 
34 #include <casa/BasicSL/String.h>
35 #include <vector>
36 
37 namespace casa {
38 
39  class AnnotationBase;
40  class DisplayData;
41 
42  namespace viewer {
43 
44  // carry over from QtRegion... hopefully, removed soon...
45  class QtRegionSourceKernel;
46 
47  class Polygon : public Region {
48  public:
49  typedef std::pair<double,double> pt;
50  typedef std::vector<pt> point_list;
51 
52  Polygon( WorldCanvas *wc, QtRegionDock *d, double x1, double y1 );
53  Polygon( WorldCanvas *wc, QtRegionDock *d, const std::vector<std::pair<double,double> > &pts );
54  // carry over from QtRegion... hopefully, removed soon...
56  const std::vector<std::pair<double,double> > &pts,
57  bool hold_signals=false );
58  Polygon( QtRegionSourceKernel *rs, WorldCanvas *wc, double x1,
59  double y1, bool hold_signals=false );
60 
61 
62  ~Polygon( ) { }
63 
64  bool clickWithin( double x, double y ) const;
65  int clickHandle( double x, double y ) const;
66  // for rectangles, resizing can change the handle...
67  // for rectangles, moving a handle is resizing...
68  int moveHandle( int handle, double x, double y );
69  void move( double dx, double dy );
70  void resize( double /*width_delta*/, double /*height_delta*/ );
71  bool valid_translation( double dx, double dy, double width_delta, double height_delta );
72 
73  // returns point state (Region::PointLocation)
74  region::PointInfo checkPoint( double x, double y ) const;
75 
76  // returns mouse state (Region::MouseState)
77  unsigned int mouseMovement( double x, double y, bool other_selected );
78 
79  void linearCenter( double &x, double &y ) const;
80  void pixelCenter( double &x, double &y ) const;
81 
82  void closeFigure( bool signal_complete=true );
83  void polygonComplete( );
84 
85  void addVertex( double x, double y, bool rewrite_last_point=false );
86 
87  AnnotationBase *annotation( ) const;
88 
89  // return the *drawing* bounding rectangle...
90  // in "linear" coordinates...
91  void boundingRectangle( double &blcx, double &blcy, double &trcx, double &trcy ) const;
92 
93  int numVertices( ) const {
94  return drawing_points( ).size( );
95  }
96 
97  void output( ds9writer &out ) const;
98 
99  // fetch region type...
101  return region::PolyRegion;
102  }
103 
104  protected:
105  unsigned int check_handle( double x, double y ) const;
106 
109  enum Tranformations { FLIP_X = 1 << 0, FLIP_Y = 1 << 1 };
110  std::list<std::shared_ptr<RegionInfo> > *generate_dds_centers( );
112 
113  void drawRegion( bool );
114 
115  virtual void fetch_region_details( region::RegionTypes &type, std::vector<std::pair<int,int> > &pixel_pts,
116  std::vector<std::pair<double,double> > &world_pts ) const;
117 
118  const point_list &drawing_points( ) const {
119  return _drawing_points_;
120  }
121 
122  private:
123  bool within_vertex_handle( double x, double y ) const;
124 
125  int move_sizing_rectangle_handle( int handle, double x, double y );
126  int move_vertex( int handle, double x, double y );
127 
130 
131  void update_drawing_state( );
132  void update_reference_state( int transformations, int handle, int new_handle );
133 
134  virtual void setCenter(double &x, double &y, double &deltx, double &delty) {
135  _center_x=x;
136  _center_y=y;
137  _center_delta_x=deltx;
138  _center_delta_y=delty;
139  };
140 
142 
147 
152 
155 
158  };
159  }
160 }
161 
162 #endif
AnnotationBase * annotation() const
Base class for annotations.
bool clickWithin(double x, double y) const
double _drawing_blc_x_
Definition: Polygon.h:149
virtual void fetch_region_details(region::RegionTypes &type, std::vector< std::pair< int, int > > &pixel_pts, std::vector< std::pair< double, double > > &world_pts) const
void update_reference_bounds_rectangle()
double _center_delta_y
Definition: Polygon.h:154
void output(ds9writer &out) const
int clickHandle(double x, double y) const
void linearCenter(double &x, double &y) const
void boundingRectangle(double &blcx, double &blcy, double &trcx, double &trcy) const
return the drawing bounding rectangle...
region::RegionTypes type() const
fetch region type...
Definition: Polygon.h:100
Polygon(WorldCanvas *wc, QtRegionDock *d, double x1, double y1)
const point_list & drawing_points() const
Definition: Polygon.h:118
double _center_delta_x
Definition: Polygon.h:154
void addVertex(double x, double y, bool rewrite_last_point=false)
std::list< std::shared_ptr< RegionInfo > > * generate_dds_centers()
unsigned int check_handle(double x, double y) const
XScaleTo _x_origin_
Definition: Polygon.h:156
double _drawing_trc_x_
Definition: Polygon.h:150
void update_reference_state(int transformations, int handle, int new_handle)
All regions are specified in &quot;linear coordinates&quot;, not &quot;pixel coordinates&quot;.
Definition: Region.qo.h:147
bool valid_translation(double dx, double dy, double width_delta, double height_delta)
point_list _ref_points_
Definition: Polygon.h:143
double _drawing_width_
Definition: Polygon.h:151
region::PointInfo checkPoint(double x, double y) const
returns point state (Region::PointLocation)
void resize(double, double)
unsigned int mouseMovement(double x, double y, bool other_selected)
returns mouse state (Region::MouseState)
Class to hold a region of interest in an image.
Definition: ImageRegion.h:86
double _drawing_height_
Definition: Polygon.h:151
std::vector< pt > point_list
Definition: Polygon.h:50
casacore::ImageRegion * get_image_region(DisplayData *) const
void pixelCenter(double &x, double &y) const
double _drawing_blc_y_
Definition: Polygon.h:149
int moveHandle(int handle, double x, double y)
for rectangles, resizing can change the handle...
point_list _drawing_points_
Definition: Polygon.h:148
Implementation of drawing in world coordinates on top of a PixelCanvas.
Definition: WorldCanvas.h:204
void closeFigure(bool signal_complete=true)
std::pair< double, double > pt
Definition: Polygon.h:49
int move_vertex(int handle, double x, double y)
Base class for display objects.
Definition: DisplayData.h:317
int move_sizing_rectangle_handle(int handle, double x, double y)
YScaleTo _y_origin_
Definition: Polygon.h:157
int numVertices() const
Definition: Polygon.h:93
bool within_vertex_handle(double x, double y) const
double _drawing_trc_y_
Definition: Polygon.h:150
virtual void setCenter(double &x, double &y, double &deltx, double &delty)
Definition: Polygon.h:134
void move(double dx, double dy)
void update_drawing_bounds_rectangle()