Text archives Help
- From: aek@sci.utah.edu
- To: rtrt@sci.utah.edu
- Subject: [MANTA] r302 - in trunk: Engine/Control Model/Cameras StandAlone
- Date: Thu, 12 May 2005 19:16:07 -0600 (MDT)
Author: aek
Date: Thu May 12 19:16:06 2005
New Revision: 302
Added:
trunk/Model/Cameras/OrthogonalCamera.cc
trunk/Model/Cameras/OrthogonalCamera.h
Modified:
trunk/Engine/Control/RTRT_register.cc
trunk/Model/Cameras/CMakeLists.txt
trunk/Model/Cameras/PinholeCamera.cc
trunk/StandAlone/manta.cc
Log:
Added orthogonal camera model. Use something like:
-camera "orthogonal(-eye 3 3 2 -lookat 0 0 1 -up 0 0 1 -scale 2)"
...to turn it on.
Modified: trunk/Engine/Control/RTRT_register.cc
==============================================================================
--- trunk/Engine/Control/RTRT_register.cc (original)
+++ trunk/Engine/Control/RTRT_register.cc Thu May 12 19:16:06 2005
@@ -26,6 +26,7 @@
#include <Image/NullImage.h>
#include <Image/SimpleImage.h>
#include <Model/Cameras/PinholeCamera.h>
+#include <Model/Cameras/OrthogonalCamera.h>
#include <Model/Groups/BVH.h>
#include <Model/Groups/Group.h>
#include <UserInterface/PromptUI.h>
@@ -78,6 +79,7 @@
// Register cameras
rtrt->registerComponent("pinhole", &PinholeCamera::create);
+ rtrt->registerComponent("orthogonal", &OrthogonalCamera::create);
// Register shadow algorithms
rtrt->registerComponent("noshadows", &NoShadows::create);
Modified: trunk/Model/Cameras/CMakeLists.txt
==============================================================================
--- trunk/Model/Cameras/CMakeLists.txt (original)
+++ trunk/Model/Cameras/CMakeLists.txt Thu May 12 19:16:06 2005
@@ -1,3 +1,4 @@
SET (Manta_Cameras_SRCS
- Cameras/PinholeCamera.cc)
+ Cameras/PinholeCamera.cc
+ Cameras/OrthogonalCamera.cc)
Added: trunk/Model/Cameras/OrthogonalCamera.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Cameras/OrthogonalCamera.cc Thu May 12 19:16:06 2005
@@ -0,0 +1,169 @@
+
+#include <Model/Cameras/OrthogonalCamera.h>
+#include <Core/Util/Args.h>
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Interface/RayPacket.h>
+#include <Core/Geometry/BBox.h>
+#include <Core/Geometry/Transform.h>
+#include <Core/Math/MiscMath.h>
+#include <Core/Math/Trig.h>
+#include <Core/Util/NotFinished.h>
+
+using namespace Manta;
+using namespace std;
+using namespace SCIRun;
+
+OrthogonalCamera::OrthogonalCamera(const vector<string>& args)
+{
+ bool gotEye = false;
+ bool gotLookat = false;
+ bool gotScale = 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("OrthogonalCamera -eye", i, args);
+ gotEye = true;
+ } else if(arg == "-lookat"){
+ if(!getPointArg(i, args, lookat))
+ throw IllegalArgument("OrthogonalCamera -lookat", i, args);
+ gotLookat = true;
+ } else if(arg == "-up"){
+ if(!getVectorArg(i, args, up))
+ throw IllegalArgument("OrthogonalCamera -up", i, args);
+ gotUp = true;
+ } else if(arg == "-scale"){
+ if(!getDoubleArg(i, args, hscale))
+ throw IllegalArgument("OrthogonalCamera -scale", i, args);
+ gotScale = true;
+ } else if(arg == "-normalizeRays"){
+ normalizeRays = true;
+ } else {
+ throw IllegalArgument("OrthogonalCamera", i, args);
+ }
+ }
+ if(!gotEye || !gotLookat || !gotUp || !gotScale)
+ throw IllegalArgument("OrthogonalCamera needs -eye -lookat -up and
-scale", 0, args);
+ setup();
+}
+
+OrthogonalCamera::~OrthogonalCamera()
+{
+}
+
+Camera* OrthogonalCamera::create(const vector<string>& args)
+{
+ return new OrthogonalCamera(args);
+}
+
+void OrthogonalCamera::setup()
+{
+ vscale = hscale;
+ direction=lookat-eye;
+ direction.normalize();
+ v=Cross(direction, up);
+ if(v.length2() == 0.0){
+ cerr << "Ambiguous up direction...\n";
+ }
+ v.normalize();
+
+ u=Cross(v, direction);
+ u.normalize();
+
+ u*=vscale;
+ v*=hscale;
+}
+
+void OrthogonalCamera::makeRays(RayPacket& rays) const
+{
+ ASSERT(rays.getFlags() & RayPacket::HaveImageCoordinates);
+
+ for(int i=0;i<rays.getSize();i++){
+ RayPacket::Element& e = rays.get(i);
+ Point rayposition(eye+v*e.imageX+u*e.imageY);
+ e.ray.set(rayposition, direction);
+ }
+ rays.setFlag(RayPacket::NormalizedDirections);
+}
+
+// FOV doesn't quite make sense here - orthogonal cameras don't have FOV's.
+// But in the context of the camera interface, adjusting the scale makes
+// the most sense, so we'll do that.
+void OrthogonalCamera::scaleFOV(double scale)
+{
+ hscale *= scale;
+ vscale *= scale;
+ setup();
+}
+
+void OrthogonalCamera::translate(Vector t)
+{
+ Vector trans(u*t.y()+v*t.x());
+
+ eye += trans;
+ lookat += trans;
+ setup();
+}
+
+void OrthogonalCamera::dolly(double scale)
+{
+ Vector dir = lookat - eye;
+ eye += dir*scale;
+ setup();
+}
+
+void OrthogonalCamera::transform(Transform t, TransformCenter center)
+{
+ Vector cen;
+ switch(center){
+ case Eye:
+ cen = eye.asVector();
+ break;
+ case LookAt:
+ cen = lookat.asVector();
+ break;
+ case Origin:
+ cen = Vector(0,0,0);
+ break;
+ }
+
+ Vector lookdir(eye-lookat);
+ double length = lookdir.length();
+ Transform frame;
+ frame.load_basis(Point(0,0,0), v.normal()*length, u.normal()*length,
lookdir);
+ frame.pre_translate(cen);
+ // double tmp = lookdir.length();
+
+ Transform frame_inv(frame);
+ frame_inv.invert();
+
+ Transform t2;
+ t2.load_identity();
+ t2.pre_trans(frame_inv);
+ t2.pre_trans(t);
+ t2.pre_trans(frame);
+
+ up = t2.project(up);
+ eye = t2.project(eye);
+ lookat = t2.project(lookat);
+ lookdir = eye-lookat;
+ setup();
+}
+
+void OrthogonalCamera::autoview(double new_fov)
+{
+ BBox bbox(Point(-1,-1,0.2), Point(1,1,2.2));
+ // double ratio = tan(DtoR(vscale/2))/tan(DtoR(hscale/2));
+ hscale = new_fov;
+ vscale = new_fov;
+ Vector diag(bbox.diagonal());
+ double w=diag.length();
+ Vector lookdir(eye-lookat);
+ lookdir.normalize();
+ lookat = bbox.center();
+ eye = lookat+lookdir*w;
+ setup();
+}
Added: trunk/Model/Cameras/OrthogonalCamera.h
==============================================================================
--- (empty file)
+++ trunk/Model/Cameras/OrthogonalCamera.h Thu May 12 19:16:06 2005
@@ -0,0 +1,43 @@
+
+#ifndef Manta_Model_OrthogonalCamera_h
+#define Manta_Model_OrthogonalCamera_h
+
+#include <Interface/Camera.h>
+#include <Core/Geometry/Point.h>
+#include <Core/Geometry/Vector.h>
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <vector>
+#include <sgi_stl_warnings_on.h>
+
+namespace Manta {
+ using namespace std;
+ using namespace SCIRun;
+ class OrthogonalCamera : public Camera {
+ public:
+ OrthogonalCamera(const vector<string>& args);
+ virtual ~OrthogonalCamera();
+ virtual void makeRays(RayPacket&) const;
+
+ // Camera manipulation
+ virtual void scaleFOV(double);
+ virtual void translate(Vector);
+ virtual void dolly(double);
+ virtual void transform(SCIRun::Transform t, TransformCenter);
+ virtual void autoview(double fov);
+
+ static Camera* create(const vector<string>& args);
+ private:
+ void setup();
+ Point eye;
+ Point lookat;
+ Vector up;
+ double hscale, vscale;
+ bool normalizeRays;
+
+ Vector direction;
+ Vector u,v;
+ };
+}
+
+#endif
Modified: trunk/Model/Cameras/PinholeCamera.cc
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.cc (original)
+++ trunk/Model/Cameras/PinholeCamera.cc Thu May 12 19:16:06 2005
@@ -66,7 +66,7 @@
double dist=direction.length();
v=Cross(direction, up);
if(v.length2() == 0.0){
- cerr << "Ambiguous up direciton...\n";
+ cerr << "Ambiguous up direction...\n";
}
v.normalize();
Modified: trunk/StandAlone/manta.cc
==============================================================================
--- trunk/StandAlone/manta.cc (original)
+++ trunk/StandAlone/manta.cc Thu May 12 19:16:06 2005
@@ -58,6 +58,8 @@
printList(cerr, rtrt->listImageTraversers(), 4);
cerr << " -pixelsampler S - Use S method for pixel sampling, valid modes
are:\n";
printList(cerr, rtrt->listPixelSamplers(), 4);
+ cerr << " -camera S - User camera model S, valid cameras are:\n";
+ printList(cerr, rtrt->listCameras(), 4);
#if NOTFINISHED
cerr << " -renderer S - Use renderer S, valid renderers are:\n";
printList(cerr, rtrt->listRenderers(), 2);
- [MANTA] r302 - in trunk: Engine/Control Model/Cameras StandAlone, aek, 05/12/2005
Archive powered by MHonArc 2.6.16.