TeGeometry.h

Go to the documentation of this file.
00001 /************************************************************************************
00002 TerraLib - a library for developing GIS applications.
00003 Copyright  2001-2007 INPE and Tecgraf/PUC-Rio.
00004 
00005 This code is part of the TerraLib library.
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 You should have received a copy of the GNU Lesser General Public
00012 License along with this library.
00013 
00014 The authors reassure the license terms regarding the warranties.
00015 They specifically disclaim any warranties, including, but not limited to,
00016 the implied warranties of merchantability and fitness for a particular purpose.
00017 The library provided hereunder is on an "as is" basis, and the authors have no
00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
00020 indirect, special, incidental, or consequential damages arising out of the use
00021 of this library and its documentation.
00022 *************************************************************************************/
00023 /*! \file TeGeometry.h
00024     \brief This file contains structures and definitions about  geometries support in TerraLib
00025 */
00026 
00027 #ifndef __TERRALIB_INTERNAL_GEOMETRY_H
00028 #define __TERRALIB_INTERNAL_GEOMETRY_H
00029 
00030 #if defined(_MSC_VER) /* MSVC Compiler */
00031 #pragma warning(disable: 4786)
00032 #endif
00033 
00034 #include "TeDefines.h"
00035 #include "TeBox.h"
00036 #include "TeCoord2D.h"
00037 #include "TeComposite.h"
00038 #include "TeMeasure.h"
00039 #include "TeUtils.h"
00040 #include "TeDataTypes.h"
00041 
00042 #include <string>
00043 #include <iostream>
00044 
00045 
00046 using namespace std;
00047 
00048 //!  A basic class for handling geometries in TerraLib
00049 /*! 
00050          All geometric classes of TerraLib are derived from
00051          TeGeometry. This class keep track of a geometryId and of a bounding box for the geometry
00052         
00053          \note The Geometry classes in TerraLib use the Composite and the Visitor patterns
00054          \sa TeBox TeGeomComposite, TeGeomSingle 
00055 */
00056 class TL_DLL TeGeometry
00057 {
00058 public:
00059 
00060         //! Empty constructor
00061         TeGeometry(): box_ ( TeMAXFLOAT, TeMAXFLOAT, -TeMAXFLOAT, -TeMAXFLOAT ),
00062                 geomId_  ( 0 ), objectId_ (""), srid_(-1) {}
00063 
00064         //! Copy Constructor
00065         TeGeometry ( const TeGeometry& other ) 
00066         {
00067                 box_    = other.box_;
00068                 geomId_ = other.geomId_;
00069                 objectId_ = other.objectId_;
00070                 srid_ = other.srid_;
00071         }
00072         
00073         //! Destructor
00074         virtual ~TeGeometry() {}
00075 
00076         //! Sets the bounding box for the object
00077         void setBox ( const TeBox & box )
00078         { box_  = box; }
00079         
00080         //! Returns the constant bounding box
00081         const TeBox& box () const 
00082         { return box_; }
00083 
00084         //! Returns the bounding box
00085         TeBox& box ()
00086         { return box_; }
00087 
00088         //! Returns the geometry Id
00089         int geomId() const
00090         { return geomId_; }
00091 
00092         //! Sets the geometryId.
00093         void geomId( int id )
00094         { geomId_ = id; }
00095 
00096         //! Returns the object unique identification
00097         virtual string objectId() const
00098         { return objectId_; }
00099 
00100         //! Sets the objectId 
00101         virtual void objectId ( const string& id )
00102         { objectId_ = id; }
00103 
00104         //! Return the srid
00105         virtual int srid() const
00106         { return srid_; }
00107 
00108         //! Sets the srid
00109         virtual void srid(const int& srid)
00110         { srid_ = srid; }
00111 
00112         //! Return the geometry size 
00113         virtual unsigned int size() const
00114         { return 0; }
00115 
00116         //! Outputs the geometical identification to an output stream
00117         ostream& operator<<(ostream& os)
00118         {
00119                 os << Te2String(geomId_);
00120                 return os;
00121         }
00122 
00123         //! Returns TRUE if a geometry is a closed ring  
00124         virtual bool isRing() const
00125         { return false; }
00126 
00127         //! Returns the basic geometry type in a set of geometries structure
00128         virtual TeGeomRep elemType() const 
00129         { return TeGEOMETRYNONE; }
00130         
00131 protected:
00132 
00133         TeBox   box_;           //!<  The bounding box of the geometry
00134         int             geomId_;        //!<  The unique geometry identification
00135         string  objectId_;      //!<  The unique object identification associated to a geometry
00136         int             srid_;          //!<  The srid associated to the geometry
00137 };
00138 
00139 
00140 //! A class that represents a non existent geometry
00141 /*!
00142         This class is used to deal in a similar way with objects with or without geometry 
00143 */
00144 class TL_DLL TeGeometryNone:  public TeGeometry
00145 {
00146 public: 
00147         //! Returns the basic geometry in a set of geometries structure 
00148         TeGeomRep elemType() const { return TeGEOMETRYNONE; }
00149 
00150         //! Removes geometry elements
00151         void clear () { return; }
00152 };
00153 
00154 //! A class to handle vector geometries
00155 class TL_DLL TeVector : public TeGeometry
00156 {
00157 };
00158 
00159 //!   TeGeomSingle: A class for handling geometries in TerraLib which consist of one location
00160 /*!  
00161   \sa TePoint, TeSample 
00162 */
00163 template <class T>
00164 class TeGeomSingle : public TeVector
00165 {
00166 public:
00167 
00168     //! Exports the type of the element of a TeGeomSingle
00169         typedef  T value_type;
00170 
00171         //! Empty constructor
00172         TeGeomSingle<T>() {}
00173 
00174         //! Constructor from the single element of the container
00175         TeGeomSingle<T> (const T& elem ): elem_ ( elem  ) 
00176         {       updateBox ( box_, elem ); }
00177 
00178         //! Copy Constructor
00179         TeGeomSingle ( const TeGeomSingle& other ) : TeVector()
00180         {
00181                 box_    = other.box_;
00182                 geomId_ = other.geomId_;
00183                 objectId_ = other.objectId_;
00184                 elem_ = other.elem_;
00185         }
00186 
00187         //! Equal Operator
00188         TeGeomSingle& operator = ( const TeGeomSingle& other )
00189         {
00190                 box_    = other.box_;
00191                 geomId_ = other.geomId_;
00192                 objectId_ = other.objectId_;
00193                 elem_ = other.elem_;
00194                 return *this;
00195         }
00196 
00197         //! Destructor
00198         virtual ~TeGeomSingle<T>() {}
00199 
00200         //! Changes the unique element
00201         void add ( T& elem )
00202         {
00203                 elem_ = elem;
00204                 box_ = TeBox(TeMAXFLOAT, TeMAXFLOAT,-TeMAXFLOAT,-TeMAXFLOAT); // invalidates its box
00205                 updateBox ( box_, elem );
00206         }
00207 
00208         //! Returns the unique element
00209         T&      location ()
00210         {       return elem_; }
00211 
00212         //! Returns the unique element
00213         const T& location () const
00214         {       return elem_; }
00215 
00216         //! Returns the unique element
00217         T& elem ()
00218         {       return elem_; }
00219 
00220         //! Returns the unique element
00221         const T& elem () const
00222         {       return elem_; }
00223 
00224         //! Returns the unique element
00225         T& operator [] ( int /* i */) 
00226         {       return elem_; }
00227 
00228         //! Returns TRUE if a TeGeomSingle is equal to other
00229         bool operator== (const TeGeomSingle& other) const
00230         {       return elem_ == other.elem(); }
00231 
00232         //! Returns the size of a TeGeomSingle: always 1
00233         int size() { return 1; }
00234 
00235 protected:
00236         T       elem_;
00237 
00238 };
00239 
00240 
00241 
00242 //!  TeGeomComposite: A template class for handling a hierarchy of geometries in TerraLib
00243 /*!
00244 
00245           Used for instantiating the different geometries. Provide a vector to store the 2D 
00246           coordinates of a ring. Multiple copies of a geometry are allowed to share the same 
00247           coordinates by means of a "handle/body"  idiom.
00248 
00249         \sa  TeLine2D TePolygon TeLineSet TePolygonSet
00250 */
00251 
00252 template <class T>  
00253 class TeGeomComposite: public TeVector
00254 {
00255 public:
00256 
00257         //! Constructor
00258         TeGeomComposite()
00259         {
00260                 pImpl_ = new TeComposite<T>;
00261                 pImpl_->attach();
00262         }
00263 
00264         //! Destructor
00265         virtual ~TeGeomComposite()
00266         {       pImpl_->detach();       }
00267 
00268 
00269         //! Copy Constructor
00270         TeGeomComposite ( const TeGeomComposite& other ) : TeVector()
00271         {
00272                 pImpl_ = other.pImpl_;
00273                 pImpl_->attach();
00274                 box_    = other.box_;
00275                 geomId_ = other.geomId_;
00276                 objectId_ = other.objectId_;
00277         }
00278 
00279         //! Operator =
00280         TeGeomComposite& operator= ( const TeGeomComposite& other )
00281         {
00282                 if ( this != &other )
00283                 {       
00284                         other.pImpl_->attach();
00285                         pImpl_->detach();
00286                         pImpl_  = other.pImpl_;
00287                         box_    = other.box_;
00288                         geomId_ = other.geomId_;
00289                         objectId_ = other.objectId_;
00290                 }
00291                 return *this;
00292         }
00293 
00294         //! Returns the identification of the object associated to this geometry
00295         virtual string objectId() const
00296         { return objectId_; }
00297 
00298         //! Sets the identification of the object associated to this geometry
00299         virtual void objectId (const string& id )
00300         { 
00301                 objectId_ = id; 
00302                 typename TeComposite<T>::iterator it = pImpl_->begin();
00303                 while (it != pImpl_->end())
00304                 {
00305                         it->objectId(id);
00306                         ++it;
00307                 }
00308         }
00309 
00310         //! Copy two composites, duplicating elements (breaking handle/body idiom)
00311         void copyElements ( const TeGeomComposite& other )
00312         {
00313                 geomId_ = other.geomId_;
00314                 objectId_ = other.objectId_;
00315 
00316                 for (unsigned int i = 0; i < other.pImpl_->size(); i++)
00317                         add (other.pImpl_->operator[](i));
00318         }
00319 
00320         //! Returns TRUE if two composites have exactly the same elements
00321         bool operator== (const TeGeomComposite& other) const
00322         {       
00323                 if ( this->size() != other.size() )
00324                         return false;
00325 
00326                 for (unsigned int i = 0; i < other.pImpl_->size(); i++)
00327                         if ( ! ( pImpl_->operator[]( i ) == other.pImpl_->operator[]( i ) ) )
00328                                 return false;
00329       
00330                 return true; 
00331         }
00332 
00333         //! Adds a new component
00334         void add ( const T& elem )
00335         {       
00336                 pImpl_->add ( elem );
00337                 updateBox ( box_, elem );
00338         }
00339 
00340         //! Removes the i-th component
00341         bool erase ( int i )
00342         {       
00343                 bool status = pImpl_->erase (i);
00344 
00345                 if (status)     // recalculates the box
00346                 {
00347                         box_ = TeBox(TeMAXFLOAT, TeMAXFLOAT,-TeMAXFLOAT,-TeMAXFLOAT);
00348                         for (unsigned int j = 0; j < pImpl_->size(); j++)
00349                                 updateBox(box_,pImpl_->operator[](j));
00350                 }
00351                 return status;
00352         }
00353 
00354         //! Removes an element
00355         bool erase ( T& object )
00356         {       
00357                 bool status = pImpl_->erase ( object ); 
00358                 if (status)     // recalculates the box
00359                 {
00360                         box_ = TeBox(TeMAXFLOAT, TeMAXFLOAT,-TeMAXFLOAT,-TeMAXFLOAT);
00361                         for (unsigned int j = 0; j < pImpl_->size(); j++)
00362                                 updateBox(box_,pImpl_->operator[](j));
00363                 }
00364                 return status;
00365         }
00366 
00367         //! Removes the element pointed by an interator
00368         typename TeComposite<T>::iterator erase(typename TeComposite<T>::iterator it)
00369         {       
00370                 typename TeComposite<T>::iterator res = pImpl_->erase(it); 
00371                 box_ = TeBox(TeMAXFLOAT, TeMAXFLOAT,-TeMAXFLOAT,-TeMAXFLOAT);
00372                 for (unsigned int j = 0; j < pImpl_->size(); j++)
00373                         updateBox(box_,pImpl_->operator[](j));
00374                 return res;
00375         }
00376 
00377         //! Removes all elements
00378         void clear ()
00379         {       
00380                 pImpl_->clear ();               // remove all elements
00381                 box_ = TeBox(TeMAXFLOAT, TeMAXFLOAT,-TeMAXFLOAT,-TeMAXFLOAT); // invalidates its box
00382         }
00383         
00384         //! Returns the size of the composite
00385         unsigned int size() const
00386         {       return ( (unsigned int) pImpl_->size() ); }
00387 
00388         //! Reserves space for a given number of elements (reserve is available for vectors)  
00389         void reserve(int nelem)
00390         { pImpl_->reserve(nelem); }
00391 
00392         //! Returns the i-th element
00393         T& operator [] ( int i ) const
00394         {       return pImpl_->operator[] ( i ); }
00395 
00396         //! Returns the first element
00397         T& first() const
00398         {       return pImpl_->operator[] ( 0 ); }
00399         
00400         //! Returns the i-th element
00401         T& last() const
00402         {       return pImpl_->operator[] ( pImpl_->size()-1 ); }
00403         
00404         //! Returns TRUE if composite is empty
00405         bool empty () const
00406         {       return pImpl_->empty (); }
00407 
00408         //! An Iterator that enables forward traversal of a TeGeomComposite
00409         typedef typename TeComposite<T>::iterator iterator;
00410 
00411         //! The type of the value obtained by dereferencing a TeGeomComposite iterator
00412 //      typedef typename T value_type;
00413         typedef  T value_type;
00414 
00415         //! The iterator to the first position in the TeGeomComposite
00416         typename TeComposite<T>::iterator begin()
00417         { return pImpl_->begin(); }
00418 
00419         //! The iterator to the first position in the TeGeomComposite
00420         typename TeComposite<T>::iterator const begin() const
00421         { return pImpl_->begin(); }
00422 
00423         //! The iterator to the last plus one position in the TeGeomComposite
00424         typename TeComposite<T>::iterator end()
00425         { return pImpl_->end(); }
00426 
00427         //! The iterator to the last plus one position in the TeGeomComposite
00428         typename TeComposite<T>::iterator const end() const
00429         { return pImpl_->end(); }
00430 
00431         //! An Iterator that enables backward traversal of a TeGeomComposite
00432         typedef typename TeComposite<T>::reverse_iterator reverse_iterator;
00433 
00434         //! The iterator to the first position in the TeGeomComposite in reverse order
00435         typename TeComposite<T>::reverse_iterator rbegin()
00436         { return pImpl_->rbegin(); }
00437 
00438         //! The iterator to the last plus one position in the TeGeomComposite in reverse order
00439         typename TeComposite<T>::reverse_iterator rend()
00440         { return pImpl_->rend(); }
00441 
00442 protected:
00443 
00444         //! Pointer to the implementation of a composite<T>
00445         TeComposite<T> * pImpl_; 
00446 };
00447 
00448 //!  TeLine2D: Supports a simple 2D line,  composed of 2D xy points
00449 /*!
00450         \sa TeGeometry TeLinearRing
00451 */
00452 class TL_DLL TeLine2D : public TeGeomComposite<TeCoord2D>
00453 {
00454 public:
00455         //! Check if a line2D is a closed ring
00456         bool isRing() const;    
00457 
00458         //! Returns the identification of the object associated to this geometry
00459         string objectId() const
00460         { return objectId_; }
00461         
00462         //! Sets the identification of the object associated to this geometry
00463         void objectId (const string& id )
00464         {  objectId_ = id; }
00465 
00466         //! Returns the basic geometry in a set of geometries structure 
00467         TeGeomRep elemType() const { return TeLINES; }
00468 };
00469 
00470 //!  TeLineSet: Supports a composite of lines
00471 /*!
00472   \sa TeGeomComposite
00473 */
00474 class TL_DLL TeLineSet: public TeGeomComposite<TeLine2D>
00475 {
00476 public:
00477         //! Returns the basic geometry in a set of geometries structure 
00478         TeGeomRep elemType() const { return TeLINES; }
00479 
00480         //! Executes a real copy of two sets (duplicate the elements)
00481         void copyElements (const TeLineSet& other ); 
00482 }; 
00483 
00484 //!  TeLinearRing: Provides support for a 2D linear ring
00485 /*!
00486          A linear ring is a 2D line (without self-intersections) whose 
00487          first point is the same as the last point.  A linear ring cannot be created 
00488          directly, but is instantiated from a 2D line.
00489 
00490    \sa TePolygon 
00491 */
00492 class TL_DLL TeLinearRing : public TeLine2D  {
00493 public:
00494 
00495         //! Empty constructor
00496         TeLinearRing() : TeLine2D() {}
00497 
00498         //! Contructor from a line
00499         TeLinearRing ( TeLine2D& line );
00500 };
00501 
00502 
00503 //!  TePolygon: A class for handling 2D polygons. 
00504 /*!
00505         In TerraLib, a 2D polygon consists of an outer ring and a list
00506         of inner rings 
00507 */
00508 class TL_DLL TePolygon: public TeGeomComposite<TeLinearRing>  
00509 {
00510 public:
00511         
00512         //! Returns the basic geometry in a set of geometries structure 
00513         TeGeomRep elemType() const { return TePOLYGONS; }
00514 
00515         //! Executes a real copy of two sets (duplicate the elements)
00516         void copyElements ( const TePolygon& other );
00517 };
00518 
00519 //!  TePolygonSet: A class for handling sets of 2D polygons. 
00520 class TL_DLL TePolygonSet: public TeGeomComposite<TePolygon> 
00521 {
00522 public:
00523         //! Returns the basic geometry in a set of geometries structure 
00524         TeGeomRep elemType() const { return TePOLYGONS; }
00525 
00526         //! Executes a real copy of two sets (duplicate the elements)
00527         void copyElements ( const TePolygonSet& other );
00528 };
00529 
00530         
00531 //!  TePoint: A class for handling 2D Points. 
00532 class TL_DLL TePoint : public TeGeomSingle<TeCoord2D>
00533 {
00534 public:
00535         //! Default constructor
00536         TePoint(const double& x = 0., const double& y = 0. ):
00537                 TeGeomSingle<TeCoord2D> ( )
00538         {
00539                         elem_ = TeCoord2D(x,y);
00540                         setBox(TeBox(x,y,x,y)); // the box of a point is the point itself
00541         }
00542 
00543         //! Copy constructor
00544         TePoint(const TeCoord2D& c):
00545                 TeGeomSingle<TeCoord2D> ( )
00546         {
00547                         elem_ = c;
00548                         setBox(TeBox(c.x(),c.y(),c.x(),c.y())); // the box of a point is the point itself
00549         }
00550 
00551         //! Returns the basic geometry in a set of geometries structure 
00552         TeGeomRep elemType() const { return TePOINTS; }
00553 
00554         //! Returns the identification of the object associated to this geometry
00555         string objectId() const
00556         { return objectId_; }
00557         
00558         //! Sets the identification of the object associated to this geometry
00559         void objectId (const string& id )
00560         {  objectId_ = id; }
00561 
00562 };
00563 
00564 //!  TePointSet:  A class for handling sets of 2D polygons. 
00565 class TL_DLL TePointSet: public  TeGeomComposite<TePoint> 
00566 {
00567 public:
00568         //! Returns the basic geometry in a set of geometries structure 
00569         TeGeomRep elemType() const { return TePOINTS; }
00570 };
00571 
00572 //!  TeText : A class for handling text.
00573 class TL_DLL TeText: public TeGeomSingle<TeCoord2D>
00574 {
00575 public:
00576         //! Default contructor
00577         /*!
00578       \param txt the string of character that form the text (default is an empty string)
00579         */
00580         TeText(const string& txt="" ):
00581                 TeGeomSingle<TeCoord2D> ( ),
00582                 angle_(0),
00583                 height_(0),
00584                 textValue_(txt),
00585                 alignmentVert_(0),
00586                 alignmentHoriz_(0)
00587         {
00588                 elem_ = TeCoord2D(0,0);
00589                 setBox(TeBox(0.0,0.0,0.0,0.0));
00590         }
00591 
00592         //! Constructor
00593         /*!
00594                 \param location basic position of the text
00595                 \param txt the string of character that form the text (default is an empty string)
00596         */
00597 
00598         TeText( TeCoord2D& location, const string& txt="" ):
00599                 TeGeomSingle<TeCoord2D> ( location ),
00600                 angle_(0),
00601                 height_(0),
00602                 textValue_(txt),
00603                 alignmentVert_(0),
00604                 alignmentHoriz_(0)
00605         {
00606                 setBox(TeBox(location,location));
00607         }
00608 
00609         //! Copy constructor
00610         TeText(const TeText& other ) : TeGeomSingle<TeCoord2D>()
00611         {
00612                 angle_ = other.angle_;
00613                 height_ = other.height_;
00614                 textValue_ = other.textValue_;
00615                 alignmentVert_ = other.alignmentVert_;
00616                 alignmentHoriz_ = other. alignmentHoriz_;
00617                 setBox(other.box());
00618                 elem_ = other.elem_;
00619                 geomId_ = other.geomId_;
00620                 objectId_ = other.objectId_;
00621         }
00622 
00623         //! Operator =
00624         TeText& operator= ( const TeText& other )
00625         {
00626                 if ( this != &other )
00627                 {       
00628                         angle_ = other.angle_;
00629                         height_ = other.height_;
00630                         textValue_ = other.textValue_;
00631                         alignmentVert_ = other.alignmentVert_;
00632                         alignmentHoriz_ = other. alignmentHoriz_;
00633                         setBox(other.box());
00634                         elem_ = other.elem_;
00635                         geomId_ = other.geomId_;
00636                         objectId_ = other.objectId_;
00637                 }
00638                 return *this;
00639         }
00640 
00641         //! Returns TRUE if a text is equal to other
00642         bool operator== (const TeText& tx) const 
00643         {
00644                 return (angle_ == tx.angle_ &&
00645                         height_ == tx.height_ &&
00646                         textValue_ == tx.textValue_ &&
00647                         alignmentVert_ == tx.alignmentVert_ &&
00648                         alignmentHoriz_ == tx.alignmentHoriz_ &&
00649                         elem_ == tx.elem_ &&
00650                         geomId_ == tx.geomId_ &&
00651                         objectId_ == tx.objectId_);
00652         }
00653 
00654         //! Sets anew value for the location of the text
00655         void setLocation(const TeCoord2D& l)
00656         {       elem_ = l; setBox(TeBox(l,l));  }
00657 
00658         //! Returns the string value of a text
00659         string textValue () const
00660         { return textValue_; }
00661         
00662         //! Sets the string value of a text
00663         void setTextValue (const string &text) 
00664         { textValue_ = text; }
00665 
00666         //! Returns the text inclination
00667         double angle () const
00668         { return angle_; }
00669 
00670         //! Sets the text inclination
00671         void setAngle (double angle) 
00672         { angle_ = angle; }
00673 
00674         //! Returns the text height
00675         double height () const
00676         { return height_ ; }
00677 
00678         //! Sets the text height
00679         void setHeight (double height) 
00680         { height_ = height; }
00681 
00682         //! Returns the text vertical alignment
00683         double alignmentVert () const
00684         { return alignmentVert_ ; }
00685 
00686         //! Sets the text vertical alignment
00687         void setAlignmentVert (double alig) 
00688         { alignmentVert_ = alig; }
00689 
00690         //! Returns the text horizontal alignment
00691         double alignmentHoriz () const
00692         { return alignmentHoriz_ ; }
00693 
00694         //! Sets the text horizontal alignment
00695         void setAlignmentHoriz (double alig) 
00696         { alignmentHoriz_ = alig; }
00697 
00698         //! Returns the basic geometry in a set of geometries structure 
00699         TeGeomRep elemType() const { return TeTEXT; }
00700 
00701 private:
00702         double angle_;  
00703         double height_;
00704         string textValue_;
00705         double alignmentVert_;
00706         double alignmentHoriz_;
00707 };
00708 
00709 
00710 //!  TeTextSet : A class for handling sets of TeText.
00711 class TL_DLL TeTextSet : public TeGeomComposite<TeText> 
00712 {
00713 public:
00714         //! Returns the basic geometry in a set of geometries structure
00715         TeGeomRep elemType() const { return TeTEXT; }
00716 
00717 };
00718 
00719 
00720 //! TeNode:  A class for handling 2D Nodes.
00721 class TL_DLL TeNode: public TeGeomSingle<TeCoord2D>
00722 {
00723 public:
00724         //! Returns TRUE if nodes are equal
00725         bool operator== (const TeNode& node) const
00726         {
00727                 TeCoord2D p1 = elem_;
00728                 TeCoord2D p2 = node.elem_;
00729                 return p1==p2;
00730         }
00731 
00732         //! Outputs the geometrical identification of a node
00733         ostream& operator<<(ostream& os)
00734         {
00735                 os << Te2String(geomId_);
00736                 return os;
00737         }
00738 
00739         //! Returns the basic geometry in a set of geometries structure 
00740         TeGeomRep elemType() const { return TeNODES; }
00741 
00742 };
00743 
00744 //! Outputs the geometrical identification of a node
00745 TL_DLL ostream& operator<<(ostream& os, TeNode& N);
00746 
00747 //!  TeNodeSet :  A class for handling sets of 2D Nodes. 
00748 class TL_DLL TeNodeSet : public TeGeomComposite<TeNode> 
00749 
00750 {
00751 public:
00752         //! Returns the basic geometry in a set of geometries structure
00753         TeGeomRep elemType() const { return TeNODES; }
00754 
00755 };
00756 
00757 //!  TeArc : Provides support for a 2D arc.
00758 class TL_DLL TeArc : public TeVector 
00759 {
00760 public:
00761 
00762         //! Empty contructors
00763         TeArc(): ifrom_ (-1), ito_ (-1){}
00764 
00765         //! Construtor
00766         /*!
00767                 \param from the starting node of an arc
00768                 \param to the ending node of an arc
00769         */
00770         TeArc(TeNode& from, TeNode& to)
00771         {
00772                 from_ = from;
00773                 to_ = to;
00774                 updateBox ( box_, from );
00775                 updateBox ( box_, to );
00776         }
00777 
00778         //! Construtor
00779         /*!
00780                 \param from the geometrical identification of the  starting node of an arc
00781                 \param to the geometrical identification of the ending node of an arc
00782         */
00783         TeArc(int from, int to): ifrom_ (from), ito_ (to) {}
00784 
00785 // -- Methods
00786 
00787         //! Returns the starting node 
00788         TeNode& fromNode () 
00789         { return from_; }
00790 
00791         //! Returns the ending node 
00792         TeNode& toNode () 
00793         { return to_; }
00794 
00795         //! Returns the geometrical identification of the starting node 
00796         int fromId () const
00797         { return ifrom_; }
00798 
00799         //! Sets the geometrical identification of the starting node 
00800         void fromId (int i) 
00801         { ifrom_ = i; }
00802 
00803         //! Returns the geometrical identification of the ending node 
00804         int toId () const
00805         { return ito_; }
00806 
00807         //! Sets the geometrical identification of the ending node 
00808         void toId (int i)
00809         { ito_ = i; }
00810         
00811         //! Sets the starting and ending node 
00812         void setNodes (TeNode& from, TeNode& to)
00813         { 
00814                 from_ = from;
00815                 to_ = to;
00816                 updateBox ( box_, from );
00817                 updateBox ( box_, to );
00818         }
00819 
00820         //! Returns the basic geometry in a set of geometries structure 
00821         TeGeomRep elemType() const { return TeARCS; }
00822 
00823         //! Returns TRUE if a TeArc is equal to other
00824         bool operator== (const TeArc& other) const
00825         {
00826                 if((from_ == other.from_) &&
00827                (to_ == other.to_) &&
00828                    (ifrom_ == other.ifrom_) &&
00829            (ito_ != other.ito_))
00830                         return true;
00831 
00832                 return false;
00833         }
00834 
00835 private:
00836 
00837         TeNode  from_, to_;
00838         int             ifrom_, ito_;
00839 };
00840 
00841 //! Outputs the description of an arc
00842 TL_DLL ostream& operator<<(ostream& os, const TeArc& N);
00843 
00844 
00845 //!  TeArcSet: Provides support for a set of 2D arc.
00846 class TL_DLL TeArcSet: public TeGeomComposite <TeArc> 
00847 {
00848 public:
00849         //! Returns the basic geometry in a set of geometries structure 
00850         TeGeomRep elemType() const { return TeARCS; }
00851 };
00852 
00853 //!  TeSample: A class for handling 2D Points with an associated measure.
00854 class TL_DLL TeSample: public TeGeomSingle<TeCoord2D>, public TeMeasure
00855 {
00856 public:
00857         //! Constructor
00858         /*!
00859                 \param location the position of the sample
00860                 \param measure the value associated to the sample
00861         */
00862         TeSample ( const TeCoord2D& location, double measure = 0.  ):
00863                 TeGeomSingle<TeCoord2D> ( location ), TeMeasure ( measure ) {}
00864 
00865         TeGeomRep elemType() const { return TeSAMPLES; }
00866 };
00867 
00868 //!  TeSampleSet: A class for handling sets of 2D samples
00869 class TL_DLL TeSampleSet: public TeGeomComposite<TeSample>
00870 {
00871 public:
00872         //! Returns the basic geometry in a set of geometries structure 
00873         TeGeomRep elemType() const { return TeSAMPLES; }
00874 };
00875 
00876 //!  TeContourLine: A class for handling 2D countour lines
00877 class TL_DLL TeContourLine: public TeLine2D, public TeMeasure
00878 {
00879 public:
00880         //! Constructor
00881         /*!
00882                 \param line the contour line
00883                 \param measure the value associated to the contour line
00884         */
00885         TeContourLine ( TeLine2D& line, double measure = 0. )
00886                 : TeLine2D ( line ), TeMeasure ( measure )
00887         {}
00888 };
00889 
00890 
00891 //!  TeContourLineSet: A class for handling sets of 2D countour lines
00892 class TL_DLL TeContourLineSet: public  TeGeomComposite <TeContourLine> 
00893 {
00894 public:
00895         //! Returns the basic geometry in a set of geometries structure 
00896         TeGeomRep elemType() const { return TeSAMPLES; }
00897 };
00898 
00899 
00900 //!    A class for handling cells. 
00901 class TL_DLL TeCell : public TeVector 
00902 {
00903         int column_;    //!< the column number of this cell     
00904         int line_;              //!< the line number of this cell
00905 
00906 public:
00907         //! Empty constructor
00908         TeCell():
00909           column_(-1),
00910           line_(-1) {}
00911 
00912         TeCell(TeBox& box, int col, int lin):
00913           column_(col),
00914           line_(lin) { setBox(box); }
00915 
00916         //! Returns the column identification of the cell
00917         int     column () const
00918         { return column_; }
00919 
00920         //! Sets the column identification of the cell
00921         void column (int column) 
00922         { column_ =  column; }
00923 
00924         //! Returns the line identification of the cell
00925         int     line () const
00926         { return line_; }
00927 
00928         //! Sets the line identification of the cell
00929         void line (int line) 
00930         { line_ =  line; }
00931 
00932         //! Returns the basic geometry in a set of geometries structure 
00933         TeGeomRep elemType() const { return TeCELLS; }
00934 
00935         //! Returns TRUE if a TeCell is equal to other
00936         bool operator== (const TeCell& other) const
00937         {
00938                 if((column_ == other.column_) &&
00939                (line_ == other.line_))
00940                         return true;
00941 
00942                 return false;
00943         }
00944 };
00945 
00946 //!  A class for handling sets of cells.
00947 class TL_DLL TeCellSet: public  TeGeomComposite<TeCell> 
00948 {
00949         double  resX_;  //!< the X resolution of a set of cells
00950         double  resY_;  //!< the Y resolution of a set of cells
00951 
00952 public:
00953 
00954         //! Empty constructor
00955         TeCellSet() : resX_(0.), resY_(0.) 
00956         {}
00957 
00958         //! Returns the X resolution of a cell set
00959         double resX () const
00960         { return resX_; }
00961 
00962         //! Returns the Y resolution of a cell set
00963         double resY () const
00964         { return resY_; }
00965 
00966         //! Sets the X resolution of a cell set
00967         void resX (double reX) 
00968         { resX_ = reX; }
00969 
00970         //! Sets the Y resolution of a cell set
00971 
00972         void resY (double reY) 
00973         { resY_ = reY; }
00974 
00975         //! Returns the basic geometry in a set of geometries structure 
00976         TeGeomRep elemType() const { return TeCELLS; }
00977 
00978 };
00979 
00980 
00981 /*! \fn TePointSet makePointSet( const TeLinearRing& lr )
00982    \brief builds a TePointSet geometry from a TeLinearRing
00983  */
00984 TL_DLL TePointSet makePointSet( const TeLinearRing& lr );
00985 
00986 
00987 /*! \fn TePointSet makePointSet( const TePolygon& p )
00988    \brief builds a TePointSet geometry from a TePolygon
00989  */
00990 TL_DLL TePointSet makePointSet( const TePolygon& p );
00991 
00992 #endif
00993 
00994 

Generated on Sun Jul 29 04:01:21 2012 for TerraLib - Development Source by  doxygen 1.5.3