MeshLib C++ Docs
Loading...
Searching...
No Matches
MRVoxels/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
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
28 const Vector3f& voxelSize, float surfaceOffset = 3,
29 ProgressCallback cb = {} );
30
31// Parameters structure for meshToVolume function
32struct MeshToVolumeParams
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)
44 ProgressCallback cb;
45};
46
47// eval min max value from FloatGrid
48MRVOXELS_API void evalGridMinMax( const FloatGrid& grid, float& min, float& max );
49
53MRVOXELS_API Expected<VdbVolume> meshToDistanceVdbVolume( const MeshPart& mp, const MeshToVolumeParams& params = {} );
54
59MRVOXELS_API Expected<VdbVolume> meshToVolume( const MeshPart& mp, const MeshToVolumeParams& params = {} );
60
61// fills VdbVolume data from FloatGrid (does not fill voxels size, cause we expect it outside)
63
64// make FloatGrid from SimpleVolume
65// make copy of data
66// background - the new background value for FloatGrid
67// grid can be used to make iso-surface later with gridToMesh function
68MRVOXELS_API FloatGrid simpleVolumeToDenseGrid( const SimpleVolume& simpleVolume, float background = 0.0f, ProgressCallback cb = {} );
69// set the simpleVolume.min as the background value
70MRVOXELS_API VdbVolume simpleVolumeToVdbVolume( const SimpleVolumeMinMax& simpleVolume, ProgressCallback cb = {} );
71
72// make VdbVolume from FunctionVolume
73// make copy of data
74// set minimum value as the background value
75MRVOXELS_API VdbVolume functionVolumeToVdbVolume( const FunctionVolume& functoinVolume, ProgressCallback cb = {} );
76
82template <typename AccessorOrGrid>
84 AccessorOrGrid& gridAccessor,
85 const Vector3i& minCoord, const SimpleVolume& simpleVolume, ProgressCallback cb = {}
86 );
87
88// make SimpleVolume from VdbVolume
89// make copy of data
90MRVOXELS_API Expected<SimpleVolumeMinMax> vdbVolumeToSimpleVolume(
91 const VdbVolume& vdbVolume, const Box3i& activeBox = Box3i(), ProgressCallback cb = {} );
97MRVOXELS_API Expected<SimpleVolumeMinMax> vdbVolumeToSimpleVolumeNorm(
98 const VdbVolume& vdbVolume, const Box3i& activeBox = Box3i(), std::optional<MinMaxf> sourceScale = {}, ProgressCallback cb = {} );
104MRVOXELS_API Expected<SimpleVolumeMinMaxU16> vdbVolumeToSimpleVolumeU16(
105 const VdbVolume& vdbVolume, const Box3i& activeBox = Box3i(), std::optional<MinMaxf> sourceScale = {}, ProgressCallback cb = {} );
106
108struct GridToMeshSettings
109{
111 Vector3f voxelSize;
113 float isoValue = 0;
115 float adaptivity = 0;
117 int maxFaces = INT_MAX;
119 int maxVertices = INT_MAX;
120 bool relaxDisorientedTriangles = true;
122 ProgressCallback cb;
123};
124
126MRVOXELS_API Expected<Mesh> gridToMesh( const FloatGrid& grid, const GridToMeshSettings & settings );
127
130MRVOXELS_API Expected<Mesh> gridToMesh( FloatGrid&& grid, const GridToMeshSettings & settings );
131
133{
136
138 std::shared_ptr<IFastWindingNumber> fwn;
139
142 float windingNumberThreshold = 0.5f;
143
145 float windingNumberBeta = 2;
146
148 ProgressCallback progress;
149};
150
152MRVOXELS_API Expected<void> makeSignedByWindingNumber( FloatGrid& grid, const Vector3f& voxelSize, const Mesh& refMesh,
153 const MakeSignedByWindingNumberSettings & settings );
154
156{
158 float voxelSize = 0;
159
161 float offsetA = 0;
162
164 float offsetB = 0;
165
167 float adaptivity = 0;
168
170 std::shared_ptr<IFastWindingNumber> fwn;
171
174 float windingNumberThreshold = 0.5f;
175
177 float windingNumberBeta = 2;
178
180 ProgressCallback progress;
181};
182
185MRVOXELS_API Expected<Mesh> doubleOffsetVdb( const MeshPart& mp, const DoubleOffsetSettings & settings );
186
187} //namespace MR
#define MRVOXELS_API
Definition MRVoxelsFwd.h:14
Definition MRVoxels/MRVDBConversions.h:156
new unsafe ref float offsetA
new unsafe ref float windingNumberThreshold
new unsafe MR.IFastWindingNumber fwn
new unsafe ref float voxelSize
new unsafe MR.Std.Function_BoolFuncFromFloat progress
new unsafe ref float adaptivity
new unsafe ref float offsetB
new unsafe ref float windingNumberBeta
Definition MRFloatGrid.h:21
Definition MRVoxels/MRVDBConversions.h:109
new unsafe ref float adaptivity
new unsafe ref int maxFaces
new unsafe MR.Std.Function_BoolFuncFromFloat cb
new unsafe ref float isoValue
new unsafe ref MR.Vector3f voxelSize
new unsafe ref int maxVertices
Definition MRVoxels/MRVDBConversions.h:133
new unsafe ref float windingNumberThreshold
new unsafe ref float windingNumberBeta
new unsafe ref MR.AffineXf3f meshToGridXf
new unsafe MR.IFastWindingNumber fwn
new unsafe MR.Std.Function_BoolFuncFromFloat progress
Definition MRVoxels/MRVDBConversions.h:33
Definition MRMesh/MRMesh.h:23
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={})
MRVOXELS_API Expected< VdbVolume > meshToVolume(const MeshPart &mp, const MeshToVolumeParams &params={})
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 Expected< VdbVolume > meshToDistanceVdbVolume(const MeshPart &mp, const MeshToVolumeParams &params={})
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 void putSimpleVolumeInDenseGrid(AccessorOrGrid &gridAccessor, const Vector3i &minCoord, const SimpleVolume &simpleVolume, ProgressCallback cb={})
Copy given simpleVolume into the grid, starting at minCoord Instantiated for AccessorOrGrid in { open...
MRVOXELS_API VdbVolume functionVolumeToVdbVolume(const FunctionVolume &functoinVolume, ProgressCallback cb={})
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...
static MR.Vector3f diagonal(float a)