Commit 56c13484 authored by Max Lyon's avatar Max Lyon
Browse files

make more functions return smart handles

parent a3fbdcb9
......@@ -198,19 +198,19 @@ public:
*
* \sa new_vertex(const Point&), new_vertex_dirty()
*/
inline VertexHandle new_vertex()
{ return Kernel::new_vertex(); }
inline SmartVertexHandle new_vertex()
{ return make_smart(Kernel::new_vertex(), this); }
/**
* \brief Adds a new vertex initialized to a custom position.
*
* \sa new_vertex(), new_vertex_dirty()
*/
inline VertexHandle new_vertex(const Point& _p)
inline SmartVertexHandle new_vertex(const Point& _p)
{
VertexHandle vh(Kernel::new_vertex());
this->set_point(vh, _p);
return vh;
return make_smart(vh, this);
}
/**
......@@ -224,20 +224,20 @@ public:
*
* \sa new_vertex(const Point &)
*/
inline VertexHandle new_vertex_dirty(const Point& _p)
inline SmartVertexHandle new_vertex_dirty(const Point& _p)
{
VertexHandle vh(Kernel::new_vertex_dirty());
this->set_point(vh, _p);
return vh;
return make_smart(vh, this);
}
/// Alias for new_vertex(const Point&).
inline VertexHandle add_vertex(const Point& _p)
inline SmartVertexHandle add_vertex(const Point& _p)
{ return new_vertex(_p); }
/// Alias for new_vertex_dirty().
inline VertexHandle add_vertex_dirty(const Point& _p)
{ return new_vertex_dirty(_p); }
inline SmartVertexHandle add_vertex_dirty(const Point& _p)
{ return make_smart(new_vertex_dirty(_p), this); }
// --- normal vectors ---
......
......@@ -49,11 +49,11 @@
namespace OpenMesh
{
TriConnectivity::FaceHandle
SmartFaceHandle
TriConnectivity::add_face(const VertexHandle* _vertex_handles, size_t _vhs_size)
{
// need at least 3 vertices
if (_vhs_size < 3) return InvalidFaceHandle;
if (_vhs_size < 3) return make_smart(InvalidFaceHandle, this);
/// face is triangle -> ok
if (_vhs_size == 3)
......@@ -78,21 +78,29 @@ TriConnectivity::add_face(const VertexHandle* _vertex_handles, size_t _vhs_size)
fh = PolyConnectivity::add_face(vhandles, 3);
}
return fh;
return make_smart(fh, this);
}
}
//-----------------------------------------------------------------------------
FaceHandle TriConnectivity::add_face(const std::vector<VertexHandle>& _vhandles)
SmartFaceHandle TriConnectivity::add_face(const std::vector<VertexHandle>& _vhandles)
{
return add_face(&_vhandles.front(), _vhandles.size());
}
//-----------------------------------------------------------------------------
SmartFaceHandle TriConnectivity::add_face(const std::vector<SmartVertexHandle>& _vhandles)
{
std::vector<VertexHandle> vhandles(_vhandles.begin(), _vhandles.end());
return add_face(&vhandles.front(), vhandles.size());
}
//-----------------------------------------------------------------------------
FaceHandle TriConnectivity::add_face(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2)
SmartFaceHandle TriConnectivity::add_face(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2)
{
VertexHandle vhs[3] = { _vh0, _vh1, _vh2 };
return PolyConnectivity::add_face(vhs, 3);
......
......@@ -85,8 +85,18 @@ public:
*
*
* */
FaceHandle add_face(const VertexHandle* _vhandles, size_t _vhs_size);
SmartFaceHandle add_face(const VertexHandle* _vhandles, size_t _vhs_size);
/** \brief Add a face with arbitrary valence to the triangle mesh
*
* Override OpenMesh::Mesh::PolyMeshT::add_face(). Faces that aren't
* triangles will be triangulated and added. In this case an
* invalid face handle will be returned.
*
*
* */
SmartFaceHandle add_face(const std::vector<VertexHandle>& _vhandles);
/** \brief Add a face with arbitrary valence to the triangle mesh
*
* Override OpenMesh::Mesh::PolyMeshT::add_face(). Faces that aren't
......@@ -95,7 +105,7 @@ public:
*
*
* */
FaceHandle add_face(const std::vector<VertexHandle>& _vhandles);
SmartFaceHandle add_face(const std::vector<SmartVertexHandle>& _vhandles);
/** \brief Add a face to the mesh (triangle)
*
......@@ -107,7 +117,7 @@ public:
* @param _vh2 VertexHandle 3
* @return FaceHandle of the added face (invalid, if the operation failed)
*/
FaceHandle add_face(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2);
SmartFaceHandle add_face(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2);
//@}
......
......@@ -264,10 +264,10 @@ public:
* @param _p New point position that will be inserted at the edge
* @return Vertex handle of the newly added vertex
*/
inline VertexHandle split(EdgeHandle _eh, const Point& _p)
inline SmartVertexHandle split(EdgeHandle _eh, const Point& _p)
{
//Do not call PolyMeshT function below as this does the wrong operation
const VertexHandle vh = this->add_vertex(_p); Kernel::split(_eh, vh); return vh;
const SmartVertexHandle vh = this->add_vertex(_p); Kernel::split(_eh, vh); return vh;
}
/** \brief Edge split (= 2-to-4 split)
......@@ -278,10 +278,10 @@ public:
* @param _p New point position that will be inserted at the edge
* @return Vertex handle of the newly added vertex
*/
inline VertexHandle split_copy(EdgeHandle _eh, const Point& _p)
inline SmartVertexHandle split_copy(EdgeHandle _eh, const Point& _p)
{
//Do not call PolyMeshT function below as this does the wrong operation
const VertexHandle vh = this->add_vertex(_p); Kernel::split_copy(_eh, vh); return vh;
const SmartVertexHandle vh = this->add_vertex(_p); Kernel::split_copy(_eh, vh); return vh;
}
/** \brief Edge split (= 2-to-4 split)
......@@ -319,8 +319,8 @@ public:
*
* @return Vertex handle of the new vertex
*/
inline VertexHandle split(FaceHandle _fh, const Point& _p)
{ const VertexHandle vh = this->add_vertex(_p); PolyMesh::split(_fh, vh); return vh; }
inline SmartVertexHandle split(FaceHandle _fh, const Point& _p)
{ const SmartVertexHandle vh = this->add_vertex(_p); PolyMesh::split(_fh, vh); return vh; }
/** \brief Face split (= 1-to-3 split, calls corresponding PolyMeshT function).
*
......@@ -331,8 +331,8 @@ public:
*
* @return Vertex handle of the new vertex
*/
inline VertexHandle split_copy(FaceHandle _fh, const Point& _p)
{ const VertexHandle vh = this->add_vertex(_p); PolyMesh::split_copy(_fh, vh); return vh; }
inline SmartVertexHandle split_copy(FaceHandle _fh, const Point& _p)
{ const SmartVertexHandle vh = this->add_vertex(_p); PolyMesh::split_copy(_fh, vh); return vh; }
/** \brief Face split (= 1-to-4) split, splits edges at midpoints and adds 4 new faces in the interior).
......
......@@ -501,5 +501,65 @@ TEST_F(OpenMeshSmartHandles, ComparisionBetweenSmartHandleAndNormalHandles)
}
TEST(OpenMeshSmartHandlesNoFixture, AddingFacesPolyMesh)
{
using MyMesh = OpenMesh::PolyMesh_ArrayKernelT<>;
MyMesh mesh;
std::vector<OpenMesh::SmartVertexHandle> vertices;
for (int i = 0; i < 4; ++i)
vertices.push_back(mesh.add_vertex(MyMesh::Point()));
auto fh = mesh.add_face(vertices);
for (auto heh : fh.halfedges())
{
heh = heh.next();
}
}
TEST(OpenMeshSmartHandlesNoFixture, AddingFacesTriMesh)
{
using MyMesh = OpenMesh::TriMesh_ArrayKernelT<>;
MyMesh mesh;
std::vector<OpenMesh::SmartVertexHandle> vertices;
for (int i = 0; i < 4; ++i)
vertices.push_back(mesh.add_vertex(MyMesh::Point()));
auto fh = mesh.add_face(vertices);
for (auto heh : fh.halfedges())
{
heh = heh.next();
}
}
TEST(OpenMeshSmartHandlesNoFixture, SplitTriMesh)
{
using MyMesh = OpenMesh::TriMesh_ArrayKernelT<>;
MyMesh mesh;
std::vector<OpenMesh::SmartVertexHandle> vertices;
for (int i = 0; i < 3; ++i)
vertices.push_back(mesh.add_vertex(MyMesh::Point()));
auto fh = mesh.add_face(vertices);
auto p = (MyMesh::Point());
OpenMesh::SmartVertexHandle vh = mesh.split(fh, p);
OpenMesh::SmartEdgeHandle eh = fh.halfedge().edge();
OpenMesh::SmartVertexHandle vh2 = mesh.split(eh, p);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment