Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r896 - in trunk: Model/Cameras fox/afr_demo/Model/Cameras


Chronological Thread 
  • From: abhinav@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r896 - in trunk: Model/Cameras fox/afr_demo/Model/Cameras
  • Date: Tue, 7 Feb 2006 16:28:45 -0700 (MST)

Author: abhinav
Date: Tue Feb  7 16:28:44 2006
New Revision: 896

Modified:
   trunk/Model/Cameras/PinholeCamera.h
   trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.cc
   trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.h
Log:
Modified pinhomecamera to have protected ratherthan private member veriables 
so that classes that inherit from it can use its member variables.

inherited AFRPinholeCamera from PinholeCamera to be use in AFR code. It adds 
functionality to write camera to file and project a 3D point into camera space



Modified: trunk/Model/Cameras/PinholeCamera.h
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.h (original)
+++ trunk/Model/Cameras/PinholeCamera.h Tue Feb  7 16:28:44 2006
@@ -41,9 +41,8 @@
     void setStereoOffset( Real stereo_offset_ ) { stereo_offset = 
stereo_offset_; }
     Real getStereoOffset() const { return stereo_offset; }
 
-  private:
-    void setup();
-    
+    virtual void setup();
+  protected:
     Point  eye;
     Point  lookat;
     Vector up;
@@ -55,7 +54,6 @@
 
     Vector direction;
     Vector u,v;
-    double proj[4][4], mv[4][4], prodMat[4][4];
   };
 }
 

Modified: trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.cc
==============================================================================
--- trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.cc        (original)
+++ trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.cc        Tue Feb  7 
16:28:44 2006
@@ -1,6 +1,6 @@
 
 #include <MantaTypes.h>
-#include <Model/Cameras/PinholeCamera.h>
+#include <fox/afr_demo/Model/Cameras/AfrPinholeCamera.h>
 #include <Core/Util/Args.h>
 #include <Core/Exceptions/IllegalArgument.h>
 #include <Interface/RayPacket.h>
@@ -15,62 +15,19 @@
 using namespace std;
 using SCIRun::Clamp;
 
-PinholeCamera::PinholeCamera(const vector<string>& args)
+AFRPinholeCamera::AFRPinholeCamera(const vector<string>& 
args):PinholeCamera(args)
 {
-  bool gotEye = false;
-  bool gotLookat = false;
-  bool gotFov = false;
-  bool gotUp = false;
-  normalizeRays = false;
-  int argc = static_cast<int>(args.size());
-  for(int i=0; i< argc; i++){
-    string arg = args[i];
-    if(arg == "-eye"){
-      if(!getPointArg(i, args, eye))
-        throw IllegalArgument("PinholeCamera -eye", i, args);
-      gotEye = true;
-    } else if(arg == "-lookat"){
-      if(!getPointArg(i, args, lookat))
-        throw IllegalArgument("PinholeCamera -lookat", i, args);
-      gotLookat = true;
-    } else if(arg == "-up"){
-      if(!getVectorArg(i, args, up))
-        throw IllegalArgument("PinholeCamera -up", i, args);
-      gotUp = true;
-    } else if(arg == "-fov"){
-      if(!getDoubleArg(i, args, hfov))
-        throw IllegalArgument("PinholeCamera -fov", i, args);
-      gotFov = true;
-    } else if(arg == "-normalizeRays"){
-      normalizeRays = true;
-    } else {
-      throw IllegalArgument("PinholeCamera", i, args);
-    }
-  }
-  if(!gotEye || !gotLookat || !gotUp || !gotFov)
-    throw IllegalArgument("PinholeCamera needs -eye -lookat -up and -fov", 
0, args);
-  setup();
 }
 
-PinholeCamera::~PinholeCamera()
+AFRPinholeCamera( const Point &eye_, const Point &lookat_, const Vector 
&up_, Real fov_ ):PinholeCamera(eye_, lookat_, up_, fov_)
 {
 }
 
-void PinholeCamera::output( std::ostream &os ) const {
-
-        os << "pinhole( -eye " << eye
-                  << " -lookat " << lookat
-                                                << " -up " << up
-                                                << " -fov " << hfov << " )"
-                                                << std::endl;
-}
-
-Camera* PinholeCamera::create(const vector<string>& args)
+AFRPinholeCamera::~AFRPinholeCamera():PinholeCamera()
 {
-  return new PinholeCamera(args);
 }
 
