snc_point_locator.h
来自「CGAL is a collaborative effort of severa」· C头文件 代码 · 共 889 行 · 第 1/3 页
H
889 行
#line 7 "point_locator.nw"// Copyright (c) 1997-2000 Max-Planck-Institute Saarbruecken (Germany).// All rights reserved.//// This file is part of CGAL (www.cgal.org); you may redistribute it under// the terms of the Q Public License version 1.0.// See the file LICENSE.QPL distributed with CGAL.//// Licensees holding a valid commercial license may use this file in// accordance with the commercial license agreement provided with the software.//// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.//// $Source: /CVSROOT/CGAL/Packages/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h,v $// $Revision: 1.29.2.3 $ $Date: 2004/12/08 19:30:55 $// $Name: $//// Author(s) : Miguel Granados <granados@mpi-sb.mpg.de>#ifndef SNC_POINT_LOCATOR_H#define SNC_POINT_LOCATOR_H#include <CGAL/basic.h>#include <CGAL/Nef_3/SNC_intersection.h>#include <CGAL/Nef_3/SNC_ray_shooter.h>#include <CGAL/Nef_3/SNC_k3_tree_traits.h>#include <CGAL/Nef_3/K3_tree.h>#include <CGAL/Unique_hash_map.h>#include <CGAL/Timer.h>// #include <CGAL/Polygon_triangulation_traits_2.h>// #include <CGAL/Nef_3/triangulate_nef3_facet.h>#undef CGAL_NEF_DEBUG#define CGAL_NEF_DEBUG 509#include <CGAL/Nef_2/debug.h>#undef _CGAL_NEF_TRACEN#define _CGAL_NEF_TRACEN(msg) CGAL_NEF_TRACEN( "SNC_point_locator: " << msg);// TODO: find out the proper CGAL replacement for this macro and remove it#define CGAL_for_each( i, C) for( i = C.begin(); i != C.end(); ++i)// #define TIMER(instruction) instruction#define TIMER(instruction)// #define CLOG(t) std::clog <<" "<<t<<std::endl; std::clog.flush()#define CLOG(t)CGAL_BEGIN_NAMESPACEtemplate <typename SNC_decorator>class SNC_point_locator{ public: class Intersection_call_back; typedef SNC_point_locator<SNC_decorator> Self; typedef typename SNC_decorator::Decorator_traits Decorator_traits; typedef typename SNC_decorator::SNC_structure SNC_structure;protected: char version_[64]; // time for construction, point location, ray shooting and intersection test mutable Timer ct_t, pl_t, rs_t, it_t; public: typedef typename SNC_structure::Object_handle Object_handle; typedef typename SNC_structure::Halfedge_const_handle Halfedge_const_handle; typedef typename SNC_structure::Halffacet_const_handle Halffacet_const_handle; typedef typename SNC_structure::Halffacet_triangle_handle Halffacet_triangle_handle; typedef typename SNC_structure::Point_3 Point_3; typedef typename SNC_structure::Segment_3 Segment_3; typedef typename SNC_structure::Ray_3 Ray_3; typedef typename SNC_structure::Vector_3 Vector_3; typedef typename SNC_structure::Triangle_3 Triangle_3; typedef typename SNC_structure::Aff_transformation_3 Aff_transformation_3; typedef typename Decorator_traits::Vertex_handle Vertex_handle; typedef typename Decorator_traits::Halfedge_handle Halfedge_handle; typedef typename Decorator_traits::Halffacet_handle Halffacet_handle; typedef typename Decorator_traits::Volume_handle Volume_handle; typedef typename Decorator_traits::Vertex_iterator Vertex_iterator; typedef typename Decorator_traits::Halfedge_iterator Halfedge_iterator; typedef typename Decorator_traits::Halffacet_iterator Halffacet_iterator; const char* version() { return version_; } virtual Object_handle locate(const Point_3& p) const = 0; virtual Object_handle shoot(const Ray_3& s) const = 0; virtual void intersect_with_edges( Halfedge_const_handle edge, const Intersection_call_back& call_back) const = 0; virtual void intersect_with_facets( Halfedge_const_handle edge, const Intersection_call_back& call_back) const = 0; virtual void intersect_with_edges_and_facets( Halfedge_const_handle edge, const Intersection_call_back& call_back) const = 0; class Intersection_call_back { public: virtual void operator()( Halfedge_const_handle edge, Object_handle object, const Point_3& intersection_point) const = 0; }; virtual void initialize(SNC_structure* W) = 0; virtual Self* clone() const = 0; virtual void transform(const Aff_transformation_3& t) = 0; //virtual bool update( Unique_hash_map<Vertex_handle, bool>& V, // Unique_hash_map<Halfedge_handle, bool>& E, // Unique_hash_map<Halffacet_handle, bool>& F) = 0; virtual ~SNC_point_locator() { CLOG(""); CLOG("construction_time: "<<ct_t.time()); CLOG("pointlocation_time: "<<pl_t.time()); CLOG("rayshooting_time: "<<rs_t.time()); CLOG("intersection_time: "<<it_t.time()); // warning: the total time showed here could be actually larger // that the real time used by this class, since point location // and intersection test use the ray shooter and so the same time // could be account to more than one timer CLOG("pltotal_time: "<< ct_t.time()+pl_t.time()+rs_t.time()+it_t.time()); };};template <typename SNC_decorator>class SNC_point_locator_by_spatial_subdivision : public SNC_point_locator<SNC_decorator>, public SNC_decorator{ typedef SNC_decorator Base; typedef CGAL::SNC_point_locator<SNC_decorator> SNC_point_locator; typedef CGAL::SNC_point_locator_by_spatial_subdivision<SNC_decorator> Self; typedef typename SNC_decorator::SNC_structure SNC_structure; typedef typename SNC_decorator::Decorator_traits Decorator_traits; typedef typename Decorator_traits::SM_decorator SM_decorator; typedef CGAL::SNC_intersection<SNC_structure> SNC_intersection; typedef typename SNC_decorator::SM_point_locator SM_point_locator; typedef typename SNC_decorator::Kernel Kernel;public: typedef typename CGAL::SNC_k3_tree_traits<SNC_decorator> K3_tree_traits; typedef typename CGAL::K3_tree<K3_tree_traits> K3_tree; typedef K3_tree SNC_candidate_provider; typedef typename SNC_structure::Object_handle Object_handle; typedef typename SNC_structure::Halfedge_const_handle Halfedge_const_handle; typedef typename SNC_structure::Halffacet_const_handle Halffacet_const_handle; typedef typename SNC_structure::Halffacet_triangle_handle Halffacet_triangle_handle; typedef typename SNC_structure::Point_3 Point_3; typedef typename SNC_structure::Segment_3 Segment_3; typedef typename SNC_structure::Ray_3 Ray_3; typedef typename SNC_structure::Vector_3 Vector_3; typedef typename SNC_structure::Triangle_3 Triangle_3; typedef typename SNC_structure::Aff_transformation_3 Aff_transformation_3; typedef typename SNC_structure::Infi_box Infi_box; typedef typename Decorator_traits::Vertex_handle Vertex_handle; typedef typename Decorator_traits::Halfedge_handle Halfedge_handle; typedef typename Decorator_traits::Halffacet_handle Halffacet_handle; typedef typename Decorator_traits::SHalfedge_handle SHalfedge_handle; typedef typename Decorator_traits::SFace_handle SFace_handle; typedef typename Decorator_traits::Vertex_iterator Vertex_iterator; typedef typename Decorator_traits::Halfedge_iterator Halfedge_iterator; typedef typename Decorator_traits::Halffacet_iterator Halffacet_iterator; typedef typename Decorator_traits::Volume_handle Volume_handle; typedef typename SNC_candidate_provider::Object_list Object_list; typedef typename Object_list::iterator Object_list_iterator; typedef typename SNC_candidate_provider::Objects_along_ray Objects_along_ray; typedef typename Objects_along_ray::Iterator Objects_along_ray_iterator;public: SNC_point_locator_by_spatial_subdivision() : initialized(false), candidate_provider(0) {} virtual void initialize(SNC_structure* W) { TIMER(ct_t.start()); strcpy( this->version_, "Point Locator by Spatial Subdivision (tm)");#ifdef CGAL_NEF3_TRIANGULATE_FACETS CLOG(version()<<" (with triangulated facets)");#else CLOG(version());#endif CGAL_assertion( W != NULL);// (Base) *this = SNC_decorator(*W); set_snc(*W); initialized = true; Object_list objects; Vertex_iterator v; Halfedge_iterator e; Halffacet_iterator f; CGAL_forall_vertices( v, *this->sncp()) objects.push_back(Object_handle(Vertex_handle(v))); typename Object_list::difference_type v_end = objects.size(); CGAL_forall_edges( e, *this->sncp()) objects.push_back(Object_handle(Halfedge_handle(e))); CGAL_forall_facets( f, *this->sncp()) {#ifdef CGAL_NEF3_TRIANGULATE_FACETS typedef typename std::list<Triangle_3> Triangles; typedef typename Triangles::const_iterator Triangles_iterator; typedef Polygon_triangulation_traits_2<Kernel> Triangulation_traits; Triangles triangles; triangulate_facet<SNC_structure> ( f, std::back_inserter(triangles), Triangulation_traits()); for( Triangles_iterator ti = triangles.begin(); ti != triangles.end(); ++ti) { Halffacet_triangle_handle th( f, *ti); objects.push_back(Object_handle(th)); CGAL_assertion( CGAL::assign( th, *(--objects.end()))); CGAL_assertion( th.get_triangle() == *ti); }#else objects.push_back(Object_handle(Halffacet_handle(f)));#endif // CGAL_NEF3_TRIANGULATE_FACETS } Object_list_iterator oli=objects.begin()+v_end; candidate_provider = new SNC_candidate_provider(objects,oli);// CGAL_NEF_TRACEN(*candidate_provider); TIMER(ct_t.stop()); } virtual Self* clone() const { return new Self; } virtual void transform(const Aff_transformation_3& t) { candidate_provider->transform(t); } virtual bool update( Unique_hash_map<Vertex_handle, bool>& V, Unique_hash_map<Halfedge_handle, bool>& E, Unique_hash_map<Halffacet_handle, bool>& F) { TIMER(ct_t.start()); CGAL_assertion( initialized); bool updated = candidate_provider->update( V, E, F); TIMER(ct_t.stop()); return updated; } virtual ~SNC_point_locator_by_spatial_subdivision() { CGAL_warning( initialized); // required? delete candidate_provider; } virtual Object_handle shoot(const Ray_3& ray) const { TIMER(rs_t.start()); CGAL_assertion( initialized); _CGAL_NEF_TRACEN( "shooting: "<<ray); Object_handle result; Vertex_handle v; Halfedge_handle e; Halffacet_handle f; Halffacet_triangle_handle t; bool hit = false; Point_3 eor; // 'end of ray', the latest ray's hit point Objects_along_ray objects = candidate_provider->objects_along_ray(ray); Objects_along_ray_iterator objects_iterator = objects.begin(); while( !hit && objects_iterator != objects.end()) { Object_list candidates = *objects_iterator; Object_list_iterator o; CGAL_for_each( o, candidates) { if( CGAL::assign( v, *o)) { _CGAL_NEF_TRACEN("trying vertex on "<<point(v)); if( ray.source() != point(v) && ray.has_on(point(v))) { _CGAL_NEF_TRACEN("the ray intersects the vertex"); _CGAL_NEF_TRACEN("prev. intersection? "<<hit); if( hit) _CGAL_NEF_TRACEN("prev. intersection on "<<eor); if( hit && !Segment_3( ray.source(), eor).has_on(point(v))) continue; eor = point(v); result = Object_handle(v); hit = true; _CGAL_NEF_TRACEN("the vertex becomes the new hit object"); } } else if( CGAL::assign( e, *o)) { Point_3 q; _CGAL_NEF_TRACEN("trying edge on "<< Segment_3(e->source()->point(),e->twin()->source()->point())); if( is.does_intersect_internally( ray, Segment_3(e->source()->point(), e->twin()->source()->point()), q)) { _CGAL_NEF_TRACEN("ray intersects edge on "<<q); _CGAL_NEF_TRACEN("prev. intersection? "<<hit);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?