Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ThreeDOut.cpp
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 #ifdef WIN32
26 # pragma warning (disable: 4251) // STL MAP DLL warning noise (JW)
27 #endif
28 
29 #include <ctype.h>
30 #include "ThreeDOut.hh"
31 #include <Base/Debug/TimeMeasure.hh>
32 #include <Base/Image/ImageIO.hh>
33 #include <Geometry/RMatrix.hh>
34 
35 #if defined(BIAS_HAVE_OPENGL) && defined(BIAS_HAVE_FONTGL)
36 #include <Utils/DrawTextGL.hh>
37 #endif
38 
39 #ifdef BIAS_HAVE_OPENGL
40 # include <Utils/StatekeeperGL.hh>
41 #endif
42 
43 #define ASSERT_MAP_ELEMENT(themap, key) if (themap.find(key)==themap.end()) { \
44  BIASERR("Tried to access map with key " \
45  <<key<<". Undefined Element." \
46  <<" Aborting."); BIASABORT; }
47 
48 #define DEGREE_PER_RAD (180.0/M_PI)
49 
50 
51 using namespace BIAS;
52 using namespace std;
53 
54 
56  writeOutTexture(false), bbmin(0,0,0), bbmax(0,0,0)
57 {
58  NormalArray = NULL;
59  useNormals = false;
60  useTexture = true;
61  useColoredVertices = false;
62  CASize = VASize = 0;
63 #ifdef BIAS_HAVE_OPENGL
64  compiled_ = false;
65  NumFacets = 0;
66  TASize = 0;
67  displayList_ = 0;
68  textureObjectID_ = 0;
69  VertArray = NULL;
70  TextureCoordArray = NULL;
71  facetArray = NULL;
72  ColorArray = NULL;
74 #endif
75 }
76 
78 {
79  VASize = a.VASize;
80  CASize = a.CASize;
81  NormalArray = NULL;
82 
83 #ifdef BIAS_HAVE_OPENGL
84  TASize = a.TASize;
85  compiled_ = false;
86  displayList_ = 0;
87  textureObjectID_ = 0,
88  VertArray = NULL;
89  TextureCoordArray = NULL;
90  facetArray = NULL;
92  ColorArray = NULL;
93 
94  if (a.VertArray!=NULL) {
95  VertArray = new GLfloat [VASize];
96  memcpy(VertArray, a.VertArray, VASize*sizeof(GLfloat));
97  }
98 
99  if (a.NormalArray!=NULL) {
100  NormalArray = new GLfloat [VASize];
101  memcpy(NormalArray, a.NormalArray, VASize*sizeof(GLfloat));
102  }
103 
104  if (a.ColorArray!=NULL) {
105  ColorArray = new GLubyte [CASize];
106  memcpy(ColorArray, a.ColorArray, CASize*sizeof(GLubyte));
107  }
108 
109  if (a.TextureCoordArray!=NULL) {
110  TextureCoordArray = new GLfloat [TASize];
111  memcpy(TextureCoordArray, a.TextureCoordArray, TASize*sizeof(GLfloat));
112  }
113 
114  NumFacets = a.NumFacets;
115  if(a.facetIndicesCountArray!=NULL) {
116  facetIndicesCountArray = new GLsizei[NumFacets];
118  NumFacets*sizeof(GLsizei));
119  }
120 
121  if(a.facetArray!=NULL) {
122  facetArray = new GLuint*[NumFacets];
123  for(int i=0; i<NumFacets; i++) {
124  facetArray[i] = new GLuint[facetIndicesCountArray[i]];
125  for(GLsizei j=0; j<facetIndicesCountArray[i]; j++)
126  facetArray[i][j] = a.facetArray[i][j];
127 // memcpy(facetArray[i], a.facetArray[i],
128 // facetIndicesCountArray[i]*sizeof(GLuint));
129  }
130  }
131 #else
132  if (a.NormalArray!=NULL) {
133  NormalArray = new float [VASize];
134  memcpy(NormalArray, a.NormalArray, VASize*sizeof(float));
135  }
136 #endif
137  texture = a.texture;
138  vertexSet = a.vertexSet;
142  name = a.name;
146  bbmin = a.bbmin;
147  bbmax = a.bbmax;
148 }
149 
151 {
152  if(NormalArray!=NULL) delete [] NormalArray;
153 #ifdef BIAS_HAVE_OPENGL
154  if(VertArray!=NULL) delete [] VertArray;
155  if(ColorArray!=NULL) delete [] ColorArray;
156  if(TextureCoordArray!=NULL) delete [] TextureCoordArray;
157  for(int i=0; i<NumFacets; i++){
158  if(facetArray[i]!=NULL) delete[] facetArray[i];
159  }
160  if(facetArray!=NULL) delete [] facetArray;
162  // TODO fixme: glDeleteLists segfaults, test for displayList_ == null added as hotfix
163  if (compiled_ && displayList_ != 0) {
164  glDeleteLists(displayList_, 1);
165  glDeleteTextures(1, &textureObjectID_);
166  }
167 #endif
168 }
169 
172 {
173  PointStyle = Point;
175  LineStyle = Solid;
178  PointSize = 0.1;
179  CameraScale = 1.0;
180  LineWidth = 1;
181  EllipsoidScale = 1.0;
182  WCSAxesLength = -1.0;
183 #ifdef BIAS_HAVE_OPENGL
184  IndexedFaceSetPrimitiveMode = GL_POLYGON;
185 #endif
186 }
187 
190  NextPointIndex_ = 0;
191  NextTextIndex_ = 0;
192  NextLineIndex_ = 0;
195  NextPIndex_ = 0;
196  NextImageIndex_ = 0;
198  WriteViewpoints_ = false;
199  visualize_viewports = true;
200 
201  SetParams(params);
202 
203 }
204 
207 
208 void ThreeDOut::
210  Params_ = params;
211 }
212 
213 void ThreeDOut::
214 SetParamsPointSize(const double pointSize)
215 {
216  Params_.PointSize = pointSize;
217 }
218 void ThreeDOut::
219 SetParamsLineWidth(const int lineWidth)
220 {
221  Params_.LineWidth = lineWidth;
222 }
223 
224 void ThreeDOut::
225 SetParamsCameraScale(const double cameraScale)
226 {
227  Params_.CameraScale = cameraScale;
228 }
229 
230 void ThreeDOut::
232 {
233  Params_.CameraStyle = cameraStyle;
234 }
235 
236 void ThreeDOut::
237 SetParamsDrawEllipse(const bool drawEllipse)
238 {
239  Params_.DrawUncertaintyEllipsoids = drawEllipse;
240 }
241 
242 void ThreeDOut::
243 SetParamsDrawCameraEllipse(const bool drawEllipse)
244 {
246 }
247 
248 void ThreeDOut::
249 SetParamsEllipsoidScale(const double ellipsoidScale)
250 {
251  Params_.EllipsoidScale = ellipsoidScale;
252 }
253 
254 void ThreeDOut::
255 SetParamsWCSAxesLength(double WCSAxesLength)
256 {
257  Params_.WCSAxesLength = WCSAxesLength;
258 }
259 
260 void ThreeDOut::
262 {
263  Params_.PointStyle = pointStyle;
264 }
265 
266 void ThreeDOut::
268 {
269  Params_.LineStyle = lineStyle;
270 }
271 
272 string ThreeDOut::
273 CorrectDefString_(const string& defstring) {
274  if(defstring.size()==0)
275  return defstring;
276  string result = defstring;
277  string::size_type posofinvalidchar = 0;
278  if( isdigit(result[0]) !=0) {
279  //BIASERR("DEF string in VRML must not start with a digit !");
280  result = "_"+result;
281  }
282  if (result.size()>0) do {
283  // just look for points (not allowed)
284  posofinvalidchar = result.find('.', posofinvalidchar);
285  if (posofinvalidchar != string::npos) {
286  //BIASERR("replaced invalid character with underscore");
287  result.at(posofinvalidchar) = '_';
288  }
289  } while (posofinvalidchar != string::npos);
290  posofinvalidchar = 0;
291  if (result.size()>0) do {
292  // just look for points (not allowed)
293  posofinvalidchar = result.find(' ', posofinvalidchar);
294  if (posofinvalidchar != string::npos) {
295  //BIASERR("replaced invalid character with underscore");
296  result.at(posofinvalidchar) = '_';
297  }
298  } while (posofinvalidchar != string::npos);
299  return result;
300 }
301 
302 //This one writes described pyramid into VRMLFile
303 //r,g,b - color of pyramid
304 //selectionRadius - length of Pyramid-EDGE
305 void ThreeDOut::
306 PaintPyramid(ostream& VRMLFile,
307  double selectionRadius,
308  double r, double g, double b, double transparency,
309  double angle,
310  double ratio,
311  double scale,
312  const std::string& name,
313  bool paint_lines)
314 {
315  double PI_1 = 3.1415926;
316  double PI_2 = 6.2831852;
317 
318  bool angle_too_big = false;
319  if(angle > PI_1 && angle < PI_2){
320  angle_too_big = true;
321  angle = PI_2-angle;
322  }
323  else if(angle > PI_2){
324  return;
325  }
326 
327  if (name.length()>0){
328  std::string mod_name = CorrectDefString_(name);
329  VRMLFile<<"DEF "<<mod_name << " ";
330  }
331 
332  double dist_x = sin(angle/2.0);
333  double dist_y = dist_x/(double)ratio;
334 
335  double dist = sqrt(dist_y*dist_y + 1.0);
336  double k = (double)selectionRadius/dist;
337 
338  double dist_z = cos(angle/2.0)*k;
339  dist_x = dist_x * k;
340  dist_y = dist_y * k;
341 
342  //VRML ROUTINE
343  VRMLFile<<"Transform { "<<std::endl;
344  VRMLFile<<" translation 0 0 0"<<std::endl;
345  //if (angle<=0.0) angle = 1.0;
346  VRMLFile<<" scale "<<scale<<" "<<scale
347  <<" "<<scale<<" "<<endl;
348  VRMLFile<<" children ["<<std::endl;
349 
350  VRMLFile<<" DEF ViewPort Transform { "<<std::endl;
351  if(angle_too_big){
352  VRMLFile<<" rotation 1 0 0 -1.57"<<std::endl;
353  VRMLFile<<" translation 0 0 0"<<std::endl;
354  }
355  else{
356  VRMLFile<<" rotation 1 0 0 1.57"<<std::endl;
357  VRMLFile<<" translation 0 0 0"<<std::endl;
358  }
359  VRMLFile<<" children ["<<std::endl;
360 
361  //----------------FACES-----------------
362 
363  VRMLFile<<" Shape { "<<std::endl;
364  VRMLFile<<" geometry IndexedFaceSet {"<<std::endl;
365 
366  VRMLFile<<" "<<std::endl;
367 
368  VRMLFile<<" coord Coordinate {"<<std::endl;
369  VRMLFile<<" point ["<<std::endl;
370 
371  VRMLFile<<" 0 0 0,"<<std::endl;
372 
373  VRMLFile<<" "
374  <<-dist_x<<" "<< dist_z<<" "<< dist_y<<","<<std::endl;
375  VRMLFile<<" "
376  << dist_x<<" "<< dist_z<<" "<< dist_y<<","<<std::endl;
377  VRMLFile<<" "
378  << dist_x<<" "<< dist_z<<" "<<-dist_y<<","<<std::endl;
379  VRMLFile<<" "
380  <<-dist_x<<" "<< dist_z<<" "<<-dist_y<<","<<std::endl;
381  VRMLFile<<" ]"<<std::endl;
382  VRMLFile<<" }"<<std::endl;
383 
384  VRMLFile<<" coordIndex ["<<std::endl;
385 
386  VRMLFile<<" 1, 2, 3, 4, -1,"<<std::endl;
387  VRMLFile<<" 0, 1, 2, -1,"<<std::endl;
388  VRMLFile<<" 0, 2, 3, -1,"<<std::endl;
389  VRMLFile<<" 0, 3, 4, -1,"<<std::endl;
390  VRMLFile<<" 0, 4, 1, -1,"<<std::endl;
391 
392  VRMLFile<<" ]"<<std::endl;
393 
394  VRMLFile<<" }"<<std::endl;
395  VRMLFile<<" appearance Appearance {"<<std::endl;
396  VRMLFile<<" material Material {"<<std::endl;
397  VRMLFile<<" emissiveColor "<<1.0<<" "<<1.0<<" "<<1.0<<std::endl;
398  VRMLFile<<" transparency "<<transparency<<std::endl;
399  VRMLFile<<" }"<<std::endl;
400  VRMLFile<<" }"<<std::endl;
401  VRMLFile<<" }"<<std::endl;
402 
403  //----------------LINES-----------------
404 
405  if(paint_lines){
406  VRMLFile<<" Shape { "<<std::endl;
407  VRMLFile<<" geometry IndexedLineSet {"<<std::endl;
408 
409  VRMLFile<<" "<<std::endl;
410 
411  VRMLFile<<" coord Coordinate {"<<std::endl;
412  VRMLFile<<" point ["<<std::endl;
413 
414  VRMLFile<<" 0 0 0,"<<std::endl;
415 
416  VRMLFile<<" "
417  <<-dist_x<<" "<< dist_z<<" "<< dist_y<<","<<std::endl;
418  VRMLFile<<" "
419  << dist_x<<" "<< dist_z<<" "<< dist_y<<","<<std::endl;
420  VRMLFile<<" "
421  << dist_x<<" "<< dist_z<<" "<<-dist_y<<","<<std::endl;
422  VRMLFile<<" "
423  <<-dist_x<<" "<< dist_z<<" "<<-dist_y<<","<<std::endl;
424  VRMLFile<<" ]"<<std::endl;
425  VRMLFile<<" }"<<std::endl;
426 
427  VRMLFile<<" color Color {"<<std::endl;
428  VRMLFile<<" color ["<<std::endl;
429  VRMLFile<<" 255 255 255"<<std::endl;
430  //<<r<<" "<<g<<" "<<b<<std::endl;
431  VRMLFile<<" ]"<<std::endl;
432  VRMLFile<<" }"<<std::endl;
433 
434  VRMLFile<<" coordIndex ["<<std::endl;
435  VRMLFile<<" 0, 1, -1,"<<std::endl;
436  VRMLFile<<" 0, 2, -1,"<<std::endl;
437  VRMLFile<<" 0, 3, -1,"<<std::endl;
438  VRMLFile<<" 0, 4, -1,"<<std::endl;
439  VRMLFile<<" ]"<<std::endl;
440 
441  VRMLFile<<" colorIndex ["<<std::endl;
442  VRMLFile<<" 0, 0, 0, 0"<<std::endl;
443  VRMLFile<<" ]"<<std::endl;
444 
445  VRMLFile<<" }"<<std::endl;
446  VRMLFile<<" }"<<std::endl;
447  }
448 
449  //--------------------------------------
450 
451  VRMLFile<<" ]"<<std::endl;
452  VRMLFile<<" }"<<std::endl;
453  VRMLFile<<" ]"<<std::endl;
454  VRMLFile<<"}"<<std::endl;
455 }
456 
457 //This one writes described cone into VRMLFile
458 //r,g,b - color of Cone
459 //selectionRadius - length of Cone-SIDE
460 void ThreeDOut::
461 PaintCone(ostream& VRMLFile,
462  double selectionRadius,
463  double r, double g, double b, double transparency,
464  double angle,
465  double scale,
466  const std::string& name)
467 {
468  double PI_1 = 3.1415926;
469  double PI_2 = 6.2831852;
470 
471  bool angle_too_big = false;
472  if(angle > PI_1 && angle < PI_2){
473  angle_too_big = true;
474  angle = PI_2-angle;
475  }
476  else if(angle > PI_2){
477  BIASERR("angle too big");
478  return;
479  }
480 
481  if (name.length()>0){
482  string mod_name = CorrectDefString_(name);
483  VRMLFile<<"DEF "<<mod_name << " ";
484  }
485 
486  VRMLFile<<"Transform { "<<std::endl;
487  VRMLFile<<" translation 0 0 0"<<std::endl;
488  VRMLFile<<" scale "<<scale<<" "<<scale
489  <<" "<<scale<<" "<<endl;
490  VRMLFile<<" children ["<<std::endl;
491 
492  double radius = selectionRadius*sin(angle/2.0);
493  double height = 0.0;
494  if(angle != 1.0 && angle != 0.0)
495  height = selectionRadius*cos(angle/2.0);
496 
497  VRMLFile<<" DEF ViewPort Transform { "<<std::endl;
498  if(angle_too_big){
499  VRMLFile<<" rotation 1 0 0 1.57"<<std::endl;
500  VRMLFile<<" translation 0 0 "<<-height/2.0<<std::endl;
501  }
502  else{
503  VRMLFile<<" rotation 1 0 0 -1.57"<<std::endl;
504  VRMLFile<<" translation 0 0 "<<height/2.0<<std::endl;
505  }
506  VRMLFile<<" children ["<<std::endl;
507  VRMLFile<<" Shape { "<<std::endl;
508  VRMLFile<<" geometry Cone{ bottomRadius "<<radius
509  <<" height "<<height<<std::endl
510  <<" side TRUE"<<std::endl
511  <<" bottom FALSE"<<std::endl
512  <<" }"<<std::endl;
513  VRMLFile<<" appearance Appearance {"<<std::endl;
514  VRMLFile<<" material Material {"<<std::endl;
515  VRMLFile<<" emissiveColor "<<1.0<<" "<<1.0<<" "<<1.0<<std::endl;
516  VRMLFile<<" transparency "<<transparency<<std::endl;
517  VRMLFile<<" }"<<std::endl;
518  VRMLFile<<" }"<<std::endl;
519  VRMLFile<<" }"<<std::endl;
520  VRMLFile<<" ]"<<std::endl;
521  VRMLFile<<" }"<<std::endl;
522 
523 
524  VRMLFile<<" ]"<<std::endl;
525  VRMLFile<<"}"<<std::endl;
526 }
527 
528 //Paints Conical representation of a perspective-viewport
529 void ThreeDOut::
530 VRMLOutViewPortPyramidal(ostream& VRMLFile,
531  double selectionRadius,
532  double r, double g, double b,
533  double angle,
534  double ratio,
535  double scale,
536  const std::string& name,
537  bool solid){
538  //MAIN VIEWPORT
539  if(solid){
540  PaintPyramid(VRMLFile, selectionRadius, r, g, b, 0.0, angle,
541  ratio, scale, name, true);
542  }
543  else{
544  PaintPyramid(VRMLFile, selectionRadius, r, g, b, 0.6, angle,
545  ratio, scale, name, true);
546  }
547 
548  //each sub-pyramid represents 45, 90, 135, ... grade angle-view
549  int iterations = (int)(angle/(3.1415926/4.0));
550 
551  for (int j = 0; j < iterations; j++){
552  PaintPyramid(VRMLFile,
553  selectionRadius,
554  r, g, b, 0.95,
555  (3.1415926/4.0)*(double)(j+1),
556  ratio,
557  scale,
558  name);
559  }
560 }
561 
562 //Paints Conical representation of a non-perspective-viewport
563 void ThreeDOut::
564 VRMLOutViewPortConical(ostream& VRMLFile,
565  double selectionRadius,
566  double r, double g, double b,
567  double angle,
568  double scale,
569  const std::string& name,
570  bool solid){
571  cout<<" trying to build conical camera rep:\n! ";
572  //MAIN VIEWPORT
573  if(solid){
574  PaintCone(VRMLFile, selectionRadius, r, g, b, 0.0, angle,
575  scale, name);
576  }
577  else{
578  PaintCone(VRMLFile, selectionRadius, r, g, b, 0.6, angle,
579  scale, name);
580  }
581 
582  //each sub-cone represents 45, 90, 135, ... grade angle-view
583  cout<<"angle "<<angle<<endl;
584  int iterations = (int)(angle/(3.1415926/4.0));
585  cout<<"iterations = "<<iterations<<endl;
586 
587  for (int j = 0; j < iterations; j++){
588  PaintCone(VRMLFile,
589  selectionRadius,
590  r, g, b, 0.95,
591  (3.1415926/4.0)*(double)(j+1),
592  scale,
593  name);
594  }
595 
596 }
597 
598 void ThreeDOut::
599 CoordinateSystem(ostream& VRMLFile,
600  double selectionRadius,
601  double r, double g, double b, double axeslength,
602  double scale,
603  const std::string& name)
604 {
605 
606  //axeslength *= selectionRadius;
607 
608  if (name.length()>0){
609  std::string mod_name = CorrectDefString_(name);
610  VRMLFile<<"DEF "<<mod_name << " ";
611  }
612 
613  VRMLFile<<"Transform { "<<std::endl;
614  if (axeslength<=0.0) axeslength = 1.0;
615  VRMLFile<<" scale "<<scale<<" "<<scale
616  <<" "<<scale<<" "<<endl;
617  VRMLFile<<" children [ "<<std::endl;
618 
619  VRMLFile<<" Shape { "<<std::endl;
620  /**
621  VRMLFile<<" geometry Box{ size "<<selectionRadius<<" "
622  <<selectionRadius<<" "<<selectionRadius<<" } "<<std::endl;
623  **/
624  VRMLFile<<" geometry Box{ size 0.1 0.1 0.1 } "<<std::endl;
625  VRMLFile<<" appearance Appearance {"<<std::endl;
626  VRMLFile<<" material Material {"<<std::endl;
627  VRMLFile<<" emissiveColor "<<r<<" "<<g<<" "<<b<<std::endl;
628  VRMLFile<<" }"<<std::endl;
629  VRMLFile<<" }"<<std::endl;
630  VRMLFile<<" }"<<std::endl;
631 
632  VRMLFile<<" DEF ArrowBody Transform { "<<std::endl;
633  VRMLFile<<" translation 0.5 0 0"<<std::endl;
634  VRMLFile<<" children ["<<std::endl;
635  VRMLFile<<" Shape { "<<std::endl;
636  VRMLFile<<" geometry Box{ size "<<1.0<<" "<<0.05<<" "<<0.05<<
637  " } "<<std::endl;
638  VRMLFile<<" appearance Appearance {"<<std::endl;
639  VRMLFile<<" material Material {"<<std::endl;
640  VRMLFile<<" emissiveColor "<<r<<" "<<g<<" "<<b<<std::endl;
641  VRMLFile<<" }"<<std::endl;
642  VRMLFile<<" }"<<std::endl;
643  VRMLFile<<" }"<<std::endl;
644  VRMLFile<<" ]"<<std::endl;
645  VRMLFile<<" }"<<std::endl;
646 
647  VRMLFile<<" Transform {"<<std::endl;
648  VRMLFile<<" rotation 0 1 0 -1.57"<<std::endl;
649  VRMLFile<<" children USE ArrowBody"<<std::endl;
650  VRMLFile<<" }"<<std::endl;
651 
652  VRMLFile<<" Transform {"<<std::endl;
653  VRMLFile<<" rotation 0 0 1 1.57"<<std::endl;
654  VRMLFile<<" children USE ArrowBody"<<std::endl;
655  VRMLFile<<" }"<<std::endl;
656 
657  double bRad = 0.05;
658  double hght = 0.20;
659 
660  VRMLFile<<" Transform {"<<std::endl;
661  VRMLFile<<" translation 1 0 0"<<std::endl;
662  VRMLFile<<" rotation 0 0 1 -1.57"<<std::endl;
663  VRMLFile<<" children ["<<std::endl;
664  VRMLFile<<" Shape {"<<std::endl;
665  VRMLFile<<" geometry Cone{ "<<std::endl;
666  VRMLFile<<" bottomRadius "<<bRad<<" "<<std::endl;
667  VRMLFile<<" height "<<hght<<std::endl;
668  VRMLFile<<" }"<<std::endl;
669  VRMLFile<<" appearance Appearance {"<<std::endl;
670  VRMLFile<<" material Material {"<<std::endl;
671  VRMLFile<<" emissiveColor 1.0 0.0 0.0"<<std::endl;
672  VRMLFile<<" }"<<std::endl;
673  VRMLFile<<" }"<<std::endl;
674  VRMLFile<<" }"<<std::endl;
675  VRMLFile<<" ]"<<std::endl;
676  VRMLFile<<" }"<<std::endl;
677 
678  VRMLFile<<" Transform {"<<std::endl;
679  VRMLFile<<" translation 0 1 0"<<std::endl;
680  VRMLFile<<" children ["<<std::endl;
681  VRMLFile<<" Shape {"<<std::endl;
682  VRMLFile<<" geometry Cone{ "<<std::endl;
683  VRMLFile<<" bottomRadius "<<bRad<<" "<<std::endl;
684  VRMLFile<<" height "<<hght<<std::endl;
685  VRMLFile<<" }"<<std::endl;
686  VRMLFile<<" appearance Appearance {"<<std::endl;
687  VRMLFile<<" material Material {"<<std::endl;
688  VRMLFile<<" emissiveColor 0.0 1.0 0.0"<<std::endl;
689  VRMLFile<<" }"<<std::endl;
690  VRMLFile<<" }"<<std::endl;
691  VRMLFile<<" }"<<std::endl;
692  VRMLFile<<" ]"<<std::endl;
693  VRMLFile<<" }"<<std::endl;
694 
695  VRMLFile<<" Transform {"<<std::endl;
696  VRMLFile<<" translation 0 0 1"<<std::endl;
697  VRMLFile<<" rotation 1 0 0 1.57"<<std::endl;
698  VRMLFile<<" children ["<<std::endl;
699  VRMLFile<<" Shape {"<<std::endl;
700  VRMLFile<<" geometry Cone{ "<<std::endl;
701  VRMLFile<<" bottomRadius "<<bRad<<" "<<std::endl;
702  VRMLFile<<" height "<<hght<<std::endl;
703  VRMLFile<<" }"<<std::endl;
704  VRMLFile<<" appearance Appearance {"<<std::endl;
705  VRMLFile<<" material Material {"<<std::endl;
706  VRMLFile<<" emissiveColor 0.0 0.0 1.0"<<std::endl;
707  VRMLFile<<" }"<<std::endl;
708  VRMLFile<<" }"<<std::endl;
709  VRMLFile<<" }"<<std::endl;
710  VRMLFile<<" ]"<<std::endl;
711  VRMLFile<<" }"<<std::endl;
712 
713  VRMLFile<<" ]"<<std::endl;
714  VRMLFile<<"}"<<std::endl;
715 }
716 
717 // ------------------------ 3d add data functions ------------------------
718 
720  const BIAS::RGBAuc &Color)
721 {
722  Point3DData D;
723  D.Color = Color;
724  D.Point = v;
726  return NextPointIndex_++;
727 }
728 
730  const BIAS::RGBAuc &Color)
731 {
732 #ifdef BIAS_DEBUG
733  if (!v.IsHomogenized()) BIASERR("Supplied unhomogenized point !");
734 #endif
735  Vector3<double> Center(v[0], v[1], v[2]);
736  return AddPoint(Center, Color);
737 }
738 
739 unsigned int ThreeDOut::AddText(const std::string& thetext,
740  const BIAS::Vector3<double> &position,
741  const BIAS::Quaternion<double> &direction,
742  const double& thesize,
743  const BIAS::RGBAuc &Color)
744 {
745  Text3DData D;
746  D.Color = Color;
747  D.Position = position;
748  D.Direction = direction;
749  D.Size = thesize;
750  D.Text=thetext;
752  return NextTextIndex_++;
753 }
754 
755 
756 unsigned int ThreeDOut::AddLine(const BIAS::Vector3<double> &Start,
757  const BIAS::Vector3<double> &End,
758  const BIAS::RGBAuc &Color)
759 {
760  Line3DData D;
761  D.Start = Start;
762  D.End = End;
763  D.Color = Color;
764 
766  return NextLineIndex_++;
767 }
768 
769 unsigned int ThreeDOut::AddLine(const BIAS::HomgPoint3D &Start,
770  const BIAS::HomgPoint3D &End,
771  const BIAS::RGBAuc &Color)
772 {
773 #ifdef BIAS_DEBUG
774  if (!Start.IsHomogenized()) BIASERR("Supplied unhomogenized start point !");
775  if (!End.IsHomogenized()) BIASERR("Supplied unhomogenized end point !");
776 #endif
777  Vector3<double> s(Start[0], Start[1], Start[2]);
778  Vector3<double> e(End[0], End[1], End[2]);
779  return AddLine(s, e, Color);
780 }
781 
783  const BIAS::Vector3<double> &C,
784  const BIAS::RGBAuc &Color,
785  const double& dConfidenceRegionScale,
786  const bool CamEllipsoid)
787 {
788  Ellipsoid3DData Data;
790  RMatrix VInv(MatrixIdentity);
791  Vector3<double> S;
792  int resPCA = cov.GetPCA(S, VT);
793  if (resPCA == 0 && BIAS::Greater(VT.GetRow(0).NormL2(), 0.0, 1e-8) &&
794  BIAS::Greater(VT.GetRow(1).NormL2(), 0.0, 1e-8) &&
795  BIAS::Greater(VT.GetRow(2).NormL2(), 0.0, 1e-8)) {
796  // assure that PCA results in a valid rotation matrix
797  VInv = VT.Transpose();
798  } else if (!VT.IsZero(1e-8)) {
799  // show warning only if we don't have the zero matrix
800  BIASWARN("Degenerated rotation matrix VT computed from covariance matrix "
801  "via PCA! Using default covariance ellipsoid alignment!" << endl
802  << "- degenerated matrix VT = " << VT);
803  }
804  VInv.GetRotationAxisAngle(Data.RotAxis, Data.dAngle);
805  Data.s0 = sqrt(S[0]) * dConfidenceRegionScale;
806  Data.s1 = sqrt(S[1]) * dConfidenceRegionScale;
807  Data.s2 = sqrt(S[2]) * dConfidenceRegionScale;
808  Data.C = C;
809  Data.Color = Color;
810  // @todo Assure that y and z can't be exchanged by SVD accidently!
811 
812  int index = 0;
813  if (CamEllipsoid){
815  index = NextCamEllipsoidIndex_++;
816  } else {
818  index = NextEllipsoidIndex_++;
819  }
820  return index;
821 }
822 
824  const BIAS::HomgPoint3D &C,
825  const BIAS::RGBAuc &Color,
826  const double &dConfidenceRegionScale,
827  const bool CamEllipsoid)
828 {
829 #ifdef BIAS_DEBUG
830  if (!C.IsHomogenized())
831  BIASERR("Supplied unhomogenized point!");
832 #endif
833  Vector3<double> Center(C[0], C[1], C[2]);
834  return AddEllipsoid(cov, Center, Color, dConfidenceRegionScale, CamEllipsoid);
835 }
836 
838  const RGBAuc& colour,
839  const double size,
840  const Vector3<double>& translation,
841  const bool wireframe)
842 {
843  // compute corners of plane
844  std::vector< Vector3<double> > corners;
845  ThreeDOut::ComputePlaneCorners(plane, size, corners);
846 
847  // translate plane points by given vector
848  for (int i = 0; i < 4; i++)
849  corners[i] += translation;
850 
851  // finally create visualisation
852  if (wireframe)
853  {
854  for (int i = 0; i < 3; i++)
855  for (int j = i + 1; j < 4; j++)
856  AddLine(corners[i], corners[j], colour);
857  }
858  else
859  {
860  const Vector3<double>& normal = plane.GetNormalVector();
861  std::vector< Vector3<double> > vertexNormals(4);
862  std::vector< Vector4<unsigned char> > vertexColors(4);
863  for (int i = 0; i < 4; i++) {
864  vertexNormals[i] = normal;
865  vertexColors[i] = colour;
866  }
867  std::vector< Vector<int> > triangleIndices(2);
868  triangleIndices[0] = Vector<int>(Vector3<int>(0, 1, 2));
869  triangleIndices[1] = Vector<int>(Vector3<int>(2, 1, 3));
870  BIAS::TriangleMesh quad;
871  quad.SetMesh(corners, vertexNormals, vertexColors, triangleIndices);
872  AddTriangleMesh(quad);
873  }
874 }
875 
876 void ThreeDOut::
877 ComputePlaneCorners(const HomgPlane3D& plane, const double size,
878  std::vector< Vector3<double> >& corners)
879 {
880  // some constants for better readability
881  const Vector3<double>& normal = plane.GetNormalVector();
882  const double halfSize = size / 2.0;
883 
884  // find coordinate axis that is closest to 90 degrees to the plane normal
885  // and create four points in the plane definded by the coordinate axis as
886  // normal. this step is necessary for the cross product below
887  const double optimalAngle = M_PI / 2.0; // = 90 degrees
888 
889  const Vector3<double> xAxis(1.0, 0.0, 0.0);
890  const Vector3<double> yAxis(0.0, 1.0, 0.0);
891  const Vector3<double> zAxis(0.0, 0.0, 1.0);
892 
893  const double angleX = acos(xAxis.ScalarProduct(normal));
894  const double angleY = acos(yAxis.ScalarProduct(normal));
895  const double angleZ = acos(zAxis.ScalarProduct(normal));
896 
897  const double diffAngleX = fabs(optimalAngle - angleX);
898  const double diffAngleY = fabs(optimalAngle - angleY);
899  const double diffAngleZ = fabs(optimalAngle - angleZ);
900 
901  Vector3<double> axis;
902  double angle;
903  Vector3<double> p1;
904  Vector3<double> p2;
905  Vector3<double> p3;
906  Vector3<double> p4;
907 
908  if (diffAngleX <= diffAngleY && diffAngleX <= diffAngleZ) { // choose x axis
909  angle = angleX;
910  axis = xAxis;
911  p1[0] = 0.0; p1[1] = -halfSize; p1[2] = halfSize;
912  p2[0] = 0.0; p2[1] = halfSize; p2[2] = halfSize;
913  p3[0] = 0.0; p3[1] = -halfSize; p3[2] = -halfSize;
914  p4[0] = 0.0; p4[1] = halfSize; p4[2] = -halfSize;
915  }
916  else if (diffAngleY <= diffAngleZ) { // choose y axis
917  angle = angleY;
918  axis = yAxis;
919  p1[0] = -halfSize; p1[1] = 0.0; p1[2] = halfSize;
920  p2[0] = halfSize; p2[1] = 0.0; p2[2] = halfSize;
921  p3[0] = -halfSize; p3[1] = 0.0; p3[2] = -halfSize;
922  p4[0] = halfSize; p4[1] = 0.0; p4[2] = -halfSize;
923  }
924  else { // choose z axis
925  angle = angleZ;
926  axis = zAxis;
927  p1[0] = -halfSize; p1[1] = halfSize; p1[2] = 0.0;
928  p2[0] = halfSize; p2[1] = halfSize; p2[2] = 0.0;
929  p3[0] = -halfSize; p3[1] = -halfSize; p3[2] = 0.0;
930  p4[0] = halfSize; p4[1] = -halfSize; p4[2] = 0.0;
931  }
932 
933  // compute rotation so that normal points into direction of chosen axis and
934  // apply the inverse rotation on points
935  const Vector3<double> rotationAxis = axis.CrossProduct(normal);
936 
937  const RMatrix rotation(rotationAxis, -angle);
938  RMatrix invRotation;
939  rotation.GetInverse(invRotation);
940 
941  p1 = invRotation * p1;
942  p2 = invRotation * p2;
943  p3 = invRotation * p3;
944  p4 = invRotation * p4;
945 
946  // move points by the distance between plane and origin, they now lie on plane
947  const double distance = -plane[3];
948  const Vector3<double> scaledNormal = distance * normal;
949 
950  p1 += scaledNormal;
951  p2 += scaledNormal;
952  p3 += scaledNormal;
953  p4 += scaledNormal;
954 
955  // return vertices
956  corners.resize(4);
957  corners[0] = p1;
958  corners[1] = p2;
959  corners[2] = p3;
960  corners[3] = p4;
961 }
962 
963 unsigned int ThreeDOut::AddImage(const Vector3<double>& UL,
964  const Vector3<double>& UR,
965  const Vector3<double>& LL,
966  const Vector3<double>& LR,
967  unsigned int Width, unsigned int Height,
968  unsigned char* pData, unsigned int channels,
969  const std::string& name,
970  bool billboard)
971 {
972 #ifdef BIAS_DEBUG
973  if (Width>UINT_MAX/2) {
974  BIASERR("Width "<<Width<<" is out of bounds !");
975  BIASABORT;
976  }
977  if (Height>UINT_MAX/2) {
978  BIASERR("Height "<<Height<<" is out of bounds !");
979  BIASABORT;
980  }
981  if ((channels!=1)&&(channels!=3)) {
982  BIASERR("Unknown channel count:"<<channels);
983  BIASABORT;
984  }
985 #endif
986  // find min w with w>=width and w=2^n, needed by opengl
987  unsigned int w(1), h(1);
988  while (w<Width) w<<=1;
989  while (h<Height) h<<=1;
990 
991  Image3DData &ImagePatch = mapImages_[NextImageIndex_];
992  if (!ImagePatch.ImageData.IsEmpty()) ImagePatch.ImageData.Release();
993  ImagePatch.ImageData.Init(w, h, channels);
994  ImagePatch.ImageData.SetROI(0, 0, Width, Height);
995  unsigned char** pColRow = ImagePatch.ImageData.GetImageDataArray();
996  unsigned char* pOrig = pData;
997  for (unsigned int i=0; i<Height; i++) {
998  memcpy(pColRow[i], pOrig, channels*Width*sizeof(unsigned char));
999  pOrig += channels*Width;
1000  }
1001  ImagePatch.UL = UL;
1002  ImagePatch.UR = UR;
1003  ImagePatch.LL = LL;
1004  ImagePatch.LR = LR;
1005  ImagePatch.name = CorrectDefString_(name);
1006  ImagePatch.BillBoard = billboard;
1007  return NextImageIndex_++;
1008 }
1009 
1010 
1011 // wrapper
1013  const unsigned int& width,
1014  const unsigned int& height,
1015  const BIAS::RGBAuc &Color,
1016  const double &dScale,
1017  const string& name)
1018 {
1019  PMatrix P( M );
1020  return AddPMatrix(P,
1021  width,
1022  height,
1023  Color,
1024  dScale,
1025  name);
1026 }
1027 
1028 
1030  const unsigned int& width,
1031  const unsigned int& height,
1032  const BIAS::RGBAuc &Color,
1033  const double &dScale,
1034  const string& name)
1035 {
1036  Vector3<double> d,A;
1037  HomgPoint2D ThisCorner(0.0, 0.0, 0.0);
1038  Matrix3x3<double> R, iKRt;
1039  KMatrix K;
1040  PMatrix3DData pd;
1041  pd.name = CorrectDefString_(name);
1042  pd.Color=Color;
1043  P.GetK(K);
1044  P.GetR(R);
1045  P.GetC(pd.C);
1046  P.GetA(A);
1047  int ires = (K * R.Transpose()).GetInverse(iKRt);
1048  if (ires!=0) BIASERR("error computing iKRt.");
1049  BIASDOUT(D_3DOUT_PDECOMP, "Decomposing P="<<P<<" into K="<<K<<" R="
1050  <<R<<" C="<<pd.C<<" A="<<A);
1051  for (unsigned int i=0; i<5; i++){
1052  switch (i) {
1053  case 0:
1054  ThisCorner[0] = 0.0;
1055  ThisCorner[1] = 0.0;
1056  break;
1057  case 1:
1058  ThisCorner[0] = width-1;
1059  ThisCorner[1] = 0.0;
1060  break;
1061  case 2:
1062  ThisCorner[0] = width-1;
1063  ThisCorner[1] = height-1;
1064  break;
1065  case 3:
1066  ThisCorner[0] = 0.0;
1067  ThisCorner[1] = height-1;
1068  break;
1069  case 4:
1070  ThisCorner[0] = K[0][2];
1071  ThisCorner[1] = K[1][2];
1072  break;
1073  }
1074  ThisCorner[2] = 1.0;
1075  // get backprojection ray d from camera center to image point ThisCorner
1076  iKRt.Mult(ThisCorner,d);
1077 
1078  // normalize projection of d on A to length 1
1079  d *= dScale / (d.ScalarProduct(A));
1080 
1081  // attach ray d to camera center to construct a 3d point
1082  d += pd.C;
1083  switch (i) {
1084  case 0: pd.UL=d; break;
1085  case 1: pd.UR=d; break;
1086  case 2: pd.LR=d; break;
1087  case 3: pd.LL=d; break;
1088  case 4: pd.PP=d; break;
1089  }
1090  } // for (unsigned int i=0; i<4; i++){
1091  BIASDOUT(D_3DOUT_PDECOMP, "Created points ul="<<pd.UL<<" ur="<<pd.UR<<" lr="
1092  <<pd.LR<<" ll="<<pd.LL<<" and principle point at "<<pd.PP);
1093  pd.Up[0] = R[0][1];
1094  pd.Up[1] = R[1][1];
1095  pd.Up[2] = R[2][1];
1096  pd.Up *= -dScale /2.0;
1097  mapPMatrices_[NextPIndex_] = pd;
1098 
1099 
1100  return NextPIndex_++;
1101 }
1102 
1103 unsigned int ThreeDOut::
1105  const std::string& name,
1106  const std::string& textureOutputName,
1107  bool writeOutTexture,
1108  bool calcNormals)
1109 {
1111  Data.name = CorrectDefString_(name);
1112  Data.textureName = textureOutputName;
1113  Data.writeOutTexture = writeOutTexture;
1114 
1115  //use texture
1116  mesh.GetTexture(Data.texture);
1117  Data.useTexture = Data.texture.GetWidth() > 0;
1118 
1119  //use colors per vertex instead of texture
1120  mesh.GetVertexColors(Data.vertexColorSet);
1121  Data.useColoredVertices = Data.vertexColorSet.size() > 0;
1122 
1123  //get vertices, texture coordinates and face indices
1124  mesh.GetVertices(Data.vertexSet);
1125  mesh.GetTexCoords(Data.texCoordSet);
1126  mesh.GetTriangleIndices(Data.faceIndices);
1127  Data.useNormals = false;
1128 
1129  //assign sizes for arrays (3 per vertex, 4 per color, 2 per tex coordinate)
1130  Data.VASize = 3 * Data.vertexSet.size();
1131  Data.CASize = 4 * Data.vertexSet.size();
1132 
1133  if(Data.NormalArray != NULL) delete [] Data.NormalArray;
1134 
1135 #ifdef BIAS_HAVE_OPENGL
1136 
1137  Data.TASize = Data.texCoordSet.size() * 2;
1138 
1139  if(Data.VertArray != NULL) delete[] Data.VertArray;
1140  if(Data.ColorArray != NULL) delete[] Data.ColorArray;
1141  if(Data.TextureCoordArray != NULL) delete[] Data.TextureCoordArray;
1142 
1143  Data.VertArray = new GLfloat[Data.VASize];
1144  Data.TextureCoordArray = new GLfloat[Data.TASize];
1145  Data.ColorArray = new GLubyte[Data.CASize];
1146  for (int i=0; i<Data.CASize; i++)
1147  Data.ColorArray[i] = 255; // use white vertices by default
1148 
1149  //assign color values
1150  if(Data.useColoredVertices)
1151  {
1152  //go over all vertices and assign colors for each vertex
1153  BIASASSERT(Data.vertexSet.size() == Data.vertexColorSet.size());
1154  for (unsigned int i=0; i<Data.vertexColorSet.size(); i++) {
1155  Vector4<unsigned char> color = Data.vertexColorSet[i];
1156  for (unsigned int j=0; j<4; j++)
1157  Data.ColorArray[i*4+j] = color[j];
1158  }
1159  }
1160 #endif // BIAS_HAVE_OPENGL
1161 
1162  //take original normals from triangle mesh or recompute them or do nothing
1163  vector<Vector3<double> > normals;
1164  mesh.GetNormals(normals);
1165  if (!normals.empty() && !calcNormals) // && !Data.useTexture)
1166  {
1167  //use normals from mesh
1168 #ifdef BIAS_HAVE_OPENGL
1169  Data.NormalArray = new GLfloat[Data.VASize];
1170 #else
1171  Data.NormalArray = new float[Data.VASize];
1172 #endif
1173  //set all values to zero
1174  for (int i=0; i<Data.VASize; i++)
1175  Data.NormalArray[i] = 0;
1176  // copy normals
1177  BIASASSERT(normals.size() == Data.vertexSet.size());
1178  for (size_t normalsCnt = 0; normalsCnt < normals.size(); ++normalsCnt) {
1179  Data.NormalArray[3 * normalsCnt ] = normals[normalsCnt][0];
1180  Data.NormalArray[3 * normalsCnt + 1] = normals[normalsCnt][1];
1181  Data.NormalArray[3 * normalsCnt + 2] = normals[normalsCnt][2];
1182  }
1183  Data.useNormals = true;
1184  }
1185  else if (calcNormals) { // && !Data.useTexture) {
1186  //recompute normals
1187 #ifdef BIAS_HAVE_OPENGL
1188  Data.NormalArray = new GLfloat[Data.VASize];
1189 #else
1190  Data.NormalArray = new float[Data.VASize];
1191 #endif
1192  //set all values to zero
1193  for (int i=0; i<Data.VASize; i++)
1194  Data.NormalArray[i] = 0;
1195  //compute normals
1196  Vector3<double> v1,v2,v3;
1197  // run over all triangles and assign normal to vertex
1198  for (unsigned int i=0; i<Data.faceIndices.size(); i++) {
1199  //BIASASSERT(Data.faceIndices[i][0]<Data.vertexSet.size());
1200  //BIASASSERT(Data.faceIndices[i][1]<Data.vertexSet.size());
1201  //BIASASSERT(Data.faceIndices[i][2]<Data.vertexSet.size());
1202  v1 = Data.vertexSet[Data.faceIndices[i][0]];
1203  v2 = Data.vertexSet[Data.faceIndices[i][1]] - v1;
1204  v3 = Data.vertexSet[Data.faceIndices[i][2]] - v1;
1205  double norm = v2.NormL2();
1206  if (norm > 0.0) v2 /= norm;
1207  norm = v3.NormL2();
1208  if (norm > 0.0) v3 /= norm;
1209  // compute normal of two triangle edges
1210  v1 = v2.CrossProduct(v3);
1211 
1212  norm = v1.NormL2();
1213  if (norm > 0.0) v1 /= norm;
1214  for (unsigned int k=0; k<3; k++)
1215  Data.NormalArray[Data.faceIndices[i][0]*3+k] += v1[k];
1216  for (unsigned int k=0; k<3; k++)
1217  Data.NormalArray[Data.faceIndices[i][1]*3+k] += v1[k];
1218  for (unsigned int k=0; k<3; k++)
1219  Data.NormalArray[Data.faceIndices[i][2]*3+k] += v1[k];
1220  }
1221 
1222  for (unsigned int i=0; i<Data.vertexSet.size(); i++) {
1223  double norm = Data.NormalArray[3*i]* Data.NormalArray[3*i] +
1224  Data.NormalArray[3*i+1]* Data.NormalArray[3*i+1] +
1225  Data.NormalArray[3*i+2]* Data.NormalArray[3*i+2];
1226  if (!BIAS::Equal(norm, 1.0)) {
1227  if (norm>0.0) {
1228  norm = 1.0 / sqrt(norm);
1229  Data.NormalArray[3*i] *= norm;
1230  Data.NormalArray[3*i+1] *= norm;
1231  Data.NormalArray[3*i+2] *= norm;
1232  } else {
1233  // no normal, the vertex is not found in ANY triangle, set (0,0,1) normal
1234  Data.NormalArray[3*i] = 0;
1235  Data.NormalArray[3*i+1] = 0;
1236  Data.NormalArray[3*i+2] = 1;
1237  }
1238  } else {
1239  BIASERR("Computed normal has norm " << norm << "!");
1240  }
1241  }
1242  Data.useNormals = true;
1243  }
1244 
1245 #ifdef BIAS_HAVE_OPENGL
1246  //fill VertArray via pCurVertex
1247  GLfloat *pCurVertex = Data.VertArray;
1248 #endif
1249  //calculate bounding box
1250  Data.bbmin[0] = Data.bbmin[1] = Data.bbmin[2] = DBL_MAX;
1251  Data.bbmax[0] = Data.bbmax[1] = Data.bbmax[2] = -DBL_MAX;
1252 
1253  for (unsigned int v =0; v<Data.vertexSet.size(); v++) {
1254  const Vector3<double> &point = Data.vertexSet[v];
1255  if (Data.bbmin[0] > point[0]) Data.bbmin[0] = point[0];
1256  if (Data.bbmax[0] < point[0]) Data.bbmax[0] = point[0];
1257 
1258  if (Data.bbmin[1] > point[1]) Data.bbmin[1] = point[1];
1259  if (Data.bbmax[1] < point[1]) Data.bbmax[1] = point[1];
1260 
1261  if (Data.bbmin[2] > point[2]) Data.bbmin[2] = point[2];
1262  if (Data.bbmax[2] < point[2]) Data.bbmax[2] = point[2];
1263 
1264 #ifdef BIAS_HAVE_OPENGL
1265  *(pCurVertex++) = (float)point[0];
1266  *(pCurVertex++) = (float)point[1];
1267  *(pCurVertex++) = (float)point[2];
1268 #endif
1269  }
1270 
1271 #ifdef BIAS_HAVE_OPENGL
1272  if (Data.useTexture) {
1273  unsigned int wold,hold,wnew,hnew;
1274  wold=Data.texture.GetWidth();
1275  hold=Data.texture.GetHeight();
1276  wnew=ImageBase::PowerOfTwoSize(wold);
1277  hnew=ImageBase::PowerOfTwoSize(hold);
1278  float sx=float(wold)/float(wnew);
1279  float sy=float(hold)/float(hnew);
1280  GLfloat *pCurTexture = Data.TextureCoordArray;
1281  for (unsigned int t =0; t<Data.texCoordSet.size(); t++) {
1282  const Vector2<float>& texCoord = Data.texCoordSet[t];
1283  *(pCurTexture++) = texCoord[0] * sx;
1284  *(pCurTexture++) = texCoord[1] * sy;
1285  }
1286  }
1287 
1288  //generate faces and index counts:
1289  Data.NumFacets = Data.faceIndices.size();
1290  if(Data.NumFacets>0) {
1291  Data.facetIndicesCountArray = new GLsizei[Data.NumFacets];
1292  Data.facetArray = new GLuint*[Data.NumFacets];
1293  for(int i=0; i<Data.NumFacets; i++) {
1294  Data.facetIndicesCountArray[i]=Data.faceIndices[i].dim();
1295  if(Data.facetIndicesCountArray[i]>0)
1296  Data.facetArray[i] = new GLuint[Data.facetIndicesCountArray[i]];
1297  for(GLsizei j=0; j<Data.facetIndicesCountArray[i]; j++) {
1298  Data.facetArray[i][j] = Data.faceIndices[i][j];
1299  }
1300  }
1301  }
1302 #endif // BIAS_HAVE_OPENGL
1303 
1304  return NextIndexedFaceSetIndex_++;
1305 }
1306 
1307 unsigned int ThreeDOut::
1309  const RGBAuc& colorSelection,
1310  const double radius,
1311  const double scale,
1312  const std::string& identifier,
1313  const int camera_type)
1314 {
1315 
1316  Projection3DData data;
1317  unsigned int i=0;
1318  while(i<p.Size()){
1320  //This is the initial Pose
1321  //BIAS::ProjectionParametersBase *P1=NULL;
1322  BIAS::Vector3<double> C,C1;
1323  if(i==0){ // this is the camera the others refer to
1324  Q1 = Q = p.GetQ(i);
1325  C1 = C = p.GetC(i);
1326  //P1 = p.GetParameters()->Clone();
1327  }//successive cameras are relative to the first in the rig
1328  else{
1329  Pose absPose = p.GetParameters()->GetPose();
1330  Pose relPose;
1332  relPose);
1333 
1334  Q = relPose.GetQ();
1335  C = relPose.GetC();
1336  AddLine(C1, C, colorSelection);
1337  }
1338 
1339  RMatrix R;
1340  R.SetFromQuaternion(Q);
1341  data.C = C;
1342  data.Set(C, R, scale);
1343 
1344  //data.Set(*p.GetParameters(i), scale);
1345  data.radiusSelection = radius;
1346  data.ColorOfSelection = colorSelection;
1347  data.identifier = identifier;
1348  data.scale = scale;
1349  data.type = camera_type;
1350 
1351  //data.angle = 0.0;
1352 
1353  /** VIEWPORT PART, DUE TO BE IMPLEMENTED
1354 
1355  unsigned int wid = 0;
1356  unsigned int hei = 0;
1357 
1358  //calculate the angle
1359  if(camera_type != -1){
1360  //calculate the size of an image
1361  p.GetParameters()->GetImageSize(wid, hei);
1362  HomgPoint2D p1_2D, p2_2D;
1363 
1364  cout << "wid: " << wid << ", hei: " << hei << endl;
1365 
1366  if(hei==0 && wid==0){
1367  cout << "Unable to calculate size of an img from projection..." << endl;
1368  }
1369  else{
1370  if(camera_type == 0){
1371  p1_2D[0] = 0; p1_2D[1] = rint(hei/2);
1372  p2_2D[0] = rint(wid/2); p2_2D[1] = rint(hei/2);
1373  }
1374  if(camera_type == 1){
1375  //we take a point (wid/4, hei/2) and (wid/2, hei/2), 'cause
1376  //the angle could be more than 180 degrees
1377  p1_2D[0] = rint(wid/4); p1_2D[1] = rint(hei/2);
1378  p2_2D[0] = rint(wid/2); p2_2D[1] = rint(hei/2);
1379  }
1380  HomgPoint3D p1_3D = p.GetParameters()->UnProjectToPoint(p1_2D, 1.0);
1381  HomgPoint3D p2_3D = p.GetParameters()->UnProjectToPoint(p2_2D, 1.0);
1382 
1383  double dx = p1_3D[0]-p2_3D[0];
1384  double dy = p1_3D[1]-p2_3D[1];
1385  double dz = p1_3D[2]-p2_3D[2];
1386 
1387  //half of the distance between two 1.0-lentgh-rays from the principal point
1388  //it's equal to a sin of an alpha/2 for perspective and aplpha/4 for
1389  //non-perspective cameras, whereas alpha is an cutoffangle of the camera.
1390  double dist_div_2 = sqrt(dx*dx+dy*dy+dz*dz)/2;
1391 
1392  if(camera_type == 0)
1393  data.angle = 2*asin(dist_div_2);
1394  if(camera_type == 1)
1395  data.angle = 4*asin(dist_div_2);
1396  }
1397  }
1398  **/
1399  i++;
1401  }
1402 
1403  return NextProjection3DIndex_;
1404 }
1405 
1406 unsigned int ThreeDOut::
1408  const RGBAuc& colorSelection,
1409  const double radius,
1410  const double scale,
1411  const int camera_type)
1412 {
1413  Projection3DData data;
1414  data.Set(p, scale);
1415  data.radiusSelection = radius;
1416  data.ColorOfSelection = colorSelection;
1417  data.type = camera_type;
1418 
1420  return NextProjection3DIndex_++;
1421 }
1422 
1423 
1424 // -------------------------- 3D data update functions -----------------------
1425 
1426 
1427 void ThreeDOut::UpdatePoint(const unsigned int& PointIndex,
1428  const BIAS::Vector3<double> &v,
1429  const BIAS::RGBAuc &Color)
1430 {
1431 #ifdef BIAS_DEBUG
1432  ASSERT_MAP_ELEMENT(mapPoints_, PointIndex);
1433 #endif
1434  Point3DData& D = mapPoints_[PointIndex];
1435  D.Point = v;
1436  D.Color = Color;
1437 }
1438 
1439 void ThreeDOut::UpdatePointColor(const unsigned int& PointIndex,
1440  const BIAS::RGBAuc &Color)
1441 {
1442  mapPoints_[PointIndex].Color = Color;
1443 }
1444 
1445 void ThreeDOut::UpdatePoint(const unsigned int& PointIndex,
1446  const BIAS::HomgPoint3D &v,
1447  const BIAS::RGBAuc &Color)
1448 {
1449 #ifdef BIAS_DEBUG
1450  if (!v.IsHomogenized()) BIASERR("Supplied unhomogenized point !");
1451 #endif
1452  Vector3<double> V(v[0], v[1], v[2]);
1453  UpdatePoint(PointIndex, V, Color);
1454 }
1455 
1456 void ThreeDOut::UpdatePMatrix(const unsigned int& PIndex,
1457  BIAS::PMatrix &P,
1458  const unsigned int& width,
1459  const unsigned int& height,
1460  const BIAS::RGBAuc &Color,
1461  const double& dScale)
1462 {
1463  unsigned int backupnextpindex = NextPIndex_;
1464  NextPIndex_ = PIndex;
1465  AddPMatrix(P, width, height, Color, dScale);
1466  NextPIndex_ = backupnextpindex;
1467 }
1468 
1469 void ThreeDOut::UpdatePMatrixColor(const unsigned int& PIndex,
1470  const BIAS::RGBAuc &Color)
1471 {
1472  mapPMatrices_[PIndex].Color = Color;
1473 }
1474 
1475 void ThreeDOut::UpdateLine(const unsigned int& LineIndex,
1476  const BIAS::Vector3<double> &Start,
1477  const BIAS::Vector3<double> &End,
1478  const BIAS::RGBAuc &Color)
1479 {
1480 #ifdef BIAS_DEBUG
1481  ASSERT_MAP_ELEMENT(mapLines_, LineIndex);
1482 #endif
1483  Line3DData& D = mapLines_[LineIndex];
1484  D.Start = Start;
1485  D.End = End;
1486  D.Color = Color;
1487 }
1488 
1489 void ThreeDOut::UpdateLine(const unsigned int& LineIndex,
1490  const BIAS::HomgPoint3D &Start,
1491  const BIAS::HomgPoint3D &End,
1492  const BIAS::RGBAuc &Color)
1493 {
1494 #ifdef BIAS_DEBUG
1495  if (!Start.IsHomogenized()) BIASERR("Supplied unhomogenized start point !");
1496  if (!End.IsHomogenized()) BIASERR("Supplied unhomogenized end point !");
1497 #endif
1498  Vector3<double> s(Start[0], Start[1], Start[2]);
1499  Vector3<double> e(End[0], End[1], End[2]);
1500  UpdateLine(LineIndex, s, e, Color);
1501 }
1502 
1503 
1504 void ThreeDOut::UpdateEllipsoid(const unsigned int& EIndex,
1505  BIAS::CovMatrix3x3 &cov,
1507  const BIAS::RGBAuc &Color,
1508  const double &dConfidenceRegionScale)
1509 {
1510 #ifdef BIAS_DEBUG
1511  ASSERT_MAP_ELEMENT(mapEllipsoids_, EIndex);
1512 #endif
1513  Ellipsoid3DData& Data = mapEllipsoids_[EIndex];
1515  RMatrix VInv(MatrixIdentity);
1516  Vector3<double> S;
1517  int resPCA = cov.GetPCA(S, VT);
1518  if (resPCA == 0 && BIAS::Greater(VT.GetRow(0).NormL2(), 0.0, 1e-8) &&
1519  BIAS::Greater(VT.GetRow(1).NormL2(), 0.0, 1e-8) &&
1520  BIAS::Greater(VT.GetRow(2).NormL2(), 0.0, 1e-8)) {
1521  // assure that PCA results in a valid rotation matrix
1522  VInv = VT.Transpose();
1523  } else if (!VT.IsZero(1e-8)) {
1524  // show warning only if we don't have the zero matrix
1525  BIASWARN("Degenerated rotation matrix VT computed from covariance matrix "
1526  "via PCA! Using default covariance ellipsoid alignment!" << endl
1527  << "- degenerated matrix VT = " << VT);
1528  }
1529  VInv.GetRotationAxisAngle(Data.RotAxis, Data.dAngle);
1530  Data.s0 = sqrt(S[0]) * dConfidenceRegionScale;
1531  Data.s1 = sqrt(S[1]) * dConfidenceRegionScale;
1532  Data.s2 = sqrt(S[2]) * dConfidenceRegionScale;
1533  Data.C = C;
1534  Data.Color = Color;
1535 }
1536 
1537 void ThreeDOut::UpdateEllipsoid(const unsigned int& EIndex,
1538  BIAS::CovMatrix3x3 &cov,
1539  BIAS::HomgPoint3D &C,
1540  const BIAS::RGBAuc &Color,
1541  const double& dConfidenceRegionScale)
1542 {
1543 #ifdef BIAS_DEBUG
1544  if (!C.IsHomogenized()) BIASERR("Supplied unhomogenized point !");
1545 #endif
1546  Vector3<double> Center(C[0], C[1], C[2]);
1547  UpdateEllipsoid(EIndex, cov, Center, Color, dConfidenceRegionScale);
1548 }
1549 
1550 void ThreeDOut::RemovePoint(const unsigned int& PointIndex)
1551 {
1552  ASSERT_MAP_ELEMENT(mapPoints_, PointIndex);
1553  // uncontrolled erase leads to crash in case of non existing PointIndex:
1554  mapPoints_.erase(mapPoints_.find(PointIndex));
1555 }
1556 
1558 {
1559  mapPoints_.clear();
1560 }
1561 
1562 void ThreeDOut::RemoveLine(const unsigned int& LineIndex)
1563 {
1564  ASSERT_MAP_ELEMENT(mapLines_, LineIndex);
1565  // uncontrolled erase leads to crash in case of non existing PointIndex:
1566  mapLines_.erase(mapLines_.find(LineIndex));
1567 }
1568 
1570 {
1571  mapLines_.clear();
1572 }
1573 
1574 void ThreeDOut::RemoveEllipsoid(const unsigned int& EIndex)
1575 {
1576  ASSERT_MAP_ELEMENT(mapEllipsoids_, EIndex);
1577  // uncontrolled erase leads to crash in case of non existing PointIndex:
1578  mapEllipsoids_.erase(mapEllipsoids_.find(EIndex));
1579 }
1580 
1582  mapEllipsoids_.clear();
1583 }
1584 
1586  mapCamEllipsoids_.clear();
1587 }
1588 
1589 void ThreeDOut::RemoveImage(const unsigned int& EIndex)
1590 {
1591  ASSERT_MAP_ELEMENT(mapImages_, EIndex);
1592  // uncontrolled erase leads to crash in case of non existing PointIndex:
1593  mapImages_.erase(mapImages_.find(EIndex));
1594 }
1595 
1597 {
1598  mapIndexedFaceSet_.clear();
1600 }
1601 
1603 {
1604  mapImages_.clear();
1605 }
1606 
1608 {
1609  mapPMatrices_.clear();
1610 }
1611 
1613 {
1614  map<unsigned int, PMatrix3DData>::iterator it = mapPMatrices_.find(index);
1615  if (it!=mapPMatrices_.end()) {
1616  mapPMatrices_.erase(it);
1617  } else {
1618  BIASERR("Tried to erase non-existing pmatrix:"<<index);
1619  }
1620 }
1621 
1622 void ThreeDOut::VRMLOutWCS(ostream& VRMLFile) {
1623  if (Params_.WCSAxesLength>0.0)
1624  CoordinateSystem(VRMLFile, (float)(0.1*Params_.WCSAxesLength), 1.0f, 1.0f, 1.0f, 1.0,
1625  (float)Params_.WCSAxesLength, "WorldCoordinateSystem");
1626 }
1627 
1628 // ---------------------------- OPENGL functions ----------------------------
1629 #ifdef BIAS_HAVE_OPENGL
1630 
1632 
1633  StatekeeperGL state;
1634 
1635  if (Params_.WCSAxesLength<=0.0) return;
1636 
1637  // stolen from geometrygl
1638 
1639  glDisable(GL_TEXTURE_2D);
1640  glDisable(GL_LIGHTING);
1641 
1642  float linewidth = 0.0;
1643  glGetFloatv(GL_LINE_WIDTH,&linewidth);
1644 
1645  if ((linewidth>=1.0) && (linewidth<32.0))
1646  glLineWidth((GLfloat)linewidth);
1647  else
1648  glLineWidth((GLfloat)1.0);
1649 
1650 #if defined(BIAS_HAVE_OPENGL) && defined(BIAS_HAVE_FONTGL)
1651  BIAS::DrawTextGL drawer;
1652  bool drawerInited = false;
1653  if (drawer.InitFont(NULL) == 0){
1654  drawerInited = true;
1655  }
1656 #endif
1657  // X-axis:
1658  glColor4d(1.0, 0.0, 0.0, 0.0); // r
1659  glBegin(GL_LINES);
1660  glVertex3d(0.0, 0.0, 0.0);
1661  glVertex3d(Params_.WCSAxesLength, 0.0, 0.0);
1662  glEnd();
1663 #if defined(BIAS_HAVE_OPENGL) && defined(BIAS_HAVE_FONTGL)
1664  if(drawerInited)
1665  drawer.Print3D("X",Params_.WCSAxesLength,0,0);
1666 #endif
1667 
1668  // Y-axis:
1669  glColor4d(0.0, 1.0, 0.0, 0.0); // g
1670  glBegin(GL_LINES);
1671  glVertex3d(0.0, 0.0, 0.0);
1672  glVertex3d(0.0, Params_.WCSAxesLength, 0.0);
1673  glEnd();
1674 #if defined(BIAS_HAVE_OPENGL) && defined(BIAS_HAVE_FONTGL)
1675  if(drawerInited)
1676  drawer.Print3D("Y",0,Params_.WCSAxesLength,0);
1677 #endif
1678  // Z-axis:
1679  glColor4d(0.0, 0.0, 1.0, 0.0); // r
1680  glBegin(GL_LINES);
1681  glVertex3d(0.0, 0.0, 0.0);
1682  glVertex3d(0.0, 0.0, Params_.WCSAxesLength);
1683  glEnd();
1684 #if defined(BIAS_HAVE_OPENGL) && defined(BIAS_HAVE_FONTGL)
1685  if(drawerInited)
1686  drawer.Print3D("Z",0,0,Params_.WCSAxesLength);
1687 #endif
1688 }
1689 
1691 {
1692  StatekeeperGL state;
1693 
1694  if (Params_.PointSize<1) return;
1695  glColor4ubv(Color.GetData());
1696  glPointSize((float)Params_.PointSize);
1697  map<unsigned int, Point3DData>::iterator it;
1698  switch (Params_.PointStyle) {
1699  case Point:
1700  glBegin(GL_POINTS);
1701  for (it=mapPoints_.begin(); it!=mapPoints_.end(); it++){
1702  glVertex3dv(it->second.Point.GetData());
1703  }
1704  glEnd();
1705  break;
1706  case PointSprite:
1707  BIASERR("PointSprites not yet implemented");
1708  break;
1709  case Sphere:
1710  for (it=mapPoints_.begin(); it!=mapPoints_.end(); it++){
1711  Vector3<double> C = it->second.Point;
1712  glTranslated(C[0],C[1], C[2]);
1713  //glColor4ubv(it->second.Color.GetData());
1714  DrawSphere_((double)Params_.PointSize,50, 50);
1715  glTranslated(-C[0], -C[1], -C[2]);
1716  }
1717  break;
1718  case Box:
1719  BIASERR("Points as Box not yet implemented");
1720  break;
1721  }
1722 }
1723 
1725 
1726  StatekeeperGL state;
1727 
1728  if (Params_.PointSize<1) return;
1729  map<unsigned int, Point3DData>::iterator it;
1730  glPointSize((float)Params_.PointSize);
1731 
1732  // BIAS::TimeMeasure timer;
1733  // double es=0.0;
1734  // std::vector<Vector4<unsigned char> > colors;
1735  // std::vector<Vector3<double> > pos;
1736 
1737  // vector<Vector4<unsigned char> >::iterator itC;
1738  // vector<Vector3<double> >::iterator itP;
1739  // for (it=mapPoints_.begin(); it!=mapPoints_.end(); it++){
1740  // colors.push_back(it->second.Color);
1741  // pos.push_back(it->second.Point);
1742  // }
1743 
1744 
1745  // cout<<"ThreeDOut Drawing :"<<mapPoints_.size()<<" elements"<<endl;
1746  switch (Params_.PointStyle) {
1747  case Point:
1748 
1749  // timer.Start();
1750 
1751  glBegin(GL_POINTS);
1752  for (it=mapPoints_.begin(); it!=mapPoints_.end(); it++){
1753  glColor4ubv(it->second.Color.GetData());
1754  glVertex3dv(it->second.Point.GetData());
1755  }
1756  glEnd();
1757 
1758  // glBegin(GL_POINTS);
1759  // for (itC=colors.begin(),itP=pos.begin();
1760  // itC!=colors.end() && itP!=pos.end();
1761  // itC++,itP++){
1762  // glColor4ubv(itC->GetData());
1763  // glVertex3dv(itP->GetData());
1764  // }
1765  // glEnd();
1766 
1767  // timer.Stop();
1768  // meanDraw.push_back(timer.GetRealTime());
1769 
1770  // for(unsigned int i=0;i<meanDraw.size();i++)
1771  // es+=meanDraw[i];
1772  // es/=meanDraw.size();
1773  // cout<<"ThreeDOut Draw mean:\t"<<es<<endl;
1774  break;
1775  case PointSprite:
1776  BIASERR("PointSprites not yet implemented");
1777  break;
1778  case Sphere:
1779  for (it=mapPoints_.begin(); it!=mapPoints_.end(); it++){
1780  Vector3<double> C = it->second.Point;
1781  glTranslated(C[0],C[1], C[2]);
1782  glColor4ubv(it->second.Color.GetData());
1783  DrawSphere_((double)Params_.PointSize,50, 50);
1784  glTranslated(-C[0], -C[1], -C[2]);
1785  }
1786  break;
1787  case Box:
1788  BIASERR("Points as Box not yet implemented");
1789  break;
1790  }
1791 }
1792 
1793 void ThreeDOut::OpenGLOutPMatrices_(const BIAS::RGBAuc &Color, bool UseOneColor)
1794 {
1795  StatekeeperGL state;
1796 
1797  // no cameras desired ???
1798  if (Params_.CameraScale<=0.0) return;
1799 
1800  unsigned int index=0;
1801 
1802  switch (Params_.CameraStyle){
1803  case PyramidMeshWithArrow:
1804  case PyramidMesh:
1805  case PyramidWithCenterBox:
1806  {
1807  if (Params_.LineWidth < 1) break;
1808  GLenum cap = GL_LINE_LOOP;
1809 
1810  glDisable(GL_TEXTURE_2D);
1811  if (UseOneColor)
1812  glColor4ubv(Color.GetData());
1813 
1814  if((float)Params_.LineWidth >= 1)
1815  glLineWidth((float)Params_.LineWidth);
1816 
1817  map<unsigned int, PMatrix3DData>::iterator itP;
1818  for (itP=mapPMatrices_.begin(); itP!=mapPMatrices_.end(); itP++){
1819  const PMatrix3DData *it = &(itP->second);
1820 
1821  glPushMatrix();
1822  glTranslated(it->C[0], it->C[1], it->C[2]);
1824  glTranslated(-it->C[0], -it->C[1], -it->C[2]);
1825 
1826  {
1827  if (!UseOneColor)
1828  glColor4ubv(it->Color.GetData());
1829  glBegin( cap );
1830  glVertex3dv(it->C.GetData());
1831  glVertex3dv(it->UR.GetData());
1832  glVertex3dv(it->UL.GetData());
1833  glEnd();
1834 
1835  glBegin( cap );
1836  glVertex3dv(it->C.GetData());
1837  glVertex3dv(it->LR.GetData());
1838  glVertex3dv(it->UR.GetData());
1839  glEnd();
1840 
1841  glBegin( cap );
1842  glVertex3dv(it->C.GetData());
1843  glVertex3dv(it->LL.GetData());
1844  glVertex3dv(it->LR.GetData());
1845  glEnd();
1846 
1847  glBegin( cap );
1848  glVertex3dv(it->C.GetData());
1849  glVertex3dv(it->UL.GetData());
1850  glVertex3dv(it->LL.GetData());
1851  glEnd();
1852  }
1853  glPopName();
1854  glPopMatrix();
1855  index++;
1856  }
1857  }
1858  // now we drew the mesh, may be we should proceed with the arrow?
1859  if (Params_.CameraStyle==PyramidMesh) break;
1860  case Arrow:
1861 
1862  {
1863  if (Params_.LineWidth < 1) break;
1864  map<unsigned int, PMatrix3DData>::iterator itP;
1865  if (UseOneColor)
1866  glColor4ubv(Color.GetData());
1867  for (itP=mapPMatrices_.begin(); itP!=mapPMatrices_.end(); itP++){
1868  const PMatrix3DData *it = &(itP->second);
1869 
1870  glPushMatrix();
1871  glTranslated(it->C[0], it->C[1], it->C[2]);
1873  glTranslated(-it->C[0], -it->C[1], -it->C[2]);
1874 
1875  glPushName(BIAS_SELECTION_OFFSET_PMATRIX +index);
1876  {
1877  if (!UseOneColor)
1878  glColor4ubv(it->Color.GetData());
1879  glBegin(GL_POINTS);
1880  glVertex3dv(it->C.GetData());
1881  glEnd();
1883  ||Params_.CameraStyle==Arrow) {
1884  //glColor3f(1.0,1.0,0.0);
1885  glBegin(GL_LINES);
1886  glVertex3dv(it->C.GetData() );
1887  glVertex3dv(it->PP.GetData());
1888  glVertex3dv(it->C.GetData() );
1889  glVertex3dv( ((it->Up) +(it->C)).GetData() );
1890  glEnd();
1891  }
1892  }
1893  glPopName();
1894  glPopMatrix();
1895  index++;
1896  }
1897  }
1898  break;
1899  case PyramidSolid:
1900  {
1901  float mat_diffuse[] = {Color[0]*0.7f, Color[1]*0.7f, Color[2]*0.7f, 1.0f};
1902  float mat_ambient[] = {Color[0]*0.1f, Color[1]*0.1f, Color[2]*0.1f, 1.0f};
1903  float mat_shininess[] = {8.0f };
1904  Vector3<double> normal;
1905 
1906  const GLenum cap = GL_POLYGON;
1907  glShadeModel(GL_FLAT);
1908  glFrontFace(GL_CW);
1909  glCullFace(GL_BACK);
1910  glEnable(GL_CULL_FACE);
1911  glEnable(GL_NORMALIZE);
1912  glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS,mat_shininess);
1913  if (UseOneColor)
1914  glColor4ubv(Color.GetData());
1915  map<unsigned int, PMatrix3DData>::iterator itP;
1916  for (itP=mapPMatrices_.begin(); itP!=mapPMatrices_.end(); itP++){
1917  const PMatrix3DData *it = &(itP->second);
1918 
1919  glPushMatrix();
1920  glTranslated(it->C[0], it->C[1], it->C[2]);
1922  glTranslated(-it->C[0], -it->C[1], -it->C[2]);
1923 
1924  glPushName(BIAS_SELECTION_OFFSET_PMATRIX +index);
1925  {
1926  if (!UseOneColor)
1927  glColor4ubv(it->Color.GetData());
1928 
1929  mat_diffuse[0] = Color[0]/255.0f*0.9f;
1930  mat_diffuse[1] = Color[1]/255.0f*0.9f;
1931  mat_diffuse[2] = Color[2]/255.0f*0.9f;
1932  mat_diffuse[3] = 1.0f;
1933 
1934  mat_ambient[0] = Color[0]/255.0f*0.2f;
1935  mat_ambient[1] = Color[1]/255.0f*0.2f;
1936  mat_ambient[2] = Color[2]/255.0f*0.2f;
1937  mat_ambient[3] = 1.0f;
1938 
1939  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
1940  glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
1941 
1942  glBegin( cap );
1943  (it->C - it->UL).CrossProduct(it->C - it->UR, normal);
1944  glNormal3f((float)normal[0], (float)normal[1], (float)normal[2]);
1945  glVertex3dv(it->C.GetData());
1946  glVertex3dv(it->UL.GetData());
1947  glVertex3dv(it->UR.GetData());
1948  glEnd();
1949 
1950  glBegin( cap );
1951  (it->C - it->UR).CrossProduct(it->C - it->LR, normal);
1952  glNormal3f(-(float)normal[0], -(float)normal[1], -(float)normal[2]);
1953  glVertex3dv(it->C.GetData());
1954  glVertex3dv(it->UR.GetData());
1955  glVertex3dv(it->LR.GetData());
1956  glEnd();
1957 
1958  glBegin( cap );
1959  (it->C - it->LR).CrossProduct(it->C - it->LL, normal);
1960  glNormal3f(-(float)normal[0], -(float)normal[1], -(float)normal[2]);
1961  glVertex3dv(it->C.GetData());
1962  glVertex3dv(it->LR.GetData());
1963  glVertex3dv(it->LL.GetData());
1964  glEnd();
1965 
1966  glBegin( cap );
1967  (it->C - it->LL).CrossProduct(it->C - it->UL, normal);
1968  glNormal3f((float)normal[0], (float)normal[1], (float)normal[2]);
1969  glVertex3dv(it->C.GetData());
1970  glVertex3dv(it->LL.GetData());
1971  glVertex3dv(it->UL.GetData());
1972  glEnd();
1973 
1974  // camera plane
1975  glBegin( cap );
1976  (it->C - it->LR).CrossProduct(it->C - it->UR, normal);
1977  glNormal3f((float)normal[0], (float)normal[1], (float)normal[2]);
1978  glVertex3dv(it->UL.GetData());
1979  glVertex3dv(it->LR.GetData());
1980  glVertex3dv(it->UR.GetData());
1981  glVertex3dv(it->UL.GetData());
1982  glVertex3dv(it->LL.GetData());
1983  glVertex3dv(it->LR.GetData());
1984  glEnd();
1985  }
1986  glPopName();
1987  glPopMatrix();
1988  index++;
1989  }
1990  }
1991  break;
1992  case Undrawn:
1993  break;
1994  default:
1995  BIASERR("unknown camera drawing style "<<Params_.CameraStyle);
1996  break;
1997  }
1998 
1999  //draw camera covariance ellipses
2001  GLUquadric *myQuad;
2002  myQuad = gluNewQuadric();
2003  map<unsigned int, Ellipsoid3DData>::iterator it;
2004  if (UseOneColor)
2005  glColor4ubv(Color.GetData());
2006  for (it=mapCamEllipsoids_.begin(); it!=mapCamEllipsoids_.end(); it++){
2007  glPushMatrix();
2008  // move to right location
2009  glTranslated(it->second.C[0], it->second.C[1], it->second.C[2]);
2010  glRotated(it->second.dAngle * DEGREE_PER_RAD, // gl wants degree
2011  it->second.RotAxis[0], it->second.RotAxis[1],
2012  it->second.RotAxis[2]);
2013  glScaled(Params_.EllipsoidScale * it->second.s0,
2014  Params_.EllipsoidScale * it->second.s1,
2015  Params_.EllipsoidScale * it->second.s2);
2016 
2017  if (!UseOneColor)
2018  // gl wants opacity not transparency
2019  glColor4ubv(it->second.Color.GetData());
2020  gluSphere(myQuad, 1, 20, 20);
2021  glPopMatrix();
2022  }
2023  gluDeleteQuadric(myQuad);
2024  }
2025 
2026 }
2027 
2029  OpenGLOutPMatrices_(Color, true);
2030 }
2031 
2033 {
2034  BIAS::RGBAuc Color;
2035  OpenGLOutPMatrices_(Color, false);
2036 }
2037 
2038 void ThreeDOut::OpenGLOutImages(const bool & disableBlending)
2039 {
2040  map<unsigned int, Image3DData>::iterator it=mapImages_.begin();
2041  // nothing to do ?
2042  if (it==mapImages_.end()) return;
2043 
2044  StatekeeperGL state(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT);
2045 
2046  GLuint texid;
2047  glGenTextures( 1, &texid ) ;
2048  glBindTexture( GL_TEXTURE_2D, texid) ;
2049  glEnable(GL_TEXTURE_2D);
2050  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2051  glDisable(GL_TEXTURE_GEN_S);
2052  glDisable(GL_TEXTURE_GEN_T);
2053 
2054  /// \todo image interface (rgb<=>grey)
2055  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
2056  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
2057  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2058  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2059 
2060  // no transparency?
2061  if (disableBlending)
2062  glDisable(GL_BLEND);
2063 
2064  for (it=mapImages_.begin(); it!=mapImages_.end(); it++)
2065  {
2066  // use roi to determine texture coordinates
2067  double texX(1.0), texY(1.0);
2068  unsigned int x1, x2, y1, y2;
2069  it->second.ImageData.GetROI()->GetCorners(x1, y1, x2, y2);
2070  texX = (double)x2 / (double)it->second.ImageData.GetWidth();
2071  texY = (double)y2 / (double)it->second.ImageData.GetHeight();
2072 
2073  GLenum GLColorModel =
2074  (it->second.ImageData.GetChannelCount()==3)? GL_RGB : GL_LUMINANCE;
2075 
2076  glTexImage2D(GL_TEXTURE_2D, 0, GLColorModel,
2077  it->second.ImageData.GetWidth(),
2078  it->second.ImageData.GetHeight(), 0, GLColorModel,
2079  GL_UNSIGNED_BYTE,
2080  (GLvoid *) it->second.ImageData.GetImageData());
2081 
2082  glBegin(GL_QUADS);
2083 
2084  glTexCoord2d(0.0, 0.0);
2085  glVertex3dv(it->second.UL.GetData());
2086 
2087  glTexCoord2d(0.0, texY);
2088  glVertex3dv(it->second.LL.GetData());
2089 
2090  glTexCoord2d(texX, texY);
2091  glVertex3dv(it->second.LR.GetData());
2092 
2093  glTexCoord2d(texX, 0.0);
2094  glVertex3dv(it->second.UR.GetData());
2095 
2096  glEnd();
2097  }
2098  glDeleteTextures(1, &texid);
2099 }
2100 
2102 
2103  StatekeeperGL state;
2104 
2105  map<unsigned int, IndexedFaceSet>::iterator it;
2106  for (it = mapIndexedFaceSet_.begin(); it!=mapIndexedFaceSet_.end(); it++) {
2107 
2108  if(it->second.compiled_) {
2109  glCallList(it->second.displayList_);
2110  }
2111  else
2112  {
2113  if (it->second.useTexture) {
2114  Image<unsigned char> flippedImage = it->second.texture;
2115  if (flippedImage.IsEmpty()) {
2116  flippedImage.Init(16,16,3);
2117  flippedImage.SetColorModel(ImageBase::CM_RGB);
2118  } else {
2119  flippedImage.Flip();
2120  flippedImage.PadToPowerOfTwo(0);
2121  }
2122 
2123  // cout<<"compiling display list ..."<<endl;
2124  glDeleteTextures(1, &it->second.textureObjectID_);
2125  glGenTextures(1, &it->second.textureObjectID_);
2126  glBindTexture( GL_TEXTURE_2D, it->second.textureObjectID_);
2127  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
2128  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
2129  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2130 
2131 
2132  unsigned int width, height;
2133  width= flippedImage.GetWidth();
2134  height= flippedImage.GetHeight();
2135 
2136  GLenum textureFormat = GL_RGB;
2137  int channels = it->second.texture.GetChannelCount();
2138  //cout<<"Channels:"<<channels<<endl;
2139  if (channels==1) {
2140  //cout<<"grey texture !"<<endl;
2141  textureFormat = GL_LUMINANCE;
2142  BIASASSERT(it->second.texture.GetColorModel()==ImageBase::CM_Grey);
2143  } else if (channels==3) {
2144  textureFormat = GL_RGB;
2145  // cout<<"rgb texture !"<<endl;
2146  BIASASSERT(it->second.texture.GetColorModel()==ImageBase::CM_RGB);
2147  } else if (channels==4) {
2148  textureFormat = GL_RGBA;
2149  BIASASSERT(it->second.texture.GetColorModel()==ImageBase::CM_RGBA);
2150  glEnable (GL_BLEND);
2151  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2152  } else {
2153  BIASERR("unsupported color model.");
2154  BIASABORT;
2155  }
2156 
2157 #ifdef BIAS_HAVE_GLEW
2158  if(GLEW_EXT_framebuffer_object) {
2159  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
2160  GL_LINEAR_MIPMAP_LINEAR);
2161  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height,
2162  0, textureFormat, GL_UNSIGNED_BYTE, 0);
2163  glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP, GL_TRUE);
2164  } else {
2165  glTexParameteri(GL_TEXTURE_2D,
2166  GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2167  }
2168 #else
2169  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2170 #endif
2171 
2172  glTexImage2D(GL_TEXTURE_2D, 0, textureFormat, width, height,
2173  0, textureFormat, GL_UNSIGNED_BYTE,
2174  flippedImage.GetImageData());
2175 
2176  glDeleteLists(it->second.displayList_, 1);
2177  it->second.displayList_ = glGenLists(1);
2178 
2179  glNewList(it->second.displayList_, GL_COMPILE_AND_EXECUTE);
2180  glPushAttrib(GL_TEXTURE_BIT | GL_ENABLE_BIT);
2181  glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
2182 
2183  glVertexPointer(3, GL_FLOAT, 0, it->second.VertArray);
2184  glTexCoordPointer(2, GL_FLOAT, 0, it->second.TextureCoordArray);
2185 
2186  if(it->second.useNormals)
2187  glNormalPointer(GL_FLOAT, 0, it->second.NormalArray);
2188 
2189  glEnable(GL_TEXTURE_2D);
2190  if(it->second.useNormals)
2191  glEnableClientState(GL_NORMAL_ARRAY);
2192  glEnableClientState(GL_VERTEX_ARRAY);
2193  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2194  //render indexed face set
2195  glBindTexture( GL_TEXTURE_2D, it->second.textureObjectID_);
2196  }//end if (it->second.useTexture)
2197  else if(it->second.useColoredVertices){
2198  //cout<<"Using colored vertices"<<endl;;
2199  glDeleteLists(it->second.displayList_, 1);
2200  it->second.displayList_ = glGenLists(1);
2201 
2202  glNewList(it->second.displayList_, GL_COMPILE_AND_EXECUTE);
2203  glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
2204 
2205  glVertexPointer(3, GL_FLOAT, 0, it->second.VertArray);
2206  if(it->second.useNormals)
2207  glNormalPointer(GL_FLOAT, 0, it->second.NormalArray);
2208  glColorPointer(4, GL_UNSIGNED_BYTE, 0, it->second.ColorArray);
2209  glDisable(GL_TEXTURE_2D);
2210  glEnableClientState(GL_VERTEX_ARRAY);
2211  if(it->second.useNormals)
2212  glEnableClientState(GL_NORMAL_ARRAY);
2213  glEnableClientState(GL_COLOR_ARRAY);
2214 
2215  glEnable( GL_COLOR_MATERIAL );
2216  glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
2217  }//end if(it->second.useColoredVertices){
2218  else {
2219  glDeleteLists(it->second.displayList_, 1);
2220  it->second.displayList_ = glGenLists(1);
2221 
2222  glNewList(it->second.displayList_, GL_COMPILE_AND_EXECUTE);
2223  glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
2224 
2225  glVertexPointer(3, GL_FLOAT, 0, it->second.VertArray);
2226  if(it->second.useNormals)
2227  glNormalPointer(GL_FLOAT, 0, it->second.NormalArray);
2228 
2229  glDisable(GL_TEXTURE_2D);
2230  glEnableClientState(GL_VERTEX_ARRAY);
2231  if(it->second.useNormals)
2232  glEnableClientState(GL_NORMAL_ARRAY);
2233 
2234 
2235  float white[4] = {0.8, 0.8, 0.8, 1.0};
2236  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
2237  }//end else (it->second.useTexture) | it->second.useColoredVertices)
2238 
2239 #ifdef BIAS_HAVE_GLEW
2240  if (GLEW_VERSION_1_4) {
2241  /*
2242  cout<<"it->second.NumFacets:"<<it->second.NumFacets<<endl;
2243  for(int i=0;i<it->second.NumFacets;i++){
2244  if(isinf(it->second.facetIndicesCountArray[i])){
2245  it->second.facetIndicesCountArray[i]=0;
2246  cout<<"C:INF"<<endl;
2247  }
2248  else cout<<"NC:"<<it->second.facetIndicesCountArray[i]<<endl;
2249 
2250  for(int j=0;j<it->second.facetIndicesCountArray[i];j++){
2251  if(isinf(it->second.facetArray[i][j])){
2252  it->second.facetArray[i][j]=0;
2253  cout<<"AR:INF"<<endl;
2254  }
2255  else cout<<"AR:"<<it->second.facetArray[i][j];
2256  }
2257  cout<<endl;
2258  }
2259  */
2260  glMultiDrawElements(Params_.IndexedFaceSetPrimitiveMode,
2261  it->second.facetIndicesCountArray,
2262  GL_UNSIGNED_INT,
2263  (const GLvoid**)it->second.facetArray,
2264  it->second.NumFacets);
2265  }//end if (GLEW_VERSION_1_4)
2266  else {
2267 #endif
2268  for(int i=0; i<it->second.NumFacets;i++) {
2269  glDrawElements(Params_.IndexedFaceSetPrimitiveMode,
2270  it->second.facetIndicesCountArray[i],
2271  GL_UNSIGNED_INT,
2272  (const GLvoid*)it->second.facetArray[i]);
2273  }//end for
2274 #ifdef BIAS_HAVE_GLEW
2275  }//end else
2276 #endif
2277  if (it->second.useTexture) {
2278  glPopClientAttrib();
2279  glPopAttrib();
2280  } else {
2281  glPopClientAttrib();
2282  }
2283 
2284  // CHECK_GL_ERROR;
2285  glEndList();
2286  it->second.compiled_=true;
2287  }
2288  }
2289 }
2290 
2291 
2293 
2294  if (Params_.LineWidth < 1) return;
2295  StatekeeperGL state(GL_ENABLE_BIT);
2296 
2297  const GLenum cap = GL_LINE_LOOP;
2298  glDisable(GL_TEXTURE_2D);
2299  glColor4ubv(Color.GetData()); // same color for alls
2300  glLineWidth((float)Params_.LineWidth);
2301  map<unsigned int, Line3DData>::iterator it;
2302  for (it=mapLines_.begin(); it!=mapLines_.end(); it++){
2303  glBegin( cap );
2304  glVertex3dv(it->second.Start.GetData());
2305  glVertex3dv(it->second.End.GetData());
2306  glEnd();
2307  }
2308 }
2309 
2311  if (Params_.LineWidth < 1) return;
2312  StatekeeperGL state(GL_ENABLE_BIT);
2313 
2314  const GLenum cap = GL_LINE_LOOP;
2315  glDisable(GL_TEXTURE_2D);
2316  map<unsigned int, Line3DData>::iterator it;
2317  for (it=mapLines_.begin(); it!=mapLines_.end(); it++){
2318  // a different colro for each
2319  glColor4ubv(it->second.Color.GetData());
2320 
2321  glBegin( cap );
2322  glVertex3dv(it->second.Start.GetData());
2323  glVertex3dv(it->second.End.GetData());
2324  glEnd();
2325  }
2326 }
2327 
2328 
2329 
2331 {
2332  StatekeeperGL state;
2333 
2334  glEnable (GL_BLEND);
2335  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2336 
2337  GLUquadric *myQuad;
2338  myQuad = gluNewQuadric();
2339  map<unsigned int, Ellipsoid3DData>::iterator it;
2340  for (it=mapEllipsoids_.begin(); it!=mapEllipsoids_.end(); it++){
2341  glPushMatrix();
2342  // move to right location
2343  glTranslated(it->second.C[0], it->second.C[1], it->second.C[2]);
2344  glRotated(it->second.dAngle * DEGREE_PER_RAD, // gl wants degree
2345  it->second.RotAxis[0], it->second.RotAxis[1],
2346  it->second.RotAxis[2]);
2347  glScaled(Params_.EllipsoidScale * it->second.s0,
2348  Params_.EllipsoidScale * it->second.s1,
2349  Params_.EllipsoidScale * it->second.s2);
2350  // gl wants opacity not transparency
2351  glColor4ubv(Color.GetData());
2352  gluSphere(myQuad, 1, 20, 20);
2353  glPopMatrix();
2354  }
2355  gluDeleteQuadric(myQuad);
2356 
2357 }
2358 
2359 
2360 
2362  StatekeeperGL state;
2363 
2364  GLUquadric *myQuad;
2365  myQuad = gluNewQuadric();
2366 
2367  // get me some lighting!
2368  float white[] = {1.0, 1.0, 1.0, 1.0};
2369  // float red[] = {1.0, 0.0, 0.0, 1.0};
2370  float lightRed[] = {0.6, 0.0, 0.0, 1.0};
2371  //float green[] = {0.0, 1.0, 0.0, 1.0};
2372  //float lightGreen[] = {0.0, 0.6, 0.0, 1.0};
2373  float darkGreen[] = {0.0, 0.2, 0.0, 1.0};
2374  //float blue[] = {0.0, 0.0, 1.0, 1.0};
2375  float lightBlue[] = {0.0, 0.0, 0.6, 1.0};
2376  //float darkBlue[] = {0.0, 0.0, 0.2, 1.0};
2377  //float black[] = {0.0, 0.0, 0.0, 0.0};
2378  float darkGrey[] = {0.2, 0.2, 0.2, 1.0};
2379  // float lightGrey[] = {0.6, 0.6, 0.6, 1.0};
2380 
2381  float position1_light[]= {1000.0, 1000.0, 3000.0, 1.0};
2382  glLightfv(GL_LIGHT4, GL_POSITION, position1_light);
2383  float position2_light[]= {-1000.0, -1000.0, 5000.0, 1.0};
2384  glLightfv(GL_LIGHT5, GL_POSITION, position2_light);
2385  float position3_light[]= {.0, .0, 4000.0, 1.0};
2386  glLightfv(GL_LIGHT6, GL_POSITION, position3_light);
2387 
2388  GLboolean hadLight[8][1];
2389  glGetBooleanv(GL_LIGHTING,hadLight[0]);
2390  glGetBooleanv(GL_LIGHT0,hadLight[1]);
2391  glGetBooleanv(GL_LIGHT1,hadLight[2]);
2392  glGetBooleanv(GL_LIGHT2,hadLight[3]);
2393  glGetBooleanv(GL_LIGHT3,hadLight[4]);
2394  glGetBooleanv(GL_LIGHT4,hadLight[5]);
2395  glGetBooleanv(GL_LIGHT5,hadLight[6]);
2396  glGetBooleanv(GL_LIGHT6,hadLight[7]);
2397 
2398 
2399  if(!hadLight[0][0]) glEnable(GL_LIGHTING);
2400  if( hadLight[1][0]) glDisable(GL_LIGHT0);
2401  if( hadLight[2][0]) glDisable(GL_LIGHT1);
2402  if( hadLight[3][0]) glDisable(GL_LIGHT2);
2403  if( hadLight[4][0]) glDisable(GL_LIGHT3);
2404  if(!hadLight[5][0]) glEnable(GL_LIGHT4);
2405  if(!hadLight[6][0]) glEnable(GL_LIGHT5);
2406  if(!hadLight[7][0]) glEnable(GL_LIGHT6);
2407 
2408  glLightfv(GL_LIGHT4, GL_DIFFUSE, lightBlue);
2409  glLightfv(GL_LIGHT4, GL_SPECULAR, white);
2410  glLightfv(GL_LIGHT4, GL_AMBIENT, darkGrey);
2411  glLightfv(GL_LIGHT5, GL_DIFFUSE, lightRed);
2412  glLightfv(GL_LIGHT5, GL_SPECULAR, white);
2413  glLightfv(GL_LIGHT5, GL_AMBIENT, darkGrey);
2414  glLightfv(GL_LIGHT6, GL_DIFFUSE, darkGreen);
2415  glLightfv(GL_LIGHT6, GL_SPECULAR, white);
2416  glLightfv(GL_LIGHT6, GL_AMBIENT, darkGrey);
2417 
2418  glFrontFace(GL_CW);
2419  glCullFace(GL_BACK);
2420  glEnable(GL_CULL_FACE);
2421  glEnable(GL_NORMALIZE);
2422 
2423  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, darkGrey);
2424  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0);
2425 
2426  glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
2427  glShadeModel(GL_SMOOTH);
2428  CHECK_GL_ERROR;
2429  map<unsigned int, Ellipsoid3DData>::iterator it;
2430  unsigned char *color; float cf[4];
2431  for (it=mapEllipsoids_.begin(); it!=mapEllipsoids_.end(); it++){
2432 
2433  color = it->second.Color.GetData();
2434  for(int i=0;i<4;i++) cf[i] = (float)(color[i])/255.0;
2435 
2436  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, cf);
2437  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,cf);
2438 
2439  glMatrixMode(GL_MODELVIEW);
2440  glPushMatrix();
2441  // move to right location
2442  glTranslated(it->second.C[0], it->second.C[1], it->second.C[2]);
2443  glRotated(it->second.dAngle * DEGREE_PER_RAD, // gl wants degree
2444  it->second.RotAxis[0], it->second.RotAxis[1],
2445  it->second.RotAxis[2]);
2446  glScaled(Params_.EllipsoidScale * it->second.s0,
2447  Params_.EllipsoidScale * it->second.s1,
2448  Params_.EllipsoidScale * it->second.s2);
2449  // gl wants opacity not transparency
2450  glColor4ubv(it->second.Color.GetData());
2451 
2452 
2453  gluSphere(myQuad, 1, 20, 20);
2454  glPopMatrix();
2455 
2456  }
2457  //turn off again
2458  if(!hadLight[0][0]) glDisable(GL_LIGHTING);
2459  if( hadLight[1][0]) glEnable(GL_LIGHT0);
2460  if( hadLight[2][0]) glEnable(GL_LIGHT1);
2461  if( hadLight[3][0]) glEnable(GL_LIGHT2);
2462  if( hadLight[4][0]) glEnable(GL_LIGHT3);
2463  if(!hadLight[5][0]) glDisable(GL_LIGHT4);
2464  if(!hadLight[6][0]) glDisable(GL_LIGHT5);
2465  if(!hadLight[7][0]) glDisable(GL_LIGHT6);
2466 
2467  gluDeleteQuadric(myQuad);
2468 }
2469 
2472  OpenGLOutEllipsoids(Color);
2473  // no color arg:
2474  OpenGLOutImages();
2475  // override color:
2476  OpenGLOutPMatrices(Color);
2477  OpenGLOutPoints(Color);
2478  OpenGLOutLines(Color);
2480  if (Params_.WCSAxesLength>0.0)
2481  OpenGLOutWCS();
2482 }
2483 
2484 
2486  BIAS::RGBAuc Color;
2488  OpenGLOutEllipsoids(Color);
2489  OpenGLOutImages();
2491  OpenGLOutPoints();
2492  OpenGLOutLines();
2494  if (Params_.WCSAxesLength>0.0)
2495  OpenGLOutWCS();
2496 }
2497 #endif // BIAS_HAVE_OPENGL
2498 
2499 
2500 
2501 void ThreeDOut::
2502 DrawSphere_(double radius, int lats, int longs) {
2503 #ifdef BIAS_HAVE_OPENGL
2504  int i, j;
2505  for(i = 0; i <= lats; i++) {
2506  double lat0 = M_PI * (-0.5 + (double) (i - 1) / lats);
2507  double z0 = sin(lat0);
2508  double zr0 = cos(lat0);
2509 
2510  double lat1 = M_PI * (-0.5 + (double) i / lats);
2511  double z1 = sin(lat1);
2512  double zr1 = cos(lat1);
2513 
2514  glBegin(GL_QUAD_STRIP);
2515  for(j = 0; j <= longs; j++) {
2516  double lng = 2 * M_PI * (double) (j - 1) / longs;
2517  double x = cos(lng);
2518  double y = sin(lng);
2519 
2520  glNormal3f(x * zr0, y * zr0, z0);
2521  glVertex3f(x * zr0, y * zr0, z0);
2522  glNormal3f(x * zr1, y * zr1, z1);
2523  glVertex3f(x * zr1, y * zr1, z1);
2524  }
2525  glEnd();
2526  }
2527 #endif
2528 }
2529 
2530 
2531 // --------------------------- VRML functions ---------------------------
2532 
2533 int ThreeDOut::VRMLOutPoints(ostream& VRMLFile, const BIAS::RGBAuc &Color){
2534  if (mapPoints_.size()==0) return 0;
2535  map<unsigned int, Point3DData>::iterator it = mapPoints_.begin();
2536  while (it!=mapPoints_.end()) {
2537  // this not really correct because it changes the color of the
2538  // points and does not only change their visualization
2539  it->second.Color = Color;
2540  it++;
2541  }
2542  return VRMLOutPoints(VRMLFile);
2543 }
2544 
2546 {
2547 
2548  unsigned int numpoints = mapPoints_.size();
2549  unsigned int numpointsets = numpoints /5000;
2550  unsigned int remainingpoints = numpoints % 5000;
2551 
2552  if (remainingpoints >0) numpointsets++;
2553  //cout <<"numpoints: "<<numpoints<<endl;
2554  //cout <<"numpointsets: "<<numpointsets<<endl;
2555  //cout <<"remainingpoints: "<<remainingpoints<<endl;
2556 
2557  map<unsigned int, Point3DData>::iterator it1 = mapPoints_.begin();
2558  map<unsigned int, Point3DData>::iterator it2 = mapPoints_.begin();
2559 
2560  for (unsigned int ps=0;ps<numpointsets; ps++)
2561  {
2562  VRMLFile<<
2563  "Shape { "<<endl<<
2564  " geometry PointSet {"<<endl<<
2565  " color Color {"<<endl<<
2566  " color [ "<<endl;
2567  double r,g,b;
2568  //int p = 0;
2569  while (it1!=mapPoints_.end()) {// && p<5000) {
2570  Point3DData &Da = it1->second;
2571  r = (double)Da.Color[0] / 255.0;
2572  g = (double)Da.Color[1] / 255.0;
2573  b = (double)Da.Color[2] / 255.0;
2574  if (it1 != mapPoints_.begin()) // && (p%5000)!=0)
2575  VRMLFile<<", "<<endl;
2576  VRMLFile << " "<< r << " " << g << " " << b;
2577  it1++; //p++;
2578  }
2579 
2580  VRMLFile<< " ] " << endl
2581  << " }"<<endl
2582  << " coord Coordinate { "<<endl
2583  << " point [ "<<endl;
2584 
2585  streamsize w=8;
2586  //p = 0;
2587  while (it2!=mapPoints_.end()) { //&& p<5000) {
2588  Point3DData &Db = it2->second;
2589  if (it2!=mapPoints_.begin()) // && (p%5000)!=0)
2590  VRMLFile<<", "<<endl;
2591  VRMLFile<< " "
2592  << setw(w) << Db.Point[0] << " "
2593  << setw(w) << Db.Point[1] << " "
2594  << setw(w) << Db.Point[2];
2595  it2++; //p++;
2596  }
2597 
2598  VRMLFile << " ] " << endl
2599  << " }" << endl
2600  << " }" << endl
2601  << "}" << endl;
2602  } // for all pointsets
2603 
2604  return 0;
2605 }
2606 
2607 
2608 
2609 int ThreeDOut::VRMLOutPointsAsBoxes_(ostream &VRMLFile)
2610 {
2611  VRMLFile<<
2612  "Shape { "<<endl<<
2613  " geometry IndexedFaceSet {"<<endl<<
2614  " color Color {"<<endl<<
2615  " color ["<<endl;
2616 
2617  double r,g,b;
2618  map<unsigned int, Point3DData>::iterator it = mapPoints_.begin();
2619  while (it!=mapPoints_.end()) {
2620  Point3DData &Da = it->second;
2621  r = (double)Da.Color[0] / 255.0;
2622  g = (double)Da.Color[1] / 255.0;
2623  b = (double)Da.Color[2] / 255.0;
2624  if (it!=mapPoints_.begin()) // add a "," behind last line
2625  VRMLFile<<","<<endl;
2626  for (unsigned int i=0;i<7;i++)
2627  VRMLFile <<
2628  " "<< r << " " << g << " " << b<<","<<endl;
2629  VRMLFile <<
2630  " "<< r << " " << g << " " << b;
2631  it++;
2632  }
2633 
2634  VRMLFile<<endl<<
2635  " ]"<<endl<<
2636  " }"<<endl<<
2637  " coord Coordinate {"<<endl<<
2638  " point ["<<endl;
2639 
2640 
2641  float size = float(Params_.PointSize / 2.0);
2642  streamsize w=8;
2643  it=mapPoints_.begin();
2644  while (it!=mapPoints_.end()) {
2645  Point3DData &Db = it->second;
2646  if (it!=mapPoints_.begin()) // add a "," behind last line
2647  VRMLFile<<","<<endl<<endl;
2648  // top four points
2649  VRMLFile<<
2650  " "
2651  << setw(w) << Db.Point[0]-size << " "
2652  << setw(w) << Db.Point[1]+size << " "
2653  << setw(w) << Db.Point[2]-size;
2654  VRMLFile<< ","<<endl;
2655  VRMLFile<<
2656  " "
2657  << setw(w) << Db.Point[0]+size << " "
2658  << setw(w) << Db.Point[1]+size << " "
2659  << setw(w) << Db.Point[2]-size;
2660  VRMLFile<< ","<<endl;
2661  VRMLFile<<
2662  " "
2663  << setw(w) << Db.Point[0]+size << " "
2664  << setw(w) << Db.Point[1]+size << " "
2665  << setw(w) << Db.Point[2]+size;
2666  VRMLFile<< ","<<endl;
2667  VRMLFile<<
2668  " "
2669  << setw(w) << Db.Point[0]-size << " "
2670  << setw(w) << Db.Point[1]+size << " "
2671  << setw(w) << Db.Point[2]+size;
2672  VRMLFile<< ","<<endl;
2673  // bottom four points
2674  VRMLFile<<
2675  " "
2676  << setw(w) << Db.Point[0]-size << " "
2677  << setw(w) << Db.Point[1]-size << " "
2678  << setw(w) << Db.Point[2]-size;
2679  VRMLFile<< ","<<endl;
2680  VRMLFile<<
2681  " "
2682  << setw(w) << Db.Point[0]+size << " "
2683  << setw(w) << Db.Point[1]-size << " "
2684  << setw(w) << Db.Point[2]-size;
2685  VRMLFile<< ","<<endl;
2686  VRMLFile<<
2687  " "
2688  << setw(w) << Db.Point[0]+size << " "
2689  << setw(w) << Db.Point[1]-size << " "
2690  << setw(w) << Db.Point[2]+size;
2691  VRMLFile<< ","<<endl;
2692  VRMLFile<<
2693  " "
2694  << setw(w) << Db.Point[0]-size << " "
2695  << setw(w) << Db.Point[1]-size << " "
2696  << setw(w) << Db.Point[2]+size;
2697  it++;
2698  }
2699 
2700  VRMLFile << endl<<
2701  " ]" << endl<<
2702  " }" << endl<< // end of Coordinate
2703  " coordIndex ["<<endl;
2704  for (unsigned int i=0;i<mapPoints_.size();i++) {
2705  if (i!=0)
2706  VRMLFile<<","<<endl<<endl;
2707  VRMLFile<<" "<<
2708  i*8+0<<", "<<i*8+1<<", "<<i*8+2<<", "<<i*8+3<<", -1,"<<
2709  " # top side"<<endl<<" "<<
2710  i*8+7<<", "<<i*8+6<<", "<<i*8+5<<", "<<i*8+4<<", -1,"<<
2711  " # bottom side"<<endl<<" "<<
2712  i*8+4<<", "<<i*8+5<<", "<<i*8+1<<", "<<i*8+0<<", -1,"<<
2713  " # back side"<<endl<<" "<<
2714  i*8+3<<", "<<i*8+2<<", "<<i*8+6<<", "<<i*8+7<<", -1,"<<
2715  " # front side"<<endl<<" "<<
2716  i*8+0<<", "<<i*8+3<<", "<<i*8+7<<", "<<i*8+4<<", -1,"<<
2717  " # left side"<<endl<<" "<<
2718  i*8+2<<", "<<i*8+1<<", "<<i*8+5<<", "<<i*8+6<<", -1";
2719  }
2720 
2721  VRMLFile<<endl<<
2722  " ]"<<endl<<
2723  " ccw FALSE"<<endl<<
2724  " colorPerVertex TRUE"<<endl<<
2725  " }" << endl<<
2726  "}" << endl;
2727 
2728  return 0;
2729 }
2730 
2731 int ThreeDOut::VRMLOutPoints(ostream& VRMLFile){
2732  if (mapPoints_.size()==0) return 0;
2733  int res=0;
2734  switch (Params_.PointStyle) {
2735  case Point:
2736  res=VRMLOutPointsAsPointSet_(VRMLFile);
2737  break;
2738  case PointSprite:
2739  BIASERR("PointSprites not yet implemented");
2740  break;
2741  case Sphere:
2742  res = VRMLOutPointsAsSpheres_(VRMLFile);
2743  break;
2744  case Box:
2745  res = VRMLOutPointsAsBoxes_(VRMLFile);
2746  break;
2747  }
2748  return res;
2749 }
2750 
2751 int ThreeDOut::VRMLOutPMatrices(ostream& VRMLFile, const BIAS::RGBAuc &Color)
2752 {
2753  int res = 0;
2754  switch (Params_.CameraStyle) {
2755  case Arrow: res = VRMLOutPMatricesAsArrows_(VRMLFile, Color); break;
2756  case PyramidMesh: res = VRMLOutPMatricesAsMesh_(VRMLFile, Color); break;
2757  default: BIASERR("Not yet implmented"); break;
2758  }
2759 
2760  if (res == 0 && Params_.DrawCameraUncertaintyEllipsoids){
2761  map<unsigned int, Ellipsoid3DData>::iterator it;
2762  for (it=mapCamEllipsoids_.begin(); it!=mapCamEllipsoids_.end(); it++) {
2763  Ellipsoid3DData& E = it->second;
2764  VRMLOutEllipsoid_(VRMLFile, E, Color);
2765  }
2766  }
2767  return res;
2768 }
2769 
2771  const BIAS::RGBAuc &Color)
2772 {
2773  if (Params_.LineWidth < 1) return 0;
2774  double r = 0;
2775  double g = 0;
2776  double b = 0;
2777  // VRML transparency=0 is opaque
2778  //double transparency = 0;
2779 
2780  map<unsigned int, PMatrix3DData>::iterator itP;
2781  r = (double)Color[0] / 255.0;
2782  g = (double)Color[1] / 255.0;
2783  b = (double)Color[2] / 255.0;
2784  //transparency = VRMLtransparency(Color);
2785  unsigned int num=0;
2786  // create vrml model of camera
2787  VRMLFile << "Shape {" << endl;
2788  // write camera center and 4 points in the image plane
2789  VRMLFile <<" geometry IndexedLineSet {" << endl;
2790  VRMLFile <<" coord Coordinate {" << endl;
2791  VRMLFile <<" point [ " << endl;
2792  for (itP=mapPMatrices_.begin(); itP!=mapPMatrices_.end(); itP++){
2793  const PMatrix3DData *it = &(itP->second);
2794  VRMLFile
2795  <<" "<<it->C[0]<<" "<<it->C[1]<<" "<<it->C[2]<< " , "<< endl
2796  <<" "<<it->UL[0]<<" "<<it->UL[1]<<" "<<it->UL[2] <<" , " <<endl
2797  <<" "<<it->UR[0]<<" "<<it->UR[1]<<" " <<it->UR[2]<<" , " << endl
2798  <<" "<<it->LR[0]<<" "<<it->LR[1]<<" " <<it->LR[2]<<" , " << endl
2799  <<" "<<it->LL[0]<<" "<<it->LL[1]<<" " <<it->LL[2]<<" , " << endl;
2800  num++;
2801  }
2802  VRMLFile<<" ] " << endl;
2803  VRMLFile <<" }" << std::endl;
2804  VRMLFile << " coordIndex [" << endl;
2805  for (unsigned int i=0;i<num; i++) {
2806  unsigned n=i*5;
2807  VRMLFile <<" "<<n<<", "<<n+2<<", "<<n+1<<", -1" <<endl;
2808  VRMLFile <<" "<<n<<", "<<n+1<<", "<<n+4<<", -1" <<endl;
2809  VRMLFile <<" "<<n<<", "<<n+4<<", "<<n+3<<", -1" <<endl;
2810  VRMLFile <<" "<<n<<", "<<n+3<<", "<<n+2<<", -1" <<endl;
2811  }
2812  VRMLFile << " ] " << endl;
2813  VRMLFile << " }" << endl; // terminates IndexedLineSet
2814  // set color of lines
2815  VRMLFile << " appearance Appearance { " << endl;
2816  VRMLFile << " material Material {"<<endl
2817  << " diffuseColor " << " "<<r<<" "<<g<<" "<<b<<endl
2818  << " emissiveColor " << " "<<r<<" "<<g<<" "<<b<<endl
2819  <<" }"<< endl; // terminates material
2820  VRMLFile << " }" << endl; // terminates appearance
2821  VRMLFile << "}" << endl; // terminates shape
2822  return 0;
2823 }
2824 
2826  const BIAS::RGBAuc &Color)
2827 {
2828  if (Params_.LineWidth < 1) return 0;
2829  double r = 0;
2830  double g = 0;
2831  double b = 0;
2832  //double transparency = 0;
2833  map<unsigned int, PMatrix3DData>::iterator itP;
2834  r = (double)Color[0] / 255.0;
2835  g = (double)Color[1] / 255.0;
2836  b = (double)Color[2] / 255.0;
2837  //transparency = VRMLtransparency(Color);
2838  unsigned int num=0;
2839  // first: one switch-case to write entry
2840  VRMLFile << "Shape {" << endl;
2841  VRMLFile << " geometry IndexedLineSet {" << endl;
2842  VRMLFile << " coord Coordinate {" << endl;
2843  VRMLFile << " point [" << endl;
2844  Vector3<double> up;
2845  // then: for-loop with switch-case to write cams efficient
2846  for (itP=mapPMatrices_.begin(); itP!=mapPMatrices_.end(); itP++){
2847  const PMatrix3DData *it = &(itP->second);
2848  // write the line
2849  up = it->C + it->Up;
2850  VRMLFile
2851  << " " <<up[0]<<" "<<up[1]<<" "<<up[2] <<", "<<endl
2852  << " " <<it->C[0]<<" "<<it->C[1]<<" "<<it->C[2]<<","<<endl
2853  << " " <<it->PP[0]<<" "<<it->PP[1]<<" "<<it->PP[2] <<", "<<endl;
2854  num++;
2855  }
2856  VRMLFile<< " ]" << endl;
2857  VRMLFile << " }"<<endl;
2858  VRMLFile << " coordIndex [ "<<endl;
2859  for (unsigned int i=0;i<num; i++)
2860  VRMLFile <<" "<<i*3<<" "<<i*3+1<<" "<<i*3+2<<" -1"<<endl;
2861  VRMLFile <<" ]"<< endl;
2862  VRMLFile << " color Color {"<<endl;
2863  VRMLFile << " color [ "<<endl;
2864  for (unsigned int i=0;i<num; i++)
2865  VRMLFile <<r<<" "<<g<<" "<<b<<", " <<r<<" "<<g<<" "<<b<<" ,"<<endl;
2866  VRMLFile << " ] "<<endl;
2867  VRMLFile << " }\n}\n}"<< endl;
2868  return 0;
2869 }
2870 
2872  const PMatrix3DData *it,
2873  double r,
2874  double g,
2875  double b,
2876  double transparency,
2877  bool CenterAsSphere){
2878  switch (Params_.CameraStyle) {
2879  case PyramidSolid:
2880  r = (double)it->Color[0] / 255.0;
2881  g = (double)it->Color[1] / 255.0;
2882  b = (double)it->Color[2] / 255.0;
2883  transparency = VRMLtransparency(it->Color);
2884 
2885  // create vrml model of camera
2886  VRMLFile << std::endl;
2887  // if (it->name.length()>0)
2888  // VRMLFile <<" DEF "<< it->name;
2889  VRMLFile << " Shape {" << std::endl;
2890 
2891  // write camera center and 4 points in the image plane
2892  if (it->name.length()>0)
2893  VRMLFile <<" geometry DEF "<<CorrectDefString_(it->name);
2894  else
2895  VRMLFile <<" geometry";
2896  VRMLFile <<" IndexedFaceSet {" << std::endl;
2897  VRMLFile <<" coord Coordinate {" << std::endl;
2898  VRMLFile <<" point [ " << std::endl;
2899  VRMLFile <<" "<<it->C[0]<<" "<<it->C[1]<<" "
2900  <<it->C[2]<< " , " << std::endl;
2901  VRMLFile <<" "<<it->UL[0]<<" "<<it->UL[1]
2902  <<" "<<it->UL[2] <<" , " <<std:: endl;
2903  VRMLFile <<" "<<it->UR[0]<<" "<<it->UR[1]<<" "
2904  <<it->UR[2]<<" , " << std::endl;
2905  VRMLFile <<" "<<it->LR[0]<<" "<<it->LR[1]<<" "
2906  <<it->LR[2]<<" , " << std::endl;
2907  VRMLFile <<" "<<it->LL[0]<<" "<<it->LL[1]<<" "
2908  <<it->LL[2] <<" ] " << std::endl;
2909 
2910  VRMLFile <<" }" << std::endl;
2911 
2912  // write triangulation for topology
2913  VRMLFile << " coordIndex [" << endl;
2914  VRMLFile << " 0, 2, 1, -1, " << std::endl;
2915  VRMLFile << " 0, 1, 4, -1, " << std::endl;
2916  VRMLFile << " 0, 4, 3, -1, " << std::endl;
2917  VRMLFile << " 0, 3, 2, -1, " << std::endl;
2918  VRMLFile << " 1, 2, 4, -1, " << std::endl;
2919  VRMLFile << " 4, 2, 3, -1 ]" << std::endl;
2920 
2921  VRMLFile << " }" << std::endl << std::endl; // terminates IndexedFaceSet
2922 
2923  VRMLFile << " appearance Appearance { " << endl;
2924 
2925  VRMLFile << " material Material { diffuseColor "
2926  << " "<<r<<" "<<g<<" "<<b<< std::endl //terminates material
2927  << " transparency "<< transparency
2928  <<"}"<<std::endl;
2929  VRMLFile << "} " << std::endl; // terminates appearance
2930  VRMLFile << " }" << std::endl; // terminates shape
2931 
2932  break;
2933  case PyramidMeshWithArrow:
2934  case PyramidMesh:
2935  if (Params_.LineWidth < 1) return 0;
2936  r = (double)it->Color[0] / 255.0;
2937  g = (double)it->Color[1] / 255.0;
2938  b = (double)it->Color[2] / 255.0;
2939 
2940  // create vrml model of camera
2941  VRMLFile << endl;
2942  VRMLFile << "Shape {" << endl;
2943 
2944  // write camera center and 4 points in the image plane
2945  VRMLFile <<" geometry IndexedLineSet {" << endl;
2946  VRMLFile <<" coord Coordinate {" << endl;
2947  VRMLFile <<" point [ " << endl;
2948  VRMLFile <<" "<<it->C[0]<<" "<<it->C[1]<<" "
2949  <<it->C[2]<< " , " << endl;
2950  VRMLFile <<" "<<
2951  it->C[0]+Params_.CameraScale*(it->UL[0]-it->C[0]) <<" "<<
2952  it->C[1]+Params_.CameraScale*(it->UL[1]-it->C[1]) <<" "<<
2953  it->C[2]+Params_.CameraScale*(it->UL[2]-it->C[2]) <<" , " <<std:: endl;
2954  VRMLFile <<" "<<
2955  it->C[0]+Params_.CameraScale*(it->UR[0]-it->C[0])<<" "<<
2956  it->C[1]+Params_.CameraScale*(it->UR[1]-it->C[1])<<" "<<
2957  it->C[2]+Params_.CameraScale*(it->UR[2]-it->C[2])<<" , " << endl;
2958  VRMLFile <<" "<<
2959  it->C[0]+Params_.CameraScale*(it->LR[0]-it->C[0])<<" "<<
2960  it->C[1]+Params_.CameraScale*(it->LR[1]-it->C[1])<<" "<<
2961  it->C[2]+Params_.CameraScale*(it->LR[2]-it->C[2])<<" , " << endl;
2962  VRMLFile <<" "<<
2963  it->C[0]+Params_.CameraScale*(it->LL[0]-it->C[0])<<" "<<
2964  it->C[1]+Params_.CameraScale*(it->LL[1]-it->C[1])<<" " <<
2965  it->C[2]+Params_.CameraScale*(it->LL[2]-it->C[2]) <<" ] " << endl;
2966  VRMLFile <<" }" << std::endl;
2967 
2968  // conect the points with lines
2969  VRMLFile << " coordIndex [" << endl;
2970  VRMLFile << " 0, 2, 1, -1, " << endl;
2971  VRMLFile << " 0, 1, 4, -1, " << endl;
2972  VRMLFile << " 0, 4, 3, -1, " << endl;
2973  VRMLFile << " 0, 3, 2, -1] " << endl;
2974  VRMLFile << " }" << endl; // terminates IndexedLineSet
2975 
2976  // set color of lines
2977  VRMLFile << " appearance Appearance { " << endl;
2978  VRMLFile << " material Material {"<<endl
2979  << " diffuseColor " << " "<<r<<" "<<g<<" "<<b<<endl
2980  << " emissiveColor " << " "<<r<<" "<<g<<" "<<b<<endl
2981  <<" }"<< endl; // terminates material
2982  VRMLFile << " }" << endl; // terminates appearance
2983  VRMLFile << "}" << endl; // terminates shape
2985  case Arrow:
2986  r = (double)it->Color[0] / 255.0;
2987  g = (double)it->Color[1] / 255.0;
2988  b = (double)it->Color[2] / 255.0;
2989 
2990  if (CenterAsSphere) {
2991  VRMLFile << "Transform {"<<endl;
2992  VRMLFile << " translation "
2993  << it->C[0] << " " <<it->C[1] << " " <<it->C[2]
2994  << endl;
2995  VRMLFile << " children ";
2996  VRMLFile <<" Shape {"<<endl;
2997  VRMLFile << " appearance Appearance { " << endl;
2998  VRMLFile << " material Material { " << endl;
2999  VRMLFile << " transparency "
3000  << VRMLtransparency(it->Color) <<endl;
3001  VRMLFile << " diffuseColor " << r << " " << g << " "<<b << endl;
3002  VRMLFile << " }" << endl; // close Material
3003  VRMLFile << " }" << endl; // close Appearance
3004  VRMLFile << " geometry Sphere { radius "
3005  << 0.1*(it->C-it->PP).NormL2()<<" }"
3006  << endl;
3007  VRMLFile << " }" << endl; // close Shape
3008  VRMLFile << "}" << endl; // close transform
3009  } else {
3010  // write the point
3011  VRMLFile << "Shape {" << endl;
3012  VRMLFile << " geometry PointSet {"<<endl;
3013  VRMLFile << " coord Coordinate {"<<endl;
3014  VRMLFile << " point ["<<it->C[0]<<" "<<it->C[1]<<" "<<it->C[2]
3015  <<"]" << endl << " }"<<endl;
3016  VRMLFile << " color Color { color [ 0 1 0, 0 1 0 ] }"<<endl;
3017  VRMLFile << " }\n}"<<endl;
3018  }
3019 
3020  // write the line
3021  VRMLFile << "Shape {" << endl;
3022  VRMLFile << " geometry IndexedLineSet {" << endl;
3023  VRMLFile << " coord Coordinate {" << endl;
3024  VRMLFile << " point [" << endl;
3025  VRMLFile << " " <<it->C[0]<<" "<<it->C[1]<<" "
3026  <<it->C[2]<<","<<endl;
3027  VRMLFile << " " <<it->PP[0]<<" "<<it->PP[1]<<" "
3028  <<it->PP[2] << " ]" << endl;
3029  VRMLFile << " }"<<endl;
3030  VRMLFile << " coordIndex [ 0 1 -1 ]"<< endl;
3031  VRMLFile << " color Color {"<<endl;
3032  VRMLFile << " color [ "<<r<<" "<<g<<" "<<b<<", "
3033  <<r<<" "<<g<<" "<<b<<" ] "<<endl;
3034  VRMLFile << " }\n}\n}"<< endl;
3035 
3036  break;
3037  default: BIASERR("Desired Camera drawing style is not implemented."
3038  <<" Skipping Cameras.");
3039  return -1;
3040  }
3041  return 0;
3042 }
3043 
3044 int ThreeDOut::VRMLOutPMatrices(ostream& VRMLFile){
3045  double r = 0;
3046  double g = 0;
3047  double b = 0;
3048  double transparency = 0;
3049  bool CenterAsSphere = true;
3050  map<unsigned int, PMatrix3DData>::iterator itP;
3051  for (itP=mapPMatrices_.begin(); itP!=mapPMatrices_.end(); itP++){
3052  const PMatrix3DData *it = &(itP->second);
3053 
3054  if(VRMLOutPMatricesRoutine(VRMLFile,
3055  it, r, g, b,
3056  transparency, CenterAsSphere) != 0)
3057  return -1;
3058 
3060  map<unsigned int, Ellipsoid3DData>::iterator mit;
3061  for (mit=mapCamEllipsoids_.begin(); mit!=mapCamEllipsoids_.end();mit++) {
3062  Ellipsoid3DData& E = mit->second;
3063  VRMLOutEllipsoid_(VRMLFile, E, it->Color);
3064  }
3065  }
3066  }
3067 
3068  return 0;
3069 }
3070 
3071 
3072 int ThreeDOut::VRMLOutLines(ostream& VRMLFile, const BIAS::RGBAuc &Color){
3073  if (Params_.LineWidth < 1) return 0;
3074  double r = (double)Color[0] / 255.0;
3075  double g = (double)Color[1] / 255.0;
3076  double b = (double)Color[2] / 255.0;
3077  // double a = (double)it->second.Color[3] / 255.0;
3078  switch (Params_.LineStyle) {
3079  case Solid:
3080  for (map<unsigned int, Line3DData>::iterator it=mapLines_.begin();
3081  it!=mapLines_.end(); it++) {
3082  VRMLFile << std::endl;
3083  VRMLFile << " Shape {" << std::endl;
3084  VRMLFile <<" geometry IndexedLineSet {" << std::endl;
3085  VRMLFile <<" coord Coordinate {" << std::endl;
3086  VRMLFile <<" point [ " << std::endl;
3087  VRMLFile <<" "<<it->second.Start[0]<<" "
3088  << it->second.Start[1]<<" " <<it->second.Start[2]<< " , "
3089  << std::endl;
3090  VRMLFile <<" "<<it->second.End[0]<<" "
3091  <<it->second.End[1] <<" "<<it->second.End[2] <<" ] "<<std::endl;
3092 
3093  VRMLFile <<" }" << std::endl;
3094  VRMLFile << " coordIndex [ 0, 1, -1 ]" << std::endl;
3095  VRMLFile << " color Color {" << std::endl;
3096  VRMLFile <<" color [ "<<r<<" "<<g<<" "<<b<<" ]"<<std::endl;
3097  VRMLFile << " } " <<std:: endl; // terminates Color
3098  VRMLFile << " colorPerVertex FALSE " << std::endl;
3099  VRMLFile << " }" << std::endl << std::endl; // terminates IndexedLineSet
3100  VRMLFile << " }" << std::endl; // terminates shape
3101  }
3102  break;
3103  default: BIASERR("Unsupported LineStyle, line drawing disabled."); return -1;
3104  }
3105  return 0;
3106 }
3107 
3108 int ThreeDOut::VRMLOutProjection(ostream& VRMLFile)
3109 {
3110  double r, g, b;
3111  map<unsigned int, Projection3DData>::iterator it;
3112 
3113  /** VIEWPORT PART, DUE TO BE IMPLEMENTED
3114 
3115  **/
3116 
3117  for(it=mapProjection3D_.begin(); it!=mapProjection3D_.end(); it++) {
3118  r = (double)it->second.ColorOfSelection[0] / 255.0;
3119  g = (double)it->second.ColorOfSelection[1] / 255.0;
3120  b = (double)it->second.ColorOfSelection[2] / 255.0;
3121  VRMLFile <<"\t Transform {"<<std::endl;
3122  VRMLFile <<"\t translation "
3123  <<it->second.C[0]<<" "<<it->second.C[1]<<" "<<it->second.C[2]
3124  <<std::endl;
3125 
3126  VRMLFile <<"\t rotation "
3127  <<it->second.axis[0]<<" "<<it->second.axis[1]
3128  <<" "<<it->second.axis[2]<<" "<<it->second.angle
3129  <<std::endl;
3130  VRMLFile <<"\t children ["<<std::endl;
3131  CoordinateSystem(VRMLFile,
3132  (float)it->second.radiusSelection,
3133  (float)r, (float)g, (float)b, 1.0f,
3134  it->second.scale,
3135  it->second.identifier);
3136 
3137  //If we want to visualize viewports
3140  //PERSPECTIVE CAMERA
3141  if(it->second.type == 0){
3142  //View The perspective-Camera-View, Pyramid Type
3143  VRMLOutViewPortPyramidal (VRMLFile,
3144  it->second.radiusSelection,
3145  r, g, b,
3146  it->second.angle,
3147  it->second.ratio,
3148  it->second.scale,
3149  it->second.identifier);
3150  }
3151 
3152  //NON-PERSPECTIVE CAMERA
3153  if(it->second.type == 1){
3154  cout<<" trying to build conical camera rep:\n! ";
3155  //View The non-perspective-Camera-View, Conical Type
3156  VRMLOutViewPortConical (VRMLFile,
3157  it->second.radiusSelection,
3158  r, g, b,
3159  it->second.angle,
3160  it->second.scale,
3161  it->second.identifier);
3162  }
3163  }
3164 
3166  //PERSPECTIVE CAMERA
3167  if(it->second.type == 0){
3168  //View The perspective-Camera-View, Pyramid Type
3169  VRMLOutViewPortPyramidal (VRMLFile,
3170  it->second.radiusSelection,
3171  r, g, b,
3172  it->second.angle,
3173  it->second.ratio,
3174  it->second.scale,
3175  it->second.identifier,
3176  true);
3177  }
3178 
3179  //NON-PERSPECTIVE CAMERA
3180  if(it->second.type == 1){
3181  //View The non-perspective-Camera-View, Conical Type
3182  VRMLOutViewPortConical (VRMLFile,
3183  it->second.radiusSelection,
3184  r, g, b,
3185  it->second.angle,
3186  it->second.scale,
3187  it->second.identifier,
3188  true);
3189  }
3190  }
3191 
3192  VRMLFile <<"\t ]"<<std::endl;
3193  VRMLFile <<"\t }"<<std::endl;
3194  }
3195 
3196  /** VIEWPORT PART, DUE TO BE IMPLEMENTED
3197 
3198  **/
3199 
3200  return 0;
3201 }
3202 
3204 {
3205  map<unsigned int, IndexedFaceSet>::iterator it;
3206  for (it = mapIndexedFaceSet_.begin(); it!=mapIndexedFaceSet_.end(); it++) {
3207  if (it->second.vertexSet.empty()) continue;
3208  VRMLFile << std::endl;
3209  VRMLFile <<"Transform { scale 1 1 1"<<endl<<" children [ "<<endl;
3210  VRMLFile << " Shape {" << std::endl;
3211  //define apperance
3212 
3213  VRMLFile << " appearance Appearance { " << std::endl;
3214  if (it->second.texture.GetSize() == 0) {
3215  VRMLFile << " material Material { diffuseColor 0.8 0.8 0.8 } "<<endl;
3216  } else {
3217  VRMLFile << "# enable this line and disable the texture below to see"
3218  << " an untextured model with normals "<<endl;
3219  VRMLFile << "# material Material { diffuseColor 0.8 0.8 0.8 } "<<endl;
3220  //adding texture
3221  VRMLFile << "# enable this line to see a textured model "<<endl;
3222  VRMLFile << " texture ";
3223  if(it->second.textureName == "") {
3224  VRMLFile << "PixelTexture {" << std::endl;
3225  //fill in PixelTexture Size and colors in hex?
3226  VRMLFile << " image "
3227  <<it->second.texture.GetWidth()<<" "
3228  <<it->second.texture.GetHeight()<<" "
3229  <<it->second.texture.GetChannelCount()<<std::endl;
3230  unsigned int channelColor;
3231  unsigned int writeCounter = 0;
3232  for (int h=it->second.texture.GetHeight()-1; h>=0; h--) {
3233  VRMLFile << " ";
3234  for(unsigned int w=0; w<it->second.texture.GetWidth(); w++) {
3235  VRMLFile <<"0x";
3236  for(unsigned int c=0; c<it->second.texture.GetChannelCount(); c++) {
3237  channelColor= it->second.texture.PixelValue(w,h,(unsigned short)c);
3238  VRMLFile.flags(ios_base::hex);
3239  VRMLFile.fill('0');
3240  VRMLFile.width(2);
3241  VRMLFile<<channelColor;
3242  }
3243  writeCounter++;
3244  if(writeCounter>=8) {
3245  VRMLFile<<std::endl;
3246  writeCounter=0;
3247  }
3248  VRMLFile.flags(ios_base::dec);
3249  VRMLFile <<" ";
3250  }
3251  VRMLFile<<std::endl;
3252  }
3253  VRMLFile.flags(ios_base::dec);
3254  VRMLFile << " } " << endl;//end PixelTexture
3255  }//end if textureName == ""
3256  else {//textureName != ""
3257  // ImageTexture { url "./thermae.ppm" }
3258  VRMLFile << "ImageTexture { url \""<<it->second.textureName;
3259  VRMLFile << "\" } " << endl;//end ImageTexture
3260  if(it->second.writeOutTexture)
3261  ImageIO::Save(it->second.textureName, it->second.texture);
3262  }
3263  } // end if GetSize() == 0
3264  VRMLFile <<" }" << endl;//end appearance
3265  //define geometry
3266  if (it->second.name.length()>0)
3267  VRMLFile << " geometry DEF "<<CorrectDefString_(it->second.name);
3268  else
3269  VRMLFile << " geometry";
3270  VRMLFile <<" IndexedFaceSet { " << std::endl;
3271  //write all vertex coordinates
3272  VRMLFile << " coord Coordinate {" << std::endl;
3273  VRMLFile << " point [ " << std::endl;
3274  {
3275  const int vnum = int(it->second.vertexSet.size());
3276  for(int i = 0; i < vnum; i++) {
3277  VRMLFile << " "
3278  << it->second.vertexSet[i][0] << " "
3279  << it->second.vertexSet[i][1] << " "
3280  << it->second.vertexSet[i][2]
3281  << (((i+1) == vnum) ? " ] " : ", ") << std::endl;
3282  }
3283  }
3284  VRMLFile <<" } " << std::endl; //closing coord
3285 
3286  if (it->second.texture.GetSize() != 0) {
3287 
3288  //write all texture coordinates
3289  VRMLFile << " texCoord TextureCoordinate { " << std::endl;
3290  VRMLFile << " point [ " << std::endl;
3291  const int vnum = int(it->second.texCoordSet.size());
3292  for(int i = 0; i < vnum; i++) {
3293  VRMLFile << " "
3294  << it->second.texCoordSet[i][0] << " "
3295  << it->second.texCoordSet[i][1]
3296  << (((i+1) == vnum) ? " ] " : ", ") << std::endl;
3297  }
3298  VRMLFile <<" }" << std::endl; //closing texCoord
3299  } // end if GetSize() == 0
3300 #ifdef BIAS_HAVE_OPENGL
3301  // for now normals are only defined if OpenGL is enabled
3302  if (it->second.NormalArray != NULL) {
3303  VRMLFile << " normal Normal {" << std::endl
3304  << " vector [ " << std::endl;
3305  float *pData = it->second.NormalArray;
3306  const int vnum = int(it->second.vertexSet.size());
3307  for(int i = 0; i < vnum; i++) {
3308  VRMLFile << " " << *pData++;
3309  VRMLFile << " " << *pData++;
3310  VRMLFile << " " << *pData++;
3311  VRMLFile << (((i+1) == vnum) ? " ] " : ", ") << std::endl;
3312  }
3313  VRMLFile << " }" << endl; //closing normal
3314  }
3315 #endif
3316  //define faces per indices
3317  VRMLFile << " coordIndex [ " << std::endl;
3318  {
3319  const int vnum = int(it->second.faceIndices.size());
3320  for(int i = 0; i < vnum; i++) {
3321  VRMLFile << " ";
3322  for(int j = 0; j < (it->second.faceIndices[i]).size(); j++)
3323  VRMLFile << it->second.faceIndices[i][j] << ", ";
3324  VRMLFile << " -1 " << (((i+1) == vnum) ? " ] " : ", ") << std::endl;
3325  }
3326  }
3327 
3328  VRMLFile <<" }" << std::endl;//closing IndexedFaceSet
3329  VRMLFile <<" }" << std::endl;//closing SHAPE
3330  VRMLFile <<" ] "<<std:: endl <<"} "<<std::endl;// end tranform , end children
3331  }
3332  return 0;
3333 }
3334 
3335 int ThreeDOut::VRMLOutImages(ostream& VRMLFile)
3336 {
3337  map<unsigned int, Image3DData>::iterator it;
3338  for (it = mapImages_.begin(); it!=mapImages_.end(); it++) {
3339  Vector3<double> Center(0.25*(it->second.UL + it->second.LR +
3340  it->second.LL + it->second.UR));
3341 
3342  VRMLFile << "Transform { "<<endl;
3343 
3344  //VRMLFile << " center "
3345  // <<Center[0]<<" "<<Center[1]<<" "<<Center[2]<<endl;
3346  //VRMLFile << " rotation 0 1 0 1.57 # [-1,1],(-,) "<<endl;
3347  //VRMLFile << " scale 1 1 1 # (0,) "<<endl;
3348  //VRMLFile << " scaleOrientation 0 0 1 0 # [-1,1],(-,) "<<endl;
3349 
3350  VRMLFile << " translation "<< Center[0]<<" "<< Center[1]<<" "<< Center[2] <<endl;
3351  VRMLFile << " children [ "<<endl;
3352 
3353  if (it->second.name != "") {
3354  VRMLFile << " Transform { "<<endl;
3355  //VRMLFile << " center "
3356  // <<Center[0]<<" "<<Center[1]<<" "<<Center[2]<<endl;
3357 
3358  VRMLFile << " rotation 1 0 0 -1.57 # [-1,1],(-,) "<<endl;
3359  //VRMLFile << " scale 1 1 1 # (0,) "<<endl;
3360  //VRMLFile << " scaleOrientation 0 0 1 0 # [-1,1],(-,) "<<endl;
3361  //VRMLFile << " translation "<< Center[0]<<" "<< Center[1]<<" "<<Center[2]<<endl;
3362  VRMLFile << " children [ "<<endl;
3363 
3364  VRMLFile << " Text { "<<endl;
3365  VRMLFile << " string \"" <<it->second.name <<"\" "<<endl;
3366  //VRMLFile << " exposedField SFNode fontStyle NULL"<<endl;
3367  // VRMLFile << " exposedField MFFloat length [] # [0,)"<<endl;
3368  // VRMLFile << " exposedField SFFloat maxExtent 0.0 # [0,)"<<endl;
3369  VRMLFile << " }"<<endl;
3370  VRMLFile<<" ]"<<endl;
3371  VRMLFile << " }"<<endl;
3372  }
3373 
3374  if (it->second.BillBoard)
3375  {
3376  Vector3<double> diag1(it->second.UL - it->second.LR),
3377  diag2(it->second.LL - it->second.UR);
3378  diag1.Normalize();
3379  diag2.Normalize();
3381  RotAx(diag1.CrossProduct(diag2).CrossProduct(Vector3<double>(0,1,0)));
3382  //double angle = 0;
3383  if (RotAx.NormL2()>1e-8) {
3384  // angle = arcsin(RotAx.NormL2());
3385  BIASERR("Billboard must lie in xz plane !!!");
3386  }
3387 
3388  Vector3<double> AxisOfRotation1(0,0,0);
3389  VRMLFile << std::endl;
3390  VRMLFile << "Billboard { "<<endl;
3391  if (AxisOfRotation1.NormL2()>0.0) AxisOfRotation1.Normalize();
3392  VRMLFile << " axisOfRotation "<< AxisOfRotation1[0]<<" "
3393  << AxisOfRotation1[1]<<" "<< AxisOfRotation1[2]
3394  <<" " <<endl;
3395 
3396  VRMLFile << " children [ "<<endl;
3397  }
3398 
3399  VRMLFile << std::endl;
3400  VRMLFile << " Shape { " << std::endl;
3401  ////////////////////////////////////////
3402  VRMLFile << " appearance Appearance { " << std::endl;
3403  VRMLFile << " material Material { "<<endl;
3404  VRMLFile << " diffuseColor 0.2 0.2 0.2 # MFColor"<<endl;
3405  VRMLFile << " specularColor 0 0 0 # MFColor"<<endl;
3406  VRMLFile << " emissiveColor 0.2 0.2 0.2 # MFColor"<<endl;
3407  VRMLFile << " shininess 0 # MFFloat"<<endl;
3408  VRMLFile << " transparency 0 # MFFloat "<<endl;
3409  VRMLFile << " } "<<endl;
3410  VRMLFile << " } " << std::endl;
3411  //////////////////////////////////////////////////
3412 
3413  // write a indexedfaceset as the pixel grid, first all grid points
3414  if (it->second.name.length()>0)
3415  VRMLFile <<" geometry DEF "<<CorrectDefString_(it->second.name)
3416  <<" IndexedFaceSet {"
3417  << std::endl;
3418  else
3419  VRMLFile <<" geometry IndexedFaceSet {" << std::endl;
3420  VRMLFile <<" coord Coordinate {" << std::endl;
3421  VRMLFile <<" point [ " << std::endl;
3422 
3423  // get roi which is the original image
3424  // ImageData may be larger, because it is padded to power of two
3425  unsigned int x1,y1,x2,y2;
3426  it->second.ImageData.GetROI()->GetCorners(x1,y1,x2,y2);
3427  const unsigned int width = x2;
3428  const unsigned int height = y2;
3429  for (unsigned int y=0; y<=height; y++) {
3430  for (unsigned int x=0; x<=width; x++) {
3431 
3432  const double xfrac = double(x) / double(width);
3433  const double yfrac = double(y) / double(height);
3434 
3435  //const double xfrac = (double(x)-0.5) / double(width-1);
3436  //const double yfrac = (double(y)-0.5) / double(height-1);
3437  Vector3<double> CurPoint(it->second.UL +
3438  xfrac*(it->second.UR-it->second.UL)+
3439  yfrac*( (1.0-xfrac) *
3440  (it->second.LL-it->second.UL)+
3441  xfrac*(it->second.LR-it->second.UR)));
3442  VRMLFile <<" "
3443  << CurPoint[0]-Center[0]<<" "<<CurPoint[1]-Center[1]
3444  <<" "<<CurPoint[2]-Center[2]
3445  << ((y == height && x == width) ? " ] " : ", ")
3446  << std::endl;
3447  }
3448  }
3449  VRMLFile <<" } " << std::endl;
3450  // now all the faces, the 3d pixels:
3451  VRMLFile <<" coordIndex [ " << endl;
3452  for (unsigned int x=0; x<width;x++) {
3453  for (unsigned int y=0; y<height;y++) {
3454  VRMLFile <<" "<< (x+y*(width+1)) << ", ";
3455  VRMLFile << (x+1+y*(width+1)) << ", ";
3456  VRMLFile << (x+1+(y+1)*(width+1)) <<", ";
3457  VRMLFile << (x+(y+1)*(width+1)) <<", -1"
3458  << (((y+1) == height && (x+1) == width) ? " ] " : ", ")
3459  << std::endl;
3460  }
3461  }
3462 
3463  // set color of the points
3464  VRMLFile << " color Color {" << std::endl;
3465  VRMLFile << " color [ " << std::endl;
3466  unsigned char** ppData = it->second.ImageData.GetImageDataArray();
3467  double r = 1.0;
3468  double g = 1.0;
3469  double b = 1.0;
3470  for (unsigned int x=0; x<width; x++) {
3471  for (unsigned int y=0; y<height; y++) {
3472  if (it->second.ImageData.GetChannelCount()==1) {
3473  r = g = b = ((double)ppData[y][x])/ 255.0;;
3474  } else if (it->second.ImageData.GetChannelCount()==3) {
3475  r = (double)ppData[y][3*x] / 255.0;
3476  g = (double)*(&(ppData[y][3*x])+1) / 255.0;
3477  b = (double)*(&(ppData[y][3*x])+2) / 255.0;
3478  } else {
3479  BIASERR("Not grey or rgb, cannot display !");
3480  }
3481  VRMLFile << " "<<r<<" "<<g<<" "<<b
3482  << (((y+1) == height && (x+1) == width) ? " ] " : ", ")
3483  << std::endl;
3484  }
3485  }
3486  VRMLFile << " } " <<std:: endl; // terminates Color
3487  VRMLFile << " colorPerVertex FALSE " <<std:: endl;
3488  VRMLFile << " } " << std::endl;
3489  VRMLFile << " } " << std::endl;
3490  if (it->second.BillBoard) {
3491  VRMLFile<<" ] "<<endl;
3492  VRMLFile<<"} " <<endl;
3493 
3494  }
3495  VRMLFile<<" ] "<<endl;
3496  VRMLFile << "} "<<endl;
3497  }
3498  return 0;
3499 }
3500 
3501 
3502 int ThreeDOut::VRMLOutLines(ostream& VRMLFile){
3503  if (Params_.LineWidth < 1) return 0;
3504  switch (Params_.LineStyle) {
3505  case Solid:
3506  for (map<unsigned int, Line3DData>::iterator it=mapLines_.begin();
3507  it!=mapLines_.end(); it++) {
3508  double r = (double)it->second.Color[0] / 255.0;
3509  double g = (double)it->second.Color[1] / 255.0;
3510  double b = (double)it->second.Color[2] / 255.0;
3511  // double a = (double)it->second.Color[3] / 255.0;
3512  VRMLFile << std::endl;
3513  VRMLFile << "Shape { "<<endl;
3514  VRMLFile << " appearance Appearance { " << endl;
3515  VRMLFile << " material Material { " << endl;
3516  VRMLFile << " transparency "<<VRMLtransparency(it->second.Color)<< endl;
3517  VRMLFile << " emissiveColor " << r << " "<< g<< " "<<b << endl
3518  << " } " << endl
3519  << " } "<<endl;
3520 
3521  VRMLFile <<" geometry IndexedLineSet { " << std::endl;
3522  VRMLFile <<" coord Coordinate { " << std::endl;
3523  VRMLFile <<" point [ " << std::endl;
3524  VRMLFile <<" "<<it->second.Start[0]<<" "
3525  << it->second.Start[1]<<" " <<it->second.Start[2]<< " , "
3526  << std::endl;
3527  VRMLFile <<" "<<it->second.End[0]<<" "
3528  <<it->second.End[1] <<" "<<it->second.End[2] <<" ] "<<std::endl;
3529 
3530  VRMLFile <<" } " << std::endl;
3531  VRMLFile <<" coordIndex [ 0, 1, -1 ] " << std::endl;
3532  VRMLFile <<" color Color { " << std::endl;
3533  VRMLFile <<" color [ "<<r<<" "<<g<<" "<<b<<" ] "<<std::endl;
3534  VRMLFile <<" } " <<std:: endl;
3535 
3536  VRMLFile <<" colorPerVertex FALSE " << std::endl;
3537  VRMLFile <<" } " << std::endl;
3538  VRMLFile <<"} " << std::endl;
3539  }
3540  break;
3541  default:
3542  BIASERR("Unsupported LineStyle, line drawing disabled.");
3543  return -1;
3544  }
3545  return 0;
3546 }
3547 
3548 
3550  const BIAS::RGBAuc &Color)
3551 {
3552  VRMLFile << "Transform { "<<endl;
3553  VRMLFile << " scaleOrientation "<< E.RotAxis[0] <<" "
3554  << E.RotAxis[1]<<" " <<E.RotAxis[2] <<" "<< E.dAngle <<" " << endl;
3555  VRMLFile << " scale "<< Params_.EllipsoidScale * E.s0 <<" "
3556  << Params_.EllipsoidScale * E.s1<< " "
3557  << Params_.EllipsoidScale * E.s2 << "" << endl;
3558  VRMLFile << " translation "
3559  << E.C[0] << " " << E.C[1] << " " << E.C[2] << " " << endl;
3560  VRMLFile << " children Shape { "<<endl;
3561  VRMLFile << " appearance Appearance { " << endl;
3562  VRMLFile << " material Material { " << endl;
3563  VRMLFile << " transparency "<<VRMLtransparency(Color)<< endl;
3564  VRMLFile << " diffuseColor " << (double)Color[0]/255.0 << " "
3565  << (double)Color[1]/255.0<< " "
3566  << (double)Color[2]/255.0 << endl;
3567  VRMLFile << " }" << endl; // close Material
3568  VRMLFile << " }" << endl; // close Appearance
3569  VRMLFile << " geometry Sphere { radius 1.0 }" << endl;
3570  VRMLFile << " }" << endl; // close Shape
3571  VRMLFile << "}" << endl; // close Transform
3572 }
3573 
3574 
3575 int ThreeDOut::VRMLOutEllipsoids(ostream& VRMLFile, const BIAS::RGBAuc &Color)
3576 {
3577  for (map<unsigned int, Ellipsoid3DData>::iterator it=mapEllipsoids_.begin();
3578  it!=mapEllipsoids_.end(); it++)
3579  {
3580  Ellipsoid3DData& E = it->second;
3581  VRMLOutEllipsoid_(VRMLFile, E, Color);
3582  }
3583  return 0;
3584 }
3585 
3586 
3587 int ThreeDOut::VRMLOutPointsAsSpheres_(std::ostream &VRMLFile)
3588 {
3589  double thesize = Params_.PointSize;
3590  for (map<unsigned int, Point3DData>::iterator it=mapPoints_.begin();
3591  it!=mapPoints_.end(); it++) {
3592  Point3DData& E = it->second;
3593  VRMLFile << "Transform {"<<endl;
3594  VRMLFile << " translation "
3595  << E.Point[0] << " " << E.Point[1] << " " << E.Point[2] << endl;
3596  VRMLFile << " children Shape {"<<endl;
3597  VRMLFile << " appearance Appearance { " << endl;
3598  VRMLFile << " material Material { " << endl;
3599  VRMLFile << " transparency "<<VRMLtransparency(E.Color)<<endl;
3600  VRMLFile << " diffuseColor "
3601  << (double)E.Color[0]/255.0 << " "
3602  << (double)E.Color[1]/255.0 << " "
3603  << (double)E.Color[2]/255.0 << endl;
3604  VRMLFile << " emissiveColor "
3605  << (double)E.Color[0]/255.0 << " "
3606  << (double)E.Color[1]/255.0 << " "
3607  << (double)E.Color[2]/255.0 << endl;
3608  VRMLFile << " }" << endl; // close Material
3609  VRMLFile << " }" << endl; // close Appearance
3610  VRMLFile << " geometry Sphere { radius "<<thesize<<" }" << endl;
3611  VRMLFile << " }" << endl; // close Shape
3612  VRMLFile << "}" << endl; // close transform
3613  }
3614  return 0;
3615 }
3616 
3617 
3618 int ThreeDOut::VRMLOutEllipsoids(ostream& VRMLFile)
3619 {
3620  for (map<unsigned int, Ellipsoid3DData>::iterator it=mapEllipsoids_.begin();
3621  it!=mapEllipsoids_.end(); it++) {
3622  Ellipsoid3DData& E = it->second;
3623  VRMLFile << "Transform {"<<endl;
3624  VRMLFile << " scaleOrientation "<< E.RotAxis[0] <<" "
3625  << E.RotAxis[1]<<" " <<E.RotAxis[2] <<" "<< E.dAngle <<" "
3626  << endl;
3627  VRMLFile << " scale "<< Params_.EllipsoidScale * E.s0 <<" "
3628  << Params_.EllipsoidScale * E.s1<< " "
3629  << Params_.EllipsoidScale * E.s2 << endl;
3630  VRMLFile << " translation "
3631  << E.C[0] << " " << E.C[1] << " " << E.C[2] << endl;
3632  VRMLFile << " children Shape { "<<endl;
3633  VRMLFile << " appearance Appearance { " << endl;
3634  VRMLFile << " material Material { " << endl;
3635  VRMLFile << " transparency "
3636  <<VRMLtransparency(E.Color)<<endl;
3637  VRMLFile << " diffuseColor " << (double)E.Color[0]/255.0 << " "
3638  << (double)E.Color[1]/255.0<< " "
3639  << (double)E.Color[2]/255.0 << endl;
3640  VRMLFile << " }" << endl; // close Material
3641  VRMLFile << " }" << endl; // close Appearance
3642  VRMLFile << " geometry Sphere { radius 1.0 }" << endl;
3643  VRMLFile << " }" << endl; // close Shape
3644  VRMLFile << "}" << endl; // close Transform
3645  }
3646  return 0;
3647 }
3648 
3649 
3650 int ThreeDOut::VRMLOut(const string &sFilename, const BIAS::RGBAuc &Color){
3651  ofstream VRMLFile;
3652  VRMLFile.open(sFilename.c_str());
3653  if (!VRMLFile) {
3654  BIASERR("Error opening VRML file for writing: "<<sFilename);
3655  return -1;
3656  }
3657  VRMLOutWriteHeader(VRMLFile);
3658  VRMLOutIndexedFaceSets(VRMLFile);
3659  VRMLOutEllipsoids(VRMLFile, Color);
3660  VRMLOutLines(VRMLFile, Color);
3661  VRMLOutPoints(VRMLFile, Color);
3662  VRMLOutImages(VRMLFile);
3663  VRMLOutPMatrices(VRMLFile, Color);
3664  if (Params_.WCSAxesLength>0.0) VRMLOutWCS(VRMLFile);
3665  VRMLFile.close();
3666  return 0 ;
3667 }
3668 
3669 
3670 int ThreeDOut::VRMLOut(const string &sFilename){
3671  ofstream VRMLFile;
3672  VRMLFile.open(sFilename.c_str());
3673  if (!VRMLFile) {
3674  BIASERR("Error opening VRML file for writing: "<<sFilename);
3675  return -1;
3676  }
3677 
3678  VRMLOutWriteHeader(VRMLFile);
3679  if (this->WriteViewpoints_)
3680  VRMLOutWriteViewpoint(VRMLFile);
3681 
3682  VRMLOutProjection(VRMLFile);
3683 
3684  VRMLOutIndexedFaceSets(VRMLFile);
3685  VRMLOutPoints(VRMLFile);
3686  VRMLOutEllipsoids(VRMLFile);
3687  VRMLOutLines(VRMLFile);
3688  VRMLOutImages(VRMLFile);
3689  VRMLOutPMatrices(VRMLFile);
3690  if (Params_.WCSAxesLength>0.0) VRMLOutWCS(VRMLFile);
3691  VRMLFile.close();
3692  return 0;
3693 }
3694 
3695 
3696 int ThreeDOut::VRMLOutWriteHeader(std::ostream& vrml){
3697  vrml << "#VRML V2.0 utf8" << endl;
3698  vrml << "# File written by Basic Image AlgorithmS (BIAS) library" << endl;
3699  vrml << "# http://www.mip.informatik.uni-kiel.de"
3700  <<endl;
3701  return 0;
3702 }
3703 
3704 // ------------------------------ other functions ----------------------------
3705 
3707  cout <<endl<< "Dumping ThreeDOut object:"<<endl;
3708  cout <<"Points: -----------------------------------------"<<endl;
3709  for(map<unsigned int, Point3DData>::iterator it = mapPoints_.begin();
3710  it != mapPoints_.end(); it++) {
3711  cout <<"["<<it->first<<"] "<<it->second.Point<<endl;
3712  }
3713  cout<<endl<< "Lines: ------------------------------------------"<<endl;
3714  for(map<unsigned int, Line3DData>::iterator it = mapLines_.begin();
3715  it != mapLines_.end(); it++) {
3716  cout <<"["<<it->first<<"] "<<it->second.Start<<" -> "
3717  <<it->second.End<<endl;
3718  }
3719  cout<<endl<< "PMatrices: -------------------------------------- "<<endl;
3720  unsigned int i=0;
3721  for(map<unsigned int, PMatrix3DData>::iterator
3722  it = mapPMatrices_.begin(); it != mapPMatrices_.end(); it++) {
3723  cout <<"["<<(i++)<<"] UL="<<it->second.UL<<" UR="<<it->second.UR
3724  <<" LL="<<it->second.LL<<" LR="
3725  <<it->second.LR<<" C="<<it->second.C<<endl;
3726  }
3727  cout<<endl<< "Ellipsoids: -------------------------------------"<<endl;
3728  for(map<unsigned int, Ellipsoid3DData>::iterator it = mapEllipsoids_.begin();
3729  it != mapEllipsoids_.end(); it++) {
3730  cout <<"["<<it->first<<"] Center at "<<it->second.C<<
3731  " size " <<it->second.s0<< " " << it->second.s1<< " " << it->second.s2 <<
3732  " color " << it->second.Color <<endl;
3733 
3734  }
3735  cout<<endl<<flush;
3736 
3737 }
3738 
3739 
3741  Vector3<double> center(0.0);
3742  unsigned int count=0;
3743  map<unsigned int, Point3DData>::iterator it;
3744  for (it=mapPoints_.begin(); it!=mapPoints_.end(); it++) {
3745  count ++;
3746  center += it->second.Point;
3747  }
3748  if(count > 0)
3749  center /= double(count);
3750  BIASWARN("The center of points cannot be determined, no points");
3751  return center;
3752 }
3753 
3754 
3755 void ThreeDOut::
3757 {
3758  for (unsigned int i=0;i<3; i++) {
3759  min[i] = DBL_MAX;
3760  max[i] = -DBL_MAX;
3761  }
3762 
3763  map<unsigned int, Point3DData>::const_iterator it;
3764  for (it=mapPoints_.begin(); it!=mapPoints_.end(); it++) {
3765  for (unsigned int i=0;i<3; i++) {
3766  if (it->second.Point[i] < min[i]) min[i] = it->second.Point[i];
3767  if (it->second.Point[i] > max[i]) max[i] = it->second.Point[i];
3768  }
3769  }
3770 
3771 
3772  map<unsigned int, PMatrix3DData >::const_iterator pit;
3773  for (pit=mapPMatrices_.begin(); pit!=mapPMatrices_.end(); pit++){
3774  for (unsigned int i=0;i<3; i++) {
3775  if (pit->second.C[i] < min[i]) min[i] = pit->second.C[i];
3776  if (pit->second.C[i] > max[i]) max[i] = pit->second.C[i];
3777  }
3778  }
3779 
3780  map<unsigned int, IndexedFaceSet>::const_iterator fit;
3781  for (fit=mapIndexedFaceSet_.begin(); fit != mapIndexedFaceSet_.end(); fit++){
3782  const Vector3<double> &fmin(fit->second.bbmin);
3783  const Vector3<double> &fmax(fit->second.bbmax);
3784  for (unsigned int i=0;i<3; i++) {
3785  if (fmin[i] < min[i]) min[i] = fmin[i];
3786  if (fmax[i] > max[i]) max[i] = fmax[i];
3787  }
3788  }
3789 
3790  for (std::map<unsigned int, Image3DData>::iterator it= mapImages_.begin();
3791  it != mapImages_.end(); it++) {
3792  for (unsigned int i=0;i<3; i++) {
3793  if (it->second.UL[i]<min[i]) min[i] = it->second.UL[i];
3794  if (it->second.UR[i]<min[i]) min[i] = it->second.UR[i];
3795  if (it->second.LL[i]<min[i]) min[i] = it->second.LL[i];
3796  if (it->second.LR[i]<min[i]) min[i] = it->second.LR[i];
3797  if (it->second.UL[i]>max[i]) max[i] = it->second.UL[i];
3798  if (it->second.UR[i]>max[i]) max[i] = it->second.UR[i];
3799  if (it->second.LL[i]>max[i]) max[i] = it->second.LL[i];
3800  if (it->second.LR[i]>max[i]) max[i] = it->second.LR[i];
3801  }
3802  }
3803 
3804  for (std::map<unsigned int, Line3DData>::iterator it= mapLines_.begin();
3805  it !=mapLines_.end() ; it++) {
3806  for (unsigned int i=0;i<3; i++) {
3807  if (it->second.Start[i] < min[i]) min[i] = it->second.Start[i];
3808  if (it->second.Start[i] > max[i]) max[i] = it->second.Start[i];
3809  if (it->second.End[i] < min[i]) min[i] = it->second.End[i];
3810  if (it->second.End[i] > max[i]) max[i] = it->second.End[i];
3811  }
3812  }
3813 
3814 
3815  for (std::map<unsigned int, Ellipsoid3DData>::iterator pit=
3816  mapEllipsoids_.begin(); pit != mapEllipsoids_.end(); pit++) {
3817  double isoscale = pit->second.s0;
3818  if (pit->second.s1>isoscale) isoscale=pit->second.s1;
3819  if (pit->second.s2>isoscale) isoscale=pit->second.s2;
3820  for (unsigned int i=0;i<3; i++) {
3821  if (pit->second.C[i]-isoscale < min[i]) min[i] =
3822  pit->second.C[i]-isoscale;
3823  if (pit->second.C[i]+isoscale > max[i]) max[i] =
3824  pit->second.C[i]+isoscale;
3825  }
3826  }
3827 
3828  for (std::map<unsigned int, Ellipsoid3DData>::iterator pit=
3829  mapCamEllipsoids_.begin(); pit != mapCamEllipsoids_.end(); pit++) {
3830  double isoscale = pit->second.s0;
3831  if (pit->second.s1>isoscale) isoscale=pit->second.s1;
3832  if (pit->second.s2>isoscale) isoscale=pit->second.s2;
3833  for (unsigned int i=0;i<3; i++) {
3834  if (pit->second.C[i]-isoscale < min[i]) min[i] =
3835  pit->second.C[i]-isoscale;
3836  if (pit->second.C[i]+isoscale > max[i]) max[i] =
3837  pit->second.C[i]+isoscale;
3838  }
3839  }
3840 
3841 
3842  if (mapPMatrices_.empty() && mapPoints_.empty()
3843  && mapIndexedFaceSet_.empty() && mapLines_.empty() &&
3844  mapCamEllipsoids_.empty() && mapEllipsoids_.empty() &&
3845  mapImages_.empty()){
3846  // BIASERR("empty bounding box in threedout object");
3847  for (unsigned int i=0;i<3; i++) {
3848  min[i] = 0;
3849  max[i] = -0;
3850  }
3851  }
3852 }
3853 
3854 
3856  RemoveAllPoints();
3857  RemoveAllLines();
3859  RemoveAllImages();
3863 }
3864 
3865 // OpenGL interpretes alpha as opacity
3866 // while VRML uses its inverse, transaparency
3867 double ThreeDOut::VRMLtransparency(const unsigned char alpha){
3868  // our alpha stores opacity (as in GL)
3869  // but VRML uses transparency and normalized scaling
3870  return double( (255.0-double(alpha)) / 255.0 );
3871 }
3872 
3874  return VRMLtransparency( vRgba[3] );
3875 }
3876 
3877 
3878 void ThreeDOut::SetWriteViewpoints(const bool & val){
3879  this->WriteViewpoints_ = val;
3880 }
3881 
3882 
3884 {
3885  vrml<<"NavigationInfo {"<<endl;
3886  vrml<<" avatarSize [0.1, 0.1, 0.1]"<<endl;
3887  vrml<<" headlight TRUE"<<endl;
3888  vrml<<" type [ \"EXAMINE\", \"ANY\" ]"<<endl;
3889  vrml<<" visibilityLimit 0.0"<<endl;
3890  vrml<<"}"<<endl;
3891 }
3892 
3893 
3894 void ThreeDOut::VRMLOutWriteViewpoint(std::ostream& vrml)
3895 {
3897 
3898  map<unsigned int, PMatrix3DData>::iterator itP = mapPMatrices_.begin();
3899  //Vector3<double> up;
3900  int counter=0;
3901  //PMatrix3DData *it;
3902 
3903  for (itP=mapPMatrices_.begin(); (itP!=mapPMatrices_.end()) && (counter<=5); itP++){
3904  PMatrix3DData *p = &(itP->second);
3905  // compute fov:
3907  u = (p->UL +p->UR)*0.5 - p->C;
3908  v = p->PP - p->C;
3909  BIASASSERT(u.Length()!=0);
3910  BIASASSERT(v.Length()!=0);
3911  double cosAlpha = u.ScalarProduct(v) / (u.Length() * v.Length());
3912  double alpha = acos(cosAlpha);
3913 
3914  // set virtual camera position, orientation and internal parameters:
3915  vrml<<"Viewpoint {"<<endl;
3916  vrml<<" position "<<p->C[0]<<" "<<p->C[1]<<" "<<p->C[2]<<endl; // x y z pos.
3917  // default orientation is xright, y top, looking in -Z direction.
3918  // rotate 180 deg around x-axis to look to +Z:
3919  vrml<<" orientation 1 0 0 "<<M_PI<<endl; // axis, angle rotate to +Z axis
3920  vrml<<" fieldOfView "
3921  <<alpha/M_PI*180.0
3922  //<<45.0
3923  // TODO: P.GetFieldOfView(widthm height, true);
3924  <<endl;// fov
3925  vrml<<" jump TRUE"<<endl; // immediate jump to position
3926  vrml<<" description \"camera P"<<counter<<"\""<<endl;
3927  vrml<<"}"<<endl; // end of viewpoint
3928 
3929  counter++;
3930  }
3931 }
3932 
3933 
3935 
3936  for (std::map<unsigned int, PMatrix3DData >::iterator it =
3937  mapPMatrices_.begin(); it !=mapPMatrices_.end() ; it++) {
3938  it->second.C += movement;
3939  it->second.UL += movement;
3940  it->second.UR += movement;
3941  it->second.LL += movement;
3942  it->second.LR += movement;
3943  }
3944 
3945  for (std::map<unsigned int, Image3DData>::iterator it= mapImages_.begin();
3946  it != mapImages_.end(); it++) {
3947  it->second.UL += movement;
3948  it->second.UR += movement;
3949  it->second.LL += movement;
3950  it->second.LR += movement;
3951  }
3952 
3953 
3954  for (std::map<unsigned int, Point3DData>::iterator it= mapPoints_.begin();
3955  it !=mapPoints_.end() ; it++) {
3956  it->second.Point += movement;
3957  }
3958 
3959 
3960  for (std::map<unsigned int, Line3DData>::iterator it= mapLines_.begin();
3961  it !=mapLines_.end() ; it++) {
3962  it->second.Start += movement;
3963  it->second.End += movement;
3964  }
3965 
3966 
3967  for (std::map<unsigned int, Ellipsoid3DData>::iterator it=
3968  mapEllipsoids_.begin(); it != mapEllipsoids_.end(); it++) {
3969  it->second.C += movement;
3970  }
3971 
3972 
3973  for (std::map<unsigned int, Ellipsoid3DData>::iterator it=
3974  mapCamEllipsoids_.begin(); it != mapCamEllipsoids_.end(); it++) {
3975  it->second.C += movement;
3976  }
3977 
3978  if (!mapIndexedFaceSet_.empty()) {
3979  for (std::map<unsigned int, IndexedFaceSet>::iterator it =
3980  mapIndexedFaceSet_.begin(); it != mapIndexedFaceSet_.end(); it++) {
3981  it->second.bbmin += movement;
3982  it->second.bbmax += movement;
3983 #ifdef BIAS_HAVE_OPENGL
3984  GLfloat *VertArray = it->second.VertArray;
3985 #endif
3986  for (std::vector<BIAS::Vector3<double> >::iterator itp =
3987  it->second.vertexSet.begin(); itp!=it->second.vertexSet.end();
3988  itp++){
3989  *itp += movement;
3990 #ifdef BIAS_HAVE_OPENGL
3991  *VertArray++ += movement[0];
3992  *VertArray++ += movement[1];
3993  *VertArray++ += movement[2];
3994 #endif
3995  }
3996 #ifdef BIAS_HAVE_OPENGL
3997  // remove cached data structures
3998  if (it->second.compiled_ && it->second.displayList_ != 0) {
3999  glDeleteLists(it->second.displayList_, 1);
4000  glDeleteTextures(1, &it->second.textureObjectID_);
4001  it->second.compiled_ = false;
4002  }
4003 #endif
4004  }
4005 
4006  }
4007 
4008  for (std::map<unsigned int, Projection3DData>::iterator it =
4009  mapProjection3D_.begin(); it != mapProjection3D_.end(); it++) {
4010  it->second.C += movement;
4011  }
4012 }
Vector3< double > UR
upper right corner of image plane in wcs
Definition: ThreeDOut.hh:219
void Release()
reimplemented from ImageBase
Definition: Image.cpp:1579
BIAS::Image< unsigned char > texture
Definition: ThreeDOut.hh:255
double dAngle
rotation in radians around RotAxes
Definition: ThreeDOut.hh:186
void GetRow(const unsigned int row, Vector3< T > &r) const
extract one row (&#39;Zeile&#39;) from ths matrix (for convenience)
Definition: Matrix3x3.cpp:287
unsigned int AddPose(const PoseParametrization &p, const RGBAuc &colorSelection=RGBAuc_WHITE_OPAQUE, const double radius=0.1, const double scale=1.0, const int camera_type=-1)
Definition: ThreeDOut.cpp:1407
GLsizei * facetIndicesCountArray
Definition: ThreeDOut.hh:285
void Print3D(const std::string &text, const float &xpos, const float &ypos, const float &zpos) const
Definition: DrawTextGL.cpp:275
void RemoveEllipsoid(const unsigned int &EIndex)
completely removes the ellipsoid from the internal structures, there is no way to get it back ...
Definition: ThreeDOut.cpp:1574
int VRMLOutPointsAsPointSet_(std::ostream &VRMLFile)
Definition: ThreeDOut.cpp:2545
void RemoveLine(const unsigned int &LineIndex)
completely removes the line from the internal structures, there is no way to get it back ...
Definition: ThreeDOut.cpp:1562
void OpenGLOutPMatrices_(const BIAS::RGBAuc &Color, bool UseOneColor)
Definition: ThreeDOut.cpp:1793
unsigned int NextProjection3DIndex_
Definition: ThreeDOut.hh:1022
void RemoveImage(const unsigned int &EIndex)
completely removes the image from the internal structures, there is no way to get it back ...
Definition: ThreeDOut.cpp:1589
std::string identifier
Definition: ThreeDOut.hh:177
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn&#39;t change the ...
Definition: Vector3.hh:202
double s2
lengths of main axes
Definition: ThreeDOut.hh:187
unsigned int AddTriangleMesh(const TriangleMesh &mesh, const std::string &name="", const std::string &textureOutputName="", bool writeOutTexture=true, bool calcNormals=false)
Adds triangle mesh as IndexedFaceSet to ThreeDOut mem.
Definition: ThreeDOut.cpp:1104
static unsigned int PowerOfTwoSize(const unsigned int &val)
Definition: ImageBase.cpp:971
virtual ~ThreeDOut()
Destructor releases all memory used.
Definition: ThreeDOut.cpp:206
std::string name
Definition: ThreeDOut.hh:261
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
GLfloat * NormalArray
Definition: ThreeDOut.hh:277
std::map< unsigned int, Projection3DData > mapProjection3D_
Definition: ThreeDOut.hh:1021
void OpenGLOutLines()
draw all pmatrices with their own color
Definition: ThreeDOut.cpp:2310
void UpdatePointColor(const unsigned int &PointIndex, const BIAS::RGBAuc &Color)
Definition: ThreeDOut.cpp:1439
Vector3< double > LR
lower right corner of image plane in wcs
Definition: ThreeDOut.hh:221
int VRMLOut(const std::string &sFilename)
flush all 3d objects to a vrml file with name sFilename, this is the function most users would call ...
Definition: ThreeDOut.cpp:3670
stores important data for drawing 3d text
Definition: ThreeDOut.hh:195
gray values, 1 channel
Definition: ImageBase.hh:130
double Length() const
returns the Euclidean Length of the Vector
Definition: Vector3.hh:193
void GetVertexColors(std::vector< BIAS::Vector4< unsigned char > > &colors) const
std::map< unsigned int, Text3DData > mapTexts_
map of all point structures
Definition: ThreeDOut.hh:999
int GetPCA(Vector3< COVMATRIX3X3_TYPE > &S, Matrix3x3< COVMATRIX3X3_TYPE > &VT)
void UpdatePoint(const unsigned int &PointIndex, const BIAS::Vector3< double > &v, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE)
Definition: ThreeDOut.cpp:1427
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
void UpdatePMatrixColor(const unsigned int &PIndex, const BIAS::RGBAuc &Color)
Definition: ThreeDOut.cpp:1469
void SetParamsCameraStyle(CameraDrawingStyle cameraStyle)
Definition: ThreeDOut.cpp:231
BIAS::Vector3< double > End
Definition: ThreeDOut.hh:240
unsigned int AddEllipsoid(BIAS::CovMatrix3x3 &cov, const BIAS::Vector3< double > &C, const BIAS::RGBAuc &Color=RGBAuc_WHITE_SEMI, const double &dConfidenceRegionScale=DEF_P_SCALE, const bool cameraCov=false)
Definition: ThreeDOut.cpp:782
ThreeDOut(const BIAS::ThreeDOutParameters &params=BIAS::ThreeDOutParameters())
Constructor for empty 3D scene with given parameters.
Definition: ThreeDOut.cpp:189
Vector3< double > C
Definition: ThreeDOut.hh:158
unsigned int NextImageIndex_
counter for the next index, gaps (due to delete) are not reused by now
Definition: ThreeDOut.hh:991
void SetParamsPointDrawingStyle(const PointDrawingStyle pointStyle)
Definition: ThreeDOut.cpp:261
std::map< unsigned int, Image3DData > mapImages_
map of all image structures
Definition: ThreeDOut.hh:989
void AddPlane(const HomgPlane3D &plane, const RGBAuc &colour=RGBAuc_WHITE_SEMI, const double size=1.0, const Vector3< double > &translation=Vector3< double >(0.0, 0.0, 0.0), const bool wireframe=true)
Adds the given plane to the scene, visualising it with lines or with a colored quad.
Definition: ThreeDOut.cpp:837
void ScalarProduct(const Vector3< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
Definition: Vector3.hh:603
const Vector3< double > & GetC() const
Set origin of local coordinate system in global coordinates.
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
int VRMLOutPMatricesRoutine(std::ostream &VRMLFile, const PMatrix3DData *it, double r=255.0, double g=255.0, double b=255.0, double transparency=0.0, bool CenterAsSphere=false)
only write camera into an open vrml file
Definition: ThreeDOut.cpp:2871
BIAS::Vector3< double > LL
lower left corner of image plane in wcs
void Set(const BIAS::PoseParametrization &p, const double scale=1.0)
Definition: ThreeDOut.hh:94
void PaintPyramid(std::ostream &VRMLFile, double selectionRadius, double r, double g, double b, double transparency, double angle, double ratio=4.0/3.0, double scale=1.0, const std::string &name="", bool paint_lines=false)
Write a parameterized pyramid into VRMLFile.
Definition: ThreeDOut.cpp:306
void SetParamsWCSAxesLength(double WCSAxesLength)
Definition: ThreeDOut.cpp:255
stores data for drawing a the extrinisc parameters of a projection.
Definition: ThreeDOut.hh:92
BIAS::Vector3< double > Point
Definition: ThreeDOut.hh:209
ThreeDOutParameters Params_
holds the params set by constructor or SetParams
Definition: ThreeDOut.hh:981
void VRMLOutViewPortPyramidal(std::ostream &VRMLFile, double selectionRadius, double r, double g, double b, double angle, double ratio, double scale, const std::string &name, bool solid=false)
Write a projection of a PERSPECTIVE camera into VRML.
Definition: ThreeDOut.cpp:530
int VRMLOutProjection(std::ostream &VRMLFile)
only write previously stored projection objects into opened vrml file.
Definition: ThreeDOut.cpp:3108
BIAS::RGBAuc ColorOfSelection
Definition: ThreeDOut.hh:176
int VRMLOutEllipsoids(std::ostream &vrml, const BIAS::RGBAuc &Color)
only write (previously stored) ellipsoids to an open vrml file, override their individual colors with...
Definition: ThreeDOut.cpp:3575
configuration struct for drawing styles of various 3d objects
Definition: ThreeDOut.hh:309
const Quaternion< double > & GetQ() const
Get orientation of local coordinate system as unit quaternion mapping from local coordinates to globa...
void VRMLOutViewPortConical(std::ostream &VRMLFile, double selectionRadius, double r, double g, double b, double angle, double scale, const std::string &name, bool solid=false)
Write a projection of a NON-PERSPECTIVE camera into VRML.
Definition: ThreeDOut.cpp:564
void GetNormals(std::vector< BIAS::Vector3< double > > &normals) const
BIAS::RGBAuc Color
RGBA color+opacity, 255=opaque, 0=transp.
GLubyte * ColorArray
Definition: ThreeDOut.hh:279
BIAS::Vector3< double > RotAxis
rot to get 1st mainaxis from (1,0,0)
Definition: ThreeDOut.hh:185
std::map< unsigned int, Line3DData > mapLines_
map of all line structures
Definition: ThreeDOut.hh:1004
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.
void SetParams(const ThreeDOutParameters &params)
Definition: ThreeDOut.cpp:209
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
int GetR(Matrix3x3< double > &R)
Definition: PMatrix.cpp:204
void VRMLOutWCS(std::ostream &vrml)
write world coordinate system origin and axes
Definition: ThreeDOut.cpp:1622
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
unsigned int NextTextIndex_
counter for the next index, gaps (due to delete) are not reused by now
Definition: ThreeDOut.hh:1001
void GetTexCoords(std::vector< BIAS::Vector2< float > > &texCoo) const
unsigned int GetWidth() const
Definition: ImageBase.hh:312
stores important data for drawing a camera
void PaintCone(std::ostream &VRMLFile, double selectionRadius, double r, double g, double b, double transparency, double angle, double scale=1.0, const std::string &name="")
Write a parameterized cone into VRMLFile.
Definition: ThreeDOut.cpp:461
void SetParamsDrawEllipse(bool drawEllipse)
Definition: ThreeDOut.cpp:237
std::map< unsigned int, Point3DData > mapPoints_
map of all point structures
Definition: ThreeDOut.hh:994
void SetWriteViewpoints(const bool &val)
write VRML viewpoint nodes for some P matrices ?
Definition: ThreeDOut.cpp:3878
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
int VRMLOutImages(std::ostream &VRMLFile)
only write (previously stored) images into an open vrml file
Definition: ThreeDOut.cpp:3335
CameraDrawingStyle CameraStyle
Definition: ThreeDOut.hh:313
BIAS::Quaternion< double > GetQ(unsigned int cam=0) const
return rotation quaternion of camera with index cam if cam&gt;0 this is a relative pose in the coordinat...
Definition: Projection.cpp:524
int InitFont(void *handleDC, const std::string theFontname=std::string(DrawTextGL_DEFAULT_FONTNAME), const int fontHeight=DrawTextGL_DEFAULT_FONTSIZE)
set the font up
Definition: DrawTextGL.cpp:80
unsigned int AddProjection(const Projection &p, const RGBAuc &colorSelection=RGBAuc_WHITE_OPAQUE, const double radius=0.1, const double scale=1.0, const std::string &identifier="", const int camera_type=-1)
Add a projection object to ThreeDOut mem.
Definition: ThreeDOut.cpp:1308
int VRMLOutPointsAsBoxes_(std::ostream &VRMLFile)
Definition: ThreeDOut.cpp:2609
3D rotation matrix
Definition: RMatrix.hh:49
void UpdatePMatrix(const unsigned int &PIndex, BIAS::PMatrix &P, const unsigned int &width, const unsigned int &height, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE, const double &dScale=DEF_P_SCALE)
Definition: ThreeDOut.cpp:1456
unsigned int NextEllipsoidIndex_
counter for the next ellipsoid index, gaps are not reused by now
Definition: ThreeDOut.hh:1011
void RemoveAllEllipsoids()
completely removes all ellipsoids from the internal structures, there is no way to get it back ...
Definition: ThreeDOut.cpp:1581
BIAS::Vector3< double > UL
upper left corner of image plane in wcs
void Translation(const Vector3< double > &movement)
transfers the whole scene by this offset
Definition: ThreeDOut.cpp:3934
bool visualize_viewports
Definition: ThreeDOut.hh:355
void RemoveAllPMatrices()
completely removes all images from the internal structures, there is no way to get it back ...
Definition: ThreeDOut.cpp:1607
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
Definition: Pose.hh:73
void UpdateLine(const unsigned int &LineIndex, const BIAS::Vector3< double > &Start, const BIAS::Vector3< double > &End, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE)
Definition: ThreeDOut.cpp:1475
void SetMesh(BIAS::Image< unsigned char > texture, std::vector< BIAS::Vector3< double > > meshVertices, std::vector< BIAS::Vector3< double > > vertexNormals, std::vector< BIAS::Vector2< float > > textureCoords, std::vector< BIAS::Vector< int > > triangleIndices)
Definition: TriangleMesh.hh:97
void OpenGLOutIndexedFaceSets()
draw mesh into opengl
Definition: ThreeDOut.cpp:2101
bool Greater(const T left, const T right, const T eps=std::numeric_limits< T >::epsilon())
comparison function for floating point values
void CrossProduct(const Vector3< T > &argvec, Vector3< T > &destvec) const
cross product of two vectors destvec = this x argvec
Definition: Vector3.hh:594
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
Definition: Projection.hh:194
void RemoveAllCamEllipsoids()
Definition: ThreeDOut.cpp:1585
void Mult(const Vector3< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
Definition: Matrix3x3.hh:302
void VRMLOutEllipsoid_(std::ostream &vrml, Ellipsoid3DData &E, const BIAS::RGBAuc &Color)
Definition: ThreeDOut.cpp:3549
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
void CoordinateSystem(std::ostream &VRMLFile, double selectionRadius, double r, double g, double b, double axeslength, double scale=1.0, const std::string &name="")
Write a projection of a camera in COORDINATE-style into VRML.
Definition: ThreeDOut.cpp:599
void VRMLOutWriteNavigationInfo(std::ostream &vrml)
write VRML 2.0 navigation info node
Definition: ThreeDOut.cpp:3883
void OpenGLOut()
render all entities (with the same color) using OpenGL Includes lines, points, pmatrices etc...
Definition: ThreeDOut.cpp:2485
int VRMLOutPMatricesAsMesh_(std::ostream &vrml, const BIAS::RGBAuc &Color)
Definition: ThreeDOut.cpp:2770
Vector3< double > bbmax
Definition: ThreeDOut.hh:265
void SetParamsDrawCameraEllipse(bool drawEllipse)
Definition: ThreeDOut.cpp:243
void RemoveAllIndexedFaceSets()
Definition: ThreeDOut.cpp:1596
void OpenGLOutWCS()
display the world coordinate system origin and axes
Definition: ThreeDOut.cpp:1631
void OpenGLOutEllipsoids()
draw all ellipsoids with their own color:
Definition: ThreeDOut.cpp:2361
stores datas for a textured plane
Definition: ThreeDOut.hh:216
int GetInverse(Matrix3x3< T > &inv) const
Matrix inversion: inverts this and stores resulty in argument inv.
Definition: Matrix3x3.cpp:373
Create and represent a 3D triangle mesh.
Definition: TriangleMesh.hh:84
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
void SetParamsLineDrawingStyle(const LineDrawingStyle lineStyle)
Definition: ThreeDOut.cpp:267
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
unsigned int GetHeight() const
Definition: ImageBase.hh:319
bool IsZero(const T eps=std::numeric_limits< T >::epsilon()) const
Definition: Matrix3x3.cpp:508
void GetNormalVector(Vector3< HOMGPLANE3D_TYPE > &normalv) const
returns normal vector
Definition: HomgPlane3D.hh:173
void RemovePoint(const unsigned int &PointIndex)
completely removes the point from the internal structures, there is no way to get it back ...
Definition: ThreeDOut.cpp:1550
class for 3x3 covariance matrices
Definition: CovMatrix3x3.hh:50
LineDrawingStyle LineStyle
Definition: ThreeDOut.hh:314
void SetParamsPointSize(const double pointSize)
Definition: ThreeDOut.cpp:214
int VRMLOutIndexedFaceSets(std::ostream &VRMLFile)
only write (previously stored) face sets into an open vrml file Will include texture into VRML as Pix...
Definition: ThreeDOut.cpp:3203
int VRMLOutPointsAsSpheres_(std::ostream &VRMLFile)
Definition: ThreeDOut.cpp:3587
std::string textureName
Definition: ThreeDOut.hh:262
int VRMLOutLines(std::ostream &vrml, const BIAS::RGBAuc &Color)
only write (previously stored) lines into an open vrml file, override their individual colors with Co...
Definition: ThreeDOut.cpp:3072
unsigned int AddLine(const BIAS::Vector3< double > &Start, const BIAS::Vector3< double > &End, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE)
Definition: ThreeDOut.cpp:756
std::vector< BIAS::Vector3< double > > vertexSet
Definition: ThreeDOut.hh:256
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
int SetROI(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
deprecated, use SetROICorners()
Definition: ImageBase.cpp:1033
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
BIAS::RGBAuc Color
Definition: ThreeDOut.hh:241
LineDrawingStyle
Definition: ThreeDOut.hh:303
void SetParamsCameraScale(double cameraScale)
Definition: ThreeDOut.cpp:225
void OpenGLOutImages(const bool &disableBlending=true)
draw all image patches using OpenGL
Definition: ThreeDOut.cpp:2038
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
BIAS::Vector3< double > UR
upper right corner of image plane in wcs
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
RGBA, 4 channels, order: red,green,blue,alpha.
Definition: ImageBase.hh:141
void RemoveAll()
removes all entites Essentially a clear on each entityt container.
Definition: ThreeDOut.cpp:3855
PointDrawingStyle
different styles when drawing points, e.g.
Definition: ThreeDOut.hh:299
static void ComputePlaneCorners(const HomgPlane3D &plane, const double size, std::vector< Vector3< double > > &corners)
Helper function computing the corners of a 3D plane.
Definition: ThreeDOut.cpp:877
stores data for drawing a point
Definition: ThreeDOut.hh:207
void GetTriangleIndices(std::vector< BIAS::Vector< int > > &triangleIndices) const
GLuint ** facetArray
Definition: ThreeDOut.hh:282
push and pop GL states on constructor/destructor Helper class pop(save) OpenGL states on constructi...
unsigned int NextIndexedFaceSetIndex_
Definition: ThreeDOut.hh:1019
void GetBoundingBox(Vector3< double > &min, Vector3< double > &max)
Get the min and max vector of the smallest bounding box, which is drawn around the added points...
Definition: ThreeDOut.cpp:3756
int GetC(Vector3< double > &C)
computes translation vector origin world coo -&gt; origin camera coo (center), uses decomposition, which is cached
Definition: PMatrix.cpp:165
Matrix3x3< T > Transpose() const
returns transposed matrix tested 12.06.2002
Definition: Matrix3x3.cpp:167
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn&#39;t change the...
Definition: Vector4.hh:177
std::string CorrectDefString_(const std::string &defstring)
replace invalid characters in def string and return corrected
Definition: ThreeDOut.cpp:273
void SetParamsLineWidth(const int lineWidth)
Definition: ThreeDOut.cpp:219
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
int GetA(Vector3< double > &A)
returns the unit vector A which is the normal vector to the image plane in world coordinates.
Definition: PMatrix.cpp:287
void RemoveAllPoints()
completely removes all points from the internal structures, there is no way to get them back ...
Definition: ThreeDOut.cpp:1557
stores data for drawing a indexed face set.
Definition: ThreeDOut.hh:248
void DrawSphere_(double radius, int lats, int longs)
Definition: ThreeDOut.cpp:2502
unsigned int NextPIndex_
counter for the next index, gaps (due to delete) are not reused by now
Definition: ThreeDOut.hh:986
static double VRMLtransparency(const unsigned char alpha)
get alpha opacity value as VRML transparency helper mapping, usually transparency = (1-alpha) ...
Definition: ThreeDOut.cpp:3867
unsigned int NextLineIndex_
counter for the next line index, gaps (due to delete) arent reused
Definition: ThreeDOut.hh:1006
std::map< unsigned int, IndexedFaceSet > mapIndexedFaceSet_
Definition: ThreeDOut.hh:1018
unsigned int Size() const
Determine number of ProjectionParameterBase pointers in Projection.
Definition: Projection.hh:178
int Flip()
flips the image vertically (row order is inverted) In place function return 0 in case of success...
Definition: ImageBase.cpp:834
unsigned int AddPMatrix(BIAS::PMatrix &P, const unsigned int &width, const unsigned int &height, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE, const double &dScale=DEF_P_SCALE, const std::string &name="")
decompose P and add to internal data structures.
Definition: ThreeDOut.cpp:1029
int GetRotationAxisAngle(Vector3< ROTATION_MATRIX_TYPE > &axis, ROTATION_MATRIX_TYPE &angle) const
Calculates angle and rotation axis representation for this rotation matrix.
BIAS::Vector3< double > PP
principle point in wcs
std::vector< BIAS::Vector4< unsigned char > > vertexColorSet
Definition: ThreeDOut.hh:257
void RemoveAllLines()
completely removes all lines from the internal structures JW
Definition: ThreeDOut.cpp:1569
void ConcatenateLocalTransform(const CoordinateTransform3D &localT, CoordinateTransform3D &res) const
Calculates transformation from global system of this instance to the local coordinate system of the g...
BIAS::RGBAuc Color
Definition: ThreeDOut.hh:201
BIAS::Vector3< double > Up
Up-Vector (V)
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
PointDrawingStyle PointStyle
Definition: ThreeDOut.hh:312
std::map< unsigned int, PMatrix3DData > mapPMatrices_
the cameras are saved in a vector for efficiency reasons
Definition: ThreeDOut.hh:984
void GetVertices(std::vector< BIAS::Vector3< double > > &vertices) const
void VRMLOutWriteViewpoint(std::ostream &vrml)
write VRMl 2.0 viewpoint that can selecetd in vrml viewer
Definition: ThreeDOut.cpp:3894
unsigned int AddPoint(const BIAS::Vector3< double > &v, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE)
Definition: ThreeDOut.cpp:719
Image< unsigned char > ImageData
data of texture image
Definition: ThreeDOut.hh:222
std::map< unsigned int, Ellipsoid3DData > mapCamEllipsoids_
map of all ellipsoid structures
Definition: ThreeDOut.hh:1014
bool IsHomogenized() const
Definition: HomgPoint3D.hh:147
void RemoveAllImages()
completely removes all images from the internal structures, there is no way to get it back ...
Definition: ThreeDOut.cpp:1602
void OpenGLOutPMatrices()
draw all pmatrices with their own color:
Definition: ThreeDOut.cpp:2032
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
Vector3< double > GetC(unsigned int cam=0) const
return Center of camera with index cam.
Definition: Projection.hh:236
void Dump()
list all internal 3d objects on cout
Definition: ThreeDOut.cpp:3706
void UpdateEllipsoid(const unsigned int &EIndex, BIAS::CovMatrix3x3 &cov, BIAS::Vector3< double > &C, const BIAS::RGBAuc &Color=RGBAuc_WHITE_SEMI, const double &dConfidenceRegionScale=DEF_P_SCALE)
Definition: ThreeDOut.cpp:1504
std::string name
Definition: ThreeDOut.hh:224
void SetParamsEllipsoidScale(double ellipsoidScale)
Definition: ThreeDOut.cpp:249
CameraDrawingStyle
different styles when drawing cameras, e.g.
Definition: ThreeDOut.hh:294
void OpenGLOutPoints()
draw all points with their own color:
Definition: ThreeDOut.cpp:1724
void RemovePMatrix(int index)
removes the P-matrix index, there is no way to get it back
Definition: ThreeDOut.cpp:1612
int VRMLOutPMatricesAsArrows_(std::ostream &vrml, const BIAS::RGBAuc &Color)
this is an optimized strategy to avoid hundred of shape nodes
Definition: ThreeDOut.cpp:2825
unsigned int NextPointIndex_
counter for the next index, gaps (due to delete) are not reused by now
Definition: ThreeDOut.hh:996
Vector3< T > & Normalize()
normalize this vector to length 1
Definition: Vector3.hh:663
int PadToPowerOfTwo(BIAS::ImageBase &dest, const int &padVal=0) const
increase the size of this image to next power of two (e.g.
Definition: ImageBase.cpp:1154
Vector3< double > GetCenterOfPoints()
get center of gravity (mean of structure)
Definition: ThreeDOut.cpp:3740
int VRMLOutPMatrices(std::ostream &vrml, const BIAS::RGBAuc &Color)
only write (previously stored) cameras into an open vrml file, override their individual colors with ...
Definition: ThreeDOut.cpp:2751
unsigned int NextCamEllipsoidIndex_
counter for the next ellipsoid index, gaps are not reused by now
Definition: ThreeDOut.hh:1016
void GetTexture(Image< unsigned char > &img) const
int VRMLOutPoints(std::ostream &vrml, const BIAS::RGBAuc &Color)
only write (previously stored) points into an open vrml file, override their individual colors with C...
Definition: ThreeDOut.cpp:2533
int VRMLOutWriteHeader(std::ostream &vrml)
write the VRML 2.0 header into an open file
Definition: ThreeDOut.cpp:3696
GLfloat * TextureCoordArray
Definition: ThreeDOut.hh:278
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
Definition: Vector3.hh:633
BIAS::Vector3< double > C
camera center in wcs
BIAS::RGBAuc Color
Definition: ThreeDOut.hh:189
Draw text to OpenGL as 2D bitmap font.
Definition: DrawTextGL.hh:71
BIAS::Vector3< double > LR
lower right corner of image plane in wcs
BIAS::Quaternion< double > Direction
Definition: ThreeDOut.hh:198
std::map< unsigned int, Ellipsoid3DData > mapEllipsoids_
map of all ellipsoid structures
Definition: ThreeDOut.hh:1009
int GetK(KMatrix &K)
calibration matrix
Definition: PMatrix.cpp:220
unsigned int AddText(const std::string &thetext, const BIAS::Vector3< double > &position, const BIAS::Quaternion< double > &direction=BIAS::Quaternion< double >(0.0, 0.0, 0.0, 0.0), const double &thesize=-12.0, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE)
Definition: ThreeDOut.cpp:739
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153
A homogeneous plane (in P^3) All points X on the plane p fulfill p &#39; * X = 0.
Definition: HomgPlane3D.hh:46