Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r915 - in trunk: Core Core/Util Model/Groups fox/FManta fox/afr_demo/Engine/ImageTraversers fox/dm_demo scenes


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r915 - in trunk: Core Core/Util Model/Groups fox/FManta fox/afr_demo/Engine/ImageTraversers fox/dm_demo scenes
  • Date: Thu, 9 Feb 2006 14:13:58 -0700 (MST)

Author: abe
Date: Thu Feb  9 14:13:57 2006
New Revision: 915

Added:
   trunk/Core/Util/Endian.h
Modified:
   trunk/Core/CMakeLists.txt
   trunk/Model/Groups/KDTree.cc
   trunk/Model/Groups/KDTree.h
   trunk/Model/Groups/KDTreeLoader.cc
   trunk/Model/Groups/KDTreeLoader.h
   trunk/Model/Groups/SSEKDTree.cc
   trunk/Model/Groups/SSEKDTree.h
   trunk/Model/Groups/TransparentKDTree.cc
   trunk/Model/Groups/TransparentKDTree.h
   trunk/Model/Groups/VerticalKDTree.cc
   trunk/Model/Groups/VerticalKDTree.h
   trunk/fox/FManta/FMantaKdExplorer.cc
   trunk/fox/FManta/FMantaKdExplorer.h
   trunk/fox/afr_demo/Engine/ImageTraversers/AFRImageTraverser.cc
   trunk/fox/dm_demo/dm_demo.cc
   trunk/scenes/boeing777.cc
Log:

Removed endian test/swap from KDTree.h and put it in a common place.
A    Core/Util/Endian.h
M    Core/CMakeLists.txt

Replaced the KDTreeDebug class with a KDTreeData class. This is the parent 
class for all KDTree traversals now. It contains all of the kdtree and 
triangle data, as well as normals and texture coordinates.

To create a kdtree, first use the KDTreeLoader to load data into a KDTreeData 
class. Then pass a pointer to the KDTreeData class to any traversal instance. 
All of the support code uses the KDTreeData interface so it will all operate 
on the same data.

M    Model/Groups/SSEKDTree.h
M    Model/Groups/TransparentKDTree.h
M    Model/Groups/KDTreeLoader.cc
M    Model/Groups/KDTreeLoader.h
M    Model/Groups/VerticalKDTree.cc
M    Model/Groups/KDTree.cc
M    Model/Groups/TransparentKDTree.cc
M    Model/Groups/VerticalKDTree.h
M    Model/Groups/KDTree.h
M    Model/Groups/SSEKDTree.cc

Updated other dependent code to use KDTreeData
M    scenes/boeing777.cc
M    fox/dm_demo/dm_demo.cc
M    fox/FManta/FMantaKdExplorer.cc
M    fox/FManta/FMantaKdExplorer.h
M    fox/afr_demo/Engine/ImageTraversers/AFRImageTraverser.cc




Modified: trunk/Core/CMakeLists.txt
==============================================================================
--- trunk/Core/CMakeLists.txt   (original)
+++ trunk/Core/CMakeLists.txt   Thu Feb  9 14:13:57 2006
@@ -40,6 +40,7 @@
 SET (CORE_SOURCES ${CORE_SOURCES}
      Util/Args.h
      Util/Args.cc
+     Util/Endian.h
      Util/ThreadStorage.h
      Util/ThreadStorage.cc)
 SET (CORE_SOURCES ${CORE_SOURCES}

Added: trunk/Core/Util/Endian.h
==============================================================================
--- (empty file)
+++ trunk/Core/Util/Endian.h    Thu Feb  9 14:13:57 2006
@@ -0,0 +1,60 @@
+/*
+  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.
+*/
+
+#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 *)&in;
+      char * const 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 * const p = (char *)&x;
+
+      return (p[0] == 0x00);
+    }
+
+};
+  
+#endif

