Skip to content

Commit a4c4b6c

Browse files
committed
Foundation Classes, Modeling Data - Add Geom2dGridEval package for batch 2D curve evaluation
Add new Geom2dGridEval package in TKG2d providing batch evaluation of 2D curves at multiple parameter values, mirroring the existing 3D GeomGridEval package in TKG3d. Specialized evaluators use analytical formulas for conics and cache-based evaluation for BSpline/Bezier curves, with a unified std::variant dispatcher for automatic type-based dispatch. New classes: - Geom2dGridEval_Line (header-only), _Circle, _Ellipse, _Hyperbola, _Parabola, _BezierCurve, _BSplineCurve, _OffsetCurve, _OtherCurve - Geom2dGridEval_Curve: unified dispatcher with Initialize() from Adaptor2d_Curve2d or occ::handle<Geom2d_Curve> - Geom2dGridEval.hxx: CurveD1/D2/D3 result structures BSplCLib_Cache changes: - Add D0Local/D1Local/D2Local/D3Local overloads for gp_Pnt2d/gp_Vec2d - Refactor existing 2D D0/D1/D2/D3 methods to delegate to D*Local, consistent with the existing 3D delegation pattern
1 parent bdddade commit a4c4b6c

30 files changed

Lines changed: 4978 additions & 49 deletions

src/FoundationClasses/TKMath/BSplCLib/BSplCLib_Cache.cxx

