Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r346 - in branches/itanium2: Core Core/Geometry Interface Model/Groups Model/Intersections Model/Primitives SCIRun/Core scenes
- Date: Wed, 25 May 2005 14:03:10 -0600 (MDT)
Author: abe
Date: Wed May 25 14:03:05 2005
New Revision: 346
Removed:
branches/itanium2/Model/Groups/geom.h
branches/itanium2/Model/Groups/raytri.cpp
Modified:
branches/itanium2/Core/CMakeLists.txt
branches/itanium2/Core/Geometry/BBox.h
branches/itanium2/Core/Geometry/PointVector.h
branches/itanium2/Interface/CMakeLists.txt
branches/itanium2/Model/Groups/CMakeLists.txt
branches/itanium2/Model/Groups/kdtree.cc
branches/itanium2/Model/Groups/kdtree.h
branches/itanium2/Model/Groups/varray.h
branches/itanium2/Model/Intersections/CMakeLists.txt
branches/itanium2/Model/Primitives/CMakeLists.txt
branches/itanium2/SCIRun/Core/CMakeLists.txt
branches/itanium2/scenes/0.cc
branches/itanium2/scenes/boeing777.cc
Log:
Moving kdtree integration to the altix... binary file issues
Modified: branches/itanium2/Core/CMakeLists.txt
==============================================================================
--- branches/itanium2/Core/CMakeLists.txt (original)
+++ branches/itanium2/Core/CMakeLists.txt Wed May 25 14:03:05 2005
@@ -1,22 +1,31 @@
SET (CORE_SOURCES)
SET (CORE_SOURCES ${CORE_SOURCES}
+ Color/ColorDB.h
Color/ColorDB.cc)
SET (CORE_SOURCES ${CORE_SOURCES}
+ Geometry/PointVector.h
Geometry/PointVector.cc
)
SET (CORE_SOURCES ${CORE_SOURCES}
+ Exceptions/BadPrimitive.h
Exceptions/BadPrimitive.cc
+ Exceptions/IllegalArgument.h
Exceptions/IllegalArgument.cc
+ Exceptions/UnknownColor.h
Exceptions/UnknownColor.cc
)
SET (CORE_SOURCES ${CORE_SOURCES}
+ Math/MT_RNG.h
Math/MT_RNG.cc
+ Math/Noise.h
Math/Noise.cc)
SET (CORE_SOURCES ${CORE_SOURCES}
+ Util/Args.h
Util/Args.cc)
SET (CORE_SOURCES ${CORE_SOURCES}
- Geometry/AffineTransform.cc
+ Geometry/AffineTransform.h
+ Geometry/AffineTransform.cc
)
ADD_LIBRARY (Manta_Core ${CORE_SOURCES})
Modified: branches/itanium2/Core/Geometry/BBox.h
==============================================================================
--- branches/itanium2/Core/Geometry/BBox.h (original)
+++ branches/itanium2/Core/Geometry/BBox.h Wed May 25 14:03:05 2005
@@ -7,7 +7,9 @@
namespace Manta {
class BBox {
public:
- BBox(const Point& min_, const Point& max_ ) {
+
+ template< typename T >
+ BBox(const PointT<T,3>& min_, const PointT<T,3>& max_ ) {
bounds[0] = min_;
bounds[1] = max_;
}
@@ -22,10 +24,12 @@
return Point(Vector(bounds[1]-bounds[0])*0.5);
}
- void extendByPoint(const Point& p) {
- bounds[0] = Min(bounds[0], p);
- bounds[1] = Max(bounds[1], p);
+ template< typename T >
+ void extendByPoint(const PointT<T,3>& p) {
+ bounds[0] = Min(bounds[0],
Point((Point::ScalarType)p[0],(Point::ScalarType)p[1],(Point::ScalarType)p[2]));
+ bounds[1] = Max(bounds[1],
Point((Point::ScalarType)p[0],(Point::ScalarType)p[1],(Point::ScalarType)p[2]));
}
+
void extendBySphere(const Point& p, Real radius) {
bounds[0] = Min(bounds[0], p-Vector(radius, radius, radius));
bounds[1] = Max(bounds[1], p+Vector(radius, radius, radius));
@@ -53,8 +57,8 @@
inline const Point &operator[] (int i) const { return bounds[i]; }
private:
- BBox(const BBox&);
- BBox& operator=(const BBox&);
+ // BBox(const BBox&);
+ // BBox& operator=(const BBox&);
Point bounds[2];
};
Modified: branches/itanium2/Core/Geometry/PointVector.h
==============================================================================
--- branches/itanium2/Core/Geometry/PointVector.h (original)
+++ branches/itanium2/Core/Geometry/PointVector.h Wed May 25 14:03:05
2005
@@ -18,11 +18,9 @@
VectorT() {
}
VectorT(T x, T y) {
- char unnamed[ Dim == 2 ? 1 : 0 ];
data[0] = x; data[1] = y;
}
VectorT(T x, T y, T z) {
- char unnamed[ Dim == 3 ? 1 : 0 ];
data[0] = x; data[1] = y; data[2] = z;
}
@@ -31,14 +29,17 @@
data[i] = copy[i];
}
- VectorT(const VectorT<T, Dim>& copy) {
+ // Copy from another vector of the same size.
+ template< typename S >
+ VectorT(const VectorT<S, Dim> ©) {
for(int i=0;i<Dim;i++)
- data[i] = copy[i];
+ data[i] = (T)copy[i];
}
- VectorT<T, Dim>& operator=(const VectorT<T, Dim>& copy) {
+ template< typename S >
+ VectorT<T, Dim>& operator=(const VectorT<S, Dim>& copy) {
for(int i=0;i<Dim;i++)
- data[i] = copy.data[i];
+ data[i] = (T)copy[i];
return *this;
}
@@ -49,11 +50,9 @@
return data[0];
}
T y() const {
- char unnamed[ Dim >=2 ? 1 : 0 ];
return data[1];
}
T z() const {
- char unnamed[ Dim >= 3 ? 1 : 0 ];
return data[2];
}
const T &operator[](int i) const {
@@ -230,13 +229,13 @@
data[0] = x; data[1] = y;
}
PointT(T x, T y, T z) {
- char unnamed[ Dim == 3 ? 1 : 0 ];
data[0] = x; data[1] = y; data[2] = z;
}
- PointT(const PointT<T, Dim>& copy) {
+ template< typename S >
+ PointT(const PointT<S, Dim>& copy) {
for(int i=0;i<Dim;i++)
- data[i] = copy.data[i];
+ data[i] = (T)copy[i];
}
explicit PointT( const VectorT<T,Dim> © ) {
@@ -244,9 +243,10 @@
data[i] = copy[i];
}
- PointT<T, Dim>& operator=(const PointT<T, Dim>& copy) {
+ template< typename S >
+ PointT<T, Dim>& operator=(const PointT<S, Dim>& copy) {
for(int i=0;i<Dim;i++)
- data[i] = copy.data[i];
+ data[i] = (T)copy[i];
return *this;
}
@@ -260,7 +260,6 @@
return data[1];
}
T z() const {
- char unnamed[ Dim == 3 ? 1 : 0 ];
return data[2];
}
T operator[](int i) const {
@@ -339,15 +338,22 @@
T data[Dim];
};
- template<typename T, int Dim>
- inline VectorT<T, Dim> operator*(T s, const VectorT<T, Dim>& v)
+ // Two multiplication by a scalar operators.
+ template<typename T, int Dim, typename S >
+ inline VectorT<T, Dim> operator*(S s, const VectorT<T, Dim>& v)
{
VectorT<T, Dim> result;
for(int i=0;i<Dim;i++)
- result[i] = s * v[i];
+ result[i] = s * (S)v[i];
return result;
}
+ template<typename T, int Dim, typename S >
+ inline VectorT<T, Dim> operator*(const VectorT<T, Dim>& v, S s)
+ {
+ return operator*((T)s,v);
+ }
+
template<typename T, int Dim>
inline T Dot(const VectorT<T, Dim>& v1, const VectorT<T, Dim>& v2)
{
Modified: branches/itanium2/Interface/CMakeLists.txt
==============================================================================
--- branches/itanium2/Interface/CMakeLists.txt (original)
+++ branches/itanium2/Interface/CMakeLists.txt Wed May 25 14:03:05 2005
@@ -1,25 +1,46 @@
ADD_LIBRARY(Manta_Interface
+ AmbientLight.h
AmbientLight.cc
+ Background.h
Background.cc
+ Camera.h
Camera.cc
+ IdleMode.h
IdleMode.cc
+ Image.h
Image.cc
+ ImageDisplay.h
ImageDisplay.cc
+ ImageTraverser.h
ImageTraverser.cc
+ Light.h
Light.cc
+ LightSet.h
LightSet.cc
+ LoadBalancer.h
LoadBalancer.cc
+ Material.h
Material.cc
+ Object.h
Object.cc
+ PixelSampler.h
PixelSampler.cc
+ Primitive.h
Primitive.cc
+ Renderer.h
Renderer.cc
+ RTRTInterface.h
RTRTInterface.cc
+ SetupCallback.h
SetupCallback.cc
+ ShadowAlgorithm.h
ShadowAlgorithm.cc
+ TexCoordMapper.h
TexCoordMapper.cc
+ Transaction.h
Transaction.cc
+ UserInterface.h
UserInterface.cc
)
Modified: branches/itanium2/Model/Groups/CMakeLists.txt
==============================================================================
--- branches/itanium2/Model/Groups/CMakeLists.txt (original)
+++ branches/itanium2/Model/Groups/CMakeLists.txt Wed May 25 14:03:05
2005
@@ -1,6 +1,11 @@
SET (Manta_Groups_SRCS
+ Groups/BVH.h
Groups/BVH.cc
+ Groups/Group.h
Groups/Group.cc
+ Groups/kdtree.h
Groups/kdtree.cc
+ Groups/geom.h
+ Groups/varray.h
)
Modified: branches/itanium2/Model/Groups/kdtree.cc
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.cc (original)
+++ branches/itanium2/Model/Groups/kdtree.cc Wed May 25 14:03:05 2005
@@ -1,143 +1,173 @@
+
+#include <iostream>
+
+
#include <stdio.h>
-#include "math/vmath.h"
#include "varray.h"
-#undef SWAP
-#include "geom.h"
#include "kdtree.h"
-#include <Model/Primitives/NullPrimitive.h>
-#include <Model/Intersections/AxisAlignedBox.h>
-#include "raytri.cpp"
+#include <Model/Intersections/AxisAlignedBox.h>
using namespace Manta;
-int LoadTris(char *filename, VArray<Triangle> **tris,
- Vec3f **perTriNormals, Vec3f **perVertNormals,
- Vec3f& min, Vec3f& max)
+using namespace Manta::Kdtree;
+using std::cerr;
+using std::endl;
+
+#if 0
+// From Tomas Akenine-Mˆller's code, included below in this file.
+int intersect_triangle3_edge(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, float *edge2);
+
+#endif
+inline int intersectTriangle3Edge(const Ray &ray, const Triangle &tri,
+
float &t, float &u,
float &v );
+
+int LoadTris(const char *filename,
+ VArray<Triangle> **tris,
+ Vectorf **perTriNormals,
+ Vectorf **perVertNormals,
+ BBox &bounds )
{
- int i, j, n;
FILE *f;
- float len;
- perVertNormals=perVertNormals;
+ // perVertNormals = perVertNormals;
+ // Open the input file.
if ((f=fopen(filename, "r")) == NULL) {
fprintf(stderr, "Cannot open file: %s\n", filename);
return 0;
}
+ // Allocate store for the triangles.
*tris = new VArray<Triangle>;
- min[0] = min[1] = min[2] = 1e20;
- max[0] = max[1] = max[2] = -1e20;
+ int line = 0;
+ char line_buffer[128];
+
+ // Read in the file.
while (! feof(f)) {
+
+ // Read in a triangle.
Triangle tri;
- bool error=false;
- char colorString[32];
- unsigned int color;
- for (j=0; j<3; j++) {
- float * v = (float*)&tri[j];
- if (fscanf(f, "%f %f %f", v, v+1, v+2) != 3) {
- error = 1;
- break;
- }
- }
-
- if (! error && fscanf(f, "%s", colorString) != 1) {
- error = 1;
- }
-
- if (error) {
- fprintf(stderr, "Error in file\n");
+ // bool error=false;
+ // char colorString[32];
+ // unsigned int color;
+
+ // Read in the current line.
+ fgets( line_buffer, 127, f );
+
+ // Parse the triangle description from the file.
+ int num_parsed = sscanf( line_buffer,
+
"%f %f %f %f %f %f %f %f %f 0x%X",
+ &tri[0][1],
&tri[0][1], &tri[0][2],
+ &tri[1][1],
&tri[1][1], &tri[1][2],
+ &tri[2][1],
&tri[2][1], &tri[2][2],
+ &tri.payload
);
+ if (num_parsed != 10) {
+ cerr << "Only parsed " << num_parsed << " components
for line "
+ << line << " in file "
+ << filename << endl;
break;
}
- sscanf(colorString+2, "%X", &color);
- *(unsigned int*)&tri.payload = color;
-
+
+ ++line;
+
+#if 0
// Get rid of degenerate polygons
if ( SAME_TOL_VEC3V(tri[0], tri[1], 1e-5) ||
- SAME_TOL_VEC3V(tri[1], tri[2], 1e-5) ||
- SAME_TOL_VEC3V(tri[2], tri[0], 1e-5) ) {
+ SAME_TOL_VEC3V(tri[1], tri[2], 1e-5) ||
+ SAME_TOL_VEC3V(tri[2], tri[0], 1e-5) ) {
+
fprintf(stderr, "Degenerated triangle.\n");
continue;
}
+#endif
// Update the bounding box of the whole scene
- for (j=0; j<3; j++) {
- float * v = (float*)&tri[j];
- if (min[0] > v[0]) min[0] = v[0];
- else if (max[0] < v[0]) max[0] = v[0];
- if (min[1] > v[1]) min[1] = v[1];
- else if (max[1] < v[1]) max[1] = v[1];
- if (min[2] > v[2]) min[2] = v[2];
- else if (max[2] < v[2]) max[2] = v[2];
- }
-
- SUB_VEC3V(tri.edge1, tri.v1, tri.v0);
- SUB_VEC3V(tri.edge2, tri.v2, tri.v0);
+ bounds.extendByPoint( tri[0] );
+ bounds.extendByPoint( tri[1] );
+ bounds.extendByPoint( tri[2] );
+
+ // Compute the triangle edges.
+ tri.edge1 = tri[1] - tri[0];
+ tri.edge2 = tri[2] - tri[0];
+
+ // Add the triangle to the list.
(**tris).append(tri);
}
- fprintf(stderr, "%d triangles loaded\n",(**tris).getLen());
-
- n = (**tris).getLen();
+
+ // Determine the total number of triangles.
+ int n = (**tris).getLen();
+ fprintf(stderr, "%d triangles loaded\n", n );
+
+ // Check to see if per face normals are needed.
if (perTriNormals) { // if per-triangle normals are required
- *perTriNormals = new Vec3f [n];
- for (i=0; i<n; i++) {
- Vec3f v01, v02;
- SUB_VEC3V(v01, (**tris)[i][1], (**tris)[i][0]);
- SUB_VEC3V(v02, (**tris)[i][2], (**tris)[i][0]);
- CROSS_VEC3V((*perTriNormals)[i], v01, v02);
- UNIT_VEC3V((*perTriNormals)[i], (*perTriNormals)[i],
len);
+ *perTriNormals = new Vectorf[n];
+ for (int i=0; i<n; i++) {
+ Vectorf v01, v02;
+ v01 = (**tris)[i][1] - (**tris)[i][0];
+ v02 = (**tris)[i][2] - (**tris)[i][0];
+
+ (*perTriNormals)[i] = Cross(v01, v02 ).normal();
}
}
+ // Check to see if per vertex normals are needed.
if (perVertNormals) { // if per-vertex normals are required
- *perVertNormals = new Vec3f [3*n];
- for (i=0; i<n; i++) {
- Vec3f v01, v02;
- SUB_VEC3V(v01, (**tris)[i][1], (**tris)[i][0]);
- SUB_VEC3V(v02, (**tris)[i][2], (**tris)[i][0]);
+ *perVertNormals = new Vectorf[3*n];
+ for (int i=0; i<n; i++) {
+ Vectorf v01, v02;
+ v01 = (**tris)[i][1] - (**tris)[i][0];
+ v02 = (**tris)[i][2] - (**tris)[i][0];
int offset = i*3;
- CROSS_VEC3V((*perVertNormals)[offset], v01, v02);
- UNIT_VEC3V((*perVertNormals)[offset],
(*perVertNormals)[offset], len);
- (*perVertNormals)[offset+1] =
(*perVertNormals)[offset+2] =
- (*perVertNormals)[offset];
+
+ // Hansong: these aren't actually per vertex normals??
+ (*perVertNormals)[offset] = Cross( v01, v02
).normal();
+ (*perVertNormals)[offset+1] =
(*perVertNormals)[offset+2] = (*perVertNormals)[offset];
}
}
- /*
- for (i=0; i<n; i++) {
- if (feof(f)) {
- delete perVertNormals;
- perVertNormals = NULL;
- break;
- }
- for (j=0; j<3; j++) {
- float * v = (*perVertNormals)[i][j];
- fscanf(f, "%f %f %f", v, v+1, v+2);
- }
- }
- */
-
+ // Close the file.
if (fclose(f))
fprintf(stderr, "Error closing %s\n", filename);
return 1;
}
-int
-KDTree::load(char *fn)
-{
- LoadTris(fn, &tris, NULL, &normals,
- bbox.min, bbox.max);
+// This structure is only used to read from the kd tree file.
+struct AABox3f {
+ Pointf min, max;
+};
+
+float endianness_swap( float in ) {
+ float out;
+ char *ci = (char *)∈
+ char *co = (char *)&out;
+ co[3] = ci[0];
+ co[2] = ci[1];
+ co[1] = ci[2];
+ co[0] = ci[3];
+
+ return out;
+}
+
+int KDTree::load( const char *fn) {
+
+ // Call a helper function to load the triangles.
+ LoadTris(fn, &tris, NULL, &normals, bbox );
+
/////////////////////////////////////////////////////////////////////////////
+ // Load the kd tree.
char filename[512];
strcpy(filename, fn);
strcat(filename, ".kd"); // the kd-tree file
FILE *f = fopen(filename, "rb");
if (! f) {
fprintf(stderr, "Error: cannot open %s for loading\n",
filename);
- // return 0;
}
fseek(f, 0, SEEK_END);
@@ -149,17 +179,32 @@
if (nread != fileSize) {
fprintf(stderr, "error reading file %s (size: %lld read:
%lld)\n",
filename, fileSize, nread);
- // return 0;
}
fclose(f);
+#if 0
+ // Swap the endianness of the input file.
+ long long num_quads = fileSize / 4;
+ float *quad_buffer = (float *)buffer;
+
+ for (long long i=0;i<num_quads;++i) {
+ quad_buffer[i] = endianness_swap(quad_buffer[i]);
+ }
+#endif
+ // Specify the root node loaded from the file.
rootNode = (KDTreeNode*)buffer;
- // get the bounding box
- bbox = *(AABox3f*)((char*)buffer + fileSize - sizeof(AABox3f));
- bbox_ms = AABox3f_ms(bbox);
-
-
- // load the index file
+
+ // Get the bounding box from the file.
+ AABox3f bboxf = *(AABox3f*)((char*)buffer + fileSize -
sizeof(AABox3f));
+
+ // bboxf.min[0] = endianness_swap( bboxf.min[0] );
+ // bboxf.min[1] = endianness_swap( bboxf.min[1] );
+ // bboxf.min[2] = endianness_swap( bboxf.min[2] );
+
+ bbox = BBox( bboxf.min, bboxf.max );
+
+
/////////////////////////////////////////////////////////////////////////////
+ // Load the index file
strcpy(filename, fn);
strcat(filename, ".idx"); // the kd-tree file
f = fopen(filename, "rb");
@@ -192,11 +237,9 @@
-int
-KDTree::intersectTriangles(const Ray3f* ray, /*const RayInternal*
rayInternal, */
- unsigned int listBegin, int listSize, float maxDist, void
*userData) const
+int KDTree::intersectTriangles(const Ray* ray, unsigned int listBegin, int
listSize, float maxDist, void *userData) const
{
- int i,j;
+ int i;
RayTriIntersectUserData *ud = (RayTriIntersectUserData*)userData;
float nearest_u, nearest_v;
int nearest_tri=-1;
@@ -207,9 +250,8 @@
int triIdx = triIndices->get(i);
Triangle &tri = tris->get(triIdx);
float t, u, v;
- if (intersect_triangle3_edge(&ray->pos[0], &ray->dir[0],
- &tri.v0[0], &tri.v1[0], &tri.v2[0],
- &t, &u, &v, &tri.edge1[0],
&tri.edge2[0])) {
+
+ if (intersectTriangle3Edge( *ray, tri, t, u, v )) {
if (t < maxDist) {
maxDist = t;
nearest_u= u;
@@ -229,46 +271,59 @@
return 0;
}
-
-typedef struct {
- KDTreeNode* node; //8 bytes
- float t; // 4 bytes
+// Traversal Stack Entry.
+struct TravStackEntry {
+ KDTreeNode* node; //8 bytes
+ float t; // 4 bytes
// float point[3]; // 4*3=12 bytes
- int prev; // 4 bytes
-} TravStackEntry;
+ int prev; // 4 bytes
+};
+///////////////////////////////////////////////////////////////////////////////
+// This is the Manta interface method.
+///////////////////////////////////////////////////////////////////////////////
void KDTree::intersect(const RenderContext& context, RayPacket& rays) const
{
rays.computeInverseDirections();
+
RayTriIntersectUserData isectData;
- NullPrimitive nullPrim;
for(int i=0;i<rays.getSize();i++) {
+
RayPacket::Element& e = rays.get(i);
Real minDist=0, maxDist=0;
- if (! Intersection::intersect_box(bbox,
- minDist, maxDist, e.ray,
- e.sign_mask, e.inverseDirection))
- continue;
-
- Ray3f ray;
- COPY_VEC3V(ray.pos, e.ray.origin());
- COPY_VEC3V(ray.dir, e.ray.direction());
- isectData.rayHitTriIndex = 0;
- _intersect(&ray, e, &isectData,
- minDist, maxDist);
- if (isectData.rayHitTriIndex >= 0) {
- COPY_VEC3V(e.normal,
normals[isectData.rayHitTriIndex*3]);
- e.hitInfo.hit(isectData.rayHit.t, lambMat, &nullPrim,
NULL);
- e.hitInfo.scratchpad<int>() =
tris->get(isectData.rayHitTriIndex).payload;
+
+ // Intersect the ray with the bounding box for the group.
+ if (Intersection::intersectAaBox( bbox,
+
minDist,
maxDist, e.ray,
+
e.signMask,
+
e.inverseDirection )) {
+
+ // Send the ray to the _intersect function.
+ isectData.rayHitTriIndex = 0;
+ _intersect( &e.ray, e, &isectData, (float)minDist,
(float)maxDist);
+
+ // Check to see if the ray hit any triangles.
+ if (isectData.rayHitTriIndex >= 0) {
+
+ e.normal =
normals[isectData.rayHitTriIndex*3]; // Is this safe??? What if the hit()
function fails?
+
+ // Check against the hit record.
+ e.hitInfo.hit(isectData.rayHit.t, lambMat,
NULL, NULL);
+ e.hitInfo.scratchpad<int>() =
tris->get(isectData.rayHitTriIndex).payload;
+ }
}
}
}
+///////////////////////////////////////////////////////////////////////////////
+// This function performs the KD-Tree Traversal.
+///////////////////////////////////////////////////////////////////////////////
void KDTree::_intersect(
- const Ray3f* ray, RayPacket::Element &e, void *userData,
+ const Ray* ray, RayPacket::Element &e, void *userData,
float minDist, float maxDist) const
{
+
TravStackEntry travStack[128];
KDTreeNode *nearNode, *farNode;
float split;
@@ -293,10 +348,10 @@
axis = nearNode->axis();
split = nearNode->split();
- float entryPos_coord_on_axis = ray->pos[axis] +
- travStack[entryPos].t*ray->dir[axis];
- float exitPos_coord_on_axis = ray->pos[axis] +
- travStack[exitPos].t*ray->dir[axis];
+ float entryPos_coord_on_axis = ray->origin()[axis] +
+ travStack[entryPos].t*ray->direction()[axis];
+ float exitPos_coord_on_axis = ray->origin()[axis] +
+ travStack[exitPos].t*ray->direction()[axis];
if (entryPos_coord_on_axis <= split) {
if (exitPos_coord_on_axis <= split) {
@@ -320,13 +375,15 @@
travStack[exitPos].node = farNode;
- travStack[exitPos].t = (split - ray->pos[axis])*
+ travStack[exitPos].t = (split - ray->origin()[axis])*
e.inverseDirection[axis];
travStack[exitPos].prev = tmp;
}
if (nearNode) {
+
+ // Intersect the ray with a list of triangles.
foundIntersection =
intersectTriangles(ray,
nearNode->listBegin(),
@@ -342,3 +399,477 @@
}
}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+/********************************************************/
+/* AABB-triangle overlap test code */
+/* by Tomas Akenine-Mˆller */
+/* 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! */
+/********************************************************/
+#if 0
+
+#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];
+
+/* the original jgt code */
+inline int intersect_triangle(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], 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);
+
+ if (det > -EPSILON && det < EPSILON)
+ return 0;
+ inv_det = 1.0f/ det;
+
+ /* calculate distance from vert0 to ray origin */
+ SUB(tvec, orig, vert0);
+
+ /* calculate U parameter and test bounds */
+ *u = DOT(tvec, pvec) * inv_det;
+ if (*u < 0.0f || *u > 1.0)
+ return 0;
+
+ /* prepare to test V parameter */
+ CROSS(qvec, tvec, edge1);
+
+ /* calculate V parameter and test bounds */
+ *v = DOT(dir, qvec) * inv_det;
+ if (*v < 0.0f || *u + *v > 1.0)
+ return 0;
+
+ /* calculate t, ray intersects triangle */
+ *t = DOT(edge2, qvec) * inv_det;
+
+ return 1;
+}
+
+
+/* code rewritten to do tests on the sign of the determinant */
+/* the division is at the end in the code */
+inline int intersect_triangle1(float orig[3], float dir[3],
+
float vert0[3], float vert1[3],
float vert2[3],
+
float *t, float *u, float *v)
+{
+ float edge1[3], edge2[3], 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);
+
+ if (det > EPSILON)
+ {
+ /* calculate distance from vert0 to ray origin */
+ SUB(tvec, orig, vert0);
+
+ /* calculate U parameter and test bounds */
+ *u = DOT(tvec, pvec);
+ if (*u < 0.0f || *u > det)
+ return 0;
+
+ /* prepare to test V parameter */
+ CROSS(qvec, tvec, edge1);
+
+ /* calculate V parameter and test bounds */
+ *v = DOT(dir, qvec);
+ if (*v < 0.0f || *u + *v > det)
+ return 0;
+
+ }
+ else if(det < -EPSILON)
+ {
+ /* calculate distance from vert0 to ray origin */
+ SUB(tvec, orig, vert0);
+
+ /* calculate U parameter and test bounds */
+ *u = DOT(tvec, pvec);
+ /* printf("*u=%f\n",(float)*u); */
+ /* printf("det=%f\n",det); */
+ if (*u > 0.0f || *u < det)
+ return 0;
+
+ /* prepare to test V parameter */
+ CROSS(qvec, tvec, edge1);
+
+ /* calculate V parameter and test bounds */
+ *v = DOT(dir, qvec) ;
+ if (*v > 0.0f || *u + *v < det)
+ return 0;
+ }
+ else return 0; /* ray is parallell to the plane of the triangle */
+
+
+ inv_det = 1.0f/ det;
+
+ /* calculate t, ray intersects triangle */
+ *t = DOT(edge2, qvec) * inv_det;
+ (*u) *= inv_det;
+ (*v) *= inv_det;
+
+ return 1;
+}
+
+/* code rewritten to do tests on the sign of the determinant */
+/* the division is before the test of the sign of the det */
+inline int intersect_triangle2(float orig[3], float dir[3],
+
float vert0[3], float vert1[3],
float vert2[3],
+
float *t, float *u, float *v)
+{
+ float edge1[3], edge2[3], 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;
+
+ if (det > EPSILON)
+ {
+ /* calculate U parameter and test bounds */
+ *u = DOT(tvec, pvec);
+ if (*u < 0.0f || *u > det)
+ return 0;
+
+ /* prepare to test V parameter */
+ CROSS(qvec, tvec, edge1);
+
+ /* calculate V parameter and test bounds */
+ *v = DOT(dir, qvec);
+ if (*v < 0.0f || *u + *v > det)
+ return 0;
+
+ }
+ else if(det < -EPSILON)
+ {
+ /* calculate U parameter and test bounds */
+ *u = DOT(tvec, pvec);
+ if (*u > 0.0f || *u < det)
+ return 0;
+
+ /* prepare to test V parameter */
+ CROSS(qvec, tvec, edge1);
+
+ /* calculate V parameter and test bounds */
+ *v = DOT(dir, qvec) ;
+ if (*v > 0.0f || *u + *v < det)
+ return 0;
+ }
+ else return 0; /* ray is parallell to the plane of the triangle */
+
+ /* calculate t, ray intersects triangle */
+ *t = DOT(edge2, qvec) * inv_det;
+ (*u) *= inv_det;
+ (*v) *= inv_det;
+
+ return 1;
+}
+
+/* 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], const float vert1[3], const float vert2[3],
+
float *t,
float *u, float *v,
+
float
*edge1, 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;
+}
+#endif
+
+inline int intersectTriangle3Edge(const Ray &ray, const Triangle &tri,
+
float &t, float &u,
float &v )
+{
+ // float edge1[3], edge2[3];
+ Vector tvec, pvec, qvec;
+ Real det,inv_det;
+
+ /* begin calculating determinant - also used to calculate U parameter
*/
+ pvec = Cross( ray.direction(), Vector(tri.edge2) );
+
+ // CROSS(pvec, dir, edge2);
+
+ /* if determinant is near zero, ray lies in plane of triangle */
+ // det = DOT(edge1, pvec);
+ det = Dot( Vector(tri.edge1), pvec );
+
+ /* calculate distance from vert0 to ray origin */
+ // SUB(tvec, orig, vert0);
+ tvec = ray.origin() - tri[0];
+ inv_det = 1.0/ det;
+
+ qvec = Cross( tvec, Vector(tri.edge1) );
+ // CROSS(qvec, tvec, edge1);
+
+ /* calculate U parameter */
+ // float uu = DOT(tvec, pvec);
+ // float vv;
+ Real uu = Dot( tvec, pvec );
+ Real vv;
+
+ if (det > 1e-5)
+ {
+ if (uu < 0.0 || uu > det)
+ return 0;
+
+ /* calculate V parameter and test bounds */
+ vv = Dot( ray.direction(), qvec );
+
+ if (vv < 0.0 || uu + vv > det)
+ return 0;
+
+ }
+ else if(det < -1e-5)
+ {
+ if (uu > 0.0 || uu < det)
+ return 0;
+
+ /* calculate V parameter and test bounds */
+ vv = Dot(ray.direction(), qvec) ;
+ if (vv > 0.0f || uu + vv < det)
+ return 0;
+ }
+ else return 0; /* ray is parallell to the plane of the triangle */
+
+ t = Dot( Vector(tri.edge2), qvec ) * inv_det;
+ u = uu * inv_det;
+ v = vv * inv_det;
+
+ return 1;
+}
+#if 0
+inline void rays_intersect_triangle3(const float orig[3], const float *dir,
+
int nRays,
+
float
vert0[3], float vert1[3], float vert2[3],
+
int
hits[], float t[], float u[], float v[])
+{
+ float edge1[3], edge2[3], 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);
+
+ /* calculate distance from vert0 to ray origin */
+ SUB(tvec, orig, vert0);
+
+ CROSS(qvec, tvec, edge1);
+
+ float uu, vv;
+ for (int i=0; i<nRays; i++, dir+=3) {
+ /* 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);
+ //fprintf(stderr, "dir:%f %f %f; det: %f\n", dir[0], dir[1],
dir[2], det);
+
+ /* calculate distance from vert0 to ray origin */
+ // SUB(tvec, orig, vert0);
+ inv_det = 1.0f/ det;
+
+ // CROSS(qvec, tvec, edge1);
+
+ /* calculate U parameter and test bounds */
+ uu = DOT(tvec, pvec);
+ if (det > EPSILON) {
+ if (uu < 0.0f || uu > det) {
+ hits[i] = 0;
+ continue;
+ }
+
+ /* calculate V parameter and test bounds */
+ vv = DOT(dir, qvec);
+ if (vv < 0.0f || uu + vv > det) {
+ hits[i] = 0;
+ continue;
+ }
+ }
+ else if(det < -EPSILON)
+ {
+ if (uu > 0.0f || uu < det) {
+ hits[i] = 0;
+ continue;
+ }
+
+ /* calculate V parameter and test bounds */
+ vv = DOT(dir, qvec) ;
+ if (vv > 0.0f || uu + vv < det) {
+ hits[i] = 0;
+ continue;
+ }
+ } else {
+ hits[i] = 0;
+ continue;
+ }
+
+ t[i] = DOT(edge2, qvec) * inv_det;
+ u[i] = uu*inv_det;
+ v[i] = vv*inv_det;
+ hits[i] = 1;
+ }
+
+}
+#endif
+
+
Modified: branches/itanium2/Model/Groups/kdtree.h
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.h (original)
+++ branches/itanium2/Model/Groups/kdtree.h Wed May 25 14:03:05 2005
@@ -3,6 +3,7 @@
#include <Model/Groups/Group.h>
#include <Core/Geometry/PointVector.h>
+#include <Core/Geometry/BBox.h>
#include <Interface/RayPacket.h>
#include <Model/Materials/LambertianAlt.h>
@@ -14,67 +15,184 @@
#define KDNODE_CHILD_MASK 0x0030
#include "varray.h"
-#include "geom.h"
-#include "math/vmath.h"
namespace Manta {
-struct KDTreeInternalNode {
- unsigned char flags;
- unsigned int left;
- float split;
-};
-
-struct KDTreeLeafNode {
- unsigned char flags;
- unsigned int listBegin;
- unsigned int listLen;
-};
-
-union KDTreeNode {
- KDTreeInternalNode internal;
- KDTreeLeafNode leaf;
-
- bool hasLeftChild() { return internal.flags & KDNODE_LEFT_CHILD_MASK;
}
- bool hasRightChild() { return internal.flags &
KDNODE_RIGHT_CHILD_MASK; }
- KDTreeNode* left() { return hasLeftChild()?this+internal.left : NULL;
}
- KDTreeNode* right() { return hasRightChild()?
- (hasLeftChild()?this+internal.left+1:this+internal.left) : 0;
}
- float split() { return internal.split; }
- bool isInternal() { return internal.flags & KDNODE_INTERNAL_MASK; }
- unsigned int axis() { return internal.flags & KDNODE_AXIS_MASK; }
-
- unsigned int listBegin() { return leaf.listBegin; }
- unsigned int listSize() { return leaf.listLen; }
-
-
-};
-
-typedef struct {
- int rayHitTriIndex;
- RayHit_Triangle rayHit;
- float eyeToHitDist2;
-} RayTriIntersectUserData;
-
-class KDTree : public Group {
- AABox3f bbox;
- AABox3f_ms bbox_ms;
- KDTreeNode *rootNode;
- VArray<int> *triIndices;
- VArray<Triangle> *tris;
- Vec3f *normals;
- LambertianAlt *lambMat;
- public:
- int load(char *fn);
-
- int intersectTriangles(const Ray3f* ray,
- unsigned int listBegin, int listSize, float maxDist, void
*userData) const;
-
- void intersect(const RenderContext& context, RayPacket& rays) const;
- void _intersect(const Ray3f* ray, RayPacket::Element &e, void
*userData,
- float _minDist=-1, float _maxDist=-1) const;
-};
-
+ namespace Kdtree {
+
+ typedef VectorT<float,3> Vectorf;
+ typedef PointT <float,3> Pointf;
+
+
///////////////////////////////////////////////////////////////////////////
+ // TRIANGLE TRIANGLE TRIANGLE TRIANGLE TRIANGLE TRIANGLE
TRIANGLE TR
+
///////////////////////////////////////////////////////////////////////////
+ class Triangle/*: public Geometry*/ {
+ public:
+ Pointf v[3]; // 3*3 floats = 9*4 bytes = 36
bytes
+ int payload; // 4 bytes; so far 36+4=40 bytes
+ Vectorf edge1, edge2; // 2*3 floats = 6*4 bytes = 24
bytes
+
// the above are exactly 64 bytes
+
+ Triangle()/* : Geometry()*/ { }
+
+ Triangle(const float *tri, int p=0) {
+ v[0] = *(Pointf*)tri; v[1] =
*(Pointf*)(tri+3); v[2] = *(Pointf*)(tri+6);
+ payload = p;
+ }
+ Triangle(const Pointf *v_, int p=0) {
+ v[0] = v_[0]; v[1] = v_[1]; v[2] = v_[2];
+ payload = p;
+ }
+ Triangle(const Pointf &v0_, const Pointf &v1_, const
Pointf &v2_, int p=0) {
+ v[0] = v0_; v[1] = v1_; v[2] = v2_;
+ payload = p;
+ }
+
+ // Access an individual vertex.
+ Pointf &operator[] (int i) { return v[i]; }
+ const Pointf &operator[] (int i) const { return v[i];
}
+
+ void getBound(BBox &bounds_) {
+ bounds_.extendByPoint( v[0] );
+ bounds_.extendByPoint( v[1] );
+ bounds_.extendByPoint( v[2] );
+ }
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+ // PACKED TRIANGLES PACKED TRIANGLES PACKED TRIANGLES
PACKED TRIANGLES
+
///////////////////////////////////////////////////////////////////////////
+ class PackedTriangles {
+ VArray<Pointf> *_v0;
+ VArray<Pointf> *_v1;
+ VArray<Pointf> *_v2;
+ VArray<int> *_payload;
+ public:
+ void pack(VArray<Triangle> *tris);
+ Pointf& getV0(int i) { return _v0->_get(i); }
+ Pointf& getV1(int i) { return _v1->_get(i); }
+ Pointf& getV2(int i) { return _v2->_get(i); }
+ int& getPayload(int i) { return _payload->_get(i);
}
+ };
+
+
+
///////////////////////////////////////////////////////////////////////////
+ // KDTREE INTERNAL NODE
+
///////////////////////////////////////////////////////////////////////////
+ struct KDTreeInternalNode {
+ unsigned char flags;
+ unsigned int left;
+ float split;
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+ // KDTREE LEAF NODE
+
///////////////////////////////////////////////////////////////////////////
+ struct KDTreeLeafNode {
+ unsigned char flags;
+ unsigned int listBegin;
+ unsigned int listLen;
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+ // KDTREE NODE
+
///////////////////////////////////////////////////////////////////////////
+ union KDTreeNode {
+ KDTreeInternalNode internal;
+ KDTreeLeafNode leaf;
+
+ bool hasLeftChild() { return internal.flags &
KDNODE_LEFT_CHILD_MASK; }
+ bool hasRightChild() { return internal.flags &
KDNODE_RIGHT_CHILD_MASK; }
+ KDTreeNode* left() { return
hasLeftChild()?this+internal.left : NULL; }
+ KDTreeNode* right() { return hasRightChild()?
+
(hasLeftChild()?this+internal.left+1:this+internal.left) : 0; }
+ float split() { return internal.split; }
+ bool isInternal() { return internal.flags &
KDNODE_INTERNAL_MASK; }
+ unsigned int axis() { return internal.flags &
KDNODE_AXIS_MASK; }
+
+ unsigned int listBegin() { return leaf.listBegin; }
+ unsigned int listSize() { return leaf.listLen; }
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+ // RAY HIT TRIANGLE
+
///////////////////////////////////////////////////////////////////////////
+ class RayHit_Triangle {
+ public:
+
+ Real t, u, v;
+
+ RayHit_Triangle() {
+ }
+
+ RayHit_Triangle(Real tt, Real uu, Real vv) {
+ t = tt; u = uu; v = vv;
+ }
+ void computeHitPoint(Point &hitP, const Point &v0,
const Point &v1, const Point &v2) {
+
+ hitP = Point( Vector(v0)*((Real)1.0 - u - v)
+
+
Vector(v1)*u +
+
Vector(v2)*v );
+ }
+
+ Real computeDistance2(const Ray &ray, const Point
&v0, const Point &v1, const Point &v2) {
+ Point hitP;
+ computeHitPoint( hitP, v0, v1, v2 );
+
+ Vector distance = (hitP - ray.origin());
+ return Dot(distance,distance);
+ }
+
+ Real computeDistance2(const Point &point, Point &v0,
const Point &v1, const Point &v2) {
+ Point hitP;
+ computeHitPoint(hitP, v0, v1, v2);
+
+ Vector distance = (hitP - point);
+ return Dot(distance,distance);
+ }
+ };
+
+
+
///////////////////////////////////////////////////////////////////////////
+ // RAY TRIANGLE INTERSECT USER DATA
+
///////////////////////////////////////////////////////////////////////////
+ struct RayTriIntersectUserData {
+ int rayHitTriIndex;
+ RayHit_Triangle rayHit;
+ float eyeToHitDist2;
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////////////
+ // KDTREE CLASS PROPER
+
///////////////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////////////
+ class KDTree : public Group {
+ BBox bbox;
+
+ KDTreeNode *rootNode;
+
+ VArray<int> *triIndices;
+ VArray<Triangle> *tris;
+ Vectorf *normals;
+
+ LambertianAlt *lambMat;
+
+ public:
+
+ // This function is called to load the data.
+ int load(const char *fn);
+
+ // This method intersects a list of triangles with
the ray.
+ int intersectTriangles(const Ray* ray, unsigned int
listBegin, int listSize, float maxDist, void *userData) const;
+
+ // This method is called by manta to intersect a ray
packet with the tree contents.
+ void intersect(const RenderContext& context,
RayPacket& rays) const;
+
+ // This method is called by the above method with a
hansong ray.
+ void _intersect(const Ray* ray, RayPacket::Element
&e, void *userData, float _minDist=-1, float _maxDist=-1) const;
+ };
+ }
}
Modified: branches/itanium2/Model/Groups/varray.h
==============================================================================
--- branches/itanium2/Model/Groups/varray.h (original)
+++ branches/itanium2/Model/Groups/varray.h Wed May 25 14:03:05 2005
@@ -11,7 +11,8 @@
#define __VARRAY_H__
-#include "alloc.h"
+// #include "alloc.h"
+#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
Modified: branches/itanium2/Model/Intersections/CMakeLists.txt
==============================================================================
--- branches/itanium2/Model/Intersections/CMakeLists.txt (original)
+++ branches/itanium2/Model/Intersections/CMakeLists.txt Wed May 25
14:03:05 2005
@@ -1,3 +1,4 @@
SET(Manta_Intersections_SRCS
+ Intersections/AxisAlignedBox.h
# Intersections/AxisAlignedBox.cc
)
Modified: branches/itanium2/Model/Primitives/CMakeLists.txt
==============================================================================
--- branches/itanium2/Model/Primitives/CMakeLists.txt (original)
+++ branches/itanium2/Model/Primitives/CMakeLists.txt Wed May 25 14:03:05
2005
@@ -1,6 +1,6 @@
SET (Manta_Primitives_SRCS
- Primitives/Parallelogram.cc
+ Primitives/Parallelogram.cc
Primitives/PrimitiveCommon.cc
Primitives/Sphere.cc
Primitives/SuperEllipsoid.cc
@@ -15,11 +15,25 @@
Primitives/Heightfield.cc
)
-# Should be include known broken objects?
-IF(BUILD_BROKEN)
+SET(INCLUDE_DOT_H TRUE)
+
+# Should header files be included on the build line?
+# (for example if the project is built with xcode)
+IF(INCLUDE_DOT_H)
SET (Manta_Primitives_SRCS
- Manta_Primitives_SRCS
- Primitives/Cube.cc
- Primitives/Cone.cc
+ ${Manta_Primitives_SRCS}
+ Primitives/Parallelogram.h
+ Primitives/PrimitiveCommon.h
+ Primitives/Sphere.h
+ Primitives/SuperEllipsoid.h
+ Primitives/Cube.h
+ Primitives/Cone.h
+ Primitives/Triangle.h
+ Primitives/HeavyTriangle.h
+ Primitives/TexTriangle.h
+ Primitives/VertexColoredTriangle.h
+ Primitives/Disk.h
+ Primitives/Hemisphere.h
+ Primitives/Heightfield.h
)
-ENDIF(BUILD_BROKEN)
+ENDIF(INCLUDE_DOT_H)
Modified: branches/itanium2/SCIRun/Core/CMakeLists.txt
==============================================================================
--- branches/itanium2/SCIRun/Core/CMakeLists.txt (original)
+++ branches/itanium2/SCIRun/Core/CMakeLists.txt Wed May 25 14:03:05
2005
@@ -1,4 +1,6 @@
+SET (CMAKE_VERBOSE_MAKEFILE TRUE)
+
SET (SCIRUN_SOURCES)
SET (SCIRUN_SOURCES ${SCIRUN_SOURCES}
Containers/StringUtil.cc
Modified: branches/itanium2/scenes/0.cc
==============================================================================
--- branches/itanium2/scenes/0.cc (original)
+++ branches/itanium2/scenes/0.cc Wed May 25 14:03:05 2005
@@ -8,12 +8,15 @@
#include <Interface/Scene.h>
#include <Model/AmbientLights/ArcAmbient.h>
#include <Model/Backgrounds/LinearBackground.h>
+#include <Model/Backgrounds/ConstantBackground.h>
#include <Model/Groups/Group.h>
#include <Model/Lights/PointLight.h>
#include <Model/Materials/Lambertian.h>
#include <Model/Materials/MetalMaterial.h>
+#include <Model/Materials/NormalMaterial.h>
#include <Model/Primitives/Parallelogram.h>
#include <Model/Primitives/Sphere.h>
+#include <Model/Primitives/Cube.h>
#include <Model/Textures/CheckerTexture.h>
#include <Core/Geometry/AffineTransform.h>
#include <Core/Util/NotFinished.h>
@@ -89,11 +92,15 @@
static void make_box(Group* group, Material* matl,
const Point& corner, const Vector& x, const Vector& y,
const Vector& z)
{
- group->add(new Parallelogram(matl, corner, x*2, z*2));
- group->add(new Parallelogram(matl, corner+y*2, z*2, x*2));
- group->add(new Parallelogram(matl, corner, y*2, z*2));
- group->add(new Parallelogram(matl, corner+x*2, z*2, y*2));
- group->add(new Parallelogram(matl, corner+z*2, x*2, y*2));
+ // group->add(new Parallelogram(matl, corner, x*2, z*2));
+ // group->add(new Parallelogram(matl, corner+y*2, z*2, x*2));
+ // group->add(new Parallelogram(matl, corner, y*2, z*2));
+ // group->add(new Parallelogram(matl, corner+x*2, z*2, y*2));
+ // group->add(new Parallelogram(matl, corner+z*2, x*2, y*2));
+
+ Point corner1 = corner + x + y + z;
+
+ group->add( new Cube( matl, corner, corner1 ) );
}
static void make_obj(Group* world, int size)
@@ -101,20 +108,20 @@
Vector objset[9];
create_dirs(objset);
Material* matl0=new Lambertian(Color(RGBColor(.4,.4,.4)));
- create_objs(world, Point(0,0,.5), BV_RADIUS/2.0, Vector(0,0,1),
- size, objset, matl0);
+ //create_objs(world, Point(0,0,.5), BV_RADIUS/2.0, Vector(0,0,1),
+ // size, objset, matl0);
- Vector diag1(1,1,0);
- diag1.normalize();
- Vector diag2(-1,1,0);
- diag2.normalize();
+ // Just make a box....
Material* matl1=new Lambertian(Color(RGBColor(.2,.4,.2)));
- diag1*=1.5;
- diag2*=1.5;
- Vector z(0,0,.4);
- Point corner(-1.8,-.3,0);
- make_box(world, matl1, corner, diag1, diag2, z);
-
+ NormalMaterial* normal_material = new NormalMaterial();
+
+ // Add a box.
+ world->add( new Cube( normal_material, Point(-1,-1,-1), Point(1,1,1)
) );
+
+ // Make a sphere where we think the box should be
+ world->add(new Sphere( normal_material, Point(0.0,0.0,0.00), 1.0 ) );
+
+ /*
Material* matl3=new MetalMaterial( Color(RGBColor(.7,.7,.7)));
world->add(new Sphere(matl3,
corner+diag1*1.25+diag2*.6+z*2+Vector(0,0,.6), .6));
double planesize=15;
@@ -127,6 +134,7 @@
Vector edge2(-planesize*1.1, planesize, 0);
Object* obj1=new Parallelogram(matl2, Point(0,0,0)-edge1-edge2, edge1*2,
edge2*2);
world->add(obj1);
+ */
}
extern "C"
@@ -159,9 +167,10 @@
if(!world)
world = new Group();
-
+
NOT_FINISHED("scene 0");
make_obj(world, scenesize);
+
#if 0
Camera cam(Point(1.8,-5.53,1.25), Point(0.0,-.13,1.22),
Vector(0,0,1), 28.2);
@@ -172,7 +181,7 @@
Color cup(RGB(0.1, 0.3, 0.8));
- rtrt::Plane groundplane ( Point(0, 0, 0), Vector(0, 0, 3) );
+ rtrt::Plane groundplane ( Point(0, 0, 0), Vector(0, 0, 300) );
Scene* scene=new Scene(obj, cam,
bgcolor, cdown, cup, groundplane,
ambient_scale, Arc_Ambient);
@@ -180,9 +189,7 @@
scene->select_shadow_mode( Single_Soft_Shadow );
#endif
Scene* scene = new Scene();
- scene->setBackground(new LinearBackground(Color(RGB(0.2, 0.4, 0.9)),
- Color::black(),
- Vector(0,0,1)));
+ scene->setBackground(new ConstantBackground(Color::white()));
scene->setObject(world);
NOT_FINISHED("soft shadows/area lights for scene 0");
Modified: branches/itanium2/scenes/boeing777.cc
==============================================================================
--- branches/itanium2/scenes/boeing777.cc (original)
+++ branches/itanium2/scenes/boeing777.cc Wed May 25 14:03:05 2005
@@ -29,6 +29,7 @@
using namespace Manta;
+using namespace Manta::Kdtree;
///////////////////////////////////////////////////////////////////////////
// This function constructs the Boeing 777 Test Scene using a KdTree.
@@ -41,8 +42,8 @@
for (int i=0;i<args.size();++i) {
if (args[i] == "-file") {
// Determine the index of the filename.
- if (!getStringArg(++i, args, file_name))
- throw IllegalArgument("boeing777 -file", i, args);
+ if (!getStringArg(i, args, file_name))
+ throw IllegalArgument("boeing777 -file <filename>", i, args);
}
else {
cerr << "Valid options for boeing777:" << endl;
@@ -56,11 +57,13 @@
// Create a kd tree.
KDTree *world = new KDTree;
- world->load("head.tri");
+ world->load( file_name.c_str() );
+
LightSet* lights = new LightSet();
lights->add(new PointLight(Point(0,0,8), Color(RGBColor(.6,.1,.1))));
lights->setAmbientLight(new ConstantAmbient(Color::black()));
- scene->setLights(lights);
+
+ scene->setLights(lights);
// Add the tree to the scene.
scene->setObject( world );
- [MANTA] r346 - in branches/itanium2: Core Core/Geometry Interface Model/Groups Model/Intersections Model/Primitives SCIRun/Core scenes, abe, 05/25/2005
Archive powered by MHonArc 2.6.16.