MeshLib Documentation
Loading...
Searching...
No Matches
MRVDBConversions.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVoxelsFwd.h"
4
5#include "MRMesh/MRMeshPart.h"
8#include "MRMesh/MRExpected.h"
9#include "MRMesh/MRBox.h"
10#include <climits>
11#include <string>
12#include <optional>
13
14namespace MR
15{
16
17// closed surface is required
18// surfaceOffset - number voxels around surface to calculate distance in (should be positive)
19// returns null if was canceled by progress callback
20MRVOXELS_API FloatGrid meshToLevelSet( const MeshPart& mp, const AffineXf3f& xf,
21 const Vector3f& voxelSize, float surfaceOffset = 3,
22 ProgressCallback cb = {} );
23
24// does not require closed surface, resulting grid cannot be used for boolean operations,
25// surfaceOffset - the number of voxels around surface to calculate distance in (should be positive)
26// returns null if was canceled by progress callback
27MRVOXELS_API FloatGrid meshToDistanceField( const MeshPart& mp, const AffineXf3f& xf,
28 const Vector3f& voxelSize, float surfaceOffset = 3,
29 ProgressCallback cb = {} );
30
31// Parameters structure for meshToVolume function
33{
34 // Conversion type
35 enum class Type
36 {
37 Signed, // only closed meshes can be converted with signed type
38 Unsigned // this type leads to shell like iso-surfaces
39 } type{ Type::Unsigned };
40 float surfaceOffset{ 3.0 }; // the number of voxels around surface to calculate distance in (should be positive)
41 Vector3f voxelSize = Vector3f::diagonal( 1.0f );
42 AffineXf3f worldXf; // mesh initial transform
43 AffineXf3f* outXf{ nullptr }; // optional output: xf to original mesh (respecting worldXf)
45};
46
47// eval min max value from FloatGrid
48MRVOXELS_API void evalGridMinMax( const FloatGrid& grid, float& min, float& max );
49
50// convert mesh to volume in (0,0,0)-(dim.x,dim.y,dim.z) grid box
52
53// fills VdbVolume data from FloatGrid (does not fill voxels size, cause we expect it outside)
55
56// make FloatGrid from SimpleVolume
57// make copy of data
58// background - the new background value for FloatGrid
59// grid can be used to make iso-surface later with gridToMesh function
60MRVOXELS_API FloatGrid simpleVolumeToDenseGrid( const SimpleVolume& simpleVolume, float background = 0.0f, ProgressCallback cb = {} );
61// set the simpleVolume.min as the background value
62MRVOXELS_API VdbVolume simpleVolumeToVdbVolume( const SimpleVolumeMinMax& simpleVolume, ProgressCallback cb = {} );
63
66 FloatGrid& grid,
67 const Vector3i& minCoord, const SimpleVolume& simpleVolume, ProgressCallback cb = {}
68 );
69
70// make SimpleVolume from VdbVolume
71// make copy of data
73 const VdbVolume& vdbVolume, const Box3i& activeBox = Box3i(), ProgressCallback cb = {} );
80 const VdbVolume& vdbVolume, const Box3i& activeBox = Box3i(), std::optional<MinMaxf> sourceScale = {}, ProgressCallback cb = {} );
87 const VdbVolume& vdbVolume, const Box3i& activeBox = Box3i(), std::optional<MinMaxf> sourceScale = {}, ProgressCallback cb = {} );
88
91{
93 Vector3f voxelSize;
95 float isoValue = 0;
97 float adaptivity = 0;
99 int maxFaces = INT_MAX;
101 int maxVertices = INT_MAX;
105};
106
109
113
115{
117 AffineXf3f meshToGridXf;
118
120 std::shared_ptr<IFastWindingNumber> fwn;
121
125
128
131};
132
134MRVOXELS_API Expected<void> makeSignedByWindingNumber( FloatGrid& grid, const Vector3f& voxelSize, const Mesh& refMesh,
135 const MakeSignedByWindingNumberSettings & settings );
136
138{
140 float voxelSize = 0;
141
143 float offsetA = 0;
144
146 float offsetB = 0;
147
149 float adaptivity = 0;
150
152 std::shared_ptr<IFastWindingNumber> fwn;
153
157
160
163};
164
167MRVOXELS_API Expected<Mesh> doubleOffsetVdb( const MeshPart& mp, const DoubleOffsetSettings & settings );
168
169} //namespace MR
#define MRVOXELS_API
Definition MRVoxelsFwd.h:13
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:576
Definition MRCameraOrientationPlugin.h:8
MRVOXELS_API Expected< SimpleVolumeMinMax > vdbVolumeToSimpleVolume(const VdbVolume &vdbVolume, const Box3i &activeBox=Box3i(), ProgressCallback cb={})
MRVOXELS_API Expected< SimpleVolumeMinMaxU16 > vdbVolumeToSimpleVolumeU16(const VdbVolume &vdbVolume, const Box3i &activeBox=Box3i(), std::optional< MinMaxf > sourceScale={}, ProgressCallback cb={})
MRVOXELS_API FloatGrid meshToDistanceField(const MeshPart &mp, const AffineXf3f &xf, const Vector3f &voxelSize, float surfaceOffset=3, ProgressCallback cb={})
MRVOXELS_API VdbVolume floatGridToVdbVolume(FloatGrid grid)
MRVOXELS_API VdbVolume simpleVolumeToVdbVolume(const SimpleVolumeMinMax &simpleVolume, ProgressCallback cb={})
std::shared_ptr< OpenVdbFloatGrid > FloatGrid
Definition MRVoxelsFwd.h:25
tl::expected< T, E > Expected
Definition MRExpected.h:58
MRVOXELS_API void evalGridMinMax(const FloatGrid &grid, float &min, float &max)
MRVOXELS_API Expected< SimpleVolumeMinMax > vdbVolumeToSimpleVolumeNorm(const VdbVolume &vdbVolume, const Box3i &activeBox=Box3i(), std::optional< MinMaxf > sourceScale={}, ProgressCallback cb={})
MRVOXELS_API FloatGrid simpleVolumeToDenseGrid(const SimpleVolume &simpleVolume, float background=0.0f, ProgressCallback cb={})
MRVOXELS_API Expected< Mesh > doubleOffsetVdb(const MeshPart &mp, const DoubleOffsetSettings &settings)
MRVOXELS_API Expected< VdbVolume > meshToVolume(const Mesh &mesh, const MeshToVolumeParams &params={})
MRVOXELS_API void putSimpleVolumeInDenseGrid(FloatGrid &grid, const Vector3i &minCoord, const SimpleVolume &simpleVolume, ProgressCallback cb={})
Copy given simpleVolume into the grid, starting at minCoord.
MRVOXELS_API Expected< Mesh > gridToMesh(const FloatGrid &grid, const GridToMeshSettings &settings)
converts OpenVDB Grid into mesh using Dual Marching Cubes algorithm
MRVOXELS_API FloatGrid meshToLevelSet(const MeshPart &mp, const AffineXf3f &xf, const Vector3f &voxelSize, float surfaceOffset=3, ProgressCallback cb={})
MRVOXELS_API Expected< void > makeSignedByWindingNumber(FloatGrid &grid, const Vector3f &voxelSize, const Mesh &refMesh, const MakeSignedByWindingNumberSettings &settings)
set signs for unsigned distance field grid using generalized winding number computed at voxel grid po...
Definition MRVDBConversions.h:138
std::shared_ptr< IFastWindingNumber > fwn
defines particular implementation of IFastWindingNumber interface that will compute windings....
Definition MRVDBConversions.h:152
float voxelSize
the size of voxel in intermediate voxel grid representation
Definition MRVDBConversions.h:140
float offsetB
the amount of second offset
Definition MRVDBConversions.h:146
float windingNumberThreshold
Definition MRVDBConversions.h:156
ProgressCallback progress
to report algorithm's progress and to cancel it
Definition MRVDBConversions.h:162
float adaptivity
in [0; 1] - ratio of combining small triangles into bigger ones (curvature can be lost on high values...
Definition MRVDBConversions.h:149
float offsetA
the amount of first offset
Definition MRVDBConversions.h:143
float windingNumberBeta
determines the precision of fast approximation: the more the better, minimum value is 1
Definition MRVDBConversions.h:159
parameters of OpenVDB Grid to Mesh conversion using Dual Marching Cubes algorithm
Definition MRVDBConversions.h:91
bool relaxDisorientedTriangles
Definition MRVDBConversions.h:102
float adaptivity
adaptivity - [0.0;1.0] ratio of combining small triangles into bigger ones (curvature can be lost on ...
Definition MRVDBConversions.h:97
int maxVertices
if the mesh exceeds this number of vertices, an error returns
Definition MRVDBConversions.h:101
int maxFaces
if the mesh exceeds this number of faces, an error returns
Definition MRVDBConversions.h:99
ProgressCallback cb
to receive progress and request cancellation
Definition MRVDBConversions.h:104
Vector3f voxelSize
the size of each voxel in the grid
Definition MRVDBConversions.h:93
float isoValue
layer of grid with this value would be converted in mesh; isoValue can be negative only in level set ...
Definition MRVDBConversions.h:95
Definition MRVDBConversions.h:115
ProgressCallback progress
to report algorithm's progress and to cancel it
Definition MRVDBConversions.h:130
float windingNumberThreshold
Definition MRVDBConversions.h:124
std::shared_ptr< IFastWindingNumber > fwn
defines particular implementation of IFastWindingNumber interface that will compute windings....
Definition MRVDBConversions.h:120
float windingNumberBeta
determines the precision of fast approximation: the more the better, minimum value is 1
Definition MRVDBConversions.h:127
AffineXf3f meshToGridXf
defines the mapping from mesh reference from to grid reference frame
Definition MRVDBConversions.h:117
Definition MRVDBConversions.h:33
AffineXf3f worldXf
Definition MRVDBConversions.h:42
AffineXf3f * outXf
Definition MRVDBConversions.h:43
Type
Definition MRVDBConversions.h:36
Vector3f voxelSize
Definition MRVDBConversions.h:41
enum MR::MeshToVolumeParams::Type Unsigned
float surfaceOffset
Definition MRVDBConversions.h:40
ProgressCallback cb
Definition MRVDBConversions.h:44
Definition MRMesh/MRMesh.h:23