00001
00075 #ifndef INC_MI32_POLYLINE_H
00076 #define INC_MI32_POLYLINE_H
00077
00078 #ifndef INC_MI32_DOUBLEAR_H
00079 #include <mi32/doublear.h>
00080 #endif
00081
00082 #ifndef INC_MI32_SIMPLEAR_H
00083 #include <mi32/simplear.h>
00084 #endif
00085
00086 #ifndef INC_MI32_RANGE_H
00087 #include <mi32/range.h>
00088 #endif
00089
00090 #ifndef INC_MI32_RECT_H
00091 #include <mi32/rect.h>
00092 #endif
00093
00094 #ifndef INC_MI32_MILIST_H
00095 #include <mi32/milist.h>
00096 #endif
00097
00098 #ifndef INC_MI32_DELEGATE_H
00099 #include <mi32/delegate.h>
00100 #endif
00101
00102
00103 #ifdef GEOMDLL
00104 #define GEOMLIBEXPORT MI_DLLEXPORT
00105 #define GEOMLIBCLASSEXPORT MI_DLLCLASSEXPORT
00106 #else
00107 #define GEOMLIBEXPORT MI_DLLIMPORT
00108 #define GEOMLIBCLASSEXPORT MI_DLLCLASSIMPORT
00109 #endif
00110
00111
00112 #ifndef GENERATING_DOXYGEN_OUTPUT
00113
00114 class BITSET_UNOWNED;
00115 class MISTRING;
00116 class POLYLINELIST;
00117 class TRANS2D_AFFINE;
00118 class TRANS2D_MAPGEN;
00119 class TRANS3D;
00120 class XMLNODE;
00121 namespace SPATREF {
00122 class COORDOP;
00123 }
00124 #endif
00125
00126
00127 struct DTRIANGLE2D {
00128 DPOINT2D p1;
00129 DPOINT2D p2;
00130 DPOINT2D p3;
00131 };
00132
00133 enum CLIPMODE {
00134 CLIPMODE_Inside = 0,
00135 CLIPMODE_Outside = 1
00136 };
00137
00138 enum TESTCRITERIA {
00139 TESTCRITERIA_FullOutside = 0,
00140 TESTCRITERIA_PartOutside = 1,
00141 TESTCRITERIA_FullInside = 2,
00142 TESTCRITERIA_PartInside = 3
00143 };
00144
00145
00146
00154
00155
00156 class GEOMLIBCLASSEXPORT POLYLINE {
00157 public:
00158
00160 enum BUFFERSIDE {
00161 BUFFERSIDE_In = 1,
00162 BUFFERSIDE_Out = 2,
00163 BUFFERSIDE_Both = 3
00164 };
00165
00167 enum COMPRESULT {
00168 COMPRESULT_Outside = 1,
00169 COMPRESULT_Inside,
00170 COMPRESULT_Intersect,
00171 COMPRESULT_Overlap
00172 };
00173
00175 enum COMBINERESULT {
00176 COMBINERESULT_Disjoint = 1,
00177 COMBINERESULT_OperInsideSrc = 2,
00178 COMBINERESULT_SrcInsideOper = 3,
00179 COMBINERESULT_Equal = 4,
00180 COMBINERESULT_Intersect = 5,
00181
00182 COMBINERESULT_ClipOutside = COMBINERESULT_Disjoint,
00183 COMBINERESULT_ClipInside = COMBINERESULT_OperInsideSrc,
00184 COMBINERESULT_SrcInside = COMBINERESULT_SrcInsideOper
00185 };
00186
00187 enum EXTRACT {
00188 EXTRACT_StartPoint = 1,
00189 EXTRACT_CenterPoint,
00190 EXTRACT_EndPoint
00191 };
00192
00193 enum JOINTYPE {
00194 JOINTYPE_Miter = 0,
00195 JOINTYPE_Round,
00196 JOINTYPE_Bevel
00197 };
00198
00199 enum SPLINEFLAGS {
00200 SPLINEFLAG_None = 0x0000,
00201 SPLINEFLAG_DontMoveEnds = 0x0001,
00202 SPLINEFLAG_UseMinDistance = 0x0002,
00203 SPLINEFLAG_TreatAsClosed = 0x0004
00204 };
00205
00206 enum SPLINE {
00207 SPLINE_NoSpline = 0,
00208 SPLINE_Cubic,
00209 SPLINE_Quadratic,
00210 SPLINE_Bezier
00211 };
00212
00213 enum THINMETHOD {
00214 THINMETHOD_MinRatio = 1,
00215 THINMETHOD_Minimum,
00216 THINMETHOD_Douglas
00217 };
00218
00219 class ITERATOR;
00220
00222 class CONST_ITERATOR {
00223 public:
00224
00226 CONST_ITERATOR (
00227 ) :
00228 m_Index(0),
00229 m_PolyLine(0)
00230 { }
00231
00233 CONST_ITERATOR (
00234 INT32 index,
00235 const POLYLINE*const PolyLine
00236 ) :
00237 m_Index(index),
00238 m_PolyLine(PolyLine)
00239 { }
00240
00242 CONST_ITERATOR (
00243 const CONST_ITERATOR& rhs
00244 ) :
00245 m_Index(rhs.m_Index),
00246 m_PolyLine(rhs.m_PolyLine)
00247 { }
00248
00250 CONST_ITERATOR (
00251 const ITERATOR& rhs
00252 ) :
00253 m_Index(rhs.m_Index),
00254 m_PolyLine(rhs.m_PolyLine)
00255 { }
00256
00258 CONST_ITERATOR& operator= (
00259 const CONST_ITERATOR& rhs
00260 ) {
00261 if (this != &rhs) {
00262 m_Index = rhs.m_Index;
00263 m_PolyLine = rhs.m_PolyLine;
00264 }
00265 return (*this);
00266 }
00267
00269 const DPOINT2D& operator* (
00270 ) const { return (m_PolyLine->GetVertex(m_Index)); }
00271
00273 const DPOINT2D* operator-> (
00274 ) const { return (&**this); }
00275
00277 CONST_ITERATOR& operator++ (
00278 ) {
00279 ++m_Index;
00280 return (*this);
00281 }
00282
00284 CONST_ITERATOR operator++(int
00285 ) {
00286 CONST_ITERATOR temp = *this;
00287 ++*this;
00288 return (temp);
00289 }
00290
00292 CONST_ITERATOR& operator-- (
00293 ) {
00294 --m_Index;
00295 return (*this);
00296 }
00297
00299 CONST_ITERATOR operator--(int
00300 ) {
00301 CONST_ITERATOR temp = *this;
00302 --*this;
00303 return (temp);
00304 }
00305
00307 bool operator== (
00308 const CONST_ITERATOR& rhs
00309 ) const { return (m_Index == rhs.m_Index && m_PolyLine == rhs.m_PolyLine); }
00310
00312 bool operator!= (
00313 const CONST_ITERATOR& rhs
00314 ) const { return (!(*this == rhs)); }
00315
00317 INT32 GetIndex (
00318 ) const { return (m_Index); }
00319
00320 protected:
00321 #ifndef GENERATING_DOXYGEN_OUTPUT
00322 INT32 m_Index;
00323 const POLYLINE* m_PolyLine;
00324 #endif
00325 };
00326
00328 class ITERATOR {
00329 public:
00330
00332 ITERATOR (
00333 ) :
00334 m_Index(0),
00335 m_PolyLine(0)
00336 { }
00337
00339 ITERATOR (
00340 INT32 index,
00341 POLYLINE* PolyLine
00342 ) :
00343 m_Index(index),
00344 m_PolyLine(PolyLine)
00345 { }
00346
00348 ITERATOR (
00349 const ITERATOR& rhs
00350 ) :
00351 m_Index(rhs.m_Index),
00352 m_PolyLine(rhs.m_PolyLine)
00353 { }
00354
00356 ITERATOR& operator= (
00357 const ITERATOR& rhs
00358 ) {
00359 if (this != &rhs) {
00360 m_Index = rhs.m_Index;
00361 m_PolyLine = rhs.m_PolyLine;
00362 }
00363 return (*this);
00364 }
00365
00367 DPOINT2D& operator* (
00368 ) const { return (m_PolyLine->GetVertexRef(m_Index)); }
00369
00371 DPOINT2D* operator-> (
00372 ) const { return (&**this); }
00373
00375 ITERATOR& operator++ (
00376 ) {
00377 m_Index ++;
00378 return (*this);
00379 }
00380
00382 ITERATOR operator++(int
00383 ) {
00384 ITERATOR temp = *this;
00385 ++*this;
00386 return (temp);
00387 }
00388
00390 ITERATOR& operator-- (
00391 ) {
00392 m_Index --;
00393 return (*this);
00394 }
00395
00397 ITERATOR operator--(int
00398 ) {
00399 ITERATOR temp = *this;
00400 --*this;
00401 return (temp);
00402 }
00403
00405 bool operator== (
00406 const ITERATOR& rhs
00407 ) const { return (m_Index == rhs.m_Index && m_PolyLine == rhs.m_PolyLine); }
00408
00410 bool operator!= (
00411 const ITERATOR& rhs
00412 ) const { return (!(*this == rhs)); }
00413
00414 protected:
00415 #ifndef GENERATING_DOXYGEN_OUTPUT
00416 INT32 m_Index;
00417 POLYLINE *m_PolyLine;
00418 friend class CONST_ITERATOR;
00419 #endif
00420 };
00421
00422 class SECTION {
00423 public:
00424 SECTION (
00425 const DRECT2D& Extents,
00426 INT32 StartVertex,
00427 INT32 EndVertex
00428 ) :
00429 m_Extents(Extents),
00430 m_VertexRange(StartVertex, EndVertex)
00431 { }
00432
00433 ~SECTION (
00434 ) { }
00435
00436 const DRECT2D& GetExtents (
00437 ) const { return (m_Extents); }
00438
00439 const INT32_RANGE& GetVertexRange (
00440 ) const { return (m_VertexRange); }
00441
00442 private:
00443 #ifndef GENERATING_DOXYGEN_OUTPUT
00444 DRECT2D m_Extents;
00445 INT32_RANGE m_VertexRange;
00446
00447 friend class POLYLINE;
00448 #endif
00449 };
00450 typedef DOUBLE_ARRAY<SECTION> SECTIONARRAY;
00451
00452 #ifndef GENERATING_DOXYGEN_OUTPUT
00453 class CLIP;
00454 class INTERSECTINFO;
00455 class SECTIONS;
00456 class SPLIT;
00457 class STRIPS;
00458 #endif
00459
00461 POLYLINE ();
00462
00464 explicit POLYLINE (
00465 bool closed,
00466 DIMENSION dimension = DIMENSION_2D,
00467 double ZValue = 0.0,
00468 UINT32 ReservePoints = 1
00469 );
00470
00473 explicit POLYLINE (
00474 const DRECT2D& rect,
00475 double ZValue = 0.0
00476 );
00477
00480 explicit POLYLINE (
00481 const DRECT3D& rect
00482 );
00483
00485 explicit POLYLINE (
00486 const DPOLYGON& dpoly,
00487 bool closed = false,
00488 DIMENSION dimension = DIMENSION_2D,
00489 double ZValue = 0.0
00490 );
00491
00493 POLYLINE (
00494 const DPOINT2D* pts,
00495 INT32 NumPoints,
00496 bool closed = false,
00497 DIMENSION dimension = DIMENSION_2D,
00498 double ZValue = 0.0
00499 );
00500
00503 explicit POLYLINE (
00504 DOUBLE_ARRAY<double>& rhs,
00505 bool closed = false,
00506 DIMENSION dimension = DIMENSION_2D,
00507 double ZValue = 0.0
00508 );
00509
00511 explicit POLYLINE (
00512 const DOUBLE_ARRAY<DPOINT2D>& rhs,
00513 bool closed = false,
00514 double ZValue = 0.0
00515 );
00516
00518 explicit POLYLINE (
00519 const SIMPLE_ARRAY<LPOINT2D>& rhs,
00520 bool closed = false,
00521 double ZValue = 0.0
00522 );
00523
00525 explicit POLYLINE (
00526 const LPOINT2D* points,
00527 INT32 NumPoints,
00528 bool closed = false,
00529 double ZValue = 0.0
00530 );
00531
00533 explicit POLYLINE (
00534 const DOUBLE_ARRAY<DPOINT3D>& rhs,
00535 bool closed = false
00536 );
00537
00540 POLYLINE (
00541 const POLYLINE& rhs
00542 );
00543
00546 POLYLINE (
00547 const POLYLINE& rhs,
00548 INT32 StartVertex,
00549 INT32 EndVertex
00550 );
00551
00553 ~POLYLINE (
00554 );
00555
00560 POLYLINE& operator= (
00561 const POLYLINE& rhs
00562 );
00563
00566 POLYLINE& operator+= (
00567 const POLYLINE& rhs
00568 );
00569
00571 ERRVALUE AddVertex (
00572 const DPOINT2D& point,
00573 INT32 index = -1
00574 );
00575
00577 ERRVALUE AddVertex (
00578 const DPOINT3D& point,
00579 INT32 index = -1
00580 );
00581
00584 ERRVALUE Append (
00585 const POLYLINE& rhs,
00586 bool RemovePoints = true
00587 );
00588
00589
00590 void ApplyZScale (
00591 double zscale
00592 );
00593
00595 ERRVALUE Assign (
00596 const DPOLYGON& dpoly,
00597 bool closed = false,
00598 DIMENSION dimension = DIMENSION_2D,
00599 double ZValue = 0.0
00600 );
00601
00603 ERRVALUE Assign (
00604 const DPOINT2D* pts,
00605 INT32 NumPoints,
00606 bool closed = false,
00607 DIMENSION dimension = DIMENSION_2D,
00608 double ZValue = 0.0
00609 );
00610
00612 ERRVALUE Assign (
00613 const SIMPLE_ARRAY<LPOINT2D>& rhs,
00614 bool closed = false,
00615 double ZValue = 0.0
00616 );
00617
00619 ERRVALUE Assign (
00620 const LPOINT2D* rhs,
00621 int NumPoints,
00622 bool closed = false,
00623 double ZValue = 0.0
00624 );
00625
00627 ERRVALUE Assign (
00628 const DOUBLE_ARRAY<DPOINT2D>& rhs,
00629 bool closed = false,
00630 double ZValue = 0.0
00631 );
00632
00634 ERRVALUE Assign (
00635 const DOUBLE_ARRAY<DPOINT3D>& rhs,
00636 bool closed = false
00637 );
00638
00640 ERRVALUE Assign (
00641 const DRECT2D& rect,
00642 double ZValue = 0.0
00643 );
00644
00646 ERRVALUE Assign (
00647 const DRECT3D& rect
00648 );
00649
00651 ERRVALUE AssignFromXML (
00652 const XMLNODE *topnode
00653 );
00654
00657 void Attach (
00658 MIDOUBLEARRAY& rhs,
00659 INT32 NumPoints,
00660 bool closed = false,
00661 DIMENSION dimension = DIMENSION_2D,
00662 double ZValue = 0.0
00663 );
00664
00666 CONST_ITERATOR Begin (
00667 ) const { return (CONST_ITERATOR(0, this)); }
00668
00670 ITERATOR Begin (
00671 ) { return (ITERATOR(0, this)); }
00672
00674 void Clear (
00675 );
00676
00678 void ClearOptimizations (
00679 );
00680
00682 void ClearPoints (
00683 INT32 StartPosn = 0,
00684 INT32 EndPosn = INT32_MAX
00685 );
00686
00689 int Clip (
00690 const DRECT2D& ClipRect,
00691 DELEGATE_ERRVALUE_POLYLINE DelegateOnClip,
00692 CLIPMODE ClipMode = CLIPMODE_Inside
00693 );
00694
00697 int Clip (
00698 const DRECT2D& ClipRect,
00699 CLIP& ClipTarget,
00700 CLIPMODE ClipMode = CLIPMODE_Inside
00701 );
00702
00706 COMPRESULT CompareLineToLine (
00707 const POLYLINE& OtherLine
00708 ) const;
00709
00713 COMPRESULT CompareLineToPolygon (
00714 const POLYLINE& Polygon
00715 ) const;
00716
00720 COMPRESULT CompareLineToPolygon (
00721 const DRECT2D& rect
00722 ) const;
00723
00727 COMPRESULT ComparePolygonToPolygon (
00728 const POLYLINE& OtherPoly
00729 ) const;
00730
00733 double ComputeAngle (
00734 ) const;
00735
00739 double ComputeArea (
00740 ) const {
00741 double area;
00742 ComputeStats(&area, 0);
00743 return (area);
00744 }
00745
00747 ERRVALUE ComputeBuffer (
00748 const double BufferDistance,
00749 POLYLINELIST& BufferLineList,
00750 const BUFFERSIDE BufferSide = BUFFERSIDE_Both
00751 ) const;
00752
00755 void ComputeCentroid (
00756 DPOINT2D& cent
00757 ) const;
00758
00761 void ComputeCentroid (
00762 DPOINT3D& cent
00763 ) const;
00764
00768 double ComputeDistance (
00769 const POLYLINE& OtherLine,
00770 bool ExtentsOverlap = true
00771 ) const;
00772
00775 bool ComputeDistPointOnLine (
00776 double Distance,
00777 DPOINT3D& NewPoint,
00778 bool DistanceFromStart = true
00779 ) const;
00780
00783 INT32 ComputeDistPointAndVertexOnLine (
00784 double Distance,
00785 DPOINT3D& NewPoint,
00786 bool DistanceFromStart = true
00787 ) const;
00788
00791 void ComputeExtents (
00792 DRECT3D& rect
00793 ) const;
00794
00796 void ComputeExtents (
00797 DRECT3D& rect,
00798 INT32 StartVertex,
00799 INT32 EndVertex
00800 ) const;
00801
00804 void ComputeExtents (
00805 DRECT2D& rect
00806 ) const;
00807
00809 void ComputeExtents (
00810 DRECT2D& rect,
00811 INT32 StartVertex,
00812 INT32 EndVertex
00813 ) const;
00814
00816 void ComputeInteriorPoint (
00817 DPOINT3D& pt
00818 ) const;
00819
00822 double ComputeLength (
00823 ) const;
00824
00827 double ComputeLength (
00828 const DPOINT3D& point
00829 ) const;
00830
00833 double ComputeLongestSegmentLength (
00834 ) const;
00835
00839 double ComputeMaxDimension (
00840 ) const;
00841
00843 void ComputeMidPoint (
00844 DPOINT3D& MidPoint
00845 ) const;
00846
00850 ERRVALUE ComputeOffset (
00851 double OffsetDistance,
00852 POLYLINE& OffsetLine,
00853 JOINTYPE JoinType = JOINTYPE_Miter
00854 ) const;
00855
00859 ERRVALUE ComputeOffset (
00860 double StartOffsetDistance,
00861 double EndOffsetDistance,
00862 POLYLINE& OffsetLine,
00863 JOINTYPE JoinType = JOINTYPE_Miter
00864 ) const;
00865
00869 ERRVALUE ComputeOffset (
00870 const SIMPLE_ARRAY<double>& OffsetDistance,
00871 POLYLINE& OffsetLine,
00872 JOINTYPE JoinType = JOINTYPE_Miter
00873 ) const;
00874
00878 ORIENTATION ComputeOrientation (
00879 ) const { return (ComputeStats(0, 0)); }
00880
00883 INT32 ComputePercentPointOnLine (
00884 double Percent,
00885 DPOINT3D& NewPoint,
00886 bool DistanceFromStart = true
00887 ) const;
00888
00892 ORIENTATION ComputeStats (
00893 double *const area,
00894 DPOINT2D *const centroid
00895 ) const;
00896
00901 ERRVALUE Conflate (
00902 double thresh,
00903 bool& LineChanged
00904 );
00905
00910 ERRVALUE Conflate (
00911 POLYLINELIST& LineList,
00912 double thresh,
00913 bool& LineChanged,
00914 BITSET_UNOWNED& LineListSet
00915 );
00916
00918 void ConvertForward (
00919 const TRANS2D_AFFINE& taf
00920 );
00921
00923 ERRVALUE ConvertForward (
00924 const TRANS2D_MAPGEN& tmg
00925 );
00926
00928 ERRVALUE ConvertForwardDense (
00929 const TRANS2D_MAPGEN& tmg
00930 );
00931
00933 void ConvertForward (
00934 const TRANS3D& t3d
00935 );
00936
00938 ERRVALUE ConvertForward (
00939 const SPATREF::COORDOP& Op
00940 );
00941
00943 ERRVALUE ConvertForwardDense (
00944 const SPATREF::COORDOP& Op,
00945 double tolerance
00946 );
00947
00949 void ConvertInverse (
00950 const TRANS2D_AFFINE& taf
00951 );
00952
00954 ERRVALUE ConvertInverse (
00955 const TRANS2D_MAPGEN& tmg
00956 );
00957
00959 ERRVALUE ConvertInverseDense (
00960 const TRANS2D_MAPGEN& tmg
00961 );
00962
00964 void ConvertInverse (
00965 const TRANS3D& t3d
00966 );
00967
00969 ERRVALUE ConvertReverse (
00970 const SPATREF::COORDOP& Op
00971 );
00972
00974 ERRVALUE ConvertReverseDense (
00975 const SPATREF::COORDOP& Op,
00976 double tolerance
00977 );
00978
00980 ERRVALUE ConvertToLong (
00981 SIMPLE_ARRAY<LPOINT2D>& PointArray
00982 ) const;
00983
00986 INT32 ConvertToLong (
00987 LPOINT2D *PointArray
00988 ) const;
00989
00991 ERRVALUE ConvertToLongFloor (
00992 SIMPLE_ARRAY<LPOINT2D>& PointArray
00993 ) const;
00994
00997 INT32 ConvertToLongFloor (
00998 LPOINT2D *PointArray
00999 ) const;
01000
01003 INT32 ConvertToLongFloor (
01004 LPOINT2D *PointArray,
01005 const DPOINT2D& scale,
01006 const DPOINT2D& offset
01007 ) const;
01008
01010 ERRVALUE ConvertToLongNearInt (
01011 SIMPLE_ARRAY<LPOINT2D>& PointArray
01012 ) const;
01013
01016 INT32 ConvertToLongNearInt (
01017 LPOINT2D *PointArray
01018 ) const;
01019
01021 ERRVALUE ConvertToLongRound (
01022 SIMPLE_ARRAY<LPOINT2D>& PointArray
01023 ) const;
01024
01027 INT32 ConvertToLongRound (
01028 LPOINT2D *PointArray
01029 ) const;
01030
01032 ERRVALUE ConvertToLongRoundKeepDups (
01033 SIMPLE_ARRAY<LPOINT2D>& PointArray
01034 ) const;
01035
01039 void DeleteVertex (
01040 int index
01041 );
01042
01044 void Detach (
01045 MIDOUBLEARRAY& rhs
01046 );
01047
01049 void DetachBuffer (
01050 MIDOUBLEARRAY& rhs
01051 );
01052
01056 void DumpCoords (
01057 MISTRING& result,
01058 int indent,
01059 bool maxprec = false
01060 ) const;
01061
01063 ITERATOR End (
01064 ) { return (ITERATOR(m_NumPoints, this)); }
01065
01067 CONST_ITERATOR End (
01068 ) const { return (CONST_ITERATOR(m_NumPoints, this)); }
01069
01072 void Exchange (
01073 POLYLINE& other
01074 );
01075
01079 ERRVALUE ExclusiveUnion (
01080 POLYLINE& OperPoly,
01081 POLYLINELIST& PolyLineList,
01082 COMBINERESULT& CombineResult
01083 );
01084
01086 void Extract (
01087 POLYLINE& NewLine,
01088 const DPOINT3D& BasePoint,
01089 double Distance,
01090 EXTRACT ExtractPoint,
01091 bool ExtrudePastEnds = false
01092 ) const;
01093
01095 void Extract (
01096 POLYLINE& NewLine,
01097 const DPOINT3D& StartPoint,
01098 const DPOINT3D& EndPoint
01099 ) const;
01100
01102 void Extract (
01103 INT32 StartPosn,
01104 INT32 NumPoints,
01105 POLYLINE& ExtractLine
01106 ) const;
01107
01110 double FindClosestPoint (
01111 const DPOINT2D& point,
01112 DPOINT2D& retpt
01113 ) const;
01114
01118 double FindClosestPoint (
01119 const DPOINT3D& point,
01120 DPOINT3D& retpt
01121 ) const;
01122
01128 double FindClosestPoint (
01129 const DPOINT3D& point,
01130 double MaximumDistance,
01131 DPOINT3D& retpt,
01132 INT32& Vertex
01133 ) const;
01134
01137 int FindClosestSegment (
01138 const DPOINT2D& point,
01139 double *distance = 0
01140 ) const;
01141
01144 double FindClosestVertex (
01145 const DPOINT2D& point,
01146 INT32& index
01147 ) const;
01148
01151 int FindClosestVertex (
01152 const DPOINT2D& point,
01153 double *distance = 0
01154 ) const;
01155
01159 double FindClosestVertex (
01160 const DPOINT3D& point,
01161 INT32& index
01162 ) const;
01163
01166 void GenerateExtentOptimization (
01167 DRECT2D& Extents
01168 ) const;
01169
01172 void GenerateExtentOptimization (
01173 ) const;
01174
01178 ERRVALUE GenerateSectionOptimization (
01179 SECTIONS*& Sections,
01180 INT32 NumVertices = 64
01181 ) const;
01182
01186 void GenerateSectionOptimization (
01187 INT32 NumVertices = 64
01188 ) const;
01189
01192 ERRVALUE GenerateStripOptimization (
01193 STRIPS*& Strips,
01194 INT32 NumDivs = 0
01195 ) const;
01196
01199 ERRVALUE GenerateStripOptimization (
01200 INT32 NumDivs = 0
01201 ) const;
01202
01204 DIMENSION GetDimension (
01205 ) const { return ((m_NumDim == 2) ? DIMENSION_2D : DIMENSION_3D); }
01206
01209 const DRECT2D* GetExtentsIfKnown () const;
01210
01213 INT32 GetNumPoints (
01214 ) const { return (m_NumPoints); }
01215
01216 #ifndef GENERATING_DOXYGEN_OUTPUT
01217 double* GetPointer (
01218 int index = 0
01219 ) { return (m_Points + GetOffset(index)); }
01220
01221 const double* GetPointer (
01222 int index = 0
01223 ) const { return (m_Points + GetOffset(index)); }
01224 #endif // GENERATING_DOXYGEN_OUTPUT
01225
01229 void GetTestPoint (
01230 DPOINT3D& pt
01231 ) const;
01232
01235 const DPOINT2D& GetVertex (
01236 INT32 index
01237 ) const { return (*reinterpret_cast<const DPOINT2D*>(GetPointer(index))); }
01238
01240 void GetVertex3D (
01241 INT32 index,
01242 DPOINT3D& pt
01243 ) const {
01244 const double *p = GetPointer(index);
01245 pt.x = p[0];
01246 pt.y = p[1];
01247 pt.z = (m_NumDim == 2) ? m_ZValue : p[2];
01248 return;
01249 }
01250
01253 double GetVertexX (
01254 INT32 index
01255 ) const { return (GetPointer(index)[0]); }
01256
01259 double GetVertexY (
01260 INT32 index
01261 ) const { return (GetPointer(index)[1]); }
01262
01265 double GetVertexZ (
01266 INT32 index
01267 ) const { return ((m_NumDim == 2) ? (m_ZValue) : GetPointer(index)[2]); }
01268
01270 ERRVALUE GetVertices (
01271 DOUBLE_ARRAY<DPOINT2D>& vertices
01272 ) const;
01273
01275 ERRVALUE GetVertices (
01276 DOUBLE_ARRAY<DPOINT3D>& vertices
01277 ) const;
01278
01280 ERRVALUE GetVertices (
01281 DPOLYGON& dpoly
01282 ) const;
01283
01285 XMLNODE* GetXML (
01286 XMLNODE *parentnode,
01287 const char *nodename = 0
01288 ) const;
01289
01291 double GetZValue (
01292 ) const { return (m_ZValue); }
01293
01295 bool HasSectionOptimization (
01296 ) const;
01297
01299 bool HasStripOptimization (
01300 ) const;
01301
01306 int Intersect (
01307 POLYLINE& OperPoly,
01308 POLYLINELIST& PolyLineList,
01309 COMBINERESULT& CombineResult
01310 );
01311
01313 void IntersectClean (
01314 INTERSECTINFO& IntsInfo
01315 ) const;
01316
01319 ERRVALUE IntersectSearch (
01320 INTERSECTINFO& IntsInfo,
01321 double threshold
01322 ) const;
01323
01327 ERRVALUE IntersectSearch (
01328 INTERSECTINFO& IntsInfo,
01329 const POLYLINE& OtherLine,
01330 INTERSECTINFO* OtherIntsInfo,
01331 double threshold
01332 ) const;
01333
01335 ERRVALUE IntersectSplitLine (
01336 INTERSECTINFO& IntsInfo,
01337 SPLIT& SplitInfo,
01338 double threshold,
01339 bool CallBadSegment = false
01340 ) const;
01341
01344 bool IsClosed (
01345 ) const { return (m_LineClosed); }
01346
01350 bool IsEqual (
01351 const POLYLINE& rhs
01352 ) const;
01353
01357 bool IsEquivalentTo (
01358 const POLYLINE& rhs,
01359 double threshold = 0.0
01360 ) const;
01361
01365 bool IsPointInside (
01366 const DPOINT2D& pt
01367 ) const;
01368
01370 bool IsRectangle (
01371 ) const;
01372
01382 void MoveVertex (
01383 int index,
01384 const DPOINT2D& delta,
01385 int FixedVertex1 = -1,
01386 int FixedVertex2 = -1
01387 );
01388
01391 bool RemoveColinearVertices (
01392 double thresh = 0.0,
01393 bool KeepEndPoints = false
01394 );
01395
01398 void RemoveDuplicates (
01399 double thresh = 0.0,
01400 bool KeepEndPoints = false
01401 );
01402
01405 bool RemoveDuplicateVertices (
01406 double thresh = 0.0
01407 );
01408
01410 ERRVALUE Replace (
01411 INT32 StartVertex,
01412 INT32 EndVertex,
01413 const POLYLINE& RepLine,
01414 INT32 RepLineStartVertex = 0,
01415 INT32 RepLineEndVertex = INT32_MAX
01416 );
01417
01421 ERRVALUE Reserve (
01422 INT32 NumPoints
01423 );
01424
01427 void Reverse (
01428 );
01429
01432 void SetClosed (
01433 bool closed
01434 );
01435
01437 ERRVALUE SetDimension (
01438 DIMENSION dimension
01439 );
01440
01443 void SetOrientation (
01444 ORIENTATION Orientation
01445 );
01446
01450 void SetPrecision (
01451 int Precision
01452 );
01453
01456 void SetupExtentOptimization (
01457 const DRECT2D& Extents
01458 ) const;
01459
01462 void SetupOrientationOptimization (
01463 ORIENTATION Orientation
01464 ) const;
01465
01469 void SetupSectionOptimization (
01470 const SECTIONS& Sections
01471 ) const;
01472
01475 void SetupStripOptimization (
01476 const STRIPS& Strips
01477 ) const;
01478
01480 void SetVertex (
01481 INT32 index,
01482 const DPOINT2D& pt
01483 );
01484
01486 void SetVertex (
01487 INT32 index,
01488 const DPOINT3D& pt
01489 );
01490
01492 void SetVertexX (
01493 INT32 index,
01494 double x
01495 );
01496
01498 void SetVertexY (
01499 INT32 index,
01500 double y
01501 );
01502
01504 void SetVertexZ (
01505 INT32 index,
01506 double z
01507 );
01508
01510 void SetZValue (
01511 double ZValue
01512 ) {m_ZValue = ZValue; }
01513
01515 void Spline (
01516 SPLINE SplineType,
01517 INT32 NumKnots,
01518 double tolerance,
01519 SPLINEFLAGS flags = SPLINEFLAG_None
01520 );
01521
01523 void SplineZ (
01524 SPLINE SplineType,
01525 INT32 NumKnots,
01526 double tolerance,
01527 SPLINEFLAGS flags = SPLINEFLAG_None
01528 );
01529
01531 void Straighten (
01532 );
01533
01538 int Subtract (
01539 POLYLINE& OperPoly,
01540 POLYLINELIST& PolyLineList,
01541 COMBINERESULT& CombineResult
01542 );
01543
01545 void Thin (
01546 THINMETHOD Method,
01547 double Factor
01548 );
01549
01551 void TransferOwnerFrom (
01552 DOUBLE_ARRAY<DPOINT2D>& rhs
01553 );
01554
01556 void TransferOwnerFrom (
01557 DOUBLE_ARRAY<DPOINT3D>& rhs
01558 );
01559
01561 void TransferOwnerTo (
01562 DOUBLE_ARRAY<DPOINT2D>& rhs
01563 );
01564
01566 void TransferOwnerTo (
01567 DOUBLE_ARRAY<DPOINT3D>& rhs
01568 );
01569
01574 int Union (
01575 POLYLINE& OperPoly,
01576 POLYLINELIST& PolyLineList,
01577 COMBINERESULT& CombineResult
01578 );
01579
01582 int ValidatePolygon (
01583 ) const;
01584
01587 int ValidatePolygon (
01588 DELEGATE_ERRVALUE_POLYLINE DelegateOnValidated
01589 ) const;
01590
01593 int ValidatePolygon (
01594 CLIP& ClipTarget
01595 ) const;
01596
01597 private:
01598 #ifndef GENERATING_DOXYGEN_OUTPUT
01599 POLYLINE (const POLYLINE& rhs, const SECTION& Section);
01600
01601 void AddJoinPoints (const DPOINT2D& BasePt, double OffsetDistance, const DPOINT3D& op1, const DPOINT3D& op2, JOINTYPE JoinType);
01602 ERRVALUE AddVertexNoCopy (const DPOINT3D& point, INT32 index);
01607 int Combine (const POLYLINE& OperPoly, POLYLINELIST& PolyLineList, COMBINERESULT& CombineResult) const;
01608 void ComputeExtentsRaw (DRECT2D& rect) const {ComputeExtentsRaw(rect, 0, m_NumPoints-1); }
01609 void ComputeExtentsRaw (DRECT2D& rect, INT32 StartVertex, INT32 EndVertex) const;
01610 double ComputeLengthRaw () const;
01611
01612 void ComputeSegment (
01613 INT32 Index1,
01614 INT32 Index2,
01615 INT32 Index3,
01616 INT32 Index4,
01617 int NumKnots,
01618 double Tolerance,
01619 bool UseMinDist,
01620 const DOUBLE_ARRAY<double>& T,
01621 POLYLINE& TempLine
01622 ) const;
01623
01624 void ComputeSegmentQ (
01625 INT32 Index1,
01626 INT32 Index2,
01627 INT32 Index3,
01628 int NumKnots,
01629 double Tolerance,
01630 bool UseMinDist,
01631 const DOUBLE_ARRAY<double>& T,
01632 POLYLINE& TempLine
01633 ) const;
01634
01635 bool ComputeSegmentOffset (INT32 PointNum, double StartOffsetDistance, double EndOffsetDistance, DPOINT3D& op0, DPOINT3D& op1) const;
01636 ORIENTATION ComputeStatsRaw (double& area, DPOINT2D& centroid) const;
01637
01638 struct INTPOINT;
01639 ERRVALUE FindIntersections (const POLYLINE& ClipPoly, DOUBLE_ARRAY<INTPOINT>& IntPoints, bool& HasCommonVertex, bool& HasCommonSegment, MISTRING *pStrDebug = 0) const;
01640 void FixStartEndPoints (const DPOINT2D& Start, const DPOINT2D& End, double Tolerance);
01641 INT32 GetOffset (int index) const { return ((m_StartOffset + index) * m_NumDim); }
01643 DPOINT2D& GetVertexRef (INT32 index) { return (*reinterpret_cast<DPOINT2D*>(GetPointer(index))); }
01644
01645 ERRVALUE IntersectSearchRaw (INTERSECTINFO& ThisIntsInfo, const POLYLINE& OtherLine, INTERSECTINFO *pOtherIntsInfo, double threshold, bool ReturnOnTrueCross, bool IgnoreLineEndPoints) const;
01646
01647 ERRVALUE MakeCopy ();
01648 void MoveVertexSub(int index, const DPOINT2D& delta, int fixed);
01649 ERRVALUE Resize (INT32 NewSize);
01650 void ResizeExc (INT32 NewSize);
01651 ERRVALUE ResizeNoCopy (INT32 NewSize);
01652 void SetVertexNoCopy (INT32 index, const DPOINT3D& pt);
01653
01654 static bool TestPoint (const POLYLINE& LHS, const POLYLINE& RHS, const double *lhs, const double *rhs, double threshold);
01655 static bool TestDistance (const POLYLINE& P, const POLYLINE& Q, const double *p1, const double *p2, const double *q1, double threshold);
01656 void ValidateClosure ();
01657
01658 bool m_LineClosed;
01659 double m_ZValue;
01660 int m_NumDim;
01661 INT32 m_NumPoints;
01662 INT32 m_StartOffset;
01663 double *m_Points;
01664
01665 class PRIV;
01666 PRIV *m_Priv;
01667
01668 class OPTIMIZE;
01669 friend class OPTIMIZE;
01670 mutable OPTIMIZE *m_Optimize;
01671
01672 static const UINT32 s_AllocInc;
01673 static const double s_AngleStep;
01674 static const double s_MiterLimit;
01675
01676 friend class POLYLINE::ITERATOR;
01677 friend class POLYLINE::STRIPS;
01678 #endif // GENERATING_DOXYGEN_OUTPUT
01679 };
01680
01681
01682 inline bool operator== (
01683 const POLYLINE& lhs,
01684 const POLYLINE& rhs
01685 ) { return (lhs.IsEqual(rhs)); }
01686
01687 inline bool operator!= (
01688 const POLYLINE& lhs,
01689 const POLYLINE& rhs
01690 ) { return (!lhs.IsEqual(rhs)); }
01691
01692 inline bool operator< (
01693 const POLYLINE& lhs,
01694 const POLYLINE& rhs
01695 ) { return (lhs.GetNumPoints() < rhs.GetNumPoints()); }
01696
01697
01698 class GEOMLIBCLASSEXPORT POLYLINELIST : public MILIST<POLYLINE> { };
01699
01701 class POLYLINE::CLIP {
01702 public:
01703 virtual ERRVALUE OnClip (
01704 const POLYLINE& PolyLine
01705 ) = 0;
01706 ERRVALUE DoClip (
01707 const POLYLINE& PolyLine
01708 ) { return (OnClip(PolyLine)); }
01709 };
01710
01711
01712 #ifndef GENERATING_DOXYGEN_OUTPUT
01713
01714 GEOMLIBEXPORT void IntersectDumpInfo (const POLYLINE::INTERSECTINFO& ints, MISTRING& LogString, INT32 LineNum);
01715
01716 #endif // GENERATING_DOXYGEN_OUTPUT
01717
01719 class POLYLINE::INTERSECTINFO {
01720 public:
01721
01722 struct CROSSPT {
01723 enum FLAGS {
01724 FLAG_KnowIsCross = 0x0001,
01725 FLAG_IsCross = 0x0002,
01726 };
01727 DPOINT3D m_point;
01728 INT32 m_index;
01729 UINT16 m_flags;
01730 UINT8 m_type;
01731 UINT8 m_spare;
01732
01733 CROSSPT (
01734 ) { memset(this, 0, sizeof(*this)); }
01735 };
01736
01737 struct OVERLAP {
01738 DPOINT2D m_start;
01739 DPOINT2D m_end;
01740 INT32 m_index;
01741 #ifndef GENERATING_DOXYGEN_OUTPUT
01742 INT32 m_spare;
01743 #endif // GENERATING_DOXYGEN_OUTPUT
01744
01745 OVERLAP (
01746 ) { memset(this, 0, sizeof(*this)); }
01747 };
01748
01749 INTERSECTINFO (
01750 ) : m_IsCleaned(true) { }
01751
01752 void Clean (
01753 const POLYLINE& PolyLine
01754 );
01755
01756 void Clear (
01757 ) {
01758 m_CrossPts.Clear();
01759 m_Overlaps.Clear();
01760 m_IsCleaned = true;
01761 return;
01762 }
01763
01764 void DumpInfo (
01765 MISTRING& LogString,
01766 INT32 LineNum
01767 ) const { IntersectDumpInfo (*this, LogString, LineNum); }
01768
01769 const SIMPLE_ARRAY<CROSSPT>& GetCrossPoints (
01770 ) const { return (m_CrossPts); }
01771
01772 SIMPLE_ARRAY<CROSSPT>& GetCrossPoints (
01773 ) { return (m_CrossPts); }
01774
01775 INT32 GetNumCrossPoints (
01776 ) const { return (m_CrossPts.GetNumItems()); }
01777
01778 INT32 GetNumOverlaps (
01779 ) const { return (m_Overlaps.GetNumItems()); }
01780
01781 const SIMPLE_ARRAY<OVERLAP>& GetOverlaps (
01782 ) const { return (m_Overlaps); }
01783
01784 SIMPLE_ARRAY<OVERLAP>& GetOverlaps (
01785 ) { return (m_Overlaps); }
01786
01787 bool HasOverlaps (
01788 ) const { return (m_Overlaps.GetNumItems() != 0); }
01789
01790 bool IsCleaned (
01791 ) const { return (m_IsCleaned); }
01792
01793 bool IsEmpty (
01794 ) const { return (m_CrossPts.GetNumItems() == 0); }
01795
01796 void SetCleaned (
01797 bool value = true
01798 ) {m_IsCleaned = value; }
01799
01800 private:
01801 #ifndef GENERATING_DOXYGEN_OUTPUT
01802 SIMPLE_ARRAY<CROSSPT> m_CrossPts;
01803 SIMPLE_ARRAY<OVERLAP> m_Overlaps;
01804 bool m_IsCleaned;
01805
01806 static int CompareCrossPt (
01807 CROSSPT *p1,
01808 CROSSPT *p2,
01809 void *vpPolyLine
01810 );
01811
01812 static int CompareOverlap (
01813 OVERLAP *o1,
01814 OVERLAP *o2,
01815 void *vpPolyLine
01816 );
01817
01818 void CleanCrossPts (
01819 const POLYLINE& PolyLine
01820 );
01821
01822 void CleanOverlaps (
01823 const POLYLINE& PolyLine
01824 );
01825
01826 #endif // GENERATING_DOXYGEN_OUTPUT
01827 };
01828
01829
01831 class GEOMLIBCLASSEXPORT POLYLINE::SECTIONS {
01832 public:
01833 SECTIONS (
01834 );
01835
01836 SECTIONS (
01837 const SECTIONS& rhs
01838 );
01839
01840 ~SECTIONS (
01841 );
01842
01843 SECTIONS& operator= (
01844 const SECTIONS& rhs
01845 );
01846
01848 void Clear (
01849 );
01850
01852 ERRVALUE ComputeSections (
01853 const POLYLINE& PolyLine,
01854 INT32 NumVertices = 64
01855 );
01856
01857 const POLYLINE::SECTIONARRAY& GetSectionArray (
01858 ) const;
01859
01861 bool IsValid (
01862 ) const;
01863
01864 void SetSectionArray (
01865 const POLYLINE::SECTIONARRAY& SectionArray
01866 );
01867
01868 private:
01869 #ifndef GENERATING_DOXYGEN_OUTPUT
01870 class PRIV;
01871 PRIV *m_Priv;
01872 POLYLINE::SECTIONARRAY m_Empty;
01873
01874 POLYLINE::SECTIONARRAY& GetSectionArrayRaw ();
01875 void GetUniqueSections (SECTIONS& NewSection) const;
01876 ERRVALUE ComputeSectionsRaw (const POLYLINE& PolyLine, INT32 NumVertices = 64);
01877 friend class POLYLINE;
01878 #endif // GENERATING_DOXYGEN_OUTPUT
01879 };
01880
01881
01883 class POLYLINE::SPLIT {
01884 public:
01885 SPLIT (){ }
01886 virtual ~SPLIT (){ }
01887
01888 ERRVALUE OnOverlap (
01889 const POLYLINE& PolyLine
01890 ) { return (v_OnOverlap(PolyLine)); }
01891
01892 virtual ERRVALUE OnAdd (
01893 const POLYLINE& PolyLine
01894 ) = 0;
01895
01898 virtual int OnBadSegment (
01899 const POLYLINE&
01900 ) { return (0); }
01901
01902 virtual ERRVALUE OnDelete (
01903 ) { return (0); }
01904
01905 private:
01908 virtual ERRVALUE v_OnOverlap (
01909 const POLYLINE&
01910 ) { return (0); }
01911 };
01912
01913
01915 class GEOMLIBCLASSEXPORT POLYLINE::STRIPS {
01916 public:
01917
01918 STRIPS (
01919 );
01920
01921 STRIPS (
01922 const STRIPS& rhs
01923 );
01924
01925 ~STRIPS (
01926 );
01927
01928 STRIPS& operator= (
01929 const STRIPS& rhs
01930 );
01931
01933 void Clear (
01934 );
01935
01938 ERRVALUE ComputeStrips (
01939 const POLYLINE& PolyLine,
01940 const DRECT2D& PolyExtents,
01941 INT32 NumDivs = 0
01942 );
01943
01946 ERRVALUE ComputeStrips (
01947 const POLYLINE& PolyLine,
01948 INT32 NumDivs = 0
01949 );
01950
01952 const SIMPLE_ARRAY<INT32_RANGE>& GetStrip (
01953 double y
01954 ) const;
01955
01957 ERRVALUE GetStrip (
01958 double yinit,
01959 double ylast,
01960 SIMPLE_ARRAY<INT32_RANGE>& Strip
01961 ) const;
01962
01964 bool IsValid (
01965 ) const;
01966
01967 private:
01968 #ifndef GENERATING_DOXYGEN_OUTPUT
01969 class PRIV;
01970 PRIV *m_Priv;
01971 SIMPLE_ARRAY<INT32_RANGE> m_Empty;
01972 #endif // GENERATING_DOXYGEN_OUTPUT
01973
01974 };
01975
01976 #ifndef GENERATING_DOXYGEN_OUTPUT
01977 DEFINE_ENUM_OP_BITWISE(POLYLINE::SPLINEFLAGS)
01978 #endif
01979
01980 #undef GEOMLIBEXPORT
01981 #undef GEOMLIBCLASSEXPORT
01982
01983 #endif // INC_MI32_POLYLINE_H