#include <Octree.h>
Collaboration diagram for pge::OctreeNode:
Public Member Functions | |
OctreeNode (AABB *boundingBox, int minMeshsPerNode, bool occlusionCulling) | |
Constructor. | |
virtual | ~OctreeNode (void) |
Destructor. | |
void | initRootNode (std::vector< Mesh * > *meshs) |
int | getMeshNum (void) |
void | render (void) |
void | renderWireframe (void) |
Private Member Functions | |
void | subdivide (std::vector< Mesh * > meshs) |
void | addMesh (Mesh *mesh) |
void | addMeshs (std::vector< Mesh * > *meshs) |
Private Attributes | |
AABB * | m_boundingBox |
OctreeNode ** | m_nodes |
std::vector< Mesh * > * | m_meshs |
int | m_minMeshsPerNode |
bool | m_occlusionCulling |
|
Constructor.
Definition at line 21 of file Octree.cpp. References m_boundingBox, m_meshs, m_minMeshsPerNode, m_nodes, and m_occlusionCulling. Referenced by subdivide().
00021 { 00022 int i; 00023 00024 00025 m_boundingBox = boundingBox; 00026 m_minMeshsPerNode = minMeshsPerNode; 00027 m_occlusionCulling = occlusionCulling; 00028 00029 m_meshs = new std::vector<Mesh*>(); 00030 00031 m_nodes = new OctreeNode*[8]; 00032 00033 for(i = 0; i < 8; i++) { 00034 m_nodes[i] = NULL; 00035 } 00036 } |
|
Destructor.
Definition at line 44 of file Octree.cpp. References m_boundingBox, m_meshs, and m_nodes.
00044 { 00045 int i; 00046 00047 00048 if(m_boundingBox != NULL) { 00049 delete m_boundingBox; 00050 m_boundingBox = NULL; 00051 } 00052 00053 if(m_meshs != NULL) { 00054 delete m_meshs; 00055 m_meshs = NULL; 00056 } 00057 00058 for(i = 0; i < 8; i++) { 00059 if(m_nodes[i] != NULL) { 00060 delete m_nodes[i]; 00061 m_nodes[i] = NULL; 00062 } 00063 } 00064 } |
|
Definition at line 275 of file Octree.cpp. References m_meshs. Referenced by addMeshs(), and subdivide().
00275 { 00276 m_meshs->push_back(mesh); 00277 } |
|
Definition at line 285 of file Octree.cpp. References addMesh(). Referenced by subdivide().
00285 { 00286 std::vector<Mesh*>::iterator it; 00287 00288 00289 for(it = meshs->begin(); it != meshs->end(); it++) { 00290 addMesh(*it); 00291 } 00292 } |
Here is the call graph for this function:
|
Definition at line 84 of file Octree.cpp. References m_meshs.
00084 { 00085 return (int)m_meshs->size(); 00086 } |
|
Definition at line 72 of file Octree.cpp. References subdivide(). Referenced by pge::Octree::init().
00072 { 00073 if(meshs != NULL) { 00074 subdivide(*meshs); 00075 } 00076 } |
Here is the call graph for this function:
|
Definition at line 94 of file Octree.cpp. References pge::Mesh::getBoundingBox(), m_boundingBox, m_meshs, m_nodes, m_occlusionCulling, and pge::Mesh::render(). Referenced by pge::Octree::render().
00094 { 00095 int i; 00096 bool visible = true; 00097 std::vector<Mesh*>::iterator it; 00098 00099 00100 // Perform frustum culling. 00101 if(CoreEngine::getInstance()->getCurrentWorld()->getFrustum()->isAABBInside(m_boundingBox)) { 00102 00103 // Add one visible octree node count. 00104 //SceneAnalyseGUI.getInstance().addVisibleNodeCount(1); 00105 00106 // Perform occlusion culling if enabled. 00107 if(!m_occlusionCulling) { 00108 visible = true; 00109 } else { 00110 if(occlusionquery::occlusionQuery(m_boundingBox) > 0) { 00111 visible = true; 00112 } else { 00113 visible = false; 00114 //SceneAnalyseGUI.getInstance().addOcclusionCulledNodeCount(1); 00115 } 00116 } 00117 00118 if(visible) { 00119 for(it = m_meshs->begin(); it != m_meshs->end(); it++) { 00120 Mesh *mesh = *it; 00121 00122 if(CoreEngine::getInstance()->getCurrentWorld()->getFrustum()->isAABBInside(mesh->getBoundingBox())) { 00123 mesh->render(); 00124 //SceneAnalyseGUI.getInstance().addVisibleTriangleCount(mesh.getTriangleNum()); 00125 //SceneAnalyseGUI.getInstance().addVisibleMeshCount(1); 00126 } 00127 } 00128 00129 for(i = 0; i < 8; i++) { 00130 if(m_nodes[i] != NULL) { 00131 m_nodes[i]->render(); 00132 } 00133 } 00134 } 00135 } 00136 } |
Here is the call graph for this function:
|
Definition at line 144 of file Octree.cpp. References m_boundingBox, m_nodes, and pge::AABB::renderWireframe().
00144 { 00145 int i; 00146 00147 00148 m_boundingBox->renderWireframe(Vector3f(1.0f, 0.0f, 0.0f)); 00149 00150 for(i = 0; i < 8; i++) { 00151 if(m_nodes[i] != NULL) { 00152 m_nodes[i]->renderWireframe(); 00153 } 00154 } 00155 } |
Here is the call graph for this function:
|
Definition at line 163 of file Octree.cpp. References addMesh(), addMeshs(), pge::Mesh::getBoundingBox(), pge::AABB::isAABBCompletelyInside(), m_boundingBox, pge::AABB::m_maxX, pge::AABB::m_maxY, pge::AABB::m_maxZ, m_minMeshsPerNode, pge::AABB::m_minX, pge::AABB::m_minY, pge::AABB::m_minZ, m_nodes, m_occlusionCulling, OCTREE_NODE_MAXX_MAXY_MAXZ, OCTREE_NODE_MAXX_MAXY_MINZ, OCTREE_NODE_MAXX_MINY_MAXZ, OCTREE_NODE_MAXX_MINY_MINZ, OCTREE_NODE_MINX_MAXY_MAXZ, OCTREE_NODE_MINX_MAXY_MINZ, OCTREE_NODE_MINX_MINY_MAXZ, OCTREE_NODE_MINX_MINY_MINZ, and OctreeNode(). Referenced by initRootNode().
00163 { 00164 AABB boundingBoxes[8]; 00165 std::vector<Mesh*> meshLists[8]; 00166 float halfX; 00167 float halfY; 00168 float halfZ; 00169 int i; 00170 bool meshDone; 00171 std::vector<Mesh*>::iterator it; 00172 00173 00174 halfX = (m_boundingBox->m_maxX - m_boundingBox->m_minX) / 2.0f; 00175 halfY = (m_boundingBox->m_maxY - m_boundingBox->m_minY) / 2.0f; 00176 halfZ = (m_boundingBox->m_maxZ - m_boundingBox->m_minZ) / 2.0f; 00177 00178 // Create the boxes. 00179 // Boxes in the back (minZ). 00180 boundingBoxes[OCTREE_NODE_MINX_MINY_MINZ] = AABB(m_boundingBox->m_minX, 00181 m_boundingBox->m_minY, m_boundingBox->m_minZ, m_boundingBox->m_minX + halfX, 00182 m_boundingBox->m_minY + halfY, m_boundingBox->m_minZ + halfZ); 00183 00184 boundingBoxes[OCTREE_NODE_MAXX_MINY_MINZ] = AABB(m_boundingBox->m_minX + halfX, 00185 m_boundingBox->m_minY, m_boundingBox->m_minZ, m_boundingBox->m_maxX, 00186 m_boundingBox->m_minY + halfY, m_boundingBox->m_minZ + halfZ); 00187 00188 boundingBoxes[OCTREE_NODE_MINX_MAXY_MINZ] = AABB(m_boundingBox->m_minX, m_boundingBox->m_minY 00189 + halfY, m_boundingBox->m_minZ, m_boundingBox->m_minX + halfX, m_boundingBox->m_maxY, 00190 m_boundingBox->m_minZ + halfZ); 00191 00192 boundingBoxes[OCTREE_NODE_MAXX_MAXY_MINZ] = AABB(m_boundingBox->m_minX + halfX, 00193 m_boundingBox->m_minY + halfY, m_boundingBox->m_minZ, m_boundingBox->m_maxX, 00194 m_boundingBox->m_maxY, m_boundingBox->m_minZ + halfZ); 00195 00196 // Boxes in the front (maxZ). 00197 boundingBoxes[OCTREE_NODE_MINX_MINY_MAXZ] = AABB(m_boundingBox->m_minX, 00198 m_boundingBox->m_minY, m_boundingBox->m_minZ + halfZ, m_boundingBox->m_minX + halfX, 00199 m_boundingBox->m_minY + halfY, m_boundingBox->m_maxZ); 00200 00201 boundingBoxes[OCTREE_NODE_MAXX_MINY_MAXZ] = AABB(m_boundingBox->m_minX + halfX, 00202 m_boundingBox->m_minY, m_boundingBox->m_minZ + halfZ, m_boundingBox->m_maxX, 00203 m_boundingBox->m_minY + halfY, m_boundingBox->m_maxZ); 00204 00205 boundingBoxes[OCTREE_NODE_MINX_MAXY_MAXZ] = AABB(m_boundingBox->m_minX, m_boundingBox->m_minY 00206 + halfY, m_boundingBox->m_minZ + halfZ, m_boundingBox->m_minX + halfX, 00207 m_boundingBox->m_maxY, m_boundingBox->m_maxZ); 00208 00209 boundingBoxes[OCTREE_NODE_MAXX_MAXY_MAXZ] = AABB(m_boundingBox->m_minX + halfX, 00210 m_boundingBox->m_minY + halfY, m_boundingBox->m_minZ + halfZ, m_boundingBox->m_maxX, 00211 m_boundingBox->m_maxY, m_boundingBox->m_maxZ); 00212 00213 00214 // Loop through the meshes of this node. 00215 // These could be distributed to the new nodes. 00216 for(it = meshs.begin(); it != meshs.end(); it++) { 00217 // Get the current mesh. It may later be added 00218 // to the new node's list. 00219 Mesh *mesh = *it; 00220 00221 meshDone = false; 00222 00223 // Go through each of the AABBs of the new nodes. 00224 for(i = 0; (i < 8) && !meshDone; i++) { 00225 00226 // Check if the mesh is completely inside the boundingbox. 00227 if(boundingBoxes[i].isAABBCompletelyInside(mesh->getBoundingBox())) { 00228 00229 // If the new node was not created before, do it now. 00230 if(m_nodes[i] == NULL) { 00231 // Create the node. 00232 m_nodes[i] = new OctreeNode(new AABB(boundingBoxes[i]), m_minMeshsPerNode, m_occlusionCulling); 00233 00234 // TODO 00235 //SceneAnalyseGUI.getInstance().setNodeCount(SceneAnalyseGUI.getInstance().getNodeCount() + 1); 00236 } 00237 00238 // If the mesh is inside of this box it can not be inside of any other 00239 // box. So add reference of the mesh to the new node's mesh list. 00240 meshLists[i].push_back(mesh); 00241 00242 // The mesh was already handled, so set this to true. 00243 meshDone = true; 00244 } 00245 } 00246 00247 // If the mesh was not completely inside of the new nodes, 00248 // add it to this node. 00249 if(!meshDone) { 00250 addMesh(mesh); 00251 } 00252 } 00253 00254 // Recursion for octree. 00255 for(i = 0; i < 8; i++) { 00256 if(m_nodes[i] != NULL) { 00257 if(meshLists[i].size() >= m_minMeshsPerNode) { 00258 // Subdivide the mesh, if there are enough meshs in the new node's list. 00259 m_nodes[i]->subdivide(meshLists[i]); 00260 } else { 00261 // When the node can't be subdivided, add all meshs of the node's list to the mesh. 00262 // The list here is just a temporary memory and will be deleted at the end of this function. 00263 m_nodes[i]->addMeshs(&meshLists[i]); 00264 } 00265 } 00266 } 00267 } |
Here is the call graph for this function:
|
Definition at line 78 of file Octree.h. Referenced by OctreeNode(), render(), renderWireframe(), subdivide(), and ~OctreeNode(). |
|
Definition at line 80 of file Octree.h. Referenced by addMesh(), getMeshNum(), OctreeNode(), render(), and ~OctreeNode(). |
|
Definition at line 81 of file Octree.h. Referenced by OctreeNode(), and subdivide(). |
|
Definition at line 79 of file Octree.h. Referenced by OctreeNode(), render(), renderWireframe(), subdivide(), and ~OctreeNode(). |
|
Definition at line 82 of file Octree.h. Referenced by OctreeNode(), render(), and subdivide(). |