Text archives Help
- From: roni@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1814 - in trunk: Core/Persistent Engine/Control Engine/Display Engine/Factory Interface Model/Cameras
- Date: Sun, 4 Nov 2007 23:18:25 -0700 (MST)
Author: roni
Date: Sun Nov 4 23:18:24 2007
New Revision: 1814
Modified:
trunk/Core/Persistent/XMLArchive.cc
trunk/Engine/Control/RTRT.cc
trunk/Engine/Display/FileDisplay.cc
trunk/Engine/Factory/Factory.h
trunk/Interface/Camera.cc
trunk/Interface/Camera.h
trunk/Model/Cameras/PinholeCamera.cc
trunk/Model/Cameras/PinholeCamera.h
Log:
Core/Persistent/XMLArchive.cc
Engine/Factory/Factory.h
Removed class name from method declarations (was causing a
build error with gcc 4.1.2 on arachne).
Interface/Camera.h
Interface/Camera.cc
Added "aspectRatioMode" attribute. This is an enum that
specifies whether and how aspect ratio maintenance is performed. The
values are as follows:
KeepNone: do nothing to maintain aspect ratio. This is the
default behavior and mimics the way Manta worked before this commit.
KeepHorizontal or KeepVertical: These instruct the camera to
preserve the hfov or vfov respectively, recomputing the other value
whenever the image size changes. I think the default behavior in
Manta before the introduction of the hfov/vfov pair was KeepVertical.
Note: the method Camera::setAspectRatio() should be pure
virtual but I didn't want to break existing cameras so right now it's
virtual with a blank body.
Model/Cameras/PinholeCamera.cc
Model/Cameras/PinholeCamera.h
Implemented setAspectRatio(). Uses easy trig to recompute one
of the fov values based on the image size and the current "fixed" fov
value.
Added new option "-maintainAspectRatio" which takes either
"horizontal" or "vertical" as an argument. Not using the argument
means no aspect ratio maintenance will happen.
Added a hack to force an extra aspect ratio recompute during
preprocess. See second note for RTRT.cc below. Didn't get a chance
to test this, so it's commented out right now.
Engine/Control/RTRT.cc
Added mechanism for sending aspect ratio recompute requests in
RTRT::changeResolution() method.
Added initial aspect ratio recompute request to
RTRT::createChannel(). This is meant to handle the case where the
user asks for a non-square image when manta starts up (via -res
argument). RTRT::changeResolution() is *not* called when the window
first appears on the screen; therefore this initial request is
necessary to prevent a distorted image from rendering until the user
"pops" the window by resizing it even slightly. However, currently
this does not work. The request goes out, the aspect ratio is
recomputed, and then some time later PinholeCamera's preprocess method
is called, which somehow undoes this computation. There seems to be
some trouble in the way PinholeCamera::preprocess is written. If you
understand it, please contact me.
Engine/Display/FileDisplay.cc
Fixed whitespace badness. Sorry James :-\
Modified: trunk/Core/Persistent/XMLArchive.cc
==============================================================================
--- trunk/Core/Persistent/XMLArchive.cc (original)
+++ trunk/Core/Persistent/XMLArchive.cc Sun Nov 4 23:18:24 2007
@@ -78,9 +78,9 @@
std::string readProperty(const std::string& fieldname);
template<class T>
- void XMLArchiveElement::readwriteInteger(const std::string& fieldname,
T& data);
+ void readwriteInteger(const std::string& fieldname, T& data);
template<class T>
- void XMLArchiveElement::readwriteIntegerArray(const std::string&
fieldname, T* data, int numElements);
+ void readwriteIntegerArray(const std::string& fieldname, T* data, int
numElements);
};
typedef std::map<void*, RefInfo> refmaptype;
Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc (original)
+++ trunk/Engine/Control/RTRT.cc Sun Nov 4 23:18:24 2007
@@ -1098,6 +1098,9 @@
channel->images.resize(channel->pipelineDepth);
channel->camera = camera;
+ // Set up aspect ratio on camera
+ channel->camera->setAspectRatio(static_cast<float>(xres)/yres);
+
// Setup images for pipeline.
for(int i=0;i<channel->pipelineDepth;i++)
channel->images[i] = 0;
@@ -1279,6 +1282,8 @@
void RTRT::changeResolution(int channel, int xres, int yres, bool
changePipeline) {
channels[channel]->xres = xres;
channels[channel]->yres = yres;
+ channels[channel]->camera->setAspectRatio(static_cast<float>(xres)/yres);
+
if (changePipeline)
pipelineNeedsSetup = true;
}
Modified: trunk/Engine/Display/FileDisplay.cc
==============================================================================
--- trunk/Engine/Display/FileDisplay.cc (original)
+++ trunk/Engine/Display/FileDisplay.cc Sun Nov 4 23:18:24 2007
@@ -175,12 +175,12 @@
// Output left and right images.
if(doFrameCount){
- lss << prefix << "_left_" << setfill( '0' ) << setw( width ) <<
number << "." << type_extension;
- rss << prefix << "_right_" << setfill( '0' ) << setw( width ) <<
number << "." << type_extension;
+ lss << prefix << "_left_" << setfill( '0' ) << setw( width ) <<
number << "." << type_extension;
+ rss << prefix << "_right_" << setfill( '0' ) << setw( width ) <<
number << "." << type_extension;
}
else{
- lss << prefix << "_left_." << type_extension;
- lss << prefix << "_right_." << type_extension;
+ lss << prefix << "_left_." << type_extension;
+ lss << prefix << "_right_." << type_extension;
}
// Send the image to the appropriate writer.
@@ -197,14 +197,14 @@
// Otherwise output a single image.
stringstream ss;
if(doFrameCount){
- ss << prefix << "_"
- << setfill( '0' )
- << setw( width )
- << number
- << "." << type_extension;
+ ss << prefix << "_"
+ << setfill( '0' )
+ << setw( width )
+ << number
+ << "." << type_extension;
}
else{
- ss << prefix << "." << type_extension;
+ ss << prefix << "." << type_extension;
}
if (writer == TGA_WRITER) {
Modified: trunk/Engine/Factory/Factory.h
==============================================================================
--- trunk/Engine/Factory/Factory.h (original)
+++ trunk/Engine/Factory/Factory.h Sun Nov 4 23:18:24 2007
@@ -199,7 +199,7 @@
string scenePath;
- Scene* Factory::readArchiveScene(const string& name, const
vector<string>& args) const;
+ Scene* readArchiveScene(const string& name, const vector<string>& args)
const;
Scene* readMOScene(const string& name, const vector<string>& args, bool
printErrors) const;
void readMOStack(const string& name, const vector<string>& args, bool
printErrors ) const;
Modified: trunk/Interface/Camera.cc
==============================================================================
--- trunk/Interface/Camera.cc (original)
+++ trunk/Interface/Camera.cc Sun Nov 4 23:18:24 2007
@@ -5,6 +5,7 @@
using namespace Manta;
Camera::Camera()
+ : aspectRatioMode(Camera::KeepNone)
{
}
Modified: trunk/Interface/Camera.h
==============================================================================
--- trunk/Interface/Camera.h (original)
+++ trunk/Interface/Camera.h Sun Nov 4 23:18:24 2007
@@ -63,6 +63,17 @@
virtual void getBasicCameraData(BasicCameraData& cam) const = 0;
virtual BasicCameraData getBasicCameraData() const { BasicCameraData c;
getBasicCameraData(c); return c; }
+ // Whether/how to maintain an aspect ratio.
+ enum AspectRatioMode {
+ KeepVertical,
+ KeepHorizontal,
+ KeepNone
+ };
+ void setAspectRatioMode(AspectRatioMode mode) { aspectRatioMode = mode; }
+
+ // Choudhury: This method is not pure virtual so as not to break
+ // the other cameras.
+ virtual void setAspectRatio(float ratio) { }
// This is not pass by reference because it needs to be used in a
transaction
virtual void setBasicCameraData(BasicCameraData cam) = 0;
@@ -97,6 +108,9 @@
virtual void output( std::ostream& os ) = 0; // Output a text
// description of the
// camera's state.
+ protected:
+ AspectRatioMode aspectRatioMode;
+
private:
Camera(const Camera&);
Camera& operator=(const Camera&);
Modified: trunk/Model/Cameras/PinholeCamera.cc
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.cc (original)
+++ trunk/Model/Cameras/PinholeCamera.cc Sun Nov 4 23:18:24 2007
@@ -78,6 +78,17 @@
normalizeRays = true;
} else if(arg == "-createCornerRays"){
createCornerRays = true;
+ } else if(arg == "-maintainAspectRatio"){
+ string keep;
+ if(!getStringArg(i, args, keep))
+ throw IllegalArgument("PinholeCamera -maintainAspectRatio", i, args);
+
+ if(keep == "horizontal")
+ aspectRatioMode = Camera::KeepHorizontal;
+ else if(keep == "vertical")
+ aspectRatioMode = Camera::KeepVertical;
+ else
+ throw IllegalArgument("PinholeCamera -maintainAspectRatio", i, args);
} else {
throw IllegalArgument("PinholeCamera", i, args);
}
@@ -115,6 +126,36 @@
os << " )" << std::endl;
}
+void PinholeCamera::setAspectRatio(float ratio){
+ // This method modifies the "variable" fov to correctly reflect the
+ // aspect ratio passed in.
+
+ const Real *inputAngle = 0;
+ Real *outputAngle = 0;
+ switch(aspectRatioMode){
+ case Camera::KeepHorizontal:
+ inputAngle = &hfov;
+ outputAngle = &vfov;
+ break;
+
+ case Camera::KeepVertical:
+ inputAngle = &vfov;
+ outputAngle = &hfov;
+ break;
+
+ case Camera::KeepNone:
+ return;
+ break;
+ }
+
+ *outputAngle = RtoD(2*atan(ratio*tan(DtoR(0.5*(*inputAngle)))));
+ setup();
+
+ // Choudhury: This is a hack to solve the initially non-square image
+ // problem.
+ savedRatio = ratio;
+}
+
Camera* PinholeCamera::create(const vector<string>& args)
{
return new PinholeCamera(args);
@@ -470,6 +511,14 @@
const BasicCameraData* bookmark = scene->currentBookmark();
if(bookmark){
setBasicCameraData(*bookmark);
+
+ // Choudhury: the following line is commented out because it
+ // hasn't been tested yet. It's a hack to get PinholeCameras to
+ // properly display non-square images at startup (as by passing
+ // -res MxY to bin/manta).
+
+ //this->setAspectRatio(savedRatio);
+
haveCamera = true;
} else {
eye = Vector(0,1,0);
Modified: trunk/Model/Cameras/PinholeCamera.h
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.h (original)
+++ trunk/Model/Cameras/PinholeCamera.h Sun Nov 4 23:18:24 2007
@@ -30,6 +30,8 @@
virtual void autoview(const BBox bbox);
virtual void output( std::ostream& os );
+ virtual void setAspectRatio(float ratio);
+
virtual void getBasicCameraData(BasicCameraData& cam) const;
// This is not pass by reference because it needs to be used in a
transaction
virtual void setBasicCameraData(BasicCameraData cam);
@@ -63,6 +65,11 @@
bool normalizeRays;
bool createCornerRays;
bool haveCamera;
+
+ // Choudhury: this variable is part of a hack to get
+ // PinholeCameras to display non-square images properly at
+ // startup.
+ float savedRatio;
};
}
- [Manta] r1814 - in trunk: Core/Persistent Engine/Control Engine/Display Engine/Factory Interface Model/Cameras, roni, 11/05/2007
Archive powered by MHonArc 2.6.16.