Box.h 19.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 *	(c) LSIIT, UMR CNRS/UdS
 *	Authors: O. Génevaux, F. Larue.
 *
 *	See licence.txt for additional information.
 */


#ifndef __BOX_H__
#define __BOX_H__


#include <QVector2D>
#include <QVector3D>
15
#include <limits>
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57




/*
 *
 *	CLASSES DECLARATIONS.
 *
 */

/**	Axis-aligned bounding box in 2D.
 *	\ingroup Acquisition
 */
class Box2f
{
	/******************\
	| Internal type(s) |
	\******************/
public:
	/** Set of 2D coordinates representing the corners of a bounding box.
	 *
	 *	Provided by the BoundingBox::GetCorners function.
	 */
	class CornerSet
	{
	public:
        typedef QVector2D       *iterator;
        typedef const QVector2D *const_iterator;

		QVector2D xy;	    /**< Corner on ( X_min, Y_min ). */
		QVector2D Xy;	    /**< Corner on ( X_max, Y_min ). */
		QVector2D xY; 	/**< Corner on ( X_min, Y_max ). */
		QVector2D XY;	    /**< Corner on ( X_max, Y_max ). */

		/** Indexed access to the box corners. */
		inline QVector2D&	    operator[]( const unsigned int i )		    { return (&xy)[i]; }
		/** Indexed access to the box corners (read-only version). */
		inline const QVector2D& operator[]( const unsigned int i ) const	{ return (&xy)[i]; }

        inline iterator         begin()                                     { return &xy; }
        inline const_iterator   begin() const                               { return &xy; }
        inline iterator         end()                                       { return (&XY)+1; }
58
        inline const_iterator   end() const                                 { return (&XY)+1; }
59
60
61
62
63
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
	};


	/********************\
	| Member variable(s) |
	\********************/
private:
#ifdef _WIN32
#pragma warning(disable: 4251)
#endif
	QVector2D	m_Min, m_Max;


	/*****************************\
	| Constructor(s) / destructor |
	\*****************************/
public:
	inline	Box2f()			    { SetNull(); }
	inline	~Box2f()			{ }


	/********************\
	| Member function(s) |
	\********************/
public:
	/**	Initialization to an "unbounding box". */
	inline	void			    SetNull();

	/**	Check if the bounding box has been initialized. */
    inline	bool                IsNull() const      { return m_Min.x() > m_Max.x(); }

	/**	Box boundaries extension so as to bound the specified 3D point.
	 *
	 *	\param[in]	v	Coordinates of the 2D point to bound.
	 */
	inline	void			    Add( const QVector2D& v );
	/**	Box boundaries extension so as to bound the specified 3D point.
	 *
	 *	\param[in]	v	Pointer to the coordinates of the 2D point to bound.
	 */
	inline	void			    Add( const QVector2D* v );
	/**	Box boundaries extension so as to bound the specified box.
	 *
	 *	\param[in]	b	Bounding box to bound.
	 */
	inline	void			    Add( const Box2f& b );
	/**	Box boundaries extension so as to bound the specified box.
	 *
	 *	\param[in]	b	Pointer to the bounding box to bound.
	 */
	inline	void			    Add( const Box2f* b );

	/**	Check if a point is included in the box.
	 *
	 *	\param[in]	v	Coordinates of the 2D point to check.
	 *	\return			True if the point is included in the box, false otherwise.
	 */
	inline	bool			    Contains( const QVector2D& v ) const;
	/**	Check if a box is included in the box.
	 *
	 *	\param[in]	b	Bounding box to check.
	 *	\return			True if the query box is included in the current one, false otherwise.
	 */
	inline	bool			    Contains( const Box2f& b ) const;
	/**	Check if a box intersects the box.
	 *
	 *	\param[in]	b	Bounding box to check.
	 *	\return			True if the query box intersects the current one, false otherwise.
	 */
	inline	bool			    Intersects( const Box2f& b ) const;

