Population.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_POPULATION_HH_
18 #define _GAZEBO_POPULATION_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <boost/shared_ptr.hpp>
23 #include <boost/scoped_ptr.hpp>
24 #include <sdf/sdf.hh>
25 #include "gazebo/common/Console.hh"
26 #include "gazebo/math/Pose.hh"
27 #include "gazebo/math/Vector3.hh"
28 #include "gazebo/physics/World.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  namespace physics
34  {
37 
39  class PopulationPrivate;
40 
43  {
46 
48  public: int rows;
49 
51  public: int cols;
52 
55 
57  public: math::Pose pose;
58 
60  public: double radius;
61 
63  public: double length;
64 
66  public: std::string modelName;
67 
69  public: std::string modelSdf;
70 
72  public: int modelCount;
73 
75  public: std::string distribution;
76 
78  public: std::string region;
79  };
80 
86  {
90  public: Population(sdf::ElementPtr _sdf, boost::shared_ptr<World> _world);
91 
93  public: virtual ~Population();
94 
98  public: bool PopulateAll();
99 
104  private: bool PopulateOne(const sdf::ElementPtr _population);
105 
112  private: template<typename T> bool ValueFromSdf(
113  const sdf::ElementPtr &_sdfElement, const std::string &_element,
114  T &_value)
115  {
116  if (_sdfElement->HasElement(_element))
117  {
118  _value = _sdfElement->Get<T>(_element);
119  return true;
120  }
121  gzerr << "Unable to find <" << _element << "> inside the population tag"
122  << std::endl;
123  return false;
124  }
125 
132  private: bool ElementFromSdf(const sdf::ElementPtr &_sdfElement,
133  const std::string &_element, sdf::ElementPtr &_value);
134 
143  private: bool ParseSdf(sdf::ElementPtr _population,
144  PopulationParams &_params);
145 
153  private: void CreatePosesBoxRandom(const PopulationParams &_populParams,
154  std::vector<math::Vector3> &_poses);
155 
164  private: void CreatePosesBoxUniform(const PopulationParams &_populParams,
165  std::vector<math::Vector3> &_poses);
166 
177  private: void CreatePosesBoxGrid(const PopulationParams &_populParams,
178  std::vector<math::Vector3> &_poses);
179 
187  private: void CreatePosesBoxLinearX(const PopulationParams &_populParams,
188  std::vector<math::Vector3> &_poses);
189 
197  private: void CreatePosesBoxLinearY(const PopulationParams &_populParams,
198  std::vector<math::Vector3> &_poses);
199 
207  private: void CreatePosesBoxLinearZ(const PopulationParams &_populParams,
208  std::vector<math::Vector3> &_poses);
209 
220  private: void CreatePosesCylinderRandom(
221  const PopulationParams &_populParams,
222  std::vector<math::Vector3> &_poses);
223 
235  private: void CreatePosesCylinderUniform(
236  const PopulationParams &_populParams,
237  std::vector<math::Vector3> &_poses);
238 
241  private: boost::scoped_ptr<PopulationPrivate> dataPtr;
242  };
244  }
245 }
246 #endif
double length
Length of the cylinder containing the models.
Definition: Population.hh:63
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
Class that automatically populates an environment with multiple objects based on several parameters t...
Definition: Population.hh:85
math::Vector3 size
The three side lengths of the box.
Definition: Population.hh:45
std::string region
Type region in which the objects will be spawned. E.g.: box.
Definition: Population.hh:78
#define gzerr
Output an error message.
Definition: Console.hh:49
Stores all the posible parameters that define a population.
Definition: Population.hh:42
std::string modelName
Name of the model.
Definition: Population.hh:66
std::string distribution
Object distribution. E.g.: random, grid.
Definition: Population.hh:75
math::Vector3 step
Distance between models when they are distributed as a grid.
Definition: Population.hh:54
double radius
Radius of the cylinder's base containing the models.
Definition: Population.hh:60
int rows
Number of rows used when models are distributed as a grid.
Definition: Population.hh:48
std::string modelSdf
Contains the sdf representation of the model.
Definition: Population.hh:69
math::Pose pose
The reference frame of the population's region.
Definition: Population.hh:57
int modelCount
Number of models to spawn.
Definition: Population.hh:72
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
int cols
Number of columns used when models are distributed as a grid.
Definition: Population.hh:51