PointCloud.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2024 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mrpt/maps/CSimplePointsMap.h>
11 #include <mrpt/opengl/COpenGLScene.h>
12 #include <mvsim/World.h>
14 
15 #include <rapidxml.hpp>
16 
17 #include "xml_utils.h"
18 
19 using namespace rapidxml;
20 using namespace mvsim;
21 using namespace std;
22 
23 PointCloud::PointCloud(World* parent, const rapidxml::xml_node<char>* root)
24  : WorldElementBase(parent)
25 {
27 }
28 
30 
32 {
33  gui_uptodate_ = false;
34 
35  if (auto x2d = root->first_node("file_txt_2d"); x2d && x2d->value())
36  {
37  const string sFile = world_->local_to_abs_path(x2d->value());
38 
39  points_ = mrpt::maps::CSimplePointsMap::Create();
40  points_->load2D_from_text_file(sFile);
41  }
42  else if (auto x3d = root->first_node("file_txt_3d"); x3d && x3d->value())
43  {
44  const string sFile = world_->local_to_abs_path(x3d->value());
45 
46  points_ = mrpt::maps::CSimplePointsMap::Create();
47  points_->load3D_from_text_file(sFile);
48  }
49  else
50  {
51  THROW_EXCEPTION("Error: No valid <file_*></file_*> XML tag was found");
52  }
53 
54  {
55  // Other general params:
57  ps["points_size"] = TParamEntry("%lf", &render_points_size_);
58  ps["pose_3d"] = TParamEntry("%pose3d", &pointcloud_pose_);
60  }
61 
62  points_->renderOptions.point_size = render_points_size_;
63 
64  gui_uptodate_ = false;
65 }
66 
68  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& viz,
69  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& physical,
70  [[maybe_unused]] bool childrenOnly)
71 {
72  using namespace mrpt::math;
73 
74  // 1st time call?? -> Create objects
75  if (!gl_points_ && viz && physical)
76  {
77  gl_points_ = mrpt::opengl::CSetOfObjects::Create();
78  gl_points_->setName("PointCloud");
79 
80  gl_points_->setPose(parent()->applyWorldRenderOffset(pointcloud_pose_));
81  viz->get().insert(gl_points_);
82  physical->get().insert(gl_points_);
83  }
84 
85  // 1st call OR gridmap changed?
86  if (!gui_uptodate_ && points_)
87  {
88  points_->getVisualizationInto(*gl_points_);
89  gui_uptodate_ = true;
90  }
91 }
92 
93 void PointCloud::simul_pre_timestep([[maybe_unused]] const TSimulContext& context) {}
mvsim::VisualObject::parent
World * parent()
Definition: VisualObject.h:51
mvsim::PointCloud::pointcloud_pose_
mrpt::poses::CPose3D pointcloud_pose_
Definition: PointCloud.h:57
mvsim
Definition: Client.h:21
mvsim::VisualObject::world_
World * world_
Definition: VisualObject.h:73
mvsim::TParamEntry
Definition: TParameterDefinitions.h:38
mvsim::parse_xmlnode_children_as_param
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions &params, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="", mrpt::system::COutputLogger *logger=nullptr)
Definition: xml_utils.cpp:215
World.h
mvsim::PointCloud::gui_uptodate_
bool gui_uptodate_
Definition: PointCloud.h:53
mvsim::PointCloud::~PointCloud
virtual ~PointCloud()
Definition: PointCloud.cpp:29
xml_utils.h
mvsim::World::local_to_abs_path
std::string local_to_abs_path(const std::string &in_path) const
Definition: World.cpp:106
rapidxml
Definition: rapidxml.hpp:57
mvsim::TSimulContext
Definition: basic_types.h:58
mvsim::PointCloud::gl_points_
mrpt::opengl::CSetOfObjects::Ptr gl_points_
Definition: PointCloud.h:54
mvsim::TParameterDefinitions
std::map< std::string, TParamEntry > TParameterDefinitions
Definition: TParameterDefinitions.h:64
mvsim::PointCloud::internalGuiUpdate
virtual void internalGuiUpdate(const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &viz, const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &physical, bool childrenOnly) override
Definition: PointCloud.cpp:67
mvsim::World
Definition: World.h:82
PointCloud.h
rapidxml::xml_node< char >
mvsim::World::user_defined_variables
const std::map< std::string, std::string > & user_defined_variables() const
Definition: World.h:390
std
mvsim::PointCloud::simul_pre_timestep
virtual void simul_pre_timestep(const TSimulContext &context) override
Definition: PointCloud.cpp:93
mvsim::PointCloud::points_
mrpt::maps::CPointsMap::Ptr points_
Definition: PointCloud.h:49
mrpt::math
Definition: xml_utils.h:22
root
root
rapidxml.hpp
mvsim::PointCloud::render_points_size_
double render_points_size_
Definition: PointCloud.h:56
mvsim::PointCloud::doLoadConfigFrom
void doLoadConfigFrom(const rapidxml::xml_node< char > *root)
Definition: PointCloud.cpp:31
mvsim::WorldElementBase
Definition: WorldElementBase.h:27


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:08