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
111 Mesh& mesh, const AffineXf3f& meshXf,
112 const VdbVolume& volume, const AffineXf3f& volumeXf,
113 const MoveMeshToVoxelMaxDerivSettings& settings,
114 ProgressCallback callback = {}
115 );
116
117
118
122template <typename MeshType>
124{
125public:
126 MRVOXELS_API MeshOnVoxelsT( MeshType& mesh, const AffineXf3f& meshXf, const VdbVolume& volume, const AffineXf3f& volumeXf );
128
129 // Access to base data
130 MRVOXELS_API MeshType& mesh() const;
131
132 MRVOXELS_API const VdbVolume& volume() const;
133
134
135 // Cached number of valid vertices
137
138 // Voxel size as scalar
139 MRVOXELS_API float voxelSize() const;
140
141
142 // Transformation mesh to volume
143 // All points are in voxels volume space, unless otherwise is implied
144 MRVOXELS_API AffineXf3f xf() const;
145
146 MRVOXELS_API Vector3f xf( const Vector3f& pt ) const;
147
148 MRVOXELS_API AffineXf3f xfInv() const;
149
150 MRVOXELS_API Vector3f xfInv( const Vector3f &pt ) const;
151
152
153 // Vertex position
154 MRVOXELS_API Vector3f point( VertId v ) const;
155
156 // Volume value
157 MRVOXELS_API float getValue( const Vector3f& pos ) const;
158
159 // Get offset vector (mesh normal for a vertex with `voxelSize` length)
160 MRVOXELS_API Vector3f getOffsetVector( VertId v ) const;
161
162 // Get a pseudo-index for a zero-based point index in a zero-centered row of `count` points
163 // Pseudo-index is a signed number; for whole index, is is whole or half-whole
164 MRVOXELS_API static float pseudoIndex( float index, int count );
165
166 MRVOXELS_API static float pseudoIndex( int index, int count );
167
168 MRVOXELS_API static float indexFromPseudoIndex( float pseudoIndex, int count );
169
170 // Get row of points with `offset` stride
171 MRVOXELS_API void getPoints( std::vector<Vector3f>& result, const Vector3f& pos, const Vector3f& offset ) const;
172
173 // Get volume values for a row of points
174 MRVOXELS_API void getValues( std::vector<float>& result, const Vector3f& pos, const Vector3f& offset ) const;
175
176 // Get derivatives from result of `getValues`
177 MRVOXELS_API static void getDerivatives( std::vector<float>& result, const std::vector<float>& values );
178
179 // Get best fit parabola in pseudo-index space for a zero-centered array
180 static Parabolaf getBestParabola( auto begin, auto end )
181 {
182 BestFitParabola<float> bestFitParabola;
183 auto size = std::distance( begin, end );
184 for ( auto it = begin; it != end; ++it )
185 bestFitParabola.addPoint( pseudoIndex( int( it - begin ), int( size ) ), *it );
186 return bestFitParabola.getBestParabola();
187 }
188
189 template <size_t degree>
190 static Polynomialf<degree> getBestPolynomial( const std::vector<float>& values )
191 {
193 for ( size_t i = 0; i < values.size(); ++i )
194 bestFit.addPoint( pseudoIndex( int( i ), int( values.size() ) ), values[i] );
195 auto poly = bestFit.getBestPolynomial().template cast<float>();
196 return poly;
197 }
198
199 MRVOXELS_API static PolynomialWrapperf getBestPolynomial( const std::vector<float>& values, size_t degree );
200
201private:
202 MeshType& mesh_;
203 const VdbVolume& volume_;
204 float voxelSize_;
207 AffineXf3f xf_, xfInv_;
208 Matrix3f xfNormal_;
209 bool noXf_; // Xf is unit or translation
210 int numVerts_;
211};
212
213
216
217
218}
#define MRVOXELS_API
Definition MRVoxels/MRVoxelsFwd.h:13
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:124
MRVOXELS_API AffineXf3f xf() const
MRVOXELS_API void getPoints(std::vector< Vector3f > &result, const Vector3f &pos, const Vector3f &offset) const
static Parabolaf getBestParabola(auto begin, auto end)
Definition MRMoveMeshToVoxelMaxDeriv.h:180
MRVOXELS_API Vector3f point(VertId v) const
MRVOXELS_API int numVerts() const
static MRVOXELS_API PolynomialWrapperf getBestPolynomial(const std::vector< float > &values, size_t degree)
MRVOXELS_API float getValue(const Vector3f &pos) const
MRVOXELS_API MeshType & mesh() const
MRVOXELS_API const VdbVolume & volume() const
MRVOXELS_API void getValues(std::vector< float > &result, const Vector3f &pos, const Vector3f &offset) const
MRVOXELS_API Vector3f getOffsetVector(VertId v) const
MRVOXELS_API Vector3f xfInv(const Vector3f &pt) const
MRVOXELS_API float voxelSize() const
static MRVOXELS_API float indexFromPseudoIndex(float pseudoIndex, int count)
static MRVOXELS_API float pseudoIndex(float index, int count)
MRVOXELS_API MeshOnVoxelsT(MeshType &mesh, const AffineXf3f &meshXf, const VdbVolume &volume, const AffineXf3f &volumeXf)
MRVOXELS_API Vector3f xf(const Vector3f &pt) const
MRVOXELS_API MeshOnVoxelsT(const MeshOnVoxelsT &other)
static MRVOXELS_API float pseudoIndex(int index, int count)
static MRVOXELS_API void getDerivatives(std::vector< float > &result, const std::vector< float > &values)
static Polynomialf< degree > getBestPolynomial(const std::vector< float > &values)
Definition MRMoveMeshToVoxelMaxDeriv.h:190
MRVOXELS_API AffineXf3f xfInv() const
helper class for generalized voxel volume data access
Definition MRVoxelsVolumeAccess.h:14
Definition MRVolumeInterpolation.h:18
auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:286
auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:288
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:600
MRVOXELS_API Expected< VertBitSet > moveMeshToVoxelMaxDeriv(Mesh &mesh, const AffineXf3f &meshXf, const VdbVolume &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:58
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