-void PinholeCamera::setup()
+void AFRPinholeCamera::setup()
 {
   int i, j, k;
   vfov = hfov; // set field of view
@@ -82,25 +39,19 @@
    
   up.normalize();
 
-  for(i=0; i<3; i++)
-    uvn[2][i] = n[i];
-
   v=Cross(direction, up);
   if(v.length2() == 0.0){
     std::cerr << __FILE__ << " line: " << __LINE__ << " Ambiguous up 
direciton...\n";
   }
   v.normalize();
 
-  for(i=0; i<3; i++)
-    uvn[1][i] = v[i];
-
   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());
@@ -115,9 +66,9 @@
   width=nearZ*tan(hfov*0.5*M_PI/180.0);
   v*=width;  
   // form projection matrix
-  double f = 1.0/tan((vfov*M_PI/180.0)/2.0);
-  double aspect = width/height;
-  double farZ = nearZ*1000.0;
+  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;
@@ -140,112 +91,13 @@
   }
 }
 
-void PinholeCamera::makeRays(RayPacket& rays) const
-{
-  ASSERT(rays.getFlags() & RayPacket::HaveImageCoordinates);
-  rays.setFlag(RayPacket::ConstantOrigin);
-  if(normalizeRays){
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      Vector raydir(v*e.imageX+u*e.imageY+direction);
-      raydir.normalize();
-      e.ray.set(eye, raydir);
-      e.importance = 1.0;
-    }
-    rays.setFlag(RayPacket::NormalizedDirections);
-  } else {
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      Vector raydir(v*e.imageX+u*e.imageY+direction);
-      e.ray.set(eye, raydir);
-      e.importance = 1.0;
-    }
-  }
-}
-
-void PinholeCamera::scaleFOV(double scale)
-{
-  double fov_min = 0;
-  double fov_max = 180;
-  hfov = RtoD(2*atan(scale*tan(DtoR(hfov/2.))));
-  hfov = Clamp(hfov, fov_min, fov_max);
-  vfov = RtoD(2*atan(scale*tan(DtoR(vfov/2.))));
-  vfov = Clamp(vfov, fov_min, fov_max);
-  setup();
-}
-
-void PinholeCamera::translate(Vector t)
-{
-  Vector trans(u*t.y()+v*t.x());
-
-  eye += trans;
-  lookat += trans;
-  setup();
-}
-
-void PinholeCamera::dolly(double scale)
-{
-  Vector d = (lookat - eye) * scale;
-  eye    += d;
-        // lookat += d; // Maybe we need two types of dolly. // Maybe not.
-  setup();
-}
-
-void PinholeCamera::transform(AffineTransform t, TransformCenter center)
-{
-  Point cen;
-  switch(center){
-  case Eye:
-    cen = eye;
-    break;
-  case LookAt:
-    cen = lookat;
-    break;
-  case Origin:
-    cen = Point(0,0,0);
-    break;
-  }
-
-  Vector lookdir(eye-lookat);
-  double length = lookdir.length();
-
-  AffineTransform frame;
-  frame.initWithBasis(v.normal(), u.normal(), lookdir.normal(), cen);
-
-  AffineTransform frame_inv = frame;
-  frame_inv.invert();
-
-  AffineTransform t2        = frame * t * frame_inv;
-  up     = t2 * up;
-  eye    = t2 * eye;
-  lookat = t2 * lookat;
-  setup();
-}
-
-void PinholeCamera::autoview(double new_fov)
-{
-  BBox bbox(Point(-1,-1,0.2), Point(1,1,2.2));
-  //  double ratio = tan(DtoR(vfov/2))/tan(DtoR(hfov/2));
-  hfov = new_fov;
-  vfov = RtoD(2*atan(tan(DtoR(hfov/2))));
-  Vector diag(bbox.diagonal());
-  double w=diag.length();
-  Vector lookdir(eye-lookat);
-  lookdir.normalize();
-  double scale = 1.0/(2*tan(DtoR(hfov/2.0)));
-  double length = w*scale;
-  lookat = bbox.center();
-  eye = lookat+lookdir*length;
-  setup();
-}
-
-Point PinholeCamera::project(const Point &point) const
+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]);
-  double zval = prodMat[3][0]*point.x() + prodMat[3][1]*point.y() + 
prodMat[3][2]*point.z() + prodMat[3][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,
@@ -253,7 +105,7 @@
                ((p2.z()/zval)+1.0)/2.0);
 }
 
