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
82{
84 int iters = 30;
85
88 int samplePoints = 6;
89
91 int degree = 3;
92
96 float outlierThreshold = 1.f;
97
100
103};
104
105
110template <typename VolumeType = VdbVolume>
112 Mesh& mesh, const AffineXf3f& meshXf,
113 const VolumeType& volume, const AffineXf3f& volumeXf,
114 const MoveMeshToVoxelMaxDerivSettings& settings,
115 ProgressCallback callback = {}
116);
117
118extern template MRVOXELS_API Expected<VertBitSet> moveMeshToVoxelMaxDeriv<VdbVolume>( Mesh& mesh, const AffineXf3f& meshXf,
119 const VdbVolume& volume, const AffineXf3f& volumeXf,
120 const MoveMeshToVoxelMaxDerivSettings& settings,
121 ProgressCallback callback );
123 const SimpleVolumeMinMax& volume, const AffineXf3f& volumeXf,
124 const MoveMeshToVoxelMaxDerivSettings& settings,
125 ProgressCallback callback );
126extern template MRVOXELS_API Expected<VertBitSet> moveMeshToVoxelMaxDeriv<FunctionVolume>( Mesh& mesh, const AffineXf3f& meshXf,
127 const FunctionVolume& volume, const AffineXf3f& volumeXf,
128 const MoveMeshToVoxelMaxDerivSettings& settings,
129 ProgressCallback callback );
130
131
135template <typename MeshType, typename VolumeType>
137{
138public:
139 MRVOXELS_API MeshOnVoxelsT( MeshType& mesh, const AffineXf3f& meshXf, const VolumeType& volume, const AffineXf3f& volumeXf );
141
142 // Access to base data
143 MRVOXELS_API MeshType& mesh() const;
144
145 MRVOXELS_API const VolumeType& volume() const;
146
147
148 // Cached number of valid vertices
150
151 // Voxel size as scalar
152 MRVOXELS_API float voxelSize() const;
153
154
155 // Transformation mesh to volume
156 // All points are in voxels volume space, unless otherwise is implied
157 MRVOXELS_API AffineXf3f xf() const;
158
159 MRVOXELS_API Vector3f xf( const Vector3f& pt ) const;
160
161 MRVOXELS_API AffineXf3f xfInv() const;
162
163 MRVOXELS_API Vector3f xfInv( const Vector3f &pt ) const;
164
165
166 // Vertex position
167 MRVOXELS_API Vector3f point( VertId v ) const;
168
169 // Volume value
170 MRVOXELS_API float getValue( const Vector3f& pos ) const;
171
172 // Get offset vector (mesh normal for a vertex with `voxelSize` length)
173 MRVOXELS_API Vector3f getOffsetVector( VertId v ) const;
174
175 // Get a pseudo-index for a zero-based point index in a zero-centered row of `count` points
176 // Pseudo-index is a signed number; for whole index, is is whole or half-whole
177 MRVOXELS_API static float pseudoIndex( float index, int count );
178
179 MRVOXELS_API static float pseudoIndex( int index, int count );
180
181 MRVOXELS_API static float indexFromPseudoIndex( float pseudoIndex, int count );
182
183 // Get row of points with `offset` stride
184 MRVOXELS_API void getPoints( std::vector<Vector3f>& result, const Vector3f& pos, const Vector3f& offset ) const;
185
186 // Get volume values for a row of points
187 MRVOXELS_API void getValues( std::vector<float>& result, const Vector3f& pos, const Vector3f& offset ) const;
188
189 // Get derivatives from result of `getValues`
190 MRVOXELS_API static void getDerivatives( std::vector<float>& result, const std::vector<float>& values );
191
192 // Get best fit parabola in pseudo-index space for a zero-centered array
193 static Parabolaf getBestParabola( auto begin, auto end )
194 {
195 BestFitParabola<float> bestFitParabola;
196 auto size = std::distance( begin, end );
197 for ( auto it = begin; it != end; ++it )
198 bestFitParabola.addPoint( pseudoIndex( int( it - begin ), int( size ) ), *it );
199 return bestFitParabola.getBestParabola();
200 }
201
202 template <size_t degree>
203 static Polynomialf<degree> getBestPolynomial( const std::vector<float>& values )
204 {
206 for ( size_t i = 0; i < values.size(); ++i )
207 bestFit.addPoint( pseudoIndex( int( i ), int( values.size() ) ), values[i] );
208 auto poly = bestFit.getBestPolynomial().template cast<float>();
209 return poly;
210 }
211
212 MRVOXELS_API static PolynomialWrapperf getBestPolynomial( const std::vector<float>& values, size_t degree );
213
214private:
215 MeshType& mesh_;
216 const VolumeType& volume_;
217 float voxelSize_;
220 AffineXf3f xf_, xfInv_;
221 Matrix3f xfNormal_;
222 bool noXf_; // Xf is unit or translation
223 int numVerts_;
224};
225
226
229
232
235}
#define MRVOXELS_API
Definition MRVoxels/MRVoxelsFwd.h:13
#define MRVOXELS_CLASS
Definition MRVoxels/MRVoxelsFwd.h:14
accumulates a number of (x,y) points to find the best-least-squares parabola approximating them
Definition MRBestFitParabola.h:12
Parabola< T > getBestParabola(T tol=std::numeric_limits< T >::epsilon()) const
computes the best approximating parabola from the accumulated points;
Definition MRBestFitParabola.h:45
void addPoint(T x, T y)
accumulates one more point for parabola fitting
Definition MRBestFitParabola.h:29
Definition MRBestFitPolynomial.h:95
MRMESH_API void addPoint(T x, T y)
MRMESH_API Polynomial< T, degree > getBestPolynomial() const
Definition MRMoveMeshToVoxelMaxDeriv.h:137
MRVOXELS_API MeshType & mesh() const
MRVOXELS_API int numVerts() const
MRVOXELS_API MeshOnVoxelsT(const MeshOnVoxelsT &other)
MRVOXELS_API Vector3f point(VertId v) const
MRVOXELS_API float voxelSize() const
static MRVOXELS_API float pseudoIndex(float index, int count)
MRVOXELS_API void getValues(std::vector< float > &result, const Vector3f &pos, const Vector3f &offset) const
MRVOXELS_API float getValue(const Vector3f &pos) const
static MRVOXELS_API void getDerivatives(std::vector< float > &result, const std::vector< float > &values)
MRVOXELS_API Vector3f xfInv(const Vector3f &pt) const
MRVOXELS_API Vector3f getOffsetVector(VertId v) const
MRVOXELS_API Vector3f xf(const Vector3f &pt) const
static Polynomialf< degree > getBestPolynomial(const std::vector< float > &values)
Definition MRMoveMeshToVoxelMaxDeriv.h:203
MRVOXELS_API const VolumeType & volume() const
static MRVOXELS_API float pseudoIndex(int index, int count)
static Parabolaf getBestParabola(auto begin, auto end)
Definition MRMoveMeshToVoxelMaxDeriv.h:193
MRVOXELS_API void getPoints(std::vector< Vector3f > &result, const Vector3f &pos, const Vector3f &offset) const
MRVOXELS_API MeshOnVoxelsT(MeshType &mesh, const AffineXf3f &meshXf, const VolumeType &volume, const AffineXf3f &volumeXf)
static MRVOXELS_API float indexFromPseudoIndex(float pseudoIndex, int count)
MRVOXELS_API AffineXf3f xfInv() const
MRVOXELS_API AffineXf3f xf() const
static MRVOXELS_API PolynomialWrapperf getBestPolynomial(const std::vector< float > &values, size_t degree)
helper class for generalized voxel volume data access
Definition MRVoxelsVolumeAccess.h:14
Definition MRVolumeInterpolation.h:18
MR_BIND_IGNORE auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:295
MR_BIND_IGNORE auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:297
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:626
MRVOXELS_API Expected< VertBitSet > moveMeshToVoxelMaxDeriv(Mesh &mesh, const AffineXf3f &meshXf, const VolumeType &volume, const AffineXf3f &volumeXf, const MoveMeshToVoxelMaxDerivSettings &settings, ProgressCallback callback={})
template MRVOXELS_API Expected< VertBitSet > moveMeshToVoxelMaxDeriv< SimpleVolumeMinMax >(Mesh &mesh, const AffineXf3f &meshXf, const SimpleVolumeMinMax &volume, const AffineXf3f &volumeXf, const MoveMeshToVoxelMaxDerivSettings &settings, ProgressCallback callback)
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
tl::expected< T, E > Expected
Definition MRExpected.h:59
template MRVOXELS_API Expected< VertBitSet > moveMeshToVoxelMaxDeriv< VdbVolume >(Mesh &mesh, const AffineXf3f &meshXf, const VdbVolume &volume, const AffineXf3f &volumeXf, const MoveMeshToVoxelMaxDerivSettings &settings, ProgressCallback callback)
template MRVOXELS_API Expected< VertBitSet > moveMeshToVoxelMaxDeriv< FunctionVolume >(Mesh &mesh, const AffineXf3f &meshXf, const FunctionVolume &volume, const AffineXf3f &volumeXf, const MoveMeshToVoxelMaxDerivSettings &settings, ProgressCallback callback)
Definition MRMesh/MRMesh.h:23
Definition MRMoveMeshToVoxelMaxDeriv.h:82
float intermediateSmoothForce
force of the smoothing (relaxation) of vector field of shifts on each iteration
Definition MRMoveMeshToVoxelMaxDeriv.h:99
float preparationSmoothForce
force of initial smoothing of vertices, before applying the algorithm
Definition MRMoveMeshToVoxelMaxDeriv.h:102
float outlierThreshold
Definition MRMoveMeshToVoxelMaxDeriv.h:96
int iters
number of iterations. Each iteration moves vertex only slightly and smooths the vector field of shift...
Definition MRMoveMeshToVoxelMaxDeriv.h:84
int samplePoints
Definition MRMoveMeshToVoxelMaxDeriv.h:88
int degree
degree of the polynomial used to fit sampled points. Must be in range [3; 6]
Definition MRMoveMeshToVoxelMaxDeriv.h:91
This is a unifying interface for a polynomial of some degree, known only in runtime.
Definition MRBestFitPolynomial.h:74
Definition MRBestFitPolynomial.h:32