| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeGeometryAlgorithms.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 *************************************************************************************/
    00027 #ifndef  __TERRALIB_INTERNAL_GEOMETRYALGORITHMS_H
    00028 #define  __TERRALIB_INTERNAL_GEOMETRYALGORITHMS_H
    00029
    00030 #include "TeGeometry.h"
    00031 #include "TeMultiGeometry.h"
    00032
    00033 #include "TePrecision.h"
    00034 #include "TeProjection.h"
    00035
    00037 typedef vector<TeCoord2D> TeIntersCoordsVec;
    00038
    00083
    00084 template<class T1, class T2>
    00085 inline bool TeEquals(const T1& /*o1*/, const T2& /*o2*/)
    00086 {
    00087            return false;
    00088 }
    00089
    00091 template<>
    00092 TL_DLL bool TeEquals(const TeCoord2D& c1, const TeCoord2D& c2);
    00093
    00095 template<>
    00096 TL_DLL bool TeEquals(const TePoint& p1, const TePoint& p2);
    00097
    00099 template<>
    00100 TL_DLL bool TeEquals(const TeLine2D& redLine, const TeLine2D& blueLine);
    00101
    00103 template<>
    00104 TL_DLL bool TeEquals(const TePolygon& redPol, const TePolygon& bluePol);
    00105
    00107 template<>
    00108 TL_DLL bool TeEquals( const TePolygonSet& ps1, const TePolygonSet& ps2 );
    00109
    00111 template<>
    00112 TL_DLL bool TeEquals(const TeBox& bx1, const TeBox& bx2);
    00113
    00115 template<>
    00116 TL_DLL bool TeEquals(const TeCell& cell1, const TeCell& cell2);
    00130 template<class T1, class T2>
    00131 inline bool TeDisjoint(const T1& o1, const T2& o2)
    00132 {
    00133            return TeDisjoint(o2, o1);
    00134 }
    00135
    00137 TL_DLL bool TeDisjoint(const TeCoord2D& c1, const TeCoord2D& c2);
    00138
    00140 TL_DLL bool TeDisjoint(const TeCoord2D& c, const TeBox& b);
    00141
    00143 TL_DLL bool TeDisjoint(const TeBox& bx1, const TeBox& bx2);
    00144
    00146 TL_DLL bool TeDisjoint(const TeCoord2D& c, const TeLine2D& l);
    00147
    00149 TL_DLL bool TeDisjoint(const TeCoord2D& c, const TePolygon& pol);
    00150
    00152 TL_DLL bool TeDisjoint(const TePoint& p1, const TePoint& p2);
    00153
    00155 TL_DLL bool TeDisjoint(const TePoint& p, const TeLine2D& l);
    00156
    00158 TL_DLL bool TeDisjoint(const TePoint& p, const TePolygon& pol);
    00159
    00161 TL_DLL bool TeDisjoint(const TeLine2D& redLine, const TeLine2D& blueLine);
    00162
    00164 TL_DLL bool TeDisjoint(const TeLine2D& l, const TePolygon& pol);
    00165
    00167 TL_DLL bool TeDisjoint(const TePolygon& redPol, const TePolygon& bluePol);
    00168
    00170 TL_DLL bool TeDisjoint(const TeCell& cell1, const TeCell& cell2);
    00171
    00173 TL_DLL bool TeDisjoint(const TeCell& cell, const TeLine2D& line);
    00174
    00176 TL_DLL bool TeDisjoint(const TeCell& cell, const TePolygon& pol);
    00177
    00179 TL_DLL bool TeDisjoint(const TeCell& cell, const TePoint& point);
    00193
    00194
    00195 template<class T1, class T2>
    00196 bool TeIntersects(const T1& o1, const T2& o2)
    00197 {
    00198            return !TeDisjoint(o1, o2);
    00199 }
    00200
    00202 template<>
    00203 TL_DLL bool TeIntersects(const TeCoord2D& c, const TeBox& b);
    00204
    00206 template<>
    00207 TL_DLL bool TeIntersects(const TePoint& p, const TeBox& b);
    00208
    00210 template<>
    00211 TL_DLL bool TeIntersects(const TeBox& bx1, const TeBox& bx2);
    00226
    00227 TL_DLL bool TeTouches(const TeCoord2D& c, const TeLine2D& l);
    00228
    00230 TL_DLL bool TeTouches(const TeCoord2D& c, const TePolygon& pol);
    00231
    00233 TL_DLL bool TeTouches(const TePoint& p, const TeLine2D& l);
    00234
    00236 TL_DLL bool TeTouches(const TePoint& p, const TePolygon& pol);
    00237
    00239 TL_DLL bool TeTouches(const TeLine2D& redLine, const TeLine2D& blueLine);
    00240
    00242 TL_DLL bool TeTouches(const TeLine2D& l, const TePolygon& pol);
    00243
    00245 TL_DLL bool TeTouches(const TePolygon& redPol, const TePolygon& bluePol);
    00246
    00248 TL_DLL bool TeTouches(const TeBox& bx1, const TeBox& bx2);
    00249
    00251 TL_DLL bool TeTouches(const TeCell& c1, const TeCell& c2);
    00252
    00254 TL_DLL bool TeTouches(const TeLine2D& line, const TeCell& cell);
    00255
    00257 TL_DLL bool TeTouches(const TeCell& c1, const TePolygon& poly);
    00258
    00260 TL_DLL bool TeTouches( const TePoint& point, const TeCell& c1);
    00276
    00277 TL_DLL bool TeCrosses(const TeLine2D& redLine, const TeLine2D& blueLine);
    00278
    00280 TL_DLL bool TeCrosses(const TeLine2D& l, const TePolygon& pol);
    00281
    00283 TL_DLL bool TeCrosses(const TeLine2D& l, const TeCell& cell);
    00302
    00303 TL_DLL bool TeWithin(const TeCoord2D& c1, const TeCoord2D& c2);
    00304
    00306 TL_DLL bool TeWithin(const TeCoord2D& c, const TeBox& b);
    00307
    00309 TL_DLL bool TeWithin(const TeCoord2D& c, const TeLine2D& l);
    00310
    00312 TL_DLL bool TeWithin(const TeCoord2D& c, const TePolygon& pol);
    00313
    00315 TL_DLL bool TeWithin(const TePoint& p1, const TePoint& p2);
    00316
    00318 TL_DLL bool TeWithin(const TePoint& p, const TeLine2D& l);
    00319
    00321 TL_DLL bool TeWithin(const TePoint& p, const TePolygon& pol);
    00322
    00324 TL_DLL bool TeWithin(const TeLine2D& redLine, const TeLine2D& blueLine);
    00325
    00327 TL_DLL bool TeWithin(const TeLine2D& l, const TePolygon& pol);
    00328
    00330 TL_DLL bool TeWithin(const TePolygon& redPol, const TePolygon& bluePol);
    00331
    00333 TL_DLL bool TeWithin(const TeBox& bx1, const TeBox& bx2);
    00334
    00336 TL_DLL bool TeWithin(const TeCell& cell1, const TeCell& cell2);
    00337
    00339 TL_DLL bool TeWithin(const TeLine2D& line, const TeCell& cell);
    00340
    00342 TL_DLL bool TeWithin(const TeCell& cell, const TePolygon& poly);
    00343
    00345 TL_DLL bool TeWithin(const TePoint& point, const TeCell& cell);
    00355
    00356 template<class T1, class T2>
    00357 inline bool TeContains(const T1& o1, const T2& o2)
    00358 {
    00359            return TeWithin(o2, o1);
    00360 }
    00376
    00377 TL_DLL bool TeOverlaps(const TeLine2D& redLine, const TeLine2D& blueLine);
    00378
    00380 TL_DLL bool TeOverlaps(const TePolygon& redPol, const TePolygon& bluePol);
    00381
    00383 TL_DLL bool TeOverlaps(const TeCell& cell1, const TeCell& cell2);
    00384
    00386 TL_DLL bool TeOverlaps(const TeCell& cell, const TePolygon& poly);
    00403
    00404 TL_DLL bool TeCoveredBy(const TeLine2D& redLine, const TeLine2D& blueLine);
    00405
    00407 TL_DLL bool TeCoveredBy(const TeLine2D& l, const TePolygon& pol);
    00408
    00410 TL_DLL bool TeCoveredBy(const TePolygon& redPol, const TePolygon& bluePol);
    00411
    00413 TL_DLL bool TeCoveredBy(const TeCell& cell1, const TeCell& cell2);
    00414
    00416 TL_DLL bool TeCoveredBy(const TePolygon& poly, const TeCell& cell);
    00417
    00419 TL_DLL bool TeCoveredBy(const TeLine2D& line, const TeCell& cell);
    00428
    00429 template<typename T1, typename T2>
    00430 inline bool TeCovers(T1& o1, T2& o2)
    00431 {
    00432            return TeCoveredBy(o2, o1);
    00433 }
    00447 TL_DLL short TeRelation(const TeCoord2D& c, const TeLine2D& l);
    00448
    00455 TL_DLL short TeRelation(const TeCoord2D& c, const TeLinearRing& r);
    00456
    00463 TL_DLL short TeRelation(const TeCoord2D& c, const TePolygon& pol);
    00464
    00471 TL_DLL short TeRelation(const TePoint& p, const TePolygon& pol);
    00472
    00479 TL_DLL short TeRelation(const TeCoord2D& c, const TePolygonSet& pSet);
    00480
    00487 TL_DLL short TeRelation(const TeLine2D& lRed, const TeLine2D& lBlue, const short& relation);
    00488
    00495 TL_DLL short TeRelation(const TeLine2D& line, const TePolygon& pol);
    00496
    00503 TL_DLL short TeRelation(const TePolygon& pRed, const TePolygon& pBlue);
    00512
    00513 TL_DLL bool TeDisjointOrTouches(const TeBox& bx1, const TeBox& bx2);
    00514
    00516 TL_DLL bool TeWithinOrTouches(const TeCoord2D& c, const TeCoord2D& c1, const TeCoord2D& c2);
    00525
    00526
    00527
    00528 template<class T1, class T2>
    00529 bool TeWithinOrCoveredByOrEquals(const T1& geom1, const T2& geom2)
    00530 {
    00531            short rel = TeRelation(geom1, geom2);
    00532
    00533            if((rel&TeINSIDE) || (rel&TeBOUNDARY))
    00534               return true;
    00535
    00536            return false;
    00537 }
    00538
    00540 template<>
    00541 TL_DLL bool TeWithinOrCoveredByOrEquals(const TeBox& bx1, const TeBox& bx2);
    00542
    00544 template<>
    00545 TL_DLL bool TeWithinOrCoveredByOrEquals(const TeLine2D& line1, const TeLine2D& line2);
    00546
    00548 template<>
    00549 TL_DLL bool TeWithinOrCoveredByOrEquals(const TeLine2D& line1, const TePolygon& pol);
    00550
    00552 template<>
    00553 TL_DLL bool TeWithinOrCoveredByOrEquals(const TePolygon& pol1, const TePolygon& pol2);
    00568 TL_DLL bool TeIntersection(const TeBox& bx1, const TeBox& bx2, TeBox& bout);
    00569
    00574 TL_DLL TeCoordPairVect           TeGetIntersections(const TePolygon &poly, const double& y);
    00588 TL_DLL TeBox TeUnion(const TeBox& bx1, const TeBox& bx2);
    00589
    00610 TL_DLL bool TePointInPoly(const TeCoord2D& c, const TeLinearRing& r);
    00611
    00617 TL_DLL bool TeIsOnSegment(const TeCoord2D& c, const TeCoord2D& c1, const TeCoord2D& c2);
    00618
    00625 TL_DLL bool TeIsOnLine(const TeCoord2D& c, const TeLine2D& l);
    00626
    00633 TL_DLL bool TeLocateLineSegment(TeCoord2D& pin, TeLine2D& line, int& segment, double tol = 0.0);
    00642 TL_DLL void removeDuplicatedCoords(vector<TeCoord2D>& coordSet);
    00643
    00645 TL_DLL TePolygon TeConvexHull(std::vector<TeCoord2D>& coordSet);
    00646
    00648 TL_DLL TePolygon TeConvexHull(const TePolygon& p);
    00649
    00651 TL_DLL TePolygon TeConvexHull(const TePolygonSet& ps);
    00652
    00654 TL_DLL TePolygon TeConvexHull(const TePointSet& ps);
    00655
    00663 template<class T>
    00664 TePolygon TeConvexHull(const T& coordSet)
    00665 {
    00666   // creates an auxiliary line with the points of the ring
    00667   vector<TeCoord2D> aux;
    00668
    00669   typename T::iterator it = coordSet.begin();
    00670
    00671   while(it != coordSet.end())
    00672   {
    00673     aux.push_back(*it);
    00674     ++it;
    00675   }
    00676
    00677   // removes duplicated coords from structs like ring
    00678   removeDuplicatedCoords(aux);
    00679
    00680   return TeConvexHull(aux);
    00681 };
    00682
    00689
    00690 TL_DLL double TeGetPrecision(TeProjection* proj);
    00691
    00693 class TL_DLL TeGeometryAlgorithmsPrecision
    00694 {
    00695            protected:
    00696
    00698                       TeGeometryAlgorithmsPrecision();
    00699
    00700            public:
    00701
    00703                       static bool IsGreater(const double& d1, const double& d2)
    00704                       {
    00705                                  return ((d1 - d2) > TePrecision::instance().precision());
    00706                       }
    00707
    00709                       static bool IsGreaterEqual(const double& d1, const double& d2)
    00710                       {
    00711                                  return ((d1 - d2) >= (-TePrecision::instance().precision()));
    00712                       }
    00713
    00715                       static bool IsSmaller(const double& d1, const double& d2)
    00716                       {
    00717                                  return ((d1 - d2) < -(TePrecision::instance().precision()));
    00718                       }
    00719
    00721                       static bool IsSmallerEqual(const double& d1, const double& d2)
    00722                       {
    00723                                  return ((d1 - d2) <= TePrecision::instance().precision());
    00724                       }
    00725
    00727                       static bool IsEqual(const double& d1, const double& d2)
    00728                       {
    00729                                  return (fabs(d1 - d2) <= TePrecision::instance().precision());
    00730                       }
    00731
    00733                       static bool IsDifferent(const double& d1, const double& d2)
    00734                       {
    00735                                  return (fabs(d1 - d2) > TePrecision::instance().precision());
    00736                       }
    00737 };
    00738
    00740 inline void TeRemoveDuplicatedCoordinates(TeLine2D& l)
    00741 {
    00742            for(int i = 0; i < (int)l.size() - 1; ++i)
    00743                       if(TeEquals(l[i], l[i + 1]))
    00744                       {
    00745                                  l.erase(l.begin() + i);
    00746                                  --i;
    00747                       }
    00748
    00749            return;
    00750 }
    00751
    00753 inline void TeRemoveDuplicatedCoordinates(TePolygon& p)
    00754 {
    00755            for(unsigned int i = 0; i < p.size(); ++i)
    00756                       TeRemoveDuplicatedCoordinates(p[i]);
    00757
    00758            return;
    00759 }
    00760
    00764 inline void TeReverseLine(TeLine2D& lin)
    00765 {
    00766            for(unsigned int i=0,j=lin.size()-1 ; i<lin.size()/2 ; ++i,--j)
    00767            {
    00768                       TeCoord2D p = lin[i];
    00769                       lin[i] = lin[j];
    00770                       lin[j] = p;
    00771            }
    00772
    00773            return;
    00774 }
    00775
    00776
    00780 TL_DLL bool TeIsConvex(const TeLinearRing& ring);
    00781
    00785 TL_DLL short TeOrientation(const TeLinearRing& r);
    00786
    00800 TL_DLL void TeGetMiddlePoint(const TeCoord2D& first, const TeCoord2D& last, TeCoord2D& middle);
    00801
    00806 TL_DLL double TeDistance(const TeCoord2D& c1, const TeCoord2D& c2);
    00807
    00811 TL_DLL double TeLength(const TeLine2D& l);
    00812
    00819 TL_DLL double TePerpendicularDistance(const TeCoord2D& first, const TeCoord2D& last, const TeCoord2D& pin, TeCoord2D &pinter);
    00820
    00828 TL_DLL double TeMinimumDistance (const TeCoord2D& first, const TeCoord2D& last, const TeCoord2D& pin, TeCoord2D& pout, double tol = 0.0);
    00829
    00837 template<class T>
    00838 double TeGeometryArea(const T& /* geom */)
    00839 {
    00840            return 0.0;
    00841 }
    00842
    00844 template<>
    00845 TL_DLL double TeGeometryArea(const TePolygon& p);
    00846
    00848 template<>
    00849 TL_DLL double TeGeometryArea(const TePolygonSet& ps);
    00850
    00852 template<>
    00853 TL_DLL double TeGeometryArea(const TeBox& b);
    00854
    00856 template<>
    00857 TL_DLL double TeGeometryArea(const TeMultiGeometry& mGeom);
    00868 TL_DLL TePolygon TeMakePolygon(const TeBox& b);
    00869
    00875 TL_DLL TeLinearRing TeSimpleClosedPath(const TePointSet& pSet);
    00888 TL_DLL TeCoord2D TeFindCentroid(TeMultiGeometry& mGeom);
    00889
    00893 TL_DLL TeCoord2D TeFindCentroid(const TePolygon& p);
    00894
    00898 TL_DLL TeCoord2D TeFindCentroid(const TeLine2D& l);
    00899
    00904 TL_DLL TeCoord2D TeFindCentroid(const TeCell& c);
    00905
    00909 TL_DLL TeCoord2D TeFindCentroid(const TePoint& p);
    00910
    00914 TL_DLL TeCoord2D TeFindCentroid(const TeText& t);
    00915
    00919 TL_DLL TeCoord2D TeFindCentroid(const TePolygonSet& s);
    00920
    00924 TL_DLL TeCoord2D TeFindCentroid(const TeLineSet& s);
    00925
    00929 TL_DLL TeCoord2D TeFindCentroid(const TeCellSet& s);
    00930
    00934 TL_DLL TeCoord2D TeFindCentroid(TePointSet& ps);
    00935
    00939 TL_DLL TeCoord2D TeFindCentroid(TeTextSet& ts);
    00940
    00947 TL_DLL bool TeFindTriangleCenter(const TeCoord2D& vert0, const TeCoord2D& vert1, const TeCoord2D& vert2, TeCoord2D& pc);
    00957 TL_DLL bool TeSegmentsIntersectPoint(const TeCoord2D& fr0, const TeCoord2D& to0, const TeCoord2D& fr1, const TeCoord2D& t1, TeCoord2D& pi);
    00958
    00967
    00968 TL_DLL bool TeNearest(TeCoord2D& pt, TeNodeSet& ns , int& i, const double& tol = 0.0);
    00969
    00971 TL_DLL bool TeNearest(TeCoord2D& pt, TePointSet& ps , int& i, const double& tol = 0.0);
    00972
    00974 TL_DLL bool TeNearest(TeCoord2D& pt, TeTextSet& ts , int& i, const double& tol = 0.0);
    00975
    00978 TL_DLL bool TeNearest(TeCoord2D& pt, TeLineSet& ls , int& i, TeCoord2D& pi, const double& tol = 0.0);
    00979
    00982 TL_DLL bool TeNearest (TeCoord2D& pt,TeLineSet& ls, int& lindex, TeCoord2D& pout, double& dmin, const double& tol = 0.0);
    00983
    00985 TL_DLL bool TeNearest(TeCoord2D& pt, TePolygonSet& ps , int& i, const double& tol = 0.0);
    00986
    00988 TL_DLL bool TeNearestByPoints(TeCoord2D& pt, TeLineSet& ls , int& i, double& dist, const double& tol = 0.0);
    01002 TL_DLL bool TeGetCenter(TePoint p1, TePoint p2, TePoint p3, TePoint &center);
    01003
    01010 TL_DLL double TeGetRadius(TePoint &p1, TePoint &p2, TePoint &p3);
    01011
    01023 TL_DLL bool TeGenerateArc(TePoint& p1, TePoint& p2, TePoint& p3, TeLine2D& arcOut, const short& NPoints);
    01024
    01031 TL_DLL bool TeGenerateCircle(const TePoint& center, const double& radius, TeLine2D& circle, const short& NPoints);
    01032
    01038 TL_DLL bool TeLineSimplify(TeLine2D& line, double snap, double maxdist);
    01039
    01048 TL_DLL bool TeAdjustSegment(TeCoord2D P0, TeCoord2D P1, double d0, TeCoord2D &P0out, TeCoord2D &P1out);
    01049
    01056 TL_DLL bool TeFindCentroid(const TeLine2D &line, TeCoord2D &p);
    01057  // end of group  GeometryAlgorithms
    01061
    01062
    01063 #endif     // __TERRALIB_INTERNAL_GEOMETRYALGORITHMS_H

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines