roughness_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  ROS_INFO_STREAM("Try to read roughness from map file...");
50  auto roughness_opt =
51  mesh_io_ptr->getDenseAttributeMap<lvr2::DenseVertexMap<float>>(
52  "roughness");
53  if (roughness_opt) {
54  ROS_INFO_STREAM("Successfully read roughness from map file.");
55  roughness = roughness_opt.get();
56  return computeLethals();
57  }
58 
59  return false;
60 }
61 
63  if (mesh_io_ptr->addDenseAttributeMap(roughness, "roughness")) {
64  ROS_INFO_STREAM("Saved roughness to map file.");
65  return true;
66  } else {
67  ROS_ERROR_STREAM("Could not save roughness to map file!");
68  return false;
69  }
70 }
71 
73 {
74  ROS_INFO_STREAM("Compute lethals for \"" << layer_name << "\" (Roughness Layer) with threshold " << config.threshold );
75  lethal_vertices.clear();
76  for (auto vH : roughness) {
77  if (roughness[vH] > config.threshold)
78  lethal_vertices.insert(vH);
79  }
80  ROS_INFO_STREAM("Found " << lethal_vertices.size() << " lethal vertices.");
81  return true;
82 }
83 
84 float RoughnessLayer::threshold() { return config.threshold; }
85 
87  ROS_INFO_STREAM("Computing roughness...");
88 
90 
91  auto face_normals_opt =
93  "face_normals");
94 
95  if (face_normals_opt) {
96  face_normals = face_normals_opt.get();
97  ROS_INFO_STREAM("Found " << face_normals.numValues()
98  << " face normals in map file.");
99  } else {
101  "No face normals found in the given map file, computing them...");
102  face_normals = lvr2::calcFaceNormals(*mesh_ptr);
103  ROS_INFO_STREAM("Computed " << face_normals.numValues()
104  << " face normals.");
105  if (mesh_io_ptr->addDenseAttributeMap(face_normals, "face_normals")) {
106  ROS_INFO_STREAM("Saved face normals to map file.");
107  } else {
108  ROS_ERROR_STREAM("Could not save face normals to map file!");
109  return false;
110  }
111  }
112 
114  auto vertex_normals_opt =
116  "vertex_normals");
117 
118  if (vertex_normals_opt) {
119  vertex_normals = vertex_normals_opt.get();
120  ROS_INFO_STREAM("Found " << vertex_normals.numValues()
121  << " vertex normals in map file!");
122  } else {
124  "No vertex normals found in the given map file, computing them...");
125  vertex_normals = lvr2::calcVertexNormals(*mesh_ptr, face_normals);
126  if (mesh_io_ptr->addDenseAttributeMap(vertex_normals, "vertex_normals")) {
127  ROS_INFO_STREAM("Saved vertex normals to map file.");
128  } else {
129  ROS_ERROR_STREAM("Could not save vertex normals to map file!");
130  return false;
131  }
132  }
133 
134  roughness =
135  lvr2::calcVertexRoughness(*mesh_ptr, config.radius, vertex_normals);
136 
137  return computeLethals();
138 }
139 
141 
142 void RoughnessLayer::reconfigureCallback(mesh_layers::RoughnessLayerConfig &cfg, uint32_t level) {
143  bool notify = false;
144 
145  ROS_INFO_STREAM("New roughness layer config through dynamic reconfigure.");
146  if (first_config) {
147  config = cfg;
148  first_config = false;
149  return;
150  }
151 
152  if(config.threshold != cfg.threshold)
153  {
154  computeLethals();
155  notify = true;
156  }
157 
158  if(notify) notifyChange();
159 
160  config = cfg;
161 }
162 
163 bool RoughnessLayer::initialize(const std::string &name) {
164  first_config = true;
166  dynamic_reconfigure::Server<mesh_layers::RoughnessLayerConfig>>(
167  new dynamic_reconfigure::Server<mesh_layers::RoughnessLayerConfig>(
168  private_nh));
169 
171  boost::bind(&RoughnessLayer::reconfigureCallback, this, _1, _2);
173  return true;
174 }
175 
176 } /* namespace mesh_layers */
roughness_layer.h
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
boost::shared_ptr
mesh_map::AbstractLayer::notifyChange
void notifyChange()
lvr2::VectorMap::numValues
size_t numValues() const final
mesh_layers::RoughnessLayer::initialize
virtual bool initialize(const std::string &name)
initializes this layer plugin
Definition: roughness_layer.cpp:163
lvr2::AttributeMap
NormalAlgorithms.hpp
mesh_layers::RoughnessLayer::threshold
virtual float threshold()
delivers the threshold above which vertices are marked lethal
Definition: roughness_layer.cpp:84
mesh_layers
Definition: height_diff_layer.h:45
mesh_layers::RoughnessLayer::reconfigureCallback
void reconfigureCallback(mesh_layers::RoughnessLayerConfig &cfg, uint32_t level)
callback for incoming reconfigure configs
Definition: roughness_layer.cpp:142
mesh_layers::RoughnessLayer::reconfigure_server_ptr
boost::shared_ptr< dynamic_reconfigure::Server< mesh_layers::RoughnessLayerConfig > > reconfigure_server_ptr
Definition: roughness_layer.h:138
mesh_layers::RoughnessLayer::first_config
bool first_config
Definition: roughness_layer.h:141
mesh_map::AbstractLayer::layer_name
std::string layer_name
class_list_macros.h
lvr2::VectorMap
lvr2::calcVertexRoughness
DenseVertexMap< float > calcVertexRoughness(const BaseMesh< BaseVecT > &mesh, double radius, const VertexMap< Normal< typename BaseVecT::CoordType >> &normals)
mesh_map::AbstractLayer
lvr2::VectorMap::get
boost::optional< const ValueT & > get(HandleT key) const final
mesh_layers::RoughnessLayer::writeLayer
virtual bool writeLayer()
try to write layer to map file
Definition: roughness_layer.cpp:62
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
mesh_layers::RoughnessLayer
Costmap layer which calculates the roughness of the surface. This is useful to differentiate paths fr...
Definition: roughness_layer.h:51
mesh_layers::RoughnessLayer::config_callback
dynamic_reconfigure::Server< mesh_layers::RoughnessLayerConfig >::CallbackType config_callback
Definition: roughness_layer.h:139
GeometryAlgorithms.hpp
mesh_layers::RoughnessLayer::costs
virtual lvr2::VertexMap< float > & costs()
deliver the current costmap
Definition: roughness_layer.cpp:140
mesh_map::AbstractLayer::private_nh
ros::NodeHandle private_nh
mesh_map::AbstractLayer::mesh_io_ptr
std::shared_ptr< lvr2::AttributeMeshIOBase > mesh_io_ptr
mesh_layers::RoughnessLayer::computeLayer
virtual bool computeLayer()
calculate the values of this layer
Definition: roughness_layer.cpp:86
mesh_map::AbstractLayer::notify
notify_func notify
mesh_map::AbstractLayer::mesh_ptr
std::shared_ptr< lvr2::HalfEdgeMesh< Vector > > mesh_ptr
mesh_layers::RoughnessLayer::readLayer
virtual bool readLayer()
try read layer from map file
Definition: roughness_layer.cpp:48
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(mesh_layers::InflationLayer, mesh_map::AbstractLayer)
mesh_layers::RoughnessLayer::lethal_vertices
std::set< lvr2::VertexHandle > lethal_vertices
Definition: roughness_layer.h:135
lvr2::calcVertexNormals
DenseVertexMap< Normal< typename BaseVecT::CoordType > > calcVertexNormals(const BaseMesh< BaseVecT > &mesh, const FaceMap< Normal< typename BaseVecT::CoordType >> &normals)
mesh_layers::RoughnessLayer::config
RoughnessLayerConfig config
Definition: roughness_layer.h:143
lvr2::calcFaceNormals
DenseFaceMap< Normal< typename BaseVecT::CoordType > > calcFaceNormals(const BaseMesh< BaseVecT > &mesh)
mesh_layers::RoughnessLayer::roughness
lvr2::DenseVertexMap< float > roughness
Definition: roughness_layer.h:133
mesh_layers::RoughnessLayer::computeLethals
bool computeLethals()
mark vertices with values above the threshold as lethal
Definition: roughness_layer.cpp:72


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