casa
$Rev:20696$
|
00001 //# PlotMSRegions.h: Properties of selected regions for a PlotMSPlot. 00002 //# Copyright (C) 2009 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 #ifndef PLOTMSREGIONS_H_ 00028 #define PLOTMSREGIONS_H_ 00029 00030 #include <plotms/PlotMS/PlotMSConstants.h> 00031 00032 #include <map> 00033 00034 #include <casa/namespace.h> 00035 using namespace std; 00036 00037 namespace casa { 00038 00039 // A single region; basically just a container class for four doubles. 00040 class PlotMSRegion { 00041 public: 00042 // Default constructor, which creates an invalid region in which all four 00043 // values are zero. 00044 PlotMSRegion(); 00045 00046 // Constructor that takes the four values of the region. 00047 PlotMSRegion(double xMin, double xMax, double yMin, double yMax); 00048 00049 // Copy constructor (see operator=()). 00050 PlotMSRegion(const PlotMSRegion& copy); 00051 00052 // Destructor. 00053 ~PlotMSRegion(); 00054 00055 00056 // Returns whether or not this region is valid. A region is invalid if 00057 // either of its maxes are <= its mins. 00058 bool isValid() const; 00059 00060 // Returns whether or not this region contains the given (x, y) pair. If 00061 // exclusive is true, then the borders are not included. 00062 bool contains(double x, double y, bool exclusive = true) const; 00063 00064 // Returns the region values. 00065 // <group> 00066 double left() const { return xMin(); } 00067 double right() const { return xMax(); } 00068 double bottom() const { return yMin(); } 00069 double top() const { return yMax(); } 00070 00071 double xMin() const; 00072 double xMax() const; 00073 double yMin() const; 00074 double yMax() const; 00075 // </group> 00076 00077 // Sets the region values. 00078 // <group> 00079 void setValues(double xMin, double xMax, double yMin, double yMax); 00080 void setX(double min, double max); 00081 void setY(double min, double max); 00082 void setXMin(double val); 00083 void setXMax(double val); 00084 void setYMin(double val); 00085 void setYMax(double val); 00086 void setLeft(double val) { setXMin(val); } 00087 void setRight(double val) { setXMax(val); } 00088 void setBottom(double val) { setYMin(val); } 00089 void setTop(double val) { setYMax(val); } 00090 // </group> 00091 00092 00093 // Equality operators. 00094 // <group> 00095 bool operator==(const PlotMSRegion& region) const; 00096 bool operator!=(const PlotMSRegion& region) const { 00097 return !(operator==(region)); } 00098 // </group> 00099 00100 // Copy operator. 00101 PlotMSRegion& operator=(const PlotMSRegion& copy); 00102 00103 private: 00104 // Values. 00105 double itsXMin_, itsXMax_, itsYMin_, itsYMax_; 00106 }; 00107 00108 // PlotMSRegions is a class that holds information about selected regions for a 00109 // single PlotMSPlot. Because PlotMSPlot can have potentially many different 00110 // plots across potentially many different canvases, it is important that 00111 // PlotMSRegions be general enough to handle many different cases. 00112 class PlotMSRegions { 00113 public: 00114 // Constructor, which creates an empty selection. 00115 PlotMSRegions(); 00116 00117 // Destructor. 00118 ~PlotMSRegions(); 00119 00120 00121 // Returns all axis pairs that have regions. 00122 Vector<pair<PMS::Axis, PMS::Axis> > allAxisPairs() const; 00123 00124 // Returns whether or not there are regions for the given (x, y) axis pair. 00125 bool hasRegionsFor(PMS::Axis x, PMS::Axis y) const; 00126 00127 // Returns a copy of the regions for the given (x, y) axis pair. 00128 Vector<PlotMSRegion> regionsFor(PMS::Axis x, PMS::Axis y) const; 00129 00130 // Adds the given regions for the given (x, y) axis pair. Will not remove 00131 // any existing regions for that pair. Only adds unique regions. 00132 // <group> 00133 void addRegions(PMS::Axis x, PMS::Axis y, const vector<PlotMSRegion>& r) { 00134 addRegions(x, y, Vector<PlotMSRegion>(r)); } 00135 void addRegions(PMS::Axis x, PMS::Axis y, const Vector<PlotMSRegion>& r); 00136 // </group> 00137 00138 // Convenience method for adding all selected regions using the standard 00139 // select tool on the given canvas for the given (x, y) axis pair. 00140 void addRegions(PMS::Axis x, PMS::Axis y, PlotCanvasPtr canvas); 00141 00142 // Sets the regions for the given (x, y) axis pair to the given. Removes 00143 // any existing regions for that pair. Only adds unique regions. 00144 // <group> 00145 void setRegions(PMS::Axis x, PMS::Axis y, const vector<PlotMSRegion>& r) { 00146 setRegions(x, y, Vector<PlotMSRegion>(r)); } 00147 void setRegions(PMS::Axis x, PMS::Axis y, const Vector<PlotMSRegion>& r); 00148 // </group> 00149 00150 // Convenience method for setting the regions for the given (x, y) axis 00151 // pair using the standard select tool on the given canvas. 00152 void setRegions(PMS::Axis x, PMS::Axis y, PlotCanvasPtr canvas); 00153 00154 // Clears the regions for the given (x, y) axis pair. 00155 void clearRegions(PMS::Axis x, PMS::Axis y); 00156 00157 private: 00158 // Convenience macro for map type. 00159 typedef map<pair<PMS::Axis, PMS::Axis>, Vector<PlotMSRegion> > PMSRMap; 00160 00161 // Map from (x, y) to selected regions. 00162 PMSRMap itsRegions_; 00163 }; 00164 00165 } 00166 00167 #endif /* PLOTMSREGIONS_H_ */