Population.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 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_PHYSICS_POPULATION_HH_
18 #define GAZEBO_PHYSICS_POPULATION_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <ignition/math/Pose3.hh>
23 #include <ignition/math/Vector3.hh>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/scoped_ptr.hpp>
26 #include <sdf/sdf.hh>
27 #include "gazebo/common/Console.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 
42  class GZ_PHYSICS_VISIBLE PopulationParams
43  {
45  public: ignition::math::Vector3d size;
46 
48  public: int rows;
49 
51  public: int cols;
52 
54  public: ignition::math::Vector3d step;
55 
57  public: ignition::math::Pose3d 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 
85  class GZ_PHYSICS_VISIBLE Population
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<ignition::math::Vector3d> &_poses);
155 
164  private: void CreatePosesBoxUniform(const PopulationParams &_populParams,
165  std::vector<ignition::math::Vector3d> &_poses);
166 
177  private: void CreatePosesBoxGrid(const PopulationParams &_populParams,
178  std::vector<ignition::math::Vector3d> &_poses);
179 
187  private: void CreatePosesBoxLinearX(const PopulationParams &_populParams,
188  std::vector<ignition::math::Vector3d> &_poses);
189 
197  private: void CreatePosesBoxLinearY(const PopulationParams &_populParams,
198  std::vector<ignition::math::Vector3d> &_poses);
199 
207  private: void CreatePosesBoxLinearZ(const PopulationParams &_populParams,
208  std::vector<ignition::math::Vector3d> &_poses);
209 
220  private: void CreatePosesCylinderRandom(
221  const PopulationParams &_populParams,
222  std::vector<ignition::math::Vector3d> &_poses);
223 
235  private: void CreatePosesCylinderUniform(
236  const PopulationParams &_populParams,
237  std::vector<ignition::math::Vector3d> &_poses);
238 
241  private: boost::scoped_ptr<PopulationPrivate> dataPtr;
242  };
244  }
245 }
246 #endif
std::string distribution
Object distribution. E.g.: random, grid.
Definition: Population.hh:75
Forward declarations for the common classes.
Definition: Animation.hh:26
Class that automatically populates an environment with multiple objects based on several parameters t...
Definition: Population.hh:85
double radius
Radius of the cylinder&#39;s base containing the models.
Definition: Population.hh:60
ignition::math::Vector3d 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
int cols
Number of columns used when models are distributed as a grid.
Definition: Population.hh:51
#define gzerr
Output an error message.
Definition: Console.hh:50
Stores all the posible parameters that define a population.
Definition: Population.hh:42
int modelCount
Number of models to spawn.
Definition: Population.hh:72
ignition::math::Vector3d step
Distance between models when they are distributed as a grid.
Definition: Population.hh:54
int rows
Number of rows used when models are distributed as a grid.
Definition: Population.hh:48
std::string modelName
Name of the model.
Definition: Population.hh:66
ignition::math::Pose3d pose
The reference frame of the population&#39;s region.
Definition: Population.hh:57
double length
Length of the cylinder containing the models.
Definition: Population.hh:63
std::string modelSdf
Contains the sdf representation of the model.
Definition: Population.hh:69