gKitGL
bvh_private.h
00001 
00002 /*
00003     pbrt source code Copyright(c) 1998-2010 Matt Pharr and Greg Humphreys.
00004 
00005     This file is part of pbrt.
00006 
00007     pbrt is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.  Note that the text contents of
00011     the book "Physically Based Rendering" are *not* licensed under the
00012     GNU GPL.
00013 
00014     pbrt is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022  */
00023 
00024 #ifndef _BVH_PRIVATE_H
00025 #define _BVH_PRIVATE_H
00026 
00027 #include "Geometry.h"
00028 
00029 //! utilisation interne. construction d'un bvh.
00030 struct BVHPrimitiveInfo
00031 {
00032     BBox bounds;
00033     Point centroid;
00034     int primitiveNumber;
00035     
00036     BVHPrimitiveInfo() { }
00037     
00038     BVHPrimitiveInfo( int pn, const BBox &b )
00039         :
00040         bounds(b),
00041         centroid(bounds.getCenter()),
00042         primitiveNumber(pn)
00043     {}
00044 };
00045 
00046 //! utilisation interne. construction d'un bvh.
00047 struct BVHBuildNode
00048 {
00049     BBox bounds;
00050     BVHBuildNode *children[2];
00051     uint32_t splitAxis, firstPrimOffset, nPrimitives;
00052 
00053     // BVHBuildNode Public Methods
00054     BVHBuildNode() 
00055     { 
00056         children[0] = children[1] = NULL; 
00057     }
00058     
00059     void InitLeaf( uint32_t first, uint32_t n, const BBox &b )
00060     {
00061         firstPrimOffset = first;
00062         nPrimitives = n;
00063         bounds = b;
00064     }
00065     
00066     void InitInterior( uint32_t axis, BVHBuildNode *c0, BVHBuildNode *c1 )
00067     {
00068         children[0] = c0;
00069         children[1] = c1;
00070         bounds = Union( c0->bounds, c1->bounds );
00071         splitAxis = axis;
00072         nPrimitives = 0;
00073     }
00074 };
00075 
00076 //! utilisation interne. construction d'un bvh.
00077 struct CompareToMid
00078 {
00079     int dim;
00080     float mid;
00081     
00082     CompareToMid( int d, float m )
00083         :
00084         dim(d),
00085         mid(m)
00086     {}
00087     
00088     bool operator( )( const BVHPrimitiveInfo &a ) const
00089     {
00090         return a.centroid[dim] < mid;
00091     }
00092 };
00093 
00094 //! utilisation interne. construction d'un bvh.
00095 struct ComparePoints
00096 {
00097     int dim;
00098 
00099     ComparePoints( int d )
00100         :
00101         dim(d)
00102     {}
00103     
00104     bool operator( )( const BVHPrimitiveInfo &a, const BVHPrimitiveInfo &b ) const
00105     {
00106         return a.centroid[dim] < b.centroid[dim];
00107     }
00108 };
00109 
00110 //! utilisation interne. construction d'un bvh.
00111 struct CompareToBucket
00112 {
00113     int splitBucket, nBuckets, dim;
00114     const BBox &centroidBounds;
00115 
00116     CompareToBucket( int split, int num, int d, const BBox &b )
00117         : 
00118         centroidBounds( b )
00119     { 
00120         splitBucket = split; 
00121         nBuckets = num; 
00122         dim = d; 
00123     }
00124     
00125     bool operator( )( const BVHPrimitiveInfo &p ) const
00126     {
00127         int b = nBuckets * (( p.centroid[dim] - centroidBounds.pMin[dim] ) /
00128             ( centroidBounds.pMax[dim] - centroidBounds.pMin[dim] ) );
00129         if ( b == nBuckets ) 
00130             b = nBuckets - 1;
00131         assert( b >= 0 && b < nBuckets );
00132         return b <= splitBucket;
00133     }
00134     
00135 };
00136 
00137 //! utilisation interne. representation d'un noeud d'un bvh.
00138 struct LinearBVHNode
00139 {
00140     BBox bounds;
00141     
00142     union
00143     {
00144         uint32_t primitivesOffset;    // leaf
00145         uint32_t secondChildOffset;   // interior
00146     };
00147     
00148     uint8_t nPrimitives;  // 0 -> interior node
00149     uint8_t axis;         // interior node: xyz
00150     uint8_t pad[2];       // ensure 32 byte total size
00151 };
00152 
00153 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends