Skip to content

Commit

Permalink
[core, tests] Topo: use wedges function, remove props. WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyr committed Jul 22, 2020
1 parent 6013fca commit 3a3bf02
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 143 deletions.
138 changes: 0 additions & 138 deletions src/Core/Geometry/TopologicalMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,144 +349,6 @@ void TopologicalMesh::updateTriangleMesh( Ra::Core::Geometry::TriangleMesh& /*me
///\todo ;)
}

bool TopologicalMesh::splitEdge( TopologicalMesh::EdgeHandle eh, Scalar f ) {
// Global schema of operation
/*
TRIANGLES ONLY
before after
A A
/ F0 \ / F2 | F0 \
/ \ / | \
/h1 h0\ /h1 e2|e0 h0\
/ he0 \ / he2 | he0 \
V1 -------- V0 V1 ------ V ------ V0
\ he1 / \ he3 | he1 /
\o1 o0/ \o1 e3|e1 o0/
\ / \ | /
\ F1 / \ F3 | F1 /
B B
*/

// incorrect factor
if ( f < 0 || f > 1 ) { return false; }

// get existing topology data
HalfedgeHandle he0 = halfedge_handle( eh, 0 );
HalfedgeHandle he1 = halfedge_handle( eh, 1 );
VertexHandle v0 = to_vertex_handle( he0 );
VertexHandle v1 = to_vertex_handle( he1 );
FaceHandle F0 = face_handle( he0 );
FaceHandle F1 = face_handle( he1 );

// not triangles or holes
if ( ( !is_boundary( he0 ) && valence( F0 ) != 3 ) ||
( !is_boundary( he1 ) && valence( F1 ) != 3 ) )
{ return false; }

// add the new vertex
const Point p = Point( f * point( v0 ) + ( Scalar( 1. ) - f ) * point( v1 ) );
VertexHandle v = add_vertex( p );

// create the new faces and reconnect the topology
HalfedgeHandle he3 = new_edge( v, v1 );
HalfedgeHandle he2 = opposite_halfedge_handle( he3 );
set_halfedge_handle( v, he0 );
set_vertex_handle( he1, v );

// does F0 exist
if ( !is_boundary( he0 ) )
{
HalfedgeHandle h0 = next_halfedge_handle( he0 );
HalfedgeHandle h1 = next_halfedge_handle( h0 );
// create new edge
VertexHandle A = to_vertex_handle( h0 );
HalfedgeHandle e2 = new_edge( v, A );
HalfedgeHandle e0 = opposite_halfedge_handle( e2 );
// split F0
FaceHandle F2 = new_face();
set_halfedge_handle( F0, he0 );
set_halfedge_handle( F2, h1 );
// update F0
set_face_handle( h0, F0 );
set_face_handle( e0, F0 );
set_face_handle( he0, F0 );
set_next_halfedge_handle( he0, h0 );
set_next_halfedge_handle( h0, e0 );
set_next_halfedge_handle( e0, he0 );
// update F2
set_face_handle( h1, F2 );
set_face_handle( he2, F2 );
set_face_handle( e2, F2 );
set_next_halfedge_handle( e2, h1 );
set_next_halfedge_handle( h1, he2 );
set_next_halfedge_handle( he2, e2 );
// deal with custom properties
// interpolate at he2
interpolateAllProps( h1, he0, he2, 0.5 );
// copy at e0, and e2
copyAllProps( he2, e0 );
}
else
{
HalfedgeHandle h1 = prev_halfedge_handle( he0 );
set_next_halfedge_handle( h1, he2 );
set_next_halfedge_handle( he2, he0 );
// next halfedge handle of he0 already is h0
// halfedge handle of V already is he0
}

// does F1 exist
if ( !is_boundary( he1 ) )
{
HalfedgeHandle o1 = next_halfedge_handle( he1 );
HalfedgeHandle o0 = next_halfedge_handle( o1 );
// create new edge
VertexHandle B = to_vertex_handle( o1 );
HalfedgeHandle e1 = new_edge( v, B );
HalfedgeHandle e3 = opposite_halfedge_handle( e1 );
// split F1
FaceHandle F3 = new_face();
set_halfedge_handle( F3, o1 );
set_halfedge_handle( F1, he1 );
// update F1
set_face_handle( o1, F3 );
set_face_handle( e3, F3 );
set_face_handle( he3, F3 );
set_next_halfedge_handle( he3, o1 );
set_next_halfedge_handle( o1, e3 );
set_next_halfedge_handle( e3, he3 );
// update F3
set_face_handle( o0, F1 );
set_face_handle( he1, F1 );
set_face_handle( e1, F1 );
set_next_halfedge_handle( he1, e1 );
set_next_halfedge_handle( e1, o0 );
set_next_halfedge_handle( o0, he1 );
// deal with custom properties
// first copy at he3
copyAllProps( he1, he3 );
// interpolate at he1
interpolateAllProps( o0, he3, he1, 0.5 );
// copy at e1, and e3
copyAllProps( he1, e3 );
copyAllProps( o1, e1 );
}
else
{
HalfedgeHandle o1 = next_halfedge_handle( he1 );
// next halfedge handle of o0 already is he1
set_next_halfedge_handle( he1, he3 );
set_next_halfedge_handle( he3, o1 );
// halfedge handle of V already is he0
}

// ensure consistency at v1
if ( halfedge_handle( v1 ) == he0 ) { set_halfedge_handle( v1, he2 ); }

return true;
}

