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
31MRMESH_API PreCollapseCallback meshPreCollapseVertAttribute( const Mesh& mesh, const MeshAttributesToUpdate& params );
32
33template <typename T>
35{
36 auto preCollapse = [&] ( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )
37 {
38 const auto org = mesh.topology.org( edgeToCollapse );
39 const auto dest = mesh.topology.dest( edgeToCollapse );
40 const auto orgPos = mesh.orgPnt( edgeToCollapse );
41 const auto destPos = mesh.destPnt( edgeToCollapse );
42
43 const auto ab = destPos - orgPos;
44 const auto dt = dot( newEdgeOrgPos - orgPos, ab );
45 const auto abLengthSq = ab.lengthSq();
46 if ( dt <= 0 )
47 {
48 return true;
49 }
50
51 if ( dt >= abLengthSq )
52 {
53 data[org] = data[dest];
54 return true;
55 }
56
57 const auto ratio = dt / abLengthSq;
58 data[org] = ( 1 - ratio ) * data[org] + ratio * data[dest];
59
60 return true;
61 };
62
63 return preCollapse;
64}
65
66}
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
VertId dest(EdgeId he) const
returns destination vertex of half-edge
Definition MRMeshTopology.h:96
MRMESH_API PreCollapseCallback meshPreCollapseVertAttribute(const Mesh &mesh, const MeshAttributesToUpdate &params)
VertId org(EdgeId he) const
returns origin vertex of half-edge
Definition MRMeshTopology.h:93
auto preCollapseVertAttribute(const Mesh &mesh, Vector< T, VertId > &data)
Definition MRMeshDecimateCallbacks.h:34
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
the attribute data of the mesh that needs to be updated
Definition MRMeshAttributesToUpdate.h:13
Definition MRMesh.h:23
Vector3f orgPnt(EdgeId e) const
returns coordinates of the edge origin
Definition MRMesh.h:62
Vector3f destPnt(EdgeId e) const
returns coordinates of the edge destination
Definition MRMesh.h:65
MeshTopology topology
Definition MRMesh.h:24