Path.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Path.hpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002 
00004 
00005 //============================================================================
00006 //
00007 //  This file is part of GPSTk, the GPS Toolkit.
00008 //
00009 //  The GPSTk is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU Lesser General Public License as published
00011 //  by the Free Software Foundation; either version 2.1 of the License, or
00012 //  any later version.
00013 //
00014 //  The GPSTk is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 //  GNU Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with GPSTk; if not, write to the Free Software Foundation,
00021 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //  
00023 //  Copyright 2004, The University of Texas at Austin
00024 //
00025 //============================================================================
00026 
00027 
00028 #ifndef VDRAW_PATH_H
00029 #define VDRAW_PATH_H
00030 
00031 #include<string>
00032 #include<vector>
00033 #include<utility> // std::pair
00034 #include<memory>  // std::auto_ptr
00035 
00036 // TODO In the future?
00037 // #include "boost/shared_ptr.hpp" // boost::shared_ptr
00038 // To use shared_ptr instead of auto_ptr
00039 
00040 #include "GraphicsConstants.hpp"
00041 #include "VDrawException.hpp"
00042 
00043 namespace vdraw
00044 {
00047 
00054   struct Point : public std::pair<double, double>
00055   {
00057     Point(double ix=0.0, double iy=0.0)
00058       : std::pair<double,double>(ix,iy)
00059     {
00060     }
00061 
00063     Point(const Point& p)
00064       : std::pair<double,double>(p.x(),p.y())
00065     {
00066     }
00067 
00069     Point(const std::pair<double,double>& o)
00070       : std::pair<double,double>(o)
00071     {
00072     }
00073 
00075     double& x() { return first; }
00076 
00078     const double& x() const { return first; }
00079 
00081     double& y() { return second; }
00082 
00084     const double& y() const { return second; }
00085 
00086   };
00087 
00107   class Path: public std::vector< Point > 
00108   {
00109     public:
00110 
00116       Path(unsigned int estimated_size=0) 
00117         : originX(0.0), originY(0.0)
00118       {
00119         if(estimated_size)
00120           reserve(estimated_size);
00121       }
00122 
00130       Path(double iOriginX, double iOriginY, unsigned int estimated_size=0) 
00131         : originX(iOriginX), originY(iOriginY)
00132       {
00133         if(estimated_size)
00134           reserve(estimated_size);
00135       }
00136 
00141       Path(const std::vector< std::pair<double,double> >& v, double iOriginX=0, double iOriginY=0)
00142       {
00143         originX = iOriginX;
00144         originY = iOriginY;
00145         reserve(v.size());
00146         std::vector< std::pair<double,double> >::const_iterator i;
00147         for(i=v.begin(); i!=v.end(); i++)
00148         {
00149           if(size()==0 
00150               || (i->first != (*this)[size()-1].x()) 
00151               || (i->second != (*this)[size()-1].y()))
00152             push_back(Point(*i));
00153         }
00154         tighten();
00155       }
00156 
00162       inline void tighten()
00163       {
00164         resize(size());
00165       }
00166 
00172       inline void setOrigin(double X, double Y)
00173       { 
00174         originX = X; 
00175         originY = Y; 
00176         return; 
00177       }
00178 
00184       inline void getOrigin(double& X, double& Y) const
00185       { 
00186         X = originX; 
00187         Y = originY; 
00188         return; 
00189       }
00190 
00196       void addPointAbsolute(double X, double Y);
00197 
00206       void addPointRelative(double X, double Y);
00207 
00213       void addPointDelta(double DX, double DY) throw (VDrawException);
00214 
00221       void rotate(double angleDegrees, double rx, double ry);
00222 
00227       void rotate(double angleDegrees);
00228 
00234       void translate(double deltaX, double deltaY);
00235 
00242       void scale(double factor, double sx, double sy);
00243 
00255       std::auto_ptr<Path> asAbsolute(void) const;
00256 
00257     protected:
00258 
00259     private:
00261       double originX; 
00263       double originY;
00264 
00265   }; // class Path
00266 
00268 
00269 } // namespace vdraw
00270 
00271 #endif //VDRAW_PLOT_PATH_H
00272 

Generated on Tue May 22 03:31:00 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1