Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r916 - trunk/fox/afr_demo/Model/Cameras


Chronological Thread 
  • From: abhinav@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r916 - trunk/fox/afr_demo/Model/Cameras
  • Date: Thu, 9 Feb 2006 14:28:19 -0700 (MST)

Author: abhinav
Date: Thu Feb  9 14:28:19 2006
New Revision: 916

Added:
   trunk/fox/afr_demo/Model/Cameras/AFRCamera.cc
   trunk/fox/afr_demo/Model/Cameras/AFRCamera.h
   trunk/fox/afr_demo/Model/Cameras/AFRPinholeCamera.cc
   trunk/fox/afr_demo/Model/Cameras/AFRPinholeCamera.h
Removed:
   trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.cc
   trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.h
Log:

oops forgot to add the camera files for afr



Added: trunk/fox/afr_demo/Model/Cameras/AFRCamera.cc
==============================================================================
--- (empty file)
+++ trunk/fox/afr_demo/Model/Cameras/AFRCamera.cc       Thu Feb  9 14:28:19 
2006
@@ -0,0 +1,22 @@
+
+#include <Model/Cameras/AFRCamera.h>
+
+using namespace Manta;
+using namespace Manta::Afr;
+
+AFRPipeline* AFRCamera::afrRoot=NULL;
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Make an update to the cam with a timestamp.
+    void AFRCamera::update() {
+       Real tst = afrRoot->getCurrentTime();
+       if(fabs(tst-time_stamp[current])>0.010)
+       {
+          int ncurr = (current+1)%Size;
+          cam[ncurr]->reset(cam[current]->getPosition(), 
cam[current]->getUp(), cam[current]->getLookAt());
+          // also we need to copy the projection matrices
+          cam[ncurr]->copyProjectionMatrices(cam[current]);
+          current = ncurr;
+       }
+       time_stamp[current] = tst;
+    }
\ No newline at end of file

Added: trunk/fox/afr_demo/Model/Cameras/AFRCamera.h
==============================================================================
--- (empty file)
+++ trunk/fox/afr_demo/Model/Cameras/AFRCamera.h        Thu Feb  9 14:28:19 
2006
@@ -0,0 +1,154 @@
+
+#ifndef Manta_Model_AFRCamera_h
+#define Manta_Model_AFRCamera_h
+
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+// Abe Stephens, December 2005
+
+#include <SCIRun/Core/Thread/Time.h>
+#include <SCIRun/Core/Exceptions/InternalError.h>
+
+#include <Model/Cameras/AFRPinholeCamera.h>
+#include <Interface/Camera.h>
+
+#include <Core/Geometry/PointVector.h>
+#include <Core/Geometry/AffineTransform.h>
+
+#include <Engine/Control/AFRPipeline.h>
+#include <iostream>
+#include <string>
+#include <vector>
+using namespace std;
+#define Size 2
+namespace Manta {
+   namespace Afr {
+  using std::string;
+  using std::vector;
+  using SCIRun::InternalError;
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  
/////////////////////////////////////////////////////////////////////////////
+  // This class contains a cam of cameras.
+  class AFRCamera : public Camera {
+     private:
+    // Camera cam.
+        AFRPinholeCamera *cam[Size];
+        Real       time_stamp[Size];
+
+    // Current index.
+        int current;
+   
+  public:
+     static AFRPipeline *afrRoot;
+    
///////////////////////////////////////////////////////////////////////////
+    // Constructors.
+    AFRCamera( const Point &eye_, const Point &lookat_, const Vector &up_, 
Real fov_ ) :
+          current( 0 ) { for(int i=0; i<Size; i++) cam[i] = new 
AFRPinholeCamera( eye_, lookat_, up_, fov_ ); };
+    AFRCamera(const vector<string>& args) :
+          current( 0 ) { for(int i=0; i<Size; i++) cam[i] = new 
AFRPinholeCamera( args ); };
+    AFRCamera( Camera *camera ) : current( 0 ) {
+       for(int i=0; i<Size; i++) cam[i]->reset( camera->getPosition(),
+                          camera->getUp(),
+                          camera->getLookAt() );
+    }
+    
+    
///////////////////////////////////////////////////////////////////////////
+    // Make an update to the cam with a timestamp.
+    void update();
+    
+    virtual ~AFRCamera() { };
+
+    static Camera* create(const vector<string>& args) { return 
AFRPinholeCamera::create( args ); }
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Render stack method.
+    virtual void makeRays( RayPacket &rays ) const { getCurrent()->makeRays( 
rays ); }
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Camera manipulation
+    virtual void scaleFOV ( Real fov_ ) { update(); getCurrent()->scaleFOV( 
fov_ ); }
+    virtual void translate( Vector v )  { update(); getCurrent()->translate( 
v ); }
+    virtual void dolly    ( Real d )    { update(); getCurrent()->dolly( d 
); }
+    virtual void transform( AffineTransform t, TransformCenter center )
+    { update(); getCurrent()->transform( t, center ); }
+    virtual void autoview ( const BBox bbox )
+    { update(); getCurrent()->autoview( bbox ); }
+    virtual void output   ( std::ostream &os )
+    { getCurrent()->output( os ); }
+    virtual Point project (const Point &point, int steps=0) const
+    { if (steps >= Size)
+       throw InternalError( "getHistory steps >= History size.", __FILE__, 
__LINE__ );
+
+       int prev = current-steps;
+       prev = (prev < 0) ? (prev+Size) : prev;
+       return cam[prev]->project( point ); 
+    }
+    virtual void reset( const Point &eye_, const Vector &up_, const Point 
&lookat_ )
+    { update(); getCurrent()->reset( eye_, up_, lookat_ ); }
+    virtual void writeToFile(FILE *fp) const {getCurrent()->writeToFile(fp); 
};
+    
///////////////////////////////////////////////////////////////////////////
+    // Accessors
+    virtual Point getPosition() const   { return 
getCurrent()->getPosition(); }
+    virtual Point getLookAt()   const   { return getCurrent()->getLookAt(); 
};
+    virtual Vector getUp()      const   { return getCurrent()->getUp(); };
+
+    
///////////////////////////////////////////////////////////////////////////
+    // History Accessors
+    Real getOldCamTime( int steps) const{
+
+      if (steps >= Size)
+        throw InternalError( "getHistory steps >= History size.", __FILE__, 
__LINE__ );
+
+      int prev = current-steps;
+      prev = (prev < 0) ? (prev+Size) : prev;
+
+      return time_stamp[prev];
+    }
+    
+    const AFRPinholeCamera* getHistory( int steps, double &time ) const {
+
+      if (steps >= Size)
+        throw InternalError( "getHistory steps >= History size.", __FILE__, 
__LINE__ );
+
+      int prev = current-steps;
+      prev = (prev < 0) ? (prev+Size) : prev;
+
+      time = time_stamp[prev];
+      
+      return cam[prev];
+    }
+
+    // Get the current camera.
+    AFRPinholeCamera*       getCurrent() { return cam[current]; };
+    const AFRPinholeCamera* getCurrent() const { return cam[current]; };
+  };
+}
+}
+#endif

