GPU-Accelerated Coverage  0.1.0
Compute coverage tours for known environment with articulated objects on GPU
Channel.h
1 /*
2  * Copyright (c) 2018, Stefan Osswald
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef INCLUDE_ARTICULATION_CHANNEL_H_
32 #define INCLUDE_ARTICULATION_CHANNEL_H_
33 
34 #include <assimp/scene.h>
35 #include <glm/detail/type_vec3.hpp>
36 #include <glm/detail/type_mat4x4.hpp>
37 #include <map>
38 #if HAS_GTEST
39 #include <gtest/gtest_prod.h>
40 #endif
41 
42 namespace gpu_coverage {
43 
44 // Forward declarations
45 class Scene;
46 class Node;
47 
53 class Channel {
54 public:
61  Channel(Scene * const scene, const aiNodeAnim * const channel, const size_t id);
65  virtual ~Channel();
66 
74  void setFrame(const size_t frame);
75 
82  inline Node * getNode() const {
83  return node;
84  }
85 
90  inline const size_t& getStartFrame() const {
91  return startFrame;
92  }
93 
98  inline const size_t& getEndFrame() const {
99  return endFrame;
100  }
101 
106  inline const size_t& getNumFrames() const {
107  return numFrames;
108  }
109 
117  inline const glm::mat4& getLocalTransform() const {
118  return localTransform;
119  }
120 
121 protected:
122  const size_t id;
123  Node * const node;
124 
125  typedef std::map<size_t, glm::vec3> Locations;
126  typedef std::map<size_t, glm::quat> Rotations;
127  typedef std::map<size_t, glm::vec3> Scales;
128 
129  Locations locations;
130  Rotations rotations;
131  Scales scales;
132 
133  glm::mat4 localTransform;
134 
140  size_t timeToFrame(const double& time) const;
141 
142  size_t startFrame;
143  size_t endFrame;
144  size_t numFrames;
145 
153  template<class M>
154  static std::pair<typename M::const_iterator, typename M::const_iterator> findInterval(const M& map,
155  const typename M::key_type& key) {
156  typename M::const_iterator a = map.begin();
157  typename M::const_iterator b = map.begin();
158  for (typename M::const_iterator it = map.begin(); it != map.end(); ++it) {
159  if (it->first <= key)
160  a = it;
161  if (it->first <= key || a->first != key)
162  b = it;
163  if (it->first > key)
164  break;
165  }
166  return std::make_pair(a, b);
167  }
168 
169 #if HAS_GTEST
170  FRIEND_TEST(Channel, findInterval);
171 #endif
172 };
173 
174 } /* namespace gpu_coverage */
175 
176 #endif /* INCLUDE_ARTICULATION_CHANNEL_H_ */
Node * getNode() const
Returns the scene graph node that this camera is attached to.
Definition: Channel.h:82
size_t numFrames
Number of frames of the animation.
Definition: Channel.h:144
size_t timeToFrame(const double &time) const
Converts time in seconds to frame number.
const size_t & getNumFrames() const
Duration of this animation channel in frames.
Definition: Channel.h:106
static std::pair< typename M::const_iterator, typename M::const_iterator > findInterval(const M &map, const typename M::key_type &key)
Definition: Channel.h:154
Scene graph corresponding to Assimp&#39;s aiScene.
Definition: Scene.h:59
Scene graph node, corresponding to Assimp&#39;s aiNode.
Definition: Node.h:52
const glm::mat4 & getLocalTransform() const
Returns the current local transform.
Definition: Channel.h:117
Locations locations
Location keyframes.
Definition: Channel.h:129
Rotations rotations
Rotation keyframes.
Definition: Channel.h:130
const size_t & getStartFrame() const
Frame number where this animation channel starts.
Definition: Channel.h:90
Channel(Scene *const scene, const aiNodeAnim *const channel, const size_t id)
Constructor.
std::map< size_t, glm::vec3 > Scales
Scale key frames, maps frame number to scale vector.
Definition: Channel.h:127
const size_t & getEndFrame() const
Frame number where this animation channel ends.
Definition: Channel.h:98
Node *const node
The scene graph node assigned to this animation channel, see getNode().
Definition: Channel.h:123
virtual ~Channel()
Destructor.
size_t startFrame
Start frame of the animation.
Definition: Channel.h:142
Definition: AbstractCamera.h:41
const size_t id
Unique ID, see getId().
Definition: Channel.h:122
void setFrame(const size_t frame)
Set the current frame of the animation.
std::map< size_t, glm::quat > Rotations
Rotation key frames, maps frame number to rotation quaternion.
Definition: Channel.h:126
Animation channel.
Definition: Channel.h:53
glm::mat4 localTransform
Local transform matrix of the animation channel.
Definition: Channel.h:133
size_t endFrame
End frame of the animation.
Definition: Channel.h:143
Scales scales
Scale keyframes.
Definition: Channel.h:131
std::map< size_t, glm::vec3 > Locations
Location key frames, maps frame number to location vector.
Definition: Channel.h:125