|
| 1 | +#include "MRPolylineToVoxels.h" |
| 2 | +#include "MRFloatGrid.h" |
| 3 | +#include "MRMesh/MRPolyline.h" |
| 4 | +#include "MRMesh/MRVector3.h" |
| 5 | +#include "MRMesh/MRProgressCallback.h" |
| 6 | +#include "MRMesh/MRTimer.h" |
| 7 | +#include "MRMesh/MRMesh.h" |
| 8 | +#include "MRMesh/MRMeshFillHole.h" |
| 9 | +#include "MRVDBConversions.h" |
| 10 | +#include "MRVoxelsVolume.h" |
| 11 | +#include "MRMeshToDistanceVolume.h" |
| 12 | + |
| 13 | +namespace MR |
| 14 | +{ |
| 15 | + |
| 16 | +Mesh polylineToDegenerateMesh( const Polyline3& polyline ) |
| 17 | +{ |
| 18 | + Mesh mesh; |
| 19 | + auto contours = polyline.topology.convertToContours<Vector3f>( |
| 20 | + [&points = polyline.points] ( VertId v ) |
| 21 | + { |
| 22 | + return points[v]; |
| 23 | + } ); |
| 24 | + |
| 25 | + std::vector<EdgeId> newHoles; |
| 26 | + newHoles.reserve( contours.size() ); |
| 27 | + for ( auto& cont : contours ) |
| 28 | + { |
| 29 | + if ( cont[0] != cont.back() ) |
| 30 | + cont.insert( cont.end(), cont.rbegin(), cont.rend() ); |
| 31 | + newHoles.push_back( mesh.addSeparateEdgeLoop( cont ) ); |
| 32 | + } |
| 33 | + |
| 34 | + for ( auto h : newHoles ) |
| 35 | + makeDegenerateBandAroundHole( mesh, h ); |
| 36 | + |
| 37 | + return mesh; |
| 38 | +} |
| 39 | + |
| 40 | +Expected<FloatGrid> polylineToDistanceField( const Polyline3& polyline, const PolylineToDistanceVolumeParams& params ) |
| 41 | +{ |
| 42 | + MR_TIMER; |
| 43 | + |
| 44 | + const Mesh mesh = polylineToDegenerateMesh( polyline ); |
| 45 | + return meshToDistanceField( mesh, {}, params.voxelSize, params.offsetCount, params.cb ); |
| 46 | +} |
| 47 | + |
| 48 | +Expected<VdbVolume> polylineToVdbVolume( const Polyline3& polyline, const PolylineToDistanceVolumeParams& params ) |
| 49 | +{ |
| 50 | + const Mesh mesh = polylineToDegenerateMesh( polyline ); |
| 51 | + MeshToVolumeParams meshParams; |
| 52 | + meshParams.voxelSize = params.voxelSize; |
| 53 | + meshParams.surfaceOffset = params.offsetCount; |
| 54 | + meshParams.cb = params.cb; |
| 55 | + return meshToDistanceVdbVolume( mesh, meshParams ); |
| 56 | +} |
| 57 | + |
| 58 | +Expected<SimpleVolume> polylineToSimpleVolume( const Polyline3& polyline, const PolylineToVolumeParams& params ) |
| 59 | +{ |
| 60 | + const Mesh mesh = polylineToDegenerateMesh( polyline ); |
| 61 | + MeshToDistanceVolumeParams meshParams; |
| 62 | + meshParams.vol = params.vol; |
| 63 | + meshParams.dist = { params.dist }; |
| 64 | + return meshToDistanceVolume( mesh, meshParams ); |
| 65 | +} |
| 66 | + |
| 67 | +Expected<FunctionVolume> polylineToFunctionVolume( const Polyline3& polyline, const PolylineToVolumeParams& params ) |
| 68 | +{ |
| 69 | + const Mesh mesh = polylineToDegenerateMesh( polyline ); |
| 70 | + MeshToDistanceVolumeParams meshParams; |
| 71 | + meshParams.vol = params.vol; |
| 72 | + meshParams.dist = { params.dist }; |
| 73 | + return meshToDistanceFunctionVolume( mesh, meshParams ); |
| 74 | +} |
| 75 | + |
| 76 | +} |
0 commit comments