-void PinholeCamera::writeToFile(FILE *fp) const
+void AFRPinholeCamera::writeToFile(FILE *fp) const
 {
   float wR, wT;
 

Modified: trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.h
==============================================================================
--- trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.h (original)
+++ trunk/fox/afr_demo/Model/Cameras/AfrPinholeCamera.h Tue Feb  7 16:28:44 
2006
@@ -1,8 +1,8 @@
 
-#ifndef Manta_Model_PinholeCamera_h
-#define Manta_Model_PinholeCamera_h
+#ifndef Manta_Model_AFRPinholeCamera_h
+#define Manta_Model_AFRPinholeCamera_h
 
-#include <Interface/Camera.h>
+#include <Model/Cameras/PinholeCamera.h>
 #include <Core/Geometry/PointVector.h>
 #include <sgi_stl_warnings_off.h>
 #include <string>
@@ -12,82 +12,18 @@
 namespace Manta {
   using namespace std;
 
-  class PinholeCamera : public Camera {
+  class AFRPinholeCamera : public PinholeCamera {
   public:
-    PinholeCamera() : eye(3,3,2), lookat(0,0,0.3), up(0,0,1), hfov(60) { 
setup(); };
-    PinholeCamera( const Point &eye_, const Point &lookat_, const Vector 
&up_, Real fov_ ) :
-                   eye( eye_ ), lookat( lookat_ ), up( up_ ), hfov( fov_ ) { 
setup(); }
-    PinholeCamera(const vector<string>& args);
-    virtual ~PinholeCamera();
-    virtual void makeRays(RayPacket&) const;
-
-    // Camera manipulation
-    virtual void scaleFOV(double);
-    virtual void translate(Vector);
-    virtual void dolly(double);
-    virtual void transform(AffineTransform t, TransformCenter);
-    virtual void autoview(double fov);
-
+    AFRPinholeCamera();
+    AFRPinholeCamera( const Point &eye_, const Point &lookat_, const Vector 
&up_, Real fov_ );
+    AFRPinholeCamera(const vector<string>& args);
+    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 output( std::ostream &os ) const;
-    static Camera* create(const vector<string>& args);
-    virtual Point getPosition() const { return eye; }
-    virtual Point getLookAt()   const { return lookat; };
-    virtual Vector getUp()       const { return up; };
-    virtual void reset( const Point &eye_, const Vector &up_, const Point 
&lookat_ ) {
-    eye = eye_; up = up_; lookat = lookat_; setup(); };
-    Camera* clone()
-    {
-      PinholeCamera *ncam = new PinholeCamera;
-      *ncam = *this;
-      return ncam;
-    }
-    inline void operator=(PinholeCamera phc)
-    {
-      printf("in phc operatopr = \n");
-      eye = phc.eye;
-      lookat = phc.lookat;
-      up = phc.up;
-      hfov = phc.hfov;
-      vfov = phc.vfov;
-      width = phc.width;
-      height = phc.height;
-      nearZ = phc.nearZ;
-      normalizeRays = phc.normalizeRays;
-      direction = phc.direction;
-      u = phc.u;
-      v = phc.v;
-      int i,j;
-      for(i=0; i<4; i++)
-        for(j=0; j<4; j++)
-      {
-        proj[i][j] = phc.proj[i][j];
-        mv[i][j] = phc.mv[i][j];
-        prodMat[i][j] = phc.prodMat[i][j];
-      }
-      for(i=0; i<3; i++)
-        for(j=0; j<3; j++)
-      {
-        uvn[i][j] = phc.uvn[i][j];
-      }
-    }
-  protected:
-    void setup();
-    Point  eye;
-    Point  lookat;
-    Vector up;
-    double hfov, vfov, width, height, nearZ; // x and y field of view, 
-                                            // width and height of image 
plane
-                                            // distance from eye to image 
plane
-    bool   normalizeRays;
-
-    Vector direction;
-    Vector u,v;
-    double proj[4][4], mv[4][4], prodMat[4][4];
-
-    // for projection we maintain a uvn rotation matrix
-    double uvn[3][3];
+    virtual void setup();
+  private:
+    Real proj[4][4], mv[4][4], prodMat[4][4];
   };
 }
 




  • [MANTA] r896 - in trunk: Model/Cameras fox/afr_demo/Model/Cameras, abhinav, 02/07/2006

Archive powered by MHonArc 2.6.16.

Top of page