BSPImplT.hh 5.82 KB
Newer Older
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62




//=============================================================================
//
//  CLASS BSPImplT
//
//=============================================================================

#ifndef BSPIMPLT_HH
#define BSPIMPLT_HH


//== INCLUDES =================================================================


#include <OpenMesh/Core/Geometry/VectorT.hh>


//== CLASS DEFINITION =========================================================
Jan Möbius's avatar
Marlin:    
Jan Möbius committed
63
#include <vector>
Jan Möbius's avatar
 
Jan Möbius committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93


template <class BSPCore>
class BSPImplT : public BSPCore
{
public: //---------------------------------------------------------------------

  typedef typename BSPCore::Traits      Traits;
  typedef typename BSPCore::Handle      Handle;
  typedef typename BSPCore::Point       Point;
  typedef typename BSPCore::Scalar      Scalar;
  typedef typename BSPCore::Node        Node;
  typedef typename BSPCore::Handles     Handles;
  typedef typename BSPCore::HandleIter  HandleIter;
  

public: //---------------------------------------------------------------------

  BSPImplT(const Traits& _traits) : BSPCore(_traits) {}
  ~BSPImplT() {}


  /// Store nearest neighbor information
  struct NearestNeighbor
  {
    NearestNeighbor() {}
    NearestNeighbor(Handle _h, Scalar _d) : handle(_h), dist(_d) {}
    Handle  handle;
    Scalar  dist;
  };
Jan Möbius's avatar
Marlin:    
Jan Möbius committed
94
95
96
97
98
99
100
101
102
103
  
  /// Store nearest neighbor information
  struct RayCollision
  {
    RayCollision() {}
    RayCollision(Handle _h, Scalar _d, std::vector<Handle> _v) : handle(_h), dist(_d), hit_vertices(_v) {}
    Handle  handle;
    Scalar  dist;
    std::vector<Handle> hit_vertices;
  };
Jan Möbius's avatar
 
Jan Möbius committed
104

105
  /// Return handle of the nearest neighbor face
Jan Möbius's avatar
 
Jan Möbius committed
106
  NearestNeighbor nearest(const Point& _p) const;
107
  
Jan Möbius's avatar
Marlin:    
Jan Möbius committed
108
109
  /// Return handles of all hit collided faces, and the handle of the nearest collided face
  RayCollision raycollision (const Point& _p, const Point& _r) const;
Jan Möbius's avatar
 
Jan Möbius committed
110
111
112
113
114
115
116
117
118
119
120
121
  

private: //---------------------------------------------------------------------


  /// Store nearest neighbor information
  struct NearestNeighborData
  {
    Point   ref;
    Scalar  dist;
    Handle  nearest;
  };
122
123
124
125
126
127
128
129
  
  /// Store ray collide information
  struct RayCollisionData
  {
    Point   ref;
    Point   ray;
    Scalar  dist;
    Handle  nearest;
Jan Möbius's avatar
Marlin:    
Jan Möbius committed
130
    std::vector<Handle> hit_vertices;
131
  };
Jan Möbius's avatar
 
Jan Möbius committed
132
133
134
135


  // Recursive part of nearest()
  void _nearest(Node* _node, NearestNeighborData& _data) const;
136
137
138
  
  //resursive part of raycollide()
  void _raycollision(Node* _node, RayCollisionData& _data) const;
Jan Möbius's avatar
 
Jan Möbius committed
139
140
141
142
143
144
145
146
147
148
149
};


//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(BSPIMPLT_C)
#  define BSPIMPLT_TEMPLATES
#  include "BSPImplT.cc"
#endif
//=============================================================================
#endif // BSPIMPLT_HH defined
//=============================================================================