Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r549 - in branches/itanium2: Model/Groups StandAlone
- Date: Wed, 14 Sep 2005 01:01:23 -0600 (MDT)
Author: bigler
Date: Wed Sep 14 01:01:23 2005
New Revision: 549
Added:
branches/itanium2/StandAlone/frust-test.cc
Modified:
branches/itanium2/Model/Groups/FrustumKDTree.cc
branches/itanium2/Model/Groups/FrustumKDTree.h
branches/itanium2/Model/Groups/KDTree.h
branches/itanium2/StandAlone/CMakeLists.txt
Log:
Model/Groups/FrustumKDTree.cc
Model/Groups/FrustumKDTree.h
Copy the signMask from the ray packet to frustum_direction.
Fix spellings of Frustrum to Frustum.
Model/Groups/KDTree.h
Code formatting. Goodbye tabs, traling white space, and lines too long.
StandAlone/CMakeLists.txt
StandAlone/frust-test.cc
Added frust-test executable for testing FrustumKDTree code.
Modified: branches/itanium2/Model/Groups/FrustumKDTree.cc
==============================================================================
--- branches/itanium2/Model/Groups/FrustumKDTree.cc (original)
+++ branches/itanium2/Model/Groups/FrustumKDTree.cc Wed Sep 14 01:01:23
2005
@@ -54,8 +54,17 @@
Point plane_point;
Vector plane_normal;
+#if 0 // This seems to be handled by a parent somewhere, so I'll leave
+ // this commented out for now.
+
+ // If we don't have constant directions for our ray packet, we can't
+ // make one of these.
+ ASSERT(rays.getFlags & RayPacket::ConstantDirections);
+#endif
+
for (int i=0;i<3;++i) {
int signMask = rays.get(0).signMask[i];
+ frustum_direction[i] = signMask;
// Compute the plane point and normal.
plane_point [i] = (2.0 * signMask) - 1.0; // signMask[i] now in {-1,1}
@@ -122,7 +131,7 @@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-// FRUSTRUM KD TREE FRUSTRUM KD TREE FRUSTRUM KD TREE FRUSTRUM KD TREE FR
+// FRUSTUM KD TREE FRUSTUM KD TREE FRUSTUM KD TREE FRUSTUM KD TREE FR
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
@@ -224,12 +233,12 @@
above[1] = (f[1] >= max_edge[1]);
// Doesn't handle "on-edge" or "on-corner" overlap.
-
+
// In the case that n[0] == min_edge[0] or f[0] == max_edge[0]
// The frustum still intersects only A or B, depending on direction.
// Not classifing these as INTERSECT_BOTH allows a deeper node to be
choosen
// as a candidate starting point.
-
+
if ( ((n[0] > min_edge[0]) && !above[0]) ||
((n[1] > min_edge[1]) && !above[1]) )
return INTERSECT_BOTH;
@@ -263,7 +272,7 @@
// #else
unsigned int child_table[2];
unsigned int result = INTERSECT_NONE;
-
+
if (frustum.origin()[axis] > node->split()) {
child_table[0] = INTERSECT_MAX;
child_table[1] = INTERSECT_MIN;
@@ -272,27 +281,27 @@
child_table[0] = INTERSECT_MIN;
child_table[1] = INTERSECT_MAX;
}
-
+
for (int i=0;i<2;++i) {
result |= child_table[above[i] ^ frustum.direction(plane_axis[i])];
}
#endif
-
+
// Which side of the split plane is the ray packet on.
unsigned int origin = (frustum.origin()[axis] > node->split());
unsigned int result = INTERSECT_NONE;
-
+
for (int i=0;i<2;++i) {
-
+
// Determine the A or B child.
- // This assumes frustum origin is positive,
+ // This assumes frustum origin is positive,
// A=INTERSECT_MAX=0x2 B=INTERSECT_MIN=0x1
unsigned int exp1 = ( 0x1 << (above[i] ^
frustum.direction(plane_axis[i])) );
-
+
// Based on origin flip A and B children
result |= ((exp1 & 0x2) >> origin) | ((exp1 & 0x1) << origin);
}
-
+
// Return the result.
return (IntersectCase)result;
}
@@ -307,7 +316,7 @@
const BBox& leaf_bounds ) {
Vector entry[4];
Vector exit[4];
- // frustrum.direction() is 0 for negative directions, 1 for zero/positive.
+ // frustum.direction() is 0 for negative directions, 1 for zero/positive.
Point bb_min(leaf_bounds[1-frustum.direction(0)].x(),
leaf_bounds[1-frustum.direction(1)].y(),
leaf_bounds[1-frustum.direction(2)].z());
Modified: branches/itanium2/Model/Groups/FrustumKDTree.h
==============================================================================
--- branches/itanium2/Model/Groups/FrustumKDTree.h (original)
+++ branches/itanium2/Model/Groups/FrustumKDTree.h Wed Sep 14 01:01:23
2005
@@ -84,7 +84,7 @@
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
- // This class implements a kdtree traversal where the frustrum of
+ // This class implements a kdtree traversal where the frustum of
// a ray packet is first intersected with the kdtree before
// individual rays are intersected with the tree.
@@ -96,27 +96,27 @@
void packet_intersect(const RenderContext& context, RayPacket &rays );
/////////////////////////////////////////////////////////////////////////
- // Intersect the specified frustrum with the kdtree.
+ // Intersect the specified frustum with the kdtree.
enum IntersectCase { INTERSECT_NONE = 0x0, // Cannot be determined by
// basic tests.
INTERSECT_MIN = 0x1,
INTERSECT_MAX = 0x2,
INTERSECT_BOTH = 0x3 };
- // Intersect the specified frustrum with an internal node.
+ // Intersect the specified frustum with an internal node.
IntersectCase frustum_node_intersect(const RenderContext& context,
const KDTreeNode *node,
const PacketFrustum &frustum,
const BBox &node_bounds );
- // Intersect the specified frustrum with a leaf.
+ // Intersect the specified frustum with a leaf.
bool frustum_leaf_intersect(const RenderContext& context,
PacketFrustum &frustum,
const BBox& leaf_bounds );
public:
/////////////////////////////////////////////////////////////////////////
- // Create a FrustrumKDTree which data may be loaded into.
+ // Create a FrustumKDTree which data may be loaded into.
FrustumKDTree( Material *material_ ) : KDTree( material_ ) { };
// Use data owned by another kdtree.
@@ -124,12 +124,12 @@
KDTree( kdtree_, material_ )
{ }
- // Intersection method -- Intersect frustrum with kdtree then call
+ // Intersection method -- Intersect frustum with kdtree then call
// KDTree::intersect.
virtual void intersect(const RenderContext& context, RayPacket& rays)
const;
};
- }; // end namespace Frustrum
+ }; // end namespace Kdtree
}; // end namespace Manta
Modified: branches/itanium2/Model/Groups/KDTree.h
==============================================================================
--- branches/itanium2/Model/Groups/KDTree.h (original)
+++ branches/itanium2/Model/Groups/KDTree.h Wed Sep 14 01:01:23 2005
@@ -1,30 +1,30 @@
/*
- 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.
- */
+ 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.
+*/
#ifndef __KD_TREE_H__
#define __KD_TREE_H__
@@ -51,272 +51,303 @@
namespace Manta {
- // Note: Kdtree is the namespace: KDTree, KDTreeTransparent are
classes
- // in the namespace.
- namespace Kdtree {
-
- // Data is stored in 32 bit floats.
- 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
- Color payload; //
- Vectorf edge1, edge2; // 2*3 floats = 6*4 bytes = 24
bytes
-
// the above are exactly 64 bytes
-
- Triangle()/* : Geometry()*/ { }
-
- Triangle(const float *tri, const Color &p) {
- v[0] = *(Pointf*)tri; v[1] =
*(Pointf*)(tri+3); v[2] = *(Pointf*)(tri+6);
- payload = p;
- }
- Triangle(const Pointf *v_, const Color &p) {
- v[0] = v_[0]; v[1] = v_[1]; v[2] = v_[2];
- payload = p;
- }
- Triangle(const Pointf &v0_, const Pointf &v1_, const
Pointf &v2_, const Color &p) {
- 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);
}
- };
-
-
-
///////////////////////////////////////////////////////////////////////////
- // 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;
- }
-
- // Check the endianness of this machine.
- inline bool is_big_endian() {
-
- unsigned int x = 0x00112233;
- char *p = (char *)&x;
-
- return (p[0] == 0x00);
- }
-
-
///////////////////////////////////////////////////////////////////////////
- // KDTREE INTERNAL NODE
-
///////////////////////////////////////////////////////////////////////////
- struct KDTreeInternalNode {
- unsigned char flags;
- unsigned int left;
- float split;
-
- void endian_swap() {
- left = Manta::Kdtree::endian_swap( left );
- split = Manta::Kdtree::endian_swap( split );
- }
- };
-
-
///////////////////////////////////////////////////////////////////////////
- // KDTREE LEAF NODE
-
///////////////////////////////////////////////////////////////////////////
- struct KDTreeLeafNode {
- unsigned char flags;
- unsigned int listBegin;
- unsigned int listLen;
-
- void endian_swap() {
- listBegin = Manta::Kdtree::endian_swap(
listBegin );
- listLen = Manta::Kdtree::endian_swap(
listLen );
- }
- };
-
-
///////////////////////////////////////////////////////////////////////////
- // KDTREE NODE
-
///////////////////////////////////////////////////////////////////////////
- union KDTreeNode {
- KDTreeInternalNode internal;
- KDTreeLeafNode leaf;
-
- bool hasLeftChild() const { return internal.flags &
KDNODE_LEFT_CHILD_MASK; }
- bool hasRightChild() const { 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() const { return internal.split; }
- bool isInternal() const { return internal.flags &
KDNODE_INTERNAL_MASK; }
- unsigned int axis() const { return internal.flags &
KDNODE_AXIS_MASK; }
-
- 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();
- }
- };
-
-
///////////////////////////////////////////////////////////////////////////
- // 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 PrimitiveCommon {
-
- // Transparent KDTree will use data owned by this
kdtree.
- friend class TransparentKDTree;
-
- // The Kdtree::load(...) function is used to load
data into the kdtree.
- friend int Manta::Kdtree::load( KDTree *kdtree, const
char *filename, int np );
-
- protected:
- BBox bbox;
- KDTreeNode *rootNode;
-
- private:
- VArray<int> *triIndices;
- VArray<Triangle> *tris;
- Vectorf *normals;
-
- protected:
- // Copy data pointers from another kdtree. (Used by
derived classes.)
- KDTree( KDTree *kdtree_, Material *material_ ) :
- PrimitiveCommon( material_ ),
- rootNode( kdtree_->rootNode ), triIndices(
kdtree_->triIndices ),
- tris( kdtree_->tris ), normals(
kdtree_->normals ) { bbox.extendByBox( bbox ); };
-
- // 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 RenderContext
&context) const;
-
- // This method is called to intersect a single ray
with the kdtree.
- // void _intersect(const Ray* ray, RayPacket::Element
&e, RayTriIntersectUserData &isectData, const RenderContext &context, float
_minDist=-1, float _maxDist=-1) const;
- void intersect_node( KDTreeNode *startNode,
- const Ray* ray, RayPacket::Element &e,
- RayTriIntersectUserData &isectData,
+ // Note: Kdtree is the namespace: KDTree, KDTreeTransparent are classes
+ // in the namespace.
+ namespace Kdtree {
+
+ // Data is stored in 32 bit floats.
+ 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
+ Color payload; //
+ Vectorf edge1, edge2; // 2*3 floats = 6*4 bytes = 24 bytes
+ // the above are exactly 64 bytes
+
+ Triangle()/* : Geometry()*/ { }
+
+ Triangle(const float *tri, const Color &p) {
+ v[0] = *(Pointf*)tri;
+ v[1] = *(Pointf*)(tri+3);
+ v[2] = *(Pointf*)(tri+6);
+ payload = p;
+ }
+ Triangle(const Pointf *v_, const Color &p) {
+ v[0] = v_[0]; v[1] = v_[1]; v[2] = v_[2];
+ payload = p;
+ }
+ Triangle(const Pointf &v0_, const Pointf &v1_, const Pointf &v2_,
+ const Color &p) {
+ 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); }
+ };
+
+
+
///////////////////////////////////////////////////////////////////////////
+ // 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;
+ }
+
+ // Check the endianness of this machine.
+ inline bool is_big_endian() {
+
+ unsigned int x = 0x00112233;
+ char *p = (char *)&x;
+
+ return (p[0] == 0x00);
+ }
+
+
///////////////////////////////////////////////////////////////////////////
+ // KDTREE INTERNAL NODE
+
///////////////////////////////////////////////////////////////////////////
+ struct KDTreeInternalNode {
+ unsigned char flags;
+ unsigned int left;
+ float split;
+
+ void endian_swap() {
+ left = Manta::Kdtree::endian_swap( left );
+ split = Manta::Kdtree::endian_swap( split );
+ }
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+ // KDTREE LEAF NODE
+
///////////////////////////////////////////////////////////////////////////
+ struct KDTreeLeafNode {
+ unsigned char flags;
+ unsigned int listBegin;
+ unsigned int listLen;
+
+ void endian_swap() {
+ listBegin = Manta::Kdtree::endian_swap( listBegin );
+ listLen = Manta::Kdtree::endian_swap( listLen );
+ }
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+ // KDTREE NODE
+
///////////////////////////////////////////////////////////////////////////
+ union KDTreeNode {
+ KDTreeInternalNode internal;
+ KDTreeLeafNode leaf;
+
+ bool hasLeftChild() const {
+ return internal.flags & KDNODE_LEFT_CHILD_MASK;
+ }
+ bool hasRightChild() const {
+ 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() const { return internal.split; }
+ bool isInternal() const {
+ return internal.flags & KDNODE_INTERNAL_MASK;
+ }
+ unsigned int axis() const { return internal.flags & KDNODE_AXIS_MASK;
}
+
+ 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();
+ }
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+ // 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 PrimitiveCommon {
+
+ // Transparent KDTree will use data owned by this kdtree.
+ friend class TransparentKDTree;
+
+ // The Kdtree::load(...) function is used to load data into the kdtree.
+ friend int Manta::Kdtree::load( KDTree *kdtree, const char *filename,
+ int np );
+
+ protected:
+ BBox bbox;
+ KDTreeNode *rootNode;
+
+ private:
+ VArray<int> *triIndices;
+ VArray<Triangle> *tris;
+ Vectorf *normals;
+
+ protected:
+ // Copy data pointers from another kdtree. (Used by derived classes.)
+ KDTree( KDTree *kdtree_, Material *material_ ) :
+ PrimitiveCommon( material_ ),
+ rootNode( kdtree_->rootNode ), triIndices( kdtree_->triIndices ),
+ tris( kdtree_->tris ), normals( kdtree_->normals )
+ {
+ bbox.extendByBox( bbox );
+ }
+
+ // 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 RenderContext &context) const;
+
+ // This method is called to intersect a single ray with the kdtree.
+
+ // void _intersect(const Ray* ray, RayPacket::Element &e,
+ // RayTriIntersectUserData &isectData,
+ // const RenderContext &context,
+ // float _minDist=-1, float _maxDist=-1) const;
+ void intersect_node( KDTreeNode *startNode,
+ const Ray* ray, RayPacket::Element &e,
+ RayTriIntersectUserData &isectData,
const RenderContext &context,
float minDist, float maxDist) const;
-
- public:
- // Constructor.
- KDTree( Material *material_ ) : PrimitiveCommon(
material_ ) { };
-
- // This structure is used to record info about the
hit.
- struct ScratchPadInfo {
- Vector normal; // Normal of the intersected
face.
- Color payload; // Payload of the intersected
face.
- };
-
- // Primitive Interface.
- virtual void intersect(const RenderContext& context,
RayPacket& rays) const;
- void computeNormal (const RenderContext& context,
RayPacket& rays) const;
- void computeBounds (const PreprocessContext
&context, BBox &box_ ) const { box_.extendByBox( bbox ); }
- void computeBounds ( BBox &box_ ) const {
box_.extendByBox( bbox ); }
-
- // This function is called to load the data.
- // np specifies the number of workers, for certain
loading functions.
- int load( const char *fn, int np );
-
- };
-
-
///////////////////////////////////////////////////////////////////////////
-
///////////////////////////////////////////////////////////////////////////
- // KDTREE TEXTURE (For extracting color information from the
kdtree
- // scratch pad.
-
///////////////////////////////////////////////////////////////////////////
-
///////////////////////////////////////////////////////////////////////////
- class KDTreeTexture : public Texture<Color> {
- public:
- virtual void mapValues(const RenderContext& context,
RayPacket& rays, Color results[]) const;
- };
- }
-}
+ public:
+ // Constructor.
+ KDTree( Material *material_ ) : PrimitiveCommon( material_ ) { };
+
+ // This structure is used to record info about the hit.
+ struct ScratchPadInfo {
+ Vector normal; // Normal of the intersected face.
+ Color payload; // Payload of the intersected face.
+ };
+
+ // Primitive Interface.
+ virtual void intersect(const RenderContext& context, RayPacket& rays)
const;
+ void computeNormal (const RenderContext& context, RayPacket& rays)
const;
+ void computeBounds (const PreprocessContext &context, BBox &box_ )
const
+ {
+ box_.extendByBox( bbox );
+ }
+ void computeBounds ( BBox &box_ ) const { box_.extendByBox( bbox ); }
+
+ // This function is called to load the data.
+ // np specifies the number of workers, for certain loading functions.
+ int load( const char *fn, int np );
+
+ };
+
+
///////////////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////////////
+ // KDTREE TEXTURE (For extracting color information from the kdtree
+ // scratch pad.
+
///////////////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////////////
+ class KDTreeTexture : public Texture<Color> {
+ public:
+ virtual void mapValues(const RenderContext& context, RayPacket& rays,
+ Color results[]) const;
+ };
+
+ } // end namespace Kdtree
+
+} // end namespace Manta
#endif
Modified: branches/itanium2/StandAlone/CMakeLists.txt
==============================================================================
--- branches/itanium2/StandAlone/CMakeLists.txt (original)
+++ branches/itanium2/StandAlone/CMakeLists.txt Wed Sep 14 01:01:23 2005
@@ -1,19 +1,29 @@
ADD_EXECUTABLE(manta manta.cc)
-TARGET_LINK_LIBRARIES(manta Manta_Engine
- Manta_UserInterface
- Manta_Model
- Manta_Image
- Manta_Interface
- Manta_Core
+TARGET_LINK_LIBRARIES(manta Manta_Engine
+ Manta_UserInterface
+ Manta_Model
+ Manta_Image
+ Manta_Interface
+ Manta_Core
SCIRun_Core)
TARGET_LINK_LIBRARIES(manta ${CMAKE_THREAD_LIBS_INIT}
- ${OPENGL_LIBRARIES}
- ${X11_LIBRARIES}
+ ${OPENGL_LIBRARIES}
+ ${X11_LIBRARIES}
-lm)
ADD_EXECUTABLE(barrier_test barrier_test.cc)
TARGET_LINK_LIBRARIES(barrier_test SCIRun_Core
- ${CMAKE_THREAD_LIBS_INIT})
\ No newline at end of file
+ ${CMAKE_THREAD_LIBS_INIT})
+
+ADD_EXECUTABLE(frust-test frust-test.cc)
+TARGET_LINK_LIBRARIES(manta Manta_Engine
+ Manta_UserInterface
+ Manta_Model
+ Manta_Image
+ Manta_Interface
+ Manta_Core
+ SCIRun_Core)
+
Added: branches/itanium2/StandAlone/frust-test.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/StandAlone/frust-test.cc Wed Sep 14 01:01:23 2005
@@ -0,0 +1,48 @@
+// This program is designed to test the FrustumKDTree code piece by
+// piece, so that we can have some confidence as to the correctness of
+// the code without having to run some giant model.
+//
+// Author: James Bigler
+// Date: Sep. 14, 2005
+//
+
+
+#include <Model/Groups/FrustumKDTree.h>
+
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+
+using namespace Manta;
+using namespace Kdtree;
+using namespace std;
+
+// These are the two main functions we will be testing
+#if 0
+// Intersect the specified frustum with an internal node.
+IntersectCase frustum_node_intersect(const RenderContext& context,
+ const KDTreeNode *node,
+ const PacketFrustum &frustum,
+ const BBox &node_bounds );
+
+// Intersect the specified frustum with a leaf.
+bool frustum_leaf_intersect(const RenderContext& context,
+ PacketFrustum &frustum,
+ const BBox& leaf_bounds );
+#endif
+
+int main(int argc, char* argv[]) {
+
+ if (argc > 1) {
+ // print help message
+ cerr << "Usage: "<<argv[0]<<" no args\n";
+ return 1;
+ }
+
+ // OK, create my first KDTreeNode
+
+
+ return 0;
+}
+
+
- [MANTA] r549 - in branches/itanium2: Model/Groups StandAlone, bigler, 09/14/2005
Archive powered by MHonArc 2.6.16.