Hello all,<br><br>I want to build distance field for the object.<br>My object is very sparsed and I want to build distance field for it and not to allocate memory for every voxel in the grid.<br>Number of voxel in 3d grid is about 10^10 (more precisely: 2000x2000x2000)<br>
Number of voxel in object itself is about 10^6.<br><br>I tried to play with itk::SignedMaurerDistanceMapImageFilter creating image 5x5x5 in sandbox:<br><br><br> const unsigned int Dimension = 3;<br> typedef char InputPixelType;<br>
typedef float OutputPixelType;<br><br> typedef itk::Image<InputPixelType, Dimension> InputImageType;<br> typedef itk::Image<OutputPixelType, Dimension> OutputImageType;<br><br> InputImageType::Pointer image = InputImageType::New();<br>
<br> InputImageType::SizeType size;<br> size[0] = 5;<br> size[1] = 5;<br> size[2] = 5;<br><br> InputImageType::IndexType start;<br> start.Fill(0);<br><br> InputImageType::RegionType region;<br> region.SetIndex(start);<br>
region.SetSize(size);<br><br> image->SetRegions(region);<br> image->Allocate();<br><br> image->FillBuffer(0);<br><br> InputImageType::IndexType index;<br><br> // initialize <br> InputImageType::IndexType gapIndex;<br>
gapIndex[0] = gapIndex[1] = gapIndex[2] = 2;<br> for (index[0] = 0; index[0] < size[0]; ++index[0])<br> for (index[1] = 0; index[1] < size[1]; ++index[1])<br> for (index[2] = 0; index[2] < size[2]; ++index[2]) {<br>
if (index == gapIndex) continue;<br> image->SetPixel(index, 1);<br> }<br><br> // Define the distance map filter and apply it to the image<br> typedef itk::SignedMaurerDistanceMapImageFilter<InputImageType, OutputImageType> DistanceFilterType;<br>
DistanceFilterType::Pointer distanceFilter = DistanceFilterType::New();<br> distanceFilter->SetInput(image);<br> distanceFilter->SetBackgroundValue(0);<br> distanceFilter->SetSquaredDistance(false);<br>
distanceFilter->Update();<br> <br> // Output distance field values<br> for (int x = 1; x < size[0]-1; ++x)<br> {<br> for (int y = 1; y < size[1]-1; ++y)<br> {<br> for (int z = 1; z < size[2]-1; ++z)<br>
{<br> InputImageType::IndexType ind;<br> ind[0] = x;<br> ind[1] = y;<br> ind[2] = z;<br><br> float value = distanceFilter->GetOutput()->GetPixel(ind);<br>
std::cout << x << " " << y << " " << z << " -> " << value << std::endl;<br> }<br> }<br> }<br><br><br>The code works fine.<br>
But it requires memory for every voxel of grid, and this is not acceptable for 10^10 voxels.<br><br>Is it possible to use some kind of sparse structure to build distance field?<br><br>I read about itk::SparseImage, but it seems this structure is sparse concerning value only, but indices are allocated for the whole grid. Am I undestood correctly? If no, I will be glad if somebody point out where I am mistaken. Thanks.<br>
<br>If itk::SparseImage is not sutable in my case, is it possible to implement custom Image format for input to itk::SignedMaurerDistanceMapImageFilter?<br>If so, are the any useful guidelines to achieve this?<br>For now it is not clear for me how to correctly derive my Image type from DataObject and handle regions - I don't need full power of ITK filter pipeline, just to call itk::SignedMaurerDistanceMapImageFilter - possibly this helps me to simplify custom image implementation.<br>
<br>Any ideas could be helpful for me!<br><br>Thanks in advance,<br>Sergiy<br><br>