41 #ifndef PCL_GEOMETRY_MESH_BASE_H
42 #define PCL_GEOMETRY_MESH_BASE_H
46 #include <pcl/geometry/boost.h>
47 #include <pcl/geometry/eigen.h>
48 #include <pcl/geometry/mesh_circulators.h>
49 #include <pcl/geometry/mesh_indices.h>
50 #include <pcl/geometry/mesh_elements.h>
51 #include <pcl/geometry/mesh_traits.h>
52 #include <pcl/point_cloud.h>
58 #ifdef PCL_GEOMETRY_MESH_BASE_TEST_DELETE_FACE_MANIFOLD_2
63 bool g_pcl_geometry_mesh_base_test_delete_face_manifold_2_success;
76 template <
class MeshT>
97 template <
class DerivedT,
class MeshTraitsT,
class MeshTagT>
103 typedef boost::shared_ptr <Self>
Ptr;
121 typedef boost::integral_constant <bool, !boost::is_same <VertexData , pcl::geometry::NoData>::value>
HasVertexData;
122 typedef boost::integral_constant <bool, !boost::is_same <HalfEdgeData, pcl::geometry::NoData>::value>
HasHalfEdgeData;
123 typedef boost::integral_constant <bool, !boost::is_same <EdgeData , pcl::geometry::NoData>::value>
HasEdgeData;
124 typedef boost::integral_constant <bool, !boost::is_same <FaceData , pcl::geometry::NoData>::value>
HasFaceData;
154 : vertex_data_cloud_ (),
155 half_edge_data_cloud_ (),
166 delete_faces_vertex_ (),
167 delete_faces_face_ ()
182 vertices_.push_back (
Vertex ());
202 return (static_cast <Derived*> (
this)->addFaceImpl (vertices, face_data, edge_data, half_edge_data));
211 assert (this->
isValid (idx_vertex));
212 if (this->
isDeleted (idx_vertex))
return;
214 delete_faces_vertex_.clear ();
223 }
while (++circ!=circ_end);
225 for (FaceIndices::const_iterator it = delete_faces_vertex_.begin (); it!=delete_faces_vertex_.end (); ++it)
237 assert (this->
isValid (idx_he));
254 assert (this->
isValid (idx_edge));
265 assert (this->
isValid (idx_face));
279 this->remove <Vertices, VertexDataCloud, VertexIndices, HasVertexData>
280 (vertices_, vertex_data_cloud_);
282 this->remove <HalfEdges, HalfEdgeDataCloud, HalfEdgeIndices, HasHalfEdgeData>
283 (half_edges_, half_edge_data_cloud_);
285 this->remove <Faces, FaceDataCloud, FaceIndices, HasFaceData>
286 (faces_, face_data_cloud_);
289 if (HasEdgeData::value)
294 HalfEdgeIndices::const_iterator it_ind = new_half_edge_indices.begin ();
295 HalfEdgeIndices::const_iterator it_ind_end = new_half_edge_indices.end ();
297 for (; it_ind!=it_ind_end; it_ind+=2, ++it_ed_old)
299 if (it_ind->isValid ())
301 *it_ed_new++ = *it_ed_old;
308 for (
VertexIterator it = vertices_.begin (); it!=vertices_.end (); ++it)
310 if (it->idx_outgoing_half_edge_.isValid ())
312 it->idx_outgoing_half_edge_ = new_half_edge_indices [it->idx_outgoing_half_edge_.get ()];
316 for (
HalfEdgeIterator it = half_edges_.begin (); it!=half_edges_.end (); ++it)
318 it->idx_terminating_vertex_ = new_vertex_indices [it->idx_terminating_vertex_.get ()];
319 it->idx_next_half_edge_ = new_half_edge_indices [it->idx_next_half_edge_.get ()];
320 it->idx_prev_half_edge_ = new_half_edge_indices [it->idx_prev_half_edge_.get ()];
321 if (it->idx_face_.isValid ())
323 it->idx_face_ = new_face_indices [it->idx_face_.get ()];
327 for (
FaceIterator it = faces_.begin (); it!=faces_.end (); ++it)
329 it->idx_inner_half_edge_ = new_half_edge_indices [it->idx_inner_half_edge_.get ()];
341 assert (this->
isValid (idx_vertex));
342 return (this->
getVertex (idx_vertex).idx_outgoing_half_edge_);
349 assert (this->
isValid (idx_vertex));
361 assert (this->
isValid (idx_half_edge));
362 return (this->
getHalfEdge (idx_half_edge).idx_terminating_vertex_);
369 assert (this->
isValid (idx_half_edge));
377 assert (this->
isValid (idx_half_edge));
386 assert (this->
isValid (idx_half_edge));
387 return (this->
getHalfEdge (idx_half_edge).idx_next_half_edge_);
394 assert (this->
isValid (idx_half_edge));
395 return (this->
getHalfEdge (idx_half_edge).idx_prev_half_edge_);
402 assert (this->
isValid (idx_half_edge));
403 return (this->
getHalfEdge (idx_half_edge).idx_face_);
410 assert (this->
isValid (idx_half_edge));
422 assert (this->
isValid (idx_face));
423 return (this->
getFace (idx_face).idx_inner_half_edge_);
430 assert (this->
isValid (idx_face));
442 assert (this->
isValid (idx_vertex));
450 assert (this->
isValid (idx_outgoing_half_edge));
458 assert (this->
isValid (idx_vertex));
466 assert (this->
isValid (idx_outgoing_half_edge));
474 assert (this->
isValid (idx_vertex));
482 assert (this->
isValid (idx_incoming_half_edge));
490 assert (this->
isValid (idx_vertex));
498 assert (this->
isValid (idx_outgoing_half_edge));
506 assert (this->
isValid (idx_face));
514 assert (this->
isValid (idx_inner_half_edge));
522 assert (this->
isValid (idx_face));
530 assert (this->
isValid (idx_inner_half_edge));
538 assert (this->
isValid (idx_face));
546 assert (this->
isValid (idx_inner_half_edge));
554 assert (this->
isValid (idx_face));
562 assert (this->
isValid (idx_inner_half_edge));
599 for (
unsigned int i=0; i<this->
sizeFaces (); ++i)
648 assert (this->
isValid (idx_vertex));
656 assert (this->
isValid (idx_he));
664 assert (this->
isValid (idx_edge));
673 assert (this->
isValid (idx_face));
685 assert (this->
isValid (idx_vertex));
697 assert (this->
isValid (idx_vertex));
698 if (this->
isIsolated (idx_vertex))
return (
true);
706 assert (this->
isValid (idx_he));
714 assert (this->
isValid (idx_edge));
722 template <
bool CheckVerticesT>
inline bool
725 assert (this->
isValid (idx_face));
726 return (this->
isBoundary (idx_face, boost::integral_constant <bool, CheckVerticesT> ()));
733 assert (this->
isValid (idx_face));
734 return (this->
isBoundary (idx_face, boost::true_type ()));
745 assert (this->
isValid (idx_vertex));
746 if (this->
isIsolated (idx_vertex))
return (
true);
765 return (vertices_.size ());
772 assert (half_edges_.size () % 2 == 0);
773 return (half_edges_.size ());
780 assert (half_edges_.size () % 2 == 0);
781 return (half_edges_.size () / 2);
788 return (faces_.size ());
806 return (vertices_.empty ());
813 return (half_edges_.empty ());
820 return (faces_.empty ());
831 vertices_.reserve (n);
839 half_edges_.reserve (2*n);
860 vertices_.resize (n);
870 half_edges_.resize (2*n);
892 half_edges_.clear ();
911 return (vertex_data_cloud_);
918 return (vertex_data_cloud_);
928 if (vertex_data_cloud.
size () == vertex_data_cloud_.
size ())
930 vertex_data_cloud_ = vertex_data_cloud;
949 return (half_edge_data_cloud_);
956 return (half_edge_data_cloud_);
966 if (half_edge_data_cloud.
size () == half_edge_data_cloud_.
size ())
968 half_edge_data_cloud_ = half_edge_data_cloud;
987 return (edge_data_cloud_);
994 return (edge_data_cloud_);
1004 if (edge_data_cloud.
size () == edge_data_cloud_.
size ())
1006 edge_data_cloud_ = edge_data_cloud;
1025 return (face_data_cloud_);
1032 return (face_data_cloud_);
1042 if (face_data_cloud.
size () == face_data_cloud_.
size ())
1044 face_data_cloud_ = face_data_cloud;
1063 if (HasVertexData::value)
1065 assert (&vertex_data >= &vertex_data_cloud_.
front () && &vertex_data <= &vertex_data_cloud_.
back ());
1066 return (
VertexIndex (std::distance (&vertex_data_cloud_.
front (), &vertex_data)));
1078 if (HasHalfEdgeData::value)
1080 assert (&half_edge_data >= &half_edge_data_cloud_.
front () && &half_edge_data <= &half_edge_data_cloud_.
back ());
1081 return (
HalfEdgeIndex (std::distance (&half_edge_data_cloud_.
front (), &half_edge_data)));
1093 if (HasEdgeData::value)
1095 assert (&edge_data >= &edge_data_cloud_.
front () && &edge_data <= &edge_data_cloud_.
back ());
1096 return (
EdgeIndex (std::distance (&edge_data_cloud_.
front (), &edge_data)));
1108 if (HasFaceData::value)
1110 assert (&face_data >= &face_data_cloud_.
front () && &face_data <= &face_data_cloud_.
back ());
1111 return (
FaceIndex (std::distance (&face_data_cloud_.
front (), &face_data)));
1149 const int n =
static_cast<int> (vertices.size ());
1153 inner_he_.resize (n);
1154 free_he_.resize (n);
1156 make_adjacent_.resize (n);
1168 if (!this->
checkTopology2 (inner_he_ [i], inner_he_ [j], is_new_ [i], is_new_ [j], this->
isIsolated (vertices [j]), make_adjacent_ [i], free_he_ [i],
IsManifold ()))
1175 if (!IsManifold::value)
1179 if (make_adjacent_ [i])
1181 this->
makeAdjacent (inner_he_ [i], inner_he_ [(i+1)%n], free_he_ [i]);
1191 inner_he_ [i] = this->
addEdge (vertices [i], vertices [(i+1)%n], half_edge_data, edge_data);
1199 if ( is_new_ [i] && is_new_ [j]) this->
connectNewNew (inner_he_ [i], inner_he_ [j], vertices [j],
IsManifold ());
1200 else if ( is_new_ [i] && !is_new_ [j]) this->
connectNewOld (inner_he_ [i], inner_he_ [j], vertices [j]);
1201 else if (!is_new_ [i] && is_new_ [j]) this->
connectOldNew (inner_he_ [i], inner_he_ [j], vertices [j]);
1204 return (this->
connectFace (inner_he_, face_data));
1224 half_edges_.push_back (
HalfEdge (idx_v_b));
1225 half_edges_.push_back (
HalfEdge (idx_v_a));
1231 return (
HalfEdgeIndex (static_cast <int> (half_edges_.size () - 2)));
1249 std::vector <bool>::reference is_new_ab,
1250 boost::true_type )
const
1253 if (this->
isIsolated (idx_v_a))
return (
true);
1257 if (!this->
isBoundary (idx_he_ab))
return (
false);
1267 std::vector <bool>::reference is_new_ab,
1268 boost::false_type )
const
1271 if (this->
isIsolated (idx_v_a))
return (
true);
1282 if (!this->
isBoundary (idx_he_ab))
return (
false);
1287 }
while (++circ!=circ_end);
1296 const bool is_new_ab,
1297 const bool is_new_bc,
1298 const bool is_isolated_b,
1299 std::vector <bool>::reference ,
1301 boost::true_type )
const
1303 if (is_new_ab && is_new_bc && !is_isolated_b)
return (
false);
1319 const bool is_new_ab,
1320 const bool is_new_bc,
1322 std::vector <bool>::reference make_adjacent_ab_bc,
1324 boost::false_type )
const
1326 if (is_new_ab || is_new_bc)
1328 make_adjacent_ab_bc =
false;
1334 make_adjacent_ab_bc =
false;
1338 make_adjacent_ab_bc =
true;
1384 faces_.push_back (
Face (inner_he.back ()));
1389 for (HalfEdgeIndices::const_iterator it=inner_he.begin (); it!=inner_he.end (); ++it)
1431 this->
connectNewNew (idx_he_ab, idx_he_bc, idx_v_b, boost::true_type ());
1497 if (idx_he_b_out == idx_he_bc)
1502 while (++circ!=circ_end)
1518 template <
class DataT>
1526 template <
class DataT>
1541 assert (this->
isValid (idx_face));
1542 delete_faces_face_.clear ();
1543 delete_faces_face_.push_back (idx_face);
1545 while (!delete_faces_face_.empty ())
1547 const FaceIndex idx_face_cur = delete_faces_face_.back ();
1548 delete_faces_face_.pop_back ();
1551 this->
deleteFace (idx_face_cur, boost::false_type ());
1560 assert (this->
isValid (idx_face));
1565 is_boundary_.clear ();
1572 }
while (++circ != circ_end);
1573 assert (inner_he_.size () >= 3);
1575 const int n = static_cast <
int> (inner_he_.size ());
1578 if (IsManifold::value)
1580 for (
int i=0; i<n; ++i)
1583 this->
reconnect (inner_he_ [i], inner_he_ [j], is_boundary_ [i], is_boundary_ [j]);
1585 for (
int i=0; i<n; ++i)
1592 for (
int i=0; i<n; ++i)
1595 this->
reconnect (inner_he_ [i], inner_he_ [j], is_boundary_ [i], is_boundary_ [j]);
1611 const bool is_boundary_ba,
1612 const bool is_boundary_cb)
1618 if (is_boundary_ba && is_boundary_cb)
1622 if (idx_he_cb_next == idx_he_ba)
1635 else if (is_boundary_ba && !is_boundary_cb)
1643 else if (!is_boundary_ba && is_boundary_cb)
1670 delete_faces_face_.push_back (this->
getFaceIndex ((circ++).getTargetIndex ()));
1672 #ifdef PCL_GEOMETRY_MESH_BASE_TEST_DELETE_FACE_MANIFOLD_2
1679 pcl::geometry::g_pcl_geometry_mesh_base_test_delete_face_manifold_2_success =
false;
1712 assert (this->
isValid (idx_vertex));
1720 assert (this->
isValid (idx_he));
1728 assert (this->
isValid (idx_edge));
1737 assert (this->
isValid (idx_face));
1754 template <
class ElementContainerT,
class DataContainerT,
class IndexContainerT,
class HasDataT> IndexContainerT
1755 remove (ElementContainerT& elements, DataContainerT& data_cloud)
1757 typedef typename IndexContainerT::value_type Index;
1758 typedef typename ElementContainerT::value_type Element;
1760 if (HasDataT::value) assert (elements.size () == data_cloud.size ());
1761 else assert (data_cloud.empty ());
1763 IndexContainerT new_indices (elements.size (),
typename IndexContainerT::value_type ());
1764 Index ind_old (0), ind_new (0);
1766 typename ElementContainerT::const_iterator it_e_old = elements.begin ();
1767 typename ElementContainerT::iterator it_e_new = elements.begin ();
1769 typename DataContainerT::const_iterator it_d_old = data_cloud.begin ();
1770 typename DataContainerT::iterator it_d_new = data_cloud.begin ();
1772 typename IndexContainerT::iterator it_ind_new = new_indices.begin ();
1773 typename IndexContainerT::const_iterator it_ind_new_end = new_indices.end ();
1775 while (it_ind_new!=it_ind_new_end)
1779 *it_ind_new = ind_new++;
1782 *it_e_new++ = *it_e_old;
1783 this->
assignIf (it_d_old, it_d_new, HasDataT ());
1792 elements.resize (ind_new.get (), Element ());
1793 if (HasDataT::value)
1795 data_cloud.resize (ind_new.get ());
1797 else if (it_d_old != data_cloud.begin () || it_d_new != data_cloud.begin ())
1799 std::cerr <<
"TODO: Bug in MeshBase::remove!\n";
1801 exit (EXIT_FAILURE);
1804 return (new_indices);
1808 template <
class IteratorT>
inline void
1815 template <
class IteratorT>
inline void
1821 template <
class ConstIteratorT,
class IteratorT>
inline void
1822 assignIf (
const ConstIteratorT source, IteratorT target, boost::true_type )
const
1828 template <
class ConstIteratorT,
class IteratorT>
inline void
1829 assignIf (
const ConstIteratorT , IteratorT , boost::false_type )
const
1841 assert (this->
isValid (idx_vertex));
1842 this->
getVertex (idx_vertex).idx_outgoing_half_edge_ = idx_outgoing_half_edge;
1849 assert (this->
isValid (idx_half_edge));
1850 this->
getHalfEdge (idx_half_edge).idx_terminating_vertex_ = idx_terminating_vertex;
1857 assert (this->
isValid (idx_half_edge));
1858 this->
getHalfEdge (idx_half_edge).idx_next_half_edge_ = idx_next_half_edge;
1866 assert (this->
isValid (idx_half_edge));
1867 this->
getHalfEdge (idx_half_edge).idx_prev_half_edge_ = idx_prev_half_edge;
1874 assert (this->
isValid (idx_half_edge));
1875 this->
getHalfEdge (idx_half_edge).idx_face_ = idx_face;
1882 assert (this->
isValid (idx_face));
1883 this->
getFace (idx_face).idx_inner_half_edge_ = idx_inner_half_edge;
1903 }
while (++circ!=circ_end);
1921 }
while (++circ!=circ_end);
1940 if (!this->
isBoundary ((circ++).getTargetIndex ()))
return (
true);
1944 }
while (++circ != circ_end);
1972 template <
class DataCloudT>
inline void
1973 reserveData (DataCloudT& cloud,
const size_t n, boost::true_type )
const
1979 template <
class DataCloudT>
inline void
1985 template <
class DataCloudT>
inline void
1986 resizeData (DataCloudT& data_cloud,
const size_t n,
const typename DataCloudT::value_type& data, boost::true_type )
const
1988 data.resize (n, data);
1992 template <
class DataCloudT>
inline void
1993 resizeData (DataCloudT& ,
const size_t ,
const typename DataCloudT::value_type& , boost::false_type )
const
1998 template <
class DataCloudT>
inline void
2005 template <
class DataCloudT>
inline void
2018 assert (this->
isValid (idx_vertex));
2019 return (vertices_ [idx_vertex.
get ()]);
2026 assert (this->
isValid (idx_vertex));
2027 return (vertices_ [idx_vertex.
get ()]);
2034 assert (this->
isValid (idx_vertex));
2035 vertices_ [idx_vertex.
get ()] = vertex;
2046 assert (this->
isValid (idx_he));
2047 return (half_edges_ [idx_he.
get ()]);
2054 assert (this->
isValid (idx_he));
2055 return (half_edges_ [idx_he.
get ()]);
2062 assert (this->
isValid (idx_he));
2063 half_edges_ [idx_he.
get ()] = half_edge;
2074 assert (this->
isValid (idx_face));
2075 return (faces_ [idx_face.
get ()]);
2082 assert (this->
isValid (idx_face));
2083 return (faces_ [idx_face.
get ()]);
2090 assert (this->
isValid (idx_face));
2091 faces_ [idx_face.
get ()] = face;
2130 std::vector <bool> is_new_;
2133 std::vector <bool> make_adjacent_;
2136 std::vector <bool> is_boundary_;
2146 template <
class MeshT>
2149 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
2154 #endif // PCL_GEOMETRY_MESH_BASE_H