	/** Access to the lower boundaries of the box.
	 *
	 *	\return		Box lower boundaries.
	 */
	inline	QVector2D&	        Min()				    { return m_Min; }
	/** Access to the lower boundaries of the box (read only version).
	 *
	 *	\return		Box lower boundaries.
	 */
	inline	const QVector2D&    Min() const			{ return m_Min; }
	/** Access to the upper boundaries of the box.
	 *
	 *	\return		Box upper boundaries.
	 */
	inline	QVector2D&	        Max()				{ return m_Max; }
	/** Access to the upper boundaries of the box (read only version).
	 *
	 *	\return		Box upper boundaries.
	 */
	inline	const QVector2D&	Max() const			{ return m_Max; }
	/** Recovery of the dimensions of the box.
	 *
	 *	\return		Box dimensions.
	 */
	inline	QVector2D		    Dimensions() const	    { return m_Max - m_Min; }
	/** Recovery of diagonal length of the box.
	 *
	 *	\return		Diagonal length.
	 */
    inline  float               Diagonal() const        { return Dimensions().length(); }
	/** Recovery of the center point of the box.
	 *
	 *	\return		Box center.
	 */
	inline	QVector2D		    Center() const		    { return 0.5f*( m_Min + m_Max ); }
	/** Recovery of the height points representing the corners of the box.
	 *
	 *	\return		Set of corner points.
	 */
169
	inline CornerSet     		Corners() const;
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

	/**	Explicit specification of the box boundaries.
	 *
	 *	\param[in]	min	Lower boundary.
	 *	\param[in]	max	Upper boundary.
	 */
	inline	void			    SetBoundaries( const QVector2D& min, const QVector2D& max );
	/**	Explicit specification of the box boundaries.
	 *
	 *	\param[in]	xMin	Lower boundary along axis X.
	 *	\param[in]	xMax	Upper boundary along axis X.
	 *	\param[in]	yMin	Lower boundary along axis Y.
	 *	\param[in]	yMax	Upper boundary along axis Y.
	 */
	inline	void			    SetBoundaries( const float xMin, const float xMax,
										       const float yMin, const float yMax );
    /** Recovery of the area of the box.
     *
     *  \return     Box area.
     */
    inline float                Area() const;
};


/*
 *
 *	INLINE MEMBER FUNCTIONS DEFINITIONS.
 *
 */


inline void Box2f::SetNull()
{
    m_Min.setX(  std::numeric_limits<float>::max() );
    m_Min.setY(  std::numeric_limits<float>::max() );

    m_Max.setX( -std::numeric_limits<float>::max() );
    m_Max.setY( -std::numeric_limits<float>::max() );
}


inline void Box2f::Add( const QVector2D& v )
{
	if( v.x() < m_Min.x() )
		m_Min.setX( v.x() );
	if( v.x() > m_Max.x() )
		m_Max.setX( v.x() );

	if( v.y() < m_Min.y() )
		m_Min.setY( v.y() );
	if( v.y() > m_Max.y() )
		m_Max.setY( v.y() );
}


inline void Box2f::Add( const QVector2D* v )
{
	Add( *v );
}


inline void Box2f::Add( const Box2f& b )
{
	if( b.m_Min.x() < m_Min.x() )
		m_Min.setX( b.m_Min.x() );
	if( b.m_Max.x() > m_Max.x() )
		m_Max.setX( b.m_Max.x() );

	if( b.m_Min.y() < m_Min.y() )
		m_Min.setY( b.m_Min.y() );
	if( b.m_Max.y() > m_Max.y() )
		m_Max.setY( b.m_Max.y() );
}


inline void Box2f::Add( const Box2f* b )
{
	Add( *b );
}


inline bool Box2f::Contains( const QVector2D& v ) const
{
	return v.x() >= m_Min.x()  &&  v.x() <= m_Max.x()  &&
		   v.y() >= m_Min.y()  &&  v.y() <= m_Max.y();
}


inline bool Box2f::Contains( const Box2f& b ) const
{
	return b.m_Min.x() >= m_Min.x()  &&  b.m_Max.x() <= m_Max.x()  &&
		   b.m_Min.y() >= m_Min.y()  &&  b.m_Max.y() <= m_Max.y();
}


