1 #include <GLviewer/GLProjectionParametersPerspective.hh>
2 #include <GLviewer/Scenes/SceneBGImage.hh>
3 #include <OpenGLFramework/Base/glfMatrix.hh>
5 #define RAD_TO_DEG 57.29577951
6 #define DEG_TO_RAD 0.017453292
13 GLProjectionParametersPerspective::
14 GLProjectionParametersPerspective() :
36 distorter_ = glppp.distorter_;
48 distorter_ = glppp.distorter_;
69 Load (
const std::string& Filename){
73 Save (
const std::string& Filename)
const{
86 if (imageWidth == -1 || imageHeight == -1)
93 viewport[2] = imageWidth;
94 viewport[3] = imageHeight;
97 double imgAspectRatio = (double) viewport[2] / (
double) viewport[3];
100 double imageSceneHeight = 2.0 * tan(fovyDEG/2.0 * DEG_TO_RAD);
101 double imageSceneWidth = imageSceneHeight * imgAspectRatio;
106 K[0][2] = (double)viewport[2]/2.0 - 0.5;
107 K[1][2] = (double)viewport[3]/2.0 - 0.5;
109 K[0][0] = (double)viewport[2]/imageSceneWidth;
110 K[1][1] = (double)viewport[3]/imageSceneHeight;
125 (
unsigned int) viewport[3]);
140 BIASERR(
"Not a perspective projection!")
161 BIASERR(
"Not a perspective projection!")
180 unsigned int imgWidth, imgHeight;
189 glMatrixMode(GL_PROJECTION);
191 glMatrixMode(GL_MODELVIEW);
216 unsigned int width,
unsigned int height)
221 double kc1, kc2, kc3, kc4;
238 unsigned int fullW, fullH;
247 if( fullW!=width || fullH!=height)
253 BIASERR(
"distortion rendering is not implemented to work with image "
254 "cut outs!"<<endl<<
"x0: "<<x0<<
" y0:"<<y0<<
" fullW: "<<fullW
255 <<
" widht:"<<width <<
" fullH: "<<fullH<<
" height: "<<height);
263 distortDummy.
SetK(idealK);
273 clippingWindowUL *= (
zNear_/clippingWindowUL[2]);
274 clippingWindowLR *= (
zNear_/clippingWindowLR[2]);
277 glPushAttrib(GL_TRANSFORM_BIT);
278 glMatrixMode(GL_PROJECTION);
283 glFrustum(clippingWindowUL[0], clippingWindowLR[0],
286 -clippingWindowLR[1], -clippingWindowUL[1],
294 x0, y0, width, height,
296 projectionMatrix.
Load();
312 Draw_(std::vector<SceneBase *>& scenes,
323 if(scenes.size() > 0){
324 for (
unsigned int i=0; i<scenes.size(); i++) {
326 scenes[i]->UpdateCameraRelatedState();
351 glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_TEXTURE_BIT |GL_STENCIL_BUFFER_BIT);
352 glEnable(GL_STENCIL_TEST);
353 glEnable(GL_DEPTH_TEST);
354 glDepthMask(GL_TRUE);
355 glStencilFunc(GL_EQUAL, 1, (GLuint)(~0));
356 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
357 glMatrixMode(GL_MODELVIEW);
360 glMatrixMode(GL_PROJECTION);
363 glDepthFunc(GL_ALWAYS);
364 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
365 glColorMask(0,0,0,1);
367 glDisable(GL_TEXTURE_2D);
370 glVertex3f(-s, s, -s);
371 glVertex3f(-s, -s, -s);
372 glVertex3f(s, -s, -s);
373 glVertex3f(s, s, -s);
375 glColorMask(1,1,1,1);
376 glDepthFunc(GL_LESS);
377 glMatrixMode(GL_PROJECTION);
379 glMatrixMode(GL_MODELVIEW);
383 glDisable(GL_STENCIL_TEST);
388 int imageWidth,
int imageHeight,
389 std::vector<SceneBase*>& scenes)
411 double decisionScaleWidth = (double)viewport[2] / (
double)imageWidth;
412 double decisionScaleHeight = (double)viewport[3] / (
double)imageHeight;
413 double decisionScale;
415 if(decisionScaleWidth>decisionScaleHeight)
416 decisionScale = 1.0/decisionScaleWidth;
418 decisionScale = 1.0/decisionScaleHeight;
435 for(
unsigned int i=0; i<4; i++)
464 if (distorter_ == -1) {
466 double kc1, kc2, kc3, kc4;
483 Z2Depth_(
const int x,
const int y,
const double z)
const
500 BIASASSERT(!
Equal(pl[2], 0.0));
virtual int EndDraw_(BIAS::glfFramebufferObject *theTarget=NULL)
int SetSimplePerspectiveCam(double fovyDEG, int imageWidth=-1, int imageHeight=-1)
BIAS::Vector4< int > lastFullGLViewport_
Remembering the last full viewport prevent unecessary calculations in AutoRescaleParams behaviour...
GLPPB encapsulates the opengl rendering interface for the projectionparameter classes.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
void MakeProjectionMatrixNew(const ProjectionParametersPerspective ¶ms, GLfloat nearZ, GLfloat farZ, unsigned int x0, unsigned int y0, unsigned int width, unsigned int height, bool useIdealK=false, bool flip=false)
int XMLRead(const std::string &Filename)
derived classes must implement the function XMLIn which is called by this function XMLRead to read ev...
BIAS::Matrix4x4< double > GLProjectionMatrix_
std::deque< BIAS::GLProjectionOutputAttachment * > outputAttachments_
virtual void SetClearColor(const BIAS::Vector4< float > &cc)
setclearcolor is pure virtual.
virtual void SetR(const BIAS::RMatrix &R)
Set orientation from rotation matrix R.
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual int GetPrincipal(double &PrincipalX, double &PrincipalY) const
Get principal point (in pixels relative to top left corner).
virtual void SetPrincipal(const double x, const double y)
Set principal point in pixels relative to top left corner, virtual overload to recalculate K_...
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
void AppendOutputAttachment(int type, std::vector< int > args=std::vector< int >())
bool ExtrinsicStateChanged_
Changes to the parameters or GL state that lead to new calculation of GL_MODELVIEW matrix...
std::deque< int > outputAttachmentIdentifiers_
virtual void InitShaders_()
virtual int BeginDraw_(BIAS::glfFramebufferObject *theTarget=NULL)
int SetGLViewport_(int lowerleftx, int lowerlefty, int sizex, int sizey)
bool IntrinsicStateChanged_
Changes to the parameters or GL state that lead to new calculation of GL_PROJECTION matrix...
int DrawWithMatchedParamsAndViewport_(int viewport[4], int imageWidth, int imageHeight, std::vector< SceneBase * > &scenes)
Takes care of adapting internal parameters and gl viewport by specified behaviour scheme...
BIAS::Matrix4x4< double > GLModelViewMatrix_
void SetUndistortion(double kc1, double kc2)
Exception class used for run-time errors in the OpenGLFramework.
void GetUndistortion(double &kc1, double &kc2, double &kc3, double &kc4) const
void SetIdealImageSize(unsigned int width, unsigned int height)
virtual BIAS::ProjectionParametersBase * GetMyselfAsProjectionParametersBase() const
the pure virtual GetMyselfAsProjectionParameterBase() forces the child classes to inherit from a proj...
virtual int Save(const std::string &filename) const
const std::string & GetMessageString() const
Returns the description of the error including the file name and line number where the error occured...
virtual int XMLRead(const std::string &Filename)
virtual void SetPose(const BIAS::Pose pose)
Set pose from pose object.
virtual void Rescale_(float scale)
virtual int UpdateGLProjectionMatrix_(unsigned x0, unsigned y0, unsigned width, unsigned height)
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
GLProjectionParametersPerspective()
void Set(BIAS::ProjectionParametersBase *p)
BIAS::GLProjectionParametersInterface::ViewingReshapeBehaviour AutoViewingMatchBehaviour_
virtual bool PoseValid() const
Check if current pose is valid.
int XMLWrite(const std::string &Filename, int CompressionLevel=0, bool AutoAddCompressionSuffix=true, std::string encoding="UTF-8") const
call this to add the class to a new xml tree and write it to the file Filename.
void SetIntrinsics(BIAS::ProjectionParametersBase *p)
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
std::deque< std::vector< int > > outputAttachmentOptions_
BIAS::Vector4< float > ClearColor_
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool ignoreDistortion=false) const =0
Calculates the view ray, which belongs to the given position on the image plane, in local coordinates...
void GetIdealK(KMatrix &K) const
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
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_...
void ClearDepthAndAlpha_()
virtual int Draw_(std::vector< SceneBase * > &scenes, BIAS::glfFramebufferObject *theTarget=NULL)
Rendering with current matrices GLProjectionMatrix_, GLModelViewMatrix_.
A 4x4 matrix in native OpenGL format.
void Rescale(float ratio)
Returns the absolute world coordinate frame position of camera.
GLProjectionParametersPerspective & operator=(const GLProjectionParametersPerspective &glppp)
double GetFocalLength() const
Returns the focal length.
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
bool informScenesOfChange_
Abstract projection params have changed, scenes have to be informed about this.
ProjectionParametersPerspective & operator=(const ProjectionParametersPerspective &P)
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &pointOnRay, Vector3< double > &direction, bool IgnoreDistortion=false) const
calculates the viewing ray from the camera center (in the camera coordinate system) which belongs to ...
void GetIdealImageSize(unsigned int &width, unsigned int &height) const
void SetFocalLengthAndAspect(double f, double AspectRatio)
Set the current camera focal length in pixel and the a spect ratio.
virtual void Rescale(double ratio, const double offset=0.0)
Adapt internal parameters to resampled image.
int UpdateGLModelViewMatrix_()
virtual int XMLWrite(const std::string &Filename) const
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
virtual void Load() const
Loads the matrix in OpenGL.
virtual void SetK(const KMatrix &K)
sets the internal parameters from a given KMatrix and updates the cached K and its inverse ...
virtual int DrawWithMatchedParamsAndViewport_(int viewport[4], int imageWidth, int imageHeight, std::vector< SceneBase * > &scenes)
Takes care of adapting internal parameters and gl viewport by specified behaviour scheme...
virtual void SetC(const BIAS::Vector3< double > &C)
Set projection center.
virtual int Load(const std::string &filename)
virtual int SetGLMatrices(bool forceUpdate=true)
Method loads the parameters into the projection and modelview Matrix.
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
class BIASGeometryBase_EXPORT HomgPoint2D
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...
virtual double Z2Depth_(const int x, const int y, const double z) const
class for rendering with projection parameters of ProjectionParametersPerspective ...