Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleTemplateSpecializedBatch.cpp

Example for specialized batch usage

,TemplateSpecializedBatch,glfException,glfFramebufferObject,glfTexture2D

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleTemplateSpecializedBatch.cpp
@relates glfPBuffer,TemplateSpecializedBatch,glfException,glfFramebufferObject,glfTexture2D
@brief Example for specialized batch usage
@ingroup g_examples
@ingroup g_openglframework
@author MIP
*/
#include <OpenGLFramework/RenderingContext/glfPBuffer.hh>
#include <OpenGLFramework/SpecializedBatches/TemplateSpecializedBatch.hh>
#include <OpenGLFramework/Base/glfException.hh>
#include <OpenGLFramework/Base/glfFramebufferObject.hh>
#include <OpenGLFramework/Base/glfTexture2D.hh>
#include <Utils/Param.hh>
#include <Utils/IOUtils.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/Image.hh>
#include <Image/Camera.hh>
//#include <mip_config.h>
#include <Gui/biasgl.h>
using namespace std;
using namespace BIAS;
int main(int argc, char* argv[])
{
Param params(true);
string* camName = params.AddParamString("image",
"filename of a BIAS readable unsigned char image", "");
string* outName = params.AddParamString("outName",
"name of the output permutated mip image", "");
if(!IOUtils::ParseCommandLineEvalHelp(params, argc, argv) )
return 0;
if(!IOUtils::LoadCamera(camName, cam)) {
return -1;
}
unsigned int width = cam.GetWidth();
unsigned int height = cam.GetHeight();
glfPBuffer pbuf;
/* The try block fullfills two tasks
* a) trying OpenGLFrameworkExceptions
* b) ensuring the live span of GL objects to be shorter
* than the live span of the GL Context, which is pbuf.
*/
try {
/* Observe that the objects are allocated before
* the gl context is available
*/
glfTexture2D resultTexture;
/** Since we will use FBO the
* resolution of the PBuffer does not
* matter,the bits in the different
* buffers, however, do matter!
* E.g. no depthSize, no z-buffer.
**/
cfg.width = 5;
cfg.height = 5;
cfg.doubleBuffer = 0;
cfg.redSize = 8;
cfg.greenSize = 8;
cfg.blueSize = 8;
cfg.alphaSize = 0;
cfg.depthSize = 24;
cfg.stencilSize = 0;
pbuf.Init(cfg);
//*******************
// output
//*******************
resultTexture.Create();
resultTexture.Set();
resultTexture.Allocate(width, height, GL_RGB);
fbo.Create();
fbo.AttachTexture(resultTexture, GL_COLOR_ATTACHMENT0_EXT);
fbo.ClearColorBuffer(1.0); //buffer is cleared to red.
//so at least we get a red image
tsb.Init(TemplateSpecializedBatch::myProcessingScheme);
tsb.SetViewport(width, height);
tsb.SetRenderTarget(&fbo);
tsb.Execute();
resultTexture.CopyToImage(resultImg);
// resultImg.Flip();
IOUtils::SaveCamera(*outName, resultImg);
} catch (glfException& e) {
std::cout << "Error: " << e.GetMessageString() << std::endl;
pbuf.Destroy();
return -1;
}
pbuf.Destroy();
}