inline bool Box2f::Intersects( const Box2f& b ) const
{
	return b.m_Min.x() < m_Max.x()  &&  b.m_Max.x() > m_Min.x()  &&
		   b.m_Min.y() < m_Max.y()  &&  b.m_Max.y() > m_Min.y();
}


inline void Box2f::SetBoundaries( const QVector2D& min, const QVector2D& max )
{
	m_Min = min;
	m_Max = max;
}


inline void Box2f::SetBoundaries( const float xMin, const float xMax,
                                  const float yMin, const float yMax )
{
	m_Min = QVector2D( xMin, yMin );
	m_Max = QVector2D( xMax, yMax );
}


287
inline Box2f::CornerSet Box2f::Corners() const
288
{
289
    CornerSet corners;
290
291
292
293
	corners.xy = m_Min;
	corners.Xy = QVector2D( m_Max.x(), m_Min.y() );
	corners.xY = QVector2D( m_Min.x(), m_Max.y() );
	corners.XY = m_Max;
294
    return corners;
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
}


inline float Box2f::Area() const
{
    return IsNull()?  0.0f  :  (m_Max.x()-m_Min.x()) * (m_Max.y()-m_Min.y());
}















/*
 *
 *	CLASSES DECLARATIONS.
 *
 */

/**	Axis-aligned bounding box in 3D.
 *	\ingroup Acquisition
 */
class Box3f
{
	/******************\
	| Internal type(s) |
	\******************/
public:
	/** Set of 3D coordinates representing the corners of a bounding box.
	 *
	 *	Provided by the BoundingBox::GetCorners function.
	 */
	class CornerSet
	{
	public:
        typedef QVector3D       *iterator;
        typedef const QVector3D *const_iterator;

		QVector3D xyz;	/**< Corner on ( X_min, Y_min, Z_min ). */
		QVector3D xyZ;	/**< Corner on ( X_min, Y_min, Z_max ). */
		QVector3D xYz;	/**< Corner on ( X_min, Y_max, Z_min ). */
		QVector3D xYZ;	/**< Corner on ( X_min, Y_max, Z_max ). */
		QVector3D Xyz;	/**< Corner on ( X_max, Y_min, Z_min ). */
		QVector3D XyZ;	/**< Corner on ( X_max, Y_min, Z_max ). */
		QVector3D XYz;	/**< Corner on ( X_max, Y_max, Z_min ). */
		QVector3D XYZ;	/**< Corner on ( X_max, Y_max, Z_max ). */

		/** Indexed access to the box corners. */
		inline	QVector3D&		    operator[]( const unsigned int i )			{ return (&xyz)[i]; }
		/** Indexed access to the box corners (read-only version). */
		inline	const QVector3D&    operator[]( const unsigned int i ) const	{ return (&xyz)[i]; }

        inline iterator             begin()                                     { return &xyz; }
        inline const_iterator       begin() const                               { return &xyz; }
        inline iterator             end()                                       { return (&XYZ)+1; }
        inline const_iterator       end() const                                 { return (&XYZ)+1; }
	};


	/********************\
	| Member variable(s) |
	\********************/
private:
#ifdef _WIN32
#pragma warning(disable: 4251)
#endif
	QVector3D	m_Min, m_Max;


	/*****************************\
	| Constructor(s) / destructor |
	\*****************************/
public:
	inline	Box3f()			{ SetNull(); }
	inline	~Box3f()			{ }


	/********************\
	| Member function(s) |
	\********************/
public:
	/**	Initialization to an "unbounding box". */
	inline	void			    SetNull();

	/**	Check if the bounding box has been initialized. */
    inline	bool                IsNull() const      { return m_Min.x() > m_Max.x(); }