Added: trunk/fox/afr_demo/Model/Cameras/AFRPinholeCamera.cc
==============================================================================
--- (empty file)
+++ trunk/fox/afr_demo/Model/Cameras/AFRPinholeCamera.cc        Thu Feb  9 
14:28:19 2006
@@ -0,0 +1,121 @@
+
+#include <MantaTypes.h>
+#include <fox/afr_demo/Model/Cameras/AFRPinholeCamera.h>
+#include <Core/Util/Args.h>
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Interface/RayPacket.h>
+#include <Core/Geometry/BBox.h>
+#include <Core/Geometry/AffineTransform.h>
+#include <Core/Math/MiscMath.h>
+#include <Core/Math/Trig.h>
+#include <Core/Util/Assert.h>
+#include <iostream>
+
+using namespace Manta;
+using namespace std;
+using SCIRun::Clamp;
+
+AFRPinholeCamera::AFRPinholeCamera(const vector<string>& 
args):PinholeCamera(args)
+{
+}
+
+AFRPinholeCamera::AFRPinholeCamera( const Point &eye_, const Point &lookat_, 
const Vector &up_, Real fov_ ):PinholeCamera(eye_, lookat_, up_, fov_)
+{
+}
+
+AFRPinholeCamera::~AFRPinholeCamera()
+{
+}
+
+void AFRPinholeCamera::setup()
+{
+  int i, j, k;
+  vfov = hfov; // set field of view
+  direction=lookat-eye; // the normal vector
+  nearZ=direction.length(); // lenghth to near plane
+
+  Vector n = direction;
+  n.normalize();
+   
+  up.normalize();
+
+  v=Cross(direction, up);
+  if(v.length2() == 0.0){
+    std::cerr << __FILE__ << " line: " << __LINE__ << " Ambiguous up 
direciton...\n";
+  }
+  v.normalize();
+
+  u=Cross(v, direction);
+  u.normalize();
+
+  for(i=0; i<4; i++)
+    for(j=0; j<4; j++)
+      proj[i][j] = mv[i][j] = 0.0;
+  
+  // form modelview matrix
+  mv[0][0] = v.x(); mv[0][1] = v.y(); mv[0][2] = v.z(); 
+  mv[0][3] = (-eye.x()*v.x()) + (-eye.y()*v.y()) + (-eye.z()*v.z());
+  mv[1][0] = u.x(); mv[1][1] = u.y(); mv[1][2] = u.z();
+  mv[1][3] = (-eye.x()*u.x()) + (-eye.y()*u.y()) + (-eye.z()*u.z());
+  mv[2][0] = -1.0*n.x(); mv[2][1] = -1.0*n.y(); mv[2][2] = -1.0*n.z();
+  mv[2][3] = (eye.x()*n.x()) + (eye.y()*n.y()) + (eye.z()*n.z());
+  mv[3][3]= 1.0;
+
+  height=nearZ*tan(vfov*0.5*M_PI/180.0);
+  u*=height;
+  width=nearZ*tan(hfov*0.5*M_PI/180.0);
+  v*=width;  
+  // form projection matrix
+  Real f = 1.0/tan((vfov*M_PI/180.0)/2.0);
+  Real aspect = width/height;
+  Real farZ = nearZ*1000.0;
+  
+    
+  proj[0][0] = f/aspect;
+  proj[1][1] = f;
+  proj[2][2] = (farZ+nearZ)/(nearZ-farZ);
+  proj[2][3] = (2.0*farZ*nearZ)/(nearZ-farZ);
+  proj[3][2] = -1.0;
+    
+  // product of two
+  for(i=0; i<4; i++)
+  {
+    for(j=0; j<4; j++)
+    {
+      prodMat[i][j] = 0.0;
+      for(k=0; k<4; k++)
+      {
+        prodMat[i][j] += proj[i][k]*mv[k][j];
+      }
+    }
+  }
+}
+
+Point AFRPinholeCamera::project(const Point &point) const
+{
+
+  Point p2(prodMat[0][0]*point.x() + prodMat[0][1]*point.y() + 
prodMat[0][2]*point.z() + prodMat[0][3],
+           prodMat[1][0]*point.x() + prodMat[1][1]*point.y() + 
prodMat[1][2]*point.z() + prodMat[1][3],
+           prodMat[2][0]*point.x() + prodMat[2][1]*point.y() + 
prodMat[2][2]*point.z() + prodMat[2][3]);
+  Real zval = prodMat[3][0]*point.x() + prodMat[3][1]*point.y() + 
prodMat[3][2]*point.z() + prodMat[3][3];
+
+
+  return Point(((p2.x()/zval)+1.0)/2.0,
+               ((p2.y()/zval)+1.0)/2.0, 
+               ((p2.z()/zval)+1.0)/2.0);
+}
+
+void AFRPinholeCamera::writeToFile(FILE *fp) const
+{
+  float wR, wT;
+
+  wR = nearZ*tan(hfov*0.5*M_PI/180.0);
+  wT = nearZ*tan(vfov*0.5*M_PI/180.0);
+  fprintf(fp,"origin %f %f %f\nU %f %f %f\nV %f %f %f\nN %f %f %f\nextents 
%f %f %f %f\nnear %f\nfar %f\n",
+          eye.x(), eye.y(), eye.z(),
+          mv[0][0], mv[0][1], mv[0][2],
+          mv[1][0], mv[1][1], mv[1][2],
+          -mv[2][0], -mv[2][1], -mv[2][2],
+          -wR, wR, -wT, wT,
+          nearZ, nearZ*1000.0);
+}

Added: trunk/fox/afr_demo/Model/Cameras/AFRPinholeCamera.h
==============================================================================
--- (empty file)
+++ trunk/fox/afr_demo/Model/Cameras/AFRPinholeCamera.h Thu Feb  9 14:28:19 
2006
@@ -0,0 +1,40 @@
+
+#ifndef Manta_Model_AFRPinholeCamera_h
+#define Manta_Model_AFRPinholeCamera_h
+
+#include <Model/Cameras/PinholeCamera.h>
+#include <Core/Geometry/PointVector.h>
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <vector>
+#include <sgi_stl_warnings_on.h>
+
+namespace Manta {
+  using namespace std;
+
+  class AFRPinholeCamera : public PinholeCamera {
+  public:
+    AFRPinholeCamera(const vector<string>& args);
+    AFRPinholeCamera( const Point &eye_, const Point &lookat_, const Vector 
&up_, Real fov_ );
+    static Camera* create(const vector<string>& args);
+    virtual ~AFRPinholeCamera();
+    virtual Point project(const Point &point) const;  // project a 3D point 
to the camera image plane
+    virtual void writeToFile(FILE *fp) const;
+    virtual void setup();
+    void copyProjectionMatrices(AFRPinholeCamera *cam)
+    {
+       int i,j;
+       for(i=0; i<4; i++)
+          for(j=0; j<4; j++)
+       {
+          proj[i][j]    = cam->proj[i][j];
+          mv[i][j]      = cam->mv[i][j];
+          prodMat[i][j] = cam->prodMat[i][j];
+       }
+    }
+  private:
+    Real proj[4][4], mv[4][4], prodMat[4][4];
+  };
+}
+
+#endif




  • [MANTA] r916 - trunk/fox/afr_demo/Model/Cameras, abhinav, 02/09/2006

Archive powered by MHonArc 2.6.16.

Top of page