Text archives Help
- From: abe@sci.utah.edu
- To: rtrt@sci.utah.edu
- Subject: [MANTA] r280 - in branches/newPointVector: Core Core/Geometry Model Model/Cameras Model/Primitives UserInterface scenes
- Date: Tue, 10 May 2005 21:43:02 -0600 (MDT)
Author: abe
Date: Tue May 10 21:43:01 2005
New Revision: 280
Modified:
branches/newPointVector/Core/CMakeLists.txt
branches/newPointVector/Core/Geometry/AffineTransform.cc
branches/newPointVector/Core/Geometry/AffineTransform.h
branches/newPointVector/Core/Geometry/PointVector.h
branches/newPointVector/Model/CMakeLists.txt
branches/newPointVector/Model/Cameras/PinholeCamera.cc
branches/newPointVector/Model/Cameras/PinholeCamera.h
branches/newPointVector/Model/Primitives/CMakeLists.txt
branches/newPointVector/Model/Primitives/Cone.cc
branches/newPointVector/Model/Primitives/Cylinder.h
branches/newPointVector/UserInterface/XWindowUI.cc
branches/newPointVector/scenes/0.cc
Log:
Complete changes for AffineTransform -- branch should compile with these
changes
Modified: branches/newPointVector/Core/CMakeLists.txt
==============================================================================
--- branches/newPointVector/Core/CMakeLists.txt (original)
+++ branches/newPointVector/Core/CMakeLists.txt Tue May 10 21:43:01 2005
@@ -11,6 +11,9 @@
Math/MT_RNG.cc)
SET (CORE_SOURCES ${CORE_SOURCES}
Util/Args.cc)
+SET (CORE_SOURCES ${CORE_SOURCES}
+ Geometry/AffineTransform.cc
+ )
ADD_LIBRARY (Manta_Core ${CORE_SOURCES})
Modified: branches/newPointVector/Core/Geometry/AffineTransform.cc
==============================================================================
--- branches/newPointVector/Core/Geometry/AffineTransform.cc (original)
+++ branches/newPointVector/Core/Geometry/AffineTransform.cc Tue May 10
21:43:01 2005
@@ -1,6 +1,9 @@
+#include <MantaTypes.h>
#include <Core/Geometry/AffineTransform.h>
#include <Core/Math/Trig.h>
+#include <Core/Math/MinMax.h>
+#include <Core/Math/MiscMath.h>
// TODO: several of these could be faster if they become bottlenecks
@@ -76,10 +79,31 @@
}
template<typename T>
- void AffineTransformT<T>::rotate(const VectorT<T, 3>& from,
- const VectorT<T, 3>& to)
+ void AffineTransformT<T>::rotate(const VectorT<T, 3>& from_,
+ const VectorT<T, 3>& to_)
{
- //...;
+
+ // Compute an axis ortho to the two vectors.
+ VectorT<T,3> axis = Cross( from_, to_ );
+
+ // Don't assume that to and from are normalized.
+ VectorT<T,3> from = from.normal();
+ VectorT<T,3> to = to.normal();
+
+ T sinth = axis.length();
+ T costh = Dot( from, to );
+
+ // Check to make sure the rotation isn't too small.
+ if ((SCIRun::Abs(sinth) < 1.0e-9) || (SCIRun::Abs(costh) < 1.0e-9))
+ return;
+
+
+ T theta = atan2( sinth, costh );
+
+ if (SCIRun::Abs(theta) > 1.0e-9)
+ rotate( axis, theta );
+
+ // Otherwise no rotation.
}
template<typename T>
@@ -161,6 +185,7 @@
template<typename T>
void AffineTransformT<T>::invert()
{
+
T a = mat[0][0];
T b = mat[0][1];
T c = mat[0][2];
@@ -172,6 +197,7 @@
T i = mat[2][2];
T denom = c*d*h-c*g*e-b*d*i+b*g*f+a*e*i-a*h*f;
+
T inv_denom = 1./denom;
mat[0][0] = (e*i-f*h)*inv_denom;
mat[0][1] = (f*g-d*i)*inv_denom;
@@ -237,4 +263,90 @@
}
return *this;
}
+
+ // Private helper function.
+ template<typename T>
+ void AffineTransformT<T>::pre_multiply( T pre[3][3] ) {
+ T tmp[3][3];
+
+ // Copy pre into tmp.
+ for(int row = 0; row < 3; row++){
+ for(int col = 0; col < 3; col++){
+ tmp[row][col] = pre[row][col];
+ }
+ }
+
+ for(int i=0;i<3;i++){
+ for(int j=0;j<3;j++){
+ T sum = 0;
+ for(int k=0;k<3;k++){
+ sum += tmp[i][k] * mat[k][j];
+ }
+ mat[i][j] = sum;
+ }
+ T sum = mat[i][3];
+ for(int k=0;k<3;k++)
+ sum += tmp[i][k] * mat[k][3];
+ mat[i][3] = sum;
+ }
+ }
+
+ template<typename T>
+ PointT<T, 3> operator*(const AffineTransformT<T>& trans, const PointT<T,
3>& point) {
+ PointT<T,3> result;
+ for (int i=0;i<3;++i) {
+ result[i] = trans(i,0) * point[0];
+ result[i] += trans(i,1) * point[1];
+ result[i] += trans(i,2) * point[2];
+ result[i] += trans(i,3); // point[3] == 1
+ }
+ return result;
+ }
+
+ template<typename T>
+ VectorT<T, 3> operator*(const AffineTransformT<T>& trans, const VectorT<T,
3>& vec) {
+ VectorT<T,3> result;
+ for (int i=0;i<3;++i) {
+ result[i] = trans(i,0) * vec[0];
+ result[i] += trans(i,1) * vec[1];
+ result[i] += trans(i,2) * vec[2];
+ // vec[3] == 0
+ }
+ return result;
+ }
+
+ // Multiply by the transpose of the AffineTransformation, useful for
+ // computations involving an inverse transpose.
+ template<typename T>
+ PointT<T, 3> transpose_mult(const AffineTransformT<T>& trans, const
PointT<T, 3>& point) {
+ PointT<T,3> result;
+ for (int i=0;i<3;++i) {
+ result[i] = trans(0,i) * point[0];
+ result[i] += trans(1,i) * point[1];
+ result[i] += trans(2,i) * point[2];
+ result[i] += trans(3,i); // point[3] == 1
+ }
+ return result;
+ }
+
+ template<typename T>
+ VectorT<T, 3> transpose_mult(const AffineTransformT<T>& trans, const
VectorT<T, 3>& vec) {
+ VectorT<T,3> result;
+ for (int i=0;i<3;++i) {
+ result[i] = trans(0,i) * vec[0];
+ result[i] += trans(1,i) * vec[1];
+ result[i] += trans(2,i) * vec[2];
+ // vec[3] == 0
+ }
+ return result;
+ }
+
+ // Static Instances.
+ template PointT <Real,3> operator*(const AffineTransformT<Real> &trans,
const PointT <Real,3> &point);
+ template VectorT<Real,3> operator*(const AffineTransformT<Real> &trans,
const VectorT<Real,3> &vec);
+ template PointT <Real,3> transpose_mult(const AffineTransformT<Real>
&trans, const PointT <Real,3> &point);
+ template VectorT<Real,3> transpose_mult(const AffineTransformT<Real>
&trans, const VectorT<Real,3> &vec);
+ template class AffineTransformT<Real>;
+
+
}
Modified: branches/newPointVector/Core/Geometry/AffineTransform.h
==============================================================================
--- branches/newPointVector/Core/Geometry/AffineTransform.h (original)
+++ branches/newPointVector/Core/Geometry/AffineTransform.h Tue May 10
21:43:01 2005
@@ -2,6 +2,7 @@
#ifndef Manta_Core_AffineTransform_h
#define Manta_Core_AffineTransform_h
+#include <iostream>
#include <MantaTypes.h>
#include <Core/Geometry/PointVector.h>
@@ -17,15 +18,21 @@
* dimensional matrices, but a few things would need to be rethought,
* such as rotation and the load_basis constructor.
*/
- template<class T>
+ template<typename T>
class AffineTransformT {
public:
AffineTransformT() {
}
~AffineTransformT() {
}
- AffineTransformT(const AffineTransformT<T>&);
- AffineTransformT<T>& operator=(const AffineTransformT<T>&);
+
+ // Use the default version of these.
+ // AffineTransformT(const AffineTransformT<T> ©) {
+ // memcpy(mat,copy.mat, sizeof(T)*12);
+ // }
+ // AffineTransformT<T>& operator=(const AffineTransformT<T> ©) {
+ // memcpy(mat,copy.mat, sizeof(T)*12);
+ //}
// These methods set the current matrix
void initWithIdentity();
@@ -36,7 +43,6 @@
void initWithBasis(const VectorT<T, 3>& v1, const VectorT<T, 3>& v2,
const VectorT<T, 3>& v3, const PointT<T, 3>& p);
-
// These methods premultiply the current matrix by the indicated
transform
void scale(const VectorT<T, 3>& scale);
void rotate(const VectorT<T, 3>& from, const VectorT<T, 3>& to);
@@ -55,26 +61,54 @@
AffineTransformT<T> inverse() const;
void invert();
+ // Const Accessors used by global multiplication operators.
+ const T &operator() (unsigned int r, unsigned int c) const { return
mat[r][c]; }
+
// Post-multiplication
AffineTransformT<T> operator*(const AffineTransformT<T>& m) const;
AffineTransformT<T>& operator*=(const AffineTransformT<T>& m);
private:
T mat[3][4];
- void pre_multiply(T m[3][4]);
+ // Pre-multiplication.
+ void pre_multiply(T m[3][3]);
};
+
+ template<typename T>
+ PointT<T, 3> operator*(const AffineTransformT<T>& trans,
+ const
PointT<T, 3>& point);
+
+ template<typename T>
+ VectorT<T, 3> operator*(const AffineTransformT<T>& trans,
+ const
VectorT<T, 3>& vec);
+ // Multiply by the transpose of the AffineTransformation, useful for
+ // computations involving an inverse transpose.
+ template<typename T>
+ PointT<T, 3> transpose_mult(const AffineTransformT<T>& trans,
+
const PointT<T, 3>& point);
+
template<typename T>
- PointT<T, 3> operator*(const AffineTransformT<T>& trans,
- const PointT<T, 3>& point);
+ VectorT<T, 3> transpose_mult(const AffineTransformT<T>& trans,
+
const VectorT<T, 3>& vec);
+
template<typename T>
- VectorT<T, 3> operator*(const AffineTransformT<T>& trans,
- const VectorT<T, 3>& vec);
+ ostream &operator << ( ostream &os, const AffineTransformT<T> &trans ) {
+ for (int i=0;i<3;++i) {
+ for (int j=0;j<4;++j) {
+ os << trans(i,j) << " ";
+ }
+ os << std::endl;
+ }
+ }
}
-#ifdef __GNUG__
+
+
+// #ifdef __GNUG__
// This should instead be a configure variable...
-#include <Core/Geometry/AffineTransform.cc>
-#endif
+// Look in the bottom of AffineTransform.cc for explicit instantiations.
+// #include <Core/Geometry/AffineTransform.cc>
+// #endif
#endif
Modified: branches/newPointVector/Core/Geometry/PointVector.h
==============================================================================
--- branches/newPointVector/Core/Geometry/PointVector.h (original)
+++ branches/newPointVector/Core/Geometry/PointVector.h Tue May 10 21:43:01
2005
@@ -2,11 +2,14 @@
#ifndef Manta_Core_PointVector_h
#define Manta_Core_PointVector_h
+#include <iostream> // for debugging.
+
#include <MantaTypes.h>
#include <Core/Math/MinMax.h>
#include <Core/Math/MiscMath.h>
#include <math.h>
+
namespace Manta {
template<typename T, int Dim>
class VectorT {
@@ -45,7 +48,7 @@
T z() const {
return data[2];
}
- T operator[](int i) const {
+ const T &operator[](int i) const {
return data[i];
}
T &operator[] ( int i ) {
@@ -285,6 +288,22 @@
Interpolate(p1.z(), p2.z(), weight));
}
+
+ template<typename T, int Dim>
+ inline ostream &operator<< (ostream &os, const VectorT<T,Dim> &v) {
+ for (int i=0;i<Dim;++i)
+ os << v[i] << " ";
+ return os;
+ }
+
+ template<typename T, int Dim>
+ inline ostream &operator<< (ostream &os, const PointT<T,Dim> &v) {
+ for (int i=0;i<Dim;++i)
+ os << v[i] << " ";
+ return os;
+ }
+
+
}
#endif
Modified: branches/newPointVector/Model/CMakeLists.txt
==============================================================================
--- branches/newPointVector/Model/CMakeLists.txt (original)
+++ branches/newPointVector/Model/CMakeLists.txt Tue May 10 21:43:01
2005
@@ -10,6 +10,11 @@
INCLUDE (Instances/CMakeLists.txt)
INCLUDE (MiscObjects/CMakeLists.txt)
+SET(BUILD_SCALAR_VOLUME CACHE BOOL false)
+IF(BUILD_SCALAR_VOLUME)
+ INCLUDE (Primitives/Volume/CMakeLists.txt)
+ENDIF(BUILD_SCALAR_VOLUME)
+
ADD_LIBRARY (Manta_Model
${Manta_AmbientLights_SRCS}
${Manta_Backgrounds_SRCS}
@@ -18,6 +23,7 @@
${Manta_Lights_SRCS}
${Manta_Materials_SRCS}
${Manta_Primitives_SRCS}
+ ${Manta_Primitives_Volume_SRCS}
${Manta_TexCoordMappers_SRCS}
${Manta_Instances_SRCS}
${Manta_MiscObjects_SRCS}
Modified: branches/newPointVector/Model/Cameras/PinholeCamera.cc
==============================================================================
--- branches/newPointVector/Model/Cameras/PinholeCamera.cc (original)
+++ branches/newPointVector/Model/Cameras/PinholeCamera.cc Tue May 10
21:43:01 2005
@@ -1,4 +1,5 @@
+#include <MantaTypes.h>
#include <Model/Cameras/PinholeCamera.h>
#include <Core/Util/Args.h>
#include <Core/Exceptions/IllegalArgument.h>
@@ -10,6 +11,9 @@
#include <Core/Util/Assert.h>
#include <iostream>
+// Required for up direction error condition.
+#include <iostream>
+
using namespace Manta;
using namespace std;
using SCIRun::Clamp;
@@ -67,7 +71,7 @@
double dist=direction.length();
v=Cross(direction, up);
if(v.length2() == 0.0){
- cerr << "Ambiguous up direciton...\n";
+ std::cerr << __FILE__ << " line: " << __LINE__ << " Ambiguous up
direciton...\n";
}
v.normalize();
@@ -145,17 +149,34 @@
Vector lookdir(eye-lookat);
double length = lookdir.length();
+
+ std::cout << "incoming transform: " << std::endl << t << std::endl;
+ std::cout << "lookdir: " << lookdir << std::endl;
+ std::cout << "v: " << v << std::endl;
+ std::cout << "u: " << u << std::endl;
+
AffineTransform frame;
- frame.initWithBasis(v.normal()*length, u.normal()*length, lookdir, cen);
+ frame.initWithBasis(v.normal(), u.normal(), lookdir.normal(), cen);
+
+ std::cout << "frame" << std::endl << frame << std::endl;
+
+ AffineTransform frame_inv = frame;
+ frame_inv.invert();
+
+ std::cout << "frame_inv" << std::endl << frame_inv << std::endl;
- AffineTransform frame_inv = frame.inverse();
- AffineTransform t2 = frame * t * frame_inv;
+ AffineTransform t2 = frame * t * frame_inv;
- up = t2 * up;
- eye = t2 * eye;
+ std::cout << "Should be frame: " << std::endl << (frame * t) <<
std::endl;
+ std::cout << "Should be identity: " << std::endl << (frame * frame_inv) <<
std::endl;
+
+ std::cout << "t2" << std::endl << t2 << std::endl;
+
+ up = t2 * up;
+ eye = t2 * eye;
lookat = t2 * lookat;
- lookdir = eye-lookat;
+ // lookdir = eye-lookat;
setup();
}
Modified: branches/newPointVector/Model/Cameras/PinholeCamera.h
==============================================================================
--- branches/newPointVector/Model/Cameras/PinholeCamera.h (original)
+++ branches/newPointVector/Model/Cameras/PinholeCamera.h Tue May 10
21:43:01 2005
@@ -28,11 +28,11 @@
static Camera* create(const vector<string>& args);
private:
void setup();
- Point eye;
- Point lookat;
+ Point eye;
+ Point lookat;
Vector up;
double hfov, vfov;
- bool normalizeRays;
+ bool normalizeRays;
Vector direction;
Vector u,v;
Modified: branches/newPointVector/Model/Primitives/CMakeLists.txt
==============================================================================
--- branches/newPointVector/Model/Primitives/CMakeLists.txt (original)
+++ branches/newPointVector/Model/Primitives/CMakeLists.txt Tue May 10
21:43:01 2005
@@ -4,7 +4,16 @@
Primitives/PrimitiveCommon.cc
Primitives/Sphere.cc
Primitives/SuperEllipsoid.cc
- Primitives/Cube.cc
- Primitives/Cone.cc
+ # Primitives/Cube.cc
+ # Primitives/Cone.cc
Primitives/Triangle.cc
)
+
+# Should be include known broken objects?
+IF(BUILD_BROKEN)
+ SET (Manta_Primitives_SRCS
+ Manta_Primitives_SRCS
+ Primitives/Cube.cc
+ Primitives/Cone.cc
+ )
+ENDIF(BUILD_BROKEN)
\ No newline at end of file
Modified: branches/newPointVector/Model/Primitives/Cone.cc
==============================================================================
--- branches/newPointVector/Model/Primitives/Cone.cc (original)
+++ branches/newPointVector/Model/Primitives/Cone.cc Tue May 10 21:43:01
2005
@@ -51,10 +51,18 @@
double dist_scale = tv.normalize();
double a = (cosA2*Dot(V-Dot(V,Va)*Va, V-Dot(V,Va)*Va))-
(sinA2*Dot(V,Va)*Dot(V,Va));
+<<<<<<< .mine
+ double b = 2*cosA2*Dot(V-Dot(V,Va)*Va,
+ Vector(dP)-Dot(Vector(dP),Va)*Va)-
+ 2*sinA2*Dot(V,Va)*Dot(Vector(dP),Va);
+ double c = cosA2*Dot(Vector(dP)-Dot(Vector(dP),Va)*Va,
+ Vector(dP)-Dot(Vector(dP),Va)*Va)-
+=======
double b = 2*cosA2*Dot(V-Dot(V,Va)*Va, dP-Dot(dP,Va)*Va)-
2*sinA2*Dot(V,Va)*Dot(dP,Va);
double c = cosA2*Dot(dP-Dot(dP,Va)*Va,
dP-Dot(dP,Va)*Va)-
+>>>>>>> .r267
sinA2*Dot(dP,Va)*Dot(dP,Va);
double d = sqrt(b*b-4*a*c);
Modified: branches/newPointVector/Model/Primitives/Cylinder.h
==============================================================================
--- branches/newPointVector/Model/Primitives/Cylinder.h (original)
+++ branches/newPointVector/Model/Primitives/Cylinder.h Tue May 10 21:43:01
2005
@@ -4,8 +4,8 @@
#include <Model/Primitives/PrimitiveCommon.h>
#include <Interface/TexCoordMapper.h>
-#include <Core/Geometry/Point.h>
-#include <Core/Geometry/Transform.h>
+#include <Core/Geometry/PointVector.h>
+#include <Core/Geometry/AffineTransform.h>
namespace Manta
{
@@ -24,8 +24,8 @@
private:
Point bottom, top;
double radius;
- Transform xform;
- Transform ixform;
+ AffineTransform xform;
+ AffineTransform ixform;
};
}
Modified: branches/newPointVector/UserInterface/XWindowUI.cc
==============================================================================
--- branches/newPointVector/UserInterface/XWindowUI.cc (original)
+++ branches/newPointVector/UserInterface/XWindowUI.cc Tue May 10 21:43:01
2005
@@ -496,8 +496,12 @@
} else {
Vector to(projectToSphere(xpos, ypos, trackball_radius));
AffineTransform trans;
- // trans.initWithIdentity();
- trans.initWithRotation(ias.rotate_from, to);
+
+ trans.initWithRotation(ias.rotate_from, to);
+
+ std::cout << "Sent to callback: " << std::endl << trans <<
std::endl;
+ std::cout << "Small rotation: " << (trans * Point(1,0,0)) <<
std::endl;
+
ias.rotate_from = to;
Camera* camera = rtrt_interface->getCamera(channel);
Modified: branches/newPointVector/scenes/0.cc
==============================================================================
--- branches/newPointVector/scenes/0.cc (original)
+++ branches/newPointVector/scenes/0.cc Tue May 10 21:43:01 2005
@@ -1,5 +1,5 @@
-#include <Core/Geometry/Vector.h>
+#include <Core/Geometry/PointVector.h>
#include <Core/Exceptions/IllegalArgument.h>
#include <Core/Util/Args.h>
#include <Interface/Context.h>
@@ -15,7 +15,7 @@
#include <Model/Primitives/Parallelogram.h>
#include <Model/Primitives/Sphere.h>
#include <Model/Textures/CheckerTexture.h>
-#include <Core/Geometry/Transform.h>
+#include <Core/Geometry/AffineTransform.h>
#include <Core/Util/NotFinished.h>
#include <sgi_stl_warnings_off.h>
@@ -43,20 +43,18 @@
axis.normalize();
double rot=asin(2.0/sqrt(6.0));
- Transform t;
- t.load_identity();
- t.post_rotate(rot, axis);
+ AffineTransform t;
+ t.initWithRotation(axis, rot);
for(int n=0;n<3;n++){
- dir[n]=t.project(dir[n]);
+ dir[n] = t * dir[n];
}
for(int ns=0;ns<3;ns++){
- Transform t;
- t.load_identity();
- t.post_rotate(ns*2.*M_PI/3., Vector(0,0,1));
+ AffineTransform t;
+ t.initWithRotation(Vector(0,0,1), ns*2.*M_PI/3.);
for(int nv=0;nv<3;nv++){
- objset[ns*3+nv]=t.project(dir[nv]);
+ objset[ns*3+nv] = t * dir[nv];
}
}
}
@@ -72,14 +70,14 @@
depth--;
// Rotation matrix to new axis from +Z axis
- Transform mx;
- mx.load_identity();
+ AffineTransform mx;
+ mx.initWithIdentity();
mx.rotate(Vector(0,0,1), dir);
double scale = radius * (1+SCALE);
for(int n=0;n<9;n++){
- Vector child_vec(mx.project(objset[n]));
+ Vector child_vec(mx * objset[n]);
Point child_pt(center+child_vec*scale);
double child_rad=radius*SCALE; Vector child_dir = child_pt-center;
child_dir *= 1./scale;
- [MANTA] r280 - in branches/newPointVector: Core Core/Geometry Model Model/Cameras Model/Primitives UserInterface scenes, abe, 05/10/2005
Archive powered by MHonArc 2.6.16.