File: scale_space_incremental.cpp

package info (click to toggle)
cgal 4.9-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 85,584 kB
  • sloc: cpp: 640,841; ansic: 140,696; sh: 708; fortran: 131; makefile: 114; python: 92
file content (81 lines) | stat: -rw-r--r-- 3,067 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <fstream>
#include <iostream>
#include <algorithm>

#include <CGAL/Scale_space_surface_reconstruction_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_off_points.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel     Kernel;

typedef CGAL::Scale_space_surface_reconstruction_3< Kernel >    Reconstruction;

typedef Reconstruction::Point                                   Point;
typedef std::vector< Point >                                    Point_collection;

typedef Reconstruction::Triple_const_iterator                   Triple_iterator;

// function for writing the reconstruction output in the off format
void dump_reconstruction(const Reconstruction& reconstruct, std::string name)
{
  std::ofstream output(name.c_str());
  output << "OFF " << reconstruct.number_of_points() << " "
         << reconstruct.number_of_triangles() << " 0\n";

  std::copy(reconstruct.points_begin(),
            reconstruct.points_end(),
            std::ostream_iterator<Point>(output,"\n"));
  for( Triple_iterator it = reconstruct.surface_begin(); it != reconstruct.surface_end(); ++it )
      output << "3 " << *it << std::endl;
}

int main(int argc, char* argv[]) {
    // Read the data.
    Point_collection points;
    if (argc!=2){
      std::cerr << "Error, no input file provided\n";
      return 1;
    }
    std::ifstream in(argv[1]);
    std::cout << "Reading " << std::flush;
    if( !in || !CGAL::read_off_points( in, std::back_inserter( points ) ) ) {
        std::cerr << "Error: cannot read file" << std::endl;
        return EXIT_FAILURE;
    }
	std::cout << "done: " << points.size() << " points." << std::endl;

    // Construct the reconstruction with parameters for
    // the neighborhood squared radius estimation.
    Reconstruction reconstruct( 10, 100 );

    // Add the points.
    reconstruct.insert( points.begin(), points.end() );

    // Advance the scale-space several steps.
    // This automatically estimates the scale-space.
    reconstruct.increase_scale( 2 );

    // Reconstruct the surface from the current scale-space.
    std::cout << "Neighborhood squared radius is "
              << reconstruct.neighborhood_squared_radius() << std::endl;
    reconstruct.reconstruct_surface();
    std::cout << "First reconstruction done." << std::endl;

    // Write the reconstruction.
    dump_reconstruction(reconstruct, "reconstruction1.off");

    // Advancing the scale-space further and visually compare the reconstruction result
    reconstruct.increase_scale( 2 );

    // Reconstruct the surface from the current scale-space.
    std::cout << "Neighborhood squared radius is "
              << reconstruct.neighborhood_squared_radius() << std::endl;
    reconstruct.reconstruct_surface();
    std::cout << "Second reconstruction done." << std::endl;

    // Write the reconstruction.
    dump_reconstruction(reconstruct, "reconstruction2.off");

    std::cout << "Reconstructions are ready to be examinated in your favorite viewer" << std::endl;
    return EXIT_SUCCESS;
}