Rectangle.h

Go to the documentation of this file.
00001 //# rectangle.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_RECTANGLE_H_
00030 #define REGION_RECTANGLE_H_
00031 
00032 #include <display/region/Region.qo.h>
00033 #include <display/region/QtRegionSource.qo.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <list>
00036 
00037 namespace casa {
00038 
00039         class PanelDisplay;
00040         class AnnotationBase;
00041         class MSAsRaster;
00042         class DisplayData;
00043 
00044         namespace viewer {
00045 
00046                 // carry over from QtRegion... hopefully, removed soon...
00047                 class QtRegionSourceKernel;
00048 
00049                 // All regions are specified in "linear coordinates", not "pixel coordinates". This is necessary
00050                 // because "linear coordinates" scale with zooming whereas "pixel coordinates" do not. Unfortunately,
00051                 // this means that coordinate transformation is required each time the region is drawn.
00052                 class Rectangle : public Region {
00053                 public:
00054                         ~Rectangle( );
00055                         Rectangle( WorldCanvas *wc, QtRegionDock *d, double x1, double y1, double x2, double y2,
00056                                    bool hold_signals=false );
00057 
00058                         // carry over from QtRegion... hopefully, removed soon...
00059                         Rectangle( QtRegionSourceKernel *rs, WorldCanvas *wc, double x1, double y1, double x2, double y2,
00060                                    bool hold_signals=false);
00061 
00062                         bool clickWithin( double x, double y ) const {
00063                                 return x > blc_x && x < trc_x && y > blc_y && y < trc_y;
00064                         }
00065 
00066                         int clickHandle( double x, double y ) const;
00067 
00068                         bool doubleClick( double /*x*/, double /*y*/ );
00069 
00070                         // returns point state (Region::PointLocation)
00071                         region::PointInfo checkPoint( double x, double y ) const;
00072 
00073                         // returns mouse state (Region::MouseState)
00074                         unsigned int mouseMovement( double x, double y, bool other_selected );
00075 
00076                         // for rectangles, resizing can change the handle...
00077                         // for rectangles, moving a handle is resizing...
00078                         int moveHandle( int handle, double x, double y );
00079                         void move( double dx, double dy );
00080 
00081                         void resize( double /*width_delta*/, double /*height_delta*/ );
00082                         bool valid_translation( double dx, double dy, double width_delta, double height_delta );
00083 
00084                         void linearCenter( double &x, double &y ) const;
00085                         void pixelCenter( double &x, double &y ) const;
00086 
00087                         AnnotationBase *annotation( ) const;
00088 
00089                         virtual bool flag( MSAsRaster *msar );
00090 
00091                         // in "linear" coordinates...
00092                         void boundingRectangle( double &blcx, double &blcy, double &trcx, double &trcy ) const;
00093 
00094                         void output( ds9writer &out ) const;
00095 
00096                         // fetch region type...
00097                         region::RegionTypes type( ) const {
00098                                 return region::RectRegion;
00099                         }
00100 
00101                 protected:
00102                         Rectangle( const std::string &name, WorldCanvas *wc, QtRegionDock *d, double x1,
00103                                    double y1, double x2, double y2,
00104                                    bool hold_signals=false, QtRegionState *supplied_state=0,
00105                                    QtMouseToolNames::PointRegionSymbols sym=QtMouseToolNames::SYM_UNKNOWN ) :
00106                                 Region( name, wc, d, hold_signals, supplied_state, sym ), blc_x(x1<x2?x1:x2),
00107                                 blc_y(y1<y2?y1:y2), trc_x(x1<x2?x2:x1), trc_y(y1<y2?y2:y1) {
00108                                 initHistogram();
00109                                 complete = true;
00110                         }
00111 
00112                         RegionInfo::stats_t *get_ms_stats( MSAsRaster *msar, double x, double y );
00113                         void generate_nonimage_statistics( DisplayData*, std::list<RegionInfo> * );
00114                         std::list<SHARED_PTR<RegionInfo> > *generate_dds_centers( );
00115                         ImageRegion *get_image_region( DisplayData* ) const;
00116 
00117                         virtual void fetch_region_details( region::RegionTypes &type, std::vector<std::pair<int,int> > &pixel_pts,
00118                                                            std::vector<std::pair<double,double> > &world_pts ) const;
00119 
00120                         void drawRegion( bool );
00121                         /* void drawHandles( ); */
00122 
00123                         virtual void setCenter(double &x, double &y, double &deltx, double &delty) {
00124                                 center_x_=x;
00125                                 center_y_=y;
00126                                 center_delta_x_=deltx;
00127                                 center_delta_y_=delty;
00128                         };
00129 
00130                         double blc_x, blc_y;
00131                         double trc_x, trc_y;
00132                         double center_x_, center_y_;
00133                         double center_delta_x_, center_delta_y_;
00134                         double handle_delta_x, handle_delta_y;
00135 
00136                 private:
00137                         virtual bool output_region( ds9writer &out, WorldCanvas *wc, const std::vector<std::pair<double,double> > &pts ) const;
00138 
00139                         bool within_vertex_handle( double x, double y ) const;
00140                         unsigned int check_handle( double x, double y ) const;
00141 
00142                 };
00143         }
00144 }
00145 
00146 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1