	/**	Box boundaries extension so as to bound the specified 3D point.
	 *
	 *	\param[in]	v	Coordinates of the 3D point to bound.
	 */
	inline	void			    Add( const QVector3D& v );
	/**	Box boundaries extension so as to bound the specified 3D point.
	 *
	 *	\param[in]	v	Pointer to the coordinates of the 3D point to bound.
	 */
	inline	void			    Add( const QVector3D* v );
401
402
403
404
405
	/**	Box boundaries extension so as to bound the specified 3D point.
	 *
	 *	\param[in]	v	Pointer to the coordinates of the 3D point to bound.
	 */
	inline	void			    Add( const float* v );
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
	/**	Box boundaries extension so as to bound the specified box.
	 *
	 *	\param[in]	b	Bounding box to bound.
	 */
	inline	void			    Add( const Box3f& b );
	/**	Box boundaries extension so as to bound the specified box.
	 *
	 *	\param[in]	b	Pointer to the bounding box to bound.
	 */
	inline	void			    Add( const Box3f* b );

	/**	Check if a point is included in the box.
	 *
	 *	\param[in]	v	Coordinates of the 3D point to check.
	 *	\return			True if the point is included in the box, false otherwise.
	 */
	inline	bool			    Contains( const QVector3D& v ) const;
	/**	Check if a box is included in the box.
	 *
	 *	\param[in]	b	Bounding box to check.
	 *	\return			True if the query box is included in the current one, false otherwise.
	 */
	inline	bool			    Contains( const Box3f& b ) const;
	/**	Check if a box intersects the box.
	 *
	 *	\param[in]	b	Bounding box to check.
	 *	\return			True if the query box intersects the current one, false otherwise.
	 */
	inline	bool			    Intersects( const Box3f& b ) const;

	/** Access to the lower boundaries of the box.
	 *
	 *	\return		Box lower boundaries.
	 */
	inline	QVector3D&	        Min()				    { return m_Min; }
	/** Access to the lower boundaries of the box (read only version).
	 *
	 *	\return		Box lower boundaries.
	 */
	inline	const QVector3D&	Min() const			    { return m_Min; }
	/** Access to the upper boundaries of the box.
	 *
	 *	\return		Box upper boundaries.
	 */
	inline	QVector3D&		    Max()				    { return m_Max; }
	/** Access to the upper boundaries of the box (read only version).
	 *
	 *	\return		Box upper boundaries.
	 */
	inline	const QVector3D&    Max() const			    { return m_Max; }
	/** Recovery of the dimensions of the box.
	 *
	 *	\return		Box dimensions.
	 */
	inline	QVector3D		    Dimensions() const	    { return m_Max - m_Min; }
	/** Recovery of diagonal length of the box.
	 *
	 *	\return		Diagonal length.
	 */
    inline  float               Diagonal() const        { return Dimensions().length(); }
	/** Recovery of the center point of the box.
	 *
	 *	\return		Box center.
	 */
	inline	QVector3D		    Center() const		    { return 0.5f*( m_Min + m_Max ); }
	/** Recovery of the height points representing the corners of the box.
	 *
	 *	\return		Set of corner points.
	 */
475
	inline CornerSet	    	Corners() const;
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499

	/**	Explicit specification of the box boundaries.
	 *
	 *	\param[in]	min	Lower boundary.
	 *	\param[in]	max	Upper boundary.
	 */
	inline	void			    SetBoundaries( const QVector3D& min, const QVector3D& max );
	/**	Explicit specification of the box boundaries.
	 *
	 *	\param[in]	xMin	Lower boundary along axis X.
	 *	\param[in]	xMax	Upper boundary along axis X.
	 *	\param[in]	yMin	Lower boundary along axis Y.
	 *	\param[in]	yMax	Upper boundary along axis Y.
	 *	\param[in]	zMin	Lower boundary along axis Z.
	 *	\param[in]	zMax	Upper boundary along axis Z.
	 */
	inline	void			    SetBoundaries( const float xMin, const float xMax,
							    			   const float yMin, const float yMax,
							    			   const float zMin, const float zMax );
    /** Recovery of the volume of the box.
     *
     *  \return     Box volume.
     */
    inline float                Volume() const;
500
501
502
503
504
505
506
507
508
509
510

