17 #if MRPT_HAS_OPENGL_GLUT 18 #ifdef MRPT_OS_WINDOWS 24 #include <OpenGL/gl.h> 31 #if MRPT_HAS_OPENGL_GLUT && defined(MRPT_OS_WINDOWS) 33 #if defined(_MSC_VER) || defined(__BORLANDC__) 34 #pragma comment (lib,"opengl32.lib") 35 #pragma comment (lib,"GlU32.lib") 37 #endif // MRPT_HAS_OPENGL_GLUT 53 const TPoint3D *arr[3]={&p1,&p2,&p3};
55 for (
size_t i=0;i<3;i++) {
59 t.r[i]=m_color.R*(1.f/255);
60 t.g[i]=m_color.G*(1.f/255);
61 t.b[i]=m_color.B*(1.f/255);
62 t.a[i]=m_color.A*(1.f/255);
64 triangles.push_back(
t);
65 CRenderizableDisplayList::notifyChange();
68 void CAngularObservationMesh::updateMesh()
const {
69 CRenderizableDisplayList::notifyChange();
71 size_t numRows=scanSet.size();
74 actualMesh.setSize(0,0);
75 validityMatrix.setSize(0,0);
79 if (pitchBounds.size()!=numRows&&pitchBounds.size()!=2)
return;
80 size_t numCols=scanSet[0].scan.size();
81 actualMesh.setSize(numRows,numCols);
82 validityMatrix.setSize(numRows,numCols);
83 double *pitchs=
new double[numRows];
84 if (pitchBounds.size()==2) {
85 double p1=pitchBounds[0];
86 double p2=pitchBounds[1];
87 for (
size_t i=0;i<numRows;i++) pitchs[i]=p1+(p2-p1)*
static_cast<double>(i)/static_cast<double>(numRows-1);
88 }
else for (
size_t i=0;i<numRows;i++) pitchs[i]=pitchBounds[i];
89 const bool rToL=scanSet[0].rightToLeft;
90 for (
size_t i=0;i<numRows;i++) {
91 const std::vector<float> &scan=scanSet[i].scan;
92 const std::vector<char> valid=scanSet[i].validRange;
93 const double pitchIncr=scanSet[i].deltaPitch;
94 const double aperture=scanSet[i].aperture;
95 const CPose3D origin=scanSet[i].sensorPose;
97 for (
size_t j=0;j<numCols;j++)
if ((validityMatrix(i,j)=(valid[j]!=0))) {
98 double pYaw=aperture*((
static_cast<double>(j)/static_cast<double>(numCols-1))-0.5);
100 actualMesh(i,j)=(origin+
CPose3D(0,0,0,rToL?pYaw:-pYaw,pitchIncr))+
CPoint3D(scan[j],0,0);
104 triangles.reserve(2*(numRows-1)*(numCols-1));
105 for (
size_t k=0;k<numRows-1;k++) {
106 for (
size_t j=0;j<numCols-1;j++) {
107 int b1=validityMatrix(k,j)?1:0;
108 int b2=validityMatrix(k,j+1)?1:0;
109 int b3=validityMatrix(k+1,j)?1:0;
110 int b4=validityMatrix(k+1,j+1)?1:0;
117 if (!
b1) addTriangle(actualMesh(k,j+1),actualMesh(k+1,j),actualMesh(k+1,j+1));
118 else if (!
b2) addTriangle(actualMesh(k,j),actualMesh(k+1,j),actualMesh(k+1,j+1));
119 else if (!
b3) addTriangle(actualMesh(k,j),actualMesh(k,j+1),actualMesh(k+1,j+1));
120 else if (!b4) addTriangle(actualMesh(k,j),actualMesh(k,j+1),actualMesh(k+1,j));
123 addTriangle(actualMesh(k,j),actualMesh(k,j+1),actualMesh(k+1,j));
124 addTriangle(actualMesh(k+1,j+1),actualMesh(k,j+1),actualMesh(k+1,j));
131 void CAngularObservationMesh::render_dl()
const {
132 #if MRPT_HAS_OPENGL_GLUT 133 if (mEnableTransparency) {
142 if (!meshUpToDate) updateMesh();
144 for (
size_t i=0;i<triangles.size();i++) {
146 float ax=
t.
x[1]-
t.x[0];
147 float bx=
t.x[2]-
t.x[0];
148 float ay=
t.y[1]-
t.y[0];
149 float by=
t.y[2]-
t.y[0];
150 float az=
t.z[1]-
t.z[0];
151 float bz=
t.z[2]-
t.z[0];
154 for (
int i=0;i<3;i++) {
158 if (mWireframe)
glEnd();
160 if (!mWireframe)
glEnd();
173 bool CAngularObservationMesh::setScanSet(
const std::vector<mrpt::obs::CObservation2DRangeScan> &scans) {
174 CRenderizableDisplayList::notifyChange();
177 if (scans.size()>0) {
178 size_t setSize=scans[0].scan.size();
179 bool rToL=scans[0].rightToLeft;
181 if (it->scan.size()!=
setSize)
return false;
182 if (it->rightToLeft!=rToL)
return false;
190 void CAngularObservationMesh::setPitchBounds(
const double initial,
const double final) {
191 CRenderizableDisplayList::notifyChange();
194 pitchBounds.push_back(initial);
195 pitchBounds.push_back(
final);
198 void CAngularObservationMesh::setPitchBounds(
const std::vector<double> &bounds) {
199 CRenderizableDisplayList::notifyChange();
204 void CAngularObservationMesh::getPitchBounds(
double &initial,
double &
final)
const {
205 initial=pitchBounds.front();
206 final=pitchBounds.back();
208 void CAngularObservationMesh::getPitchBounds(std::vector<double> &bounds)
const {
211 void CAngularObservationMesh::getScanSet(std::vector<CObservation2DRangeScan> &scans)
const {
215 void CAngularObservationMesh::generateSetOfTriangles(CSetOfTrianglesPtr &
res)
const {
216 if (!meshUpToDate) updateMesh();
217 res->insertTriangles(triangles.begin(),triangles.end());
229 void CAngularObservationMesh::generatePointCloud(
CPointsMap *out_map)
const {
253 writeToStreamRender(out);
255 out<<pitchBounds<<scanSet<<mWireframe<<mEnableTransparency;
266 readFromStreamRender(
in);
267 in>>pitchBounds>>scanSet>>mWireframe>>mEnableTransparency;
276 double value=initialValue();
277 double incr=increment();
280 for (
size_t i=0;i<am-1;i++,
value+=incr) vals[i]=
value;
281 vals[am-1]=finalValue();
284 void CAngularObservationMesh::getTracedRays(CSetOfLinesPtr &
res)
const {
285 if (!meshUpToDate) updateMesh();
287 for (
size_t i=0;i<validityMatrix.getRowCount();i++)
for (
size_t j=0;j<validityMatrix.getColCount();j++)
if (validityMatrix(i,j))
count++;
289 for (
size_t i=0;i<actualMesh.getRowCount();i++)
for (
size_t j=0;j<actualMesh.getColCount();j++)
if (validityMatrix(i,j))
res->appendLine(
TPose3D(scanSet[i].sensorPose),actualMesh(i,j));
298 pitchs.reserve(pi.size());
299 for (std::vector<double>::const_reverse_iterator it=pi.rbegin();it!=pi.rend();++it) pitchs.push_back(*it);
306 double yaw=obs.
aperture*((
static_cast<double>(i)/static_cast<double>(obs.
scan.
size()-1))-0.5);
312 void CAngularObservationMesh::getUntracedRays(CSetOfLinesPtr &
res,
double dist)
const {
318 for (
size_t i=0;i<3;i++) {
326 void CAngularObservationMesh::generateSetOfTriangles(std::vector<TPolygon3D> &
res)
const {
327 if (!meshUpToDate) updateMesh();
328 res.resize(triangles.size());
334 if (!meshUpToDate) updateMesh();
336 bb_min =
mrpt::math::TPoint3D(std::numeric_limits<double>::max(),std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
337 bb_max =
mrpt::math::TPoint3D(-std::numeric_limits<double>::max(),-std::numeric_limits<double>::max(),-std::numeric_limits<double>::max());
339 for (
size_t i=0;i<triangles.size();i++)
357 m_pose.composePoint(bb_min, bb_min);
358 m_pose.composePoint(bb_max, bb_max);
void clear()
Erase all the contents of the map.
GLuint GLuint GLsizei count
void operator()(const CObservation2DRangeScan &obs)
A mesh built from a set of 2D laser scan observations.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLboolean GLenum GLenum GLvoid * values
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
STLCONTAINER::const_iterator begin() const
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
const Scalar * const_iterator
#define GL_ONE_MINUS_SRC_ALPHA
double z
X,Y,Z coordinates.
#define GL_COLOR_MATERIAL
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
GLsizei GLsizei GLuint * obj
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL's display lists.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
std::vector< double > pitchs
This base provides a set of functions for maths stuff.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This namespace contains representation of robot actions and observations.
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
mrpt::utils::ContainerReadOnlyProxyAccessor< std::vector< char > > validRange
It's false (=0) on no reflected rays, referenced to elements in scan.
CAngularObservationMesh_fnctr(CPointsMap *p)
GLAPI void GLAPIENTRY glBegin(GLenum mode)
A class used to store a 3D point.
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
STLCONTAINER::const_iterator end() const
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
TPolygon3D createFromTriangle(const CSetOfTriangles::TTriangle &t)
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
double deltaPitch
If the laser gathers data by sweeping in the pitch/elevation angle, this holds the increment in "pitc...
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
The namespace for 3D scene representation and rendering.
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees)...
void operator()(const CObservation2DRangeScan &obj)
GLAPI void GLAPIENTRY glEnd(void)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLsizei const GLfloat * value
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
mrpt::utils::ContainerReadOnlyProxyAccessor< std::vector< float > > scan
The range values of the scan, in meters. Must have same length than validRange.
GLuint GLenum GLenum transform
GLAPI void GLAPIENTRY glDisable(GLenum cap)
bool insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=NULL)
Insert the observation information into this map.
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
FAddUntracedLines(CSetOfLinesPtr &l, const CPoint3D &p, const std::vector< double > &pi)
3D polygon, inheriting from std::vector<TPoint3D>
bool rightToLeft
The scanning direction: true=counterclockwise; false=clockwise.