Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r328 - in trunk: Engine/Control Model/Cameras


Chronological Thread 
  • From: cgribble@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r328 - in trunk: Engine/Control Model/Cameras
  • Date: Mon, 16 May 2005 17:05:04 -0600 (MDT)

Author: cgribble
Date: Mon May 16 17:05:03 2005
New Revision: 328

Added:
   trunk/Model/Cameras/EnvironmentCamera.cc
   trunk/Model/Cameras/EnvironmentCamera.h
Modified:
   trunk/Engine/Control/RTRT_register.cc
   trunk/Model/Cameras/CMakeLists.txt
Log:
Added an environment camera for generating environment maps.

Modified: trunk/Engine/Control/RTRT_register.cc
==============================================================================
--- trunk/Engine/Control/RTRT_register.cc       (original)
+++ trunk/Engine/Control/RTRT_register.cc       Mon May 16 17:05:03 2005
@@ -26,6 +26,7 @@
 #include <Image/Pixel.h>
 #include <Image/NullImage.h>
 #include <Image/SimpleImage.h>
+#include <Model/Cameras/EnvironmentCamera.h>
 #include <Model/Cameras/PinholeCamera.h>
 #include <Model/Cameras/OrthogonalCamera.h>
 #include <Model/Groups/BVH.h>
@@ -79,6 +80,7 @@
     rtrt->registerComponent("raytracer", &Raytracer::create);
 
     // Register cameras
+    rtrt->registerComponent("environment", &EnvironmentCamera::create);
     rtrt->registerComponent("pinhole", &PinholeCamera::create);
     rtrt->registerComponent("orthogonal", &OrthogonalCamera::create);
 

Modified: trunk/Model/Cameras/CMakeLists.txt
==============================================================================
--- trunk/Model/Cameras/CMakeLists.txt  (original)
+++ trunk/Model/Cameras/CMakeLists.txt  Mon May 16 17:05:03 2005
@@ -1,4 +1,5 @@
 
 SET (Manta_Cameras_SRCS
+     Cameras/EnvironmentCamera.cc
      Cameras/PinholeCamera.cc
      Cameras/OrthogonalCamera.cc)

Added: trunk/Model/Cameras/EnvironmentCamera.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Cameras/EnvironmentCamera.cc    Mon May 16 17:05:03 2005
@@ -0,0 +1,173 @@
+
+#include <MantaTypes.h>
+#include <Model/Cameras/EnvironmentCamera.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 <Core/Util/NotFinished.h>
+#include <iostream>
+
+using namespace Manta;
+using namespace std;
+using SCIRun::Clamp;
+
+EnvironmentCamera::EnvironmentCamera(const vector<string>& args)
+{
+  bool gotEye=false;
+  bool gotLookat=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("EnvironmentCamera -eye", i, args);
+      gotEye=true;
+    } else if (arg=="-lookat") {
+      if (!getPointArg(i, args, lookat))
+       throw IllegalArgument("EnvironmentCamera -lookat", i, args);
+      gotLookat=true;
+    } else if (arg=="-up") {
+      if (!getVectorArg(i, args, up))
+       throw IllegalArgument("EnvironmentCamera -up", i, args);
+      gotUp=true;
+    } else if (arg=="-normalizeRays") {
+      normalizeRays=true;
+    } else {
+      throw IllegalArgument("EnvironmentCamera", i, args);
+    }
+  }
+  if (!gotEye || !gotLookat || !gotUp)
+    throw IllegalArgument("EnvironmentCamera needs -eye -lookat and -up", 0, 
args);
+  setup();
+}
+
+EnvironmentCamera::~EnvironmentCamera()
+{
+}
+
+Camera* EnvironmentCamera::create(const vector<string>& args)
+{
+  return new EnvironmentCamera(args);
+}
+
+void EnvironmentCamera::setup()
+{
+  int i;
+  direction=lookat - eye;
+  n=direction;
+  n.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();
+
+  v=-v;
+}
+
+void EnvironmentCamera::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);
+      double theta=0.5*(M_PI - M_PI*e.imageY);
+      double phi=M_PI*e.imageX + M_PI;
+      Vector xyz(sin(theta)*cos(phi), sin(theta)*sin(phi),
+                 cos(theta));
+      Vector raydir(Dot(xyz, v),
+                    Dot(xyz, n),
+                    Dot(xyz, u));
+      raydir.normalize();
+      e.ray.set(eye, raydir);
+    }
+    rays.setFlag(RayPacket::NormalizedDirections);
+  } else {
+    for (int i=0; i<rays.getSize(); i++) {
+      RayPacket::Element& e=rays.get(i);
+      double theta=0.5*(M_PI - M_PI*e.imageY);
+      double phi=M_PI*e.imageX + M_PI;
+      Vector xyz(sin(theta)*cos(phi), sin(theta)*sin(phi),
+                 cos(theta));
+      Vector raydir(Dot(xyz, v),
+                    Dot(xyz, n),
+                    Dot(xyz, u));
+      e.ray.set(eye, raydir);
+    }
+  }
+}
+
+void EnvironmentCamera::scaleFOV(double scale)
+{
+  // This functionality doesn't make much sense with the environment camera
+}
+
+void EnvironmentCamera::translate(Vector t)
+{
+  Vector trans(u*t.y() + v*t.x());
+
+  eye += trans;
+  lookat += trans;
+  setup();
+}
+
+void EnvironmentCamera::dolly(double scale)
+{
+  Vector dir=lookat - eye;
+  eye += dir*scale;
+  setup();
+}
+
+void EnvironmentCamera::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 EnvironmentCamera::autoview(double new_fov)
+{
+  // This functionality doesn't make much sense with the environment camera
+}
+
+Point EnvironmentCamera::project(const Point &point)
+{
+  // NOT FINISHED
+  return Point(0., 0., 0.);
+}

Added: trunk/Model/Cameras/EnvironmentCamera.h
==============================================================================
--- (empty file)
+++ trunk/Model/Cameras/EnvironmentCamera.h     Mon May 16 17:05:03 2005
@@ -0,0 +1,41 @@

+#ifndef Manta_Model_EnvironmentCamera_h
+#define Manta_Model_EnvironmentCamera_h
+
+#include <Interface/Camera.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 EnvironmentCamera : public Camera {
+  public:
+    EnvironmentCamera(const vector<string>& args);
+    virtual ~EnvironmentCamera();
+    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);
+    virtual Point project(const Point &point);  // project a 3D point to the 
camera image plane
+    static Camera* create(const vector<string>& args);
+  private:
+    void setup();
+    Point  eye;
+    Point  lookat;
+    Vector up;
+    bool   normalizeRays;
+
+    Vector direction;
+    Vector u, v, n;
+  };
+}
+
+#endif




  • [MANTA] r328 - in trunk: Engine/Control Model/Cameras, cgribble, 05/16/2005

Archive powered by MHonArc 2.6.16.

Top of page