    /** Performs an intersection between a ray and the box.
     *
     *  \param[in]
     */
    inline bool                 Intersects( const QVector3D& rayOrigin,
                                            const QVector3D& rayDirection,
                                            QVector3D& intersectionCoords,
                                            float& intersectionDist );
    inline bool                 Intersects( const QVector3D& rayOrigin,
                                            const QVector3D& rayDirection );
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
};


/*
 *
 *	INLINE MEMBER FUNCTIONS DEFINITIONS.
 *
 */


inline void Box3f::SetNull()
{
    m_Min.setX(  std::numeric_limits<float>::max() );
    m_Min.setY(  std::numeric_limits<float>::max() );
    m_Min.setZ(  std::numeric_limits<float>::max() );

    m_Max.setX( -std::numeric_limits<float>::max() );
    m_Max.setY( -std::numeric_limits<float>::max() );
    m_Max.setZ( -std::numeric_limits<float>::max() );
}


inline void Box3f::Add( const QVector3D& v )
{
	if( v.x() < m_Min.x() )
		m_Min.setX( v.x() );
	if( v.x() > m_Max.x() )
		m_Max.setX( v.x() );

	if( v.y() < m_Min.y() )
		m_Min.setY( v.y() );
	if( v.y() > m_Max.y() )
		m_Max.setY( v.y() );
	
	if( v.z() < m_Min.z() )
		m_Min.setZ( v.z() );
	if( v.z() > m_Max.z() )
		m_Max.setZ( v.z() );
}


inline void Box3f::Add( const QVector3D* v )
{
	Add( *v );
}


558
559
560
561
562
563
inline void	Box3f::Add( const float* v )
{
    Add( QVector3D(v[0], v[1], v[2]) );
}


564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
inline void Box3f::Add( const Box3f& b )
{
	if( b.m_Min.x() < m_Min.x() )
		m_Min.setX( b.m_Min.x() );
	if( b.m_Max.x() > m_Max.x() )
		m_Max.setX( b.m_Max.x() );

	if( b.m_Min.y() < m_Min.y() )
		m_Min.setY( b.m_Min.y() );
	if( b.m_Max.y() > m_Max.y() )
		m_Max.setY( b.m_Max.y() );

	if( b.m_Min.z() < m_Min.z() )
		m_Min.setZ( b.m_Min.z() );
	if( b.m_Max.z() > m_Max.z() )
		m_Max.setZ( b.m_Max.z() );
}


inline void Box3f::Add( const Box3f* b )
{
	Add( *b );
}


inline bool Box3f::Contains( const QVector3D& v ) const
{
	return v.x() >= m_Min.x()  &&  v.x() <= m_Max.x()  &&
		   v.y() >= m_Min.y()  &&  v.y() <= m_Max.y()  &&
		   v.z() >= m_Min.z()  &&  v.z() <= m_Max.z();
}


inline bool Box3f::Contains( const Box3f& b ) const
{
	return b.m_Min.x() >= m_Min.x()  &&  b.m_Max.x() <= m_Max.x()  &&
		   b.m_Min.y() >= m_Min.y()  &&  b.m_Max.y() <= m_Max.y()  &&
		   b.m_Min.z() >= m_Min.z()  &&  b.m_Max.z() <= m_Max.z();
}


inline bool Box3f::Intersects( const Box3f& b ) const
{
	return b.m_Min.x() < m_Max.x()  &&  b.m_Max.x() > m_Min.x()  &&
		   b.m_Min.y() < m_Max.y()  &&  b.m_Max.y() > m_Min.y()  &&
		   b.m_Min.z() < m_Max.z()  &&  b.m_Max.z() > m_Min.z();
}


inline void Box3f::SetBoundaries( const QVector3D& min, const QVector3D& max )
{
	m_Min = min;
	m_Max = max;
}


