| 429 | } |
| 430 | |
| 431 | bool CurvesPrimitiveEvaluator::closestPoint( const Imath::V3f &p, PrimitiveEvaluator::Result *result ) const |
| 432 | { |
| 433 | if( !m_verticesPerCurve.size() ) |
| 434 | { |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | Result *typedResult = static_cast<Result *>( result ); |
| 439 | // the cast isn't pretty but i think is the best of the alternatives. we want to delay building the tree until the first |
| 440 | // closestPoint() query so people don't pay the overhead if they're just using other queries. the alternative to |
| 441 | // the cast is to make the tree members mutable, but i'd rather keep them immutable so that the compiler tells us if |
| 442 | // we do anything wrong during the query. |
| 443 | const_cast<CurvesPrimitiveEvaluator *>( this )->buildTree(); |
| 444 | |
| 445 | unsigned curveIndex = 0; |
| 446 | float v = -1; |
| 447 | float distSquared = std::numeric_limits<float>::max(); |
| 448 | closestPointWalk( m_tree.rootIndex(), p, curveIndex, v, distSquared ); |
| 449 | (typedResult->*typedResult->m_init)( curveIndex, v, this ); |
| 450 | |
| 451 | return true; |
| 452 | } |
| 453 | |
| 454 | void CurvesPrimitiveEvaluator::closestPointWalk( Box3fTree::NodeIndex nodeIndex, const Imath::V3f &p, unsigned &curveIndex, float &v, float &closestDistSquared ) const |
| 455 | { |