mirror of https://github.com/CGAL/cgal
first pass over examples
This commit is contained in:
parent
5c8fe581c3
commit
1eaaa82c5e
|
|
@ -23,7 +23,7 @@ typedef std::vector<Point_with_normal> Point_list;
|
||||||
typedef CGAL::Identity_property_map<Point_with_normal> Point_pmap;
|
typedef CGAL::Identity_property_map<Point_with_normal> Point_pmap;
|
||||||
typedef CGAL::Normal_of_point_with_normal_pmap<Kernel> Normal_pmap;
|
typedef CGAL::Normal_of_point_with_normal_pmap<Kernel> Normal_pmap;
|
||||||
|
|
||||||
// In Shape_detection_traits_3 the used types, i.e. Point and Vector types
|
// In Shape_detection_traits_3 the basic types, i.e., Point and Vector types
|
||||||
// as well as iterator type and property maps, are defined.
|
// as well as iterator type and property maps, are defined.
|
||||||
typedef CGAL::Shape_detection_traits_3<Kernel,
|
typedef CGAL::Shape_detection_traits_3<Kernel,
|
||||||
Point_list::iterator, Point_pmap, Normal_pmap> ShapeDetectionTraits;
|
Point_list::iterator, Point_pmap, Normal_pmap> ShapeDetectionTraits;
|
||||||
|
|
@ -33,9 +33,9 @@ typedef CGAL::Shape_detection_3<ShapeDetectionTraits> Shape_detection;
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
Point_list points;
|
Point_list points;
|
||||||
|
|
||||||
// Loading a point set from file.
|
// Loading a point set from a file.
|
||||||
// read_xyz_points_and_normals takes an OutputIterator for storing the points
|
// read_xyz_points_and_normals takes an OutputIterator for writing the points
|
||||||
// and a property map to store the normal vector with each point.
|
// and a property map for storing the normal vector associated to each point.
|
||||||
std::ifstream stream("cube.xyz");
|
std::ifstream stream("cube.xyz");
|
||||||
|
|
||||||
if (!stream ||
|
if (!stream ||
|
||||||
|
|
@ -46,20 +46,20 @@ int main(int argc, char **argv) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creation of the instance and providing the input data.
|
// Instantiates shape detection engine and provides input data.
|
||||||
Shape_detection sd(points.begin(),
|
Shape_detection sd(points.begin(),
|
||||||
points.end(), Point_pmap(), Normal_pmap());
|
points.end(), Point_pmap(), Normal_pmap());
|
||||||
|
|
||||||
// Shapes to be searched for are registered
|
// Shapes to be detected are registered
|
||||||
// by using the template Shape_factory
|
// by using the template Shape_factory
|
||||||
sd.add_shape_factory(new
|
sd.add_shape_factory(new
|
||||||
CGAL::Shape_factory<CGAL::Plane_shape<ShapeDetectionTraits> >);
|
CGAL::Shape_factory<CGAL::Plane_shape<ShapeDetectionTraits> >);
|
||||||
|
|
||||||
// The actual shape detection with default parameters.
|
// Detects registered shapes with default parameters.
|
||||||
sd.detect();
|
sd.detect();
|
||||||
|
|
||||||
// Print results.
|
// Prints number of detected shapes.
|
||||||
std::cout << sd.number_of_shapes() << " primitives" << std::endl;
|
std::cout << sd.number_of_shapes() << " shapes detected." << std::endl;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ typedef std::vector<Point_with_normal> Point_list;
|
||||||
typedef CGAL::Identity_property_map<Point_with_normal> Point_pmap;
|
typedef CGAL::Identity_property_map<Point_with_normal> Point_pmap;
|
||||||
typedef CGAL::Normal_of_point_with_normal_pmap<Kernel> Normal_pmap;
|
typedef CGAL::Normal_of_point_with_normal_pmap<Kernel> Normal_pmap;
|
||||||
|
|
||||||
// In Shape_detection_traits_3 the used types, i.e. Point and Vector types
|
// In Shape_detection_traits_3 the basic types, i.e., Point and Vector types
|
||||||
// as well as iterator type and property maps, are defined.
|
// as well as iterator type and property maps, are defined.
|
||||||
typedef CGAL::Shape_detection_traits_3<Kernel,
|
typedef CGAL::Shape_detection_traits_3<Kernel,
|
||||||
Point_list::iterator, Point_pmap, Normal_pmap> ShapeDetectionTraits;
|
Point_list::iterator, Point_pmap, Normal_pmap> ShapeDetectionTraits;
|
||||||
|
|
@ -33,9 +33,9 @@ typedef CGAL::Shape_detection_3<ShapeDetectionTraits> Shape_detection;
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
Point_list points;
|
Point_list points;
|
||||||
|
|
||||||
// Loading a point set from file.
|
// Loads point set from a file.
|
||||||
// read_xyz_points_and_normals takes an OutputIterator for storing the points
|
// read_xyz_points_and_normals takes an OutputIterator for writing the points
|
||||||
// and a property map to store the normal vector with each point.
|
// and a property map for storing the normal vector associated to each point.
|
||||||
std::ifstream stream("cube.xyz");
|
std::ifstream stream("cube.xyz");
|
||||||
|
|
||||||
if (!stream ||
|
if (!stream ||
|
||||||
|
|
@ -46,12 +46,13 @@ int main(int argc, char **argv) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creation of the instance and providing the input data.
|
// Instantiates shape detection engine and provides input data.
|
||||||
Shape_detection sd(points.begin(),
|
Shape_detection sd(points.begin(),
|
||||||
points.end(), Point_pmap(), Normal_pmap());
|
points.end(), Point_pmap(), Normal_pmap());
|
||||||
|
|
||||||
// Shapes to be searched for are registered
|
// Shapes to be detected are registered
|
||||||
// by using the template Shape_factory
|
// by using the template Shape_factory
|
||||||
|
|
||||||
sd.add_shape_factory(new
|
sd.add_shape_factory(new
|
||||||
CGAL::Shape_factory<CGAL::Plane_shape<ShapeDetectionTraits> >);
|
CGAL::Shape_factory<CGAL::Plane_shape<ShapeDetectionTraits> >);
|
||||||
|
|
||||||
|
|
@ -67,42 +68,42 @@ int main(int argc, char **argv) {
|
||||||
sd.add_shape_factory(new
|
sd.add_shape_factory(new
|
||||||
CGAL::Shape_factory<CGAL::Torus_shape<ShapeDetectionTraits> >);
|
CGAL::Shape_factory<CGAL::Torus_shape<ShapeDetectionTraits> >);
|
||||||
|
|
||||||
// Parameterization of the shape detection using the Parameters structure.
|
// Setting parameters for shape detection.
|
||||||
Shape_detection::Parameters op;
|
Shape_detection::Parameters parameters;
|
||||||
|
|
||||||
// 5% probability to miss the largest primitive on each iteration.
|
// 5% probability to miss the largest primitive on each iteration.
|
||||||
op.probability = 0.05f;
|
parameters.probability = 0.05f;
|
||||||
|
|
||||||
// Only extract shapes with at least 500 points.
|
// Detect shapes with at least 500 points.
|
||||||
op.min_points = 500;
|
parameters.min_points = 500;
|
||||||
|
|
||||||
// 0.002 maximum euclidean distance between point and shape.
|
// 0.002 maximum Euclidean distance between a point and a shape.
|
||||||
op.epsilon = 0.002f;
|
parameters.epsilon = 0.002f;
|
||||||
|
|
||||||
// 0.01 maximum euclidean distance between points to be clustered.
|
// 0.01 maximum Euclidean distance between points to be clustered.
|
||||||
op.cluster_epsilon = 0.01f;
|
parameters.cluster_epsilon = 0.01f;
|
||||||
|
|
||||||
// 0.9 < dot(surface_normal, point_normal); maximum normal deviation.
|
// 0.9 < dot(surface_normal, point_normal); maximum normal deviation.
|
||||||
op.normal_threshold = 0.9f;
|
parameters.normal_threshold = 0.9f;
|
||||||
|
|
||||||
// The actual shape detection.
|
// Detects shapes
|
||||||
sd.detect(op);
|
sd.detect(parameters);
|
||||||
|
|
||||||
// Print results.
|
// Prints number of detected shapes and unassigned points.
|
||||||
std::cout << sd.number_of_shapes() << " primitives, "
|
std::cout << sd.number_of_shapes() << " detecte shapes, "
|
||||||
<< sd.number_of_unassigned_points()
|
<< sd.number_of_unassigned_points()
|
||||||
<< " unassigned points" << std::endl;
|
<< " unassigned points." << std::endl;
|
||||||
|
|
||||||
// Shape_detection_3::shapes_begin() provides
|
// Shape_detection_3::shapes_begin() provides
|
||||||
// an iterator to the detected shapes.
|
// an iterator to the detected shapes.
|
||||||
Shape_detection::Shape_iterator it = sd.shapes_begin();
|
Shape_detection::Shape_iterator it = sd.shapes_begin();
|
||||||
while (it != sd.shapes_end()) {
|
while (it != sd.shapes_end()) {
|
||||||
const Shape_detection::Shape *shape = *it;
|
const Shape_detection::Shape *shape = *it;
|
||||||
// Using Shape_base::info() for printing
|
// Uses Shape_base::info() for printing
|
||||||
// the parameters of the detected shape.
|
// the parameters of the detected shape.
|
||||||
std::cout << (*it)->info() << std::endl;
|
std::cout << (*it)->info() << std::endl;
|
||||||
|
|
||||||
// Proceed with next shape.
|
// Proceeds with next detected shape.
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,7 @@ int main(int argc, char **argv) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For time measurement we take the time
|
// Measure time before setting up the shape detection.
|
||||||
// before setting up the shape detection.
|
|
||||||
CGAL::Timer time;
|
CGAL::Timer time;
|
||||||
time.start();
|
time.start();
|
||||||
|
|
||||||
|
|
@ -55,18 +54,17 @@ int main(int argc, char **argv) {
|
||||||
Shape_detection sd(points.begin(),
|
Shape_detection sd(points.begin(),
|
||||||
points.end(), Point_pmap(), Normal_pmap());
|
points.end(), Point_pmap(), Normal_pmap());
|
||||||
|
|
||||||
// Shapes to be searched for are registered
|
// Registers detection of planes
|
||||||
// by using the template Shape_factory
|
|
||||||
sd.add_shape_factory(new
|
sd.add_shape_factory(new
|
||||||
CGAL::Shape_factory<CGAL::Plane_shape<ShapeDetectionTraits> >);
|
CGAL::Shape_factory<CGAL::Plane_shape<ShapeDetectionTraits> >);
|
||||||
|
|
||||||
// The actual shape detection.
|
// Detects shapes.
|
||||||
sd.detect();
|
sd.detect();
|
||||||
|
|
||||||
// Take the time afterwards.
|
// Measures time after detection.
|
||||||
time.stop();
|
time.stop();
|
||||||
|
|
||||||
// Print results.
|
// Prints number of assigned shapes and unsassigned points.
|
||||||
std::cout << "time: " << time.time() * 1000 << "ms" << std::endl;
|
std::cout << "time: " << time.time() * 1000 << "ms" << std::endl;
|
||||||
std::cout << sd.number_of_shapes() << " primitives, "
|
std::cout << sd.number_of_shapes() << " primitives, "
|
||||||
<< sd.number_of_unassigned_points()
|
<< sd.number_of_unassigned_points()
|
||||||
|
|
@ -76,33 +74,37 @@ int main(int argc, char **argv) {
|
||||||
// an iterator to the detected shapes.
|
// an iterator to the detected shapes.
|
||||||
Shape_detection::Shape_iterator it = sd.shapes_begin();
|
Shape_detection::Shape_iterator it = sd.shapes_begin();
|
||||||
while (it != sd.shapes_end()) {
|
while (it != sd.shapes_end()) {
|
||||||
|
|
||||||
const Shape_detection::Shape *shape = *it;
|
const Shape_detection::Shape *shape = *it;
|
||||||
// Using Shape_base::info() for printing
|
// Using Shape_base::info() for printing
|
||||||
// the parameters of the detected shape.
|
// the parameters of the detected shape.
|
||||||
std::cout << (*it)->info();
|
std::cout << (*it)->info();
|
||||||
|
|
||||||
// Determine mean distance of points to detected shape.
|
// Sum distances of points to detected shapes.
|
||||||
FT mean_distance = 0;
|
FT sum_distances = 0.f;
|
||||||
// Iterate through indices of points assigned to each shape.
|
|
||||||
|
// Iterate through point indices assigned to each detected shape.
|
||||||
std::vector<size_t>::const_iterator
|
std::vector<size_t>::const_iterator
|
||||||
indexIt = (*it)->assigned_points().begin();
|
indexIt = (*it)->assigned_points().begin();
|
||||||
|
|
||||||
while (indexIt != (*it)->assigned_points().end()) {
|
while (indexIt != (*it)->assigned_points().end()) {
|
||||||
// Retrieve point
|
|
||||||
|
// Retrieve point
|
||||||
const Point &p = *(points.begin() + (*indexIt));
|
const Point &p = *(points.begin() + (*indexIt));
|
||||||
|
|
||||||
// Add Euclidean distance between point and shape.
|
// Add Euclidean distance between point and shape.
|
||||||
mean_distance += sqrt((*it)->squared_distance(p));
|
sum_distances += sqrt((*it)->squared_distance(p));
|
||||||
|
|
||||||
// Proceed with next point.
|
// Proceed with next point.
|
||||||
indexIt++;
|
indexIt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Divide sum of distance by number of points.
|
// Compute average distance.
|
||||||
mean_distance /= shape->assigned_points().size();
|
const FT average_distance = sum_distances / shape->assigned_points().size();
|
||||||
|
|
||||||
std::cout << " mean error: " << mean_distance << std::endl;
|
std::cout << " average distance: " << average_distance << std::endl;
|
||||||
|
|
||||||
// Proceed with next shape.
|
// Proceed with next detected shape.
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue