include/cinder/gl/StereoAutoFocuser.h
Go to the documentation of this file.
00001 /*
00002  Copyright (c) 2012, The Cinder Project, All rights reserved.
00003  This code is intended for use with the Cinder C++ library: http://libcinder.org
00004  
00005  Portions of this code (C) Paul Houx
00006  All rights reserved.
00007 
00008  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
00009  the following conditions are met:
00010 
00011     * Redistributions of source code must retain the above copyright notice, this list of conditions and
00012     the following disclaimer.
00013     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
00014     the following disclaimer in the documentation and/or other materials provided with the distribution.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00017  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00018  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00019  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00020  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00021  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00022  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00023  POSSIBILITY OF SUCH DAMAGE.
00024 */
00025 
00026 #pragma once
00027 
00028 #include "cinder/gl/gl.h"
00029 #include "cinder/gl/Fbo.h"
00030 
00031 // forward declarations
00032 namespace cinder {
00033     class Camera; class CameraPersp; class CameraStereo;
00034 } // namespace cinder
00035 
00036 namespace cinder { namespace gl {
00037 
00038 class StereoAutoFocuser {
00039   public:
00040     StereoAutoFocuser()
00041         : mSpeed(1.0f), mDepth(1.0f) {}
00042 
00048     void                    autoFocus( CameraStereo *cam, const Area &area = gl::getViewport() ) { autoFocus( cam, area, GL_NONE ); }
00054     void                    autoFocus( CameraStereo *cam, const gl::Fbo &buffer ) { autoFocus( cam, buffer.getBounds(), buffer.getId() ); }
00056     float                   getSpeed() const { return mSpeed; }
00060     void                    setSpeed( float factor ) { mSpeed = math<float>::clamp( factor, 0.01f, 1.0f); }
00062     float                   getDepth() const { return mDepth; }
00067     void                    setDepth( float factor ) { mDepth = math<float>::max( factor, 0.01f); }
00068 
00070     void                    draw();
00071   private:
00072     void                    createBuffers( const Area &area );
00073 
00075     void                    autoFocus( CameraStereo *cam, const Area &area, GLuint buffer );
00076   public:
00078     static const int        AF_WIDTH = 64;
00079     static const int        AF_HEIGHT = 64;
00080   private:
00081     float                   mSpeed;
00082     float                   mDepth;
00083 
00084     Area                    mArea;
00085 
00086     Fbo                     mFboSmall;
00087     Fbo                     mFboLarge;
00088     std::vector<GLfloat>    mBuffer; 
00089 
00091     Vec3f                   mNearest;
00092 };
00093 
00094 } } // namespace cinder::gl