Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleTemplateSpecializedBatch.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 /**
26  @example ExampleTemplateSpecializedBatch.cpp
27  @relates glfPBuffer,TemplateSpecializedBatch,glfException,glfFramebufferObject,glfTexture2D
28  @brief Example for specialized batch usage
29  @ingroup g_examples
30  @ingroup g_openglframework
31  @author MIP
32 */
33 
34 
35 #include <OpenGLFramework/RenderingContext/glfPBuffer.hh>
36 #include <OpenGLFramework/SpecializedBatches/TemplateSpecializedBatch.hh>
37 #include <OpenGLFramework/Base/glfException.hh>
38 #include <OpenGLFramework/Base/glfFramebufferObject.hh>
39 #include <OpenGLFramework/Base/glfTexture2D.hh>
40 
41 
42 #include <Utils/Param.hh>
43 #include <Utils/IOUtils.hh>
44 #include <Base/Image/ImageIO.hh>
45 #include <Base/Image/Image.hh>
46 #include <Image/Camera.hh>
47 
48 //#include <mip_config.h>
49 #include <Gui/biasgl.h>
50 
51 using namespace std;
52 using namespace BIAS;
53 
54 
55 
56 int main(int argc, char* argv[])
57 {
58  Param params(true);
59 
60  string* camName = params.AddParamString("image",
61  "filename of a BIAS readable unsigned char image", "");
62  string* outName = params.AddParamString("outName",
63  "name of the output permutated mip image", "");
64 
65  if(!IOUtils::ParseCommandLineEvalHelp(params, argc, argv) )
66  return 0;
67 
69 
70  if(!IOUtils::LoadCamera(camName, cam)) {
71  return -1;
72  }
73 
74  unsigned int width = cam.GetWidth();
75  unsigned int height = cam.GetHeight();
76 
77  glfPBuffer pbuf;
78  /* The try block fullfills two tasks
79  * a) trying OpenGLFrameworkExceptions
80  * b) ensuring the live span of GL objects to be shorter
81  * than the live span of the GL Context, which is pbuf.
82  */
83  try {
84  /* Observe that the objects are allocated before
85  * the gl context is available
86  */
89  glfTexture2D resultTexture;
90 
92  /** Since we will use FBO the
93  * resolution of the PBuffer does not
94  * matter,the bits in the different
95  * buffers, however, do matter!
96  * E.g. no depthSize, no z-buffer.
97  **/
98  cfg.width = 5;
99  cfg.height = 5;
100  cfg.doubleBuffer = 0;
101  cfg.redSize = 8;
102  cfg.greenSize = 8;
103  cfg.blueSize = 8;
104  cfg.alphaSize = 0;
105  cfg.depthSize = 24;
106  cfg.stencilSize = 0;
107 
108  pbuf.Init(cfg);
109 
110  //*******************
111  // output
112  //*******************
113  resultTexture.Create();
114  resultTexture.Set();
115  resultTexture.Allocate(width, height, GL_RGB);
116 
117  fbo.Create();
118  fbo.AttachTexture(resultTexture, GL_COLOR_ATTACHMENT0_EXT);
119  fbo.CheckComplete();
120  fbo.ClearColorBuffer(1.0); //buffer is cleared to red.
121  //so at least we get a red image
122 
123  tsb.Init(TemplateSpecializedBatch::myProcessingScheme);
124  tsb.SetViewport(width, height);
125  tsb.SetRenderTarget(&fbo);
126  tsb.UploadTextureImage(cam);
127  tsb.Execute();
128 
129 
130  Camera<unsigned char> resultImg;
131  resultTexture.CopyToImage(resultImg);
132 
133  // resultImg.Flip();
134  IOUtils::SaveCamera(*outName, resultImg);
135 
136  } catch (glfException& e) {
137  std::cout << "Error: " << e.GetMessageString() << std::endl;
138  pbuf.Destroy();
139  return -1;
140  }
141 
142  pbuf.Destroy();
143 }
144 
void Allocate(int width, int height, GLenum internalFormat, int mipmap=0)
Creates a texture with undefined content.
void AttachTexture(const glfTexture &texture, GLenum attachmentPoint, int attachedMipMapLevel=0, int zSlice=0, GLenum cubeMapSide=0)
Attaches a texture to an attachment point which can be.
This file contains the header for a class template.
A 2D texture.
Definition: glfTexture2D.hh:40
void Create()
Creates the texture but does not upload any data yet.
Definition: glfTexture.cpp:80
void CopyToImage(ImageBase &image, int mipmap=0)
Copies the pixels of a mipmap of the texture to a BIAS::ImageBase.
Exception class used for run-time errors in the OpenGLFramework.
Definition: glfException.hh:79
unsigned int GetWidth() const
Definition: ImageBase.hh:312
void SetViewport(unsigned int viewportWidth, unsigned int viewportHeight, unsigned int viewportOx=0, unsigned int viewportOy=0)
Method determines the viewport size, which is used in the render target.
void UploadTextureImage(BIAS::ImageBase &img)
Some textures will certainly be created internally.
virtual void Destroy()
Uninitializes the rendering context.
const std::string & GetMessageString() const
Returns the description of the error including the file name and line number where the error occured...
void Execute()
Configures GL and issues a &quot;rendering&quot; on the GPU.
void CheckComplete() const
Checks whether the framebuffer object is supported in its current state.
unsigned int GetHeight() const
Definition: ImageBase.hh:319
GLX pbuffer rendering context.
virtual void Init(const glfRenderingContextConfig &config)
Initializes the rendering context with the given configuration.
This class Param provides generic support for parameters.
Definition: Param.hh:231
void Init(TemplateSpecializedBatch::ProcessingScheme ps)
This method initializes all necessary GL structures.
void SetRenderTarget(BIAS::glfRenderTarget *rt)
Method determines where the results are delivered.
void Set(GLenum minFilter=GL_NEAREST, GLenum magFilter=GL_NEAREST, GLenum wrapS=GL_CLAMP, GLenum wrapT=GL_CLAMP, GLint textureNr=GL_TEXTURE0)
Convenience wrapper.
void ClearColorBuffer(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=0.0f)
Clears the color buffer of the render target with the given color.
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:327
Configuration for a rendering context.
void Create()
Creates the framebuffer object.