casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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                                 int clickHandle( double x, double y ) const;
00066 
00067                                 bool doubleClick( double /*x*/, double /*y*/ );
00068 
00069                                 // returns point state (Region::PointLocation)
00070                                 region::PointInfo checkPoint( double x, double y ) const;
00071 
00072                                 // returns mouse state (Region::MouseState)
00073                                 unsigned int mouseMovement( double x, double y, bool other_selected );
00074 
00075                                 // for rectangles, resizing can change the handle...
00076                                 // for rectangles, moving a handle is resizing...
00077                                 int moveHandle( int handle, double x, double y );
00078                                 void move( double dx, double dy );
00079 
00080                                 void resize( double /*width_delta*/, double /*height_delta*/ );
00081                                 bool valid_translation( double dx, double dy, double width_delta, double height_delta );
00082 
00083                                 void linearCenter( double &x, double &y ) const;
00084                                 void pixelCenter( double &x, double &y ) const;
00085 
00086                                 AnnotationBase *annotation( ) const;
00087 
00088                                 virtual bool flag( MSAsRaster *msar );
00089 
00090                                 // in "linear" coordinates...
00091                                 void boundingRectangle( double &blcx, double &blcy, double &trcx, double &trcy ) const;
00092 
00093                                 void output( ds9writer &out ) const;
00094 
00095                                 // fetch region type...
00096                                 region::RegionTypes type( ) const { return region::RectRegion; }
00097 
00098                         protected:
00099                                 Rectangle( const std::string &name, WorldCanvas *wc, QtRegionDock *d, double x1, 
00100                                                    double y1, double x2, double y2, bool hold_signals=false, 
00101                                                    QtMouseToolNames::PointRegionSymbols sym=QtMouseToolNames::SYM_UNKNOWN ) :
00102                                                                                                 Region( name, wc, d, hold_signals, sym ), blc_x(x1<x2?x1:x2),
00103                                                                                                 blc_y(y1<y2?y1:y2), trc_x(x1<x2?x2:x1), trc_y(y1<y2?y2:y1) { complete = true; }
00104 
00105                                 RegionInfo::stats_t *get_ms_stats( MSAsRaster *msar, double x, double y );
00106                                 void generate_nonimage_statistics( DisplayData*, std::list<RegionInfo> * );
00107                                 std::list<std::tr1::shared_ptr<RegionInfo> > *generate_dds_centers( );
00108                                 ImageRegion *get_image_region( DisplayData* ) const;
00109 
00110                                 virtual void fetch_region_details( region::RegionTypes &type, std::vector<std::pair<int,int> > &pixel_pts, 
00111                                                                                                    std::vector<std::pair<double,double> > &world_pts ) const;
00112 
00113                                 void drawRegion( bool );
00114                                 /* void drawHandles( ); */
00115 
00116                                 virtual void setCenter(double &x, double &y, double &deltx, double &delty) {center_x_=x; center_y_=y; center_delta_x_=deltx; center_delta_y_=delty;};
00117 
00118                                 double blc_x, blc_y;
00119                                 double trc_x, trc_y;
00120                                 double center_x_, center_y_;
00121                                 double center_delta_x_, center_delta_y_;
00122                                 double handle_delta_x, handle_delta_y;
00123 
00124                         private:
00125                                 bool within_vertex_handle( double x, double y ) const;
00126                                 unsigned int check_handle( double x, double y ) const;
00127 
00128                 };
00129     }
00130 }
00131 
00132 #endif