Developer Documentation

BSPImplT.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 //=============================================================================
44 //
45 // CLASS BSPImplT
46 //
47 //=============================================================================
48
49 #ifndef BSPIMPLT_HH
50 #define BSPIMPLT_HH
51
52
53 //== INCLUDES =================================================================
54
55
56 #include <OpenMesh/Core/Geometry/VectorT.hh>
57
58
59 //== CLASS DEFINITION =========================================================
60 #include <vector>
61 #include <ostream>
62
63 template <class BSPCore>
64 class BSPImplT : public BSPCore
65 {
66 public: //---------------------------------------------------------------------
67
68 typedef typename BSPCore::Traits Traits;
69 typedef typename BSPCore::Handle Handle;
70 typedef typename BSPCore::Point Point;
71 typedef typename BSPCore::Scalar Scalar;
72 typedef typename BSPCore::Node Node;
73 typedef typename BSPCore::Handles Handles;
74 typedef typename BSPCore::HandleIter HandleIter;
75
76
77 public: //---------------------------------------------------------------------
78
79 BSPImplT(const Traits& _traits, const Scalar& _infinity = std::numeric_limits<Scalar>::infinity()) :
80 BSPCore(_traits),
81 infinity_(_infinity) {}
82 ~BSPImplT() {}
83
84
86 struct NearestNeighbor
87 {
88 NearestNeighbor() {}
89 NearestNeighbor(Handle _h, Scalar _d) : handle(_h), dist(_d) {}
90 Handle handle;
91 Scalar dist;
92 };
93
95 typedef std::vector< std::pair<Handle,Scalar> > RayCollision;
96
98 NearestNeighbor nearest(const Point& _p) const;
99
110 RayCollision raycollision (const Point& _p, const Point& _r) const;
111
123 RayCollision directionalRaycollision (const Point& _p, const Point& _r) const;
124
137 RayCollision nearestRaycollision(const Point& _p, const Point& _r) const;
138
150 template<class Callback>
151 void intersectBall(const Point & _c, Scalar _r, Callback _callback) const;
152
153 private: //---------------------------------------------------------------------
154
155
157 struct NearestNeighborData
158 {
159 Point ref;
160 Scalar dist;
161 Handle nearest;
162
163 friend std::ostream &operator<< (std::ostream &stream, const NearestNeighborData &data) {
164 stream << "[NearestNeghborData instance. ref: " << data.ref << ", dist: " << data.dist << ", nearest: " << data.nearest.idx() << "]";
165 return stream;
166 }
167 };
168
170 struct RayCollisionData
171 {
172 RayCollisionData() : ref(), ray() {}
173
174 Point ref;
175 Point ray;
176 RayCollision hit_handles;
177 };
178
179
180 // Recursive part of nearest()
181 void _nearest(Node* _node, NearestNeighborData& _data) const;
182
188 void _raycollision_non_directional(Node* _node, RayCollisionData& _data) const;
189
195 void _raycollision_directional(Node* _node, RayCollisionData& _data) const;
196
197 void _raycollision_nearest_directional(Node* _node, RayCollisionData& _data) const;
198
199 template<class Callback>
200 void _intersect_ball(const Node& _node, const Point & _c, Scalar _r, Callback _callback) const;
201
202 template<typename T,typename U>
203 struct less_pair_second: public std::binary_function<T,U,bool> {
204 bool operator()(const std::pair<T,U> &left, const std::pair<T,U> &right) {
205 return (fabs(left.second) < fabs(right.second));
206 }
207 };
208
209 const Scalar infinity_;
210
211 };
212
213 //=============================================================================
214 #if defined(OM_INCLUDE_TEMPLATES) && !defined(BSPIMPLT_C)
215 # define BSPIMPLT_TEMPLATES
216 # include "BSPImplT_impl.hh"
217 #endif
218 //=============================================================================
219 #endif // BSPIMPLT_HH defined
220 //=============================================================================
BSPImplT::RayCollisionData
Store ray collide information.
Definition: BSPImplT.hh:170
BSPImplT::raycollision
RayCollision raycollision(const Point &_p, const Point &_r) const
intersect mesh with ray
Definition: BSPImplT_impl.hh:127
BSPImplT::nearest
NearestNeighbor nearest(const Point &_p) const
Return handle of the nearest neighbor face.
Definition: BSPImplT_impl.hh:68
BSPImplT::_raycollision_directional
void _raycollision_directional(Node *_node, RayCollisionData &_data) const
recursive part of directionalRaycollision()
Definition: BSPImplT_impl.hh:229
BSPImplT::nearestRaycollision
RayCollision nearestRaycollision(const Point &_p, const Point &_r) const
intersect mesh with ray
Definition: BSPImplT_impl.hh:162
BSPImplT::_raycollision_non_directional
void _raycollision_non_directional(Node *_node, RayCollisionData &_data) const
recursive part of raycollision()
Definition: BSPImplT_impl.hh:191
BSPImplT
Definition: BSPImplT.hh:64
BSPImplT::NearestNeighborData
Store nearest neighbor information.
Definition: BSPImplT.hh:157
BSPImplT::RayCollision
std::vector< std::pair< Handle, Scalar > > RayCollision
Store nearest neighbor information.
Definition: BSPImplT.hh:95
BSPImplT::directionalRaycollision
RayCollision directionalRaycollision(const Point &_p, const Point &_r) const
intersect mesh with ray
Definition: BSPImplT_impl.hh:144
BSPImplT::less_pair_second
Definition: BSPImplT.hh:203
BSPImplT::NearestNeighbor
Store nearest neighbor information.
Definition: BSPImplT.hh:86
BSPImplT::intersectBall
void intersectBall(const Point &_c, Scalar _r, Callback _callback) const
intersect mesh with open ball
Definition: BSPImplT_impl.hh:179