MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMoveMeshToVoxelMaxDeriv.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVoxelsFwd.h"
4
7#include "MRMesh/MRMatrix3.h"
8#include "MRMesh/MRAffineXf.h"
11
12
13namespace MR
14{
15
78
81
84{
86 int iters = 30;
87
90 int samplePoints = 6;
91
93 int degree = 3;
94
98 float outlierThreshold = 1.f;
99
102
105};
106
107
112template <typename VolumeType = VdbVolume>
114 Mesh& mesh, const AffineXf3f& meshXf,
115 const VolumeType& volume, const AffineXf3f& volumeXf,
116 const MoveMeshToVoxelMaxDerivSettings& settings,
117 ProgressCallback callback = {}
118);
119
120extern template MRVOXELS_API Expected<VertBitSet> moveMeshToVoxelMaxDeriv<VdbVolume>( Mesh& mesh, const AffineXf3f& meshXf,
121 const VdbVolume& volume, const AffineXf3f& volumeXf,
122 const MoveMeshToVoxelMaxDerivSettings& settings,
123 ProgressCallback callback );
125 const SimpleVolumeMinMax& volume, const AffineXf3f& volumeXf,
126 const MoveMeshToVoxelMaxDerivSettings& settings,
127 ProgressCallback callback );
128extern template MRVOXELS_API Expected<VertBitSet> moveMeshToVoxelMaxDeriv<FunctionVolume>( Mesh& mesh, const AffineXf3f& meshXf,
129 const FunctionVolume& volume, const AffineXf3f& volumeXf,
130 const MoveMeshToVoxelMaxDerivSettings& settings,
131 ProgressCallback callback );
132
133
137template <typename MeshType, typename VolumeType>
139{
140public:
141 MRVOXELS_API MeshOnVoxelsT( MeshType& mesh, const AffineXf3f& meshXf, const VolumeType& volume, const AffineXf3f& volumeXf );
143
145 MRVOXELS_API MeshType& mesh() const;
146
147 MRVOXELS_API const VolumeType& volume() const;
148
149
152
154 MRVOXELS_API float voxelSize() const;
155
156
159 MRVOXELS_API AffineXf3f xf() const;
160
161 MRVOXELS_API Vector3f xf( const Vector3f& pt ) const;
162
163 MRVOXELS_API AffineXf3f xfInv() const;
164
165 MRVOXELS_API Vector3f xfInv( const Vector3f &pt ) const;
166
167
169 MRVOXELS_API Vector3f point( VertId v ) const;
170
172 MRVOXELS_API float getValue( const Vector3f& pos ) const;
173
175 MRVOXELS_API Vector3f getOffsetVector( VertId v ) const;
176
179 MRVOXELS_API static float pseudoIndex( float index, int count );
180
181 MRVOXELS_API static float pseudoIndex( int index, int count );
182
183 MRVOXELS_API static float indexFromPseudoIndex( float pseudoIndex, int count );
184
186 MRVOXELS_API void getPoints( std::vector<Vector3f>& result, const Vector3f& pos, const Vector3f& offset ) const;
187
189 MRVOXELS_API void getValues( std::vector<float>& result, const Vector3f& pos, const Vector3f& offset ) const;
190
192 MRVOXELS_API static void getDerivatives( std::vector<float>& result, const std::vector<float>& values );
193
195 static Parabolaf getBestParabola( auto begin, auto end )
196 {
197 BestFitParabola<float> bestFitParabola;
198 auto size = std::distance( begin, end );
199 for ( auto it = begin; it != end; ++it )
200 bestFitParabola.addPoint( pseudoIndex( int( it - begin ), int( size ) ), *it );
201 return bestFitParabola.getBestParabola();
202 }
203
204 template <size_t degree>
205 static Polynomialf<degree> getBestPolynomial( const std::vector<float>& values )
206 {
208 for ( size_t i = 0; i < values.size(); ++i )
209 bestFit.addPoint( pseudoIndex( int( i ), int( values.size() ) ), values[i] );
210 auto poly = bestFit.getBestPolynomial().template cast<float>();
211 return poly;
212 }
213
214 MRVOXELS_API static PolynomialWrapperf getBestPolynomial( const std::vector<float>& values, size_t degree );
215
216private:
217 MeshType& mesh_;
218 const VolumeType& volume_;
219 float voxelSize_;
222 AffineXf3f xf_, xfInv_;
223 Matrix3f xfNormal_;
224 bool noXf_;
225 int numVerts_;
226};
227
228
231
234
237
239
240}
#define MRVOXELS_API
see explanation in MRMesh/MRMeshFwd.h
Definition MRVoxelsFwd.h:14
#define MRVOXELS_CLASS
Definition MRVoxelsFwd.h:18
accumulates a number of (x,y) points to find the best-least-squares parabola approximating them
Definition MRBestFitParabola.h:15
Definition MRBestFitPolynomial.h:98
Definition MRMoveMeshToVoxelMaxDeriv.h:139
int numVerts() const
Cached number of valid vertices.
AffineXf3f xfInv() const
void getPoints(std::vector< Vector3f > &result, const Vector3f &pos, const Vector3f &offset) const
Get row of points with offset stride.
static PolynomialWrapperf getBestPolynomial(const std::vector< float > &values, size_t degree)
Vector3f getOffsetVector(VertId v) const
Get offset vector (mesh normal for a vertex with voxelSize length)
Vector3f xfInv(const Vector3f &pt) const
Vector3f point(VertId v) const
Vertex position.
static float indexFromPseudoIndex(float pseudoIndex, int count)
void getValues(std::vector< float > &result, const Vector3f &pos, const Vector3f &offset) const
Get volume values for a row of points.
static float pseudoIndex(float index, int count)
AffineXf3f xf() const
static Polynomialf< degree > getBestPolynomial(const std::vector< float > &values)
Definition MRMoveMeshToVoxelMaxDeriv.h:205
MeshOnVoxelsT(const MeshOnVoxelsT &other)
MeshOnVoxelsT(MeshType &mesh, const AffineXf3f &meshXf, const VolumeType &volume, const AffineXf3f &volumeXf)
static void getDerivatives(std::vector< float > &result, const std::vector< float > &values)
Get derivatives from result of getValues
static Parabolaf getBestParabola(auto begin, auto end)
Get best fit parabola in pseudo-index space for a zero-centered array.
Definition MRMoveMeshToVoxelMaxDeriv.h:195
float getValue(const Vector3f &pos) const
Volume value.
float voxelSize() const
Voxel size as scalar.
const VdbVolume & volume() const
Vector3f xf(const Vector3f &pt) const
static float pseudoIndex(int index, int count)
helper class for generalized voxel volume data access
Definition MRVoxelsVolumeAccess.h:17
Definition MRVolumeInterpolation.h:21
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:753
void addPoint(T x, T y)
double volume(const MeshTopology &topology, const VertCoords &points, const FaceBitSet *region=nullptr)
Polynomial< T, degree > getBestPolynomial() const
MRVOXELS_CLASS SimpleVolumeMinMax
Definition MRVoxelsFwd.h:35
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
MRVOXELS_CLASS FunctionVolume
Definition MRVoxelsFwd.h:46
Parabola< T > getBestParabola(T tol=std::numeric_limits< T >::epsilon()) const
computes the best approximating parabola from the accumulated points;
Definition MRBestFitParabola.h:48
tl::expected< T, E > Expected
Definition MRExpected.h:31
void addPoint(T x, T y)
accumulates one more point for parabola fitting
Definition MRBestFitParabola.h:32
PolynomialWrapper< float > PolynomialWrapperf
Definition MRBestFitPolynomial.h:92
Parabolaf
Definition MRMeshFwd.h:356
Polynomial< float, degree > Polynomialf
Definition MRBestFitPolynomial.h:57
@ other
Angle, normally float. Measure in radians.
Definition MRFeatureObject.h:27
Expected< VertBitSet > moveMeshToVoxelMaxDeriv(Mesh &mesh, const AffineXf3f &meshXf, const VolumeType &volume, const AffineXf3f &volumeXf, const MoveMeshToVoxelMaxDerivSettings &settings, ProgressCallback callback={})
auto begin(ViewportMask mask)
Definition MRViewportId.h:122
auto end(ViewportMask)
Definition MRViewportId.h:124
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
MeshOnVoxelsT< Mesh, FunctionVolume > MeshOnVoxelsFunction
Definition MRMoveMeshToVoxelMaxDeriv.h:235
MeshOnVoxelsT< const Mesh, SimpleVolumeMinMax > MeshOnVoxelsSimpleC
Definition MRMoveMeshToVoxelMaxDeriv.h:233
MeshOnVoxelsT< const Mesh, FunctionVolume > MeshOnVoxelsFunctionC
Definition MRMoveMeshToVoxelMaxDeriv.h:236
template Expected< VertBitSet > moveMeshToVoxelMaxDeriv< VdbVolume >(Mesh &mesh, const AffineXf3f &meshXf, const VdbVolume &volume, const AffineXf3f &volumeXf, const MoveMeshToVoxelMaxDerivSettings &settings, ProgressCallback callback)
MeshOnVoxelsT< Mesh, VdbVolume > MeshOnVoxelsVdb
Definition MRMoveMeshToVoxelMaxDeriv.h:229
MeshOnVoxelsT< Mesh, SimpleVolumeMinMax > MeshOnVoxelsSimple
Definition MRMoveMeshToVoxelMaxDeriv.h:232
MeshOnVoxelsT< const Mesh, VdbVolume > MeshOnVoxelsVdbC
Definition MRMoveMeshToVoxelMaxDeriv.h:230
template Expected< VertBitSet > moveMeshToVoxelMaxDeriv< SimpleVolumeMinMax >(Mesh &mesh, const AffineXf3f &meshXf, const SimpleVolumeMinMax &volume, const AffineXf3f &volumeXf, const MoveMeshToVoxelMaxDerivSettings &settings, ProgressCallback callback)
template Expected< VertBitSet > moveMeshToVoxelMaxDeriv< FunctionVolume >(Mesh &mesh, const AffineXf3f &meshXf, const FunctionVolume &volume, const AffineXf3f &volumeXf, const MoveMeshToVoxelMaxDerivSettings &settings, ProgressCallback callback)
Definition MRMesh.h:23
Definition MRMoveMeshToVoxelMaxDeriv.h:84
float intermediateSmoothForce
force of the smoothing (relaxation) of vector field of shifts on each iteration
Definition MRMoveMeshToVoxelMaxDeriv.h:101
float preparationSmoothForce
force of initial smoothing of vertices, before applying the algorithm
Definition MRMoveMeshToVoxelMaxDeriv.h:104
float outlierThreshold
Definition MRMoveMeshToVoxelMaxDeriv.h:98
int iters
number of iterations. Each iteration moves vertex only slightly and smooths the vector field of shift...
Definition MRMoveMeshToVoxelMaxDeriv.h:86
int samplePoints
Definition MRMoveMeshToVoxelMaxDeriv.h:90
int degree
degree of the polynomial used to fit sampled points. Must be in range [3; 6]
Definition MRMoveMeshToVoxelMaxDeriv.h:93