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{
21 SchwartzP,
22 ThickSchwartzP,
23 DoubleGyroid,
24 ThickGyroid,
25
26 Count
27};
28
30MRVOXELS_API std::vector<std::string> getTypeNames();
31
33MRVOXELS_API std::vector<std::string> getTypeTooltips();
34
36MRVOXELS_API bool isThick( Type type );
37
38
39struct VolumeParams
40{
41 Type type = Type::ThickGyroid; // 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
46struct MeshParams : VolumeParams
47{
48 float iso = 0.6f;
49 bool decimate = true;
50};
51
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
90enum class Type : int
91{
92 Cylinder = 0,
93 Rect
94};
95
96struct Params
97{
98 Type type = Type::Cylinder;
101 float r = 0.f;
102
103 // used in tests in order to make surfaces close to their analytical expression
104 // recommended to be false for real usage for better performance
105 bool highRes = false;
106
107 // Used in tests for roughly the same purpose: the computations of density estimation are made under the assumption of an infinite surface.
108 // Thus, we must impose "boundary conditions" that inflict the "tips" of the bars (cylinders or cubes) to be preserved on the boundary of the
109 // generated filling surface. However, for the aesthetic reasons, it was requested that the tips must be cut in the UI. And here comes this flag.
110 // Note that for the estimation of density in UI the influence of "tips" is not significant (it tends to zero with growing size), however
111 // we cannot afford to run tests on too big surfaces as it takes too long.
112 bool preserveTips = false;
113};
115MRVOXELS_API std::vector<std::string> getTypeNames();
116
117
119MRVOXELS_API Expected<Mesh> build( const Vector3f& size, const Params& params, const ProgressCallback& cb = {} );
120
122MRVOXELS_API Expected<Mesh> fill( const Mesh& mesh, const Params& params, const ProgressCallback& cb = {} );
123
125MRVOXELS_API float estimateDensity( float period, float width, float r );
126
129// Due to the simplification of the formula (sphere must either fully contain the intersection of cylinders or be inside it), solution not always exists.
130MRVOXELS_API std::optional<float> estimateWidth( float period, float r, float targetDensity );
131
132}
133
134
135// Different kinds of filling surface
136enum class Kind : int
137{
138 TPMS = 0,
139 Cellular
140};
141MRVOXELS_API std::vector<std::string> getKindNames();
142
143using MeshParamsRef = std::variant
144 < std::reference_wrapper<TPMS::MeshParams>
145 , std::reference_wrapper<CellularSurface::Params>
146 >;
147
148using ConstMeshParamsRef = std::variant
149 < std::reference_wrapper<const TPMS::MeshParams>
150 , std::reference_wrapper<const CellularSurface::Params>
151 >;
152
154MR_BIND_IGNORE MRVOXELS_API Expected<Mesh> build( const Vector3f& size, ConstMeshParamsRef params, ProgressCallback cb = {} );
155MR_BIND_IGNORE MRVOXELS_API Expected<Mesh> fill( const Mesh& mesh, ConstMeshParamsRef params, ProgressCallback cb = {} );
156
157
159template <typename T>
160struct MR_BIND_IGNORE ParamsFacade
161{
163
165 {
166 return std::visit( overloaded{
167 [] ( const TPMS::MeshParams& p ){ return Vector3f::diagonal( 1.f / p.frequency ); },
168 [] ( const CellularSurface::Params& p ) { return p.period; }
169 }, params );
170 }
171};
172
175
176} // namespace FillingSurface
#define MRVOXELS_API
Definition MRVoxelsFwd.h:14
Definition MRFillingSurface.h:97
new unsafe ref MR.FillingSurface.CellularSurface.Type type
Definition MRFillingSurface.h:47
Definition MRFillingSurface.h:40
Definition MRMesh/MRMesh.h:23
auto width(const Box< V > &box)
returns size along x axis
Definition MRMesh/MRBox.h:354
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 std::vector< std::string > getTypeNames()
Returns the names for each type of filling.
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.
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
ParamsFacade(MeshParamsRef) -> ParamsFacade< MeshParamsRef >
MRVOXELS_API std::vector< std::string > getKindNames()
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
A helper to access parameters common for different kind of surfaces.
Definition MRFillingSurface.h:161
Vector3f getPeriod() const
Definition MRFillingSurface.h:164
T params
Definition MRFillingSurface.h:162
static MR.Vector3f diagonal(float a)
Definition MRMeshFwd.h:774