MeshLib C++ Docs
Loading...
Searching...
No Matches
MRFillingSurface.h
Go to the documentation of this file.
1#pragma once
2
3#include <MRMesh/MRMeshFwd.h>
4#include <MRMesh/MRExpected.h>
5#include <MRMesh/MRVector3.h>
7
8#include <variant>
9#include <optional>
10
12{
13
14namespace TPMS // Triply Periodic Minimal Surface
15{
16
17
19enum class Type : int
20{
25
26 Count
27};
28
30MRVOXELS_API std::vector<std::string> getTypeNames();
31
33MRVOXELS_API std::vector<std::string> getTypeTooltips();
34
37
38
40{
41 Type type = Type::SchwartzP; // Type of the surface
42 float frequency = 1.f; // Frequency of oscillations (determines size of the "cells" in the "grid")
43 float resolution = 5.f; // Ratio `n / T`, between the number of voxels and period of oscillations
44};
45
47{
48 float iso = 0.f;
49 bool decimate = false;
50};
51
55MRVOXELS_API FunctionVolume buildVolume( const Vector3f& size, const VolumeParams& params );
56
58MRVOXELS_API Expected<Mesh> build( const Vector3f& size, const MeshParams& params, ProgressCallback cb = {} );
59
61MRVOXELS_API Expected<Mesh> fill( const Mesh& mesh, const MeshParams& params, ProgressCallback cb = {} );
62
64MRVOXELS_API size_t getNumberOfVoxels( const Mesh& mesh, float frequency, float resolution );
65
67MRVOXELS_API size_t getNumberOfVoxels( const Vector3f& size, float frequency, float resolution );
68
72MRVOXELS_API float estimateIso( Type type, float targetDensity );
73
77MRVOXELS_API float estimateDensity( Type type, float targetIso );
78
80MRVOXELS_API float getMinimalResolution( Type type, float iso );
81
82} // namespace TPMS
83
84
85
86namespace CellularSurface // Surface of cylinders in a grid
87{
88
89struct Params
90{
91 Vector3f period = Vector3f::diagonal( 1.f );
92 Vector3f width = Vector3f::diagonal( 0.3f );
93 float r = 0.4f;
94
95 // used in tests in order to make surfaces close to their analytical expression
96 // recommended to be false for real usage for better performance
97 bool highRes = false;
98
99};
100
102MRVOXELS_API Expected<Mesh> build( const Vector3f& size, const Params& params, const ProgressCallback& cb = {} );
103
105MRVOXELS_API Expected<Mesh> fill( const Mesh& mesh, const Params& params, const ProgressCallback& cb = {} );
106
108MRVOXELS_API float estimateDensity( float period, float width, float r );
109
112// Due to the simplification of the formula (sphere must either fully contain the intersection of cylinders or be inside it), solution not always exists.
113MRVOXELS_API std::optional<float> estimateWidth( float period, float r, float targetDensity );
114
115}
116
117
118// Different kinds of filling surface
119enum class Kind : int
120{
121 TPMS = 0,
123};
124MRVOXELS_API std::vector<std::string> getKindNames();
125
126using MeshParamsRef = std::variant
127 < std::reference_wrapper<TPMS::MeshParams>
128 , std::reference_wrapper<CellularSurface::Params>
129 >;
130
131using ConstMeshParamsRef = std::variant
132 < std::reference_wrapper<const TPMS::MeshParams>
133 , std::reference_wrapper<const CellularSurface::Params>
134 >;
135
139
140} // namespace FillingSurface
#define MRVOXELS_API
Definition MRVoxels/MRVoxelsFwd.h:13
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:729
auto width(const Box< V > &box)
returns size along x axis
Definition MRMesh/MRBox.h:341
MRVOXELS_API float estimateDensity(float period, float width, float r)
Estimate the density of the cellular surface.
MRVOXELS_API Expected< Mesh > fill(const Mesh &mesh, const Params &params, const ProgressCallback &cb={})
Fill given mesh with a cellular surface.
MRVOXELS_API std::optional< float > estimateWidth(float period, float r, float targetDensity)
MRVOXELS_API Expected< Mesh > build(const Vector3f &size, const Params &params, const ProgressCallback &cb={})
Build a cellular surface of size size.
MRVOXELS_API float estimateIso(Type type, float targetDensity)
MRVOXELS_API std::vector< std::string > getTypeTooltips()
Returns the tooltips for each type of filling.
MRVOXELS_API bool isThick(Type type)
Returns true if the type is thick.
MRVOXELS_API size_t getNumberOfVoxels(const Mesh &mesh, float frequency, float resolution)
Returns number of voxels that would be used to perform fillWithTPMS.
Type
Supported types of TPMS (Triply Periodic Minimal Surfaces)
Definition MRFillingSurface.h:20
MRVOXELS_API float getMinimalResolution(Type type, float iso)
Returns minimal reasonable resolution for given parameters.
MRVOXELS_API Expected< Mesh > build(const Vector3f &size, const MeshParams &params, ProgressCallback cb={})
Constructs TPMS level-set and then convert it to mesh.
MRVOXELS_API Expected< Mesh > fill(const Mesh &mesh, const MeshParams &params, ProgressCallback cb={})
Constructs TPMS-filling for the given mesh.
MRVOXELS_API FunctionVolume buildVolume(const Vector3f &size, const VolumeParams &params)
MRVOXELS_API float estimateDensity(Type type, float targetIso)
MRVOXELS_API std::vector< std::string > getTypeNames()
Returns the names for each type of filling.
Definition MRFillingSurface.h:12
std::variant< std::reference_wrapper< const TPMS::MeshParams >, std::reference_wrapper< const CellularSurface::Params > > ConstMeshParamsRef
Definition MRFillingSurface.h:131
Kind
Definition MRFillingSurface.h:120
MRVOXELS_API std::vector< std::string > getKindNames()
std::variant< std::reference_wrapper< TPMS::MeshParams >, std::reference_wrapper< CellularSurface::Params > > MeshParamsRef
Definition MRFillingSurface.h:126
MR_BIND_IGNORE MRVOXELS_API Expected< Mesh > build(const Vector3f &size, ConstMeshParamsRef params, ProgressCallback cb={})
Unified functions to build and fill using the specified filling structures.
MR_BIND_IGNORE MRVOXELS_API Expected< Mesh > fill(const Mesh &mesh, ConstMeshParamsRef params, ProgressCallback cb={})
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:29
tl::expected< T, E > Expected
Definition MRExpected.h:25
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:10
Definition MRFillingSurface.h:90
float r
the radius of uniting spheres
Definition MRFillingSurface.h:93
Vector3f period
the distance between consecutive cylinders in each direction
Definition MRFillingSurface.h:91
Vector3f width
the width of cylinders in each direction
Definition MRFillingSurface.h:92
bool highRes
Definition MRFillingSurface.h:97
Definition MRFillingSurface.h:47
bool decimate
Definition MRFillingSurface.h:49
float iso
Definition MRFillingSurface.h:48
Definition MRFillingSurface.h:40
float resolution
Definition MRFillingSurface.h:43
Type type
Definition MRFillingSurface.h:41
float frequency
Definition MRFillingSurface.h:42
Definition MRMesh/MRMesh.h:23