CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
FMImpCachedContour2D.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23#ifndef __FMIMP_CACHED_CONTOUR2D_H__
24#define __FMIMP_CACHED_CONTOUR2D_H__
25
26#include "FMGeometry.h"
30
31#include "Ge/GeExtents2d.h"
32
33namespace FacetModeler
34{
35
37{
38public:
39
41
43
45// Internal segment cache data
46
48 {
51
52 // data members
53 bool m_bValid; // Is the cache valid ?
54
55 SegmentType m_eType; // type of the segment
56 double m_dLength; // Length of the segment
57
58 // Arc/Circle data:
59 double m_dArcInclAngle; // signed included angle of the arc
60 OdGePoint2d m_ptArcCenter; // center of the arc
61 };
62
63
65// Internal data corresponding to a single vertex (a point, a bulge and some extra values).
66
67
68
70 {
71 private:
72 // essential members
73 OdGePoint2d m_ptStart; // Start point of the segment
74 double m_dBulge; // Bulge value of the segment
75
76 mutable SegmentCacheData m_Cache; // cached data
77
78 // Start length of this segment in the contour
79 // This value is not included in m_Cache, because it depends on another segments
80 mutable double m_dStartLength;
81
82 mutable Attributes2D m_Attr;
83
84 public:
86 : m_dBulge(0), m_dStartLength(0) { }
87
88 VertexData(const OdGePoint2d & rPt, double dBulge = 0.0 )
89 : m_ptStart(rPt), m_dBulge(dBulge), m_dStartLength(0) { }
90
91 VertexData(const OdGePoint2d & rPt, double dBulge, const Attributes2D& rAttr )
92 : m_ptStart(rPt), m_dBulge(dBulge), m_dStartLength(0), m_Attr(rAttr) { }
93
94 inline const OdGePoint2d & point() const { return m_ptStart; };
95 inline OdGePoint2d & point() { return m_ptStart; };
96
97 inline const double & bulge() const { return m_dBulge; };
98 inline double & bulge() { return m_dBulge; };
99
100 inline Attributes2D& attributes() const { return m_Attr; };
101
102 inline SegmentCacheData & cache() const { return m_Cache; };
103 inline double & startLength() const { return m_dStartLength; };
104
105 inline void resetCache() const { m_Cache.m_bValid = false; /* m_dStartLength = 0; */ };
106 };
107
108
110// ImplSeg2D class is used internally in implementation of Contour methods
111
113 {
114 public:
115 ImplSeg2D( ) : m_pVertex(0), m_pEndPt(0) { };
116
117 ImplSeg2D( const VertexData & rVData, const OdGePoint2d & rPt )
118 : m_pVertex(&rVData), m_pEndPt( &rPt ) { };
119
120 void set( const VertexData & rVData, const OdGePoint2d & rPt )
121 { m_pVertex = &rVData; m_pEndPt = &rPt; };
122
123 // ToDo: another constructors...
124
126
127 inline SegmentCacheData & _cache() const { return m_pVertex->cache(); };
128 inline double _startLength() const { return m_pVertex->startLength(); };
129
130 // Updates cached values in VertexData::m_pCache
131 void _UpdateCache() const;
132
133
135 // fast inline methods:
136
137 inline const OdGePoint2d & _startPt() const { return m_pVertex->point(); }
138 inline double _bulge() const { return m_pVertex->bulge(); }
139 inline const OdGePoint2d & _endPt() const { return *m_pEndPt; }
140 //inline OdUInt32 _metadata()const { return m_pVertex->metadata(); }
141 inline Attributes2D& _attr() const { return m_pVertex->attributes(); }
142
143 // These methods work fine only after _UpdateCache is called
144 inline SegmentType _type() const { return _cache().m_eType; };
145 inline double _length() const { return _cache().m_dLength; };
146 inline double _arcAngle() const { return _cache().m_dArcInclAngle; };
147 inline double _arcRadius() const { return _cache().m_dLength / ::fabs(_cache().m_dArcInclAngle); };
148 inline const OdGePoint2d & _arcCenter() const { return _cache().m_ptArcCenter; };
149 double _arcStartAngle() const;
150
151
153 // Implementation of methods not implemented in CommonSeg2DImpl
154
155 // Update ends and bulge ( always fails )
156 virtual Result set( const OdGePoint2d & ptA, const OdGePoint2d & ptB, double dBulge, const Attributes2D& rAttr );
157
158
160
162
163 virtual const OdGePoint2d & startPt() const;
164
165 virtual const OdGePoint2d & endPt () const;
166
167 virtual double bulge () const;
168
169 virtual const Attributes2D& attributes() const { return _attr(); }
170 virtual Attributes2D& attributes4U() { return _attr(); }
171
172
174
175 // returns the type of this segment
176 virtual SegmentType type() const;
177
178 // returns signed deviation from the line [start, end]
179 // the deviation has the same sign, as the bulge() value
180 virtual double deviation() const;
181
182 // returns vDir = endPt - startPt
183 virtual void getDir ( OdGeVector2d & vDir ) const;
184
185 // returns distance btw startPt and endPt
186 virtual double dirLength( ) const;
187
188 // returns length of the segment
189 virtual double length ( ) const;
190
191
192 // Arcs and circles ( length>0 and bulge != 0 )
193
194 // returns arc center, if type()==estArc
195 virtual OdGePoint2d arcCenter() const;
196
197 // returns arc radius, if type()==estArc
198 virtual double arcRadius( ) const;
199
200 // returns arc radius and center point, if type()==estArc
201 virtual Result getCircleData( OdGePoint2d & ptCenter, double & dRadius ) const;
202
203 // returns signed included angle of the arc segment
204 // The returned value belongs to range ( -2*Pi, 2*Pi )
205 virtual double arcAngle() const;
206
207 // returns starting angle of the arc (direction from center to startPt )
208 // The returned value belongs to range [ 0, 2*Pi )
209 virtual double arcStartAngle() const;
210
211 // returns arc center point, radius and angles if type()==estArc
212 virtual Result getArcData( OdGePoint2d & ptCenter, double & dRadius,
213 double & dStartAngle, double & dInclAngle ) const;
214
215 private:
216 const VertexData * m_pVertex;
217 const OdGePoint2d * m_pEndPt;
218 };
219
220
222//
223// Contour data
224private:
225
226 // Array of vertex data (points, bulges etc.)
227 //std::vector<VertexData> m_vecVertices;
228 OdArray<VertexData> m_vecVertices;
229
230 // If m_bClosed==true, the contour is closed and the last segment is
231 // [ m_vecVertices.back().point(), m_vecVertices.front().point(), m_vecVertices.back().bulge() ]
232 // Otherwise the last bulge value is ignored and the last point
233 // of the contour is m_vecVertices.back().point()
234 bool m_bClosed;
235
236
238 // Cached contour data:
239
240 OdUInt32 m_iNumSegments; // should be valid always
241 OdUInt32 _updateNumSegments();
242
243public:
244
246 {
247 ecsNotValid = 0, // All cached info is not valid
248 ecsLengthsValid = 0x01, // m_dLength and lengths of all segments are valid
249 ecsAreaValid = 0x02, // m_dSignedArea is valid
250 ecsExtentsValid = 0x04, // m_Extents is valid
251 ecsConvexValid = 0x08 // m_bConvex is Valid
252
253 };
254
256
257 mutable double m_dLength;
258 mutable double m_dSignedArea;
260 mutable bool m_bConvex;
261
262 // These methods update (if not valid) and return cached values
263 double _updateCacheLengths() const;
264 //double _updateCacheArea() const;
265 //const OdGeExtents2d& _updateCacheExtents() const;
266
267 // reset contour`s and segments` cache.
268 // use iNumVerts=0 to keep segments` cache intact.
269 // if bStepBack is true, then iFirstVertex is the first modified vertex,
270 // so the segment (iFirstVertex-1) is updated too!
271 void _resetCache(OdUInt32 iFirstVertex=0, OdUInt32 iNumVerts = OdUInt32(-1), bool bStepBack = true );
272
274//
275// methods used by TContour2DImpl
276//
277public:
278 inline ContourImplClass _implClass() const { return ecicCached; };
279
280 inline bool _closed() const { return m_bClosed; };
281
282 inline bool _empty() const { return m_vecVertices.empty(); };
283
284 inline OdUInt32 _numVerts() const { return m_vecVertices.size(); };
285
286 inline OdUInt32 _numSegments() const { return m_iNumSegments; };
287
288 Result _getSegment( OdUInt32 iIndex, ImplSeg2D & rSeg ) const;
289
290 Result _normalizeIndex( OdUInt32 & iVertIndex ) const;
291
292
293 inline const VertexData& _vertex( OdUInt32 iIndex ) const
294 {
295 FMGE_ASSERT( iIndex < _numVerts() );
296 return m_vecVertices[iIndex];
297 };
298
300 // Non-const methods
301
302 inline VertexData& _vertex( OdUInt32 iIndex )
303 {
304 FMGE_ASSERT( iIndex < _numVerts() );
305 return m_vecVertices[iIndex];
306 };
307
308
309 void _reset( OdUInt32 iVertexCount = 0, bool bClosed = false );
310
311 void _resize( OdUInt32 iNewVertNum );
312
313 void _reserveVertices( OdUInt32 iReservedSize );
314
315 void _setClosed( bool bClosed );
316
317 // These methods update cached values or reset cache flags
319 void _setModifiedSegs ( OdUInt32 iFirst, OdUInt32 iCount = 1 );
320 void _setModifiedVerts( OdUInt32 iFirst, OdUInt32 iCount = 1 );
321
322
324 const OdGePoint2d * paPoints, const double * paBulges = 0, const Attributes2D* pAttrs = 0);
325
327
328};
329
330
331
332
333
334class CachedContour2DImpl : public TContour2DImpl<CachedContour2DImplData>
335{
336public:
338
339 // Implement some IContour2D methods, not implemented in TContour2DImpl
340 // or overload with better implementation
341
342 virtual IContour2D * clone( ) const;
343
344
345 virtual double length() const;
346
347 virtual Result getDistAtParam (double dParam, double& dDist ) const;
348 virtual Result getParamAtDist (double dDist, double& dParam ) const;
349
350 virtual Result addExtents(OdGeExtents2d& geExtents ) const;
351
352 virtual double signedArea() const;
353
354 virtual bool isConvex() const;
355
356 // ToDo: override intersect,isOn etc. to check extents first, if available
357
358 virtual bool contains( const OdGePoint2d &rPoint, bool * pbOnBorder = 0,
359 const OdGeTol & gTol = FMGeGbl::gTol) const;
360
361
362private:
363
364 // These methods update (if not valid) and return cached values
365 double _updateCacheArea() const;
366 const OdGeExtents2d& _updateCacheExtents() const;
367 bool _updateCacheConvex() const;
368};
369
370
371};
372
373
374#endif //__FMIMP_CACHED_CONTOUR2D_H__
false
Definition: DimVarDefs.h:165
#define FMGE_ASSERT(x)
unsigned int OdUInt32
virtual Result getCircleData(OdGePoint2d &ptCenter, double &dRadius) const
void set(const VertexData &rVData, const OdGePoint2d &rPt)
virtual SegmentImplClass implClass() const
virtual void getDir(OdGeVector2d &vDir) const
virtual Result getArcData(OdGePoint2d &ptCenter, double &dRadius, double &dStartAngle, double &dInclAngle) const
virtual Result set(const OdGePoint2d &ptA, const OdGePoint2d &ptB, double dBulge, const Attributes2D &rAttr)
virtual const Attributes2D & attributes() const
ImplSeg2D(const VertexData &rVData, const OdGePoint2d &rPt)
virtual const OdGePoint2d & startPt() const
virtual const OdGePoint2d & endPt() const
VertexData(const OdGePoint2d &rPt, double dBulge, const Attributes2D &rAttr)
VertexData(const OdGePoint2d &rPt, double dBulge=0.0)
void _setModifiedSegs(OdUInt32 iFirst, OdUInt32 iCount=1)
const VertexData & _vertex(OdUInt32 iIndex) const
void _resize(OdUInt32 iNewVertNum)
VertexData & _vertex(OdUInt32 iIndex)
Result _getSegment(OdUInt32 iIndex, ImplSeg2D &rSeg) const
Result _normalizeIndex(OdUInt32 &iVertIndex) const
void _resetCache(OdUInt32 iFirstVertex=0, OdUInt32 iNumVerts=OdUInt32(-1), bool bStepBack=true)
Result _removeVertices(OdUInt32 iIndex, OdUInt32 iCount=1)
Result _insertVerticesAt(OdUInt32 iIndex, OdUInt32 iCount, const OdGePoint2d *paPoints, const double *paBulges=0, const Attributes2D *pAttrs=0)
void _setModifiedVerts(OdUInt32 iFirst, OdUInt32 iCount=1)
void _reset(OdUInt32 iVertexCount=0, bool bClosed=false)
void _reserveVertices(OdUInt32 iReservedSize)
virtual Result addExtents(OdGeExtents2d &geExtents) const
virtual double length() const
virtual Result getDistAtParam(double dParam, double &dDist) const
virtual bool isConvex() const
virtual double signedArea() const
virtual Result getParamAtDist(double dDist, double &dParam) const
virtual bool contains(const OdGePoint2d &rPoint, bool *pbOnBorder=0, const OdGeTol &gTol=FMGeGbl::gTol) const
virtual IContour2D * clone() const
bool empty() const
Definition: OdArray.h:1257
size_type size() const
Definition: OdArray.h:1247
Definition: GeTol.h:49
static FMGEOMETRY_API_STATIC OdGeTol gTol
Definition: FMGeometry.h:169