MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMeshDecimateCallbacks.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMesh.h"
5
6namespace MR
7{
10
14template <typename T>
15auto preCollapseVertAttribute( const Mesh& mesh, Vector<T, VertId>& data );
16
34
35template <typename T>
37{
38 auto preCollapse = [&] ( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )
39 {
40 const auto org = mesh.topology.org( edgeToCollapse );
41 const auto dest = mesh.topology.dest( edgeToCollapse );
42 const auto orgPos = mesh.orgPnt( edgeToCollapse );
43 const auto destPos = mesh.destPnt( edgeToCollapse );
44
45 const auto ab = destPos - orgPos;
46 const auto dt = dot( newEdgeOrgPos - orgPos, ab );
47 const auto abLengthSq = ab.lengthSq();
48 if ( dt <= 0 )
49 {
50 return true;
51 }
52
53 if ( dt >= abLengthSq )
54 {
55 data[org] = data[dest];
56 return true;
57 }
58
59 const auto ratio = dt / abLengthSq;
60 data[org] = ( 1 - ratio ) * data[org] + ratio * data[dest];
61
62 return true;
63 };
64
65 return preCollapse;
66}
67
68}
#define MRMESH_API
Definition MRMeshFwd.h:85
Vector<T> is indexed by size_t.
Definition MRVector.h:24
PreCollapseCallback meshPreCollapseVertAttribute(const Mesh &mesh, const MeshAttributesToUpdate &params)
auto dot(const Matrix2< T > &a, const Matrix2< T > &b) -> decltype(dot(a.x, b.x))
double-dot product: x = a : b
Definition MRMatrix2.h:142
VertId dest(EdgeId he) const
returns destination vertex of half-edge
Definition MRMeshTopology.h:112
VertId org(EdgeId he) const
returns origin vertex of half-edge
Definition MRMeshTopology.h:109
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> PreCollapseCallback
Definition MRMeshFwd.h:596
auto preCollapseVertAttribute(const Mesh &mesh, Vector< T, VertId > &data)
Definition MRMeshDecimateCallbacks.h:36
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
the attribute data of the mesh that needs to be updated
Definition MRMeshAttributesToUpdate.h:13
Definition MRMesh.h:24
Vector3f orgPnt(EdgeId e) const
returns coordinates of the edge origin
Definition MRMesh.h:72
Vector3f destPnt(EdgeId e) const
returns coordinates of the edge destination
Definition MRMesh.h:75
MeshTopology topology
Definition MRMesh.h:25