Carna  Version 3.3.2
Spatial.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 SPATIAL_H_6014714286
13 #define SPATIAL_H_6014714286
14 
15 #include <Carna/Carna.h>
16 #include <Carna/base/math.h>
17 #include <Carna/base/noncopyable.h>
18 #include <functional>
19 
24 namespace Carna
25 {
26 
27 namespace base
28 {
29 
30 
31 
32 // ----------------------------------------------------------------------------------
33 // Spatial
34 // ----------------------------------------------------------------------------------
35 
44 class CARNA_LIB Spatial
45 {
46 
48 
49  Node* myParent;
50  math::Matrix4f myWorldTransform;
51  const void* myUserData;
52  bool movable;
53  std::string myTag;
54 
55 public:
56 
57  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
58 
64  explicit Spatial( const std::string& tag = "" );
65 
69  virtual ~Spatial();
70 
74  typedef std::function< void( Spatial& ) > MutableVisitor;
75 
79  typedef std::function< void( const Spatial& ) > ImmutableVisitor;
80 
84  bool hasParent() const;
85 
98  Spatial* detachFromParent();
99 
104  void updateParent( Node& parent );
105 
110  Node& parent();
111 
114  const Node& parent() const;
115 
119  Node& findRoot();
120 
124  const Node& findRoot() const;
125 
133 
140  virtual void updateWorldTransform();
141 
146  const math::Matrix4f& worldTransform() const;
147 
154  template< typename UserDataType >
155  void setUserData( const UserDataType& userData );
156 
166  void removeUserData();
167 
172  bool hasUserData() const;
173 
181  template< typename UserDataType >
182  const UserDataType& userData() const;
183 
191  void setMovable( bool movable );
192 
200  bool isMovable() const;
201 
207  virtual void invalidate();
208 
212  void setTag( const std::string& tag );
213 
217  const std::string& tag() const;
218 
219 }; // Spatial
220 
221 
222 template< typename UserDataType >
223 void Spatial::setUserData( const UserDataType& userData )
224 {
225  myUserData = &userData;
226  CARNA_ASSERT( hasUserData() );
227 }
228 
229 
230 template< typename UserDataType >
231 const UserDataType& Spatial::userData() const
232 {
233  CARNA_ASSERT( hasUserData() );
234  return *static_cast< const UserDataType* >( myUserData );
235 }
236 
237 
238 
239 } // namespace Carna :: base
240 
241 } // namespace Carna
242 
243 #endif // SPATIAL_H_6014714286
Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
std::function< void(Spatial &) > MutableVisitor
Declares an entity that visits mutable Spatial instances.
Definition: Spatial.h:74
std::function< void(const Spatial &) > ImmutableVisitor
Declares an entity that visits mutable Spatial instances.
Definition: Spatial.h:79
Defines the inner node of a scene graph. Implements a spatial scene element that is allowed to have c...
Definition: Node.h:44
Represents a spatial scene element. It&#39;s location is determined relatively to another spatial that is...
Definition: Spatial.h:44
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > Matrix4f
Defines matrix.
Definition: math.h:193
void setUserData(const UserDataType &userData)
Links an arbitrary object with this Spatial instance.
Definition: Spatial.h:223
const UserDataType & userData() const
Retrieves the object previously linked with this Spatial instance.
Definition: Spatial.h:231
#define CARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
#define NON_COPYABLE
Features class it is placed in as non-copyable.
Definition: noncopyable.h:109
math::Matrix4f localTransform
Defines the location, rotation and scale of this spatial in relation to it&#39;s parent. If this spatial has no parent, the value has no meaning.
Definition: Spatial.h:132