Main MRPT website > C++ reference for MRPT 1.4.0
CGeneralizedCylinder.h
Go to the documentation of this file.
1/* +---------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | http://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6 | See: http://www.mrpt.org/Authors - All rights reserved. |
7 | Released under BSD License. See details in http://www.mrpt.org/License |
8 +---------------------------------------------------------------------------+ */
9#ifndef opengl_CGeneralizedCylinder_H
10#define opengl_CGeneralizedCylinder_H
11
15#include <mrpt/math/geometry.h>
18
19namespace mrpt {
20namespace opengl {
22 // This must be added to any CSerializable derived class:
24 /**
25 * This object represents any figure obtained by extruding any profile along a given axis. The profile should lie over a x=0 plane, and the axis must be roughly perpendicular to this plane. In particular, it should be almost perpendicular to the Z axis.
26 * \ingroup mrpt_opengl_grp
27 */
30 public:
31 /**
32 * Auxiliary struct holding any quadrilateral, represented by foour points.
33 */
35 private:
36 /**
37 * Automatically compute a vector normal to this quadrilateral.
38 */
40 public:
41 /**
42 * Quadrilateral`'s points.
43 */
45 /**
46 * Normal vector.
47 */
48 double normal[3];
49 /**
50 * Given a polygon with 4 already positions allocated, this method fills it with the quadrilateral points.
51 * \sa mrpt::math::TPolygon3D
52 */
54 vec[0]=points[0];
55 vec[1]=points[1];
56 vec[2]=points[2];
57 vec[3]=points[3];
58 }
59 /**
60 * Constructor from 4 points.
61 */
63 points[0]=p1;
64 points[1]=p2;
65 points[2]=p3;
66 points[3]=p4;
67 calculateNormal();
68 }
69 /**
70 * Construction from any array of four compatible objects.
71 */
72 template<class T> TQuadrilateral(const T (&p)[4]) {
73 for (int i=0;i<4;i++) points[i]=p[i];
74 calculateNormal();
75 }
76 /**
77 * Empty constructor. Initializes to garbage.
78 */
80 /**
81 * Destructor.
82 */
84 };
85 protected:
86 /** Cylinder's axis. It's represented as a pose because it holds the angle to get to the next pose. */
88 /** Object's generatrix, that is, profile which will be extruded. */
89 std::vector<mrpt::math::TPoint3D> generatrix;
90 /** Mutable object with mesh information, used to avoid repeated computations. */
91 mutable std::vector<TQuadrilateral> mesh;
92 /** Mutable object with the cylinder's points, used to avoid repeated computations. */
94 /** Mutable flag which tells if recalculations are needed. */
95 mutable bool meshUpToDate;
96 /**
97 * Mutable set of data used in ray tracing.
98 * \sa mrpt::math::TPolygonWithPlane
99 */
100 mutable std::vector<mrpt::math::TPolygonWithPlane> polys;
101 /** Mutable flag telling whether ray tracing temporary data must be recalculated or not. */
102 mutable bool polysUpToDate;
103 /** Boolean variable which determines if the profile is closed at each section. */
104 bool closed;
105 /** Flag to determine whether the object is fully visible or only some sections are. */
107 /**
108 * First visible section, if fullyVisible is set to false.
109 * \sa fullyVisible,lastSection
110 */
112 /**
113 * Last visible section, if fullyVisible is set to false.
114 * \sa fullyVisible,firstSection
115 */
117 public:
118 /**
119 * Creation of generalized cylinder from axis and generatrix
120 */
121 static CGeneralizedCylinderPtr Create(const std::vector<mrpt::math::TPoint3D> &axis,const std::vector<mrpt::math::TPoint3D> &generatrix);
122 /**
123 * Render.
124 * \sa mrpt::opengl::CRenderizable
125 */
127 /**
128 * Ray tracing.
129 * \sa mrpt::opengl::CRenderizable.
130 */
131 bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const MRPT_OVERRIDE;
132 /**
133 * Get axis's spatial coordinates.
134 */
135 inline void getAxis(std::vector<mrpt::math::TPoint3D> &a) const {
136 //a=axis;
137 size_t N=axis.size();
138 a.resize(N);
139 for (size_t i=0;i<N;i++) {
140 a[i].x=axis[i].x();
141 a[i].y=axis[i].y();
142 a[i].z=axis[i].z();
143 }
144 }
145 /**
146 * Get axis, including angular coordinates.
147 */
149 a=axis;
150 }
151 /**
152 * Set the axis points.
153 */
154 inline void setAxis(const std::vector<mrpt::math::TPoint3D> &a) {
155 generatePoses(a,axis);
156 meshUpToDate=false;
157 fullyVisible=true;
159 }
160 /**
161 * Get cylinder's profile.
162 */
163 inline void getGeneratrix(std::vector<mrpt::math::TPoint3D> &g) const {
164 g=generatrix;
165 }
166 /**
167 * Set cylinder's profile.
168 */
169 inline void setGeneratrix(const std::vector<mrpt::math::TPoint3D> &g) {
170 generatrix=g;
171 meshUpToDate=false;
173 }
174 /**
175 * Returns true if each section is a closed polygon.
176 */
177 inline bool isClosed() const {
178 return closed;
179 }
180 /**
181 * Set whether each section is a closed polygon or not.
182 */
183 inline void setClosed(bool c=true) {
184 closed=c;
185 meshUpToDate=false;
187 }
188 /**
189 * Get a polyhedron containing the starting point of the cylinder (its "base").
190 * \sa getEnd,mrpt::opengl::CPolyhedron
191 */
192 void getOrigin(CPolyhedronPtr &poly) const;
193 /**
194 * Get a polyhedron containing the ending point of the cylinder (its "base").
195 * \sa getOrigin,mrpt::opengl::CPolyhedron
196 */
197 void getEnd(CPolyhedronPtr &poly) const;
198 /**
199 * Get the cylinder as a set of polygons in 3D.
200 * \sa mrpt::math::TPolygon3D
201 */
202 void generateSetOfPolygons(std::vector<mrpt::math::TPolygon3D> &res) const;
203 /**
204 * Get a polyhedron consisting of a set of closed sections of the cylinder.
205 * \sa mrpt::opengl::CPolyhedron
206 */
207 void getClosedSection(size_t index1,size_t index2,CPolyhedronPtr &poly) const;
208 /**
209 * Get a polyhedron consisting of a single section of the cylinder.
210 * \sa mrpt::opengl::CPolyhedron
211 */
212 inline void getClosedSection(size_t index,CPolyhedronPtr &poly) const {
213 getClosedSection(index,index,poly);
214 }
215 /**
216 * Get the number of sections in this cylinder.
217 */
218 inline size_t getNumberOfSections() const {
219 return axis.size()?(axis.size()-1):0;
220 }
221 /**
222 * Get how many visible sections are in the cylinder.
223 */
224 inline size_t getVisibleSections() const {
225 return fullyVisible?getNumberOfSections():(lastSection-firstSection);
226 }
227 /**
228 * Gets the cylinder's visible sections.
229 */
230 void getVisibleSections(size_t &first,size_t &last) const {
231 if (fullyVisible) {
232 first=0;
233 last=getNumberOfSections();
234 } else {
235 first=firstSection;
236 last=lastSection;
237 }
238 }
239 /**
240 * Sets all sections visible.
241 */
242 inline void setAllSectionsVisible() {
243 fullyVisible=true;
245 }
246 /**
247 * Hides all sections.
248 */
249 inline void setAllSectionsInvisible(size_t pointer=0) {
250 fullyVisible=false;
251 firstSection=pointer;
252 lastSection=pointer;
254 }
255 /**
256 * Sets which sections are visible.
257 * \throw std::logic_error on wrongly defined bounds.
258 */
259 inline void setVisibleSections(size_t first,size_t last) {
260 fullyVisible=false;
261 if (first>last||last>getNumberOfSections()) throw std::logic_error("Wrong bound definition");
262 firstSection=first;
263 lastSection=last;
265 }
266 /**
267 * Adds another visible section at the start of the cylinder. The cylinder must have an invisble section to display.
268 * \throw std::logic_error if there is no section to add to the displaying set.
269 * \sa addVisibleSectionAtEnd,removeVisibleSectionAtStart,removeVisibleSectionAtEnd
270 */
272 if (fullyVisible||firstSection==0) throw std::logic_error("No more sections");
273 firstSection--;
275 }
276 /**
277 * Adds another visible section at the end of the cylinder. The cylinder must have an invisible section to display.
278 * \throw std::logic_error if there is no section to add to the displaying set.
279 * \sa addVisibleSectionAtStart,removeVisibleSectionAtStart,removeVisibleSectionAtEnd
280 */
282 if (fullyVisible||lastSection==getNumberOfSections()) throw std::logic_error("No more sections");
283 lastSection++;
285 }
286 /**
287 * Removes a visible section from the start of the currently visible set.
288 * \throw std::logic_error if there are no visible sections.
289 * \sa addVisibleSectionAtStart,addVisibleSectionAtEnd,removeVisibleSectionAtEnd
290 */
292 /**
293 * Removes a visible section from the ending of the currently visible set.
294 * \throw std::logic_error when there is no such section.
295 * \sa addVisibleSectionAtStart,addVisibleSectionAtEnd,removeVisibleSectionAtStart
296 */
298 /**
299 * Gets the axis pose of the first section, returning false if there is no such pose.
300 */
302 /**
303 * Gets the axis pose of the last section, returning false if there is no such pose.
304 */
306 /**
307 * Gets the axis pose of the first visible section, returning false if there is no such pose.
308 */
310 /**
311 * Gets the axis pose of the last section, returning false if there is no such pose.
312 */
314 /**
315 * Updates the mutable set of polygons used in ray tracing.
316 */
317 void updatePolys() const;
318
319 /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
321
322 private:
323 /**
324 * Updates the axis, transforming each point into a pose pointing to the next section.
325 */
326 void generatePoses(const std::vector<mrpt::math::TPoint3D> &pIn, mrpt::aligned_containers<mrpt::poses::CPose3D>::vector_t &pOut);
327 /**
328 * Updates the mutable mesh.
329 */
330 void updateMesh() const;
331 /**
332 * Given a vector of polyhedrons, gets the starting and ending iterators to the section to be actually rendered.
333 */
335 /**
336 * Basic constructor with default initialization.
337 */
338 CGeneralizedCylinder():axis(),generatrix(),mesh(),meshUpToDate(false),polysUpToDate(false),closed(false),fullyVisible(true) {}
339 /**
340 * Constructor with axis and generatrix.
341 */
342 CGeneralizedCylinder(const std::vector<mrpt::math::TPoint3D> &a,const std::vector<mrpt::math::TPoint3D> &g):generatrix(g),mesh(),meshUpToDate(false),polysUpToDate(false),closed(false),fullyVisible(true) {
343 generatePoses(a,axis);
344 }
345 /**
346 * Destructor.
347 */
349 };
351}
352}
353#endif
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
3D polygon, inheriting from std::vector<TPoint3D>
This object represents any figure obtained by extruding any profile along a given axis.
std::vector< TQuadrilateral > mesh
Mutable object with mesh information, used to avoid repeated computations.
void getEnd(CPolyhedronPtr &poly) const
Get a polyhedron containing the ending point of the cylinder (its "base").
void setGeneratrix(const std::vector< mrpt::math::TPoint3D > &g)
Set cylinder's profile.
void updateMesh() const
Updates the mutable mesh.
void getMeshIterators(const std::vector< TQuadrilateral > &m, std::vector< TQuadrilateral >::const_iterator &begin, std::vector< TQuadrilateral >::const_iterator &end) const
Given a vector of polyhedrons, gets the starting and ending iterators to the section to be actually r...
bool getFirstSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the first section, returning false if there is no such pose.
void setVisibleSections(size_t first, size_t last)
Sets which sections are visible.
std::vector< mrpt::math::TPoint3D > generatrix
Object's generatrix, that is, profile which will be extruded.
mrpt::math::CMatrixTemplate< mrpt::math::TPoint3D > pointsMesh
Mutable object with the cylinder's points, used to avoid repeated computations.
bool getLastSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the last section, returning false if there is no such pose.
void setAllSectionsVisible()
Sets all sections visible.
void getOrigin(CPolyhedronPtr &poly) const
Get a polyhedron containing the starting point of the cylinder (its "base").
void removeVisibleSectionAtStart()
Removes a visible section from the start of the currently visible set.
bool fullyVisible
Flag to determine whether the object is fully visible or only some sections are.
bool getFirstVisibleSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the first visible section, returning false if there is no such pose.
size_t lastSection
Last visible section, if fullyVisible is set to false.
void setAllSectionsInvisible(size_t pointer=0)
Hides all sections.
bool closed
Boolean variable which determines if the profile is closed at each section.
void updatePolys() const
Updates the mutable set of polygons used in ray tracing.
static CGeneralizedCylinderPtr Create(const std::vector< mrpt::math::TPoint3D > &axis, const std::vector< mrpt::math::TPoint3D > &generatrix)
Creation of generalized cylinder from axis and generatrix.
mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t axis
Cylinder's axis.
CGeneralizedCylinder()
Basic constructor with default initialization.
void render_dl() const MRPT_OVERRIDE
Render.
bool polysUpToDate
Mutable flag telling whether ray tracing temporary data must be recalculated or not.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
void getVisibleSections(size_t &first, size_t &last) const
Gets the cylinder's visible sections.
void generatePoses(const std::vector< mrpt::math::TPoint3D > &pIn, mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t &pOut)
Updates the axis, transforming each point into a pose pointing to the next section.
bool getLastVisibleSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the last section, returning false if there is no such pose.
std::vector< mrpt::math::TPolygonWithPlane > polys
Mutable set of data used in ray tracing.
bool meshUpToDate
Mutable flag which tells if recalculations are needed.
void setClosed(bool c=true)
Set whether each section is a closed polygon or not.
CGeneralizedCylinder(const std::vector< mrpt::math::TPoint3D > &a, const std::vector< mrpt::math::TPoint3D > &g)
Constructor with axis and generatrix.
void setAxis(const std::vector< mrpt::math::TPoint3D > &a)
Set the axis points.
void addVisibleSectionAtStart()
Adds another visible section at the start of the cylinder.
void getClosedSection(size_t index, CPolyhedronPtr &poly) const
Get a polyhedron consisting of a single section of the cylinder.
void removeVisibleSectionAtEnd()
Removes a visible section from the ending of the currently visible set.
void getClosedSection(size_t index1, size_t index2, CPolyhedronPtr &poly) const
Get a polyhedron consisting of a set of closed sections of the cylinder.
size_t firstSection
First visible section, if fullyVisible is set to false.
size_t getNumberOfSections() const
Get the number of sections in this cylinder.
size_t getVisibleSections() const
Get how many visible sections are in the cylinder.
void getAxis(mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t &a) const
Get axis, including angular coordinates.
bool isClosed() const
Returns true if each section is a closed polygon.
void generateSetOfPolygons(std::vector< mrpt::math::TPolygon3D > &res) const
Get the cylinder as a set of polygons in 3D.
void getGeneratrix(std::vector< mrpt::math::TPoint3D > &g) const
Get cylinder's profile.
void addVisibleSectionAtEnd()
Adds another visible section at the end of the cylinder.
A renderizable object suitable for rendering with OpenGL's display lists.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:73
const Scalar * const_iterator
Definition: eigen_plugins.h:24
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:27
bool BASE_IMPEXP traceRay(const vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
class OPENGL_IMPEXP CGeneralizedCylinder
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
STL namespace.
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
Lightweight 3D point.
Auxiliary struct holding any quadrilateral, represented by foour points.
void getAsPolygonUnsafe(mrpt::math::TPolygon3D &vec) const
Given a polygon with 4 already positions allocated, this method fills it with the quadrilateral point...
TQuadrilateral(const T(&p)[4])
Construction from any array of four compatible objects.
TQuadrilateral(const mrpt::math::TPoint3D &p1, const mrpt::math::TPoint3D &p2, const mrpt::math::TPoint3D &p3, const mrpt::math::TPoint3D &p4)
Constructor from 4 points.
void calculateNormal()
Automatically compute a vector normal to this quadrilateral.



Page generated by Doxygen 1.9.4 for MRPT 1.4.0 SVN: at Thu Aug 4 01:35:14 UTC 2022