Lines changed: 81 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,9 @@ void BSplCLib_Cache::calculateDerivativeLocal(double theLocalParam,
189189

190190
void BSplCLib_Cache::D0(const double& theParameter, gp_Pnt2d& thePoint) const
191191
{
192-
double aNewParameter = myParams.PeriodicNormalization(theParameter);
193-
aNewParameter = (aNewParameter - myParams.SpanStart) / myParams.SpanLength;
194-
195-
double* aPolesArray = const_cast<double*>(myPolesWeightsBuffer);
196-
double aPoint[4];
197-
const int aDimension = myRowLength;
198-
199-
PLib::NoDerivativeEvalPolynomial(aNewParameter,
200-
myParams.Degree,
201-
aDimension,
202-
myParams.Degree * aDimension,
203-
aPolesArray[0],
204-
aPoint[0]);
205-
206-
thePoint.SetCoord(aPoint[0], aPoint[1]);
207-
if (myIsRational)
208-
thePoint.ChangeCoord().Divide(aPoint[2]);
192+
double aLocalParam = myParams.PeriodicNormalization(theParameter);
193+
aLocalParam = (aLocalParam - myParams.SpanStart) / myParams.SpanLength;
194+
D0Local(aLocalParam, thePoint);
209195
}
210196

211197
//==================================================================================================
@@ -240,15 +226,9 @@ void BSplCLib_Cache::D0Local(double theLocalParam, gp_Pnt& thePoint) const
240226

241227
void BSplCLib_Cache::D1(const double& theParameter, gp_Pnt2d& thePoint, gp_Vec2d& theTangent) const
242228
{
243-
int aDimension = myRowLength;
244-
double aPntDeriv[8]; // result storage (point and derivative coordinates)
245-
246-
calculateDerivative(theParameter, 1, aPntDeriv);
247-
if (myIsRational) // the size of aPntDeriv was changed by PLib::RationalDerivative
248-
aDimension -= 1;
249-
250-
thePoint.SetCoord(aPntDeriv[0], aPntDeriv[1]);
251-
theTangent.SetCoord(aPntDeriv[aDimension], aPntDeriv[aDimension + 1]);
229+
double aLocalParam = myParams.PeriodicNormalization(theParameter);
230+
aLocalParam = (aLocalParam - myParams.SpanStart) / myParams.SpanLength;
231+
D1Local(aLocalParam, thePoint, theTangent);
252232
}
253233

254234
void BSplCLib_Cache::D1(const double& theParameter, gp_Pnt& thePoint, gp_Vec& theTangent) const
@@ -275,16 +255,9 @@ void BSplCLib_Cache::D2(const double& theParameter,
275255
gp_Vec2d& theTangent,
276256
gp_Vec2d& theCurvature) const
277257
{
278-
int aDimension = myRowLength;
279-
double aPntDeriv[12]; // result storage (point and derivatives coordinates)
280-
281-
calculateDerivative(theParameter, 2, aPntDeriv);
282-
if (myIsRational) // the size of aPntDeriv was changed by PLib::RationalDerivative
283-
aDimension -= 1;
284-
285-
thePoint.SetCoord(aPntDeriv[0], aPntDeriv[1]);
286-
theTangent.SetCoord(aPntDeriv[aDimension], aPntDeriv[aDimension + 1]);
287-
theCurvature.SetCoord(aPntDeriv[aDimension << 1], aPntDeriv[(aDimension << 1) + 1]);
258+
double aLocalParam = myParams.PeriodicNormalization(theParameter);
259+
aLocalParam = (aLocalParam - myParams.SpanStart) / myParams.SpanLength;
260+
D2Local(aLocalParam, thePoint, theTangent, theCurvature);
288261
}
289262

290263
void BSplCLib_Cache::D2(const double& theParameter,
@@ -320,19 +293,9 @@ void BSplCLib_Cache::D3(const double& theParameter,
320293
gp_Vec2d& theCurvature,
321294
gp_Vec2d& theTorsion) const
322295
{
323-
int aDimension = myRowLength;
324-
double aPntDeriv[16]; // result storage (point and derivatives coordinates)
325-
326-
calculateDerivative(theParameter, 3, aPntDeriv);
327-
if (myIsRational) // the size of aPntDeriv was changed by PLib::RationalDerivative
328-
aDimension -= 1;
329-
330-
thePoint.SetCoord(aPntDeriv[0], aPntDeriv[1]);
331-
theTangent.SetCoord(aPntDeriv[aDimension], aPntDeriv[aDimension + 1]);
332-
int aShift = aDimension << 1;
333-
theCurvature.SetCoord(aPntDeriv[aShift], aPntDeriv[aShift + 1]);
334-
aShift += aDimension;
335-
theTorsion.SetCoord(aPntDeriv[aShift], aPntDeriv[aShift + 1]);
296+
double aLocalParam = myParams.PeriodicNormalization(theParameter);
297+
aLocalParam = (aLocalParam - myParams.SpanStart) / myParams.SpanLength;
298+
D3Local(aLocalParam, thePoint, theTangent, theCurvature, theTorsion);
336299
}
337300

338301
void BSplCLib_Cache::D3(const double& theParameter,
@@ -365,3 +328,72 @@ void BSplCLib_Cache::D3Local(double theLocalParam,
365328
theCurvature.SetCoord(aDerivArray[aShift2], aDerivArray[aShift2 + 1], aDerivArray[aShift2 + 2]);
366329
theTorsion.SetCoord(aDerivArray[aShift3], aDerivArray[aShift3 + 1], aDerivArray[aShift3 + 2]);
367330
}
331+
332+
//==================================================================================================
333+
334+
void BSplCLib_Cache::D0Local(double theLocalParam, gp_Pnt2d& thePoint) const
335+
{
336+
double aPoint[4];
337+
338+
PLib::NoDerivativeEvalPolynomial(theLocalParam,
339+
myParams.Degree,
340+
myRowLength,
341+
myParams.Degree * myRowLength,
342+
myPolesWeightsBuffer[0],
343+
aPoint[0]);
344+
345+
thePoint.SetCoord(aPoint[0], aPoint[1]);
346+
if (myIsRational)
347+
{
348+
thePoint.ChangeCoord().Divide(aPoint[2]);
349+
}
350+
}
351+
352+
//==================================================================================================
353+
354+
void BSplCLib_Cache::D1Local(double theLocalParam, gp_Pnt2d& thePoint, gp_Vec2d& theTangent) const
355+
{
356+
double aDerivArray[8];
357+
calculateDerivativeLocal(theLocalParam, 1, aDerivArray);
358+
359+
const int aDim = myIsRational ? myRowLength - 1 : myRowLength;
360+
thePoint.SetCoord(aDerivArray[0], aDerivArray[1]);
361+
theTangent.SetCoord(aDerivArray[aDim], aDerivArray[aDim + 1]);
362+
}
363+
364+
//==================================================================================================
365+
366+
void BSplCLib_Cache::D2Local(double theLocalParam,
367+
gp_Pnt2d& thePoint,
368+
gp_Vec2d& theTangent,
369+
gp_Vec2d& theCurvature) const
370+
{
371+
double aDerivArray[12];
372+
calculateDerivativeLocal(theLocalParam, 2, aDerivArray);
373+
374+
const int aDim = myIsRational ? myRowLength - 1 : myRowLength;
375+
const int aShift = aDim << 1;
376+
thePoint.SetCoord(aDerivArray[0], aDerivArray[1]);
377+
theTangent.SetCoord(aDerivArray[aDim], aDerivArray[aDim + 1]);
378+
theCurvature.SetCoord(aDerivArray[aShift], aDerivArray[aShift + 1]);
379+
}
380+
381+
//==================================================================================================
382+
383+
void BSplCLib_Cache::D3Local(double theLocalParam,
384+
gp_Pnt2d& thePoint,
385+
gp_Vec2d& theTangent,
386+
gp_Vec2d& theCurvature,
387+
gp_Vec2d& theTorsion) const
388+
{
389+
double aDerivArray[16];
390+
calculateDerivativeLocal(theLocalParam, 3, aDerivArray);
391+
392+
const int aDim = myIsRational ? myRowLength - 1 : myRowLength;
393+
const int aShift2 = aDim << 1;
394+
const int aShift3 = aShift2 + aDim;
395+
thePoint.SetCoord(aDerivArray[0], aDerivArray[1]);
396+
theTangent.SetCoord(aDerivArray[aDim], aDerivArray[aDim + 1]);
397+
theCurvature.SetCoord(aDerivArray[aShift2], aDerivArray[aShift2 + 1]);
398+
theTorsion.SetCoord(aDerivArray[aShift3], aDerivArray[aShift3 + 1]);
399+
}

src/FoundationClasses/TKMath/BSplCLib/BSplCLib_Cache.hxx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,43 @@ public:
155155
gp_Vec& theCurvature,
156156
gp_Vec& theTorsion) const;
157157

158+
//! Calculates the 2D point using pre-computed local parameter in [0, 1] range.
159+
//! This bypasses periodic normalization and local parameter calculation.
160+
//! @param[in] theLocalParam pre-computed local parameter: (Param - SpanStart) / SpanLength
161+
//! @param[out] thePoint the result of calculation (the point on the curve)
162+
Standard_EXPORT void D0Local(double theLocalParam, gp_Pnt2d& thePoint) const;
163+
164+
//! Calculates the 2D point and first derivative using pre-computed local parameter.
165+
//! @param[in] theLocalParam pre-computed local parameter: (Param - SpanStart) / SpanLength
166+
//! @param[out] thePoint the point on the curve
167+
//! @param[out] theTangent first derivative (tangent vector)
168+
Standard_EXPORT void D1Local(double theLocalParam,
169+
gp_Pnt2d& thePoint,
170+
gp_Vec2d& theTangent) const;
171+
172+
//! Calculates the 2D point, first and second derivatives using pre-computed local parameter.
173+
//! @param[in] theLocalParam pre-computed local parameter: (Param - SpanStart) / SpanLength
174+
//! @param[out] thePoint the point on the curve
175+
//! @param[out] theTangent first derivative (tangent vector)
176+
//! @param[out] theCurvature second derivative (curvature vector)
177+
Standard_EXPORT void D2Local(double theLocalParam,
178+
gp_Pnt2d& thePoint,
179+
gp_Vec2d& theTangent,
180+
gp_Vec2d& theCurvature) const;
181+
182+
//! Calculates the 2D point, first, second and third derivatives using pre-computed local
183+
//! parameter.
184+
//! @param[in] theLocalParam pre-computed local parameter: (Param - SpanStart) / SpanLength
185+
//! @param[out] thePoint the point on the curve
186+
//! @param[out] theTangent first derivative (tangent vector)
187+
//! @param[out] theCurvature second derivative (curvature vector)
188+
//! @param[out] theTorsion third derivative (torsion vector)
189+
Standard_EXPORT void D3Local(double theLocalParam,
190+
gp_Pnt2d& thePoint,
191+
gp_Vec2d& theTangent,
192+
gp_Vec2d& theCurvature,
193+
gp_Vec2d& theTorsion) const;
194+
158195
DEFINE_STANDARD_RTTIEXT(BSplCLib_Cache, Standard_Transient)
159196

160197
protected:

src/ModelingData/TKG2d/GTests/FILES.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ set(OCCT_TKG2d_GTests_FILES
99
Geom2dAPI_InterCurveCurve_Test.cxx
1010
Geom2dGcc_Circ2d2TanOn_Test.cxx
1111
Geom2dGcc_Circ2d2TanRad_Test.cxx
12+
Geom2dGridEval_BezierCurve_Test.cxx
13+
Geom2dGridEval_Curve_Test.cxx
14+
Geom2dGridEval_Ellipse_Test.cxx
15+
Geom2dGridEval_Hyperbola_Test.cxx
16+
Geom2dGridEval_Parabola_Test.cxx
1217
Geom2dHash_CurveHasher_Test.cxx
1318
)

0 commit comments

Comments
 (0)