From 7a0b2326e170da7efda10d8fa339ba65935e0a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 20 Jul 2011 21:59:14 +0000 Subject: [PATCH] add property_map as template parameter of segment and triangle primitive and add a template parameter to enable or disable the caching of the or object inside the primitive. Pb to handle: in case the object is not cached, point() might be expansive --- .gitattributes | 1 + .../include/CGAL/AABB_segment_primitive.h | 34 +++++----- .../include/CGAL/AABB_triangle_primitive.h | 54 ++++++++-------- .../internal/AABB_tree/Primitive_caching.h | 62 +++++++++++++++++++ 4 files changed, 109 insertions(+), 42 deletions(-) create mode 100644 AABB_tree/include/CGAL/internal/AABB_tree/Primitive_caching.h diff --git a/.gitattributes b/.gitattributes index 8934bf9f7fa..70f73f8952c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -43,6 +43,7 @@ AABB_tree/include/CGAL/AABB_segment_primitive.h -text AABB_tree/include/CGAL/AABB_traits.h -text AABB_tree/include/CGAL/AABB_triangle_primitive.h -text AABB_tree/include/CGAL/internal/AABB_tree/AABB_search_tree.h -text +AABB_tree/include/CGAL/internal/AABB_tree/Primitive_caching.h -text AABB_tree/include/CGAL/internal/AABB_tree/nearest_point_segment_3.h -text AABB_tree/test/AABB_tree/AABB_test_util.h -text AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp -text diff --git a/AABB_tree/include/CGAL/AABB_segment_primitive.h b/AABB_tree/include/CGAL/AABB_segment_primitive.h index 27aaf13a9dd..6777922b5be 100644 --- a/AABB_tree/include/CGAL/AABB_segment_primitive.h +++ b/AABB_tree/include/CGAL/AABB_segment_primitive.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// Copyright (c) 2009, 2011 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -15,7 +15,7 @@ // $Id$ // // -// Author(s) : Pierre Alliez, Stephane Tayeb +// Author(s) : Pierre Alliez, Stephane Tayeb, Sebastien Loriot // //****************************************************************************** // File Description : @@ -25,12 +25,20 @@ #ifndef CGAL_AABB_SEGMENT_PRIMITIVE_H_ #define CGAL_AABB_SEGMENT_PRIMITIVE_H_ +#include +#include + namespace CGAL { -template -class AABB_segment_primitive +template , + bool cache_primitive=true> +class AABB_segment_primitive : + public internal::Primitive_caching { // types + typedef internal::Primitive_caching Base; public: typedef typename GeomTraits::Point_3 Point; // point type typedef typename GeomTraits::Segment_3 Datum; // datum type @@ -39,29 +47,23 @@ public: // member data private: Id m_it; - Datum m_datum; - public: // constructors AABB_segment_primitive() {} - AABB_segment_primitive(Id it) + AABB_segment_primitive(Id it,PropertyMap pmap=PropertyMap()) : m_it(it) { - m_datum = *it; // copy segment - } - AABB_segment_primitive(const AABB_segment_primitive& primitive) - { - m_it = primitive.id(); - m_datum = primitive.datum(); + this->set_primitive(it,pmap); } public: Id& id() { return m_it; } const Id& id() const { return m_it; } - Datum& datum() { return m_datum; } - const Datum& datum() const { return m_datum; } + typename Base::result_type datum() const { + return this->get_primitive(m_it); + } /// Returns a point on the primitive - Point reference_point() const { return m_datum.source(); } + Point reference_point() const { return datum().source(); } }; } // end namespace CGAL diff --git a/AABB_tree/include/CGAL/AABB_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_triangle_primitive.h index 1696cd7c0ca..d325d16e6ed 100644 --- a/AABB_tree/include/CGAL/AABB_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_triangle_primitive.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// Copyright (c) 2009, 2011 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -15,7 +15,7 @@ // $Id$ // // -// Author(s) : Pierre Alliez, Stephane Tayeb +// Author(s) : Pierre Alliez, Stephane Tayeb, Sebastien Loriot // //****************************************************************************** // File Description : @@ -25,44 +25,46 @@ #ifndef CGAL_AABB_TRIANGLE_PRIMITIVE_H_ #define CGAL_AABB_TRIANGLE_PRIMITIVE_H_ +#include +#include + namespace CGAL { - template - class AABB_triangle_primitive - { - public: +template , + bool cache_primitive=true> +class AABB_triangle_primitive : + public internal::Primitive_caching +{ // types - typedef Iterator Id; // Id type + typedef internal::Primitive_caching Base; +public: typedef typename GeomTraits::Point_3 Point; // point type typedef typename GeomTraits::Triangle_3 Datum; // datum type + typedef Iterator Id; // Id type - private: // member data - Id m_it; // iterator - Datum m_datum; // 3D triangle - - // constructor - public: +private: + Id m_it; +public: + // constructors AABB_triangle_primitive() {} - AABB_triangle_primitive(Id it) - : m_it(it) + AABB_triangle_primitive(Id it,PropertyMap pmap=PropertyMap()) + : m_it(it) { - m_datum = *it; // copy triangle + this->set_primitive(it,pmap); } - AABB_triangle_primitive(const AABB_triangle_primitive& primitive) - { - m_datum = primitive.datum(); - m_it = primitive.id(); - } - public: +public: Id& id() { return m_it; } const Id& id() const { return m_it; } - Datum& datum() { return m_datum; } - const Datum& datum() const { return m_datum; } + typename Base::result_type datum() const { + return this->get_primitive(m_it); + } /// Returns a point on the primitive - Point reference_point() const { return m_datum.vertex(0); } - }; + Point reference_point() const { return datum().vertex(0); } +}; } // end namespace CGAL diff --git a/AABB_tree/include/CGAL/internal/AABB_tree/Primitive_caching.h b/AABB_tree/include/CGAL/internal/AABB_tree/Primitive_caching.h new file mode 100644 index 00000000000..ffed226945d --- /dev/null +++ b/AABB_tree/include/CGAL/internal/AABB_tree/Primitive_caching.h @@ -0,0 +1,62 @@ +// Copyright (c) 2011 GeometryFactory (France). +// 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. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Sebastien Loriot +// +//****************************************************************************** +// File Description : +// +//****************************************************************************** + + +#ifndef CGAL_INTERNAL_AABB_TREE_PRIMITIVE_CACHING_H +#define CGAL_INTERNAL_AABB_TREE_PRIMITIVE_CACHING_H + +namespace CGAL { +namespace internal{ + + template + struct Primitive_caching; + + template + struct Primitive_caching + { + typedef const Primitive& result_type; + Primitive datum; + + void set_primitive(Id id,PropertyMap pmap){datum=get(pmap,*id);} + result_type get_primitive(Id) const{ + return datum; + } + }; + + template + struct Primitive_caching + { + typedef Primitive result_type; + PropertyMap pmap_; + + void set_primitive(Id,PropertyMap pmap){pmap_=pmap;} + result_type get_primitive(Id id) const{ + return get(pmap_,*id); + } + }; + + +} } //namespace CGAL::internal + +#endif