height_diff_layer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020, Sebastian Pütz
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided
14  * with the distribution.
15  *
16  * 3. Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * authors:
34  * Sebastian Pütz <spuetz@uni-osnabrueck.de>
35  *
36  */
37 
39 
43 
45 
46 namespace mesh_layers
47 {
49 {
50  ROS_INFO_STREAM("Try to read height differences from map file...");
51  auto height_diff_opt = mesh_io_ptr->getDenseAttributeMap<lvr2::DenseVertexMap<float>>("height_diff");
52 
53  if (height_diff_opt)
54  {
55  ROS_INFO_STREAM("Height differences have been read successfully.");
56  height_diff = height_diff_opt.get();
57 
58  return computeLethals();
59  }
60 
61  return false;
62 }
63 
65 {
66  ROS_INFO_STREAM("Compute lethals for \"" << layer_name << "\" (Height Differences Layer) with threshold "
67  << config.threshold);
68  lethal_vertices.clear();
69  for (auto vH : height_diff)
70  {
71  if (height_diff[vH] > config.threshold)
72  lethal_vertices.insert(vH);
73  }
74  ROS_INFO_STREAM("Found " << lethal_vertices.size() << " lethal vertices.");
75  return true;
76 }
77 
79 {
80  ROS_INFO_STREAM("Saving height_differences to map file...");
81  if (mesh_io_ptr->addDenseAttributeMap(height_diff, "height_diff"))
82  {
83  ROS_INFO_STREAM("Saved height differences to map file.");
84  return true;
85  }
86  else
87  {
88  ROS_ERROR_STREAM("Could not save height differences to map file!");
89  return false;
90  }
91 }
92 
94 {
95  return config.threshold;
96 }
97 
99 {
101  return computeLethals();
102 }
103 
105 {
106  return height_diff;
107 }
108 
109 void HeightDiffLayer::reconfigureCallback(mesh_layers::HeightDiffLayerConfig& cfg, uint32_t level)
110 {
111  bool notify = false;
112  ROS_INFO_STREAM("New height diff layer config through dynamic reconfigure.");
113 
114  if (first_config)
115  {
116  config = cfg;
117  first_config = false;
118  return;
119  }
120 
121  if (config.threshold != cfg.threshold)
122  {
123  computeLethals();
124  notify = true;
125  }
126 
127  config = cfg;
128  if (notify)
129  notifyChange();
130 }
131 
132 bool HeightDiffLayer::initialize(const std::string& name)
133 {
134  first_config = true;
136  new dynamic_reconfigure::Server<mesh_layers::HeightDiffLayerConfig>(private_nh));
137 
138  config_callback = boost::bind(&HeightDiffLayer::reconfigureCallback, this, _1, _2);
140  return true;
141 }
142 
143 } /* namespace mesh_layers */
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
boost::shared_ptr
mesh_map::AbstractLayer::notifyChange
void notifyChange()
mesh_layers::HeightDiffLayer::writeLayer
virtual bool writeLayer()
try to write layer to map file
Definition: height_diff_layer.cpp:78
lvr2::AttributeMap
NormalAlgorithms.hpp
mesh_layers::HeightDiffLayer::threshold
virtual float threshold()
delivers the threshold above which vertices are marked lethal
Definition: height_diff_layer.cpp:93
mesh_layers::HeightDiffLayer::height_diff
lvr2::DenseVertexMap< float > height_diff
Definition: height_diff_layer.h:143
mesh_layers
Definition: height_diff_layer.h:45
mesh_map::AbstractLayer::layer_name
std::string layer_name
mesh_layers::HeightDiffLayer::config
HeightDiffLayerConfig config
Definition: height_diff_layer.h:140
class_list_macros.h
lvr2::VectorMap
mesh_layers::HeightDiffLayer::computeLethals
bool computeLethals()
mark vertices with values above the threshold as lethal
Definition: height_diff_layer.cpp:64
mesh_map::AbstractLayer
height_diff_layer.h
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
mesh_layers::HeightDiffLayer::initialize
virtual bool initialize(const std::string &name)
initializes this layer plugin
Definition: height_diff_layer.cpp:132
lvr2::calcVertexHeightDifferences
DenseVertexMap< float > calcVertexHeightDifferences(const BaseMesh< BaseVecT > &mesh, double radius)
mesh_layers::HeightDiffLayer::reconfigure_server_ptr
boost::shared_ptr< dynamic_reconfigure::Server< mesh_layers::HeightDiffLayerConfig > > reconfigure_server_ptr
Definition: height_diff_layer.h:135
GeometryAlgorithms.hpp
mesh_map::AbstractLayer::private_nh
ros::NodeHandle private_nh
mesh_map::AbstractLayer::mesh_io_ptr
std::shared_ptr< lvr2::AttributeMeshIOBase > mesh_io_ptr
mesh_map::AbstractLayer::notify
notify_func notify
mesh_layers::HeightDiffLayer::first_config
bool first_config
Definition: height_diff_layer.h:138
mesh_map::AbstractLayer::mesh_ptr
std::shared_ptr< lvr2::HalfEdgeMesh< Vector > > mesh_ptr
mesh_layers::HeightDiffLayer::computeLayer
virtual bool computeLayer()
calculate the values of this layer
Definition: height_diff_layer.cpp:98
mesh_layers::HeightDiffLayer::reconfigureCallback
void reconfigureCallback(mesh_layers::HeightDiffLayerConfig &cfg, uint32_t level)
callback for incoming reconfigure configs
Definition: height_diff_layer.cpp:109
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(mesh_layers::InflationLayer, mesh_map::AbstractLayer)
mesh_layers::HeightDiffLayer::readLayer
virtual bool readLayer()
try read layer from map file
Definition: height_diff_layer.cpp:48
mesh_layers::HeightDiffLayer
Costmap layer which calculates the height difference to avoid steep regions.
Definition: height_diff_layer.h:50
mesh_layers::HeightDiffLayer::lethal_vertices
std::set< lvr2::VertexHandle > lethal_vertices
Definition: height_diff_layer.h:145
mesh_layers::HeightDiffLayer::costs
virtual lvr2::VertexMap< float > & costs()
deliver the current costmap
Definition: height_diff_layer.cpp:104
mesh_layers::HeightDiffLayer::config_callback
dynamic_reconfigure::Server< mesh_layers::HeightDiffLayerConfig >::CallbackType config_callback
Definition: height_diff_layer.h:136


mesh_layers
Author(s): Sebastian Pütz
autogenerated on Thu Jan 25 2024 03:43:03