Subject: CGAL users discussion list
List archive
- From: hardik kabaria <>
- To: "" <>
- Subject: [cgal-discuss] AABB Tree: Seg fault
- Date: Fri, 16 Jan 2015 14:49:58 -0800
Hi everyone,
--
I am having some trouble with AABB tree and finding closest point projection to a given query point.
cgal @4.5 gis/cgal
gcc version 4.8.2
I have triangular mesh file ,
and the corresponding .cpp file is pasted here
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/AABB_polyhedron_triangle_primitive.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <iostream>
#include <fstream>
// typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::FT FT;
typedef K::Point_3 Point;
typedef K::Segment_3 Segment;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_polyhedron_triangle_primitive<K,Polyhedron> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef Tree::Object_and_primitive_id Object_and_primitive_id;
typedef Tree::Point_and_primitive_id Point_and_primitive_id;
int main()
{
Point p(1.0, 0.0, 0.0);
Point q(0.0, 1.0, 0.0);
Point r(0.0, 0.0, 1.0);
Point s(0.0, 0.0, 0.0);
Polyhedron polyhedron;
std::ifstream input("./poisson_rec.off");
input>>polyhedron;
// polyhedron.make_tetrahedron(p, q, r, s);
// constructs AABB tree and computes internal KD-tree
// data structure to accelerate distance queries
Tree tree(polyhedron.facets_begin(),polyhedron.facets_end());
tree.accelerate_distance_queries();
// query point
Point query(0.5, 0.5, 0.5);
// computes squared distance from query
FT sqd = tree.squared_distance(query);
std::cout << "squared distance: " << sqd << std::endl;
// computes closest point
Point closest = tree.closest_point(query);
std::cout << "closest point: " << closest << std::endl;
// computes closest point and primitive id
Point_and_primitive_id pp = tree.closest_point_and_primitive(query);
Point cpt = tree.closest_point(Point(0.5,0.5,0.5));
std::cout<<cpt<<std::endl;
Point closest_point = pp.first;
Polyhedron::Face_handle f = pp.second; // closest primitive id
std::cout << "closest point: " << closest_point << std::endl;
std::cout << "closest triangle: ( "
<< f->halfedge()->vertex()->point() << " , "
<< f->halfedge()->next()->vertex()->point() << " , "
<< f->halfedge()->next()->next()->vertex()->point()
<< " )" << std::endl;
return EXIT_SUCCESS;
}
It gives me segmentation fault. The .cpp is exactly that of AABB_polyhedron_facet_distance_example.cpp
Can someone shade light on what am I doing wrong ?
Thanks!
Hardik Kabaria
Ph.D. Candidate
Department of Mechanical Engineering
Stanford University
Ph.D. Candidate
Department of Mechanical Engineering
Stanford University
- [cgal-discuss] AABB Tree: Seg fault, hardik kabaria, 01/16/2015
- Re: [cgal-discuss] AABB Tree: Seg fault, Etienne Vouga, 01/16/2015
Archive powered by MHonArc 2.6.18.