Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ThreeDOut.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef _BIASTHREEDOUT_HH_
27 #define _BIASTHREEDOUT_HH_
28 
29 #include <bias_config.h>
30 
31 #include <cmath>
32 #include <list>
33 #include <vector>
34 #include <map>
35 // BIAS
36 #include <Base/Debug/Debug.hh>
37 #include <Base/Image/Image.hh>
38 #include <Base/Math/Vector3.hh>
39 #include <Base/Math/Vector4.hh>
40 #include <Base/Math/RGBA.hh>
41 #include <Base/Geometry/HomgPlane3D.hh>
42 #include <Base/Geometry/HomgPoint3D.hh>
43 #include <Geometry/PMatrix.hh>
44 #include <Geometry/Quadric3D.hh>
45 #include <Geometry/CovMatrix3x3.hh>
46 #include <Utils/PMatrix3DData.hh>
47 #include <Utils/TriangleMesh.hh>
48 #include <Geometry/Projection.hh>
49 #include <Geometry/ProjectionParametersBase.hh>
50 #include <Base/Geometry/PoseParametrization.hh>
51 
52 #define GL_GLEXT_PROTOTYPES
53 
54 #ifdef BIAS_HAVE_OPENGL
55 # include <Gui/biasgl.h>
56 #ifdef __APPLE__
57 # include <OpenGL/glu.h>
58 #else // __APPLE__
59 # include <GL/glu.h>
60 #endif // __APPLE__
61 //# include <GL/gl.h>
62  //# include <GL/glx.h>
63 #endif
64 
65 /// use one sigma as the standard confidence region for ellipsoid surfaces
66 /// if you want to supply a probability, see defines in Quadric3D.hh
67 #define DEF_P_SCALE 1.0
68 
69 // opaque, non transparent surface alpha value
70 #define ALPHA_TRANSPARENT 0
71 #define ALPHA_OPAQUE 255
72 
73 /// entity index offsets for selection rendering/picking. (OpenGL GL_SELECT)
74 /// Each entity index is mapped to an int using a entity specific offset
75 /// Thus the nr. of entites is currently limited to 100.000 !
76 /// Assert unique indexing, ranges must not overlap.
77 /// @author Jan Woetzel
78 //#define BIAS_SELECTION_OFFSET_IMAGE 100000
79 #define BIAS_SELECTION_OFFSET_PMATRIX 200000
80 //#define BIAS_SELECTION_OFFSET_LINE 300000
81 //#define BIAS_SELECTION_OFFSET_ELLIPSOID 400000
82 //#define BIAS_SELECTION_OFFSET_POINT 500000
83 
84 // BIASDOUT - log destination (?)
85 #define D_3DOUT_PDECOMP 0x00001000
86 
87 namespace BIAS {
88 
89  /** \class Projection3DData
90  * \brief stores data for drawing a the extrinisc parameters of a projection.
91  */
92  class BIASUtils_EXPORT Projection3DData {
93  public:
94  inline void Set(const BIAS::PoseParametrization& p,
95  const double scale=1.0) {
96 
97 
98  C = p.GetPosition();
100  RMatrix R;
101  R.SetFromQuaternion(Q);
102 
103  Set(C, R, scale);
104  }
105  /**
106  @bug this only works for projections with only one camera defined
107  @bug extend it to iterate over all cameras ore use
108  Set(const BIAS::ProjectionParametersBase& p,...)
109  */
110  inline void Set(const BIAS::Projection& p, const double scale=1.0 ) {
111  unsigned int width, height;
112  p.GetParameters()->GetImageSize(width, height);
113 
114  ratio = (double)width/(double)height;
115 
116  C = p.GetC();
117  RMatrix R = p.GetR();
118  Set(C, R, scale);
119  identifier = p.GetIdentifier();
120  }
121 
122  /**
123  @brief Only use this if you have a single camera or a Projection
124  with absolute Transformations of your cameras
125  It does not handle relative Transformations between first
126  and successive cameras.
127  */
128  inline void Set(const BIAS::ProjectionParametersBase& p,
129  const double scale=1.0 ) {
130  unsigned int width, height;
131  p.GetImageSize(width, height);
132  ratio = (double)width/(double)height;
133 
134  C = p.GetC();
135  RMatrix R = p.GetR();
136  Set(C, R, scale);
137  }
138 
139 
140 
141  inline void Set(const BIAS::Vector3<double>& C,
142  const BIAS::RMatrixBase& R,
143  const double scale=1.0) {
144  for(unsigned int i=0; i<3; i++) {
145  H[i] = scale*R[i][0];
146  V[i] = scale*R[i][1];
147  A[i] = scale*R[i][2];
148  }
149 
150  H = H+C;
151  V = V+C;
152  A = A+C;
153 
154  R.GetRotationAxisAngle(axis, angle);
155  }
156 
157  Projection3DData() : radiusSelection(0.1) {}
163  double angle;
164 
165  double ratio;
166 
168 
169  //type: 0 - perspective camera
170  // 1 - nonperspective camera
171  // -1 - no type of camera selected
172  int type;
173 
174  double scale;
175 
177  std::string identifier;
178  };
179 
180  /** @class Ellipsoid3DData
181  * @brief stores important data for drawing an el4000lipsoid
182  */
183  class BIASUtils_EXPORT Ellipsoid3DData {
184  public:
185  BIAS::Vector3<double> RotAxis; ///< rot to get 1st mainaxis from (1,0,0)
186  double dAngle; ///< rotation in radians around RotAxes
187  double s0, s1, s2; ///< lengths of main axes
188  BIAS::Vector3<double> C; ///< center of ellipsoid
190  };
191 
192  /** @class Text3DData
193  * @brief stores important data for drawing 3d text
194  */
195  class BIASUtils_EXPORT Text3DData {
196  public:
199  std::string Text;
200  double Size;
202  };
203 
204 
205  /** @class Point3DData
206  @brief stores data for drawing a point */
207  class BIASUtils_EXPORT Point3DData {
208  public:
211  };
212 
213  /** @class Image3DData
214  * @brief stores datas for a textured plane
215  */
216  class BIASUtils_EXPORT Image3DData {
217  public:
218  Vector3<double> UL; ///< upper left corner of image plane in wcs
219  Vector3<double> UR; ///< upper right corner of image plane in wcs
220  Vector3<double> LL; ///< lower left corner of image plane in wcs
221  Vector3<double> LR; ///< lower right corner of image plane in wcs
222  Image<unsigned char> ImageData; ///< data of texture image
223  bool BillBoard;
224  std::string name;
225  Image3DData() : BillBoard(false) {}
226 
228  UL=d.UL; UR=d.UR; LL=d.LL; LR=d.LR; ImageData=d.ImageData;
229  name=d.name; BillBoard = d.BillBoard;
230  }
231 
232  };
233 
234  /** @class Line3DData
235  * @brief stores data for drawing a line
236  */
237  class BIASUtils_EXPORT Line3DData {
238  public:
242  };
243 
244  /** @class IndexedFaceSet
245  * @brief stores data for drawing a indexed face set.
246  * Faces beeing (preferably flat) polygons
247  */
248  class BIASUtils_EXPORT IndexedFaceSet {
249  public:
250 
251  IndexedFaceSet();
252  IndexedFaceSet(const IndexedFaceSet& a);
253  ~IndexedFaceSet();
254 
256  std::vector<BIAS::Vector3<double> > vertexSet;
257  std::vector<BIAS::Vector4<unsigned char> > vertexColorSet;
258  std::vector<BIAS::Vector2<float> > texCoordSet;
259  //each BIAS::Vector storing a face
260  std::vector<BIAS::Vector<int> > faceIndices;
261  std::string name;
262  std::string textureName;
264  /// bounding box
269 
270  int VASize;
271  int CASize;
272 #ifdef BIAS_HAVE_OPENGL
273  int TASize, NumFacets;
274  bool compiled_;
275  GLuint displayList_;
277  GLfloat *VertArray, *NormalArray;
279  GLubyte *ColorArray;
280  // array holding pointer to indices making up a facet
281  // facet[0] -> {0, 100 , 200}
282  GLuint** facetArray;
283  // number of indices a single facet is using
284  //facetIndicesCountArray[0] = 3
286 #else
287  float *NormalArray;
288 #endif
289 
290  };
291 
292  /** @enum CameraDrawingStyle
293  @brief different styles when drawing cameras, e.g. in GL or VRML */
296 
297  /** @enum PointDrawingStyle
298  @brief different styles when drawing points, e.g. in GL or VRML */
300 
301  /** @enum PointDrawingStyle
302  @brief different styles when drawing lines, e.g. in GL or VRML */
304 
305  /** @struct ThreeDOutParameters
306  * @brief configuration struct for drawing styles of various 3d objects
307  * @ingroup g_utils
308  */
309  class BIASUtils_EXPORT ThreeDOutParameters {
310  public:
317  double PointSize;
318  double CameraScale;
319  int LineWidth; ///< in pixel
321  double WCSAxesLength; ///< <=0 means no visual coordinate axes
322 #ifdef BIAS_HAVE_OPENGL
324 #endif
325  };
326 
327  /** @class ThreeDOut
328  * @ingroup g_utils
329  @brief Unified output of 3D entities via OpenGL or VRML.
330 
331  Alpha blending policy (like OpenGL defaults):
332  - Alpha blending value means opacity (not transparency), e.g.
333  0 = full transparent (invisible glass), see ALPHA_TRANSPARENT
334  255 (1.0f) = opaque (not transparent), see ALPHA_OPAQUE
335  - Thus set OpenGL state of calling application accordingly e.g.
336  \verbatim
337  glEnable (GL_BLEND);
338  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
339  \endverbatim
340  - Remember to render in correct order:
341  - opaque primitives first,
342  - back to front order.
343  Details:
344  http://www.opengl.org/resources/faq/technical/transparency.htm
345 
346  However, VRML has inverse interpretation (!),
347  thus a conversion is required, see
348  http://www.web3d.org/x3d/specifications/vrml/ISO-IEC-14772-VRML97/part1/nodesRef.html */
349  class BIASUtils_EXPORT ThreeDOut : public Debug
350  {
351  public:
352 
353  // @brief Flag indicating whether the viewports should be displayed
354  // with cones and pyramids or not
356 
357  /// @brief Destructor releases all memory used
358  virtual ~ThreeDOut();
359 
360  /// @brief Constructor for empty 3D scene with given parameters
361  ThreeDOut(const BIAS::ThreeDOutParameters& params =
363 
364  void SetParamsPointSize(const double pointSize);
365  void SetParamsLineWidth(const int lineWidth);
366  void SetParamsCameraScale(double cameraScale); // only works for OpenGLOut!
367  void SetParamsCameraStyle(CameraDrawingStyle cameraStyle);
368  void SetParamsDrawEllipse(bool drawEllipse);
369  void SetParamsDrawCameraEllipse(bool drawEllipse);
370  void SetParamsEllipsoidScale(double ellipsoidScale);
371  void SetParamsWCSAxesLength(double WCSAxesLength);
372  void SetParamsPointDrawingStyle(const PointDrawingStyle pointStyle);
373  void SetParamsLineDrawingStyle(const LineDrawingStyle lineStyle);
374 
375  void SetParams(const ThreeDOutParameters& params);
376 
377  /** @brief transfers the whole scene by this offset */
378  void Translation(const Vector3<double>& movement);
379 
380  /** @name Functions to add geometric objects for output
381  @brief save the return value to update or delete the objects later
382  @{ */
383 
384  /** @return index value to change the point later
385  @param v point coordinates */
386  unsigned int AddPoint(const BIAS::Vector3<double> &v,
387  const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE );
388 
389  /** @return index value to change the text later
390  @param position text coordinates
391  @param orientation 3d orientation (screen-aligned if zero)
392  @param thetext string to be visualized in 3d
393  @param thesize: if>0: 3d height of text
394  if<0: 2d height (in pixels) of text */
395  unsigned int AddText(const std::string& thetext,
396  const BIAS::Vector3<double> &position,
397  const BIAS::Quaternion<double> &direction=
398  BIAS::Quaternion<double>(0.0,0.0,0.0,0.0),
399  const double& thesize = -12.0,
400  const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE );
401 
402 
403  /** @return index value to change the point later
404  @param v point coordinates */
405  unsigned int AddPoint(const BIAS::HomgPoint3D &v,
406  const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE );
407 
408  /** @return index value to change the line later
409  @param Start Start point of line
410  @param End End point of line */
411  unsigned int AddLine(const BIAS::Vector3<double> &Start,
412  const BIAS::Vector3<double> &End,
413  const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE );
414 
415  /** @return index value to change the line later
416  @param Start Start point of line
417  @param End End point of line */
418  unsigned int AddLine(const BIAS::HomgPoint3D &Start,
419  const BIAS::HomgPoint3D &End,
420  const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE);
421 
422  /** @param dConfidenceRegionScale see Quadric3D.hh for the relationship
423  between enlarging the standard confidence region and the probability
424  that a measurement will be inside that region, 1.0 means sigma */
425  unsigned int AddEllipsoid(BIAS::CovMatrix3x3 &cov,
426  const BIAS::Vector3<double> &C,
427  const BIAS::RGBAuc &Color=RGBAuc_WHITE_SEMI,
428  const double& dConfidenceRegionScale = DEF_P_SCALE,
429  const bool cameraCov = false);
430 
431  /** @param dConfidenceRegionScale see Quadric3D.hh for the relationship
432  between enlarging the standard confidence region and the probability
433  that a measurement will be inside that region, 1.0 means sigma */
434  unsigned int AddEllipsoid(BIAS::CovMatrix3x3 &cov,
435  const BIAS::HomgPoint3D &C,
436  const BIAS::RGBAuc &Color=RGBAuc_WHITE_SEMI,
437  const double& dConfidenceRegionScale = DEF_P_SCALE,
438  const bool cameraCov = false);
439 
440  /**
441  * @brief Adds the given plane to the scene, visualising it with lines
442  * or with a colored quad.
443  *
444  * @note The translation vector may render the plane's distance to the
445  * center of origin inconsistent. You must compute a proper
446  * translation vector that is located on the plane by yourself, e.g.
447  * by using HomgPlane3D::ProjectPoint().
448  *
449  * @param plane
450  * the plane to add
451  * @param colour
452  * the colour used for drawing
453  * @param size
454  * edge length of the plane
455  * @param translation
456  * the lines are moved by this vector
457  * @param wireframe
458  * specifies if plane should be displayed with lines or solid
459  *
460  * @author rwulff
461  * @date 09/2011
462  */
463  void AddPlane(const HomgPlane3D& plane,
464  const RGBAuc& colour = RGBAuc_WHITE_SEMI,
465  const double size = 1.0,
466  const Vector3<double>& translation = Vector3<double>(0.0, 0.0, 0.0),
467  const bool wireframe = true);
468 
469  /**
470  * @brief Helper function computing the corners of a 3D plane.
471  *
472  * @param plane
473  * the plane to compute corners for
474  * @param size
475  * edge length of the plane
476  * @param corners
477  * returns 3D coordinates of plane corners
478  *
479  * @author esquivel
480  * @date 06/2012
481  */
482  static void ComputePlaneCorners(const HomgPlane3D& plane,
483  const double size,
484  std::vector< Vector3<double> >& corners);
485 
486  /** decompose P and add to internal data structures.
487  \param name defines node name in vrml - does not like dots ('.')!
488  @todo the scale of the camera should be a (dynamic) visualization
489  option, not a parameter of the add function
490  @author woelk 01/2004 */
491  unsigned int AddPMatrix(BIAS::PMatrix &P,
492  const unsigned int& width,
493  const unsigned int& height,
494  const BIAS::RGBAuc &Color = RGBAuc_WHITE_OPAQUE,
495  const double &dScale = DEF_P_SCALE,
496  const std::string& name = "");
497 
498  /** interface for the above @author Jan Woetzel */
499  unsigned int AddPMatrix(BIAS::Matrix3x4<double> &M,
500  const unsigned int& width,
501  const unsigned int& height,
502  const BIAS::RGBAuc &Color = RGBAuc_WHITE_OPAQUE,
503  const double &dScale = DEF_P_SCALE,
504  const std::string& name = "");
505 
506 
507  /** @brief add a small rectangular image patch spanned by three 3d points
508  small means really small (only a few pixels), the patch is approximated
509  in a very complicated way in vrml to allow for inline data
510  @param channels number of channels: 1=grey, 3=rgb
511  @author koeser 09/2004 */
512  inline unsigned int AddImage(const Vector3<double>& UL,
513  const Vector3<double>& UR,
514  const Vector3<double>& LL,
515  unsigned int Width, unsigned int Height,
516  unsigned char* pData,
517  unsigned int channels = 1,
518  const std::string& name = "",
519  bool billboard = false)
520  {
521  Vector3<double> LR = LL + (UR-UL);
522  return AddImage(UL, UR, LL, LR, Width, Height, pData, channels,
523  name, billboard);
524  }
525 
526  /** @brief add a small image patch spanned by four 3d points
527  small means really small (only a few pixels), the patch is approximated
528  in a very complicated way in vrml to allow for inline data
529  @param channels number of channels: 1=grey, 3=rgb
530  @author koeser 09/2005 */
531  unsigned int AddImage(const Vector3<double>& UL,
532  const Vector3<double>& UR,
533  const Vector3<double>& LL,
534  const Vector3<double>& LR,
535  unsigned int Width, unsigned int Height,
536  unsigned char* pData,
537  unsigned int channels = 1,
538  const std::string& name = "",
539  bool billboard=false);
540 
541 
542  /** Adds triangle mesh as IndexedFaceSet to ThreeDOut mem.
543  * \param name defines node name in vrml - must not contain dots ('.')!
544  * \param textureOutputName is telling which name the texture shall have
545  * when writing the vrml. If this param is empty (default), the texture is
546  * integrated into the vrml as PixelMap.
547  * \param writeOutTexture if true and the textureOutputName is not "" then
548  * the texture is written into textureOutputName, otherwise only the texture
549  * name or a PixelMap is integrated into vrml. (default = true)
550  * \param calcNormals[in]: set whether to calculate normals (e.g. for lighting) or not.
551  * Normally normals are only calculated if no texture is present in mesh (default behaviour)
552  */
553  unsigned int AddTriangleMesh(const TriangleMesh& mesh,
554  const std::string& name="",
555  const std::string& textureOutputName = "",
556  bool writeOutTexture = true,
557  bool calcNormals = false);
558 
559  /** Add a projection object to ThreeDOut mem.
560  * \param colorSelection color of the small sphere around the center
561  * Draws the four cam coordinate axes (A in red, H in Green, V in blue)
562  * and a small sphere around the center which is usefull for selection.
563  */
564  unsigned int AddProjection(const Projection& p,
565  const RGBAuc& colorSelection =
566  RGBAuc_WHITE_OPAQUE,
567  const double radius = 0.1,
568  const double scale = 1.0,
569  const std::string& identifier = "",
570  const int camera_type = -1);
571 
572  /// interface for above
573  unsigned int AddProjection(const Projection& p,
574  const std::string& identifier)
575  {
576  return AddProjection(p,
577  RGBAuc_WHITE_OPAQUE,
578  0.1,
579  1.0,
580  identifier,
581  -1);
582  };
583 
584  /** @author bartczak */
585  unsigned int AddPose(const PoseParametrization& p,
586  const RGBAuc& colorSelection = RGBAuc_WHITE_OPAQUE,
587  const double radius = 0.1,
588  const double scale = 1.0,
589  const int camera_type = -1);
590 
591  /** @}
592  @name Functions to update previously added objects for output
593  @{ */
594 
595  /** @param PointIndex value previously returned by AddPoint */
596  void UpdatePoint(const unsigned int& PointIndex,
597  const BIAS::Vector3<double> &v,
598  const BIAS::RGBAuc &Color = RGBAuc_WHITE_OPAQUE);
599 
600  /** @param PointIndex value previously returned by AddPoint */
601  void UpdatePointColor(const unsigned int& PointIndex,
602  const BIAS::RGBAuc &Color);
603 
604  /** @param PointIndex value previously returned by AddPoint */
605  void UpdatePoint(const unsigned int& PointIndex,
606  const BIAS::HomgPoint3D &v,
607  const BIAS::RGBAuc &Color = RGBAuc_WHITE_OPAQUE);
608 
609  /** @param PIndex value previously returned by AddPMatrix */
610  void UpdatePMatrix(const unsigned int& PIndex, BIAS::PMatrix &P,
611  const unsigned int& width,
612  const unsigned int& height,
613  const BIAS::RGBAuc &Color = RGBAuc_WHITE_OPAQUE,
614  const double& dScale = DEF_P_SCALE);
615 
616  /** @param PIndex value previously returned by AddPMatrix */
617  void UpdatePMatrixColor(const unsigned int& PIndex,
618  const BIAS::RGBAuc &Color);
619 
620  /** @param LineIndex value previously returned by AddLine
621  @param Start Start point of line
622  @param End End point of line */
623  void UpdateLine(const unsigned int& LineIndex,
624  const BIAS::Vector3<double> &Start,
625  const BIAS::Vector3<double> &End,
626  const BIAS::RGBAuc &Color = RGBAuc_WHITE_OPAQUE);
627 
628  /** @param LineIndex value previously returned by AddLine
629  @param Start Start point of line
630  @param End End point of line */
631  void UpdateLine(const unsigned int& LineIndex,
632  const BIAS::HomgPoint3D &Start,
633  const BIAS::HomgPoint3D &End,
634  const BIAS::RGBAuc &Color = RGBAuc_WHITE_OPAQUE);
635 
636  /** @param dConfidenceRegionScale see Quadric3D.hh for the relationship
637  between enlarging the standard confidence region and the probability
638  that a measurement will be inside that region, 1.0 means sigma */
639  void UpdateEllipsoid(const unsigned int& EIndex,
640  BIAS::CovMatrix3x3 &cov,
642  const BIAS::RGBAuc &Color = RGBAuc_WHITE_SEMI,
643  const double& dConfidenceRegionScale = DEF_P_SCALE);
644 
645  /** @param dConfidenceRegionScale see Quadric3D.hh for the relationship
646  between enlarging the standard confidence region and the probability
647  that a measurement will be inside that region, 1.0 means sigma */
648  void UpdateEllipsoid(const unsigned int& EIndex,
649  BIAS::CovMatrix3x3 &cov,
651  const BIAS::RGBAuc &Color = RGBAuc_WHITE_SEMI,
652  const double& dConfidenceRegionScale = DEF_P_SCALE);
653  /** @}
654  @name Functions to remove previously added objects for output
655  @{ */
656 
657  /** @brief removes all entites
658  Essentially a clear on each entityt container.
659  @author Jan Woetzel */
660  void RemoveAll();
661 
662  /** @brief completely removes the point from the internal structures,
663  there is no way to get it back */
664  void RemovePoint(const unsigned int& PointIndex);
665 
666  /** @brief completely removes all points from the internal structures,
667  there is no way to get them back */
668  void RemoveAllPoints();
669 
670  /** @brief completely removes the line from the internal structures,
671  there is no way to get it back */
672  void RemoveLine(const unsigned int& LineIndex);
673 
674  /** @brief completely removes all lines from the internal structures JW */
675  void RemoveAllLines();
676 
677  /** @brief completely removes the ellipsoid from the internal structures,
678  there is no way to get it back */
679  void RemoveEllipsoid(const unsigned int& EIndex);
680 
681  /** @brief completely removes all ellipsoids from the internal structures,
682  there is no way to get it back */
683  void RemoveAllEllipsoids();
684 
685  void RemoveAllCamEllipsoids();
686 
687  /** @brief completely removes the image from the internal structures,
688  there is no way to get it back */
689  void RemoveImage(const unsigned int& EIndex);
690 
691  /** @brief completely removes all images from the internal structures,
692  there is no way to get it back */
693  void RemoveAllImages();
694 
695  void RemoveAllIndexedFaceSets();
696 
697  /** @brief removes the P-matrix index,
698  there is no way to get it back */
699  void RemovePMatrix(int index);
700 
701  /** @brief completely removes all images from the internal structures,
702  there is no way to get it back */
703  void RemoveAllPMatrices();
704 
705  /** @}
706  @name Functions for openGL output (if BIAS_HAVE_OPENGL)
707  @{ */
708 
709 #ifdef BIAS_HAVE_OPENGL
710 
711  /// @brief draw all points with the same color:
712  void OpenGLOutPoints(const BIAS::RGBAuc &Color);
713 
714  /// @brief draw all points with their own color:
715  void OpenGLOutPoints();
716 
717  /// @brief draw all pmatrices with the same color:
718  void OpenGLOutPMatrices(const BIAS::RGBAuc &Color);
719 
720  /// @brief draw all pmatrices with their own color:
721  void OpenGLOutPMatrices();
722 
723  /// @brief draw all lines with the same color:
724  void OpenGLOutLines(const BIAS::RGBAuc &Color);
725 
726  /// @brief draw all pmatrices with their own color
727  /// @todo linedrawingstyle=dashed not implmented
728  void OpenGLOutLines();
729 
730  /// @brief draw all ellipsoids with the same color:
731  void OpenGLOutEllipsoids(const BIAS::RGBAuc &Color);
732 
733  /// @brief draw all ellipsoids with their own color:
734  void OpenGLOutEllipsoids();
735 
736  /// @brief draw mesh into opengl
737  void OpenGLOutIndexedFaceSets();
738 
739  /** @brief draw all image patches using OpenGL
740  @param disableBlending true to glDisbale(GL_BLEND) temporarily
741  \todo: This implementation is very inefficient because it
742  recreates the textures for each rendering pass! JW */
743  void OpenGLOutImages(const bool & disableBlending=true);
744 
745  /** @brief display the world coordinate system origin and axes */
746  void OpenGLOutWCS();
747 
748  /** @brief draw all entities (with the same color) using OpenGL
749  Includes lines, points, pmatrices etc. (everything) */
750  void OpenGLOut(const BIAS::RGBAuc &Color);
751 
752  /** @brief render all entities (with the same color) using OpenGL
753  Includes lines, points, pmatrices etc. (everything) */
754  void OpenGLOut();
755 
756 
757 #endif // BIAS_HAVE_OPENGL
758 
759  /// get center of gravity (mean of structure)
760  Vector3<double> GetCenterOfPoints();
761 
762  /** Get the min and max vector of the smallest bounding box, which
763  * is drawn around the added points.
764  * \brief uncompleted, doesn't deliver correct results (mostly 0)
765  * \status alpha
766  */
767  void GetBoundingBox(Vector3<double> &min,Vector3<double> &max);
768 
769  /** @}
770  @name Functions for VRML output
771  @{ */
772 
773  /** @brief Generic write method (wrapper for VRMLOut). */
774  virtual int WriteToFile(const std::string &filename) {
775  return VRMLOut(filename);
776  }
777 
778  /** @brief flush all 3d objects to a vrml file with name sFilename, this
779  is the function most users would call */
780  int VRMLOut(const std::string &sFilename);
781 
782  /** @brief flush all 3d objects to a vrml file with name sFilename, use
783  Color as the color for all elements */
784  int VRMLOut(const std::string &sFilename, const BIAS::RGBAuc &Color);
785 
786  /** @brief only write (previously stored) points into an open vrml file,
787  override their individual colors with Color */
788  int VRMLOutPoints(std::ostream& vrml, const BIAS::RGBAuc &Color);
789 
790  /** @brief only write (previously stored) points into an open vrml file */
791  int VRMLOutPoints(std::ostream& vrml);
792 
793  /** @brief only write (previously stored) cameras into an open vrml file,
794  override their individual colors with Color */
795  int VRMLOutPMatrices(std::ostream& vrml, const BIAS::RGBAuc &Color);
796 
797 
798  /** @brief only write (previously stored) cameras into an open vrml file */
799  int VRMLOutPMatrices(std::ostream& vrml);
800 
801  /** @brief only write camera into an open vrml file */
802  int VRMLOutPMatricesRoutine(std::ostream& VRMLFile,
803  const PMatrix3DData *it,
804  double r=255.0,
805  double g=255.0,
806  double b=255.0,
807  double transparency=0.0,
808  bool CenterAsSphere=false);
809 
810  /** @brief only write (previously stored) lines into an open vrml file,
811  override their individual colors with Color */
812  int VRMLOutLines(std::ostream& vrml, const BIAS::RGBAuc &Color);
813 
814  /** @brief only write (previously stored) points into an open vrml file */
815  int VRMLOutLines(std::ostream& vrml);
816 
817  /** @brief only write (previously stored) ellipsoids to an open vrml file,
818  override their individual colors with Color */
819  int VRMLOutEllipsoids(std::ostream& vrml, const BIAS::RGBAuc &Color);
820 
821  /** @brief only write (previously stored) ellipsoids into an open vrml
822  file */
823  int VRMLOutEllipsoids(std::ostream& vrml);
824 
825  /** @brief only write (previously stored) images into an open vrml file */
826  int VRMLOutImages(std::ostream& VRMLFile);
827 
828  /** @brief only write (previously stored) face sets into an open vrml file
829  * Will include texture into VRML as PixelTexture node.
830  */
831  int VRMLOutIndexedFaceSets(std::ostream& VRMLFile);
832 
833  /** only write previously stored projection objects into opened vrml file.
834  */
835  int VRMLOutProjection(std::ostream& VRMLFile);
836 
837  /** only write previously stored projectionview objects into opened vrml
838  * file.
839  */
840  int VRMLOutProjectionView(std::ostream& VRMLFile);
841 
842  /** @brief write the VRML 2.0 header into an open file */
843  int VRMLOutWriteHeader(std::ostream& vrml);
844 
845  /** @brief write VRML 2.0 navigation info node @author Jan Woetzel */
846  void VRMLOutWriteNavigationInfo(std::ostream& vrml);
847 
848  /** write VRMl 2.0 viewpoint that can selecetd in vrml viewer
849  @author Jan Woetzel */
850  void VRMLOutWriteViewpoint(std::ostream& vrml);
851 
852  /** @brief write world coordinate system origin and axes */
853  void VRMLOutWCS(std::ostream& vrml);
854 
855  /** @}
856  @name Debug functions
857  @{ */
858  /** @brief list all internal 3d objects on cout */
859  void Dump();
860  /** @} */
861 
862  /** call by reference accessor for data member mapPMatrices_ JW */
863  inline std::map< unsigned int, PMatrix3DData > & GetMapPMatrices()
864  {
865  return mapPMatrices_;
866  }
867 
868  /** get alpha opacity value as VRML transparency
869  helper mapping, usually transparency = (1-alpha) */
870  static double VRMLtransparency(const unsigned char alpha);
871 
872  /** get alpha opacity component as VRML transparency g */
873  static double VRMLtransparency(const BIAS::Vector4<unsigned char> & vRgba);
874 
875  /** @brief write VRML viewpoint nodes for some P matrices ?
876  @author Jan Woetzel */
877  void SetWriteViewpoints(const bool & val);
878 
879  // ------------------------------------------------------------
880  protected:
881 
882  void DrawSphere_(double radius, int lats, int longs);
883 
884  //TWO MAIN METHODS OF DESCRIBING PYRAMID AND PAINTCONE IN VRML
885 
886  /** @brief Write a parameterized pyramid into VRMLFile.
887  * @param VRMLFile destination, writes to an end of the file
888  * @param selectionRadius length of an edge of the pyramid
889  * @param transparency transparency of given (r,g,b)-color
890  * @param angle angle between two opposite faces of pyramid which 3rd
891  * edges are width-of-the-projection far from eachother
892  * @param ratio width-of-the-projection/height-of-the-projection
893  * @param paint_lines redraw 4 edges of the pyramid (looks better)
894  * @author amattal
895  */
896  void PaintPyramid(std::ostream& VRMLFile,
897  double selectionRadius,
898  double r, double g, double b, double transparency,
899  double angle,
900  double ratio = 4.0/3.0,
901  double scale = 1.0,
902  const std::string& name = "",
903  bool paint_lines = false);
904 
905  /** @brief Write a parameterized cone into VRMLFile.
906  * @param VRMLFile destination, writes to an end of the file
907  * @param selectionRadius length of the side of the cone
908  * @param transparency transparency of given (r,g,b)-color
909  * @param angle angle of the cone
910  * @author amattal
911  */
912  void PaintCone(std::ostream& VRMLFile,
913  double selectionRadius,
914  double r, double g, double b, double transparency,
915  double angle,
916  double scale = 1.0,
917  const std::string& name = "");
918  //------------------------------------------------------------
919 
920 #ifdef BIAS_HAVE_OPENGL
921  void OpenGLOutPMatrices_(const BIAS::RGBAuc &Color, bool UseOneColor);
922 #endif
923 #ifdef BIAS_HAVE_GLEW
924  bool glewInitialized_;
925 #endif
926 
927  //THREE MAIN METHODS OF GRAPHICALLY DESCRIBING VIEWPORTS IN VRML
928 
929  /** @brief Write a projection of a PERSPECTIVE camera into VRML.
930  * @param VRMLFile destination, writes to an end of the file
931  * @param selectionRadius length of an edge of the pyramid(s)
932  * @param angle maximum angle of the camera-view
933  * @param ratio width-of-the-projection/height-of-the-projection
934  * @param scale scale of the projection
935  * @param solid true if Style = PyramidSolid
936  * @author amattal
937  */
938  void VRMLOutViewPortPyramidal(std::ostream& VRMLFile,
939  double selectionRadius,
940  double r, double g, double b,
941  double angle,
942  double ratio,
943  double scale,
944  const std::string& name,
945  bool solid = false);
946 
947  /** @brief Write a projection of a NON-PERSPECTIVE camera into VRML.
948  * @param VRMLFile destination, writes to an end of the file
949  * @param selectionRadius length of a side of the cone(s)
950  * @param angle maximum angle of the camera-view
951  * @param scale scale of the projection
952  * @param solid true if Style = PyramidSolid
953  * @author amattal
954  */
955  void VRMLOutViewPortConical(std::ostream& VRMLFile,
956  double selectionRadius,
957  double r, double g, double b,
958  double angle,
959  double scale,
960  const std::string& name,
961  bool solid = false);
962 
963  /** @brief Write a projection of a camera in COORDINATE-style into VRML.
964  * @param VRMLFile destination, writes to an end of the file
965  * @param scale scale of the projection
966  */
967  void CoordinateSystem(std::ostream& VRMLFile,
968  double selectionRadius,
969  double r, double g, double b, double axeslength,
970  double scale = 1.0,
971  const std::string& name = "");
972  //------------------------------------------------------------
973 
974  // helper for VRMLOutPoints()
975  int VRMLOutPointsAsPointSet_(std::ostream &VRMLFile);
976  int VRMLOutPointsAsBoxes_(std::ostream &VRMLFile);
977  int VRMLOutPointsAsSpheres_(std::ostream &VRMLFile);
978 
979  /// this is an optimized strategy to avoid hundred of shape nodes
980  int VRMLOutPMatricesAsArrows_(std::ostream& vrml, const BIAS::RGBAuc &Color);
981  int VRMLOutPMatricesAsMesh_(std::ostream& vrml, const BIAS::RGBAuc &Color);
982 
983  void VRMLOutEllipsoid_(std::ostream& vrml, Ellipsoid3DData& E,
984  const BIAS::RGBAuc &Color);
985 
986  /** @brief replace invalid characters in def string and return corrected
987  @author koeser */
988  std::string CorrectDefString_(const std::string& defstring);
990  /// holds the params set by constructor or SetParams
992 
993  /// the cameras are saved in a vector for efficiency reasons
994  std::map<unsigned int, PMatrix3DData > mapPMatrices_;
995  /// counter for the next index, gaps (due to delete) are not reused by now
996  unsigned int NextPIndex_;
997 
998  /// map of all image structures
999  std::map<unsigned int, Image3DData> mapImages_;
1000  /// counter for the next index, gaps (due to delete) are not reused by now
1001  unsigned int NextImageIndex_;
1002 
1003  /// map of all point structures
1004  std::map<unsigned int, Point3DData> mapPoints_;
1005  /// counter for the next index, gaps (due to delete) are not reused by now
1006  unsigned int NextPointIndex_;
1007 
1008  /// map of all point structures
1009  std::map<unsigned int, Text3DData> mapTexts_;
1010  /// counter for the next index, gaps (due to delete) are not reused by now
1011  unsigned int NextTextIndex_;
1012 
1013  /// map of all line structures
1014  std::map<unsigned int, Line3DData> mapLines_;
1015  /// counter for the next line index, gaps (due to delete) arent reused
1016  unsigned int NextLineIndex_;
1017 
1018  /// map of all ellipsoid structures
1019  std::map<unsigned int, Ellipsoid3DData> mapEllipsoids_;
1020  /// counter for the next ellipsoid index, gaps are not reused by now
1021  unsigned int NextEllipsoidIndex_;
1023  /// map of all ellipsoid structures
1024  std::map<unsigned int, Ellipsoid3DData> mapCamEllipsoids_;
1025  /// counter for the next ellipsoid index, gaps are not reused by now
1026  unsigned int NextCamEllipsoidIndex_;
1027 
1028  std::map<unsigned int, IndexedFaceSet> mapIndexedFaceSet_;
1029  unsigned int NextIndexedFaceSetIndex_;
1030 
1031  std::map<unsigned int, Projection3DData> mapProjection3D_;
1032  unsigned int NextProjection3DIndex_;
1033 
1034  bool WriteViewpoints_; //< write VRML viewpoint nodes for (some) PMatrices
1035 
1036  std::vector<double> meanDraw;
1037 
1038  }; // end class
1039 
1040 } // end namespace
1041 
1042 #endif
1043 
1044 
Vector3< double > UR
upper right corner of image plane in wcs
Definition: ThreeDOut.hh:219
virtual BIAS::Vector3< double > GetC() const
Get projection center.
BIAS::Image< unsigned char > texture
Definition: ThreeDOut.hh:255
double dAngle
rotation in radians around RotAxes
Definition: ThreeDOut.hh:186
GLsizei * facetIndicesCountArray
Definition: ThreeDOut.hh:285
void Set(const BIAS::Projection &p, const double scale=1.0)
Definition: ThreeDOut.hh:110
std::string identifier
Definition: ThreeDOut.hh:177
double s2
lengths of main axes
Definition: ThreeDOut.hh:187
std::string name
Definition: ThreeDOut.hh:261
Vector3< double > LR
lower right corner of image plane in wcs
Definition: ThreeDOut.hh:221
stores important data for drawing 3d text
Definition: ThreeDOut.hh:195
BIAS::Vector3< double > End
Definition: ThreeDOut.hh:240
Vector3< double > C
Definition: ThreeDOut.hh:158
Image3DData(const Image3DData &d)
Definition: ThreeDOut.hh:227
Unified output of 3D entities via OpenGL or VRML.
Definition: ThreeDOut.hh:349
void Set(const BIAS::PoseParametrization &p, const double scale=1.0)
Definition: ThreeDOut.hh:94
stores data for drawing a the extrinisc parameters of a projection.
Definition: ThreeDOut.hh:92
BIAS::Vector3< double > Point
Definition: ThreeDOut.hh:209
BIAS::RGBAuc ColorOfSelection
Definition: ThreeDOut.hh:176
std::string GetIdentifier() const
Return the identifier of the Projection such as a name.
Definition: Projection.hh:483
unsigned int AddProjection(const Projection &p, const std::string &identifier)
interface for above
Definition: ThreeDOut.hh:573
configuration struct for drawing styles of various 3d objects
Definition: ThreeDOut.hh:309
GLubyte * ColorArray
Definition: ThreeDOut.hh:279
BIAS::Vector3< double > RotAxis
rot to get 1st mainaxis from (1,0,0)
Definition: ThreeDOut.hh:185
unsigned int AddImage(const Vector3< double > &UL, const Vector3< double > &UR, const Vector3< double > &LL, unsigned int Width, unsigned int Height, unsigned char *pData, unsigned int channels=1, const std::string &name="", bool billboard=false)
add a small rectangular image patch spanned by three 3d points small means really small (only a few p...
Definition: ThreeDOut.hh:512
Vector3< double > bbmin
bounding box
Definition: ThreeDOut.hh:265
int SetFromQuaternion(const Quaternion< ROTATION_MATRIX_TYPE > &q)
Set rotation matrix from a quaternion.
double WCSAxesLength
&lt;=0 means no visual coordinate axes
Definition: ThreeDOut.hh:321
Slim class bundeling pose parametrization and associated covariance matrix.
stores data for drawing a line
Definition: ThreeDOut.hh:237
stores important data for drawing an el4000lipsoid
Definition: ThreeDOut.hh:183
BIAS::Vector3< double > C
center of ellipsoid
Definition: ThreeDOut.hh:188
BIAS::RGBAuc Color
Definition: ThreeDOut.hh:210
stores important data for drawing a camera
Vector3< double > UL
upper left corner of image plane in wcs
Definition: ThreeDOut.hh:218
std::vector< BIAS::Vector< int > > faceIndices
Definition: ThreeDOut.hh:260
std::string Text
Definition: ThreeDOut.hh:199
CameraDrawingStyle CameraStyle
Definition: ThreeDOut.hh:313
Vector3< double > V
Definition: ThreeDOut.hh:161
3D rotation matrix
Definition: RMatrix.hh:49
bool visualize_viewports
Definition: ThreeDOut.hh:355
Vector3< double > axis
Definition: ThreeDOut.hh:162
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
Definition: Projection.hh:194
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
stores datas for a textured plane
Definition: ThreeDOut.hh:216
Create and represent a 3D triangle mesh.
Definition: TriangleMesh.hh:84
std::vector< BIAS::Vector2< float > > texCoordSet
Definition: ThreeDOut.hh:258
Vector3< double > LL
lower left corner of image plane in wcs
Definition: ThreeDOut.hh:220
virtual BIAS::RMatrix GetR() const
Get orientation as rotation matrix R.
class for 3x3 covariance matrices
Definition: CovMatrix3x3.hh:50
LineDrawingStyle LineStyle
Definition: ThreeDOut.hh:314
std::string textureName
Definition: ThreeDOut.hh:262
std::vector< BIAS::Vector3< double > > vertexSet
Definition: ThreeDOut.hh:256
BIAS::Vector3< double > Start
Definition: ThreeDOut.hh:239
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
BIAS::Vector3< double > Position
Definition: ThreeDOut.hh:197
void Set(const BIAS::Vector3< double > &C, const BIAS::RMatrixBase &R, const double scale=1.0)
Definition: ThreeDOut.hh:141
LineDrawingStyle
Definition: ThreeDOut.hh:303
BIAS::RGBAuc Color
Definition: ThreeDOut.hh:241
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
Vector3< PP_TYPE > GetPosition() const
returns the position (first 3 entries) part of the pose parametrization vector
PointDrawingStyle
different styles when drawing points, e.g.
Definition: ThreeDOut.hh:299
stores data for drawing a point
Definition: ThreeDOut.hh:207
GLuint ** facetArray
Definition: ThreeDOut.hh:282
void Set(const BIAS::ProjectionParametersBase &p, const double scale=1.0)
Only use this if you have a single camera or a Projection with absolute Transformations of your camer...
Definition: ThreeDOut.hh:128
Vector3< double > H
Definition: ThreeDOut.hh:160
stores data for drawing a indexed face set.
Definition: ThreeDOut.hh:248
Implements a 3D rotation matrix.
Definition: RMatrixBase.hh:44
int GetRotationAxisAngle(Vector3< ROTATION_MATRIX_TYPE > &axis, ROTATION_MATRIX_TYPE &angle) const
Calculates angle and rotation axis representation for this rotation matrix.
std::vector< BIAS::Vector4< unsigned char > > vertexColorSet
Definition: ThreeDOut.hh:257
BIAS::RGBAuc Color
Definition: ThreeDOut.hh:201
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
PointDrawingStyle PointStyle
Definition: ThreeDOut.hh:312
Image< unsigned char > ImageData
data of texture image
Definition: ThreeDOut.hh:222
Quaternion< PP_TYPE > GetOrientation() const
returns the quaternion (last 4 entries) part of the pose parametrization vector
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
Vector3< double > GetC(unsigned int cam=0) const
return Center of camera with index cam.
Definition: Projection.hh:236
std::string name
Definition: ThreeDOut.hh:224
CameraDrawingStyle
different styles when drawing cameras, e.g.
Definition: ThreeDOut.hh:294
GLfloat * TextureCoordArray
Definition: ThreeDOut.hh:278
RMatrix GetR(unsigned int cam=0) const
return RMatrix of camera with index cam.
Definition: Projection.hh:243
BIAS::RGBAuc Color
Definition: ThreeDOut.hh:189
Vector3< double > A
Definition: ThreeDOut.hh:159
BIAS::Quaternion< double > Direction
Definition: ThreeDOut.hh:198
A homogeneous plane (in P^3) All points X on the plane p fulfill p &#39; * X = 0.
Definition: HomgPlane3D.hh:46