Standard_Real NewU = U;
Handle(TColStd_HArray1OfReal) TheKnots;
if (WithKnotRepetition) TheKnots = flatknots;
else TheKnots = knots;
const TColStd_Array1OfReal & CKnots = TheKnots->Array1();
PeriodicNormalization(NewU); //Attention a la periode
Standard_Real UFirst = CKnots (1);
Standard_Real ULast = CKnots (CKnots.Length());
if (Abs (NewU - UFirst) <= Abs(ParametricTolerance)) { I1 = I2 = 1; }
else if (Abs (NewU - ULast) <= Abs(ParametricTolerance)) {
I1 = I2 = CKnots.Length();
}
else if (NewU < UFirst - Abs(ParametricTolerance)) {
I2 = 1;
I1 = 0;
}
else if (NewU > ULast + Abs(ParametricTolerance)) {
I1 = CKnots.Length();
I2 = I1 + 1;
}
else {
I1 = 1;
BSplCLib::Hunt (CKnots, NewU, I1);
while ( Abs( CKnots(I1+1) - NewU) <= Abs(ParametricTolerance)) I1++;
if ( Abs( CKnots(I1) - NewU) <= Abs(ParametricTolerance)) {
I2 = I1;
}
else {
I2 = I1 + 1;
}
}
带H的是Handle 操作允许数组的共享。
const TColStd_Array1OfReal & CKnots = TheKnots->Array1();给出的一个安全代码。从以上看到,有时候效率并不是我们考虑的。在做好代码安全保障之前,和代码的逻辑正确。以上代码现代的编译器都可以做很好的优化?

本文详细解析了一种参数化曲线定位算法的具体实现过程。通过使用Handle操作来管理数组资源,确保了数组的安全共享,并利用TColStd_Array1OfReal进行关键节点的计算。文章重点介绍了如何根据输入参数NewU在曲线上的位置确定对应的索引区间,通过精确的条件判断实现了高效且准确的参数化定位。
1007

被折叠的 条评论
为什么被折叠?



