| 365 | } |
| 366 | |
| 367 | ConvertToIntVector getToIntConverter( const Box3d& box ) |
| 368 | { |
| 369 | Vector3d center{ box.center() }; |
| 370 | auto bbSize = box.size(); |
| 371 | double maxDim = std::max( { bbSize[0],bbSize[1],bbSize[2] } ); |
| 372 | |
| 373 | // range is selected so that after centering each integer point is within [-max/2; +max/2] range, |
| 374 | // so the difference of any two points will be within [-max; +max] range |
| 375 | double invRange = cRangeIntMax / maxDim; |
| 376 | |
| 377 | return [invRange, center] ( const Vector3f& v ) |
| 378 | { |
| 379 | // perform intermediate operations in double for better precision |
| 380 | const auto d = ( Vector3d{ v } - center ) * invRange; |
| 381 | // and round to the nearest integer instead of truncating to zero |
| 382 | return Vector3i( (int)std::round( d.x ), (int)std::round( d.y ), (int)std::round( d.z ) ); |
| 383 | }; |
| 384 | } |
| 385 | |
| 386 | ConvertToFloatVector getToFloatConverter( const Box3d& box ) |
| 387 | { |