Modified: trunk/Model/Groups/KDTree.cc
==============================================================================
--- trunk/Model/Groups/KDTree.cc        (original)
+++ trunk/Model/Groups/KDTree.cc        Thu Feb  9 14:13:57 2006
@@ -630,7 +630,7 @@
 void KDTreeTexCoordMapper::computeTexCoords2(const RenderContext& context, 
RayPacket& rays) const {
 
   // Obtain a pointer to the kdtree.
-  const KDTreeDebug *kdtree = dynamic_cast<const KDTreeDebug *>( 
rays.getHitPrimitive( rays.begin() ) );
+  const KDTreeData *kdtree = dynamic_cast<const KDTreeData *>( 
rays.getHitPrimitive( rays.begin() ) );
 
   // Interpolate texture coordinates.
   for(int i=rays.begin();i<rays.end();i++){

Modified: trunk/Model/Groups/KDTree.h
==============================================================================
--- trunk/Model/Groups/KDTree.h (original)
+++ trunk/Model/Groups/KDTree.h Thu Feb  9 14:13:57 2006
@@ -30,8 +30,10 @@
 #define __KD_TREE_H__
 
 #include <Model/Groups/Group.h>
+
 #include <Core/Geometry/PointVector.h>
 #include <Core/Geometry/BBox.h>
+#include <Core/Util/Endian.h>
 
 #include <Interface/RayPacket.h>
 
@@ -42,9 +44,10 @@
 
 #include <Model/Groups/varray.h>
 
+
 namespace Manta {
 
-  // Note: Kdtree is the namespace: KDTree, KDTreeTransparent are classes
+  // Note: Kdtree is the namespace: KDTree, KDTreeTransparent, etc, are 
classes
   // in the namespace.
   namespace Kdtree {
 
@@ -63,35 +66,20 @@
     
///////////////////////////////////////////////////////////////////////////
     // TRIANGLE  TRIANGLE  TRIANGLE  TRIANGLE  TRIANGLE  TRIANGLE  TRIANGLE  
TR
     
///////////////////////////////////////////////////////////////////////////
-    class Triangle/*: public Geometry*/ {
+    class Triangle {
     public:
       Pointf  v[3];         // 3*3 floats = 9*4 bytes = 36 bytes
-      Color   payload;      //
+      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;
-      }
+      Triangle() {  }
 
-      // Access an individual vertex.
+      // Access vertices.
       Pointf &operator[] (int i) { return v[i]; }
       const Pointf &operator[] (int i) const { return v[i]; }
 
+      // Compute bounds.
       void getBound(BBox &bounds_) {
         bounds_.extendByPoint( v[0] );
         bounds_.extendByPoint( v[1] );
@@ -122,47 +110,6 @@
     };    
     
     
///////////////////////////////////////////////////////////////////////////
-    // 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 *)&in;
-      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 {
@@ -171,8 +118,8 @@
       float split;
 
       void endian_swap() {
-        left  = Manta::Kdtree::endian_swap( left );
-        split = Manta::Kdtree::endian_swap( split );
+        left  = Manta::endian_swap( left );
+        split = Manta::endian_swap( split );
       }
     };
 
@@ -185,8 +132,8 @@
       unsigned int listLen;
 
       void endian_swap() {
-        listBegin = Manta::Kdtree::endian_swap( listBegin );
-        listLen   = Manta::Kdtree::endian_swap( listLen   );
+        listBegin = Manta::endian_swap( listBegin );
+        listLen   = Manta::endian_swap( listLen   );
       }
     };
 
@@ -288,49 +235,120 @@
     };
 
     
///////////////////////////////////////////////////////////////////////////
-    // KDTREE DEBUG INTERFACE
+    // KDTREE DATA  KDTREE DATA  KDTREE DATA  KDTREE DATA  KDTREE DATA  
KDTREE 
     
///////////////////////////////////////////////////////////////////////////
-    class KDTreeDebug {
+    class KDTreeData {
     public:
+
+      
/////////////////////////////////////////////////////////////////////////
+      // The Kdtree::load(...) function is used to load data into the kdtree.
+      friend int Manta::Kdtree::load( KDTreeData *kdtree, const char 
*filename,
+                                      int np );
+
+      
/////////////////////////////////////////////////////////////////////////
+      // SCRATCH PAD
+      
/////////////////////////////////////////////////////////////////////////
+      struct ScratchPadInfo {
+        Vector normal;              // Normal of the intersected face.
+        Color payload;              // Payload of the intersected face.
+        unsigned int hit_index;     // Triangle index for defered normal 
interpolation.
+        Real a, b;                  // Barycentric coordinates of the hit.
+      };
+      
/////////////////////////////////////////////////////////////////////////
+      
/////////////////////////////////////////////////////////////////////////
+
+                       enum {
+                               PICK_HIGHLIGHT = 1,
+                               PICK_REMOVE    = 2,
+                       };
       
-      virtual void        computeBounds( BBox &bounds ) const   = 0;
+      
/////////////////////////////////////////////////////////////////////////
+      // CONSTRUCTORS
+      
/////////////////////////////////////////////////////////////////////////
+      
+      KDTreeData() :
+        rootNode  ( 0 ),
+        triIndices( 0 ),
+        tris      ( 0 ),
+        normals   ( 0 ),
+        texcoords ( 0 ),
+        __pickingEnabled( true ),
+        pickingEnabled( false ),
+        pickedTri( -1 ),
+        pickedFlag( PICK_HIGHLIGHT ) { }
+
+      KDTreeData( const KDTreeData *kdtree_ ) :
+        rootNode  ( kdtree_->rootNode ),
+        triIndices( kdtree_->triIndices ),
+        tris      ( kdtree_->tris ),
+        normals   ( kdtree_->normals ),
+        texcoords ( kdtree_->texcoords ),
+        pickedFlag      ( kdtree_->pickedFlag ),
+        __pickingEnabled( kdtree_->__pickingEnabled ),
+        pickingEnabled  ( kdtree_->pickingEnabled ),
+        pickedTri       ( kdtree_->pickedTri ),        
+        bbox      ( kdtree_->bbox ) {  }
+
+      
/////////////////////////////////////////////////////////////////////////
+      // SELECTION 
+      
/////////////////////////////////////////////////////////////////////////
 
-      // Accessors.
-      virtual void        setRootNode( KDTreeNode *node ) = 0;
-      virtual KDTreeNode *getRootNode()                   = 0;
-      virtual Triangle   &getFace( int index ) const = 0;
-      virtual TextureCoord &getTextureCoord( int index ) const = 0;
-    };
-    
-    
///////////////////////////////////////////////////////////////////////////
-    
///////////////////////////////////////////////////////////////////////////
-    // KDTREE CLASS PROPER
-    
///////////////////////////////////////////////////////////////////////////
-    
///////////////////////////////////////////////////////////////////////////
-    class KDTree : public PrimitiveCommon, public KDTreeDebug {
+                       void enablePicking()          { if (__pickingEnabled) 
pickingEnabled = true; }
+                       void disablePicking()         { pickingEnabled = 
false; }
+                       bool isPickingEnabled() const { return 
pickingEnabled&&__pickingEnabled; }
+                       void resetPicking()           { pickedTri = -1; 
triFlags->clear(); }
+                       void __setPicking(bool flag)  { __pickingEnabled = 
flag; }
 
-      // Transparent KDTree will use data owned by this kdtree.
-      friend class TransparentKDTree;
-      friend class VerticalKDTree;
-      friend class SSEKDTree;
+                       void setPickedFlag(unsigned char flag)
+                                    { pickedFlag = flag; }
+                       unsigned char getPickedFlag() { return pickedFlag; }
 
-      // The Kdtree::load(...) function is used to load data into the kdtree.
-      friend int Manta::Kdtree::load( KDTree *kdtree, const char *filename,
-                                      int np );
+      const char *getPickedName() { 
+        if (pickedTri >= 0) return 
&(groupNames->get(groupToNameMap->get(triToGroupMap->get( pickedTri ))));
+        return (char *)"No selection";
+      }
+
+
+      
+      
/////////////////////////////////////////////////////////////////////////
+      // ACCESSORS
+      
/////////////////////////////////////////////////////////////////////////
+      
+      // Compute bounds.
+      void computeBounds( BBox &box_ ) const { box_.extendByBox( bbox ); }
+
+      // Root node accessors.
+      void        setRootNode( KDTreeNode *node ) { rootNode = node; };
+      KDTreeNode *getRootNode()                   { return rootNode; };
+
+      // Data member accessors.
+      Triangle     &getFace( int index ) const         { return 
(*tris)[index]; };
+      TextureCoord &getTextureCoord( int index ) const { return 
(texcoords)[index]; };
 
     protected:
+
+      
/////////////////////////////////////////////////////////////////////////
+      // DATA MEMBERS
+      
/////////////////////////////////////////////////////////////////////////
+      
+      // Bounds.
       BBox bbox;
+
+      // Root node.
       KDTreeNode       *rootNode;
 
-    private:
+      // Leaf index list, actual triangles, normals, texcoords.
       VArray<int>      *triIndices;
       VArray<Triangle> *tris;
       TriangleNormal   *normals;
       TextureCoord     *texcoords;
 
+      // Group name list.
                        VArray<int> *triToGroupMap;
                        VArray<int> *groupToNameMap;
                        VArray<char> *groupNames;
+
+      // Selection.
                        bool __pickingEnabled;
                        bool pickingEnabled;
                        mutable long long pickedTri;
@@ -338,38 +356,15 @@
                        VArray<Color> pickedSavedColors;
                        VArray<unsigned char> *triFlags;
                        unsigned char pickedFlag;
-               public:
-                       enum {
-                               PICK_HIGHLIGHT = 1,
-                               PICK_REMOVE = 2,
-                       };
-
-                       void enablePicking() {
-                               if (__pickingEnabled)
-                                       pickingEnabled = true;
-                       }
-                       void disablePicking() { pickingEnabled = false; }
-                       bool isPickingEnabled() const { return 
pickingEnabled&&__pickingEnabled; }
-                       void resetPicking() { 
-                               pickedTri = -1; 
-                               triFlags->clear();
-                       }
-                       void __setPicking(bool flag) { __pickingEnabled = 
flag; }
-
-                       void setPickedFlag(unsigned char flag) { pickedFlag = 
flag; }
-                       unsigned char getPickedFlag() { return pickedFlag; }
-
+    };
+    
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    // KDTREE CLASS PROPER
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    class KDTree : public PrimitiveCommon, public KDTreeData {
     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 );
-               pickedFlag = PICK_HIGHLIGHT;
-      }
-
       // This method intersects a list of triangles with the ray.
       int intersectTriangles(const Pointf& origin, const Vectorf& direction,
                              unsigned int listBegin, unsigned int listSize,
@@ -385,43 +380,16 @@
 
     public:
       // Constructor.
-      KDTree( Material *material_ ) : PrimitiveCommon( material_ ) {  
-                 __pickingEnabled = true;
-                 pickingEnabled = false;
-                 pickedTri = -1;
-                 pickedFlag = PICK_HIGHLIGHT;
-         };
-
-      // 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.
-        unsigned int hit_index;     // Triangle index for defered normal 
interpolation.
-        Real a, b;                  // Barycentric coordinates of the hit.
-      };
+      KDTree( KDTreeData *kdtree_, Material *material_ ) :
+        PrimitiveCommon( material_ ),
+        KDTreeData( kdtree_ ) {  };
 
       virtual ~KDTree() {}
-
+      
       // Primitive Interface.
       virtual void intersect(const RenderContext& context, RayPacket& rays) 
const;
       virtual void computeNormal (const RenderContext& context, RayPacket& 
rays) const;
-      virtual void computeBounds (const PreprocessContext& /*context*/,
-                          BBox &box_ ) const
-      {
-        box_.extendByBox( bbox );
-      }
-      virtual 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 );
-
-      // Accessors (used by gui to examine kdtree).
-      virtual void        setRootNode( KDTreeNode *node ) { rootNode = node; 
};
-      virtual KDTreeNode *getRootNode()                   { return rootNode; 
};
-      virtual Triangle   &getFace( int index ) const            { return 
(*tris)[index]; };
-      virtual TextureCoord &getTextureCoord( int index ) const { return 
(texcoords)[index]; };
-      
+      virtual void computeBounds (const PreprocessContext& , BBox &box_ ) 
const { box_.extendByBox( bbox ); }
     };
 
     
///////////////////////////////////////////////////////////////////////////

Modified: trunk/Model/Groups/KDTreeLoader.cc
==============================================================================
--- trunk/Model/Groups/KDTreeLoader.cc  (original)
+++ trunk/Model/Groups/KDTreeLoader.cc  Thu Feb  9 14:13:57 2006
@@ -530,7 +530,7 @@
 
///////////////////////////////////////////////////////////////////////////////
 
 // Given a file name, and a number of workers, load the specified file.
-int Manta::Kdtree::load( KDTree *kdtree, const char *fn, int np ) {
+int Manta::Kdtree::load( KDTreeData *kdtree, const char *fn, int np ) {
        
        // Time triangle load.
        double time_begin = Time::currentSeconds();

Modified: trunk/Model/Groups/KDTreeLoader.h
==============================================================================
--- trunk/Model/Groups/KDTreeLoader.h   (original)
+++ trunk/Model/Groups/KDTreeLoader.h   Thu Feb  9 14:13:57 2006
@@ -34,12 +34,12 @@
 namespace Manta {
   namespace Kdtree {
 
-    class KDTree;
+    class KDTreeData;
 
     // Load the specified file (and associated kdtree files) using the given
     // number of processors. For example if using model.v3c1, the files
     // model.v3c1.kd and model.v3c1.idx must be located in the same 
directory.
-    int load( KDTree *kdtree, const char *filename, int np );
+    int load( KDTreeData *kdtree, const char *filename, int np );
 
   };
 };

Modified: trunk/Model/Groups/SSEKDTree.cc
==============================================================================
--- trunk/Model/Groups/SSEKDTree.cc     (original)
+++ trunk/Model/Groups/SSEKDTree.cc     Thu Feb  9 14:13:57 2006
@@ -492,15 +492,10 @@
 // Simple kdtree functions.
 
///////////////////////////////////////////////////////////////////////////////
 
-SSEKDTree::SSEKDTree( KDTree *kdtree_, Material *material_ )
+SSEKDTree::SSEKDTree( KDTreeData *kdtree_, Material *material_ )
   : PrimitiveCommon( material_ ),
-    rootNode( kdtree_->rootNode ),
-    triIndices( kdtree_->triIndices ),
-    tris( kdtree_->tris ),
-    normals( kdtree_->normals )
-{
-  bbox.extendByBox( kdtree_->bbox );
-}
+    KDTreeData( kdtree_ ) { }
+
 SSEKDTree::~SSEKDTree() { };
 
 void SSEKDTree::computeNormal(const RenderContext& /*context*/,

Modified: trunk/Model/Groups/SSEKDTree.h
==============================================================================
--- trunk/Model/Groups/SSEKDTree.h      (original)
+++ trunk/Model/Groups/SSEKDTree.h      Thu Feb  9 14:13:57 2006
@@ -60,13 +60,13 @@
     // SSE KDTREE CLASS PROPER
     
///////////////////////////////////////////////////////////////////////////
     
///////////////////////////////////////////////////////////////////////////
-    class SSEKDTree : public PrimitiveCommon, public KDTreeDebug {
+    class SSEKDTree : public PrimitiveCommon, public KDTreeData {
     public:
-      typedef KDTree::ScratchPadInfo ScratchPadInfo;
+      typedef KDTreeData::ScratchPadInfo ScratchPadInfo;
 
       
/////////////////////////////////////////////////////////////////////////
       // Constructor.
-      SSEKDTree( KDTree *kdtree_, Material *material_ );      
+      SSEKDTree( KDTreeData *kdtree_, Material *material_ );      
       virtual ~SSEKDTree();
 
       
/////////////////////////////////////////////////////////////////////////
@@ -75,28 +75,8 @@
       void computeNormal (const RenderContext& context, RayPacket& rays) 
const;
       void computeBounds (const PreprocessContext&, BBox &box_ ) const;
       void computeBounds ( BBox &box_ ) const;
-
-      
/////////////////////////////////////////////////////////////////////////
-      // Accessors.
-      virtual void        setRootNode( KDTreeNode *node ) { rootNode = node; 
};
-      virtual KDTreeNode *getRootNode()                   { return rootNode; 
};      
-      virtual Triangle   &getFace( int index ) const      { return 
(*tris)[index]; };
-      virtual TextureCoord &getTextureCoord( int index ) const { return 
(texcoords)[index]; };
       
     private:
-      BBox bbox;
-      KDTreeNode       *rootNode;
-
-      VArray<int>      *triIndices;
-      VArray<Triangle> *tris;
-      TriangleNormal   *normals;
-      TextureCoord     *texcoords;
-
-                       VArray<int> *triToGroupMap;
-                       VArray<int> *groupToNameMap;
-                       VArray<char> *groupNames;
-                       VArray<unsigned char> *triFlags;
-
       // This method intersects a list of triangles with the rays.
       void intersectTriangles(IntersectPacket *intersect_packet,
                          const RayPacket &rays,

Modified: trunk/Model/Groups/TransparentKDTree.cc
==============================================================================
--- trunk/Model/Groups/TransparentKDTree.cc     (original)
+++ trunk/Model/Groups/TransparentKDTree.cc     Thu Feb  9 14:13:57 2006
@@ -91,27 +91,11 @@
 // CONSTRUCTOR  CONSTRUCTOR  CONSTRUCTOR  CONSTRUCTOR  CONSTRUCTOR  
CONSTRUCTOR
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
-TransparentKDTree::TransparentKDTree( KDTree *kdtree_, Material *material_,
+TransparentKDTree::TransparentKDTree( KDTreeData *kdtree_, Material 
*material_,
                                       Real sample_alpha_ ) :
   PrimitiveCommon( material_ ),
-  rootNode( kdtree_->rootNode ),
-  triIndices( kdtree_->triIndices ),
-  tris( kdtree_->tris ),
-  normals( kdtree_->normals ),
-  sample_alpha( sample_alpha_ ),
-  triToGroupMap(kdtree_->triToGroupMap),
-  groupToNameMap(kdtree_->groupToNameMap),
-  groupNames(kdtree_->groupNames),
-  __pickingEnabled(kdtree_->__pickingEnabled),
-  pickingEnabled(kdtree_->pickingEnabled),
-  pickedTri(kdtree_->pickedTri),
-  pickedBeginIndex(kdtree_->pickedBeginIndex),
-  pickedEndIndex(kdtree_->pickedEndIndex),
-  triFlags(kdtree_->triFlags),
-  pickedFlag(kdtree_->pickedFlag)
-{
-       bbox.extendByBox( kdtree_->bbox );
-}
+  KDTreeData( kdtree_ ),
+  sample_alpha( sample_alpha_ ) {}
 
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////

Modified: trunk/Model/Groups/TransparentKDTree.h
==============================================================================
--- trunk/Model/Groups/TransparentKDTree.h      (original)
+++ trunk/Model/Groups/TransparentKDTree.h      Thu Feb  9 14:13:57 2006
@@ -51,56 +51,24 @@
     // Note: Uses data structures defined in normal KDTree.h
     
///////////////////////////////////////////////////////////////////////////
     
///////////////////////////////////////////////////////////////////////////
-    class TransparentKDTree : public PrimitiveCommon, public KDTreeDebug {
-    private:
-      BBox bbox;
-
-      KDTreeNode       *rootNode;
-                       
-      VArray<int>      *triIndices;
-      VArray<Triangle> *tris;
-      TriangleNormal          *normals;
-      TextureCoord     *texcoords;
-
-      VArray<int> *triToGroupMap;
-      VArray<int> *groupToNameMap;
-      VArray<char> *groupNames;
-      bool __pickingEnabled;
-      bool pickingEnabled;
-      mutable long long pickedTri;
-      mutable int pickedBeginIndex, pickedEndIndex;
-      VArray<Color> pickedSavedColors;
-      VArray<unsigned char> *triFlags;
-      unsigned char pickedFlag;
+    class TransparentKDTree : public PrimitiveCommon, public KDTreeData {
 
     public:
-      const char *getPickedName() { 
-       if (pickedTri >= 0) return 
&(groupNames->get(groupToNameMap->get(triToGroupMap->get( pickedTri ))));
-       return (char *)"No selection";
-      }
-      void enablePicking() {
-       if (__pickingEnabled)
-         pickingEnabled = true;
-      }
-      void disablePicking() { pickingEnabled = false; }
-      bool isPickingEnabled() const 
-       { return pickingEnabled&&__pickingEnabled; }
-      void resetPicking() { 
-       pickedTri = -1; 
-       triFlags->clear();
-      }
-      void __setPicking(bool flag) { __pickingEnabled = flag; }
-
-      void setPickedFlag(unsigned char flag) { pickedFlag = flag; }
-      unsigned char getPickedFlag() { return pickedFlag; }
-
-      // Predeclaration for the benefit of functions that want to use it.
-                       class ScratchPadInfo;
+      // This structure is used to record info about the hit.
+      struct ScratchPadInfo : public KDTreeData::ScratchPadInfo {
+        Real alpha;    // Alpha of the ray (fully attenuated at alpha==1.0)
+        Real sample_t; // t value along ray of last sample blended.
+                               
+        inline void reset() {
+          payload  = Color(RGB(0.0,0.0,0.0));
+          alpha    = 0.0;
+          sample_t = 0.0;
+        }
+      };
       
     private:           
       Real sample_alpha;
 
-
       // This method intersects a list of triangles with the ray.
       int intersectTrianglesTransparent(const Pointf& origin,
                                         const Vectorf& direction,
@@ -121,10 +89,10 @@
       // This structure is used to order the triangle hits along the ray
       // before blending.
       struct Isect {
-       Real t, u, v;
-       int triIdx;
+        Real t, u, v;
+        int triIdx;
                                
-       inline bool operator < (const Isect &b) const { return t < b.t; }
+        inline bool operator < (const Isect &b) const { return t < b.t; }
       };
                        
       // Per thread buffers used to order samples for blending.
@@ -132,21 +100,10 @@
       static VArray<VArray<Isect> *> isectBuffers;
                        
     public:
-      // This structure is used to record info about the hit.
-      struct ScratchPadInfo : public KDTree::ScratchPadInfo {
-       Real alpha;    // Alpha of the ray (fully attenuated at alpha==1.0)
-       Real sample_t; // t value along ray of last sample blended.
-                               
-       inline void reset() {
-         payload  = Color(RGB(0.0,0.0,0.0));
-         alpha    = 0.0;
-         sample_t = 0.0;
-       }
-      };
                        
       // Constructor.
       // The transparent KDTree uses data owned by a normal KDTree.
-      TransparentKDTree( KDTree *kdtree_, Material *material_, Real 
sample_alpha_ = 0.9 );
+      TransparentKDTree( KDTreeData *kdtree_, Material *material_, Real 
sample_alpha_ = 0.9 );
                        
       void setAlpha( Real alpha_ ) { sample_alpha = alpha_; };
       Real getAlpha() const { return sample_alpha; };
@@ -159,10 +116,6 @@
       void computeBounds(const PreprocessContext &context, BBox &box_ ) 
const { box_.extendByBox( bbox ); }
       void computeBounds( BBox &box_ ) const { box_.extendByBox( bbox ); }
 
-      virtual void        setRootNode( KDTreeNode *node ) { rootNode = node; 
};
-      virtual KDTreeNode *getRootNode()                   { return rootNode; 
};
-      virtual Triangle   &getFace( int index ) const      { return 
(*tris)[index]; };
-      virtual TextureCoord &getTextureCoord( int index ) const { return 
(texcoords)[index]; };
     };
   }
 

Modified: trunk/Model/Groups/VerticalKDTree.cc
==============================================================================
--- trunk/Model/Groups/VerticalKDTree.cc        (original)
+++ trunk/Model/Groups/VerticalKDTree.cc        Thu Feb  9 14:13:57 2006
@@ -519,15 +519,10 @@
 // Simple kdtree functions.
 
///////////////////////////////////////////////////////////////////////////////
 
-VerticalKDTree::VerticalKDTree( KDTree *kdtree_, Material *material_ )
+VerticalKDTree::VerticalKDTree( KDTreeData *kdtree_, Material *material_ )
   : PrimitiveCommon( material_ ),
-    rootNode( kdtree_->rootNode ),
-    triIndices( kdtree_->triIndices ),
-    tris( kdtree_->tris ),
-    normals( kdtree_->normals )
-{
-  bbox.extendByBox( kdtree_->bbox );
-}
+    KDTreeData( kdtree_ ) { }
+
 VerticalKDTree::~VerticalKDTree() { };
 
 void VerticalKDTree::computeNormal(const RenderContext& /*context*/,

Modified: trunk/Model/Groups/VerticalKDTree.h
==============================================================================
--- trunk/Model/Groups/VerticalKDTree.h (original)
+++ trunk/Model/Groups/VerticalKDTree.h Thu Feb  9 14:13:57 2006
@@ -188,13 +188,13 @@
     // VERTICAL KDTREE CLASS PROPER
     
///////////////////////////////////////////////////////////////////////////
     
///////////////////////////////////////////////////////////////////////////
-    class VerticalKDTree : public PrimitiveCommon, public KDTreeDebug {
+    class VerticalKDTree : public PrimitiveCommon, public KDTreeData {
     public:
-      typedef KDTree::ScratchPadInfo ScratchPadInfo;
+      typedef KDTreeData::ScratchPadInfo ScratchPadInfo;
 
       
/////////////////////////////////////////////////////////////////////////
       // Constructor.
-      VerticalKDTree( KDTree *kdtree_, Material *material_ );      
+      VerticalKDTree( KDTreeData *kdtree_, Material *material_ );      
       virtual ~VerticalKDTree();
 
       
/////////////////////////////////////////////////////////////////////////
@@ -204,26 +204,7 @@
       void computeBounds (const PreprocessContext&, BBox &box_ ) const;
       void computeBounds ( BBox &box_ ) const;
 
-      
/////////////////////////////////////////////////////////////////////////
-      // Accessors.
-      virtual void        setRootNode( KDTreeNode *node ) { rootNode = node; 
};
-      virtual KDTreeNode *getRootNode()                   { return rootNode; 
};      
-      virtual Triangle   &getFace( int index ) const      { return 
(*tris)[index]; };
-      virtual TextureCoord &getTextureCoord( int index ) const { return 
(texcoords)[index]; };
-      
     private:
-      BBox bbox;
-      KDTreeNode       *rootNode;
-
-      VArray<int>      *triIndices;
-      VArray<Triangle> *tris;
-      TriangleNormal   *normals;
-      TextureCoord     *texcoords;
-
-                       VArray<int> *triToGroupMap;
-                       VArray<int> *groupToNameMap;
-                       VArray<char> *groupNames;
-                       VArray<unsigned char> *triFlags;
 
       // This method intersects a list of triangles with the rays.
       void intersectTriangles(IntersectPacket &intersect_packet,

Modified: trunk/fox/FManta/FMantaKdExplorer.cc
==============================================================================
--- trunk/fox/FManta/FMantaKdExplorer.cc        (original)
+++ trunk/fox/FManta/FMantaKdExplorer.cc        Thu Feb  9 14:13:57 2006
@@ -29,7 +29,7 @@
 
 
 FMantaKdExplorerDialog::FMantaKdExplorerDialog( FMantaWindow *manta_window_,
-                                                                             
                                  KDTreeDebug *kdtree_,
+                                                                             
                                  KDTreeData *kdtree_,
                                                                              
                                  const FXString &name, FXuint opts,
                                                                              
                                  FXint x,FXint y,FXint w,FXint h,FXint pl,
                                                                              
                                  FXint pr,FXint pt,FXint pb,FXint hs,FXint 
vs ) : 
@@ -103,7 +103,7 @@
   // Restore the root node.
   if (node_stack.size() > 0) {
     KDTreeNode *root = node_stack.front();
-    manta_interface->addTransaction( "Reset Root", Callback::create( kdtree, 
&KDTreeDebug::setRootNode, root ) );
+    manta_interface->addTransaction( "Reset Root", Callback::create( kdtree, 
&KDTreeData::setRootNode, root ) );
   }
 }
 
@@ -172,7 +172,7 @@
   manta_interface->addTransaction( "Update Plane", Callback::create( this, 
&FMantaKdExplorerDialog::updatePlane, bbox ) );
   
   // Update manta.
-  manta_interface->addTransaction( "Reset Root", Callback::create( kdtree, 
&KDTreeDebug::setRootNode, root ) );
+  manta_interface->addTransaction( "Reset Root", Callback::create( kdtree, 
&KDTreeData::setRootNode, root ) );
 
   // Update buttons.
   update_buttons();
@@ -189,7 +189,7 @@
     KDTreeNode *root = node_stack.back();
     
     // Update manta.
-    manta_interface->addTransaction( "Set Parent", Callback::create( kdtree, 
&KDTreeDebug::setRootNode, root ) );
+    manta_interface->addTransaction( "Set Parent", Callback::create( kdtree, 
&KDTreeData::setRootNode, root ) );
 
     // Update bbox and split plane.
     bbox_stack.pop_back();
@@ -219,7 +219,7 @@
     node_stack.push_back( child );
 
     // Update manta.
-    manta_interface->addTransaction( "Set Left", Callback::create( kdtree, 
&KDTreeDebug::setRootNode, child ) );
+    manta_interface->addTransaction( "Set Left", Callback::create( kdtree, 
&KDTreeData::setRootNode, child ) );
 
     // Update bbox and plane.
     BBox bbox = bbox_stack.back();
@@ -252,7 +252,7 @@
     node_stack.push_back( child );
 
     // Update manta.
-    manta_interface->addTransaction( "Set Right", Callback::create( kdtree, 
&KDTreeDebug::setRootNode, child ) );
+    manta_interface->addTransaction( "Set Right", Callback::create( kdtree, 
&KDTreeData::setRootNode, child ) );
 
     // Update bbox and plane.
     BBox bbox = bbox_stack.back();

Modified: trunk/fox/FManta/FMantaKdExplorer.h
==============================================================================
--- trunk/fox/FManta/FMantaKdExplorer.h (original)
+++ trunk/fox/FManta/FMantaKdExplorer.h Thu Feb  9 14:13:57 2006
@@ -41,7 +41,7 @@
     MantaInterface *manta_interface;
     
     // Target kdtree.
-    KDTreeDebug *kdtree;
+    KDTreeData *kdtree;
 
     // Information labels.
     FXLabel *depth_label;
@@ -77,7 +77,7 @@
     
     FMantaKdExplorerDialog() {  };
     FMantaKdExplorerDialog( FMantaWindow *manta_window_,
-                            KDTreeDebug *kdtree_,
+                            KDTreeData *kdtree_,
                   const FXString &name, FXuint opts=DECOR_ALL,
                   FXint x=50,FXint y=50,FXint w=0,FXint h=0,FXint pl=10,
                   FXint pr=10,FXint pt=10,FXint pb=10,FXint hs=4,FXint vs=4 
);

Modified: trunk/fox/afr_demo/Engine/ImageTraversers/AFRImageTraverser.cc
==============================================================================
--- trunk/fox/afr_demo/Engine/ImageTraversers/AFRImageTraverser.cc      
(original)
+++ trunk/fox/afr_demo/Engine/ImageTraversers/AFRImageTraverser.cc      Thu 
Feb  9 14:13:57 2006
@@ -44,7 +44,7 @@
     }
     if(tv!=NULL && validinfo[i])
     {
-      const Kdtree::KDTreeDebug *kdtree = dynamic_cast<const 
Kdtree::KDTreeDebug *>(
+      const Kdtree::KDTreeData *kdtree = dynamic_cast<const 
Kdtree::KDTreeData *>(
           rays.getHitPrimitive(i) );
       if (kdtree) {
         int face_index = 
rays.scratchpad<Kdtree::KDTree::ScratchPadInfo>(i).hit_index;
@@ -67,6 +67,9 @@
         tv[i].v3[0] = rp.x()*xres;
         tv[i].v3[1] = rp.y()*yres;
         tv[i].v3[2] = rp.z();
+      }
+      else {
+        std::cerr << "Not using KDTreeData: " << __FILE__ << ":" << __LINE__ 
<< "\n";
       }
     }
   }

Modified: trunk/fox/dm_demo/dm_demo.cc
==============================================================================
--- trunk/fox/dm_demo/dm_demo.cc        (original)
+++ trunk/fox/dm_demo/dm_demo.cc        Thu Feb  9 14:13:57 2006
@@ -325,8 +325,8 @@
     }
 
     // Add a kdtree debugger.
-    KDTreeDebug *kdtree_debug = 0;
-    if ((kdtree_debug = dynamic_cast<KDTreeDebug *>( root_object ))) {
+    KDTreeData *kdtree_debug = 0;
+    if ((kdtree_debug = dynamic_cast<KDTreeData *>( root_object ))) {
 
       // Create a kdtree explorer dialog.
       manta_window.addExtraOptionsDialog( "kd-Tree Explorer",

Modified: trunk/scenes/boeing777.cc
==============================================================================
--- trunk/scenes/boeing777.cc   (original)
+++ trunk/scenes/boeing777.cc   Thu Feb  9 14:13:57 2006
@@ -237,7 +237,20 @@
                                                          
scene_ambient[2]))));
        scene->setLights(lights);
 
-  
+
+       
/////////////////////////////////////////////////////////////////////////////
+       // Load the kdtree.
+       double start_time = Time::currentSeconds();
+
+  KDTreeData *kdtree_data = new KDTreeData();
+       Kdtree::load( kdtree_data, file_name.c_str(), workers_np );
+       
+       double end_time = Time::currentSeconds();
+       
+       std::cerr << "Total load time: " << (end_time-start_time)/60.0 << " 
minutes." 
+                 << std::endl << std::endl;
+
+/////////////////////////////////////////////////////////////////////////////
  
   // Choose a material.
   Material *kd_material = 0;
   switch (material_type) {
@@ -278,48 +291,41 @@
     kd_material = new Transparent( new KDTreeTexture(), new 
WireframeTexture<KDTree::ScratchPadInfo,ColorComponent>( (ColorComponent)0.1, 
(ColorComponent)1.0) );
     break;
   };
-       
-       KDTree *kdtree = new KDTree( kd_material );
-                                                                             
                                                                              
                                    
-       // KDTree *kdtree = new KDTree( new LambertianAlt );
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       // Load the kdtree.
-       double start_time = Time::currentSeconds();
-       
-       Kdtree::load( kdtree, file_name.c_str(), workers_np );
-       
-       double end_time = Time::currentSeconds();
-       
-       std::cerr << "Total load time: " << (end_time-start_time)/60.0 << " 
minutes." 
-                 << std::endl << std::endl;
-       
+                                                                             
                                                                              
                                            
        
/////////////////////////////////////////////////////////////////////////////
        // Determine the bounds of the model.
        BBox bounds;
-       kdtree->computeBounds( bounds );
+       kdtree_data->computeBounds( bounds );
        
        // Determine if we should start with a transparent kdtree or not.
-       Primitive *kd_primitive = kdtree;
+       Primitive *kd_primitive = 0;
   if (traversal == TRAVERSAL_SINGLE) {
     if (use_transparency) {
-      TransparentKDTree *transparent = new TransparentKDTree( kdtree,
-                                                              // Just copy 
the color out of the
-                                                              // hit info.
+      TransparentKDTree *transparent = new TransparentKDTree( kdtree_data,
                                                               new Flat( new 
KDTreeTexture ) );
       transparent->setAlpha( alpha );
       kd_primitive = transparent;
     }
+    else {
+      // Create a single ray traversal kdtree. (default).
+      kd_primitive = new KDTree( kdtree_data, kd_material );      
+    }
   }
   else if (traversal == TRAVERSAL_VERTICAL) {
     // Create a vertical kdtree.
-    kd_primitive = new VerticalKDTree( kdtree, kd_material );
+    kd_primitive = new VerticalKDTree( kdtree_data, kd_material );
   }
   else if (traversal == TRAVERSAL_SSE) {
     // Create a sse kdtree.
-    kd_primitive = new SSEKDTree( kdtree, kd_material );
+    kd_primitive = new SSEKDTree( kdtree_data, kd_material );
   }
-       
+  else {
+    std::cerr << "Traversal not supported\n";
+  }
+
+  assert( kd_primitive );
+
+  
        
////////////////////////////////////////////////////////////////////////////
        // Compute the middle of the model for a cutting plane.
        if (cutting_type == CUTTING_DEFAULT) {
@@ -338,7 +344,7 @@
        else { 
                root_object = kd_primitive;
        }
-       
+
        
        // Add the tree to the scene.
        scene->setObject( root_object );




  • [MANTA] r915 - in trunk: Core Core/Util Model/Groups fox/FManta fox/afr_demo/Engine/ImageTraversers fox/dm_demo scenes, abe, 02/09/2006

Archive powered by MHonArc 2.6.16.

Top of page