GPU-Accelerated Coverage  0.1.0
Compute coverage tours for known environment with articulated objects on GPU
Node.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_NODE_H_
32 #define INCLUDE_ARTICULATION_NODE_H_
33 
34 #include <gpu_coverage/Programs.h>
35 #include <assimp/scene.h>
36 #include <glm/detail/type_mat4x4.hpp>
37 #include <vector>
38 #include <iostream>
39 
40 namespace gpu_coverage {
41 
42 // Forward declarations
43 struct LocationsCommonRender;
44 class Mesh;
45 class AbstractCamera;
46 class Light;
47 class Channel;
48 
52 class Node {
53 public:
54  typedef std::vector<Node *> Children;
55  typedef std::vector<Mesh *> Meshes;
56  typedef std::vector<AbstractCamera *> Cameras;
57  typedef std::vector<Light *> Lights;
58  typedef std::vector<Channel *> Channels;
59 
67  Node(const aiNode * const node, const aiScene * scene, const std::vector<Mesh*>& meshes, Node * const parent =
68  NULL);
74  Node(const std::string& name, Node * const parent);
78  virtual ~Node();
79 
87  void setFrame();
88 
96  void render(const std::vector<glm::mat4>& view, const LocationsMVP * const locationsMVP,
97  const LocationsMaterial * const locationsMaterial, const bool hasTesselationShader) const;
98 
103  void toDot(FILE *dot);
104 
109  inline const Children& getChildren() const {
110  return children;
111  }
112 
117  inline const Meshes& getMeshes() const {
118  return meshes;
119  }
120 
125  inline size_t getId() const {
126  return id;
127  }
128 
135  inline const std::string& getName() const {
136  return name;
137  }
138 
143  inline const Node * getParent() const {
144  return parent;
145  }
146 
151  inline const glm::mat4& getLocalTransform() const {
152  return localTransform;
153  }
154 
159  inline const glm::mat4& getWorldTransform() const {
160  return worldTransform;
161  }
162 
170  inline void setLocalTransform(const glm::mat4& localTransform) {
171  this->localTransform = localTransform;
173  }
174 
179  void addCamera(AbstractCamera * const camera);
180 
185  void addLight(Light * const light);
186 
191  void addAnimationChannel(Channel * const channel);
192 
197  inline bool isVisible() const {
198  return visible;
199  }
200 
207  inline void setVisible(bool visible) {
208  this->visible = visible;
209  }
210 
215  inline const Cameras& getCameras() const {
216  return cameras;
217  }
218 
223  inline const Lights& getLights() const {
224  return lights;
225  }
226 
231  inline const Channels& getChannels() const {
232  return channels;
233  }
234 
235 protected:
236  const size_t id;
237  const std::string name;
238 
239  Children children;
240  std::vector<bool> allocatedChild;
241  Meshes meshes;
242  Cameras cameras;
243  Lights lights;
244  Channels channels;
245  Node * const parent;
246  glm::mat4 worldTransform;
247  glm::mat4 localTransform;
248  bool visible;
249 
258  void setFrameRecursive(bool needsUpdate);
259 
265  void updateWorldTransform();
266 
267  friend class Scene;
268 };
269 
270 } /* namespace gpu_coverage */
271 
272 #endif /* INCLUDE_ARTICULATION_NODE_H_ */
void toDot(FILE *dot)
Write Graphviz Dot node representing this node to file for debugging.
const Meshes & getMeshes() const
Returns a vector of all meshes associated with this node.
Definition: Node.h:117
Children children
Direct children of this node.
Definition: Node.h:239
void addCamera(AbstractCamera *const camera)
Adds a camera to this node.
Node *const parent
Parent node.
Definition: Node.h:245
const std::string & getName() const
Returns the name of this node for logging.
Definition: Node.h:135
const Lights & getLights() const
Returns the light sources associated with this node.
Definition: Node.h:223
void setVisible(bool visible)
Sets the visibility of this node.
Definition: Node.h:207
Represents a light source, corresponds to Assimp&#39;s aiLight structure.
Definition: Light.h:45
Channels channels
Animation channels influencing this node.
Definition: Node.h:244
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
Locations of material shader variables.
Definition: Programs.h:142
Locations of model, view, and projection shader variables.
Definition: Programs.h:104
bool visible
True if node is visible while rendering, see setVisible() and isVisible().
Definition: Node.h:248
void addLight(Light *const light)
Adds a light source to this node.
size_t getId() const
Returns the unique ID of this node.
Definition: Node.h:125
void addAnimationChannel(Channel *const channel)
Adds an animation channel to this node.
const Channels & getChannels() const
Returns the animation channels influencing this node.
Definition: Node.h:231
Cameras cameras
Cameras associated with this node.
Definition: Node.h:242
void updateWorldTransform()
Recomputes the world transform after the local transform has changed.
const Node * getParent() const
Returns the parent node.
Definition: Node.h:143
const glm::mat4 & getLocalTransform() const
Returns the local transform of the node relative to the parent node.
Definition: Node.h:151
const std::string name
Name of this node for logging, see getName().
Definition: Node.h:237
bool isVisible() const
Returns true if the node is visible.
Definition: Node.h:197
Definition: AbstractCamera.h:41
glm::mat4 localTransform
Current world transform, see getLocalTransform().
Definition: Node.h:247
std::vector< bool > allocatedChild
Bit map indicating which children this node has allocated and is in charge of deleting later...
Definition: Node.h:240
Lights lights
Light sources associated with this node.
Definition: Node.h:243
const glm::mat4 & getWorldTransform() const
Returns the transform of the node in world coordinates.
Definition: Node.h:159
Abstract superclass for all cameras.
Definition: AbstractCamera.h:48
virtual ~Node()
Destructor.
const size_t id
Unique ID, see getId().
Definition: Node.h:236
Meshes meshes
Meshes associated with this node.
Definition: Node.h:241
void setLocalTransform(const glm::mat4 &localTransform)
Sets the local transform of the node relative to the parent node.
Definition: Node.h:170
void setFrame()
Set the current frame of the animation.
Node(const aiNode *const node, const aiScene *scene, const std::vector< Mesh * > &meshes, Node *const parent=NULL)
Constructor for creating a node from an Assimp aiNode.
const Children & getChildren() const
Returns a vector of all direct children.
Definition: Node.h:109
glm::mat4 worldTransform
Current world transform, see getWorldTransform().
Definition: Node.h:246
Animation channel.
Definition: Channel.h:53
void render(const std::vector< glm::mat4 > &view, const LocationsMVP *const locationsMVP, const LocationsMaterial *const locationsMaterial, const bool hasTesselationShader) const
Renders the scene using the current shaders.
void setFrameRecursive(bool needsUpdate)
Updates the current frame number recursively in all child frames.
const Cameras & getCameras() const
Returns the cameras associated with this node.
Definition: Node.h:215