Process an incoming geofence polygon message.
82 {
83 if (!validateFloats(msg)) {
84 setStatus(rviz_common::properties::StatusProperty::Error, "Topic",
85 "Message contained invalid floating point values (nans or infs)");
86 return;
87 }
88
89 rclcpp::Time msg_time(msg->header.stamp, RCL_ROS_TIME);
90 if (!updateFrame(msg->header.frame_id, msg_time)) {
91 setMissingTransformToFixedFrame(msg->header.frame_id);
92 return;
93 }
94 setTransformOk();
95
97
99 Ogre::ColourValue base_color(static_cast<float>(base_color_qt.redF()), static_cast<float>(base_color_qt.greenF()),
100 static_cast<float>(base_color_qt.blueF()), 1.0f);
101
106
107
108 rviz_rendering::MaterialManager::enableAlphaBlending(
material_, std::min(alpha_bottom, alpha_top));
109
110 const size_t n = msg->polygon.points.size();
111 if (n < 2 || height <= 0.0f) {
112 return;
113 }
114
115
116
118
119
120 unsigned int vertex_index = 0;
121 auto add_quad = [&](const Ogre::Vector3& b0, const Ogre::Vector3& b1, const Ogre::Vector3& t1, const Ogre::Vector3& t0) {
122
123 const unsigned int start_index = vertex_index;
124
125 Ogre::ColourValue bottom_color = base_color;
126 bottom_color.a = alpha_bottom;
127 Ogre::ColourValue top_color = base_color;
128 top_color.a = alpha_top;
129
138
139
140 manual_object_->triangle(start_index + 0, start_index + 1, start_index + 2);
141 manual_object_->triangle(start_index + 0, start_index + 2, start_index + 3);
142 vertex_index += 4;
143 };
144
145 const Ogre::Vector3 z_up(0.0f, 0.0f, 1.0f);
146
147 for (size_t i = 0; i < n; ++i) {
148 const auto& p0 = msg->polygon.points[i];
149 const auto& p1 = msg->polygon.points[(i + 1) % n];
150
151 Ogre::Vector3 P0(p0.x, p0.y, p0.z);
152 Ogre::Vector3 P1(p1.x, p1.y, p1.z);
153
154 Ogre::Vector3 edge = P1 - P0;
155 Ogre::Vector3 edge_xy(edge.x, edge.y, 0.0f);
156 if (edge_xy.squaredLength() < 1e-10f) {
157 continue;
158 }
159 edge_xy.normalise();
160 Ogre::Vector3 normal(-edge_xy.y, edge_xy.x, 0.0f);
161
162 const float hw = thickness * 0.5f;
163
164
165 Ogre::Vector3 B0 = P0;
166 Ogre::Vector3 B1 = P1;
167 Ogre::Vector3 T0 = P0 + height * z_up;
168 Ogre::Vector3 T1 = P1 + height * z_up;
169
170 if (thickness > 1e-6f) {
171
172 Ogre::Vector3 off = -normal * hw;
173 add_quad(B0 + off, B1 + off, T1 + off, T0 + off);
174
175 off = normal * hw;
176 add_quad(B0 + off, B1 + off, T1 + off, T0 + off);
177 } else {
178
179 Ogre::Vector3 off = normal * 1e-3f;
180 add_quad(B0 - off, B1 - off, T1 - off, T0 - off);
181 add_quad(B0 + off, B1 + off, T1 + off, T0 + off);
182 }
183 }
184
186}