GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_octree.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
23 
24 #include "glc_octree.h"
25 #include "glc_octreenode.h"
26 #include "glc_3dviewcollection.h"
27 #include "../glc_factory.h"
28 
30 
32 : GLC_SpacePartitioning(pCollection)
33 , m_pRootNode(NULL)
34 , m_OctreeDepth(m_DefaultOctreeDepth)
35 {
36 
37 
38 }
39 
41 : GLC_SpacePartitioning(octree)
42 , m_pRootNode(NULL)
43 , m_OctreeDepth(octree.m_OctreeDepth)
44 {
45  if (NULL != octree.m_pRootNode)
46  {
47  m_pRootNode= new GLC_OctreeNode(*(octree.m_pRootNode));
48  }
49 }
50 
52 {
53  delete m_pRootNode;
54 }
55 
57 {
58  return m_DefaultOctreeDepth;
59 }
60 
61 QList<GLC_3DViewInstance*> GLC_Octree::listOfIntersectedInstances(const GLC_BoundingBox& bBox)
62 {
63  if (NULL == m_pRootNode)
64  {
66  }
67  return m_pRootNode->setOfIntersectedInstances(bBox).toList();
68 }
69 
71 {
72  if (NULL == m_pRootNode)
73  {
75  }
77 }
78 
80 {
81  delete m_pRootNode;
83  // fill the octree
84  QList<GLC_3DViewInstance*> instanceList(m_pCollection->instancesHandle());
85  const int size= instanceList.size();
86  for (int i= 0; i < size; ++i)
87  {
88  m_pRootNode->addInstance(instanceList.at(i), m_OctreeDepth);
89  }
91 }
92 
94 {
95  delete m_pRootNode;
96  m_pRootNode= NULL;
97 }
98 
99 void GLC_Octree::setDepth(int depth)
100 {
101  m_OctreeDepth= depth;
102  if (NULL != m_pRootNode)
103  {
105  }
106 }
107 
109 {
110  if (NULL == m_pRootNode)
111  {
113  }
114 
115  if (NULL == pCol) pCol= m_pCollection;
116  if (!m_pRootNode->isEmpty())
117  {
118  createBoxWithMaterial(pCol, m_pRootNode, pMat);
119  }
120 }
121 
123 {
124  m_DefaultOctreeDepth= depth;
125 }
126 
128 {
129  if (!pNode->isEmpty())
130  {
131  if (pNode->hasGeometry())
132  {
134  box.geomAt(0)->replaceMasterMaterial(pMat);
135  pCol->add(box);
136  }
137 
138  if (pNode->hasChild())
139  {
140  const int size= pNode->childCount();
141  for (int i= 0; i < size; ++i)
142  {
143  createBoxWithMaterial(pCol, pNode->childAt(i), pMat);
144  }
145  }
146 
147  }
148 
149 }
150 

©2005-2013 Laurent Ribon