template <typename T>
void interpolate( const VectorArray<T>& in1,
const VectorArray<T>& in2,
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Geometry/TopologicalMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class RA_CORE_API TopologicalMesh : public OpenMesh::PolyMesh_ArrayKernelT<Topol
* If you work with vertex normals, please call this function on all vertex
* handles before convertion with toTriangleMesh.
*/
void propagate_normal_to_halfedges( VertexHandle vh );
void propagate_normal_to_wedges( VertexHandle vh );

/**
* Return a handle to the halfedge property storing vertices indices within
Expand Down Expand Up @@ -351,7 +351,7 @@ class RA_CORE_API TopologicalMesh : public OpenMesh::PolyMesh_ArrayKernelT<Topol
* \note f=0 correspond to halfedge_handle( eh, 0 ) (i.e. first vertex of
* the edge)
*/
bool splitEdge( TopologicalMesh::EdgeHandle eh, Scalar f );
bool splitEdge( TopologicalMesh::EdgeHandle eh, Scalar f ) { return splitEdgeWedge( eh, f ); }
bool splitEdgeWedge( TopologicalMesh::EdgeHandle eh, Scalar f );

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Core/Geometry/TopologicalMesh.inl
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,14 @@ inline void TopologicalMesh::set_normal( VertexHandle vh, FaceHandle fh, const N
set_normal( halfedge_handle( vh, fh ), n );
}

inline void TopologicalMesh::propagate_normal_to_halfedges( VertexHandle vh ) {
inline void TopologicalMesh::propagate_normal_to_wedges( VertexHandle vh ) {
for ( VertexIHalfedgeIter vih_it = vih_iter( vh ); vih_it.is_valid(); ++vih_it )
{
set_normal( *vih_it, normal( vh ) );
auto wd = getWedgeData( property( getWedgeIndexPph(), *vih_it ) );

m_wedges.setWedgeAttrib( wd, "in_normal", normal( vh ) );

replaceWedge( *vih_it, wd );
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unittest/Core/topomesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ TEST_CASE( "Core/Geometry/TopologicalMesh", "[Core][Core/Geometry][TopologicalMe
v_it != topologicalMesh.vertices_end();
++v_it )
{
topologicalMesh.propagate_normal_to_halfedges( *v_it );
topologicalMesh.propagate_normal_to_wedges( *v_it );
}

{
Expand Down

0 comments on commit 3a3bf02

Please sign in to comment.