int DominatorGraph::semi_dominators (int r) { int bsize = n+1; int *buffer = new int [5*bsize]; int *label2pre = &buffer[0]; int *pre2label = &buffer[bsize]; int *parent = &buffer[2*bsize]; //int *ancestor = &buffer[3*bsize]; int *label = &buffer[3*bsize]; int *semi = &buffer[4*bsize]; resetcounters(); int npdom = 0; //number of vertices dominated by their parent int i; for (i=0; i<=n; i++) { label[i] = semi[i] = i; //ancestor[i] = 0; } int N = preDFSp (r, label2pre, pre2label, parent); for (i=N; i>=2; i--) { int w = pre2label[i]; int *p, *stop; getInBounds(w,p,stop); for (; p<stop; p++) { int v = label2pre[*p]; if (v) { int u; //if (!ancestor[v]) {u=v;} //if (!parent[v]) {u=v;} if (v<=i) {u=v;} //u is an ancestor of i else { //rcompress(v,ancestor,semi,label); rcompress(v,parent,semi,label,i); u = label[v]; } if (semi[u]<semi[i]) semi[i] = semi[u]; } } //if (semi[i]==parent[i]) npdom++; incs(); //ancestor[i] = parent[i]; } delete [] buffer; return npdom; }
std::set<const Model*> UniformGrid::getModels(const Ray& ray) const { std::set<const Model*> models; Point3D nextT(0, 0, 0); // The point *within* the grid where the ray first intersected it Point3D rayStartPoint(0, 0, 0); if (!inGrid(ray.start)) { const auto& sp = startPoint; // Not in the grid: We will use a cube the sz of whole grid to find // the point of entry into the grid auto gridCubeInverse = (translationMatrix(sp[0], sp[0], sp[0]) * gridSizeScaleMatrix).invert(); HitRecord hr; if (!utilityCube.intersects(ray, &hr, gridCubeInverse)) { // Does not intersect the grid even return models; } nextT[0] = hr.t; nextT[1] = hr.t; nextT[2] = hr.t; rayStartPoint = ray.at(hr.t); } else { rayStartPoint = ray.start; } // Place in the grid we are currently stepping through CellCoord gridCoord = coordAt(rayStartPoint); Vector3D dir( std::abs(ray.dir[0]), std::abs(ray.dir[1]), std::abs(ray.dir[2])); // These values are in units of t: how far we must go to travel a whole cell Vector3D dt( isZero(dir[0]) ? 0 : cellSize / dir[0], isZero(dir[1]) ? 0 : cellSize / dir[1], isZero(dir[2]) ? 0 : cellSize / dir[2] ); { // The bottom left corner of the cell we are starting in Point3D gsp = pointAt(gridCoord); // "Grid start point" // Determine how far, in units of t, we have to go in any direction // to reach the next cell // If we are going "forwards" in a coordinate then we need to travel to // gsp + cellSize. If we are going "backwards" in a coordinate then we need // to travel to only gsp. for (int i = 0; i < 3; ++i) { if (isZero(dir[i])) { nextT[i] = -1; continue; } if (ray.dir[i] < 0) { nextT[i] += (rayStartPoint[i] - gsp[i]) / dir[i]; } else { nextT[i] += (gsp[i] + cellSize - rayStartPoint[i]) / dir[i]; } } } // Which direction in the grid to move when we hit a "next" value CellCoord incs( (ray.dir[0] > 0) ? 1 : -1, (ray.dir[1] > 0) ? 1 : -1, (ray.dir[2] > 0) ? 1 : -1 ); // Check if a coord is still valid auto coordOk = [&] (int coord) -> bool { return 0 <= coord && coord < sideLength; }; auto smaller = [] (double a, double b) -> bool { return (b < 0) || a <= b; }; while (coordOk(gridCoord.x) && coordOk(gridCoord.y) && coordOk(gridCoord.z)) { for (const Model* model : cells[indexFor(gridCoord)].models) { models.insert(model); } for (int i = 0; i < 3; ++i) { if (nextT[i] < 0) continue; const auto a = nextT[(i + 1) % 3]; const auto b = nextT[(i + 2) % 3]; if (smaller(nextT[i], a) && smaller(nextT[i], b)) { nextT[i] += dt[i]; gridCoord[i] += incs[i]; break; } } } return models; }
void* thr(void* arg) { inct(); __VERIFIER_assert(s < t); incs(); }