20 #ifndef _STELSPHERICALINDEX_HPP_
21 #define _STELSPHERICALINDEX_HPP_
23 #include "StelRegionObject.hpp"
34 void insert(StelRegionObjectP obj);
39 rootNode->processIntersectingRegions(region, func);
45 rootNode->processBoundingCapIntersectingRegions(cap, func);
51 rootNode->processContainedRegions(region, func);
55 template<
class FuncObject>
void processAll(FuncObject& func)
const
57 rootNode->processAll(func);
70 processAll<CountFunc>(func);
77 CountFunc() : nb(0) {;}
89 NodeElem(StelRegionObjectP aobj) : obj(aobj), cap(obj->getRegion()->getBoundingCap()) {;}
90 StelRegionObjectP obj;
100 QVector<NodeElem> elements;
101 QVector<Node> children;
107 Q_ASSERT(children.empty());
108 Q_ASSERT(triangle.getConvexContour().size() == 3);
110 const Vec3d& c0 = triangle.getConvexContour().at(0);
111 const Vec3d& c1 = triangle.getConvexContour().at(1);
112 const Vec3d& c2 = triangle.getConvexContour().at(2);
114 Q_ASSERT((c1^c0)*c2 >= 0.0);
115 Vec3d e0(c1[0]+c2[0], c1[1]+c2[1], c1[2]+c2[2]);
117 Vec3d e1(c2[0]+c0[0], c2[1]+c0[1], c2[2]+c0[2]);
119 Vec3d e2(c0[0]+c1[0], c0[1]+c1[1], c0[2]+c1[2]);
124 Q_ASSERT(children[0].triangle.checkValid());
126 Q_ASSERT(children[1].triangle.checkValid());
128 Q_ASSERT(children[2].triangle.checkValid());
130 Q_ASSERT(children[3].triangle.checkValid());
143 class RootNode :
public Node
146 RootNode(
int amaxObjectsPerNode,
int amaxLevel) : maxObjectsPerNode(amaxObjectsPerNode), maxLevel(amaxLevel)
153 static const Vec3d vertice[6] =
155 Vec3d(0,0,1),
Vec3d(1,0,0),
Vec3d(0,1,0),
Vec3d(-1,0,0),
Vec3d(0,-1,0),
Vec3d(0,0,-1)
158 static const int verticeIndice[8][3] =
160 {0,2,1}, {0,1,4}, {0,4,3}, {0,3,2}, {5,1,2}, {5,4,1}, {5,3,4}, {5,2,3}
165 for (
int i=0;i<8;++i)
167 node.triangle =
SphericalConvexPolygon(vertice[verticeIndice[i][0]], vertice[verticeIndice[i][1]], vertice[verticeIndice[i][2]]);
168 Q_ASSERT(node.triangle.checkValid());
169 children.append(node);
174 void insert(
const NodeElem& el,
int level)
197 template<
class FuncObject>
void processAll(FuncObject& func)
const
204 void insert(Node& node,
const NodeElem& el,
int level)
206 if (node.children.isEmpty())
208 node.elements.append(el);
210 if (level<maxLevel && node.elements.size() > maxObjectsPerNode)
213 const QVector<NodeElem> nodeElems = node.elements;
214 node.elements.clear();
216 for (QVector<NodeElem>::ConstIterator iter = nodeElems.constBegin();iter != nodeElems.constEnd(); ++iter)
218 insert(node, *iter, level);
225 for (QVector<Node>::iterator iter = node.children.begin(); iter!=node.children.end(); ++iter)
227 if (((
SphericalRegion*)&(iter->triangle))->contains(el.obj->getRegion().data()))
229 insert(*iter, el, level+1);
234 node.elements.append(el);
240 foreach (
const NodeElem& el, node.elements)
245 if (region->intersects(el.obj->getRegion().data()))
248 foreach (
const Node& child, node.children)
250 if (region->contains(child.triangle))
252 else if (region->intersects(child.triangle))
259 foreach (
const NodeElem& el, node.elements)
264 if (cap.intersects(el.cap))
267 foreach (
const Node& child, node.children)
269 if (cap.contains(child.triangle))
271 else if (cap.intersects(child.triangle))
279 foreach (
const NodeElem& el, node.elements)
284 if (region->contains(el.obj->getRegion().data()))
287 foreach (
const Node& child, node.children)
289 if (region->contains(child.triangle))
291 else if (region->intersects(child.triangle))
297 template<
class FuncObject>
void processAll(
const Node& node, FuncObject& func)
const
302 foreach (
const NodeElem& el, node.elements)
304 foreach (
const Node& child, node.children)
309 int maxObjectsPerNode;
315 int maxObjectsPerNode;
320 #endif // _STELSPHERICALINDEX_HPP_