ObjectGrid.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 João Borrego
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 
25 // WorldUtils request
26 #include "world_utils_request.pb.h"
27 
28 // Utilities
29 #include "utils.hh"
30 
31 // Gazebo
32 #include <gazebo/gazebo_client.hh>
33 // Eigen
34 #include <Eigen/Dense>
35 
37 #define SPHERE 0
38 #define CYLINDER 1
40 #define BOX 2
42 
44 class Object
45 {
46  // Public attributes
47 
49  public: int type;
51  public: std::string name;
53  public: ignition::math::Pose3d pose;
55  public: ignition::math::Vector3d scale;
57  public: std::vector<double> parameters;
59  public: std::vector<Eigen::Vector4f> points;
61  public: std::vector<int> bounding_box;
62 
63  // Private attributes
64 
66  private: const double ANGLE_STEP_C = 30.0;
68  private: const double TOTAL_STEPS_C = 360.0 / ANGLE_STEP_C;
70  private: const double ANGLE_STEP_S = 30.0;
72  private: const double TOTAL_STEPS_S = 360.0 / ANGLE_STEP_S;
73 
80  public: Object(
81  int & _type,
82  const std::string & _name,
83  const ignition::math::Pose3d & _pose,
84  const ignition::math::Vector3d & _scale,
85  const std::vector<double> & _parameters
86  );
87 
89  public: void sampleSurface();
90 
91 };
92 
95 {
96  // Public attributes
97 
99  public: std::vector<int> cells;
101  public: float grid_x;
103  public: float grid_y;
105  public: int num_cells_x;
107  public: int num_cells_y;
109  public: float cell_x;
111  public: float cell_y;
113  public: float cell_z;
115  public: std::vector<Object> objects;
117  public: int counters[3] = {0};
118 
120  public: const std::vector<std::string> TYPES = {"sphere", "cylinder","box"};
121 
128  public: ObjectGrid(
129  int num_x,
130  int num_y,
131  float size_x,
132  float size_y,
133  float size_z);
134 
137  public: void populate(int num_objects);
138 
142  private: void addRandomObject(int x, int y);
143 
144 };
float grid_y
Size of y dimension.
Definition: ObjectGrid.hh:103
Object in 2D grid.
Definition: ObjectGrid.hh:44
float cell_z
Height of each cell.
Definition: ObjectGrid.hh:113
std::vector< double > parameters
Object parameter values.
Definition: ObjectGrid.hh:57
const double ANGLE_STEP_C
Sample 3D points on object surface.
Definition: ObjectGrid.hh:66
std::vector< Object > objects
List of objects in grid.
Definition: ObjectGrid.hh:115
ignition::math::Pose3d pose
Object 3D world pose.
Definition: ObjectGrid.hh:53
ignition::math::Vector3d scale
Object scale vector.
Definition: ObjectGrid.hh:55
const double TOTAL_STEPS_S
Sample 3D points on object surface.
Definition: ObjectGrid.hh:72
float grid_x
Size of x dimension.
Definition: ObjectGrid.hh:101
const double TOTAL_STEPS_C
Sample 3D points on object surface.
Definition: ObjectGrid.hh:68
Object(int &_type, const std::string &_name, const ignition::math::Pose3d &_pose, const ignition::math::Vector3d &_scale, const std::vector< double > &_parameters)
Constructor.
Definition: ObjectGrid.cc:28
std::vector< int > cells
Array of grid cells.
Definition: ObjectGrid.hh:99
std::vector< int > bounding_box
Object 2D bounding box.
Definition: ObjectGrid.hh:61
std::vector< Eigen::Vector4f > points
Object surface 3D points.
Definition: ObjectGrid.hh:59
float cell_x
Size of each cell in x dimension.
Definition: ObjectGrid.hh:109
int num_cells_x
Number of cells in x dimension.
Definition: ObjectGrid.hh:105
int type
Object type.
Definition: ObjectGrid.hh:49
float cell_y
Size of each cell in y dimension.
Definition: ObjectGrid.hh:111
Object 2D grid.
Definition: ObjectGrid.hh:94
Generic utilities for scene generation example.
const double ANGLE_STEP_S
Sample 3D points on object surface.
Definition: ObjectGrid.hh:70
int num_cells_y
Number of cells in y dimension.
Definition: ObjectGrid.hh:107
std::string name
Object name.
Definition: ObjectGrid.hh:51
void sampleSurface()
Sample 3D points on object surface.
Definition: ObjectGrid.cc:41