00001
00077 #ifndef INC_MI32_REGION2D_H
00078 #define INC_MI32_REGION2D_H
00079
00080 #ifndef INC_MI32_POLYLINE_H
00081 #include <mi32/polyline.h>
00082 #endif
00083
00084 #ifndef INC_MI32_SPATREF_H
00085 #include <mi32/spatref.h>
00086 #endif
00087
00088
00089 #ifdef GEOMDLL
00090 #define GEOMLIBCLASSEXPORT MI_DLLCLASSEXPORT
00091 #else
00092 #define GEOMLIBCLASSEXPORT MI_DLLCLASSIMPORT
00093 #endif
00094
00095 #ifndef GENERATING_DOXYGEN_OUTPUT
00096
00097 class TRANS2D_AFFINE;
00098 class TRANS2D_MAPGEN;
00099 class REGION2D;
00100 class SERIALIZER;
00101 class BINARYTOREGION2D;
00102 namespace RVC {
00103 class CAD;
00104 class VECTOR;
00105 class REGION;
00106 class REGIONHANDLE;
00107 }
00108 #endif
00109
00110
00114 class GEOMLIBCLASSEXPORT SUBREGION2D {
00115 public:
00116
00117 typedef POLYLINELIST::CONST_ITERATOR CONST_ITERATOR;
00118
00120 class GEOMLIBCLASSEXPORT COPYFILTER {
00121 public:
00123 COPYFILTER ();
00125 virtual ~COPYFILTER () = 0;
00127 bool IsIslandIncluded (
00128 const POLYLINE& island
00129 ) { return (v_IsIslandIncluded(island)); }
00130 private:
00133 virtual bool v_IsIslandIncluded (
00134 const POLYLINE& island
00135 );
00136 };
00137
00139 SUBREGION2D ();
00140
00142 SUBREGION2D (
00143 const SUBREGION2D& rhs
00144 );
00145
00147 SUBREGION2D (
00148 const DRECT2D& rect
00149 );
00150
00152 ~SUBREGION2D ();
00153
00155 SUBREGION2D& operator= (
00156 const SUBREGION2D& rhs
00157 );
00158
00160 SUBREGION2D& operator= (
00161 const DRECT2D& rhs
00162 );
00163
00165 SUBREGION2D& operator= (
00166 const DRECT3D& rhs
00167 );
00168
00171 ERRVALUE Assign (
00172 const POLYLINE& Polygon
00173 );
00174
00176 ERRVALUE AssignFromXML (
00177 const XMLNODE *topnode
00178 );
00179
00183 void AssignValidated (
00184 const POLYLINE& Polygon
00185 );
00186
00191 void AssignValidated (
00192 const POLYLINELIST& PolygonList
00193 );
00194
00198 CONST_ITERATOR Begin (
00199 ) const { return (m_ItemList.Begin()); }
00200
00202 void Clear ();
00203
00206 int ClipLine (
00207 POLYLINE& PolyLine,
00208 POLYLINE::CLIP& ClipTarget,
00209 CLIPMODE ClipMode = CLIPMODE_Inside
00210 ) const;
00211
00213 double ComputeArea () const;
00214
00216 double ComputeAreaNoIslands () const;
00217
00220 double ComputeCentroid (
00221 DPOINT3D& centroid
00222 ) const;
00223
00225 double ComputePerimeter () const;
00226
00228 double ComputePerimeterNoIslands () const;
00229
00231 void ConvertForward (
00232 const TRANS2D_AFFINE& taf
00233 );
00234
00236 ERRVALUE ConvertForward (
00237 const TRANS2D_MAPGEN& tmg
00238 );
00239
00241 ERRVALUE ConvertForward (
00242 const SPATREF::COORDOP& Op
00243 );
00244
00248 ERRVALUE ConvertForwardDense (
00249 const TRANS2D_MAPGEN& tmg
00250 );
00251
00255 ERRVALUE ConvertForwardDense (
00256 const SPATREF::COORDOP& Op,
00257 double tolerance
00258 );
00259
00261 void ConvertInverse (
00262 const TRANS2D_AFFINE& taf
00263 );
00264
00266 ERRVALUE ConvertInverse (
00267 const TRANS2D_MAPGEN& tmg
00268 );
00269
00273 ERRVALUE ConvertInverseDense (
00274 const TRANS2D_MAPGEN& tmg
00275 );
00276
00278 ERRVALUE ConvertReverse (
00279 const SPATREF::COORDOP& Op
00280 );
00281
00285 ERRVALUE ConvertReverseDense (
00286 const SPATREF::COORDOP& Op,
00287 double tolerance
00288 );
00289
00291 ERRVALUE ConvertToLongFloor (
00292 SIMPLE_ARRAY<LPOLYGON>& PolygonArray,
00293 SIMPLE_ARRAY<LPOINT2D>& PointArray
00294 ) const;
00295
00297 ERRVALUE ConvertToLongFloor (
00298 SIMPLE_ARRAY<LPOLYGON>& PolygonArray,
00299 SIMPLE_ARRAY<LPOINT2D>& PointArray,
00300 const DPOINT2D& scale,
00301 const DPOINT2D& offset
00302 ) const;
00303
00305 ERRVALUE ConvertToLongNearInt (
00306 SIMPLE_ARRAY<LPOLYGON>& PolygonArray,
00307 SIMPLE_ARRAY<LPOINT2D>& PointArray
00308 ) const;
00309
00311 ERRVALUE ConvertToLongRound (
00312 SIMPLE_ARRAY<LPOLYGON>& PolygonArray,
00313 SIMPLE_ARRAY<LPOINT2D>& PointArray
00314 ) const;
00315
00317 ERRVALUE CopyTo (
00318 SUBREGION2D& target,
00319 COPYFILTER& filter
00320 ) const;
00321
00325 void DumpCoords (
00326 MISTRING& result,
00327 int indent,
00328 bool maxprec = false
00329 ) const;
00330
00333 CONST_ITERATOR End () const
00334 { return (m_ItemList.End()); }
00335
00344 int FitRectangleInside (
00345 const DPOINT2D& size,
00346 DPOINT2D& ptCenterRet,
00347 UINT32 QuantFactor = 10,
00348 bool bUseFirstFound = false
00349 ) const;
00350
00353 ERRVALUE GeneratePointInside (
00354 DPOINT2D& PointInside
00355 ) const;
00356
00360 ERRVALUE GenerateRandomPointInside (
00361 DPOINT2D& PointInside
00362 ) const;
00363
00366 const DRECT3D& GetExtents () const
00367 { return (m_Extents); }
00368
00371 const DRECT2D& GetExtents2D () const
00372 { return (m_Extents); }
00373
00376 INT32 GetNumIslands () const
00377 { return (IsEmpty() ? 0 : m_ItemList.GetNumItems()-1); }
00378
00380 XMLNODE* GetXML (
00381 XMLNODE *parentnode,
00382 const char *nodename = "SubRegion"
00383 ) const;
00384
00387 ERRVALUE Intersect (
00388 const DRECT2D& Rect,
00389 MILIST<SUBREGION2D>& SubRegionList
00390 );
00391
00396 ERRVALUE Intersect (
00397 const POLYLINE& PolyLine,
00398 MILIST<SUBREGION2D>& SubRegionList
00399 );
00400
00403 ERRVALUE Intersect (
00404 const SUBREGION2D& SubRegion,
00405 MILIST<SUBREGION2D>& SubRegionList
00406 );
00407
00411 ERRVALUE IntersectValidated (
00412 const POLYLINE& PolyLine,
00413 MILIST<SUBREGION2D>& SubRegionList
00414 );
00415
00420 bool IsEquivalentTo (
00421 const SUBREGION2D& rhs,
00422 double threshold = 0.0
00423 ) const;
00424
00427 bool IsPointInside (
00428 const DPOINT2D& point
00429 ) const;
00430
00432 bool IsEmpty (
00433 ) const { return (!m_Extents.IsValid()); }
00434
00436 bool IsRectangle (
00437 ) const { return (m_IsRectangle); }
00438
00440 void RemoveIslands ();
00441
00443 void Reverse ();
00444
00446 void SetDimension (
00447 DIMENSION dim
00448 );
00449
00453 void SetOrientation (
00454 ORIENTATION Orientation
00455 );
00456
00461 ERRVALUE Subtract (
00462 const POLYLINE& Island,
00463 MILIST<SUBREGION2D>& SubRegionList
00464 );
00465
00468 ERRVALUE Subtract (
00469 const SUBREGION2D& SubRegion,
00470 MILIST<SUBREGION2D>& SubRegionList
00471 );
00472
00475 ERRVALUE Subtract (
00476 const DRECT2D& IslandRect,
00477 MILIST<SUBREGION2D>& SubRegionList
00478 );
00479
00483 ERRVALUE SubtractValidated (
00484 const POLYLINE& Island,
00485 MILIST<SUBREGION2D>& SubRegionList
00486 );
00487
00491 ERRVALUE SubtractValidated (
00492 const POLYLINE& Island,
00493 MILIST<SUBREGION2D>& SubRegionList,
00494 double ConflateThreshold
00495 );
00496
00499 bool TestLine (
00500 const POLYLINE& PolyLine,
00501 TESTCRITERIA TestCriteria
00502 ) const;
00503
00506 POLYLINE::COMPRESULT TestLine (
00507 const POLYLINE& PolyLine
00508 ) const;
00509
00512 bool TestPoint (
00513 const DPOINT2D& Point,
00514 TESTCRITERIA TestCriteria
00515 ) const;
00516
00519 bool TestPolygon (
00520 const POLYLINE& PolyLine,
00521 TESTCRITERIA TestCriteria
00522 ) const;
00523
00526 POLYLINE::COMPRESULT TestPolygon (
00527 const POLYLINE& PolyLine
00528 ) const;
00529
00532 bool TestSubRegion (
00533 const SUBREGION2D& SubRegion,
00534 TESTCRITERIA TestCriteria
00535 ) const;
00536
00539 POLYLINE::COMPRESULT TestSubRegion (
00540 const SUBREGION2D& SubRegion
00541 ) const;
00542
00544 ERRVALUE Union (
00545 const DRECT2D& Rect,
00546 MILIST<SUBREGION2D>& SubRegionList,
00547 POLYLINE::COMBINERESULT& CombineResult
00548 );
00549
00551 ERRVALUE Union (
00552 const POLYLINE& PolyLine,
00553 MILIST<SUBREGION2D>& SubRegionList
00554 );
00555
00557 ERRVALUE Union (
00558 const SUBREGION2D& SubRegion,
00559 MILIST<SUBREGION2D>& SubRegionList,
00560 POLYLINE::COMBINERESULT& CombineResult
00561 );
00562
00564 ERRVALUE UnionValidated (
00565 const POLYLINE& PolyLine,
00566 MILIST<SUBREGION2D>& SubRegionList,
00567 POLYLINE::COMBINERESULT& CombineResult
00568 );
00569
00570 private:
00571 #ifndef GENERATING_DOXYGEN_OUTPUT
00572
00573 POLYLINELIST m_ItemList;
00574 DRECT3D m_Extents;
00575 bool m_IsRectangle;
00576
00577 ERRVALUE ComputeBuffer (const double Distance, REGION2D& Buffer) const;
00578 void UpdateExtentsRect ();
00579 ERRVALUE UpdateFromShells (POLYLINELIST& PolyLineList, MILIST<SUBREGION2D>& SubRegionList);
00580
00581 friend class RVC::VECTOR;
00582 friend class RVC::REGION;
00583 friend class REGION2D;
00584 friend class RVC::REGIONHANDLE;
00585 friend class BINARYTOREGION2D;
00586 friend class SERIALIZER;
00587 #endif // GENERATING_DOXYGEN_OUTPUT
00588 };
00589
00590 typedef MILIST<SUBREGION2D> SUBREGIONLIST;
00591
00592
00597 class GEOMLIBCLASSEXPORT REGION2D {
00598 public:
00599
00600 typedef SUBREGIONLIST::CONST_ITERATOR CONST_ITERATOR;
00601
00603 class GEOMLIBCLASSEXPORT COPYFILTER : public SUBREGION2D::COPYFILTER {
00604 public:
00606 COPYFILTER ();
00608 virtual ~COPYFILTER () = 0;
00610 bool IsLineIncluded (
00611 const POLYLINE& line
00612 ) { return (v_IsLineIncluded(line)); }
00614 bool IsPointIncluded (
00615 const DPOINT2D& point
00616 ) { return (v_IsPointIncluded(point)); }
00618 bool IsSubRegionIncluded (
00619 const SUBREGION2D& subregion
00620 ) { return (v_IsSubRegionIncluded(subregion)); }
00621 private:
00624 virtual bool v_IsLineIncluded (
00625 const POLYLINE& line
00626 );
00629 virtual bool v_IsPointIncluded (
00630 const DPOINT2D& point
00631 );
00634 virtual bool v_IsSubRegionIncluded (
00635 const SUBREGION2D& subregion
00636 );
00637 };
00638
00640 REGION2D (
00641 );
00642
00644 REGION2D (
00645 const REGION2D& rhs
00646 );
00647
00649 REGION2D (
00650 const DRECT2D& rhs
00651 );
00652
00654 REGION2D (
00655 const SUBREGION2D& SubRegion
00656 );
00657
00659 REGION2D (
00660 const POLYLINELIST&
00661 );
00662
00664 ~REGION2D (
00665 );
00666
00668 REGION2D& operator= (
00669 const REGION2D& rhs
00670 );
00671
00673 REGION2D& operator= (
00674 const DRECT2D& rhs
00675 );
00676
00678 REGION2D& operator= (
00679 const DRECT3D& rhs
00680 );
00681
00683 REGION2D& operator= (
00684 const SUBREGION2D& SubRegion
00685 );
00686
00688 void AddLine (
00689 const POLYLINE& PolyLine
00690 );
00691
00693 void AddLines (
00694 const POLYLINELIST& LineList
00695 );
00696
00698 void AddPoint (
00699 const DPOINT3D& Point
00700 );
00701
00703 void AddPoints (
00704 const POLYLINE& points
00705 );
00706
00708 void AddSubRegion (
00709 const SUBREGION2D& SubRegion
00710 );
00711
00713 ERRVALUE Assign (
00714 const POLYLINE& PolyLine,
00715 const SIMPLE_ARRAY<INT32>& Index
00716 );
00717
00719 ERRVALUE AssignFromXML (
00720 const XMLNODE *topnode
00721 );
00722
00725 CONST_ITERATOR Begin (
00726 ) const { return (m_SubList.Begin()); }
00727
00729 void Clear (
00730 );
00731
00733 void ClearCoordRefSys (
00734 );
00735
00738 int ClipLine (
00739 POLYLINE& PolyLine,
00740 POLYLINE::CLIP& ClipTarget,
00741 CLIPMODE ClipMode = CLIPMODE_Inside
00742 ) const;
00743
00745 double ComputeArea (
00746 ) const;
00747
00749 double ComputeAreaNoIslands (
00750 ) const;
00751
00756 void ComputeCentroid (
00757 DPOINT3D& centroid
00758 ) const;
00759
00763 ERRVALUE ComputeExpansion (
00764 const double Distance,
00765 REGION2D& Expansion
00766 ) const;
00767
00770 double ComputePerimeter (
00771 ) const;
00772
00775 ERRVALUE ComputePerimeter (
00776 double& result,
00777 SPATREF::COORDREFSYS::MEASUREMETHOD method,
00778 UOM::IDNUM LengthUnitIdNum = UOM::IDNUM_Length_Meter
00779 ) const;
00780
00783 double ComputePerimeterNoIslands (
00784 ) const;
00785
00788 void ConvertForward (
00789 const TRANS2D_AFFINE& taf
00790 );
00791
00797 ERRVALUE ConvertForward (
00798 const TRANS2D_MAPGEN& tmg
00799 );
00800
00804 ERRVALUE ConvertForward (
00805 const SPATREF::COORDOP& Op
00806 );
00807
00813 ERRVALUE ConvertForwardDense (
00814 const TRANS2D_MAPGEN& tmg
00815 );
00816
00820 ERRVALUE ConvertForwardDense (
00821 const SPATREF::COORDOP& Op,
00822 double tolerance
00823 );
00824
00827 void ConvertInverse (
00828 const TRANS2D_AFFINE& taf
00829 );
00830
00836 ERRVALUE ConvertInverse (
00837 const TRANS2D_MAPGEN& tmg
00838 );
00839
00845 ERRVALUE ConvertInverseDense (
00846 const TRANS2D_MAPGEN& tmg
00847 );
00848
00852 ERRVALUE ConvertReverse (
00853 const SPATREF::COORDOP& Op
00854 );
00855
00859 ERRVALUE ConvertReverseDense (
00860 const SPATREF::COORDOP& Op,
00861 double tolerance
00862 );
00863
00865 ERRVALUE ConvertTo (
00866 const SPATREF::COORDREFSYS& DestCoordRefSys,
00867 double tolerance = 0.0
00868 );
00869
00871 ERRVALUE CopyTo (
00872 REGION2D& target,
00873 COPYFILTER& filter
00874 ) const;
00875
00879 void DumpCoords (
00880 MISTRING& result,
00881 int indent,
00882 bool maxprec = false
00883 ) const;
00884
00887 CONST_ITERATOR End (
00888 ) const { return (m_SubList.End()); }
00889
00891 ERRVALUE ExclusiveUnion (
00892 const REGION2D& RegionB
00893 );
00894
00897 ERRVALUE ExclusiveUnion (
00898 const REGION2D& RegionA,
00899 const REGION2D& RegionB
00900 );
00901
00905 ERRVALUE Expand (
00906 const double Distance
00907 );
00908
00911 const SPATREF::COORDREFSYS& GetCoordRefSys (
00912 ) const { return (m_CoordRefSys); }
00913
00916 const DRECT3D& GetExtents (
00917 ) const { return (m_Extents); }
00918
00921 const DRECT2D& GetExtents2D (
00922 ) const { return (m_Extents); }
00923
00926 const POLYLINELIST& GetLineList (
00927 ) const { return (m_LineList); }
00928
00931 INT32 GetNumLines (
00932 ) const { return (m_LineList.GetNumItems()); }
00933
00936 INT32 GetNumPoints (
00937 ) const { return (m_PointList.GetNumPoints()); }
00938
00941 INT32 GetNumSubRegions (
00942 ) const { return (m_SubList.GetNumItems()); }
00943
00946 const POLYLINE& GetPointList (
00947 ) const { return (m_PointList); }
00948
00951 const SUBREGIONLIST& GetSubRegionList (
00952 ) const { return (m_SubList); }
00953
00955 XMLNODE* GetXML (
00956 XMLNODE *parentnode,
00957 const char *nodename = "Region"
00958 ) const;
00959
00961 bool HasPoints (
00962 ) const { return (m_PointList.GetNumPoints() > 0); }
00963
00965 bool HasLines (
00966 ) const { return (!m_LineList.IsEmpty()); }
00967
00969 bool HasSubRegions (
00970 ) const { return (!m_SubList.IsEmpty()); }
00971
00973 ERRVALUE Intersect (
00974 const DRECT2D& Rect
00975 );
00976
00978 ERRVALUE Intersect (
00979 const POLYLINE& PolyLine
00980 );
00981
00983 ERRVALUE Intersect (
00984 const SUBREGION2D& SubRegion
00985 );
00986
00988 ERRVALUE Intersect (
00989 const REGION2D& RegionB
00990 );
00991
00994 ERRVALUE Intersect (
00995 const REGION2D& RegionA,
00996 const REGION2D& RegionB
00997 );
00998
01000 ERRVALUE IntersectValidated (
01001 const POLYLINE& PolyLine
01002 );
01003
01005 bool IsEmpty (
01006 ) const { return (!m_Extents.IsValid()); }
01007
01012 bool IsEquivalentTo (
01013 const REGION2D& rhs,
01014 double threshold = 0.0
01015 ) const;
01016
01019 bool IsPointInside (
01020 const DPOINT2D& point
01021 ) const;
01022
01024 bool IsRectangle (
01025 ) const { return (m_IsRectangle); }
01026
01030 ERRVALUE NormalizeToCRS (
01031 );
01032
01034 void RemoveIslands ();
01035
01037 void Reverse ();
01038
01042 void SetCoordRefSys (
01043 const SPATREF::COORDREFSYS& CoordSysRef
01044 ) { m_CoordRefSys = CoordSysRef; }
01045
01047 void SetDimension (
01048 DIMENSION dim
01049 );
01050
01053 void SetOrientation (
01054 ORIENTATION Orientation
01055 );
01056
01058 void SetZRange (
01059 const DOUBLE_RANGE& range
01060 );
01061
01063 ERRVALUE Subtract (
01064 const DRECT2D& Rect
01065 );
01066
01068 ERRVALUE Subtract (
01069 const POLYLINE& PolyLine
01070 );
01071
01073 ERRVALUE Subtract (
01074 const SUBREGION2D& SubRegion
01075 );
01076
01078 ERRVALUE Subtract (
01079 const REGION2D& RegionB
01080 );
01081
01084 ERRVALUE Subtract (
01085 const REGION2D& RegionA,
01086 const REGION2D& RegionB
01087 );
01088
01090 ERRVALUE SubtractValidated (
01091 const POLYLINE& PolyLine
01092 );
01093
01096 bool TestLine (
01097 const POLYLINE& PolyLine,
01098 TESTCRITERIA TestCriteria
01099 ) const;
01100
01103 bool TestPoint (
01104 const DPOINT2D& Point,
01105 TESTCRITERIA TestCriteria
01106 ) const;
01107
01110 bool TestPolygon (
01111 const POLYLINE& PolyLine,
01112 TESTCRITERIA TestCriteria
01113 ) const;
01114
01117 bool TestSubRegion (
01118 const SUBREGION2D& SubRegion,
01119 TESTCRITERIA TestCriteria
01120 ) const;
01121
01124 bool TestRegion (
01125 const REGION2D& Region,
01126 TESTCRITERIA TestCriteria
01127 ) const;
01128
01130 ERRVALUE Union (
01131 const DRECT2D& Rect
01132 );
01133
01135 ERRVALUE Union (
01136 const POLYLINE& PolyLine
01137 );
01138
01140 ERRVALUE Union (
01141 const SUBREGION2D& SubRegion
01142 );
01143
01146 ERRVALUE Union (
01147 const REGION2D& RegionA,
01148 const REGION2D& RegionB
01149 );
01150
01152 ERRVALUE Union (
01153 const REGION2D& RegionB
01154 );
01155
01157 ERRVALUE UnionValidated (
01158 const POLYLINE& PolyLine
01159 );
01160
01161 private:
01162 #ifndef GENERATING_DOXYGEN_OUTPUT
01163
01164 SUBREGIONLIST m_SubList;
01165 POLYLINELIST m_LineList;
01166 POLYLINE m_PointList;
01167 DRECT3D m_Extents;
01168 SPATREF::COORDREFSYS m_CoordRefSys;
01169 bool m_IsRectangle;
01170
01171 void AppendDisjointRegion (const REGION2D& rhs);
01172 ERRVALUE ComputeBuffer (const double Distance, REGION2D& Buffer) const;
01173 bool UnionRectangle (const DRECT2D& Rect);
01174 void UpdateExtentsRect ();
01175
01176 class INTERSECTREGION;
01177 friend class INTERSECTREGION;
01178 friend class RVC::VECTOR;
01179 friend class RVC::REGION;
01180 friend class RVC::CAD;
01181 friend class RVC::REGIONHANDLE;
01182 friend class BINARYTOREGION2D;
01183 friend class SERIALIZER;
01184 #endif // GENERATING_DOXYGEN_OUTPUT
01185 };
01186
01187 #undef GEOMLIBCLASSEXPORT
01188
01189 #endif // INC_MI32_REGION2D_H
01190