| 13 | |
| 14 | |
| 15 | TransformVdbVolumeResult transformVdbVolume( const VdbVolume& volume, const AffineXf3f& xf0, bool fixBox, const Box3f& box ) |
| 16 | { |
| 17 | AffineXf3f xf = xf0; |
| 18 | Box3f newBox; |
| 19 | { |
| 20 | Box3f pseudoBox; |
| 21 | if ( box.valid() ) |
| 22 | pseudoBox = box; |
| 23 | else |
| 24 | pseudoBox = Box3f{ { 0.f, 0.f, 0.f }, mult( Vector3f( volume.dims ), volume.voxelSize ) }; |
| 25 | |
| 26 | for ( auto c : getCorners( pseudoBox ) ) |
| 27 | newBox.include( xf( c ) ); |
| 28 | } |
| 29 | |
| 30 | bool boxFixed = false; |
| 31 | if ( fixBox && box.valid() && |
| 32 | std::any_of( begin( newBox.min ), end( newBox.min ), [] ( float f ) { return f < 0; } ) ) |
| 33 | { |
| 34 | Vector3f fixer; |
| 35 | for ( int i = 0; i < 3; ++i ) |
| 36 | { |
| 37 | if ( newBox.min[i] < 0 ) |
| 38 | { |
| 39 | fixer[i] = -newBox.min[i]; |
| 40 | newBox.min[i] = 0; |
| 41 | newBox.max[i] += fixer[i]; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | xf = AffineXf3f::translation( fixer ) * xf; |
| 46 | boxFixed = true; |
| 47 | } |
| 48 | |
| 49 | Matrix4d m( Matrix3d( xf.A ), Vector3d( div( xf.b, volume.voxelSize ) ) ); |
| 50 | m = m.transposed(); |
| 51 | openvdb::math::AffineMap map( openvdb::math::Mat4d{ ( double* )&m } ); |
| 52 | openvdb::tools::GridTransformer tr( map.getConstMat4() ); |
| 53 | |
| 54 | const FloatGrid& oldGrid = volume.data; |
| 55 | auto newGrid = openvdb::FloatGrid::create( oldGrid->background() ); |
| 56 | newGrid->setGridClass( oldGrid->getGridClass() ); |
| 57 | tr.transformGrid<openvdb::tools::QuadraticSampler, openvdb::FloatGrid>( *volume.data, *newGrid ); |
| 58 | |
| 59 | VdbVolume res; |
| 60 | res = volume; |
| 61 | res.data = MakeFloatGrid( std::move( newGrid ) ); |
| 62 | res.dims = Vector3i( div( newBox.max, volume.voxelSize ) ); |
| 63 | evalGridMinMax( res.data, res.min, res.max ); |
| 64 | |
| 65 | return { .volume = res, .boxFixed = boxFixed }; |
| 66 | } |
| 67 | |
| 68 | bool voxelsApplyTransform( ObjectVoxels& obj, const AffineXf3f& xf, bool fixBox ) |
| 69 | { |
no test coverage detected