MeshLib Documentation
Loading...
Searching...
No Matches
MRMeshSubdivideCallbacks.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 each time edge (e) is split into (e1->e), but before the ring is made Delone
9// (i.e. in subdivideMesh) 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 onEdgeSplitVertAttribute( const Mesh& mesh, Vector<T, VertId>& data );
13
14// callback that is called each time edge (e) is split into (e1->e), but before the ring is made Delone
15// (i.e. in subdivideMesh) and changes moved vertex attribute to correct value.
16// Useful to update face based attributes like texturePerFace or face colors
17template <typename T>
18auto onEdgeSplitFaceAttribute( const Mesh& mesh, Vector<T, FaceId>& data );
19
32
34
36
37template <typename T>
39{
40 auto onEdgeSplit = [&] ( EdgeId e1, EdgeId e )
41 {
42 const auto org = mesh.topology.org( e1 );
43 const auto dest = mesh.topology.dest( e );
44 if ( org < data.size() && dest < data.size() )
45 data.push_back( ( data[org] + data[dest] ) * 0.5f );
46 };
47
48 return onEdgeSplit;
49}
50
51template <typename T>
53{
54 auto onEdgeSplit = [&] ( EdgeId e1, EdgeId e )
55 {
56 // getting a left face for an edge that has been split.
57 auto oldLeft = mesh.topology.left( e );
58 // getting a left face for a new edge that was added during splitting.
59 auto newLeft = mesh.topology.left( e1 );
60
61 if ( newLeft && oldLeft && oldLeft < data.size() )
62 data.autoResizeSet( newLeft, data[oldLeft] );
63
64 // getting a right face for an edge that has been split.
65 auto oldRight = mesh.topology.right( e );
66 // getting a right face for a new edge that was added during splitting.
67 auto newRight = mesh.topology.right( e1 );
68
69 if ( newRight && oldRight && oldRight < data.size() )
70 data.autoResizeSet( newRight, data[oldRight] );
71 };
72
73 return onEdgeSplit;
74}
75
76}
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
FaceId left(EdgeId he) const
returns left face of half-edge
Definition MRMesh/MRMeshTopology.h:92
VertId dest(EdgeId he) const
returns destination vertex of half-edge
Definition MRMesh/MRMeshTopology.h:89
VertId org(EdgeId he) const
returns origin vertex of half-edge
Definition MRMesh/MRMeshTopology.h:86
FaceId right(EdgeId he) const
returns right face of half-edge
Definition MRMesh/MRMeshTopology.h:95
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
std::size_t size() const
Definition MRMesh/MRVector.h:42
void autoResizeSet(I pos, size_t len, T val)
sets elements [pos, pos+len) to given value, adjusting the size of the vector to include new elements
Definition MRMesh/MRVector.h:87
void push_back(const T &t)
Definition MRMesh/MRVector.h:111
Definition MRCameraOrientationPlugin.h:8
MRMESH_API OnEdgeSplit meshOnEdgeSplitVertAttribute(const Mesh &mesh, const MeshAttributesToUpdate &params)
struct MRMESH_CLASS Mesh
Definition MRMesh/MRMeshFwd.h:475
auto onEdgeSplitVertAttribute(const Mesh &mesh, Vector< T, VertId > &data)
Definition MRMeshSubdivideCallbacks.h:38
auto onEdgeSplitFaceAttribute(const Mesh &mesh, Vector< T, FaceId > &data)
Definition MRMeshSubdivideCallbacks.h:52
MRMESH_API OnEdgeSplit meshOnEdgeSplitFaceAttribute(const Mesh &mesh, const MeshAttributesToUpdate &params)
std::function< void(EdgeId e1, EdgeId e)> OnEdgeSplit
Definition MRMesh/MRMeshFwd.h:428
MRMESH_API OnEdgeSplit meshOnEdgeSplitAttribute(const Mesh &mesh, const MeshAttributesToUpdate &params)
Definition MRMeshAttributesToUpdate.h:10
Definition MRMesh/MRMesh.h:23
MeshTopology topology
Definition MRMesh/MRMesh.h:24