Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StereoAutoFocuser.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, The Cinder Project, All rights reserved.
3  This code is intended for use with the Cinder C++ library: http://libcinder.org
4 
5  Portions of this code (C) Paul Houx
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
9  the following conditions are met:
10 
11  * Redistributions of source code must retain the above copyright notice, this list of conditions and
12  the following disclaimer.
13  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
14  the following disclaimer in the documentation and/or other materials provided with the distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
17  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
19  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23  POSSIBILITY OF SUCH DAMAGE.
24 */
25 
26 #pragma once
27 
28 #include "cinder/gl/gl.h"
29 #include "cinder/gl/Fbo.h"
30 
31 // forward declarations
32 namespace cinder {
33  class Camera; class CameraPersp; class CameraStereo;
34 } // namespace cinder
35 
36 namespace cinder { namespace gl {
37 
39  public:
41  : mSpeed(1.0f), mDepth(1.0f) {}
42 
48  void autoFocus( CameraStereo *cam, const Area &area = gl::getViewport() ) { autoFocus( cam, area, GL_NONE ); }
54  void autoFocus( CameraStereo *cam, const gl::Fbo &buffer ) { autoFocus( cam, buffer.getBounds(), buffer.getId() ); }
56  float getSpeed() const { return mSpeed; }
60  void setSpeed( float factor ) { mSpeed = math<float>::clamp( factor, 0.01f, 1.0f); }
62  float getDepth() const { return mDepth; }
67  void setDepth( float factor ) { mDepth = math<float>::max( factor, 0.01f); }
68 
70  void draw();
71  private:
72  void createBuffers( const Area &area );
73 
75  void autoFocus( CameraStereo *cam, const Area &area, GLuint buffer );
76  public:
78  static const int AF_WIDTH = 64;
79  static const int AF_HEIGHT = 64;
80  private:
81  float mSpeed;
82  float mDepth;
83 
84  Area mArea;
85 
86  Fbo mFboSmall;
87  Fbo mFboLarge;
88  std::vector<GLfloat> mBuffer;
89 
91  Vec3f mNearest;
92 };
93 
94 } } // namespace cinder::gl
Definition: Camera.h:191
void autoFocus(CameraStereo *cam, const Area &area=gl::getViewport())
Definition: StereoAutoFocuser.h:48
Definition: Area.h:37
static const int AF_WIDTH
width and height of the auto focus sample
Definition: StereoAutoFocuser.h:78
void draw()
Draws a visualizer, showing the sample area and the location of the nearest pixel.
Definition: StereoAutoFocuser.cpp:79
Area getViewport()
Returns the current OpenGL Viewport as an Area.
Definition: gl.cpp:377
GLuint getId() const
Returns the ID of the framebuffer itself. For antialiased FBOs this is the ID of the output multisamp...
Definition: Fbo.h:133
void autoFocus(CameraStereo *cam, const gl::Fbo &buffer)
Definition: StereoAutoFocuser.h:54
unsigned int GLuint
Definition: gldx.h:55
static T max(T x, T y)
Definition: CinderMath.h:76
Definition: StereoAutoFocuser.h:38
Area getBounds() const
Returns the bounding area of the FBO in pixels.
Definition: Fbo.h:108
GLuint buffer
Definition: GLee.h:2065
static T clamp(T x, T min=0, T max=1)
Definition: CinderMath.h:77
float getDepth() const
Returns the auto-focus depth, which influences the parallax effect.
Definition: StereoAutoFocuser.h:62
StereoAutoFocuser()
Definition: StereoAutoFocuser.h:40
#define GL_NONE
Definition: gldx.h:217
void setDepth(float factor)
Definition: StereoAutoFocuser.h:67
void setSpeed(float factor)
Definition: StereoAutoFocuser.h:60
static const int AF_HEIGHT
Definition: StereoAutoFocuser.h:79
Represents an OpenGL Framebuffer Object. //! Represents an instance of a font at a point size...
Definition: Fbo.h:90
GLclampf f
Definition: GLee.h:15307
float getSpeed() const
Returns the speed at which auto-focussing takes place.
Definition: StereoAutoFocuser.h:56