1 #include <GLviewer/RenderContextBase.hh>
2 #include <GLviewer/Scenes/SceneBGImage.hh>
4 #include <Gui/biasgl.h>
17 #ifdef BIAS_HAVE_PTHREADS
37 #ifdef BIAS_HAVE_PTHREADS
40 int res = contextLock_->
Lock();
47 return contextLock_->
Unlock();
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);
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;
80 BIASERR(
"No camera set!\n");
93 BIASERR(
"No camera set!\n");
106 BIASERR(
"No camera set!\n");
121 BIASERR(
"No camera set!\n");
137 BIASERR(
"No camera set!\n");
154 glEnable(GL_DEPTH_TEST);
155 glDepthFunc(GL_LESS);
157 glGetIntegerv(GL_DEPTH_BITS,&depthbits);
159 BIASERR(
"No depth buffer was found most functionality is unavailable!");
168 glGetIntegerv(GL_ALPHA_BITS, &alphabits);
169 if(alphabits>0 && blend)
182 glEnable(GL_CULL_FACE);
184 glDisable(GL_CULL_FACE);
192 #ifndef TURN_OF_LOCKING
193 #ifdef BIAS_HAVE_PTHREADS
198 GLenum err = glGetError();
199 if (err != GL_NO_ERROR) {
200 BIASERR(
"OpenGL Error before rendering: " << gluErrorString(err));
205 BIASERR(
"No GLProjection object set!\n");
206 #ifdef BIAS_HAVE_PTHREADS
222 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
226 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
236 bool autoClippingSucceeded =
false;
238 for (
unsigned int i = 0; i <
scenes_.size(); i++)
240 double newNear = 0.0;
243 scenes_[i]->GetBoundingBox(min, max);
258 centerOfBox = max - min;
259 centerOfBox = centerOfBox / 2.0;
260 radiusOfSphere = centerOfBox;
261 centerOfBox = min + centerOfBox;
264 direction = (centerOfBox - C);
265 newNear = (direction.
Length() - radiusOfSphere.
Length());
266 newFar = (direction.
Length() + radiusOfSphere.
Length());
268 if (zNear == 0.0) zNear = newNear;
280 autoClippingSucceeded =
true;
284 if (autoClippingSucceeded) {
290 if (zFar < zNear*1.01) zFar = zNear*1.01;
297 BIASWARNONCE(
"autoclipping active but no bounding boxes could be retrieved.");
305 for (
int i = 0; i < (int)views_.size(); i++) {
313 #ifndef TURN_OF_LOCKING
314 #ifdef BIAS_HAVE_PTHREADS
319 if (err != GL_NO_ERROR) {
320 BIASERR(
"OpenGL Error after rendering: " << gluErrorString(err));
346 int numberOfScenes = (int)
scenes_.size();
347 for (
int i = 0; i < numberOfScenes; i++)
354 if (!noWarning) BIASWARN(
"Cannot remove scene. Unknown scene pointer");
360 vector<SceneBase*>::iterator itor =
scenes_.begin();
370 scenes_.insert( itor, 1, scene );
389 vector<SceneBase*>::iterator itor =
scenes_.begin();
393 BIASERR(
"Index out of range");
408 for(
unsigned int i=0; i<
scenes_.size(); i++)
415 BIASASSERT(index <
scenes_.size())
428 std::vector<ControlInterface*>::iterator begin, end, pos;
429 begin = additionalListeners_.begin();
430 end = additionalListeners_.end();
432 for(pos = begin; test != *pos && pos != end; pos++) {}
434 additionalListeners_.erase(pos);
445 unsigned int foundBoundingBox = 0;
447 for (
unsigned int i = 0; i < scenes_.size(); i++)
449 scenes_[i]->GetBoundingBox(min, max);
458 newRadius = ((max - min) / 2.0);
459 newCenter = newRadius + min;
464 if (foundBoundingBox >= 2)
468 newCenter = (newCenter - center) / 2.0;
469 newRadius = newCenter + radius;
470 newCenter = newCenter + center;
480 if (radius.
Length() == 0.0)
490 if(newCamera == NULL) {
491 BIASERR(
"RenderContextBase: specified camera is NULL");
496 for(
unsigned int i=0; i<
scenes_.size(); i++)
506 bool callCaught =
false;
511 callCaught = callCaught || res;
553 bool callCaught =
false;
560 callCaught = callCaught || res;
567 bool callCaught =
false;
575 callCaught = callCaught || res;
584 bool callCaught =
false;
594 for(
unsigned i=0;i<
scenes_.size();i++)
595 scenes_[i]->SelectObjectAt(p3);
607 callCaught = callCaught || res;
616 bool callCaught =
false;
623 callCaught = callCaught || res;
632 bool callCaught =
false;
640 callCaught = callCaught || res;
649 bool callCaught =
false;
656 callCaught = callCaught || res;
665 bool callCaught =
false;
669 if(
scenes_.size() == 0 || callCaught)
675 callCaught = callCaught || res;
683 bool callCaught =
false;
690 callCaught = callCaught || res;
697 bool callCaught =
false;
705 callCaught = callCaught || res;
713 bool callCaught =
false;
719 callCaught = callCaught || res;
727 bool callCaught =
false;
731 if(
scenes_.size() == 0 || callCaught)
737 callCaught = callCaught || res;
744 bool callCaught =
false;
751 callCaught = callCaught || res;
758 bool callCaught =
false;
766 callCaught = callCaught || res;
775 bool callCaught =
false;
784 callCaught = callCaught || res;
793 bool callCaught =
false;
797 if(
scenes_.size() == 0 || callCaught)
803 callCaught = callCaught || res;
811 bool callCaught =
false;
819 callCaught = callCaught || res;
828 bool callCaught =
false;
836 callCaught = callCaught || res;
847 bool callCaught =
false;
855 callCaught = callCaught || res;
863 bool callCaught =
false;
871 callCaught = callCaught || res;
880 bool callCaught =
false;
887 callCaught = callCaught || res;
903 glGetIntegerv(GL_VIEWPORT, viewport);
907 if(viewport[2]>width) {
909 newviewport[2]=width;
911 int viewportHalfWidth = viewport[2]/2;
912 int windowHalfWidth = width/2;
913 newviewport[0]=windowHalfWidth-viewportHalfWidth;
914 newviewport[2]=viewport[2];
917 if(viewport[3]>height) {
919 newviewport[3]=width;
921 int viewportHalfHeight = viewport[3]/2;
922 int windowHalfHeight = height/2;
923 newviewport[1]=windowHalfHeight-viewportHalfHeight;
924 newviewport[3]=viewport[3];
927 glViewport(newviewport[0], newviewport[1], newviewport[2], newviewport[3]);
932 glViewport(0,0, width, height);
951 BIASASSERT(view != NULL);
952 views_.push_back(view);
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 int GetGreyImage(BIAS::Image< unsigned char > &Image, bool lock=true)
brief Get the currently displayed image as unsigned char grey image Set lock to false if no context l...
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 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
void ClearScenes()
Delete the attached scenes.
Scene that renders a background image behind all other scenes.
virtual bool MouseLeftWindow()
react to mouse leaving the window overwrite in derived class of desired
virtual bool StandardKeyUp(unsigned char, int, int)
react to press of ascii-coded charakter plus pointer position
bool StandardKeyUp(unsigned char, int, int)
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 GetMetricZMap(BIAS::Image< float > &Image, const float invalid=0.0, bool lock=true)
brief Get the currently displayed zbuffer image in metric (real) values Set lock to false if no conte...
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 'automatic' initialization.
virtual bool StandardKeyPressed(unsigned char, int, int)
react to press of ascii-coded charakter plus pointer position
virtual bool WindowReshape(int, int)
this function is called by RenderContextBase if the window is reshaped.
bool GetSceneCenter(BIAS::Vector3< double > ¢er, 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 SpecialKeyUp(int key)
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
virtual int GetZBuffer(BIAS::Image< float > &Image, bool lock=true)
brief Get the currently displayed zbuffer image (values 0-1) * Set lock to false if no context lock s...
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
int ReleaseContextSwitch()
bool LeftAndRightMouseMoved(int x1, int x2, int y1, int y2)
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
A view is a rectangular part of a render context in which a set of scenes is rendered using a GLProje...
bool RightMouseUp(int x, int y)
virtual void MakeGLContextCurrent()=0
try to make this OpenGl context current
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.
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<SceneBase*> 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
bool SpecialKeyPressed(int key)
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)
virtual int GetImage(BIAS::Image< unsigned char > &Image, bool lock=true)
brief Get the currently displayed image as unsigned char color image.
void Init_()
called once when rendering starts
virtual int GetDepthMap(BIAS::Image< float > &Image, const float invalid=0.0, bool lock=true)
brief Get the currently displayed depth image Set lock to false if no context lock should be used (i...
virtual bool SpecialKeyPressed(int)
react to press of special keys such as F1-F12, ...
void SetControl(BIAS::ControlInterface *newControl)
Control is implemented the following way: cout<<"F1"<<endl; All input is passed to control_ first...
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...