casa
$Rev:20696$
|
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 { return drawing_points( ).size( ); } 00088 00089 void output( ds9writer &out ) const; 00090 00091 // fetch region type... 00092 region::RegionTypes type( ) const { return region::PolylineRegion; } 00093 00094 void addPlot( QWidget* parent, string label ); 00095 00096 00097 00098 signals: 00099 void show1DSliceTool(); 00100 00101 public slots: 00102 //Position marker 00103 void setMarkerPosition( int regionId, int segmentIndex, float percentage ); 00104 void setShowMarkerPosition( int regionId, bool show ); 00105 00106 protected: 00107 virtual RegionInfo *newInfoObject( ImageInterface<Float> *image, PrincipalAxesDD * ); 00108 unsigned int check_handle( double x, double y ) const; 00109 00110 enum YScaleTo { ScaleTop, ScaleBottom }; 00111 enum XScaleTo { ScaleLeft, ScaleRight }; 00112 enum Tranformations { FLIP_X = 1 << 0, FLIP_Y = 1 << 1 }; 00113 std::list<std::tr1::shared_ptr<RegionInfo> > *generate_dds_centers( ); 00114 ImageRegion *get_image_region( DisplayData* ) const; 00115 00116 void drawRegion( bool ); 00117 void drawText( ); 00118 00119 virtual void fetch_region_details( region::RegionTypes &type, std::vector<std::pair<int,int> > &pixel_pts, 00120 std::vector<std::pair<double,double> > &world_pts ) const; 00121 00122 const point_list &drawing_points( ) const { return _drawing_points_; } 00123 00124 private slots: 00125 void updatePolyLine(int regionId, viewer::region::RegionChanges, 00126 const QList<double> & worldX, const QList<double>& worldY, 00127 const QList<int> & pixelX, const QList<int> & pixelY); 00128 void polyLineRegionChanged( viewer::Region* region, std::string changeType); 00129 void polyLineRegionUpdate(int regionId, viewer::region::RegionChanges change, 00130 const QList<double> & worldX, const QList<double>& worldY, 00131 const QList<int> & pixelX, const QList<int> & pixelY); 00132 00133 00134 00135 private: 00136 bool within_vertex_handle( double x, double y ) const; 00137 int move_sizing_rectangle_handle( int handle, double x, double y ); 00138 int move_vertex( int handle, double x, double y ); 00139 00140 void update_drawing_bounds_rectangle( ); 00141 void update_reference_bounds_rectangle( ); 00142 00143 void update_drawing_state( ); 00144 void update_reference_state( int transformations, int handle, int new_handle ); 00145 00146 virtual void setCenter(double &x, double &y, double &deltx, double &delty); 00147 void initPlot( ); 00148 void setPlotLineColor(); 00149 void setPlotLineColor( SlicePlot* plot ); 00150 00151 double handle_delta_x, handle_delta_y; 00152 00153 point_list _ref_points_; 00154 double _ref_blc_x_, _ref_blc_y_; 00155 double _ref_trc_x_, _ref_trc_y_; 00156 double _ref_width_, _ref_height_; 00157 00158 point_list _drawing_points_; 00159 double _drawing_blc_x_, _drawing_blc_y_; 00160 double _drawing_trc_x_, _drawing_trc_y_; 00161 double _drawing_width_, _drawing_height_; 00162 00163 double _center_x, _center_y; 00164 double _center_delta_x, _center_delta_y; 00165 00166 XScaleTo _x_origin_; 00167 YScaleTo _y_origin_; 00168 00169 //Slice functionality 00170 void drawPositionMarker(); 00171 QMap<QString,SlicePlot*> slicePlots; 00172 int markerSegmentIndex; 00173 float markerPercentage; 00174 bool showPositionMarker; 00175 }; 00176 } 00177 } 00178 00179 #endif