Carna  Version 3.0.1
RaySphereHitTest.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 - 2015 Leonid Kostrykin
3  *
4  * Chair of Medical Engineering (mediTEC)
5  * RWTH Aachen University
6  * Pauwelsstr. 20
7  * 52074 Aachen
8  * Germany
9  *
10  */
11 
12 #ifndef RAYSPHEREHITTEST_H_6014714286
13 #define RAYSPHEREHITTEST_H_6014714286
14 
15 #include <Carna/Carna.h>
16 #include <Carna/base/math.h>
17 #include <Carna/base/math/Ray.h>
19 
24 namespace Carna
25 {
26 
27 namespace base
28 {
29 
30 namespace math
31 {
32 
33 
34 
35 // ----------------------------------------------------------------------------------
36 // RaySphereHitTest
37 // ----------------------------------------------------------------------------------
38 
48 template< typename VectorType, typename ScalarType >
50 {
51 
52  bool myHitExists;
53  VectorType myHitLocation;
54 
55 public:
56 
63 
69  void compute( const Ray< VectorType >& ray, const ScalarType radius );
70 
74  bool hitExists() const;
75 
81  const VectorType& hitLocation() const;
82 
83 }; // RaySphereHitTest
84 
85 
86 template< typename VectorType, typename ScalarType >
88  : myHitExists( false )
89 {
90 }
91 
92 
93 template< typename VectorType, typename ScalarType >
95 {
96  return myHitExists;
97 }
98 
99 
100 template< typename VectorType, typename ScalarType >
102 {
103  CARNA_ASSERT( hitExists() );
104  return myHitLocation;
105 }
106 
107 
108 template< typename VectorType, typename ScalarType >
110 {
111  CARNA_ASSERT( isEqual< ScalarType >( ray.direction.norm(), 1 ) );
112  CARNA_ASSERT( isEqual< ScalarType >( planeNormal.norm(), 1 ) );
113  CARNA_ASSERT( ray.direction.rows() == ray.origin.rows() && ray.origin.rows() == planeNormal.rows() );
114  CARNA_ASSERT( ray.direction.cols() == ray.origin.cols() && ray.origin.cols() == planeNormal.cols() && planeNormal.cols() == 1 );
115 
116  ;
117 }
118 
119 
120 
121 } // namespace Carna :: base :: math
122 
123 } // namespace Carna :: base
124 
125 } // namespace Carna
126 
127 #endif // RAYSPHEREHITTEST_H_6014714286
Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
void compute(const Ray< VectorType > &ray, const ScalarType radius)
Performs a hit test of ray with a sphere of radius radius. The sphere is assumed to be centered in th...
bool hitExists() const
Tells whether a hit exists.
const VectorType & hitLocation() const
References the location of the hit.
VectorType origin
Holds the origin of this ray.
Definition: Ray.h:62
Tests whether sphere in origin is hit by a Ray object.
Defines ray in where is the Scalar type derived from VectorType and is dimension of VectorType...
Definition: Ray.h:47
VectorType direction
Holds the direction of this ray.
Definition: Ray.h:67
Defines Carna::base::CarnaException, Carna::base::AssertionFailure.
Defines Carna::base::math::Ray.
#define CARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...