#include <Quadtree.h>
Collaboration diagram for pge::QuadtreeNode:
Public Member Functions | |
QuadtreeNode (AABB *boundingBox, int minMeshsPerNode, bool occlusionCulling) | |
Constructor. | |
virtual | ~QuadtreeNode (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 |
QuadtreeNode ** | m_nodes |
std::vector< Mesh * > * | m_meshs |
int | m_minMeshsPerNode |
bool | m_occlusionCulling |
|
Constructor.
Definition at line 21 of file Quadtree.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 QuadtreeNode*[4]; 00032 00033 for(i = 0; i < 4; i++) { 00034 m_nodes[i] = NULL; 00035 } 00036 } |
|
Destructor.
Definition at line 44 of file Quadtree.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 < 4; i++) { 00059 if(m_nodes[i] != NULL) { 00060 delete m_nodes[i]; 00061 m_nodes[i] = NULL; 00062 } 00063 } 00064 } |
|
Definition at line 256 of file Quadtree.cpp. References m_meshs. Referenced by addMeshs(), and subdivide().
00256 { 00257 m_meshs->push_back(mesh); 00258 } |
|
Definition at line 266 of file Quadtree.cpp. References addMesh(). Referenced by subdivide().
00266 { 00267 std::vector<Mesh*>::iterator it; 00268 00269 00270 for(it = meshs->begin(); it != meshs->end(); it++) { 00271 addMesh(*it); 00272 } 00273 } |
Here is the call graph for this function:
|
Definition at line 84 of file Quadtree.cpp. References m_meshs.
00084 { 00085 return (int)m_meshs->size(); 00086 } |
|
Definition at line 72 of file Quadtree.cpp. References subdivide(). Referenced by pge::Quadtree::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 Quadtree.cpp. References pge::Mesh::getBoundingBox(), m_boundingBox, m_meshs, m_nodes, m_occlusionCulling, and pge::Mesh::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 < 4; 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 Quadtree.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 < 4; 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 Quadtree.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, QUADTREE_NODE_MAXX_MAXZ, QUADTREE_NODE_MAXX_MINZ, QUADTREE_NODE_MINX_MAXZ, QUADTREE_NODE_MINX_MINZ, and QuadtreeNode(). Referenced by initRootNode().
00163 { 00164 AABB boundingBoxes[4]; 00165 std::vector<Mesh*> meshLists[4]; 00166 float halfX; 00167 float halfZ; 00168 int i; 00169 bool meshDone; 00170 std::vector<Mesh*>::iterator it; 00171 00172 00173 halfX = (m_boundingBox->m_maxX - m_boundingBox->m_minX) / 2.0f; 00174 halfZ = (m_boundingBox->m_maxZ - m_boundingBox->m_minZ) / 2.0f; 00175 00176 // Create the boxes. 00177 // Boxes in the back (minZ). 00178 boundingBoxes[QUADTREE_NODE_MINX_MINZ] = AABB(m_boundingBox->m_minX, m_boundingBox->m_minY, 00179 m_boundingBox->m_minZ, m_boundingBox->m_minX + halfX, m_boundingBox->m_maxY, 00180 m_boundingBox->m_minZ + halfZ); 00181 00182 boundingBoxes[QUADTREE_NODE_MAXX_MINZ] = AABB(m_boundingBox->m_minX + halfX, 00183 m_boundingBox->m_minY, m_boundingBox->m_minZ, m_boundingBox->m_maxX, 00184 m_boundingBox->m_maxY, m_boundingBox->m_minZ + halfZ); 00185 00186 // Boxes in the front (maxZ). 00187 boundingBoxes[QUADTREE_NODE_MINX_MAXZ] = AABB(m_boundingBox->m_minX, m_boundingBox->m_minY, 00188 m_boundingBox->m_minZ + halfZ, m_boundingBox->m_minX + halfX, m_boundingBox->m_maxY, 00189 m_boundingBox->m_maxZ); 00190 00191 boundingBoxes[QUADTREE_NODE_MAXX_MAXZ] = AABB(m_boundingBox->m_minX + halfX, 00192 m_boundingBox->m_minY, m_boundingBox->m_minZ + halfZ, m_boundingBox->m_maxX, 00193 m_boundingBox->m_maxY, m_boundingBox->m_maxZ); 00194 00195 // Loop through the meshes of this node. 00196 // These could be distributed to the new nodes. 00197 for(it = meshs.begin(); it != meshs.end(); it++) { 00198 // Get the current mesh. It may later be added 00199 // to the new node's list. 00200 Mesh *mesh = *it; 00201 00202 meshDone = false; 00203 00204 // Go through each of the AABBs of the new nodes. 00205 for(i = 0; (i < 4) && !meshDone; i++) { 00206 00207 // Check if the mesh is completely inside the boundingbox. 00208 if(boundingBoxes[i].isAABBCompletelyInside(mesh->getBoundingBox())) { 00209 00210 // If the new node was not created before, do it now. 00211 if(m_nodes[i] == NULL) { 00212 // Create the node. 00213 m_nodes[i] = new QuadtreeNode(new AABB(boundingBoxes[i]), m_minMeshsPerNode, m_occlusionCulling); 00214 00215 // TODO 00216 //SceneAnalyseGUI.getInstance().setNodeCount(SceneAnalyseGUI.getInstance().getNodeCount() + 1); 00217 } 00218 00219 // If the mesh is inside of this box it can not be inside of any other 00220 // box. So add reference of the mesh to the new node's mesh list. 00221 meshLists[i].push_back(mesh); 00222 00223 // The mesh was already handled, so set this to true. 00224 meshDone = true; 00225 } 00226 } 00227 00228 // If the mesh was not completely inside of the new nodes, 00229 // add it to this node. 00230 if(!meshDone) { 00231 addMesh(mesh); 00232 } 00233 } 00234 00235 // Recursion for quadtree. 00236 for(i = 0; i < 4; i++) { 00237 if(m_nodes[i] != NULL) { 00238 if(meshLists[i].size() >= m_minMeshsPerNode) { 00239 // Subdivide the mesh, if there are enough meshs in the new node's list. 00240 m_nodes[i]->subdivide(meshLists[i]); 00241 } else { 00242 // When the node can't be subdivided, add all meshs of the node's list to the mesh. 00243 // The list here is just a temporary memory and will be deleted at the end of this function. 00244 m_nodes[i]->addMeshs(&meshLists[i]); 00245 } 00246 } 00247 } 00248 } |
Here is the call graph for this function:
|
Definition at line 74 of file Quadtree.h. Referenced by QuadtreeNode(), render(), renderWireframe(), subdivide(), and ~QuadtreeNode(). |
|
Definition at line 76 of file Quadtree.h. Referenced by addMesh(), getMeshNum(), QuadtreeNode(), render(), and ~QuadtreeNode(). |
|
Definition at line 77 of file Quadtree.h. Referenced by QuadtreeNode(), and subdivide(). |
|
Definition at line 75 of file Quadtree.h. Referenced by QuadtreeNode(), render(), renderWireframe(), subdivide(), and ~QuadtreeNode(). |
|
Definition at line 78 of file Quadtree.h. Referenced by QuadtreeNode(), render(), and subdivide(). |