mirror of https://github.com/CGAL/cgal
Change doc for default index maps and add an example to Surface_mesh_segmentation using area() and Connected_components_graphs.
This commit is contained in:
parent
557e1a78c1
commit
64eb2d09c6
|
|
@ -42,14 +42,13 @@ namespace CGAL
|
|||
* For example, calling `vertices(graph)` will return an iterator range of all but only the vertices that belong to the selected connected components.
|
||||
*
|
||||
* \tparam Graph must be a model of a `FaceListGraph` and `HalfedgeListGraph`.
|
||||
* \tparam FIMap a model of `ReadablePropertyMap` with `boost::graph_traits<Graph>::%face_descriptor` as key and `graph_traits<Graph>::faces_size_type`
|
||||
* \tparam VIMap a model of `ReadablePropertyMap` with `boost::graph_traits<Graph>::%vertex_descriptor` as key and `graph_traits<Graph>::vertices_size_type`
|
||||
* \tparam HIMap a model of `ReadablePropertyMap` with `boost::graph_traits<Graph>::%halfedge_descriptor` as key and `graph_traits<Graph>::halfedges_size_type`
|
||||
* \tparam FIMap a model of `ReadablePropertyMap` with `boost::graph_traits<Graph>::%face_descriptor` as key and `graph_traits<Graph>::%faces_size_type` as value
|
||||
* \tparam VIMap a model of `ReadablePropertyMap` with `boost::graph_traits<Graph>::%vertex_descriptor` as key and `graph_traits<Graph>::%vertices_size_type` as value
|
||||
* \tparam HIMap a model of `ReadablePropertyMap` with `boost::graph_traits<Graph>::%halfedge_descriptor` as key and `graph_traits<Graph>::%halfedges_size_type` as value
|
||||
*
|
||||
* \cgalModels `FaceListGraph`
|
||||
* \cgalModels `HalfedgeListGraph`
|
||||
*/
|
||||
|
||||
template<typename Graph,
|
||||
typename FIMap = typename boost::property_map<Graph, CGAL::face_index_t>::type,
|
||||
typename VIMap = typename boost::property_map<Graph, boost::vertex_index_t>::type,
|
||||
|
|
@ -125,14 +124,20 @@ struct Connected_components_graph
|
|||
|
||||
* \tparam FaceComponentMap a model of `ReadablePropertyMap` with
|
||||
`boost::graph_traits<Graph>::%face_descriptor` as key type and
|
||||
`graph_traits<Graph>::faces_size_type` as value type.
|
||||
`graph_traits<Graph>::%faces_size_type` as value type.
|
||||
|
||||
* \param graph the graph containing the wanted patches.
|
||||
* \param fcmap the property_map that assigns a connected component to each face, with
|
||||
`boost::graph_traits<Graph>::%face_descriptor` as key type and
|
||||
`graph_traits<Graph>::faces_size_type` as value type.
|
||||
`graph_traits<Graph>::%faces_size_type` as value type.
|
||||
* \param begin an interator to the beginning of a range of connected components indices of interest.
|
||||
* \param end an interator to the element past the end of a range of connected components indices of interest.
|
||||
* \param fimap the property map that assigns an index to each face,
|
||||
* with boost::graph_traits<Graph>::%face_descriptor as key type and boost::graph_traits<Graph>::%faces_size_type as value type
|
||||
* \param vimap the property map that assigns an index to each vertex,
|
||||
* with boost::graph_traits<Graph>::%vertex_descriptor as key type and boost::graph_traits<Graph>::%vertices_size_type as value type
|
||||
* \param himap the property map that assigns an index to each halfedge,
|
||||
* with boost::graph_traits<Graph>::%halfedge_descriptor as key type and boost::graph_traits<Graph>::%halfedges_size_type as value type
|
||||
*/
|
||||
|
||||
template <typename FaceComponentMap, class IndexRangeIterator>
|
||||
|
|
@ -140,9 +145,16 @@ struct Connected_components_graph
|
|||
FaceComponentMap fcmap,
|
||||
IndexRangeIterator begin,
|
||||
IndexRangeIterator end,
|
||||
#ifdef DOXYGEN_RUNNING
|
||||
FIMap fimap = get(CGAL::face_index, graph),
|
||||
VIMap vimap = get(boost::vertex_index, graph),
|
||||
HIMap himap = get(CGAL::halfedge_index, graph)
|
||||
#else
|
||||
FIMap fimap,
|
||||
VIMap vimap,
|
||||
HIMap himap)
|
||||
HIMap himap
|
||||
#endif
|
||||
)
|
||||
: _graph(const_cast<Graph&>(graph)), fimap(fimap), vimap(vimap), himap(himap)
|
||||
{
|
||||
base_iterator_constructor(begin, end, fcmap);
|
||||
|
|
@ -165,20 +177,33 @@ struct Connected_components_graph
|
|||
*
|
||||
* \tparam FaceComponentMap a model of `ReadablePropertyMap` with
|
||||
`boost::graph_traits<Graph>::%face_descriptor` as key type and
|
||||
`graph_traits<Graph>::faces_size_type` as value type.
|
||||
`graph_traits<Graph>::%faces_size_type` as value type.
|
||||
* \param graph the graph containing the wanted patch.
|
||||
* \param fcmap the property_map that assigns a connected component's index to each face, with
|
||||
`boost::graph_traits<Graph>::%face_descriptor` as key type and
|
||||
`graph_traits<Graph>::faces_size_type` as value type.
|
||||
`graph_traits<Graph>::%faces_size_type` as value type.
|
||||
* \param pid the index of the connected component of interest.
|
||||
* \param fimap the property map that assigns an index to each face,
|
||||
* with boost::graph_traits<Graph>::%face_descriptor as key type and boost::graph_traits<Graph>::%faces_size_type as value type
|
||||
* \param vimap the property map that assigns an index to each vertex,
|
||||
* with boost::graph_traits<Graph>::%vertex_descriptor as key type and boost::graph_traits<Graph>::%vertices_size_type as value type
|
||||
* \param himap the property map that assigns an index to each halfedge,
|
||||
* with boost::graph_traits<Graph>::%halfedge_descriptor as key type and boost::graph_traits<Graph>::%halfedges_size_type as value type
|
||||
*/
|
||||
template <typename FaceComponentMap>
|
||||
Connected_components_graph(const Graph& graph,
|
||||
FaceComponentMap fcmap,
|
||||
typename boost::property_traits<FaceComponentMap>::value_type pid,
|
||||
#ifdef DOXYGEN_RUNNING
|
||||
FIMap fimap = get(CGAL::face_index, graph),
|
||||
VIMap vimap = get(boost::vertex_index, graph),
|
||||
HIMap himap = get(CGAL::halfedge_index, graph)
|
||||
#else
|
||||
FIMap fimap,
|
||||
VIMap vimap,
|
||||
HIMap himap)
|
||||
HIMap himap
|
||||
#endif
|
||||
)
|
||||
: _graph(const_cast<Graph&>(graph)), fimap(fimap), vimap(vimap), himap(himap)
|
||||
{
|
||||
base_constructor(fcmap, pid);
|
||||
|
|
@ -195,9 +220,9 @@ struct Connected_components_graph
|
|||
himap = get(CGAL::halfedge_index, graph);
|
||||
base_constructor(fcmap, pid);
|
||||
}
|
||||
///returns the graph of the Connected_components_graph.
|
||||
///returns a const reference to the graph of the Connected_components_graph.
|
||||
const Graph& graph()const{ return _graph; }
|
||||
|
||||
///returns a reference to the graph of the Connected_components_graph.
|
||||
Graph& graph(){ return _graph; }
|
||||
|
||||
struct Is_simplex_valid
|
||||
|
|
|
|||
|
|
@ -200,11 +200,17 @@ The main advantage is to decrease from log to constant the complexity for access
|
|||
|
||||
\cgalExample{Surface_mesh_segmentation/segmentation_with_facet_ids_example.cpp}
|
||||
|
||||
|
||||
\subsection Surface_mesh_segmentationUsingapolyhedron Using a Surface_mesh
|
||||
When using a `Surface_mesh`, you can use the built-in property mechanism.
|
||||
|
||||
\cgalExample{Surface_mesh_segmentation/segmentation_from_sdf_values_SM_example.cpp}
|
||||
|
||||
\subsection Surface_mesh_segmentationIndependantmeshpersegment Independant TriangleMesh per Segment
|
||||
It is possible to consider each segment as an independant triangle mesh, like in the following example, where the area of each segment is computed.
|
||||
|
||||
\cgalExample{Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp}
|
||||
|
||||
<BR>
|
||||
\section Performances Performances
|
||||
<!-- \subsection SMSRuntime Runtime of the functions sdf_values() and segmentation_from_sdf_values() -->
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@
|
|||
/// \example Surface_mesh_segmentation/segmentation_from_sdf_values_SM_example.cpp
|
||||
/// \example Surface_mesh_segmentation/segmentation_via_sdf_values_example.cpp
|
||||
/// \example Surface_mesh_segmentation/segmentation_with_facet_ids_example.cpp
|
||||
/// \example Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp
|
||||
|
|
|
|||
|
|
@ -64,8 +64,11 @@ create_single_source_cgal_program( "segmentation_from_sdf_values_example.cpp" )
|
|||
create_single_source_cgal_program( "segmentation_via_sdf_values_example.cpp" )
|
||||
|
||||
create_single_source_cgal_program( "segmentation_with_facet_ids_example.cpp" )
|
||||
|
||||
create_single_source_cgal_program( "segmentation_from_sdf_values_SM_example.cpp")
|
||||
|
||||
create_single_source_cgal_program( "extract_segmentation_into_mesh_example.cpp")
|
||||
|
||||
if(OpenMesh_FOUND)
|
||||
create_single_source_cgal_program( "segmentation_from_sdf_values_OpenMesh_example.cpp" )
|
||||
target_link_libraries( segmentation_from_sdf_values_OpenMesh_example ${OPENMESH_LIBRARIES} )
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
|
||||
#include <CGAL/boost/graph/Connected_components_graph.h>
|
||||
#include <CGAL/Polygon_mesh_processing/measure.h>
|
||||
#include <CGAL/boost/graph/copy_face_graph.h>
|
||||
#include <CGAL/mesh_segmentation.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef CGAL::Surface_mesh<Kernel::Point_3> SM;
|
||||
typedef boost::graph_traits<SM>::face_descriptor face_descriptor;
|
||||
|
||||
int main(int argc, char** argv )
|
||||
{
|
||||
SM mesh;
|
||||
if (argc==2){
|
||||
std::ifstream input(argv[1]);
|
||||
input >> mesh;
|
||||
} else {
|
||||
std::ifstream cactus("data/cactus.off");
|
||||
cactus >> mesh;
|
||||
}
|
||||
typedef SM::Property_map<face_descriptor,double> Facet_double_map;
|
||||
Facet_double_map sdf_property_map;
|
||||
|
||||
sdf_property_map = mesh.add_property_map<face_descriptor,double>("f:sdf").first;
|
||||
|
||||
CGAL::sdf_values(mesh, sdf_property_map);
|
||||
|
||||
// create a property-map for segment-ids
|
||||
typedef SM::Property_map<face_descriptor, std::size_t> Facet_int_map;
|
||||
Facet_int_map segment_property_map = mesh.add_property_map<face_descriptor,std::size_t>("f:sid").first;;
|
||||
|
||||
// segment the mesh using default parameters for number of levels, and smoothing lambda
|
||||
// Any other scalar values can be used instead of using SDF values computed using the CGAL function
|
||||
std::size_t number_of_segments = CGAL::segmentation_from_sdf_values(mesh, sdf_property_map, segment_property_map);
|
||||
|
||||
typedef CGAL::Connected_components_graph<SM> Cc_graph;
|
||||
//print area of each segment and then put it in a Mesh and print it in an OFF file
|
||||
for(std::size_t id = 0; id < number_of_segments; ++id)
|
||||
{
|
||||
Cc_graph segment_mesh(mesh, segment_property_map, id);
|
||||
std::cout << "Segment "<<id<<"'s area is : "<<CGAL::Polygon_mesh_processing::area(segment_mesh)<<std::endl;
|
||||
SM out;
|
||||
CGAL::copy_face_graph(segment_mesh, out);
|
||||
std::ostringstream oss;
|
||||
oss << "Segment_" << id<<".off";
|
||||
std::ofstream os(oss.str().data());
|
||||
os<<out;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue