~ubuntu-branches/debian/stretch/cgal/stretch

« back to all changes in this revision

Viewing changes to examples/Surface_mesh_segmentation/segmentation_via_sdf_values_example.cpp

  • Committer: Package Import Robot
  • Author(s): Joachim Reichel
  • Date: 2014-04-05 10:56:43 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140405105643-jgnrpu2thtx23zfs
Tags: 4.4-1
* New upstream release.
* Remove patches do-not-link-example-with-qt4-support-library.patch and
  fix_jet_fitting_3.patch (applied upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
 
2
#include <CGAL/Polyhedron_3.h>
 
3
#include <CGAL/IO/Polyhedron_iostream.h>
 
4
#include <CGAL/mesh_segmentation.h>
 
5
 
 
6
#include <CGAL/property_map.h>
 
7
 
 
8
#include <iostream>
 
9
#include <fstream>
 
10
 
 
11
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
 
12
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
 
13
 
 
14
int main()
 
15
{
 
16
    // create and read Polyhedron
 
17
    Polyhedron mesh;
 
18
    std::ifstream input("data/cactus.off");
 
19
    if ( !input || !(input >> mesh) || mesh.empty() ) {
 
20
        std::cerr << "Not a valid off file." << std::endl;
 
21
        return EXIT_FAILURE;
 
22
    }
 
23
 
 
24
    // create a property-map for segment-ids
 
25
    typedef std::map<Polyhedron::Facet_const_handle, std::size_t> Facet_int_map;
 
26
    Facet_int_map internal_segment_map;
 
27
    boost::associative_property_map<Facet_int_map> segment_property_map(internal_segment_map);
 
28
 
 
29
    // calculate SDF values and segment the mesh using default parameters.
 
30
    std::size_t number_of_segments = CGAL::segmentation_via_sdf_values(mesh, segment_property_map);
 
31
 
 
32
    std::cout << "Number of segments: " << number_of_segments << std::endl;
 
33
 
 
34
    // print segment-ids
 
35
    for(Polyhedron::Facet_const_iterator facet_it = mesh.facets_begin();
 
36
        facet_it != mesh.facets_end(); ++facet_it) {
 
37
        std::cout << segment_property_map[facet_it] << " ";
 
38
    }
 
39
    std::cout << std::endl;
 
40
}