Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r949 - in trunk: Core/Geometry Core/Util Engine/Control Model/Groups Model/Intersections Model/Materials Model/Readers StandAlone
- Date: Tue, 21 Feb 2006 23:13:46 -0700 (MST)
Author: abe
Date: Tue Feb 21 23:13:45 2006
New Revision: 949
Added:
trunk/Model/Materials/MaterialTable.cc
trunk/Model/Materials/MaterialTable.h
trunk/Model/Readers/V3C1.cc
trunk/Model/Readers/V3C1.h
Modified:
trunk/Core/Geometry/BBox.h
trunk/Core/Util/Endian.h
trunk/Engine/Control/RTRT.cc
trunk/Model/Groups/KDTree.cc
trunk/Model/Groups/KDTree.h
trunk/Model/Groups/KDTreeLoader.cc
trunk/Model/Groups/SSEKDTree.cc
trunk/Model/Groups/TransparentKDTree.cc
trunk/Model/Groups/VerticalKDTree.cc
trunk/Model/Intersections/TriangleEdge.h
trunk/Model/Materials/CMakeLists.txt
trunk/StandAlone/manta.cc
Log:
The commit contains most of the code I changed while adding a dynamic grid
implementation to manta....
Replaced exit(..) with Thread::exitAll(..).
M StandAlone/manta.cc
Added reset method.
M Core/Geometry/BBox.h
Added specializations for Vector and Color
M Core/Util/Endian.h
Added struct's and function api for loading .v3c1 files.
A Model/Readers/V3C1.cc
A Model/Readers/V3C1.h
Removed two vertices from the kdtree triangle class (also used by the grids,
etc). Typedef'ed normal and texcoord classes back to V3C1 structs.
M Model/Groups/KDTree.h
M Model/Groups/KDTreeLoader.cc
M Model/Groups/VerticalKDTree.cc
M Model/Groups/KDTree.cc
M Model/Groups/TransparentKDTree.cc
M Model/Groups/SSEKDTree.cc
Added a material type that supports indirection to another material based on
a texture. For use with kdtree's and grids.
A Model/Materials/MaterialTable.cc
A Model/Materials/MaterialTable.h
M Model/Materials/CMakeLists.txt
Moved the ever popular macro triangle-edge intersection code into a header.
M Model/Intersections/TriangleEdge.h
Altered code so that if a scene fails to load, the loading function which
failed isn't called a second time (???)
Switched order of serial and parallel animation callbacks so that serial
callbacks are made first.
M Engine/Control/RTRT.cc
Modified: trunk/Core/Geometry/BBox.h
==============================================================================
--- trunk/Core/Geometry/BBox.h (original)
+++ trunk/Core/Geometry/BBox.h Tue Feb 21 23:13:45 2006
@@ -43,6 +43,11 @@
bounds[0] = Vector( max_val, max_val, max_val);
bounds[1] = Vector(-max_val, -max_val, -max_val);
}
+
+ void reset( const Vector& min_, const Vector& max_ ) {
+ bounds[0] = min_;
+ bounds[1] = max_;
+ }
// Test whether the box is in the "uninitialized state"
bool isDefault() const {
Modified: trunk/Core/Util/Endian.h
==============================================================================
--- trunk/Core/Util/Endian.h (original)
+++ trunk/Core/Util/Endian.h Tue Feb 21 23:13:45 2006
@@ -29,32 +29,55 @@
#ifndef Manta_Endian_h
#define Manta_Endian_h
-namespace Manta {
-
-
///////////////////////////////////////////////////////////////////////////
- // Swap the endianness of a variable.
- template< typename T >
- inline T endian_swap( T in ) {
- T out;
- char * const pin = (char *)∈
- char * const pout = (char *)&out;
+#include <MantaTypes.h>
+#include <Core/Color/ColorSpace.h>
- for (int i=0;i<sizeof(T);++i) {
- pout[i] = pin[sizeof(T)-1-i];
- }
+namespace Manta {
- return out;
+ ///////////////////////////////////////////////////////////////////////////
+ // Swap the endianness of a variable.
+ template< typename T >
+ inline T endian_swap( const T &in ) {
+ T out;
+ char const * const pin = (char *)∈
+ char * const pout = (char *)&out;
+
+ for (int i=0;i<sizeof(T);++i) {
+ pout[i] = pin[sizeof(T)-1-i];
}
-
- // Check the endianness of this machine.
- inline bool is_big_endian() {
-
- unsigned int x = 0x00112233;
- char * const p = (char *)&x;
-
- return (p[0] == 0x00);
+
+ return out;
+ }
+
+ // Check the endianness of this machine.
+ inline bool is_big_endian() {
+
+ unsigned int x = 0x00112233;
+ char * const p = (char *)&x;
+
+ return (p[0] == 0x00);
+ }
+
+
/////////////////////////////////////////////////////////////////////////////
+ // Specializations.
+ template<>
+ inline VectorT<Real,3> endian_swap( const VectorT<Real, 3> &in ) {
+ VectorT<Real,3> out;
+ for (int i=0;i<3;++i) {
+ out[i] = endian_swap( in[i] );
}
+ return out;
+ }
+ template<>
+ inline ColorSpace<RGBTraits> endian_swap( const ColorSpace<RGBTraits> &in
) {
+ ColorSpace<RGBTraits> out;
+ const int size = (ColorSpace<RGBTraits>::NumComponents);
+ for (int i=0;i<size;++i) {
+ out[i] = endian_swap( in[i] );
+ }
+ return out;
+ }
};
#endif
Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc (original)
+++ trunk/Engine/Control/RTRT.cc Tue Feb 21 23:13:45 2006
@@ -305,8 +305,10 @@
// Do callbacks
changed=false;
//callbackLock.readLock();
- doParallelAnimationCallbacks(changed, proc, workersAnimAndImage);
+
doSerialAnimationCallbacks(changed, proc, workersAnimAndImage);
+ doParallelAnimationCallbacks(changed, proc, workersAnimAndImage);
+
if(proc == 0)
postTransactions(changed);
@@ -1171,8 +1173,8 @@
(suffix == "dll")) {
// Do this twice - once silently and once printing errors
newScene = readMOScene(name, args, false);
- if(!newScene)
- readMOScene(name, args, true);
+ // if(!newScene)
+ // readMOScene(name, args, true);
} else {
// Try reading it as an MO
newScene = readMOScene(name+"."+system_suffix, args, false);
Modified: trunk/Model/Groups/KDTree.cc
==============================================================================
--- trunk/Model/Groups/KDTree.cc (original)
+++ trunk/Model/Groups/KDTree.cc Tue Feb 21 23:13:45 2006
@@ -32,6 +32,7 @@
#include <Model/Groups/varray.h>
#include <Model/Intersections/AxisAlignedBox.h>
+#include <Model/Intersections/TriangleEdge.h>
#include <Interface/Context.h>
#include <SCIRun/Core/Thread/Time.h>
@@ -53,35 +54,6 @@
#define SHOW_DUPLICATES 0
-//static unsigned long global_counter = 0;
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-// Triangle Intersection routines.
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-static int
-intersect_triangle3(const float orig[3],
- const float dir[3],
- const float vert0[3], const float vert1[3], const float
vert2[3],
- float *t, float *u, float *v );
-
-// Currently this routine is the fastest.
-// This is a C version of the ray triangle intersection edge form.
-static inline int
-intersect_triangle3_edge(const float orig[3],
- const float dir[3],
- const float vert0[3],
- float *t, float *u, float *v,
- const float *edge1, const float *edge2);
-
-// This is a C++ version of the above routine.
-static int
-intersectTriangle3Edge(const Vectorf& direction, const Vectorf& origin,
- const Vectorf& edge1, Vectorf& edge2, Vectorf& p0,
- float& t, float& u, float& v );
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -107,8 +79,8 @@
Triangle &tri = tris->get(triIdx);
float t, u, v;
- if(intersect_triangle3_edge( origin.getDataPtr(), direction.getDataPtr(),
- &tri[0][0],
+ if(Intersection::intersect_triangle3_edge( origin.getDataPtr(),
direction.getDataPtr(),
+ tri.v.getDataPtr(),
&t, &u, &v,
tri.edge1.getDataPtr(),
tri.edge2.getDataPtr() ))
@@ -385,227 +357,6 @@
exitPos = travStack[exitPos].prev;
nearNode = travStack[entryPos].node;
}
-}
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-/********************************************************/
-/* AABB-triangle overlap test code */
-/* by Tomas Akenine-Moller */
-/* Function: int triBoxOverlap(float boxcenter[3], */
-/* float boxhalfsize[3],float triverts[3][3]); */
-/* History: */
-/* 2001-03-05: released the code in its first version */
-/* 2001-06-18: changed the order of the tests, faster */
-/* 2003-2005: converted to using routines/macros in vmath.h */
-/* */
-/* Acknowledgement: Many thanks to Pierre Terdiman for */
-/* suggestions and discussions on how to optimize code. */
-/* Thanks to David Hunt for finding a ">="-bug! */
-/********************************************************/
-
-
-// #include <math.h>
-// #include <stdio.h>
-
-#define EPSILON 0.000001
-
-#define CROSS(dest,v1,v2) \
-(dest)[0]=(v1)[1]*(v2)[2]-(v1)[2]*(v2)[1]; \
-(dest)[1]=(v1)[2]*(v2)[0]-(v1)[0]*(v2)[2]; \
-(dest)[2]=(v1)[0]*(v2)[1]-(v1)[1]*(v2)[0];
-#define DOT(v1,v2) ((v1)[0]*(v2)[0]+(v1)[1]*(v2)[1]+(v1)[2]*(v2)[2])
-#define SUB(dest,v1,v2) \
-(dest)[0]=(v1)[0]-(v2)[0]; \
-(dest)[1]=(v1)[1]-(v2)[1]; \
-(dest)[2]=(v1)[2]-(v2)[2];
-
-/* code rewritten to do tests on the sign of the determinant */
-/* the division is before the test of the sign of the det */
-/* and one CROSS has been moved out from the if-else if-else */
-inline int intersect_triangle3(const float orig[3], const float dir[3],
- const float vert0[3], const float vert1[3],
const float vert2[3],
- float *t, float *u, float *v)
-{
- float edge1[3], edge2[3];
- float tvec[3], pvec[3], qvec[3];
- float det,inv_det;
-
- /* find vectors for two edges sharing vert0 */
- SUB(edge1, vert1, vert0);
- SUB(edge2, vert2, vert0);
-
- /* begin calculating determinant - also used to calculate U parameter */
- CROSS(pvec, dir, edge2);
-
- /* if determinant is near zero, ray lies in plane of triangle */
- det = DOT(edge1, pvec);
-
- /* calculate distance from vert0 to ray origin */
- SUB(tvec, orig, vert0);
- inv_det = 1.0f/ det;
-
- CROSS(qvec, tvec, edge1);
-
- /* calculate U parameter */
- float uu = DOT(tvec, pvec);
- float vv;
-
- if (det > EPSILON)
- {
- if (uu < 0.0f || uu > det)
- return 0;
-
- /* calculate V parameter and test bounds */
- vv = DOT(dir, qvec);
- if (vv < 0.0f || uu + vv > det)
- return 0;
-
- }
- else if(det < -EPSILON)
- {
- if (uu > 0.0f || uu < det)
- return 0;
-
- /* calculate V parameter and test bounds */
- vv = DOT(dir, qvec) ;
- if (vv > 0.0f || uu + vv < det)
- return 0;
- }
- else return 0; /* ray is parallell to the plane of the triangle */
-
- *t = DOT(edge2, qvec) * inv_det;
- (*u) = uu*inv_det;
- (*v) = vv*inv_det;
-
- return 1;
-}
-
-inline int intersect_triangle3_edge(const float orig[3], const float dir[3],
- const float vert0[3],
- float *t, float *u, float *v, const float
*edge1, const float *edge2 )
-{
- // float edge1[3], edge2[3];
- float tvec[3], pvec[3], qvec[3];
- float det,inv_det;
-
- /* find vectors for two edges sharing vert0 */
- // SUB(edge1, vert1, vert0);
- // SUB(edge2, vert2, vert0);
-
- /* begin calculating determinant - also used to calculate U parameter */
- CROSS(pvec, dir, edge2);
-
- /* if determinant is near zero, ray lies in plane of triangle */
- det = DOT(edge1, pvec);
-
- /* calculate distance from vert0 to ray origin */
- SUB(tvec, orig, vert0);
- inv_det = 1.0f/ det;
-
- CROSS(qvec, tvec, edge1);
-
- /* calculate U parameter */
- float uu = DOT(tvec, pvec);
- float vv;
-
- if (det > EPSILON)
- {
- if (uu < 0.0f || uu > det)
- return 0;
-
- /* calculate V parameter and test bounds */
- vv = DOT(dir, qvec);
- if (vv < 0.0f || uu + vv > det)
- return 0;
-
- }
- else if(det < -EPSILON)
- {
- if (uu > 0.0f || uu < det)
- return 0;
-
- /* calculate V parameter and test bounds */
- vv = DOT(dir, qvec) ;
- if (vv > 0.0f || uu + vv < det)
- return 0;
- }
- else return 0; /* ray is parallell to the plane of the triangle */
-
- *t = DOT(edge2, qvec) * inv_det;
- (*u) = uu*inv_det;
- (*v) = vv*inv_det;
-
- return 1;
-}
-
-inline int intersectTriangle3Edge(const Vectorf &direction, const Vectorf
&origin,
- const Vectorf &edge1, Vectorf &edge2,
Vectorf &p0,
- float &t, float &u, float &v )
-{
-
- Vectorf tvec, pvec, qvec;
-
-
- // Vectorf edge1 = ( tri.edge1 );
- // Vectorf edge2 = ( tri.edge2 );
-
- /* begin calculating determinant - also used to calculate U parameter */
- pvec = Cross( direction, edge2 );
-
- // CROSS(pvec, dir, edge2);
-
- /* if determinant is near zero, ray lies in plane of triangle */
- // det = DOT(edge1, pvec);
- float det = Dot( edge1, pvec );
-
- /* calculate distance from vert0 to ray origin */
- // SUB(tvec, orig, vert0);
- tvec = origin - p0;
-
- qvec = Cross( tvec, edge1 );
- // CROSS(qvec, tvec, edge1);
-
- /* calculate U parameter */
- // float uu = DOT(tvec, pvec);
- // float vv;
- float uu = Dot( tvec, pvec );
- float vv;
-
- if (det > 1e-5f) {
- if (uu < 0.0 || uu > det)
- return 0;
-
- /* calculate V parameter and test bounds */
- vv = Dot( direction, qvec );
-
- if (vv < 0.0 || uu + vv > det)
- return 0;
-
- }
- else if(det < -1e-5f) {
- if (uu > 0.0 || uu < det)
- return 0;
-
- /* calculate V parameter and test bounds */
- vv = Dot(direction, qvec) ;
- if (vv > 0.0 || uu + vv < det)
- return 0;
- }
- else {
- return 0; /* ray is parallell to the plane of the triangle */
- }
-
- float inv_det = 1.0f / det;
-
- t = (Dot( edge2, qvec ) * inv_det);
- u = (uu * inv_det);
- v = (vv * inv_det);
-
- return 1;
}
///////////////////////////////////////////////////////////////////////////////
Modified: trunk/Model/Groups/KDTree.h
==============================================================================
--- trunk/Model/Groups/KDTree.h (original)
+++ trunk/Model/Groups/KDTree.h Tue Feb 21 23:13:45 2006
@@ -43,6 +43,7 @@
#include <Model/Groups/KDTreeLoader.h>
#include <Model/Groups/varray.h>
+#include <Model/Readers/V3C1.h>
namespace Manta {
@@ -67,46 +68,29 @@
///////////////////////////////////////////////////////////////////////////
class Triangle {
public:
- Vectorf v[3]; // 3*3 floats = 9*4 bytes = 36 bytes
+ Vectorf v;
Color payload;
Vectorf edge1, edge2; // 2*3 floats = 6*4 bytes = 24 bytes
- // the above are exactly 64 bytes
Triangle() { }
- // Access vertices.
- Vectorf& operator[] (int i) { return v[i]; }
- const Vectorf& operator[] (int i) const { return v[i]; }
-
// Compute bounds.
- void getBound(BBox &bounds_) {
- bounds_.extendByPoint( v[0] );
- bounds_.extendByPoint( v[1] );
- bounds_.extendByPoint( v[2] );
+ void computeBounds(BBox &bounds_) {
+ bounds_.extendByPoint( v );
+ bounds_.extendByPoint( v+edge1 );
+ bounds_.extendByPoint( v+edge2 );
}
};
///////////////////////////////////////////////////////////////////////////
// TRIANGLE NORMALS TRIANGLE NORMALS TRIANGLE NORMALS TRIANGLE
NORMALS
///////////////////////////////////////////////////////////////////////////
- class TriangleNormal {
- private:
- Vectorf normal[3];
- public:
- Vectorf& operator[] ( int i ) { return normal[i]; };
- const Vectorf& operator[] ( int i ) const { return normal[i]; };
- };
+ typedef V3C1Normal TriangleNormal;
///////////////////////////////////////////////////////////////////////////
// TEXTURE COORD TEXTURE COORD TEXTURE COORD TEXTURE COORD TEXTURE
COOR
///////////////////////////////////////////////////////////////////////////
- class TextureCoord {
- private:
- VectorT<float,2> coord[3];
- public:
- VectorT<float,2> &operator[] ( int i ) { return coord[i]; };
- const VectorT<float,2> &operator[] ( int i ) const { return coord[i];
};
- };
+ typedef V3C1TextureCoord TextureCoord;
///////////////////////////////////////////////////////////////////////////
// KDTREE INTERNAL NODE
Modified: trunk/Model/Groups/KDTreeLoader.cc
==============================================================================
--- trunk/Model/Groups/KDTreeLoader.cc (original)
+++ trunk/Model/Groups/KDTreeLoader.cc Tue Feb 21 23:13:45 2006
@@ -141,7 +141,7 @@
// Touch all of the buffers assigned to this thread.
for (long i=begin_offset;i<end_offset;++i) {
- (**tris)[i][0][0] = 0.0;
+ (**tris)[i].v[0] = 0.0;
(*perVertNormals)[i][0][0] = 0.0;
(*perVertTexCoords)[i][0][0] = 0.0;
}
@@ -161,9 +161,11 @@
// Check to see if we are on a big endian system
// Data was generate on Altix (little endian)
+ Vectorf vertex[3];
+
if (is_big_endian()) {
for (int j=0; j<3; ++j) {
- (**tris)[i][j] = Vectorf(
endian_swap( _rawVertColData[0] ),
+ vertex[j] = Vectorf( endian_swap(
_rawVertColData[0] ),
endian_swap( _rawVertColData[1] ),
endian_swap( _rawVertColData[2] ));
_rawVertColData += 3;
@@ -180,9 +182,9 @@
// Otherwise don't swap.
else {
for (int j=0; j<3; ++j) {
- (**tris)[i][j] = Vectorf(
_rawVertColData[0],
- _rawVertColData[1],
- _rawVertColData[2] );
+ vertex[j] = Vectorf(
_rawVertColData[0],
+ _rawVertColData[1],
+ _rawVertColData[2] );
_rawVertColData += 3;
if(rawNormData) {
@@ -215,10 +217,15 @@
b = _rawVertColData[2];
_rawVertColData += 3;
}
-
+
+ (**tris)[i].v = vertex[0]; // (**tris)[i][0];
+
// Compute edges.
- (**tris)[i].edge1 = (**tris)[i][1] - (**tris)[i][0];
- (**tris)[i].edge2 = (**tris)[i][2] - (**tris)[i][0];
+ // (**tris)[i].edge1 = (**tris)[i][1] -
(**tris)[i][0];
+ // (**tris)[i].edge2 = (**tris)[i][2] -
(**tris)[i][0];
+ (**tris)[i].edge1 = vertex[1] - vertex[0];
+ (**tris)[i].edge2 = vertex[2] - vertex[0];
+
// Specify the payload.
// (**tris)[i].payload = ((r<<16)+(g<<8)+b);
@@ -226,7 +233,8 @@
if(!rawNormData) {
// Compute the normal.
- (*perVertNormals)[i][0] =
Cross((**tris)[i].edge1, (**tris)[i].edge2).normal();
+ (*perVertNormals)[i][0] =
+ Cross((**tris)[i].edge1, (**tris)[i].edge2).normal();
// Use the same normal for each vertex
(*perVertNormals)[i][1] = (*perVertNormals)[i][2] =
(*perVertNormals)[i][0];
@@ -235,9 +243,7 @@
// Update the bounding box of the whole scene
for (long j=0; j<3; j++) {
Triangle &tri = (**tris)[i];
- bounds.extendByPoint( tri[0] );
- bounds.extendByPoint( tri[1] );
- bounds.extendByPoint( tri[2] );
+ tri.computeBounds( bounds );
}
}
}
Modified: trunk/Model/Groups/SSEKDTree.cc
==============================================================================
--- trunk/Model/Groups/SSEKDTree.cc (original)
+++ trunk/Model/Groups/SSEKDTree.cc Tue Feb 21 23:13:45 2006
@@ -120,7 +120,7 @@
index,
tri.edge1,
tri.edge2,
- tri[0] );
+ tri.v );
}
}
Modified: trunk/Model/Groups/TransparentKDTree.cc
==============================================================================
--- trunk/Model/Groups/TransparentKDTree.cc (original)
+++ trunk/Model/Groups/TransparentKDTree.cc Tue Feb 21 23:13:45 2006
@@ -149,7 +149,7 @@
// if (intersectTriangle3Edge( direction, origin, tri.edge1, tri.edge2,
tri[0], t, u, v )) {
if(intersect_triangle3_edge( origin.getDataPtr(), direction.getDataPtr(),
- &tri[0][0],
+ tri.v.getDataPtr(),
&t, &u, &v,
tri.edge1.getDataPtr(),
tri.edge2.getDataPtr() ))
Modified: trunk/Model/Groups/VerticalKDTree.cc
==============================================================================
--- trunk/Model/Groups/VerticalKDTree.cc (original)
+++ trunk/Model/Groups/VerticalKDTree.cc Tue Feb 21 23:13:45 2006
@@ -131,7 +131,7 @@
if(intersect_packet.active_mask[p] &&
intersect_triangle3_edge( rays.getOrigin(which+p).getDataPtr(),
rays.getDirection(which+p).getDataPtr(),
- &tri[0][0],
+ tri.v.getDataPtr(),
&t, &u, &v,
tri.edge1.getDataPtr(),
tri.edge2.getDataPtr() )) {
Modified: trunk/Model/Intersections/TriangleEdge.h
==============================================================================
--- trunk/Model/Intersections/TriangleEdge.h (original)
+++ trunk/Model/Intersections/TriangleEdge.h Tue Feb 21 23:13:45 2006
@@ -38,7 +38,90 @@
namespace Manta {
namespace Intersection {
+
+
///////////////////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////////////////
+ // Triangle Intersection routines.
+
///////////////////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////////////////
+
+
+
///////////////////////////////////////////////////////////////////////////////
+ // C-style ray triangle edge intersection test. Slightly faster than C++
+ // version included below.
+
+#define EPSILON 0.000001
+
+#define CROSS(dest,v1,v2) \
+(dest)[0]=(v1)[1]*(v2)[2]-(v1)[2]*(v2)[1]; \
+(dest)[1]=(v1)[2]*(v2)[0]-(v1)[0]*(v2)[2]; \
+(dest)[2]=(v1)[0]*(v2)[1]-(v1)[1]*(v2)[0];
+#define DOT(v1,v2) ((v1)[0]*(v2)[0]+(v1)[1]*(v2)[1]+(v1)[2]*(v2)[2])
+#define SUB(dest,v1,v2) \
+(dest)[0]=(v1)[0]-(v2)[0]; \
+(dest)[1]=(v1)[1]-(v2)[1]; \
+(dest)[2]=(v1)[2]-(v2)[2];
+
+ inline int intersect_triangle3_edge(const float orig[3], const float
dir[3],
+ const float vert0[3],
+ float *t, float *u, float *v, const
float *edge1, const float *edge2 )
+ {
+ // float edge1[3], edge2[3];
+ float tvec[3], pvec[3], qvec[3];
+ float det,inv_det;
+ /* find vectors for two edges sharing vert0 */
+ // SUB(edge1, vert1, vert0);
+ // SUB(edge2, vert2, vert0);
+
+ /* begin calculating determinant - also used to calculate U parameter
*/
+ CROSS(pvec, dir, edge2);
+
+ /* if determinant is near zero, ray lies in plane of triangle */
+ det = DOT(edge1, pvec);
+
+ /* calculate distance from vert0 to ray origin */
+ SUB(tvec, orig, vert0);
+ inv_det = 1.0f/ det;
+
+ CROSS(qvec, tvec, edge1);
+
+ /* calculate U parameter */
+ float uu = DOT(tvec, pvec);
+ float vv;
+
+ if (det > EPSILON)
+ {
+ if (uu < 0.0f || uu > det)
+ return 0;
+
+ /* calculate V parameter and test bounds */
+ vv = DOT(dir, qvec);
+ if (vv < 0.0f || uu + vv > det)
+ return 0;
+
+ }
+ else if(det < -EPSILON)
+ {
+ if (uu > 0.0f || uu < det)
+ return 0;
+
+ /* calculate V parameter and test bounds */
+ vv = DOT(dir, qvec) ;
+ if (vv > 0.0f || uu + vv < det)
+ return 0;
+ }
+ else return 0; /* ray is parallell to the plane of the triangle */
+
+ *t = DOT(edge2, qvec) * inv_det;
+ (*u) = uu*inv_det;
+ (*v) = vv*inv_det;
+
+ return 1;
+ }
+
+
+
inline bool intersectTriangleEdge(Real& t, Real& u, Real& v,
const Ray& ray,
const Vector& edge1,
Modified: trunk/Model/Materials/CMakeLists.txt
==============================================================================
--- trunk/Model/Materials/CMakeLists.txt (original)
+++ trunk/Model/Materials/CMakeLists.txt Tue Feb 21 23:13:45 2006
@@ -12,6 +12,8 @@
Materials/Lambertian.cc
Materials/LitMaterial.h
Materials/LitMaterial.cc
+ Materials/MaterialTable.h
+ Materials/MaterialTable.cc
Materials/MetalMaterial.h
Materials/MetalMaterial.cc
Materials/Phong.h
Added: trunk/Model/Materials/MaterialTable.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Materials/MaterialTable.cc Tue Feb 21 23:13:45 2006
@@ -0,0 +1,107 @@
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005-2006
+ Scientific Computing and Imaging Institute, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Model/Materials/MaterialTable.h>
+
+
+#include <Interface/RayPacket.h>
+#include <Interface/Context.h>
+
+using namespace Manta;
+
+MaterialTable::~MaterialTable() {
+
+ // Delete all of the owned materials.
+ for (int i=0;i<material_table.size();++i) {
+ if (material_table[i].material && material_table[i].owned) {
+ delete material_table[i].material;
+ }
+ }
+}
+
+void MaterialTable::preprocess(const PreprocessContext& context) {
+
+ // Call preprocess on each material.
+ for (int i=0;i<material_table.size();++i) {
+ if (material_table[i].material) {
+ material_table[i].material->preprocess( context );
+ }
+ }
+}
+
+void MaterialTable::shade(const RenderContext& context, RayPacket& rays)
const {
+
+ // Determine material id's.
+ int id[RayPacket::MaxSize];
+ id_texture->mapValues( context, rays, id );
+
+ // Shade continuous subpackets of matching materials.
+ for(int i = rays.begin();i<rays.end();){
+ const Material *hit_matl = material_table[ id[i] ].material;
+ int end = i+1;
+
+ while(end < rays.end() && rays.wasHit(end) &&
+ material_table[id[end]].material == hit_matl)
+ end++;
+
+ // Shade the subpacket of rays.
+ RayPacket subPacket(rays, i, end);
+ hit_matl->shade(context, subPacket);
+ i=end;
+
+ }
+}
+
+void MaterialTable::setMaterial( int material_id, Material *material, bool
owned ) {
+ // Check to see that the table size is correct.
+ if (material_id >= material_table.size()) {
+ material_table.resize( material_id+1, Entry( 0, false ) );
+ }
+
+ // Check to see if another owned material already occupies the spot.
+ if (material_table[material_id].material &&
+ material_table[material_id].owned) {
+ delete material_table[material_id].material;
+ material_table[material_id].material = 0;
+ }
+
+ // Lastly assign the pointer.
+ material_table[material_id].material = material;
+ material_table[material_id].owned = owned;
+}
+
+Material *MaterialTable::getMaterial( int material_id ) {
+
+ return material_table[material_id].material;
+}
+
+
+
+
+
Added: trunk/Model/Materials/MaterialTable.h
==============================================================================
--- (empty file)
+++ trunk/Model/Materials/MaterialTable.h Tue Feb 21 23:13:45 2006
@@ -0,0 +1,68 @@
+
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005-2006
+ Scientific Computing and Imaging Institute, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Interface/Material.h>
+#include <Interface/Texture.h>
+
+#include <vector>
+
+namespace Manta {
+
+ class MaterialTable : public Material {
+ public:
+ // Constructors.
+ MaterialTable() {};
+ MaterialTable( const Texture<int> *id_texture_, int size ) :
+ id_texture( id_texture ),
+ material_table( size, Entry(0, false) ) { }
+
+ virtual ~MaterialTable();
+
+ // Material interface methods.
+ virtual void preprocess(const PreprocessContext&);
+ virtual void shade(const RenderContext& context, RayPacket& rays) const;
+
+ // Accessors.
+ void setMaterial( int material_id, Material *material, bool owned = true
);
+ Material* getMaterial( int material_id );
+
+ private:
+ // Texture to obtain table entry id's from.
+ Texture<int> *id_texture;
+
+ // Table itself.
+ struct Entry {
+ Entry( Material *m, bool b ) : material( m ), owned( b ) { };
+ Material *material;
+ bool owned;
+ };
+ std::vector<Entry> material_table;
+ };
+};
Added: trunk/Model/Readers/V3C1.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Readers/V3C1.cc Tue Feb 21 23:13:45 2006
@@ -0,0 +1,125 @@
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2006
+ Scientific Computing and Imaging Institute, University of Utah.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Model/Readers/V3C1.h>
+
+#include <Core/Util/Endian.h>
+
+#include <SCIRun/Core/Containers/Array1.h>
+
+#include <string>
+
+using namespace SCIRun;
+using namespace std;
+
+using namespace Manta;
+
+size_t fread_64(void *ptr, size_t size, size_t nitems, FILE *stream);
+
+///////////////////////////////////////////////////////////////////////////////
+// Endian swapping for V3C1 structs.
+template<>
+inline V3C1Triangle endian_swap( const V3C1Triangle &in ) {
+
+ V3C1Triangle out;
+
+ out.vertex[0] = endian_swap( in.vertex[0] );
+ out.vertex[1] = endian_swap( in.vertex[1] );
+ out.vertex[2] = endian_swap( in.vertex[2] );
+ out.color = endian_swap( in.color );
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+//
+void v3c1_load_triangles( Array1<V3C1Triangle> &array, const string &prefix
) {
+
+ // Attempt to open the input file.
+ FILE *file;
+ ((file = fopen( prefix.c_str(), "rb" )) == 0) {
+ throw ErrnoException( "Error opening .v3c1 file.", errno,
+ __FILE__, __LINE__ );
+ }
+
+ // Determine input file size.
+ fseek(file, 0, SEEK_END);
+ size_t file_size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ // Check file size and allocate input buffer.
+ if ((file_size % sizeof( V3C1Triangle )) != 0) {
+ throw InputError( "Error .v3c1 file wrong size." );
+ }
+
+ size_t array_size = file_size / sizeof( V3C1Triangle );
+ array.resize( array_size );
+
+ // Read in the datafile.
+ size_t total_read = fread_64( &array[0], sizeof(V3C1Triangle),
+ array_size, file );
+
+ if (total_read != array_size) {
+ throw InputError( "Did not read expected number of triangles from file."
);
+ }
+
+ // Check endianness and flip if necessary.
+ if (is_big_endian()) {
+
+ for (int i=0;i<array_size;++i) {
+ array[i] = endian_swap( array[i] );
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+void v3c1_load_normals ( Array1<V3C1Normal> &array, const string &prefix
) {
+
+ throw InputError( "Not finished" );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// FREAD 64 FREAD 64 FREAD 64 FREAD 64 FREAD 64 FREAD 64 FREAD 64
FREAD
+///////////////////////////////////////////////////////////////////////////////
+size_t fread_64(void *ptr, size_t size, size_t nitems, FILE *stream)
+{
+ long long chunkSize = 0x7fffffff;
+ long long remaining = size*nitems;
+ while (remaining > 0) {
+ long long toRead = remaining>chunkSize?chunkSize:remaining;
+ long long result;
+ if ((result = fread(ptr, toRead, 1, stream)) != 1) {
+ fprintf(stderr, "read error: %ld != %ld",
+ toRead, result);
+ return 0;
+ }
+ remaining -= toRead;
+ ptr = (char*)ptr + toRead;
+ }
+ return nitems;
+}
Added: trunk/Model/Readers/V3C1.h
==============================================================================
--- (empty file)
+++ trunk/Model/Readers/V3C1.h Tue Feb 21 23:13:45 2006
@@ -0,0 +1,76 @@
+
+
+#ifndef MANTA_MODEL_V3C1__H
+#define MANTA_MODEL_V3C1__H
+
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ */
+
+#include <MantaTypes.h>
+#include <Core/Geometry/VectorT.h>
+#include <SCIRun/Core/Containers/Array1.h>
+
+namespace Manta {
+
+
/////////////////////////////////////////////////////////////////////////////
+ // Binary formats for triangles, normals, and texture coords read from
+ // .v3c1 files.
+
/////////////////////////////////////////////////////////////////////////////
+
+ struct V3C1Triangle {
+ VectorT<float,3> vertex[3]; // 9 floats.
+ Color color; // 3 floats.
+ };
+
+ struct V3C1Normal {
+ VectorT<float,3> normal[3]; // 9 floats.
+
+ VectorT<float,3>& operator[] ( int i ) { return normal[i]; };
+ const VectorT<float,3>& operator[] ( int i ) const { return normal[i];
};
+ };
+
+ struct V3C1TextureCoord {
+ VectorT<float,2> coord[3];
+
+ VectorT<float,2> &operator[] ( int i ) { return coord[i]; };
+ const VectorT<float,2> &operator[] ( int i ) const { return coord[i]; };
+ };
+
+
/////////////////////////////////////////////////////////////////////////////
+ // Loading functions.
+
/////////////////////////////////////////////////////////////////////////////
+
+ // Load data into arrays of corresponding type and correct endianness if
+ // necessary.
+ void v3c1_load_triangles( SCIRun::Array1<V3C1Triangle> &array, const
string &prefix );
+ void v3c1_load_normals ( SCIRun::Array1<V3C1Normal> &array, const
string &prefix );
+
+};
+
+#endif
Modified: trunk/StandAlone/manta.cc
==============================================================================
--- trunk/StandAlone/manta.cc (original)
+++ trunk/StandAlone/manta.cc Tue Feb 21 23:13:45 2006
@@ -70,6 +70,7 @@
using namespace Manta;
using SCIRun::InternalError;
using SCIRun::Time;
+using SCIRun::Thread;
#if HAVE_IEEEFP_H
#include <ieeefp.h>
@@ -121,7 +122,7 @@
cerr << " -renderer S - Use renderer S, valid renderers are:\n";
printList(cerr, rtrt->listRenderers(), 2);
cerr << " -scene S - Render Scene S\n";
- exit(1);
+ Thread::exitAll(1);
}
class BenchHelper {
@@ -355,7 +356,7 @@
if(!ui){
cerr << "Cannot find default user interface:
X, available user interfaces are:\n";
printList(cerr, rtrt->listUserInterfaces());
- exit(1);
+ Thread::exitAll(1);
}
ui->startup();
}
@@ -387,22 +388,21 @@
///////////////////////////////////////////////////////////////////////////
} catch (SCIRun::Exception& e) {
- cerr << "manta.cc: Caught exception: " << e.message() << '\n';
- // if(e.stackTrace())
- // cerr << "Stack trace: " << e.stackTrace() << '\n';
- exit( 1 );
+ cerr << "manta.cc: Caught SCIRun exception: " << e.message() << '\n';
+ Thread::exitAll( 1 );
} catch (std::exception e){
cerr << "manta.cc: Caught std exception: "
<< e.what()
<< '\n';
- exit(1);
+ Thread::exitAll(1);
} catch(...){
cerr << "manta.cc: Caught unknown exception\n";
- exit(1);
+ Thread::exitAll(1);
}
- exit(0);
+
+ Thread::exitAll(0);
}
///////////////////////////////////////////////////////////////////////////////
- [MANTA] r949 - in trunk: Core/Geometry Core/Util Engine/Control Model/Groups Model/Intersections Model/Materials Model/Readers StandAlone, abe, 02/21/2006
Archive powered by MHonArc 2.6.16.