void finish_vertex(VertexDescriptorType v, VertexDescriptorType sourceNode, TGraph& g) { // Construct the region around the vertex itk::Index<2> indexToFinish; indexToFinish[0] = v[0]; indexToFinish[1] = v[1]; itk::ImageRegion<2> region = ITKHelpers::GetRegionInRadiusAroundPixel(indexToFinish, HalfWidth); region.Crop(Image->GetLargestPossibleRegion()); // Make sure the region is entirely inside the image // Mark all the pixels in this region as filled. // It does not matter which image we iterate over, we just want the indices. itk::ImageRegionConstIteratorWithIndex<TImage> gridIterator(Image, region); while(!gridIterator.IsAtEnd()) { VertexDescriptorType v; v[0] = gridIterator.GetIndex()[0]; v[1] = gridIterator.GetIndex()[1]; put(FillStatusMap, v, true); MaskImage->SetPixel(gridIterator.GetIndex(), MaskImage->GetValidValue()); ++gridIterator; } // Additionally, initialize the filled vertices because they may now be valid. // This must be done in a separate loop like this because the mask image used to check for boundary pixels is incorrect until the above loop updates it. gridIterator.GoToBegin(); while(!gridIterator.IsAtEnd()) { VertexDescriptorType v; v[0] = gridIterator.GetIndex()[0]; v[1] = gridIterator.GetIndex()[1]; initialize_vertex(v, g); ++gridIterator; } // Update the priority function. this->PriorityFunction->Update(sourceNode, v); // Add pixels that are on the new boundary to the queue, and mark other pixels as not in the queue. itk::ImageRegionConstIteratorWithIndex<Mask> imageIterator(this->MaskImage, region); while(!imageIterator.IsAtEnd()) { VertexDescriptorType v; v[0] = imageIterator.GetIndex()[0]; v[1] = imageIterator.GetIndex()[1]; // Mark all nodes in the patch around this node as filled (in the FillStatusMap). // This makes them ignored if they are still in the boundaryNodeQueue. if(ITKHelpers::HasNeighborWithValue(imageIterator.GetIndex(), this->MaskImage, this->MaskImage->GetHoleValue())) { put(BoundaryStatusMap, v, true); this->BoundaryNodeQueue.push(v); float priority = this->PriorityFunction->ComputePriority(imageIterator.GetIndex()); //std::cout << "updated priority: " << priority << std::endl; put(this->PriorityMap, v, priority); } else { put(this->BoundaryStatusMap, v, false); } ++imageIterator; } { // Debug only - write the mask to a file HelpersOutput::WriteImage(this->MaskImage, Helpers::GetSequentialFileName("debugMask", this->NumberOfFinishedVertices, "png")); HelpersOutput::WriteVectorImageAsRGB(this->Image, Helpers::GetSequentialFileName("output", this->NumberOfFinishedVertices, "png")); this->NumberOfFinishedVertices++; } } // finish_vertex