/* Zone tests */ bool VEF::isVertexInZone(Vertex v, int zid) { Zone z = m_zones[zid]; return (v >= z.getZoneBottomVertex()) && (v <= z.getZoneTopVertex()); }
// we use a tree architecture to build the subzones int VEF::divideIntoZones(Zone z, int nbZones){ TreeZone tz(z); TreeZone *father; int flag, flag2, depth; // used to determine the cutting axis flag = flag2 = depth = 0; Vertex bottom, middle_bottom, middle_top, top; bottom = middle_bottom = z.getZoneBottomVertex(); top = middle_top = z.getZoneTopVertex(); int id = 0; int rootFlag = 0; std::vector<TreeZone> parents; // store the parent trees relative to the one we manipulate for (int i = 0; i < nbZones; i++){ if (!(i % 2)){ if (flag % 3 == 0) // we cut along the x axis { Vertex vx(middle_top.getX() - (middle_top.getX() / 2), middle_top.getY(), middle_top.getZ()); Zone zl(bottom, vx, -1); TreeZone *l = new TreeZone(zl); tz.addLeftChild(l); //top.setX(vx.getX()); middle_top = vx; } if (flag % 3 == 1) // we cut along the y axis { Vertex vy(middle_top.getX(), middle_top.getY() - middle_top.getY() / 2, middle_top.getZ()); Zone zl(bottom, vy, -1); TreeZone *l = new TreeZone(zl); tz.addLeftChild(l); //top.setY(vy.getY()); middle_top = vy; } if (flag % 3 == 2) // we cut along the z axis { Vertex vz(middle_top.getX(), middle_top.getY(), middle_top.getZ() - middle_top.getZ() / 2); Zone zl(bottom, vz, -1); TreeZone *l = new TreeZone(zl); tz.addLeftChild(l); //top.setZ(vz.getZ()); middle_top = vz; } } else { if (flag2 % 3 == 0) // we cut along the x axis { Vertex vx(middle_bottom.getX() + (middle_bottom.getX() / 2), middle_bottom.getY(), middle_bottom.getZ()); Zone zr(vx, top, -1); TreeZone *r = new TreeZone(zr); tz.addRightChild(r); middle_bottom = vx; } if (flag2 % 3 == 1) // we cut along the y axis { Vertex vy(middle_bottom.getX(), middle_bottom.getY() + (middle_bottom.getY() / 2), middle_bottom.getZ()); Zone zr(vy, top, -1); TreeZone *r = new TreeZone(zr); tz.addRightChild(r); middle_bottom = vy; } if (flag2 % 3 == 2) // we cut along the z axis { Vertex vz(middle_bottom.getX(), middle_bottom.getY(), middle_bottom.getZ() + (middle_bottom.getZ() / 2)); Zone zr(vz, top, -1); TreeZone *r = new TreeZone(zr); tz.addRightChild(r); } if (depth){ if (!(*(father->getRightChild()) == tz)) { if (father->getRightChild()->getLeftChild() == NULL) { // the brother of t doesn't exist yet tz = *(father->getRightChild()); father = &(parents.back()); parents.pop_back(); } } } parents.push_back(*father); father = &tz; tz = *(tz.getLeftChild()); depth++; } } // depth-first search to add the zones we created (the leaves) into the zone vector while (tz.hasLeftChild()){ father = &tz; tz = *(tz.getLeftChild()); } tz.getRoot().setZoneId(id); m_zones.push_back(tz.getRoot()); id++; // we stop when we reach the root for the second time, i.e, when all the leaves have been found /*while(rootFlag != 1){ if (father->hasRightChild()){ father->getRightChild()->getRoot().setZoneId(id); m_zones.push_back(father->getRightChild()->getRoot()); } tz = father; if (depth){ father = parents.back(); parents.pop_back(); } depth--; }*/ return 0; }