PlotMSRegions.h

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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1