source: GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h @ 2629

Revision 2629, 5.6 KB checked in by bittner, 17 years ago (diff)

commit after merge with vlastimil

RevLine 
[2582]1#ifndef _HavranRayCaster_H__
2#define _HavranRayCaster_H__
3
4#include "RayCaster.h"
5#include "Containers.h"
6#include <string>
[2592]7#include "ktbconf.h"
8#include "raypack.h"
[2582]9
10namespace GtpVisibilityPreprocessor {
11
12
13class Intersectable;
14class VssRay;
15class KdTree;
16class Ray;
17class SimpleRayContainer;
18class AxisAlignedBox3;
19class Vector3;
20struct VssRayContainer;
21class Preprocessor;
22struct SimpleRay;
23class CKTB;
24
[2629]25// This macro should be undefined when testing ray tracing
26// by casting rays from file or using camera
27#define _PROCESS_RAY
28
[2582]29/** This class provides an interface for ray casting.
30*/
31class HavranRayCaster: public RayCaster
32{
33public:
34  /** Default constructor initialising e.g., KD tree
35   */
36  HavranRayCaster(const Preprocessor &preprocessor);
37  virtual ~HavranRayCaster();
38
39  void Build(ObjectContainer &objlist);
40 
41  int Type() const { return HAVRAN_RAYCASTER; }
[2629]42 
[2582]43  virtual int CastRay(
44                      const SimpleRay &simpleRay,
45                      VssRayContainer &vssRays,
46                      const AxisAlignedBox3 &box,
47                      const bool castDoubleRay,
48                      const bool pruneInvalidRays = true
49                      );
50 
51  virtual void CastRays16(SimpleRayContainer &rays,
52                          VssRayContainer &vssRays,
53                          const AxisAlignedBox3 &sbox,
54                          const bool castDoubleRay,
55                          const bool pruneInvalidRays = true
56                          );
57
58  virtual void CastRays16(SimpleRayContainer &rays,
59                          int offset,
60                          VssRayContainer &vssRays,
61                          const AxisAlignedBox3 &sbox,
62                          const bool castDoubleRay,
63                          const bool pruneInvalidRays = true
64                          ); 
65  void
66  CastSimpleForwardRays(SimpleRayContainer &rays,
67                        const AxisAlignedBox3 &sbox
68                        );
69
70  virtual void CastRays(
71                        SimpleRayContainer &rays,
72                        VssRayContainer &vssRays,
73                        const AxisAlignedBox3 &sbox,
74                        const bool castDoubleRay,
75                        const bool pruneInvalidRays = true);
[2592]76
77  // Using packet of 4 rays supposing that these are coherent
78  // We give a box to which each ray is clipped to before the
79  // ray shooting is computed !
[2599]80  virtual void CastRaysPacket4(const Vector3 &minBox,
[2602]81                               const Vector3 &maxBox,
82                               const Vector3 origin4[],
83                               const Vector3 direction4[],
84                               int     result4[],
85                               float   dist4[]);
[2592]86
87#ifdef _USE_HAVRAN_SSE 
88  // Just for testing concept
89  virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
90                                 bool castDoubleRay,
91                                 const bool pruneInvalidRays = true);
92#endif 
93
94  bool ExportBinTree(const string &filename);
95  bool ImportBinTree(const string &filename, ObjectContainer &objects);
96 
[2582]97protected:
98  CKTB *mKtbtree;
[2629]99#ifdef _USE_HAVRAN_SSE
100  static GALIGN16 RayPacket2x2 raypack;
101#endif
[2582]102};
103
104
[2629]105// --------------------------------------------------------------------
106// The implementation of ray caster with dynamic objects
107
108class HavranDynRayCaster: public HavranRayCaster
109{
110public:
111  /** Default constructor initialising e.g., KD tree
112   */
113  HavranDynRayCaster(const Preprocessor &preprocessor);
114  virtual ~HavranDynRayCaster();
115
116  int Type() const { return HAVRAN_DYN_RAYCASTER; }
117 
118  virtual int CastRay(const SimpleRay &simpleRay,
119                      VssRayContainer &vssRays,
120                      const AxisAlignedBox3 &box,
121                      const bool castDoubleRay,
122                      const bool pruneInvalidRays = true
123                      );
124 
125  virtual void CastRays16(SimpleRayContainer &rays,
126                          VssRayContainer &vssRays,
127                          const AxisAlignedBox3 &sbox,
128                          const bool castDoubleRay,
129                          const bool pruneInvalidRays = true
130                          );
131
132  virtual void CastRays16(SimpleRayContainer &rays,
133                          int offset,
134                          VssRayContainer &vssRays,
135                          const AxisAlignedBox3 &sbox,
136                          const bool castDoubleRay,
137                          const bool pruneInvalidRays = true
138                          );
139  virtual void
140  CastSimpleForwardRays(SimpleRayContainer &rays,
141                        const AxisAlignedBox3 &sbox);
142
143  virtual void CastRays(SimpleRayContainer &rays,
144                        VssRayContainer &vssRays,
145                        const AxisAlignedBox3 &sbox,
146                        const bool castDoubleRay,
147                        const bool pruneInvalidRays = true);
148
149  // Using packet of 4 rays supposing that these are coherent
150  // We give a box to which each ray is clipped to before the
151  // ray shooting is computed !
152  virtual void CastRaysPacket4(const Vector3 &minBox,
153                               const Vector3 &maxBox,
154                               const Vector3 origin4[],
155                               const Vector3 direction4[],
156                               int     result4[],
157                               float   dist4[]);
158
159#ifdef _USE_HAVRAN_SSE 
160  // Just for testing concept
161  virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
162                                 bool castDoubleRay,
163                                 const bool pruneInvalidRays = true);
164#endif 
165
166  virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m);
167
168  virtual void UpdateDynamicObjects(const Matrix4x4 &m);
169
170  virtual void DeleteDynamicObjects();
171 
172protected:
173
174  // The kd-tree for dynamic objects
175  CKTB *mDynKtbtree;
176
177#ifdef _USE_HAVRAN_SSE
178  // This has to be aligned by 16 Bytes boundary - if HavranDynRayCaster
179  // is aligned, then also this data entity below !!!
180  static GALIGN16 RayPacket2x2 raypack_t;
181#endif
182
183  ObjectContainer *dynobjects;
184  bool dynamicFlag;
185
186  Matrix4x4 matTr, matTr_inv;
187
188  int     result4_t[4];
189  float   dist4_t[4];
190  SimpleRay sray_t;
191 
192  Vector3 orig[16];
193  Vector3 dirs[16];
194  float   tdist[32];
195  Intersectable* objI[32];
196  Vector3 normal[32];
197
198  // This transforms the ray
199  void ApplyTransform(SimpleRay &sray) {
200    sray.mOrigin = matTr_inv * sray.mOrigin;
201    sray.mDirection = RotateOnly(matTr_inv, sray.mDirection);
202    // note that normalization to the unit size of the direction
203    // is NOT computed -- this is what we want.
204  }
205};
206
207 
[2582]208} // namespace
209
[2629]210#endif // _HavranRayCaster_H__
Note: See TracBrowser for help on using the repository browser.