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&lt;InputPixelType, Dimension&gt; InputImageType;<br>    typedef itk::Image&lt;OutputPixelType, Dimension&gt; 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-&gt;SetRegions(region);<br>    image-&gt;Allocate();<br><br>    image-&gt;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] &lt; size[0]; ++index[0])<br>        for (index[1] = 0; index[1] &lt; size[1]; ++index[1])<br>            for (index[2] = 0; index[2] &lt; size[2]; ++index[2]) {<br>

                if (index == gapIndex) continue;<br>                image-&gt;SetPixel(index, 1);<br>            }<br><br>    // Define the distance map filter and apply it to the image<br>    typedef itk::SignedMaurerDistanceMapImageFilter&lt;InputImageType, OutputImageType&gt; DistanceFilterType;<br>

    DistanceFilterType::Pointer distanceFilter = DistanceFilterType::New();<br>    distanceFilter-&gt;SetInput(image);<br>    distanceFilter-&gt;SetBackgroundValue(0);<br>    distanceFilter-&gt;SetSquaredDistance(false);<br>

    distanceFilter-&gt;Update();<br>    <br>    // Output distance field values<br>    for (int x = 1; x &lt; size[0]-1; ++x)<br>    {<br>        for (int y = 1; y &lt; size[1]-1; ++y)<br>        {<br>            for (int z = 1; z &lt; 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-&gt;GetOutput()-&gt;GetPixel(ind);<br>

                std::cout &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; y &lt;&lt; &quot; &quot; &lt;&lt; z &lt;&lt; &quot; -&gt; &quot; &lt;&lt; value &lt;&lt; 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&#39;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>