Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r350 - in branches/itanium2: Core/Geometry Model/Groups Model/Materials
- Date: Wed, 25 May 2005 19:59:14 -0600 (MDT)
Author: abe
Date: Wed May 25 19:59:12 2005
New Revision: 350
Modified:
branches/itanium2/Core/Geometry/BBox.h
branches/itanium2/Model/Groups/kdtree.cc
branches/itanium2/Model/Groups/kdtree.h
branches/itanium2/Model/Materials/LambertianAlt.cc
Log:
Eliminated core dump on mac, now need correct image on both platforms
Modified: branches/itanium2/Core/Geometry/BBox.h
==============================================================================
--- branches/itanium2/Core/Geometry/BBox.h (original)
+++ branches/itanium2/Core/Geometry/BBox.h Wed May 25 19:59:12 2005
@@ -24,6 +24,11 @@
return Point(Vector(bounds[1]-bounds[0])*0.5);
}
+ void extendByBox( const BBox &box ) {
+ extendByPoint( box[0] );
+ extendByPoint( box[1] );
+ }
+
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]));
Modified: branches/itanium2/Model/Groups/kdtree.cc
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.cc (original)
+++ branches/itanium2/Model/Groups/kdtree.cc Wed May 25 19:59:12 2005
@@ -181,25 +181,22 @@
filename, fileSize, nread);
}
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;
+
+ rootNode->endian_swap();
// 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] );
+ bboxf.min[0] = endian_swap( bboxf.min[0] );
+ bboxf.min[1] = endian_swap( bboxf.min[1] );
+ bboxf.min[2] = endian_swap( bboxf.min[2] );
+
+ bboxf.max[0] = endian_swap( bboxf.max[0] );
+ bboxf.max[1] = endian_swap( bboxf.max[1] );
+ bboxf.max[2] = endian_swap( bboxf.max[2] );
bbox = BBox( bboxf.min, bboxf.max );
@@ -229,6 +226,11 @@
triIndices = indices;
+ // Swap the indicies.
+ for (int i=0;i<nInt;++i) {
+ (*indices)[i] = endian_swap( (*indices)[i] );
+ }
+
// create material
lambMat = new LambertianAlt;
@@ -299,6 +301,8 @@
e.signMask,
e.inverseDirection )) {
+ e.hitInfo.hit(minDist,lambMat,this,0);
+
// Send the ray to the _intersect function.
isectData.rayHitTriIndex = 0;
_intersect( &e.ray, e, &isectData, (float)minDist,
(float)maxDist);
@@ -306,15 +310,29 @@
// 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?
+ // 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;
+ // Check against the hit record, Note that
tex coord mapper is null.
+ if (e.hitInfo.hit(isectData.rayHit.t,
lambMat, this, 0 )) {
+
e.hitInfo.scratchpad<ScratchPadInfo>().normal =
normals[isectData.rayHitTriIndex*3];
+
e.hitInfo.scratchpad<ScratchPadInfo>().payload =
tris->get(isectData.rayHitTriIndex).payload;
+ }
}
}
}
}
+
+///////////////////////////////////////////////////////////////////////////////
+// This function performs the KD-Tree Traversal.
+///////////////////////////////////////////////////////////////////////////////
+void KDTree::computeNormal(const RenderContext& context, RayPacket& rays)
const {
+
+ // Copy the normal out of the KDTree::ScratchPadInfo structure.
+ for (int i=0;i<rays.getSize();++i) {
+ rays.get(i).normal =
rays.get(i).hitInfo.scratchpad<ScratchPadInfo>().normal;
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
// This function performs the KD-Tree Traversal.
Modified: branches/itanium2/Model/Groups/kdtree.h
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.h (original)
+++ branches/itanium2/Model/Groups/kdtree.h Wed May 25 19:59:12 2005
@@ -74,7 +74,20 @@
Pointf& getV2(int i) { return _v2->_get(i); }
int& getPayload(int i) { return _payload->_get(i);
}
};
+
+ // Swap the endianness of a variable.
+ template< typename T >
+ T endian_swap( T in ) {
+ T out;
+ char *pin = (char *)∈
+ char *pout = (char *)&out;
+
+ for (int i=0;i<sizeof(T);++i) {
+ pout[i] = pin[sizeof(T)-1-i];
+ }
+ return out;
+ }
///////////////////////////////////////////////////////////////////////////
// KDTREE INTERNAL NODE
@@ -83,6 +96,11 @@
unsigned char flags;
unsigned int left;
float split;
+
+ void endian_swap() {
+ left = Manta::Kdtree::endian_swap( left );
+ split = Manta::Kdtree::endian_swap( split );
+ }
};
///////////////////////////////////////////////////////////////////////////
@@ -92,6 +110,11 @@
unsigned char flags;
unsigned int listBegin;
unsigned int listLen;
+
+ void endian_swap() {
+ listBegin = Manta::Kdtree::endian_swap(
listBegin );
+ listLen = Manta::Kdtree::endian_swap(
listLen );
+ }
};
///////////////////////////////////////////////////////////////////////////
@@ -112,6 +135,16 @@
unsigned int listBegin() { return leaf.listBegin; }
unsigned int listSize() { return leaf.listLen; }
+
+ void endian_swap() {
+
+ internal.endian_swap();
+
+ if (hasLeftChild())
+ left()->endian_swap();
+ if (hasRightChild())
+ right()->endian_swap();
+ }
};
///////////////////////////////////////////////////////////////////////////
@@ -167,7 +200,8 @@
// KDTREE CLASS PROPER
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
- class KDTree : public Group {
+ class KDTree : public Primitive {
+ private:
BBox bbox;
KDTreeNode *rootNode;
@@ -178,19 +212,30 @@
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;
+
+ public:
+ // This structure is used to record info about the
hit.
+ struct ScratchPadInfo {
+ Vector normal; // Normal of the
intersected face.
+ unsigned int payload; // Payload of the
intersected face.
+ };
+
+ // Primitive Interface.
+ void intersect(const RenderContext& context, RayPacket&
rays) const;
+ void preprocess(const PreprocessContext& context) {
};
+ void setTexCoordMapper(const TexCoordMapper* new_tex)
{ };
+ void computeNormal(const RenderContext& context,
RayPacket& rays) const;
+ void computeBounds(const PreprocessContext &context,
BBox &box_ ) const {
+ box_.extendByBox( bbox ); }
+
+ // This function is called to load the data.
+ int load(const char *fn);
+
};
}
}
Modified: branches/itanium2/Model/Materials/LambertianAlt.cc
==============================================================================
--- branches/itanium2/Model/Materials/LambertianAlt.cc (original)
+++ branches/itanium2/Model/Materials/LambertianAlt.cc Wed May 25 19:59:12
2005
@@ -1,5 +1,6 @@
#include <Model/Materials/LambertianAlt.h>
+#include <Model/Groups/kdtree.h>
#include <Interface/Light.h>
#include <Interface/LightSet.h>
#include <Interface/Primitive.h>
@@ -12,8 +13,13 @@
using namespace Manta;
-void LambertianAlt::shade(const RenderContext& context, RayPacket& rays)
const
-{
+void LambertianAlt::shade(const RenderContext& context, RayPacket& rays)
const {
+
+ for (int i=0;i<rays.getSize();++i) {
+ rays.setResult(i,Color(RGBColor(1.0,0.0,0.0)));
+ }
+
+#if 0
// Shade a bunch of rays. We know that they all have the same intersected
// object and are all of the same material
@@ -25,15 +31,14 @@
float inv255 = 1.0f/255.0f;
for (int i=0;i<rays.getSize();i++) {
RayPacket::Element& e = rays.get(i);
- int rgb = e.hitInfo.scratchpad<int>();
- colors[i] = Color(RGBColor(
- ((rgb & 0xFF0000) >> 16)*inv255,
- ((rgb & 0x00FF00) >> 8)*inv255,
- ((rgb & 0x0000FF) >> 0)*inv255));
+ unsigned int rgb =
e.hitInfo.scratchpad<Kdtree::KDTree::ScratchPadInfo>().payload;
+ colors[i] = Color(RGBColor(((rgb & 0xFF0000) >> 16)*inv255,
+ ((rgb & 0x00FF00) >> 8)*inv255,
+ ((rgb & 0x0000FF) >>
0)*inv255));
}
for(int i=0;i<rays.getSize();i++) {
- RayPacket::Element& e = rays.get(i);
+ RayPacket::Element& e = rays.get(i);
float z = SCIRun::Abs(e.normal[2]);
Color totalLight(RGBColor(z,z,z));
rays.setResult(i, colors[i]*totalLight);
@@ -41,43 +46,47 @@
return;
Scene *scene = (Scene*)context.scene;
- // Compute ambient contributions for all rays
+
+ // Compute ambient contributions for all rays
scene->getLights()->getAmbientLight()->computeAmbient(context, rays);
+ // Compute the normals.
+ rays.computeNormals( context );
+
RayPacketData data;
int start = 0;
do {
RayPacket shadowRays(data, 0, rays.getDepth(), 0);
- int end = context.shadowAlgorithm->computeShadows(context,
scene->getLights(),
- rays, start,
shadowRays);
+ int end = context.shadowAlgorithm->computeShadows(context,
scene->getLights(), rays, start, shadowRays);
if(shadowRays.getFlags() & RayPacket::NormalizedDirections){
for(int i=start;i<end;i++){
- RayPacket::Element& e = rays.get(i);
- Color totalLight(e.ambientLight);
- for(int j=e.shadowBegin;j<e.shadowEnd;j++){
- RayPacket::Element& s = shadowRays.get(j);
- if(!s.hitInfo.wasHit()){
- double cos_theta = Dot(s.ray.direction(), e.normal);
- totalLight += s.light*cos_theta;
- }
- }
- rays.setResult(i, colors[i]*totalLight);
- }
+ RayPacket::Element& e = rays.get(i);
+ Color totalLight(e.ambientLight);
+ for(int j=e.shadowBegin;j<e.shadowEnd;j++){
+ RayPacket::Element& s =
shadowRays.get(j);
+ if(!s.hitInfo.wasHit()){
+ double cos_theta =
Dot(s.ray.direction(), e.normal);
+ totalLight +=
s.light*cos_theta;
+ }
+ }
+ rays.setResult(i, colors[i]*totalLight);
+ }
} else {
for(int i=start;i<end;i++){
- RayPacket::Element& e = rays.get(i);
- Color totalLight(e.ambientLight);
- for(int j=e.shadowBegin;j<e.shadowEnd;j++){
- RayPacket::Element& s = shadowRays.get(j);
- if(!s.hitInfo.wasHit()){
- s.ray.normalizeDirection();
- double cos_theta = Dot(s.ray.direction(), e.normal);
- totalLight += s.light*cos_theta;
- }
- }
- rays.setResult(i, colors[i]*totalLight);
+ RayPacket::Element& e = rays.get(i);
+ Color totalLight(e.ambientLight);
+ for(int j=e.shadowBegin;j<e.shadowEnd;j++){
+ RayPacket::Element& s =
shadowRays.get(j);
+ if(!s.hitInfo.wasHit()){
+ s.ray.normalizeDirection();
+ double cos_theta =
Dot(s.ray.direction(), e.normal);
+ totalLight +=
s.light*cos_theta;
+ }
+ }
+ rays.setResult(i, colors[i]*totalLight);
}
}
start = end;
} while(start < rays.getSize());
+#endif
}
- [MANTA] r350 - in branches/itanium2: Core/Geometry Model/Groups Model/Materials, abe, 05/25/2005
Archive powered by MHonArc 2.6.16.