Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RenderContextBase.cpp
1 #include <GLviewer/RenderContextBase.hh>
2 #include <GLviewer/Scenes/SceneBGImage.hh>
3 
4 #include <Gui/biasgl.h>
5 
6 #include <iostream>
7 
8 using namespace BIAS;
9 using namespace BIAS;
10 using namespace std;
11 
12 
13 //#define MIN_ZNEAR 1.0
14 
15 //#define TURN_OF_LOCKING
16 
17 #ifdef BIAS_HAVE_PTHREADS
19 #endif
20 
22 RenderContextBase() : ClearColor_(0.0, 0.0, 0.0, 0.0), centerViewport_(false)
23 {
24  camera_ = NULL;
25  control_ = NULL;
26  backgroundImageScene_ = NULL;
27 
28  initialized_=false;
29  AutoClipping_ = false;
30  blendingAllowed_=false;
31  AutoMinZNear_ = 0.1; //old default.
32  culling_=false;
33  UseStencil_ = false;
34  bSelectionMode_ = false;
35 }
36 
37 #ifdef BIAS_HAVE_PTHREADS
39 {
40  int res = contextLock_->Lock();
42  return res;
43 }
44 
46 {
47  return contextLock_->Unlock();
48 }
49 #endif
50 
53 {
54  int redbits, greenbits, bluebits, depthbits, alphabits,stencilbits;
55  GLboolean doublebuffered;
56  glGetIntegerv(GL_DEPTH_BITS,&depthbits);
57  glGetIntegerv(GL_RED_BITS, &redbits);
58  glGetIntegerv(GL_GREEN_BITS, &greenbits);
59  glGetIntegerv(GL_BLUE_BITS, &bluebits);
60  glGetIntegerv(GL_ALPHA_BITS, &alphabits);
61  glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
62  glGetBooleanv(GL_DOUBLEBUFFER, &doublebuffered);
63  int viewport[4];
64  glGetIntegerv(GL_VIEWPORT, viewport);
65  cout <<"GL buffer resolution Red: "<<redbits<<" bits"<<endl;
66  cout <<"GL buffer resolution Green: "<<greenbits <<" bits"<<endl;
67  cout <<"GL buffer resolution Blue: "<<bluebits <<" bits"<<endl;
68  cout <<"GL buffer resolution Alpha: "<<alphabits <<" bits"<<endl;
69  cout <<"GL buffer resolution Depth: "<<depthbits <<" bits"<<endl;
70  cout <<"GL buffer resolution Stencil: "<<stencilbits <<" bits"<<endl;
71  cout <<"GL doublebuffered: "<<(doublebuffered == GL_TRUE)<<endl;
72  cout <<"GL Viewport: "<<viewport[0];
73  cout<<","<<viewport[1]<<","<<viewport[2]<<","<<viewport[3]<<endl;
74 }
75 
78 {
79  if(camera_==NULL) {
80  BIASERR("No camera set!\n");
81  return -1;
82  }
84  camera_->GetImage(Image);
86  return 0;
87 }
88 
91 {
92  if(camera_==NULL) {
93  BIASERR("No camera set!\n");
94  return -1;
95  }
97  camera_->GetGreyImage(Image);
99  return 0;
100 }
101 
103 GetDepthMap(BIAS::Image<float>& Image, const float invalid)
104 {
105  if(camera_==NULL) {
106  BIASERR("No camera set!\n");
107  return -1;
108  }
109 
111  int retVal = camera_->GetDepthMap(Image, invalid);
113  return retVal;
114 
115 }
116 
119 {
120  if(camera_==NULL) {
121  BIASERR("No camera set!\n");
122  return -1;
123  }
124 
126  int retVal = camera_->GetZBuffer(Image);
128  return retVal;
129 
130 }
131 
133 GetMetricZMap(BIAS::Image<float>& Image, const float invalid)
134 {
135  if (camera_ == NULL)
136  {
137  BIASERR("No camera set!\n");
138  return -1;
139  }
141  int retVal = camera_->GetMetricZMap(Image, invalid);
143  return retVal;
144 }
145 
146 
149 {
150  int depthbits;
153 
154  glEnable(GL_DEPTH_TEST);
155  glDepthFunc(GL_LESS);
156 
157  glGetIntegerv(GL_DEPTH_BITS,&depthbits);
158  if(depthbits == 0)
159  BIASERR("No depth buffer was found most functionality is unavailable!");
160 
161  initialized_ = true;
162 }
163 
165 SetBlending(bool blend){
166  blendingAllowed_ = blend;
167  int alphabits;
168  glGetIntegerv(GL_ALPHA_BITS, &alphabits);
169  if(alphabits>0 && blend)
170  glEnable(GL_BLEND);
171  else{
172  blendingAllowed_=false;
173  glDisable(GL_BLEND);
174  }
175  return blendingAllowed_;
176 }
177 
180  culling_ = cull;
181  if(cull)
182  glEnable(GL_CULL_FACE);
183  else
184  glDisable(GL_CULL_FACE);
185  return culling_;
186 }
187 
190 {
191 
192 #ifndef TURN_OF_LOCKING
193 #ifdef BIAS_HAVE_PTHREADS
195 #endif
196 #endif
197 
198  GLenum err = glGetError();
199  if (err != GL_NO_ERROR) {
200  BIASERR("OpenGL Error before rendering: " << gluErrorString(err));
201  }
202 
203 // MakeGLContextCurrent();
204  if(camera_ == NULL) {
205  BIASERR("No GLProjection object set!\n");
206 #ifdef BIAS_HAVE_PTHREADS
208 #endif
209  return -1;
210  }
211 
212  if(!initialized_) Init_();
213 
214 
215  glClearColor(ClearColor_[0], ClearColor_[1],
216  ClearColor_[2], ClearColor_[3]);
217 
218  // cout<<"ClearColor:"<<ClearColor_[0]<<","<<ClearColor_[1]<<","<<ClearColor_[2]<<","<<ClearColor_[3]<<endl;
219  if(UseStencil_)
220  {
221  glClearStencil(0);
222  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
223  }
224  else
225  {
226  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
227  }
228 
229  // near and far clipping plane is automatically derived and set.
230  if (AutoClipping_)
231  {
232  Vector3<double> C, min, max, radiusOfSphere, centerOfBox;
233 
234  double zFar = 0.0;
235  double zNear = 0.0;
236  bool autoClippingSucceeded = false;
237 
238  for (unsigned int i = 0; i < scenes_.size(); i++)
239  {
240  double newNear = 0.0;
241  double newFar = 0.0;
242 
243  scenes_[i]->GetBoundingBox(min, max);
244 
245  //cout<<"min :"<<min<<" max: "<<max<<endl;
246 
247  // has the scene a bounding box.
248  if (min.Length() == 0.0 && max.Length() == 0.0)
249  {
250  continue;
251  }
252 
253  //this is the new way, droogs!
255  // cout<<"C:"<<C<<endl;
256 
257  // compute radius of the sphere around the bounding box.
258  centerOfBox = max - min;
259  centerOfBox = centerOfBox / 2.0;
260  radiusOfSphere = centerOfBox;
261  centerOfBox = min + centerOfBox;
262 
263  Vector3<double> direction;
264  direction = (centerOfBox - C);
265  newNear = (direction.Length() - radiusOfSphere.Length());
266  newFar = (direction.Length() + radiusOfSphere.Length());
267 
268  if (zNear == 0.0) zNear = newNear;
269 
270  // set new clipping planes.
271  if (newNear < zNear)
272  {
273  zNear = newNear;
274  }
275 
276  if (newFar > zFar)
277  {
278  zFar = newFar;
279  }
280  autoClippingSucceeded = true;
281  }
282 
283 
284  if (autoClippingSucceeded) {
285  // set clipping planes to nearest and farest point +-10%
286  zFar *= 1.1;
287  zNear *= 0.9;
288 
289  if (zNear < AutoMinZNear_) zNear = AutoMinZNear_; //MIN_ZNEAR
290  if (zFar < zNear*1.01) zFar = zNear*1.01;
291 
292  //cout<<"Context ALTERTED znear,zfar to:"<<zNear<<","<<zFar<<endl;
293  //cout<<"Setting clipping planes to "<<zNear<<";"<<zFar<<endl;
296  } else {
297  BIASWARNONCE("autoclipping active but no bounding boxes could be retrieved.");
298  }
299  }//end if(autoclipping)
300 
301  //finally draw scenes with camera
303 
304  // draw views
305  for (int i = 0; i < (int)views_.size(); i++) {
306  views_[i]->Render();
307  }
308 
309  // TODO: should this be called once or for each view?
310  for (unsigned int i=0; i<additionalListeners_.size(); i++)
311  additionalListeners_[i]->FinishedDraw();
312 
313 #ifndef TURN_OF_LOCKING
314 #ifdef BIAS_HAVE_PTHREADS
316 #endif
317 #endif
318  err = glGetError();
319  if (err != GL_NO_ERROR) {
320  BIASERR("OpenGL Error after rendering: " << gluErrorString(err));
321  }
322 
323  return res;
324 }
325 
328 {
329  return scenes_.size();
330 }
331 
332 void RenderContextBase::AppendScene(SceneBase* scene, bool push_front)
333 {
335 
336  if (push_front)
337  scenes_.insert(scenes_.begin(),scene);
338  else
339  scenes_.push_back(scene);
340 
341 }
342 
343 void RenderContextBase::RemoveScene(SceneBase* scene, bool noWarning)
344 {
345  int index = -1;
346  int numberOfScenes = (int)scenes_.size();
347  for (int i = 0; i < numberOfScenes; i++)
348  if (scenes_[i] == scene)
349  index = i;
350 
351  if (index != -1)
352  scenes_.erase(scenes_.begin() + index);
353  else
354  if (!noWarning) BIASWARN("Cannot remove scene. Unknown scene pointer");
355 }
356 
358 InsertSceneAt(SceneBase* scene, unsigned int index)
359 {
360  vector<SceneBase*>::iterator itor = scenes_.begin();
361 
362  if (index <= scenes_.size())
363  {
364  unsigned int i = 0;
365  while (i < index)
366  {
367  itor++;
368  i++;
369  }
370  scenes_.insert( itor, 1, scene );
371  }
372  else
373  {
374  scenes_.push_back(scene);
375  }
376 }
377 
380 {
381  delete backgroundImageScene_;
383 }
384 
385 
387 DeleteSceneAt(unsigned int index)
388 {
389  vector<SceneBase*>::iterator itor = scenes_.begin();
390 
391  if (index >= scenes_.size())
392  {
393  BIASERR("Index out of range");
394  }
395 
396  unsigned int i = 0;
397  while (i < index)
398  {
399  itor++;
400  i++;
401  }
402  scenes_.erase(itor);
403 }
404 
407 {
408  for(unsigned int i=0; i<scenes_.size(); i++)
409  delete scenes_[i];
410  scenes_.clear();
411 }
412 
414 GetSceneAt(unsigned int index){
415  BIASASSERT(index < scenes_.size())
416  return scenes_[index];
417 }
418 
421 {
422  scenes_.clear();
423 }
424 
427 {
428  std::vector<ControlInterface*>::iterator begin, end, pos;
429  begin = additionalListeners_.begin();
430  end = additionalListeners_.end();
431  ControlInterface* test = &listener;
432  for(pos = begin; test != *pos && pos != end; pos++) {}
433  if(*pos == test)
434  additionalListeners_.erase(pos);
435 }
436 
439 {
440  center = Vector3<double>(0.0,0.0,0.0);
441  radius = Vector3<double>(0.0,0.0,0.0);
442 
443  Vector3<double> min, max;
444  Vector3<double> newCenter, newRadius;
445  unsigned int foundBoundingBox = 0;
446 
447  for (unsigned int i = 0; i < scenes_.size(); i++)
448  {
449  scenes_[i]->GetBoundingBox(min, max);
450 
451  // has the scene a bounding box.
452  if (min.Length() == 0.0 && max.Length() == 0.0)
453  continue;
454 
455  foundBoundingBox++;
456 
457  // compute radius of the sphere around the bounding box.
458  newRadius = ((max - min) / 2.0);
459  newCenter = newRadius + min;
460 
461  if (newRadius.Length() > radius.Length())
462  radius = newRadius;
463 
464  if (foundBoundingBox >= 2)
465  {
466  // compute new center and radius of sphere which includes all
467  // spheres
468  newCenter = (newCenter - center) / 2.0;
469  newRadius = newCenter + radius;
470  newCenter = newCenter + center;
471  }
472 
473  // set new radius and center for next iteration
474  radius = newRadius;
475  center = newCenter;
476  }
477 
478 
479  // if radius is zero then no bounding box was retrieved
480  if (radius.Length() == 0.0)
481  return false;
482  else
483  return true;
484 }
485 
486 
489 {
490  if(newCamera == NULL) {
491  BIASERR("RenderContextBase: specified camera is NULL");
492  return;
493  }
494  camera_ = newCamera;
496  for(unsigned int i=0; i<scenes_.size(); i++)
498  if(control_ != NULL)
500 }
501 
502 
504 MouseWheelUsed(double stepsize){
505 
506  bool callCaught = false;
507  callCaught = control_->MouseWheelUsed(stepsize);
508  for (int i = 0; i < (int)additionalListeners_.size(); i++)
509  {
510  bool res = additionalListeners_[i]->MouseWheelUsed(stepsize);
511  callCaught = callCaught || res;
512  }
513  return callCaught;
514 }
515 
516 
518 SetBackgroundImageScene(SceneBGImage* backgroundImageScene)
519 {
520  BIAS::Vector4<float> cc(255,255,255,0);
521  SetClearColor(cc);
522  backgroundImageScene_ = backgroundImageScene;
523 }
524 
527 {
528  control_ = newControl;
529  if(control_ != NULL && camera_ != NULL) {
531  }
532 
533 }
534 
537 {
538 
539  bool res = false;
540  if(control_!=NULL)
541  res = control_->RightMouseDoubleClicked(x, y);
542 
543  for (unsigned i = 0; i < additionalListeners_.size(); i++)
544  {
545  res = res || additionalListeners_[i]->RightMouseDoubleClicked(x, y);
546  }
547 
548  return res;
549 }
550 
552 {
553  bool callCaught = false;
554  if(control_!=NULL) {
555  callCaught = control_->LeftMouseDown(x,y);
556  }
557  for (int i = 0; i < (int)additionalListeners_.size(); i++)
558  {
559  bool res = additionalListeners_[i]->LeftMouseDown(x, y);
560  callCaught = callCaught || res;
561  }
562  return callCaught;
563 }
564 
566 {
567  bool callCaught = false;
568  if(control_!=NULL) {
569  callCaught = control_->LeftMouseUp(x,y);
570  }
571 
572  for (int i = 0; i < (int)additionalListeners_.size(); i++)
573  {
574  bool res = additionalListeners_[i]->LeftMouseUp(x, y);
575  callCaught = callCaught || res;
576  }
577 
578  return callCaught;
579 }
580 
582 LeftMouseDoubleClicked(int x, int y, int m)
583 {
584  bool callCaught = false;
585 
586  //if the selection mode is enabled, call selectAt for all scenes
587  if(bSelectionMode_){
588  // Get from 2D mouse position 3D point in scene.
589  if(camera_->GetViewportCoordinates(x, y)) {
591  if (p[3] != 0.0)
592  {
593  BIAS::Vector3<double> p3(p[0],p[1],p[2]);
594  for(unsigned i=0;i<scenes_.size();i++)
595  scenes_[i]->SelectObjectAt(p3);
596  }
597  }
598  }
599 
600  if(control_!=NULL) {
601  callCaught = control_->LeftMouseDoubleClicked(x, y, m);
602  }
603 
604  for (unsigned int i = 0; i < additionalListeners_.size(); i++)
605  {
606  bool res = additionalListeners_[i]->LeftMouseDoubleClicked(x, y, m);
607  callCaught = callCaught || res;
608  }
609 
610  return callCaught;
611 }
612 
615 {
616  bool callCaught = false;
617  if(control_!=NULL)
618  callCaught = control_->LeftMouseSingleClicked(x, y);
619 
620  for (unsigned i = 0; i < additionalListeners_.size(); i++)
621  {
622  bool res = additionalListeners_[i]->LeftMouseSingleClicked(x, y);
623  callCaught = callCaught || res;
624  }
625 
626  return callCaught;
627 }
628 
631 {
632  bool callCaught = false;
633  if(control_!=NULL)
634  callCaught = control_->RightMouseSingleClicked(x, y);
635 
636 
637  for (unsigned i = 0; i < additionalListeners_.size(); i++)
638  {
639  bool res = additionalListeners_[i]->RightMouseSingleClicked(x, y);
640  callCaught = callCaught || res;
641  }
642 
643  return callCaught;
644 }
645 
647 LeftMouseMoved(int x1, int x2, int y1, int y2)
648 {
649  bool callCaught = false;
650  if(control_!=NULL)
651  callCaught = control_->LeftMouseMoved(x1, x2, y1, y2);
652 
653  for (unsigned i = 0; i < additionalListeners_.size(); i++)
654  {
655  bool res = additionalListeners_[i]->LeftMouseMoved(x1, x2, y1, y2);
656  callCaught = callCaught || res;
657  }
658 
659  return callCaught;
660 }
661 
663 RightMouseMoved(int x1, int x2, int y1, int y2)
664 {
665  bool callCaught = false;
666  if(control_!=NULL)
667  callCaught = control_->RightMouseMoved(x1, x2, y1, y2);
668 
669  if(scenes_.size() == 0 || callCaught)
670  return callCaught;
671 
672  for (unsigned i = 0; i < additionalListeners_.size(); i++)
673  {
674  bool res = additionalListeners_[i]->RightMouseMoved(x1, x2, y1, y2);
675  callCaught = callCaught || res;
676  }
677  return callCaught;
678 }
679 
680 
682 {
683  bool callCaught = false;
684  if(control_!=NULL) {
685  callCaught = control_->RightMouseDown(x,y);
686  }
687  for (int i = 0; i < (int)additionalListeners_.size(); i++)
688  {
689  bool res = additionalListeners_[i]->RightMouseDown(x, y);
690  callCaught = callCaught || res;
691  }
692  return callCaught;
693 }
694 
696 {
697  bool callCaught = false;
698  if(control_!=NULL) {
699  callCaught = control_->RightMouseUp(x,y);
700  }
701 
702  for (int i = 0; i < (int)additionalListeners_.size(); i++)
703  {
704  bool res = additionalListeners_[i]->RightMouseUp(x, y);
705  callCaught = callCaught || res;
706  }
707 
708  return callCaught;
709 }
710 
712 {
713  bool callCaught = false;
714  if(control_!=NULL)
715  callCaught = control_->MouseLeftWindow();
716  for (unsigned i = 0; i < additionalListeners_.size(); i++)
717  {
718  bool res = additionalListeners_[i]->MouseLeftWindow();
719  callCaught = callCaught || res;
720  }
721  return callCaught;
722 }
723 
725 MiddleMouseMoved(int x1, int x2, int y1, int y2)
726 {
727  bool callCaught = false;
728  if(control_!=NULL)
729  callCaught = control_->MiddleMouseMoved(x1, x2, y1, y2);
730 
731  if(scenes_.size() == 0 || callCaught)
732  return callCaught;
733 
734  for (unsigned i = 0; i < additionalListeners_.size(); i++)
735  {
736  bool res = additionalListeners_[i]->MiddleMouseMoved(x1, x2, y1, y2);
737  callCaught = callCaught || res;
738  }
739  return callCaught;
740 }
741 
743 {
744  bool callCaught = false;
745  if(control_!=NULL) {
746  callCaught = control_->MiddleMouseDown(x,y);
747  }
748  for (int i = 0; i < (int)additionalListeners_.size(); i++)
749  {
750  bool res = additionalListeners_[i]->MiddleMouseDown(x, y);
751  callCaught = callCaught || res;
752  }
753  return callCaught;
754 }
755 
757 {
758  bool callCaught = false;
759  if(control_!=NULL) {
760  callCaught = control_->MiddleMouseUp(x,y);
761  }
762 
763  for (int i = 0; i < (int)additionalListeners_.size(); i++)
764  {
765  bool res = additionalListeners_[i]->MiddleMouseUp(x, y);
766  callCaught = callCaught || res;
767  }
768 
769  return callCaught;
770 }
771 
773 MouseMoved(int x, int y)
774 {
775  bool callCaught = false;
776  if(control_!=NULL){
777  callCaught = control_->MouseMoved(x, y);
778  // cout<<"RCB Mouse Moved:"<<x<<" "<<y<<endl;
779  }
780 
781  for (unsigned i = 0; i < additionalListeners_.size(); i++)
782  {
783  bool res = additionalListeners_[i]->MouseMoved(x, y);
784  callCaught = callCaught || res;
785  }
786  return callCaught;
787 }
788 
789 
791 LeftAndRightMouseMoved(int x1, int x2, int y1, int y2)
792 {
793  bool callCaught = false;
794  if(control_!=NULL)
795  callCaught = control_->LeftAndRightMouseMoved(x1, x2, y1, y2);
796 
797  if(scenes_.size() == 0 || callCaught)
798  return callCaught;
799 
800  for (unsigned i = 0; i < additionalListeners_.size(); i++)
801  {
802  bool res = additionalListeners_[i]->LeftAndRightMouseMoved(x1, x2, y1, y2);
803  callCaught = callCaught || res;
804  }
805  return callCaught;
806 }
807 
810 {
811  bool callCaught = false;
812  if(control_!=NULL) {
813  callCaught = control_->SpecialKeyPressed(key);
814  }
815 
816  for (unsigned int i = 0; i < additionalListeners_.size(); i++)
817  {
818  bool res = additionalListeners_[i]->SpecialKeyPressed(key);
819  callCaught = callCaught || res;
820  }
821 
822  return callCaught;
823 }
824 
826 SpecialKeyUp(int key)
827 {
828  bool callCaught = false;
829  if(control_!=NULL) {
830  callCaught = control_->SpecialKeyUp(key);
831  }
832 
833  for (unsigned int i = 0; i < additionalListeners_.size(); i++)
834  {
835  bool res = additionalListeners_[i]->SpecialKeyUp(key);
836  callCaught = callCaught || res;
837  }
838 
839  return callCaught;
840 }
841 
842 
843 
845 StandardKeyPressed(unsigned char key,int x,int y)
846 {
847  bool callCaught = false;
848  if(control_!=NULL) {
849  callCaught = control_->StandardKeyPressed(key,x,y);
850  }
851 
852  for (unsigned int i = 0; i < additionalListeners_.size(); i++)
853  {
854  bool res = additionalListeners_[i]->StandardKeyPressed(key,x,y);
855  callCaught = callCaught || res;
856  }
857  return callCaught;
858 }
859 
861 StandardKeyUp(unsigned char key,int x,int y)
862 {
863  bool callCaught = false;
864  if(control_!=NULL) {
865  callCaught = control_->StandardKeyUp(key,x,y);
866  }
867 
868  for (unsigned int i = 0; i < additionalListeners_.size(); i++)
869  {
870  bool res = additionalListeners_[i]->StandardKeyUp(key,x,y);
871  callCaught = callCaught || res;
872  }
873  return callCaught;
874 }
875 
876 // static int calls = 0;
879 {
880  bool callCaught = false;
881  if(control_!=NULL) {
882  callCaught = control_->TimerExpired();
883  }
884 
885  for( unsigned int i = 0; i<additionalListeners_.size(); i++) {
886  bool res = additionalListeners_[i]->TimerExpired();
887  callCaught = callCaught || res;
888  }
889  return callCaught;
890 }
891 
893 CenterViewport(bool center) {
894  centerViewport_ = center;
895 }
896 
898 WindowReshape(int width, int height)
899 {
900  LockContextSwitch();//MakeGLContextCurrent();
901 
902  int viewport[4];
903  glGetIntegerv(GL_VIEWPORT, viewport);
904 
905  if(centerViewport_) {
906  int newviewport[4];
907  if(viewport[2]>width) {
908  newviewport[0]=0;
909  newviewport[2]=width;
910  } else {
911  int viewportHalfWidth = viewport[2]/2;
912  int windowHalfWidth = width/2;
913  newviewport[0]=windowHalfWidth-viewportHalfWidth;
914  newviewport[2]=viewport[2];
915  }
916 
917  if(viewport[3]>height) {
918  newviewport[1]=0;
919  newviewport[3]=width;
920  } else {
921  int viewportHalfHeight = viewport[3]/2;
922  int windowHalfHeight = height/2;
923  newviewport[1]=windowHalfHeight-viewportHalfHeight;
924  newviewport[3]=viewport[3];
925  }
926 
927  glViewport(newviewport[0], newviewport[1], newviewport[2], newviewport[3]);
928  } else {
929  /* cout<<"---------------------------------------------------------------"<<endl;
930  cout<<"viewport was: "<<viewport[0]<<" "<<viewport[1]<<" "<<viewport[2]<<" "<<viewport[3]<<endl;
931  cout<<"setting view port in windowreshape to: "<<width<<" "<<height<<endl;*/
932  glViewport(0,0, width, height);
933  }
934 
935  if(control_!=NULL) {
936  control_->WindowReshape(width, height);
937  }
938 
939  // unsigned int i = 0;
940  // while(i<scenes_.size()) {
941  // scenes_[i]->WindowReshape(width, height);
942  // i++;
943  // }
945  return true;
946 }
947 
950 {
951  BIASASSERT(view != NULL);
952  views_.push_back(view);
953 }
954 
956 {
957  UseStencil_ = enable;
958 }
virtual BIAS::Vector3< double > GetC() const
Get projection center.
bool LeftMouseDoubleClicked(int x, int y, int m)
bool LeftMouseSingleClicked(int x, int y)
virtual void GetGreyImage(BIAS::Image< unsigned char > &image)=0
bool SetBackfaceCulling(bool cull=true)
En-/Disable backface culling.
bool SetBlending(bool blend=true)
En-/Disable blending.
SceneBase * GetSceneAt(unsigned int index)
returns scene with the given index in the vector of scenes
void DeleteSceneAt(unsigned int index)
removes scene with the given index in the vector of scenes
bool MiddleMouseDown(int x, int y)
virtual bool SpecialKeyUp(int)
react to press of special keys such as F1-F12, ...
virtual bool LeftMouseSingleClicked(int, int)
react to left mouse single click overwrite in derived class of desired
void EnableStencilUsage(bool enable)
Enable the useage of stencil buffer.
virtual BIAS::HomgPoint3D UnProject(const unsigned int x, const unsigned int y)=0
virtual int GetGreyImage(BIAS::Image< unsigned char > &Image)
Get the currently displayed image as unsigned char grey image.
virtual bool GetViewportCoordinates(int &x, int &y)=0
Takes x, y as window coordinates, checks whether the coordinates lie in the rendered image (in the vi...
double Length() const
returns the Euclidean Length of the Vector
Definition: Vector3.hh:145
void ClearScenes()
Delete the attached scenes.
Scene that renders a background image behind all other scenes.
Definition: SceneBGImage.hh:42
virtual bool MouseLeftWindow()
react to mouse leaving the window overwrite in derived class of desired
virtual int GetDepthMap(BIAS::Image< float > &Image, const float invalid=0.0)
Get the currently displayed depth image.
virtual bool StandardKeyUp(unsigned char, int, int)
react to press of ascii-coded charakter plus pointer position
bool StandardKeyUp(unsigned char, int, int)
virtual int GetMetricZMap(BIAS::Image< float > &Image, const float invalid=0.0)
Get the currently displayed zbuffer image in metric (real) values.
virtual bool LeftMouseDoubleClicked(int, int, int m)
react to left mouse double click overwrite in derived class of desired
virtual BIAS::ProjectionParametersBase * GetMyselfAsProjectionParametersBase() const =0
void AppendView(View *view)
Append a view to the context.
void RemoveAdditionalListener(ControlInterface &listener)
virtual int GetZBuffer(BIAS::Image< float > &zBuffer)=0
int GetSceneCount()
Get the number of attached scenes.
bool RightMouseDoubleClicked(int x, int y)
virtual bool MouseMoved(int, int)
react to mouse movement overwrite in derived class of desired
virtual bool RightMouseMoved(int, int, int, int)
react to mouse movement while right button held down overwrite in derived class of desired ...
SceneBGImage * backgroundImageScene_
bool LeftMouseDown(int x, int y)
virtual int Render()
Simple rendering routine.
virtual bool TimerExpired()
this function is called by RenderContextBase when timer is expired Overwrite and implement to do some...
virtual void SetFarClippingPlane(float f)=0
bool MouseWheelUsed(double stepsize)
virtual bool RightMouseSingleClicked(int, int)
react to right mouse single click event overwrite in derived class of desired
bool LeftMouseMoved(int x1, int x2, int y1, int y2)
Wrapper for pthread mutex for use with &#39;automatic&#39; initialization.
virtual bool StandardKeyPressed(unsigned char, int, int)
react to press of ascii-coded charakter plus pointer position
virtual int GetZBuffer(BIAS::Image< float > &Image)
Get the currently displayed zbuffer image (values 0-1)
virtual bool WindowReshape(int, int)
this function is called by RenderContextBase if the window is reshaped.
bool GetSceneCenter(BIAS::Vector3< double > &center, BIAS::Vector3< double > &radius)
Returns the center of all bounding boxes of appended scenes and the radius which include all scenes...
bool TimerExpired()
Always informs both camera and scenes!
virtual void GetImage(BIAS::Image< unsigned char > &image)=0
ControlInterface * control_
virtual void SetClearColor(const BIAS::Vector4< float > &cc)=0
void DeleteScenes()
Delete the attached scenes.
virtual bool MiddleMouseMoved(int, int, int, int)
react to mouse movement while middle button held down overwrite in derived class of desired ...
Abstract interface class to handle changes in rendering parameters by controllers and in rendering co...
bool MiddleMouseUp(int x, int y)
void AppendScene(SceneBase *scene, bool push_front=false)
attach scenes to render here
bool StandardKeyPressed(unsigned char, int, int)
void PrintGLStatus()
prints to current status of the OpenGL context
virtual bool RightMouseDown(int, int)
react to right mouse button down event overwrite in derived class of desired
bool RightMouseSingleClicked(int x, int y)
bool LeftMouseUp(int x, int y)
virtual bool LeftMouseDown(int, int)
react to left mouse button down event overwrite in derived class of desired
std::vector< ControlInterface * > additionalListeners_
Listening for special keys only.
bool RightMouseDown(int x, int y)
void SetGLProjectionParametersInterface(GLProjectionParametersInterface *newCamera)
set the camera parameters
bool LeftAndRightMouseMoved(int x1, int x2, int y1, int y2)
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
A view is a rectangular part of a render context in which a set of scenes is rendered using a GLProje...
Definition: View.hh:25
bool RightMouseUp(int x, int y)
virtual void MakeGLContextCurrent()=0
try to make this OpenGl context current
static BIAS::MutexSingleton * contextLock_
virtual bool LeftMouseMoved(int, int, int, int)
react to mouse movement while left button held down overwrite in derived class of desired ...
bool WindowReshape(int width, int height)
void DeleteBackgroundImageScene()
Delete the background image scene.
virtual bool LeftMouseUp(int, int)
react to left mouse button up event overwrite in derived class of desired
virtual void SetNearClippingPlane(float n)=0
Base class for all scenes.
Definition: SceneBase.hh:68
void SetBackgroundImageScene(SceneBGImage *backgroundImageScene)
Deactivate background image rendering pass by passing NULL here, or deactivating scene itself...
GLProjectionParametersInterface * camera_
virtual bool MouseWheelUsed(double stepsize)
react to mouse wheel usage overwrite in derived class of desired
virtual int GetMetricZMap(BIAS::Image< float > &metricZMap, const float invalid=0.0)=0
bool MiddleMouseMoved(int x1, int x2, int y1, int y2)
void InsertSceneAt(SceneBase *scene, unsigned int index)
Inserts or deletes a scene at the specified position in std::vector&lt;SceneBase*&gt; scenes_.
virtual int Draw(std::vector< BIAS::SceneBase * > &scenes, BIAS::SceneBGImage *backgroundImageScene=NULL, BIAS::glfFramebufferObject *theTarget=NULL)=0
virtual void SetGLProjectionParametersInterface(BIAS::GLProjectionParametersInterface *interface_)
Set the camera projection parameters.
void SetClearColor(const BIAS::Vector4< float > &cc)
set the opengl clear color for color buffer
bool MouseMoved(int x, int y)
virtual bool LeftAndRightMouseMoved(int, int, int, int)
react to mouse movement while right and middle button held down overwrite in derived class of desired...
virtual bool MiddleMouseUp(int, int)
react to middle mouse button up event overwrite in derived class of desired
std::vector< SceneBase * > scenes_
virtual int GetDepthMap(BIAS::Image< float > &depthMap, const float invalid=0.0)=0
virtual bool MiddleMouseDown(int, int)
react to middle mouse button down event overwrite in derived class of desired
virtual bool RightMouseUp(int, int)
react to right mouse button up event overwrite in derived class of desired
BIAS::Vector4< float > ClearColor_
virtual bool RightMouseDoubleClicked(int, int)
react to right mouse double click overwrite in derived class of desired
Defines the common interface used for communication between rendering components. ...
void CenterViewport(bool center=true)
center the viewport
bool RightMouseMoved(int x1, int x2, int y1, int y2)
void Init_()
called once when rendering starts
virtual bool SpecialKeyPressed(int)
react to press of special keys such as F1-F12, ...
virtual int GetImage(BIAS::Image< unsigned char > &Image)
Get the currently displayed image as unsigned char color image.
void SetControl(BIAS::ControlInterface *newControl)
Control is implemented the following way: cout&lt;&lt;&quot;F1&quot;&lt;&lt;endl; All input is passed to control_ first...
std::vector< View * > views_
void RemoveScene(SceneBase *scene, bool noWarning=false)
removes scene with the given pointer from the vector of scenes
virtual void SetGLProjectionParametersInterface(GLProjectionParametersInterface *nc)
Set the camera as projectionparametersinterface, can be of type GLProjection of of any from GLProject...
Definition: SceneBase.hh:80