void FastMarch2D::FindPhi(int index, int x, int y) { static Double phiX, phiY, phiZ, b, quotient, phi; static int a; static bool flagX, flagY; phiX = phiY = phiZ = 0.; a = 0; flagX = flagY = 0; //Find The phiS CheckFront (phiX, a, flagX, GI(x+1, y)); CheckBehind(phiX, a, flagX, GI(x-1, y)); CheckFront (phiY, a, flagY, GI(x ,y+1)); CheckBehind(phiY, a, flagY, GI(x ,y-1)); //Max Tests if(a == 2) { if(phiX >= phiY) CheckMax2(a, phiX, phiY); else CheckMax2(a, phiY, phiX); } b = phiX + phiY + phiZ; quotient = square(b) - Double(a) * (square(phiX) + square(phiY) + square(phiZ) - square(h)); if(quotient < 0.) cout << "0 "; else { phi = b + sqrt(quotient); phi /= Double(a); grid[index].value = phi; if(grid[index].HeapPosition == -1) AddToHeap(index); else UpdateHeap(index); } }
void Marching(void) { int tempt_x, tempt_y, tempt_z; float dt,dist; int neighbor,seed; char boundary; float min_seedx, min_seedy, min_seedz; float seedx, seedy, seedz; min_seedx = AllSeeds[min_seed].seedx; min_seedy = AllSeeds[min_seed].seedy; min_seedz = AllSeeds[min_seed].seedz; boundary = 0; /* ============================ */ tempt_x=max(min_x-1,0); tempt_y=min_y; tempt_z=min_z; if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] == MaxVal) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx)+(tempt_y-min_seedy)*(tempt_y-min_seedy)+(tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist <= threshold) InsertHeap(tempt_x, tempt_y, tempt_z, dist); else boundary = 1; } else if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] > -1) { neighbor = heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)]; dt = min_heap->dist[neighbor]; if (dt < MaxDist) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist < dt) UpdateHeap(tempt_x, tempt_y, tempt_z, dist); } else { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); seed = min_heap->seed[neighbor]; seedx = AllSeeds[seed].seedx; seedy = AllSeeds[seed].seedy; seedz = AllSeeds[seed].seedz; if (dist < (tempt_x-seedx)*(tempt_x-seedx)+(tempt_y-seedy)*(tempt_y-seedy)+(tempt_z-seedz)*(tempt_z-seedz)) UpdateHeap(tempt_x, tempt_y, tempt_z, MaxDist); } } //else if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] > -11) { /* ============================ */ tempt_x=min(min_x+1,xdim1-1); tempt_y=min_y; tempt_z=min_z; if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] == MaxVal) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx)+(tempt_y-min_seedy)*(tempt_y-min_seedy)+(tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist <= threshold) InsertHeap(tempt_x, tempt_y, tempt_z, dist); else boundary = 1; } else if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] > -1) { neighbor = heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)]; dt = min_heap->dist[neighbor]; if (dt < MaxDist) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist < dt) UpdateHeap(tempt_x, tempt_y, tempt_z, dist); } else { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); seed = min_heap->seed[neighbor]; seedx = AllSeeds[seed].seedx; seedy = AllSeeds[seed].seedy; seedz = AllSeeds[seed].seedz; if (dist < (tempt_x-seedx)*(tempt_x-seedx)+(tempt_y-seedy)*(tempt_y-seedy)+(tempt_z-seedz)*(tempt_z-seedz)) UpdateHeap(tempt_x, tempt_y, tempt_z, MaxDist); } } /* ============================ */ tempt_y=max(min_y-1,0); tempt_x=min_x; tempt_z=min_z; if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] == MaxVal) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx)+(tempt_y-min_seedy)*(tempt_y-min_seedy)+(tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist <= threshold) InsertHeap(tempt_x, tempt_y, tempt_z, dist); else boundary = 1; } else if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] > -1) { neighbor = heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)]; dt = min_heap->dist[neighbor]; if (dt < MaxDist) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist < dt) UpdateHeap(tempt_x, tempt_y, tempt_z, dist); } else { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); seed = min_heap->seed[neighbor]; seedx = AllSeeds[seed].seedx; seedy = AllSeeds[seed].seedy; seedz = AllSeeds[seed].seedz; if (dist < (tempt_x-seedx)*(tempt_x-seedx)+(tempt_y-seedy)*(tempt_y-seedy)+(tempt_z-seedz)*(tempt_z-seedz)) UpdateHeap(tempt_x, tempt_y, tempt_z, MaxDist); } } /* ============================ */ tempt_y=min(min_y+1,ydim1-1); tempt_x=min_x; tempt_z=min_z; if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] == MaxVal) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx)+(tempt_y-min_seedy)*(tempt_y-min_seedy)+(tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist <= threshold) InsertHeap(tempt_x, tempt_y, tempt_z, dist); else boundary = 1; } else if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] > -1) { neighbor = heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)]; dt = min_heap->dist[neighbor]; if (dt < MaxDist) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist < dt) UpdateHeap(tempt_x, tempt_y, tempt_z, dist); } else { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); seed = min_heap->seed[neighbor]; seedx = AllSeeds[seed].seedx; seedy = AllSeeds[seed].seedy; seedz = AllSeeds[seed].seedz; if (dist < (tempt_x-seedx)*(tempt_x-seedx)+(tempt_y-seedy)*(tempt_y-seedy)+(tempt_z-seedz)*(tempt_z-seedz)) UpdateHeap(tempt_x, tempt_y, tempt_z, MaxDist); } } /* ============================ */ tempt_z=max(min_z-1,0); tempt_x=min_x; tempt_y=min_y; if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] == MaxVal) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx)+(tempt_y-min_seedy)*(tempt_y-min_seedy)+(tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist <= threshold) InsertHeap(tempt_x, tempt_y, tempt_z, dist); else boundary = 1; } else if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] > -1) { neighbor = heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)]; dt = min_heap->dist[neighbor]; if (dt < MaxDist) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist < dt) UpdateHeap(tempt_x, tempt_y, tempt_z, dist); } else { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); seed = min_heap->seed[neighbor]; seedx = AllSeeds[seed].seedx; seedy = AllSeeds[seed].seedy; seedz = AllSeeds[seed].seedz; if (dist < (tempt_x-seedx)*(tempt_x-seedx)+(tempt_y-seedy)*(tempt_y-seedy)+(tempt_z-seedz)*(tempt_z-seedz)) UpdateHeap(tempt_x, tempt_y, tempt_z, MaxDist); } } /* ============================ */ tempt_z=min(min_z+1,zdim1-1); tempt_x=min_x; tempt_y=min_y; if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] == MaxVal) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx)+(tempt_y-min_seedy)*(tempt_y-min_seedy)+(tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist <= threshold) InsertHeap(tempt_x, tempt_y, tempt_z, dist); else boundary = 1; } else if (heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)] > -1) { neighbor = heap_pointer[IndexVect1(tempt_x,tempt_y,tempt_z)]; dt = min_heap->dist[neighbor]; if (dt < MaxDist) { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); if (dist < dt) UpdateHeap(tempt_x, tempt_y, tempt_z, dist); } else { dist = (tempt_x-min_seedx)*(tempt_x-min_seedx) + (tempt_y-min_seedy)*(tempt_y-min_seedy) + (tempt_z-min_seedz)*(tempt_z-min_seedz); seed = min_heap->seed[neighbor]; seedx = AllSeeds[seed].seedx; seedy = AllSeeds[seed].seedy; seedz = AllSeeds[seed].seedz; if (dist < (tempt_x-seedx)*(tempt_x-seedx)+(tempt_y-seedy)*(tempt_y-seedy)+(tempt_z-seedz)*(tempt_z-seedz)) UpdateHeap(tempt_x, tempt_y, tempt_z, MaxDist); } } if (boundary) InsertHeap(min_x,min_y,min_z, MaxDist); }