Text archives Help
- From: abhinav@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r311 - in trunk: Engine/ImageTraversers Interface Model/Cameras
- Date: Fri, 13 May 2005 14:36:48 -0600 (MDT)
Author: abhinav
Date: Fri May 13 14:36:47 2005
New Revision: 311
Modified:
trunk/Engine/ImageTraversers/FramelessImageTraverser.cc
trunk/Interface/Camera.h
trunk/Interface/Fragment.h
trunk/Model/Cameras/OrthogonalCamera.cc
trunk/Model/Cameras/OrthogonalCamera.h
trunk/Model/Cameras/PinholeCamera.cc
trunk/Model/Cameras/PinholeCamera.h
Log:
Fragment.h: deleted commented code that was buggy
Camera.h: added routine to project a 3D point to image plane
implemented project function for pinhole camera and added a placeholder for
Orthogonal camera
FramelessImageTraverser.cc: corrected to support variable sizes and
number of tiles and their sizes are set to vary with size rather than a fixed
one
- Abhinav
Modified: trunk/Engine/ImageTraversers/FramelessImageTraverser.cc
==============================================================================
--- trunk/Engine/ImageTraversers/FramelessImageTraverser.cc (original)
+++ trunk/Engine/ImageTraversers/FramelessImageTraverser.cc Fri May 13
14:36:47 2005
@@ -23,8 +23,6 @@
FramelessImageTraverser::FramelessImageTraverser(const vector<string>& args)
{
- xtilesize = 16; // should be a decent tile, not very big and not very small
- ytilesize = 16;
shuffledTiles = NULL;
myRandomNumber = NULL;
int argc = static_cast<int>(args.size());
@@ -79,12 +77,40 @@
int i, j, k;
int xres,yres;
context.getResolution(stereo, xres, yres);
+
+ // get some mean number of tiles. Find the power of 2 that is >= the
resolution in each
+ // dimension, i.e. let 2^x > xres, then xtilesize = 2^(x/2)
+ int nx, ny;
+
+ nx = 1;
+ int tres = xres;
+ while(tres>1)
+ {
+ nx++;
+ tres /= 2;
+ }
+
+ ny = 1;
+ tres = yres;
+ while(tres>1)
+ {
+ ny++;
+ tres /= 2;
+ }
+ nx /=2;
+ ny/=2;
+ xtilesize = 1;
+ for(i=0; i<nx; i++) xtilesize *= 2;
+ ytilesize = 1;
+ for(i=0; i<ny; i++) ytilesize *= 2;
+
myRandomNumber = new MT_RNG[context.numProcs];
for(i=0; i<context.numProcs; i++)
myRandomNumber[i].seed_rng(1234); // just to begin give a simple seed
xtiles = (xres + xtilesize-1)/xtilesize;
ytiles = (yres + ytilesize-1)/ytilesize;
+ // printf("tilesize: %d,%d; final tilenum: %d,%d; tilenum: %d,%d",
xtilesize, ytilesize, xtiles, ytiles, nx, ny);
// allocate unifrom row ordered tiles
shuffledTiles = new UniformTiles[xtiles*ytiles];
for(i=0; i<xtiles*ytiles; i++) {
@@ -97,7 +123,9 @@
if(shuffledTiles[i].xend>xres)
shuffledTiles[i].xend = xres;
if(shuffledTiles[i].yend>yres)
- shuffledTiles[i].yend = yres;
+ shuffledTiles[i].yend = yres;
+ ASSERT( shuffledTiles[i].xstart != shuffledTiles[i].xend);
+ ASSERT( shuffledTiles[i].ystart != shuffledTiles[i].yend);
}
shuffleMyTiles(); // shuffle them up
@@ -136,7 +164,7 @@
Fragment::Element& fe = fragment.get(f+i);
// normalized
double px = (double)(-1.0 + 2.0*(double)(fe.x+0.5)/(double)xres);
- double py = (double)(-1.0 + 2.0*(double)(fe.y+0.5)/(double)yres);
+ double py = (double)(-1.0 + 2.0*(double)(fe.y+0.5)/(double)xres);
//printf("%f, %f\n", (float)px, (float)py);
rays.setPixel(i, 0, px, py, &fe.color);
}
Modified: trunk/Interface/Camera.h
==============================================================================
--- trunk/Interface/Camera.h (original)
+++ trunk/Interface/Camera.h Fri May 13 14:36:47 2005
@@ -17,7 +17,7 @@
virtual void scaleFOV(double) = 0;
virtual void translate(Vector v) = 0;
virtual void dolly(double) = 0;
-
+ virtual Point project(const Point &point) = 0; // project the 3D
point on to the camera image plane
enum TransformCenter {
LookAt,
Eye,
Modified: trunk/Interface/Fragment.h
==============================================================================
--- trunk/Interface/Fragment.h (original)
+++ trunk/Interface/Fragment.h Fri May 13 14:36:47 2005
@@ -60,9 +60,6 @@
{
data[i].x =
(int)(xstart+myRandomNumber.genfrand()*(xend - xstart));
data[i].y =
(int)(ystart+myRandomNumber.genfrand()*(yend - ystart));
- //data[i].x = (int)(xstart+0.5*(xend - xstart));
- //data[i].y = (int)(ystart+0.5*(yend - ystart));
- //printf("%d,%d\n", data[i].x, data[i].y);
data[i].which_eye = which_eye;
}
}
Modified: trunk/Model/Cameras/OrthogonalCamera.cc
==============================================================================
--- trunk/Model/Cameras/OrthogonalCamera.cc (original)
+++ trunk/Model/Cameras/OrthogonalCamera.cc Fri May 13 14:36:47 2005
@@ -160,3 +160,9 @@
eye = lookat+lookdir*w;
setup();
}
+
+Point OrthogonalCamera::project(const Point &point)
+{
+ // NOT FINISHED
+ return Point(0,0,0); // just a placeholder
+}
Modified: trunk/Model/Cameras/OrthogonalCamera.h
==============================================================================
--- trunk/Model/Cameras/OrthogonalCamera.h (original)
+++ trunk/Model/Cameras/OrthogonalCamera.h Fri May 13 14:36:47 2005
@@ -23,7 +23,7 @@
virtual void dolly(double);
virtual void transform(AffineTransform t, TransformCenter);
virtual void autoview(double fov);
-
+ virtual Point project(const Point &point);
static Camera* create(const vector<string>& args);
private:
void setup();
Modified: trunk/Model/Cameras/PinholeCamera.cc
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.cc (original)
+++ trunk/Model/Cameras/PinholeCamera.cc Fri May 13 14:36:47 2005
@@ -63,21 +63,35 @@
void PinholeCamera::setup()
{
+ int i;
vfov = hfov;
direction=lookat-eye;
- double dist=direction.length();
+ nearZ=direction.length();
+
+ Vector n = direction;
+ n.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();
- double height=dist*tan(vfov*0.5*M_PI/180.0);
+ for(i=0; i<3; i++)
+ uvn[0][i] = u[i];
+
+ height=nearZ*tan(vfov*0.5*M_PI/180.0);
u*=height;
- double width=dist*tan(hfov*0.5*M_PI/180.0);
+ width=nearZ*tan(hfov*0.5*M_PI/180.0);
v*=width;
}
@@ -175,4 +189,29 @@
lookat = bbox.center();
eye = lookat+lookdir*length;
setup();
+}
+
+Point PinholeCamera::project(const Point &point)
+{
+ // translate camera center to origin
+ Vector trans(-eye.x(), -eye.y(), -eye.z());
+ Point p1 = point + trans;
+
+ // rotate to align with camera axis
+ Point p2((uvn[0][0]*p1.x() + uvn[0][1]*p1.y() + uvn[0][2]*p1.z()),
+ (uvn[1][0]*p1.x() + uvn[1][1]*p1.y() + uvn[1][2]*p1.z()),
+ (uvn[2][0]*p1.x() + uvn[2][1]*p1.y() + uvn[2][2]*p1.z()));
+
+ // project the point to the image plane using simlar triangles
+ // the viewZ is just a ratio to tell whether point is valid or not
+ // if returned viewZ>1, it means that the point lied beyong the image plane
+ // and is visible to camera, else it is not
+ // It is not a sufficient condition though, the x and y coordinates should
lie within the
+ // width and height of the image, so returned coordinates are in the
normalized space [-1,1]
+ if(fabs(p2.z())<0.0001) // check for inconsistencies
+ return Point(0,0,0);
+ else
+ return Point((p2.x()*nearZ/p2.z())/(width/2.0),
+ (p2.y()*nearZ/p2.z())/(height/2.0),
+ p2.z()/nearZ);
}
Modified: trunk/Model/Cameras/PinholeCamera.h
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.h (original)
+++ trunk/Model/Cameras/PinholeCamera.h Fri May 13 14:36:47 2005
@@ -24,18 +24,23 @@
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;
- double hfov, vfov;
+ 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;
+
+ // for projection we maintain a uvn rotation matrix
+ double uvn[3][3];
};
}
- [MANTA] r311 - in trunk: Engine/ImageTraversers Interface Model/Cameras, abhinav, 05/13/2005
Archive powered by MHonArc 2.6.16.