// now we apply the fast marching algorithm main loop // (1) take the smallest narrow band element and // freeze it. // (2) for each neighbor of the frozen point calculate distance based // on frozen elements // - mark each neighbor as narrow band and stick it // into the heap // - if the neighbor is already in the heap update the // distance value. void baseMarcher::solve() { int frozenCount=0; for (int i=0; i<size_; i++) if (flag_[i] == Frozen) frozenCount++; if (!frozenCount) { error_ = 2; return; } int i=0; while (! heap_->empty()) { i++; double value = 0; int addr = 0; heap_->pop(&addr, &value); flag_[addr]=Frozen; finalizePoint(addr, value); for (int dim=0; dim<dim_; dim++) { for (int j=-1; j<2; j+=2) // each direction { int naddr = _getN(addr,dim,j,Frozen); if (naddr!=-1 && flag_[naddr]!=Frozen) { if (flag_[naddr]==Narrow) { double d; if (order_ == 2) d = updatePointOrderTwo(naddr); else d = updatePointOrderOne(naddr); if (d) { heap_->set(heapptr_[naddr],fabs(d)); distance_[naddr]=d; } } else if (flag_[naddr]==Far) { double d; if (order_ == 2) d = updatePointOrderTwo(naddr); else d = updatePointOrderOne(naddr); if (d) { distance_[naddr]=d; flag_[naddr]=Narrow; heapptr_[naddr] = heap_->push(naddr,fabs(d)); } } } //========================================================== // update the far point in the second order stencil // "jump" over a Frozen point if needed if (order_ == 2) { int local_naddr = _getN(addr,dim,j,Mask); if (local_naddr!=-1 && flag_[local_naddr]==Frozen) { int naddr2 = _getN(addr,dim,j*2,Frozen); if (naddr2!=-1 && flag_[naddr2]==Narrow) { double d = updatePointOrderTwo(naddr2); if (d) { heap_->set(heapptr_[naddr2], fabs(d)); distance_[naddr2]=d; } } } } //========================================================== } // for each direction } // for each dimension } // main loop of Fast Marching Method // add back mask here. The python wrapper will look for elements // equal to maxDouble and add the mask back for (int i=0; i<size_; i++) { if (flag_[i] == Mask) distance_[i] = maxDouble; if (flag_[i] == Far) distance_[i] = maxDouble; } error_ = 0; return; }
// now we apply the fast marching algorithm main loop // (1) take the smallest narrow band element and // freeze it. // (2) for each neighbor of the frozen point calculate distance based // on frozen elements // - mark each neighbor as narrow band and stick it // into the heap // - if the neighbor is already in the heap update the // distance value. void baseMarcher::solve() { int frozenCount=0; for (int i=0; i<size_; i++) if (flag_[i] == Frozen) frozenCount++; if (!frozenCount) { error_ = 2; return; } int i=0; while (! heap_->empty()) { i++; double value = 0; int addr = 0; heap_->pop(&addr, &value); flag_[addr]=Frozen; finalizePoint(addr, value); for (int dim=0; dim<dim_; dim++) { for (int j=-1; j<2; j+=2) // each direction { int naddr = _getN(addr,dim,j,Frozen); if (naddr!=-1 && flag_[naddr]!=Frozen) { if (flag_[naddr]==Narrow) { double d; if (order_ == 2) d = updatePointOrderTwo(naddr); else d = updatePointOrderOne(naddr); if (d) { heap_->set(heapptr_[naddr],fabs(d)); distance_[naddr]=d; } } else if (flag_[naddr]==Far) { double d; if (order_ == 2) d = updatePointOrderTwo(naddr); else d = updatePointOrderOne(naddr); if (d) { distance_[naddr]=d; flag_[naddr]=Narrow; heapptr_[naddr] = heap_->push(naddr,fabs(d)); } } } } } } // add back mask here. The python wrapper will look for elements // equal to mexDouble and add the mask back for (int i=0; i<size_; i++) { if (flag_[i] == Mask) distance_[i] = maxDouble; if (flag_[i] == Far) distance_[i] = maxDouble; } error_ = 0; return; }