OpenGLCapture.cpp
Go to the documentation of this file.
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:  OpenGLCapture.cpp
00037 // Author:    Pedram Azad
00038 // Date:      27.07.2008
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include "OpenGLCapture.h"
00047 #include "Image/ImageProcessor.h"
00048 #include "Image/ByteImage.h"
00049 #include "Calibration/Calibration.h"
00050 #include "Calibration/StereoCalibration.h"
00051 #include "Visualizer/OpenGLVisualizer.h"
00052 
00053 
00054 
00055 // *****************************************************************
00056 // Constructors / Destructor
00057 // *****************************************************************
00058 
00059 COpenGLCapture::COpenGLCapture()
00060 {
00061         m_nCameras = 0;
00062 
00063         width = height = 0;
00064         type = CByteImage::eRGB24;
00065 
00066         m_pOpenGLVisualizer = 0;
00067         m_pCalibration = 0;
00068         m_pStereoCalibration = 0;
00069 }
00070 
00071 COpenGLCapture::COpenGLCapture(const CCalibration &calibration)
00072 {
00073         m_nCameras = 1;
00074 
00075         width = calibration.GetCameraParameters().width;
00076         height = calibration.GetCameraParameters().height;
00077         type = CByteImage::eRGB24;
00078         
00079         m_pOpenGLVisualizer = new COpenGLVisualizer();
00080         m_pCalibration = new CCalibration();
00081         m_pStereoCalibration = 0;
00082         
00083         m_pCalibration->Set(calibration);
00084 }
00085 
00086 COpenGLCapture::COpenGLCapture(const CStereoCalibration &stereoCalibration)
00087 {
00088         m_nCameras = 2;
00089 
00090         width = stereoCalibration.width;
00091         height = stereoCalibration.height;
00092         type = CByteImage::eRGB24;
00093         
00094         m_pOpenGLVisualizer = new COpenGLVisualizer();
00095         m_pStereoCalibration = new CStereoCalibration();
00096         m_pCalibration = 0;
00097 
00098         m_pStereoCalibration->Set(stereoCalibration);
00099 }
00100 
00101 COpenGLCapture::~COpenGLCapture()
00102 {
00103         if (m_pCalibration)
00104                 delete m_pCalibration;
00105 
00106         if (m_pStereoCalibration)
00107                 delete m_pStereoCalibration;
00108 
00109         if (m_pOpenGLVisualizer)
00110                 delete m_pOpenGLVisualizer;
00111 }
00112 
00113 
00114 // ****************************************************************************
00115 // Methods
00116 // ****************************************************************************
00117 
00118 void COpenGLCapture::Set(const CCalibration &calibration)
00119 {
00120         m_nCameras = 1;
00121 
00122         width = calibration.GetCameraParameters().width;
00123         height = calibration.GetCameraParameters().height;
00124         type = CByteImage::eRGB24;
00125 
00126         if (m_pStereoCalibration)
00127         {
00128                 delete m_pStereoCalibration;
00129                 m_pStereoCalibration = 0;
00130         }
00131 
00132         if (!m_pCalibration)
00133                 m_pCalibration = new CCalibration();
00134         
00135         if (!m_pOpenGLVisualizer)
00136                 m_pOpenGLVisualizer = new COpenGLVisualizer();
00137 
00138         m_pCalibration->Set(calibration);
00139 }
00140 
00141 
00142 void COpenGLCapture::Set(const CStereoCalibration &stereoCalibration)
00143 {
00144         m_nCameras = 2;
00145 
00146         width = stereoCalibration.width;
00147         height = stereoCalibration.height;
00148         type = CByteImage::eRGB24;
00149 
00150         if (m_pCalibration)
00151         {
00152                 delete m_pCalibration;
00153                 m_pCalibration = 0;
00154         }
00155 
00156         if (!m_pStereoCalibration)
00157                 m_pStereoCalibration = new CStereoCalibration();
00158         
00159         if (!m_pOpenGLVisualizer)
00160                 m_pOpenGLVisualizer = new COpenGLVisualizer();
00161 
00162         m_pStereoCalibration->Set(stereoCalibration);
00163 }
00164 
00165 bool COpenGLCapture::OpenCamera()
00166 {
00167         if (m_pStereoCalibration)
00168                 return m_pOpenGLVisualizer->InitByCalibration(m_pStereoCalibration->GetLeftCalibration());
00169         else if (m_pCalibration)
00170                 return m_pOpenGLVisualizer->InitByCalibration(m_pCalibration);
00171         else
00172                 printf("error: no calibration object has been instantiated\n");
00173 
00174         return false;
00175 }
00176 
00177 void COpenGLCapture::CloseCamera()
00178 {
00179 }
00180 
00181 bool COpenGLCapture::CaptureImage(CByteImage **ppImages)
00182 {
00183         if (ppImages[0]->width != width || ppImages[0]->height != height || ppImages[0]->type != type)
00184                 printf("error: image does not match COpenGLCapture::CaptureImage\n");
00185         
00186         if (m_nCameras == 1)
00187         {
00188                 m_pOpenGLVisualizer->InitByCalibration(m_pCalibration);
00189                 DrawScene(); // virtual method call
00190                 m_pOpenGLVisualizer->GetImage(ppImages[0]);
00191                 ImageProcessor::FlipY(ppImages[0], ppImages[0]);
00192         }
00193         else if (m_nCameras == 2)
00194         {
00195                 if (ppImages[1]->width != width || ppImages[1]->height != height || ppImages[1]->type != type)
00196                         printf("error: image does not match COpenGLCapture::CaptureImage\n");
00197         
00198                 // left camera
00199                 m_pOpenGLVisualizer->InitByCalibration(m_pStereoCalibration->GetLeftCalibration());
00200                 DrawScene(); // virtual method call
00201                 m_pOpenGLVisualizer->GetImage(ppImages[0]);
00202                 ImageProcessor::FlipY(ppImages[0], ppImages[0]);
00203                 
00204                 // right camera
00205                 m_pOpenGLVisualizer->InitByCalibration(m_pStereoCalibration->GetRightCalibration());
00206                 DrawScene(); // virtual method call
00207                 m_pOpenGLVisualizer->GetImage(ppImages[1]);
00208                 ImageProcessor::FlipY(ppImages[1], ppImages[1]);
00209         }
00210         
00211         return true;
00212 }


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:57