MeshLib
 
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}
int EdgeId
Definition MRDotNet/MRMeshFwd.h:52
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
FaceId left(EdgeId he) const
returns left face of half-edge
Definition MRMesh/MRMeshTopology.h:83
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
FaceId right(EdgeId he) const
returns right face of half-edge
Definition MRMesh/MRMeshTopology.h:86
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:19
std::size_t size() const
Definition MRMesh/MRVector.h:40
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:85
void push_back(const T &t)
Definition MRMesh/MRVector.h:109
represents a mesh, including topology (connectivity) information and point coordinates,
Definition MRDotNet/MRMesh.h:30
Definition MRCameraOrientationPlugin.h:7
MRMESH_API OnEdgeSplit meshOnEdgeSplitVertAttribute(const Mesh &mesh, const MeshAttributesToUpdate &params)
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:418
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