inline void Box3f::SetBoundaries( const float xMin, const float xMax,
                                  const float yMin, const float yMax,
                                  const float zMin, const float zMax )
{
	m_Min = QVector3D( xMin, yMin, zMin );
	m_Max = QVector3D( xMax, yMax, zMax );
}


629
inline Box3f::CornerSet Box3f::Corners() const
630
{
631
    CornerSet corners;
632
633
634
635
636
637
638
639
	corners.xyz = m_Min;
	corners.xyZ = QVector3D( m_Min.x(), m_Min.y(), m_Max.z() );
	corners.xYz = QVector3D( m_Min.x(), m_Max.y(), m_Min.z() );
	corners.xYZ = QVector3D( m_Min.x(), m_Max.y(), m_Max.z() );
	corners.Xyz = QVector3D( m_Max.x(), m_Min.y(), m_Min.z() );
	corners.XyZ = QVector3D( m_Max.x(), m_Min.y(), m_Max.z() );
	corners.XYz = QVector3D( m_Max.x(), m_Max.y(), m_Min.z() );
	corners.XYZ = m_Max;
640
    return corners;
641
642
643
644
645
646
647
648
649
}


inline float Box3f::Volume() const
{
    return IsNull()?  0.0f  :  (m_Max.x()-m_Min.x()) * (m_Max.y()-m_Min.y()) * (m_Max.z()-m_Min.z());
}


650
651
652
653
654
655
656
657
658
659
inline bool Box3f::Intersects( const QVector3D& rayOrigin,
                               const QVector3D& rayDirection,
                               QVector3D& intersectionCoords,
                               float& intersectionDist )
{
    // For each of the three dimensions, only the plane that faces the ray is checked. This leads to three possible intersection
    // points, but only the farthest positive one may correspond to the real ray/cube intersection, if it exists.

    int intersectionPlaneId = -1;

660
    if( Contains(rayOrigin) )
661
    {
662
663
664
        intersectionDist = std::numeric_limits<float>::max();

        for( int i=0; i<3; ++i )
665
            if( rayDirection[i] != 0.0f )
666
            {
667
668
669
670
671
672
673
                float frontFacingPlane = (rayDirection[i] > 0.0f)?  m_Max[i]  :  m_Min[i];
                float t = (frontFacingPlane - rayOrigin[i]) / rayDirection[i];
                if( t < intersectionDist )
                {
                    intersectionDist = t;
                    intersectionPlaneId = i;
                }
674
675
676
677
678
679
680
            }
    }
    else
    {
        intersectionDist = 0.0f;

        for( int i=0; i<3; ++i )
681
            if( rayDirection[i] != 0.0f )
682
            {
683
684
685
686
687
688
689
                float frontFacingPlane = (rayDirection[i] > 0.0f)?  m_Min[i]  :  m_Max[i];
                float t = (frontFacingPlane - rayOrigin[i]) / rayDirection[i];
                if( t > intersectionDist )
                {
                    intersectionDist = t;
                    intersectionPlaneId = i;
                }
690
            }
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
    }

    if( intersectionPlaneId < 0 )
        return false;

    // Computes the coordinates of this ray/plane intersection, as well as its distance to the observer.

    intersectionCoords = rayOrigin + intersectionDist * rayDirection;

    // If the intersection point on the plane is inside the bounds of the cube face, the ray effectively intersects the cube.

    int planeX = (intersectionPlaneId + 1) % 3;
    int planeY = (intersectionPlaneId + 2) % 3;

    bool isIntersecting = intersectionCoords[planeX] >= m_Min[planeX]  &&
                          intersectionCoords[planeX] <= m_Max[planeX]  &&
                          intersectionCoords[planeY] >= m_Min[planeY]  &&
                          intersectionCoords[planeY] <= m_Max[planeY];

    return isIntersecting;
}


inline bool Box3f::Intersects( const QVector3D& rayOrigin,
                               const QVector3D& rayDirection )
{
    QVector3D intersectionCoords;
    float intersectionDist;
    return Intersects( rayOrigin, rayDirection, intersectionCoords, intersectionDist );
}


723
724
725


#endif /*__BOX_H__*/