33 void CGeneralizedCylinder::TQuadrilateral::calculateNormal() {
40 normal[0]=az*
by-ay*
bz;
41 normal[1]=ax*
bz-az*bx;
42 normal[2]=ay*bx-ax*
by;
44 for (
size_t i=0;i<3;i++)
s+=normal[i]*normal[i];
46 for (
size_t i=0;i<3;i++) normal[i]/=
s;
49 #if MRPT_HAS_OPENGL_GLUT 50 class FQuadrilateralRenderer {
56 for (
int i=0;i<4;i++)
glVertex3d(
t.points[i].x,
t.points[i].y,
t.points[i].z);
59 ~FQuadrilateralRenderer() {}
68 size_t qps=m.size()/getNumberOfSections();
69 begin=m.begin()+qps*firstSection;
70 end=m.begin()+qps*lastSection;
74 void CGeneralizedCylinder::render_dl()
const {
75 #if MRPT_HAS_OPENGL_GLUT 76 if (!meshUpToDate) updateMesh();
82 glColor4ub(m_color.R,m_color.G,m_color.B,m_color.A);
85 for_each(
begin,
end,FQuadrilateralRenderer(m_color));
109 if (!meshUpToDate||!polysUpToDate) updatePolys();
113 void CGeneralizedCylinder::updateMesh()
const {
114 CRenderizableDisplayList::notifyChange();
116 size_t A=axis.size();
117 vector<TPoint3D> genX=generatrix;
118 if (closed&&genX.size()>2) genX.push_back(genX[0]);
119 size_t G=genX.size();
123 for (
size_t i=0;i<A;i++)
for (
size_t j=0;j<G;j++) axis[i].composePoint(genX[j],pointsMesh.get_unsafe(i,j));
133 writeToStreamRender(out);
134 out<<axis<<generatrix;
141 readFromStreamRender(
in);
144 generatePoses(
a,axis);
149 readFromStreamRender(
in);
151 in>>axis>>generatrix;
158 CRenderizableDisplayList::notifyChange();
163 for (
size_t i=0;i<profile.size();i++) pose.
composePoint(profile[i].x,profile[i].y,profile[i].z,
p[i].x,
p[i].y,
p[i].z);
164 vector<math::TPolygon3D> convexPolys;
166 poly=CPolyhedron::Create(convexPolys);
169 void CGeneralizedCylinder::getOrigin(CPolyhedronPtr &poly)
const {
170 if (!meshUpToDate) updateMesh();
171 if (axis.size()<2||generatrix.size()<3)
throw std::logic_error(
"Not enough points.");
172 size_t i=fullyVisible?0:firstSection;
174 poly->setPose(this->m_pose);
175 poly->setColor(getColor());
178 void CGeneralizedCylinder::getEnd(CPolyhedronPtr &poly)
const {
179 if (!meshUpToDate) updateMesh();
180 if (axis.size()<2||generatrix.size()<3)
throw std::logic_error(
"Not enough points.");
181 size_t i=(fullyVisible?axis.size():lastSection)-1;
183 poly->setPose(this->m_pose);
184 poly->setColor(getColor());
187 void CGeneralizedCylinder::generateSetOfPolygons(std::vector<TPolygon3D> &
res)
const {
188 if (!meshUpToDate||!polysUpToDate) updatePolys();
189 size_t N=polys.size();
191 for (
size_t i=0;i<N;i++)
res[i]=polys[i].poly;
194 void CGeneralizedCylinder::getClosedSection(
size_t index1,
size_t index2,mrpt::opengl::CPolyhedronPtr &poly)
const {
195 if (index1>index2) swap(index1,index2);
196 if (index2>=axis.size()-1)
throw std::logic_error(
"Out of range");
198 if (!meshUpToDate) updateMesh();
199 pointsMesh.extractRows(index1,index2+1,ROIpoints);
203 vector<TPoint3D> vec;
207 vector<TPoint3D> vertices;
211 vector<vector<uint32_t> > faces;
212 faces.reserve(nr*nc+2);
213 vector<uint32_t> tmp(4);
214 for (
size_t i=0;i<nr;i++)
for (
size_t j=0;j<nc;j++) {
215 size_t base=(nc+1)*i+j;
220 faces.push_back(tmp);
223 for (
size_t i=0;i<nr+1;i++) tmp[i]=i*(nc+1);
224 faces.push_back(tmp);
225 for (
size_t i=0;i<nr+1;i++) tmp[i]=i*(nc+2)-1;
226 poly=CPolyhedron::Create(vertices,faces);
229 void CGeneralizedCylinder::removeVisibleSectionAtStart() {
230 CRenderizableDisplayList::notifyChange();
232 if (!getNumberOfSections())
throw std::logic_error(
"No more sections");
235 lastSection=getNumberOfSections();
236 }
else if (firstSection>=lastSection)
throw std::logic_error(
"No more sections");
239 void CGeneralizedCylinder::removeVisibleSectionAtEnd() {
240 CRenderizableDisplayList::notifyChange();
242 if (!getNumberOfSections())
throw std::logic_error(
"No more sections");
245 lastSection=getNumberOfSections()-1;
246 }
else if (firstSection>=lastSection)
throw std::logic_error(
"No more sections");
250 void CGeneralizedCylinder::updatePolys()
const {
251 CRenderizableDisplayList::notifyChange();
253 if (!meshUpToDate) updateMesh();
254 size_t N=mesh.size();
257 for (
size_t i=0;i<N;i++) {
258 for (
size_t j=0;j<4;j++) tmp[j]=mesh[i].
points[j];
273 for (;;)
if ((it2=it1+1)==pIn.end())
break;
275 yaws.push_back(atan2(it2->y-it1->y,it2->x-it1->x));
278 yaws.push_back(*yaws.rbegin());
280 for (
size_t i=0;i<N;i++) {
286 bool CGeneralizedCylinder::getFirstSectionPose(
CPose3D &
p) {
287 if (axis.size()<=0)
return false;
292 bool CGeneralizedCylinder::getLastSectionPose(
CPose3D &
p) {
293 if (axis.size()<=0)
return false;
298 bool CGeneralizedCylinder::getFirstVisibleSectionPose(
CPose3D &
p) {
299 if (fullyVisible)
return getFirstSectionPose(
p);
300 if (getVisibleSections()<=0)
return false;
301 p=axis[firstSection];
305 bool CGeneralizedCylinder::getLastVisibleSectionPose(
CPose3D &
p) {
306 if (fullyVisible)
return getLastSectionPose(
p);
307 if (getVisibleSections()<=0)
return false;
318 m_pose.composePoint(bb_min, bb_min);
319 m_pose.composePoint(bb_max, bb_max);
void extractCol(size_t nCol, std::vector< T > &out, int startingRow=0) const
Returns a given column to a vector (without modifying the matrix)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
bool BASE_IMPEXP splitInConvexComponents(const TPolygon2D &poly, std::vector< TPolygon2D > &components)
Splits a 2D polygon into convex components.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
EIGEN_STRONG_INLINE iterator begin()
This file implements miscelaneous matrix and matrix/vector operations, and internal functions in mrpt...
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
const Scalar * const_iterator
#define GL_ONE_MINUS_SRC_ALPHA
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
GLsizei const GLfloat * points
A renderizable object suitable for rendering with OpenGL's display lists.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
This base provides a set of functions for maths stuff.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
GLAPI void GLAPIENTRY glNormal3d(GLdouble nx, GLdouble ny, GLdouble nz)
GLAPI void GLAPIENTRY glBegin(GLenum mode)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void getAsVector(std::vector< T > &out) const
Returns a vector containing the matrix's values.
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
void generatePolygon(CPolyhedronPtr &poly, const vector< TPoint3D > &profile, const CPose3D &pose)
class OPENGL_IMPEXP CGeneralizedCylinder
This template class provides the basic functionality for a general 2D any-size, resizable container o...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
This object represents any figure obtained by extruding any profile along a given axis...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void appendCol(const std::vector< T > &in)
Appends a new column to the matrix from a vector.
void OPENGL_IMPEXP checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
The namespace for 3D scene representation and rendering.
size_t getColCount() const
Number of columns in the matrix.
GLAPI void GLAPIENTRY glEnd(void)
size_t getRowCount() const
Number of rows in the matrix.
Auxiliary struct holding any quadrilateral, represented by foour points.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLubyte GLubyte GLubyte a
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
3D polygon, inheriting from std::vector<TPoint3D>
void createMesh(const CMatrixTemplate< TPoint3D > &pointsMesh, size_t R, size_t C, vector< CGeneralizedCylinder::TQuadrilateral > &mesh)