MeshLib
 
Loading...
Searching...
No Matches
MRMarchingCubes.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVoxelsFwd.h"
5#include "MRVoxelsVolume.h"
8#include "MRMesh/MRExpected.h"
9#include <climits>
10
11namespace MR
12{
13
14// Callback type for positioning marching cubes vertices
15// args: position0, position1, value0, value1, iso
16using VoxelPointPositioner = std::function<Vector3f( const Vector3f&, const Vector3f&, float, float, float )>;
17
19{
22
25
27 float iso{ 0.0f };
28
30 bool lessInside{ false };
31
34
39
41 int maxVertices = INT_MAX;
42
55
57 std::function<void()> freeVolume;
58};
59
60// makes Mesh from SimpleVolume with given settings using Marching Cubes algorithm
61MRVOXELS_API Expected<Mesh> marchingCubes( const SimpleVolume& volume, const MarchingCubesParams& params = {} );
62MRVOXELS_API Expected<TriMesh> marchingCubesAsTriMesh( const SimpleVolume& volume, const MarchingCubesParams& params = {} );
63
64// makes Mesh from SimpleVolumeMinMax with given settings using Marching Cubes algorithm
65MRVOXELS_API Expected<Mesh> marchingCubes( const SimpleVolumeMinMax& volume, const MarchingCubesParams& params = {} );
66MRVOXELS_API Expected<TriMesh> marchingCubesAsTriMesh( const SimpleVolumeMinMax& volume, const MarchingCubesParams& params = {} );
67
68// makes Mesh from VdbVolume with given settings using Marching Cubes algorithm
69MRVOXELS_API Expected<Mesh> marchingCubes( const VdbVolume& volume, const MarchingCubesParams& params = {} );
70MRVOXELS_API Expected<TriMesh> marchingCubesAsTriMesh( const VdbVolume& volume, const MarchingCubesParams& params = {} );
71
72// makes Mesh from FunctionVolume with given settings using Marching Cubes algorithm
73MRVOXELS_API Expected<Mesh> marchingCubes( const FunctionVolume& volume, const MarchingCubesParams& params = {} );
74MRVOXELS_API Expected<TriMesh> marchingCubesAsTriMesh( const FunctionVolume& volume, const MarchingCubesParams& params = {} );
75
85{
86public:
89 MRVOXELS_API explicit MarchingCubesByParts( const Vector3i & dims, const MarchingCubesParams& params, int layersPerBlock = 0 );
90
94
97
99 MRVOXELS_API int nextZ() const;
100
102 MRVOXELS_API Expected<void> addPart( const SimpleVolume& part );
103
106
107private:
108 struct Impl;
109 std::unique_ptr<Impl> impl_;
110};
111
112} //namespace MR
#define MRVOXELS_API
Definition MRVoxelsFwd.h:13
Definition MRMarchingCubes.h:85
MRVOXELS_API Expected< TriMesh > finalize()
finishes processing and outputs produced trimesh
MRVOXELS_API int layersPerBlock() const
the number of z-slices of the volume in the blocks
MRVOXELS_API MarchingCubesByParts(const Vector3i &dims, const MarchingCubesParams &params, int layersPerBlock=0)
MRVOXELS_API Expected< void > addPart(const SimpleVolume &part)
adds one more part of volume into consideration, with first z=nextZ()
MRVOXELS_API ~MarchingCubesByParts()
MRVOXELS_API MarchingCubesByParts & operator=(MarchingCubesByParts &&s) noexcept
MRVOXELS_API int nextZ() const
the last z-layer of the previous part and the first z-layer of the next part
MRVOXELS_API MarchingCubesByParts(MarchingCubesByParts &&s) noexcept
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:19
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:571
Definition MRCameraOrientationPlugin.h:8
Vector3< float > Vector3f
Definition MRDotNet/MRMeshFwd.h:8
tl::expected< T, E > Expected
Definition MRExpected.h:58
MRVOXELS_API Expected< Mesh > marchingCubes(const SimpleVolume &volume, const MarchingCubesParams &params={})
MRVOXELS_API Expected< TriMesh > marchingCubesAsTriMesh(const SimpleVolume &volume, const MarchingCubesParams &params={})
std::function< Vector3f(const Vector3f &, const Vector3f &, float, float, float)> VoxelPointPositioner
Definition MRMarchingCubes.h:16
Definition MRMarchingCubes.h:19
std::function< void()> freeVolume
this optional function is called when volume is no longer needed to deallocate it and reduce peak mem...
Definition MRMarchingCubes.h:57
Vector3f origin
origin point of voxels box in 3D space with output mesh
Definition MRMarchingCubes.h:21
int maxVertices
if the mesh exceeds this number of vertices, an error returns
Definition MRMarchingCubes.h:41
enum MR::MarchingCubesParams::CachingMode cachingMode
CachingMode
Definition MRMarchingCubes.h:46
@ Normal
allocates 2 full slices per parallel thread
VoxelPointPositioner positioner
Definition MRMarchingCubes.h:38
ProgressCallback cb
progress callback
Definition MRMarchingCubes.h:24
bool lessInside
should be false for dense volumes, and true for distance volume
Definition MRMarchingCubes.h:30
float iso
target iso-value of the surface to be extracted from volume
Definition MRMarchingCubes.h:27
Vector< VoxelId, FaceId > * outVoxelPerFaceMap
optional output map FaceId->VoxelId
Definition MRMarchingCubes.h:33