MeshLib
 
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{
8// callback that is called when before edge is collapsed
9// (i.e. in decimateMesh) and changes moved vertex attribute to correct value.
10// Useful to update vertices based attributes like uv coordinates or verts colormaps
11template <typename T>
12auto preCollapseVertAttribute( const Mesh& mesh, Vector<T, VertId>& data );
13
29
30template <typename T>
32{
33 auto preCollapse = [&] ( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )
34 {
35 const auto org = mesh.topology.org( edgeToCollapse );
36 const auto dest = mesh.topology.dest( edgeToCollapse );
37 const auto orgPos = mesh.orgPnt( edgeToCollapse );
38 const auto destPos = mesh.destPnt( edgeToCollapse );
39
40 const auto ab = destPos - orgPos;
41 const auto dt = dot( newEdgeOrgPos - orgPos, ab );
42 const auto abLengthSq = ab.lengthSq();
43 if ( dt <= 0 )
44 {
45 return true;
46 }
47
48 if ( dt >= abLengthSq )
49 {
50 data[org] = data[dest];
51 return true;
52 }
53
54 const auto ratio = dt / abLengthSq;
55 data[org] = ( 1 - ratio ) * data[org] + ratio * data[dest];
56
57 return true;
58 };
59
60 return preCollapse;
61}
62
63}
int EdgeId
Definition MRDotNet/MRMeshFwd.h:52
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
VertId dest(EdgeId he) const
returns destination vertex of half-edge
Definition MRMesh/MRMeshTopology.h:80
VertId org(EdgeId he) const
returns origin vertex of half-edge
Definition MRMesh/MRMeshTopology.h:77
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:19
represents a mesh, including topology (connectivity) information and point coordinates,
Definition MRDotNet/MRMesh.h:30
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
Definition MRCameraOrientationPlugin.h:7
MRMESH_API PreCollapseCallback meshPreCollapseVertAttribute(const Mesh &mesh, const MeshAttributesToUpdate &params)
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> PreCollapseCallback
Definition MRMesh/MRMeshFwd.h:417
auto preCollapseVertAttribute(const Mesh &mesh, Vector< T, VertId > &data)
Definition MRMeshDecimateCallbacks.h:31
Definition MRMeshAttributesToUpdate.h:10
Definition MRMesh/MRMesh.h:23
Vector3f orgPnt(EdgeId e) const
returns coordinates of the edge origin
Definition MRMesh/MRMesh.h:62
Vector3f destPnt(EdgeId e) const
returns coordinates of the edge destination
Definition MRMesh/MRMesh.h:65
MeshTopology topology
Definition MRMesh/MRMesh.h:24