00001 // **************************************************************************** 00002 // This file is part of the Integrating Vision Toolkit (IVT). 00003 // 00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT) 00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de). 00006 // 00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT). 00008 // All rights reserved. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are met: 00012 // 00013 // 1. Redistributions of source code must retain the above copyright 00014 // notice, this list of conditions and the following disclaimer. 00015 // 00016 // 2. Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // 3. Neither the name of the KIT nor the names of its contributors may be 00021 // used to endorse or promote products derived from this software 00022 // without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY 00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY 00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 // **************************************************************************** 00035 // **************************************************************************** 00036 // Filename: OpenGLVisualizer.h 00037 // Author: Pedram Azad 00038 // Date: 2004 00039 // **************************************************************************** 00040 // Changes: 25.10.2010, Zhixing Xue 00041 // * Added COpenGLVisualizer::GetDepthMatrix 00042 // **************************************************************************** 00043 00044 #ifndef _OPENGL_VISUALIZER_SCENE_H_ 00045 #define _OPENGL_VISUALIZER_SCENE_H_ 00046 00047 00048 // **************************************************************************** 00049 // Necessary includes 00050 // **************************************************************************** 00051 00052 #include "Math/Math3d.h" 00053 00054 00055 // **************************************************************************** 00056 // Forward declarations 00057 // **************************************************************************** 00058 00059 class GLUquadric; 00060 class CByteImage; 00061 class CCalibration; 00062 class CFloatMatrix; 00063 00064 00065 00066 // **************************************************************************** 00067 // COpenGLVisualizer 00068 // **************************************************************************** 00069 00070 class COpenGLVisualizer 00071 { 00072 public: 00073 // constructor 00074 COpenGLVisualizer(); 00075 00076 // destructor 00077 ~COpenGLVisualizer(); 00078 00079 // static variables for colors 00080 static const float red[3]; 00081 static const float green[3]; 00082 static const float blue[3]; 00083 static const float yellow[3]; 00084 00085 00086 // public methods 00087 bool Init(int width = 640, int height = 480, bool bActivateShading = true); 00088 bool InitByCalibration(const CCalibration *pCalibration, bool bActivateShading = true); 00089 void ActivateShading(bool bActivateShading); 00090 void SetProjectionMatrix(const CCalibration *pCalibration); 00091 bool GetImage(CByteImage *pDestinationImage); 00092 bool GetDepthMatrix(CFloatMatrix *pDestinationMatrix); 00093 void SetViewMatrix(const Transformation3d &transformation) 00094 { 00095 m_ViewMatrix = transformation; 00096 } 00097 00098 // methods for drawing 00099 void Clear(); 00100 void DrawPoint(float x, float y, float z, const float *pColor = 0); 00101 void DrawPoints(Vec3dList &points, const float *pColor = 0); 00102 void DrawSphere(const Vec3d &point, float radius, const float *pColor = 0); 00103 void DrawCylinder(const Vec3d &point1, const Vec3d &point2, float radius1, float radius2, const float color[3]); 00104 void DrawObject(const CFloatMatrix *pMatrix, const Transformation3d &transformation); 00105 00106 // static methods 00107 static void ConvertToOpenGLMatrix(const Transformation3d &transformation, float resultMatrix[16]); 00108 static void CalculateOpenGLProjectionMatrix(const Mat3d &K, int width, int height, float gnear, float gfar, float *m); 00109 static void CalculateOpenGLProjectionMatrixDefaultPrincipalPoint(const Mat3d &K, int width, int height, float gnear, float gfar, float *m); 00110 00111 00112 private: 00113 // private methods 00114 void SetProjectionMatrix(int nWidth, int nHeight); 00115 bool InitExtension(); 00116 00117 // private attributes 00118 int width, height; 00119 00120 GLUquadric *m_pQuadric; 00121 00122 // current view matrix 00123 bool m_bMatrixOnStack; 00124 Transformation3d m_ViewMatrix; 00125 }; 00126 00127 00128 00129 #endif /* _OPENGL_VISUALIZER_SCENE_H_ */