GPU-Accelerated Coverage  0.1.0
Compute coverage tours for known environment with articulated objects on GPU
RobotSceneConfiguration.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_ROBOTSCENECONFIGURATION_H_
32 #define INCLUDE_ARTICULATION_ROBOTSCENECONFIGURATION_H_
33 
34 #include <gpu_coverage/AbstractRenderer.h>
35 #include <gpu_coverage/Node.h>
36 #include <glm/detail/type_mat4x4.hpp>
37 #include <stdexcept>
38 #include <list>
39 
40 namespace gpu_coverage {
41 
46 public:
55  explicit RobotSceneConfiguration(const RobotSceneConfiguration& other);
59  virtual ~RobotSceneConfiguration();
60 
70  float getCost(RobotSceneConfiguration& previousConfig) const;
71 
81  float getGain(RobotSceneConfiguration& previousConfig) const;
82 
93  inline float getEvaluation(RobotSceneConfiguration& previousConfig) const {
94  return getGain(previousConfig) - getCost(previousConfig);
95  }
96 
101  void set(const RobotSceneConfiguration& other) {
104  // numArticulation is the same for all instances, hence the
105  // array does not need to be reallocated or resized.
106  memcpy(articulation, other.articulation, numArticulation * sizeof(float));
107  count = other.count;
108  }
109 
114  void setRandomArticulation(unsigned int& seed);
115 
120  void setRandomCameraHeight(unsigned int& seed);
121 
127  void setRandomCameraPosition(unsigned int& seed, const std::vector<glm::vec3> * const targetPoints);
128 
133  void setCameraHeight(const float& value);
134 
139  void setCameraLocalTransform(const glm::mat4x4& cameraTransform);
140 
145  inline const glm::mat4x4& getCameraLocalTransform() const {
146  return cameraLocalTransform;
147  }
148 
153  void applyToScene(Scene * const scene) const;
154 
161  inline float getArticulation(const size_t& handle) const {
162 #ifdef DEBUG
163  if (handle >= numArticulation) {
164  throw std::out_of_range("RobotSceneConfiguration::getArticulation index out of range");
165  }
166 #endif
167  return articulation[handle];
168  }
169 
176  inline void setArticulation(const size_t& handle, const float& value) {
177 #ifdef DEBUG
178  if (handle >= numArticulation) {
179  throw std::out_of_range("RobotSceneConfiguration::setArticulation index out of range");
180  }
181 #endif
182  articulation[handle] = value;
183  }
184 
190  inline const GLuint& getCount() const {
191  return count;
192  }
193 
199  inline void setCount(const GLuint& count) {
200  this->count = count;
201  }
202 
216  static void loadCosts();
217 
218  static size_t numArticulation;
219 
220 protected:
221  glm::mat4x4 cameraLocalTransform;
222  glm::vec3 cameraPosition;
223  float *articulation;
224  GLuint count;
225 
230  float constant;
231  float linear;
232 
237  ArticulationCost(const float& constant = 0.0f, const float& linear = 0.0f)
238  : constant(constant), linear(linear) {
239  }
240  };
241 
242  static float costCameraHeightChange;
243  static float costDistance;
244  static float minCameraHeight;
245  static float maxCameraHeight;
246  static float gainFactor;
248 
249  friend class RandomSearchTask;
250  friend class HillclimbingTask;
251 
252 };
253 
254 } /* namespace gpu_coverage */
255 
256 #endif /* INCLUDE_ARTICULATION_ROBOTSCENECONFIGURATION_H_ */
static float maxCameraHeight
Maximum feasible camera height above ground, see loadCosts()
Definition: RobotSceneConfiguration.h:245
void setCameraLocalTransform(const glm::mat4x4 &cameraTransform)
Sets the camera to a given pose.
static float costDistance
Cost factor for moving the camera (Euclidean distance), see loadCosts()
Definition: RobotSceneConfiguration.h:243
float getCost(RobotSceneConfiguration &previousConfig) const
Computes the cost for transitioning from a previous configuration.
void setCameraHeight(const float &value)
Sets the camera height.
glm::vec3 cameraPosition
Camera position in world coordinates.
Definition: RobotSceneConfiguration.h:222
static float gainFactor
Coefficient for weighting the information gain relative to the costs, see loadCosts() ...
Definition: RobotSceneConfiguration.h:246
GLuint count
Total number of observed pixels so far.
Definition: RobotSceneConfiguration.h:224
static float minCameraHeight
Minimum feasible camera height above ground, see loadCosts()
Definition: RobotSceneConfiguration.h:244
Scene graph corresponding to Assimp&#39;s aiScene.
Definition: Scene.h:59
float * articulation
Array current of articulation positions.
Definition: RobotSceneConfiguration.h:223
virtual ~RobotSceneConfiguration()
Destructor.
float constant
Constant cost factor for manipulating the object.
Definition: RobotSceneConfiguration.h:230
Definition: RandomSearchTask.h:47
void applyToScene(Scene *const scene) const
Applies the articulation configuration to the scene and re-computes the scene graph transformations...
void setRandomCameraHeight(unsigned int &seed)
Sets the camera height to a random value within the feasible range.
float linear
Linear cost factor for manipulating the object.
Definition: RobotSceneConfiguration.h:231
void setCount(const GLuint &count)
Sets the total number of observed pixels so far.
Definition: RobotSceneConfiguration.h:199
float getEvaluation(RobotSceneConfiguration &previousConfig) const
Returns the evaluation of the current config.
Definition: RobotSceneConfiguration.h:93
float getGain(RobotSceneConfiguration &previousConfig) const
Calculates the information gain achieved by moving to the new configuration.
void setRandomArticulation(unsigned int &seed)
Sets a random articulated object to a random configuration and the other articulated objects to the z...
const glm::mat4x4 & getCameraLocalTransform() const
Returns the camera pose.
Definition: RobotSceneConfiguration.h:145
Linear cost function for manipulating an articulated scene object.
Definition: RobotSceneConfiguration.h:229
Definition: AbstractCamera.h:41
static size_t numArticulation
The maximum number of articulated objects, hard-coded to 20.
Definition: RobotSceneConfiguration.h:218
glm::mat4x4 cameraLocalTransform
Camera pose as homogeneous transformation matrix in world coordinates.
Definition: RobotSceneConfiguration.h:221
static ArticulationCost * costArticulation
Linear cost function for changing articulation, see loadCosts()
Definition: RobotSceneConfiguration.h:247
static float costCameraHeightChange
Cost factor for changing the height of the camera, see loadCosts()
Definition: RobotSceneConfiguration.h:242
Represents a combined configuration of the robot and the articulation objects.
Definition: RobotSceneConfiguration.h:45
ArticulationCost(const float &constant=0.0f, const float &linear=0.0f)
Constructor.
Definition: RobotSceneConfiguration.h:237
float getArticulation(const size_t &handle) const
Returns the current articulation pose for a given articulated object.
Definition: RobotSceneConfiguration.h:161
void setRandomCameraPosition(unsigned int &seed, const std::vector< glm::vec3 > *const targetPoints)
Sets the camera pose to a random pose with the camera facing a random point from targetPoints.
Definition: HillclimbingTask.h:51
const GLuint & getCount() const
Returns the total number of observed pixels so far.
Definition: RobotSceneConfiguration.h:190
static void loadCosts()
Load the cost coefficients and feasible ranges from the configuration file.
void setArticulation(const size_t &handle, const float &value)
Sets the current articulation pose for a given articulated object.
Definition: RobotSceneConfiguration.h:176