[vtkusers] vtkPolyDataToImageStencil

David Gobbi david.gobbi at gmail.com
Thu Apr 30 12:55:11 EDT 2015


On Thu, Apr 30, 2015 at 9:53 AM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi Nil,
>
> I wrote a stencil iterator that provides the x, y, and z indices (not in
> VTK yet).  It still requires an image to iterate over, but it might be
> worth a glance:
>
> https://github.com/dgobbi/AIRS/blob/master/ImageSegmentation/vtkImageRegionIterator.h
>
> In order for your GetNext() function to work as an iterator function, it
> should not have any loops, just conditionals:
>
> if ->GetNextExtent() returns zero, it should reset m_Iter to zero and
> increment m_Y
> if m_Y > maxY, it should reset m_Y to zero and increment m_Z
> if m_Z > maxZ, it should reset m_Z to zero and return false
>

I realized that it isn't quite as simple as what I wrote.  Everything has
to be in a loop, because it has to keep trying until it gets a valid extent:

  bool gotExtent = false;
  while (!gotExtent)
    {
    gotExtent = m_ImageStencilData->GetNextExtent()
    if gotExtent is zero, it should reset m_Iter to zero and increment m_Y
    if m_Y > maxY, it should reset m_Y to zero and increment m_Z
    if m_Z > maxZ, it should reset m_Z to zero and return false
    }

No guarantees, of course, since it's completely untested pseudocode.

 - David


On Thu, Apr 30, 2015 at 8:54 AM, Nil Goyette <nil.goyette at imeka.ca> wrote:
>
>>  Hi all,
>>
>> I'm  using vtkPolyDataToImageStencil to get all voxels index inside of a
>> surface. If I understand correctly, I have only two choices here:
>> - vtkImageStencil to create a new image
>> - vtkImageStencilIterator to iterate on the values (of another image)
>> The problem is, I have a different goal in mind. I need the index of all
>> voxels inside a surface.
>>
>> I read the vtkPolyDataToImageStencil code and tried to create my own
>> "iterator" but there's probably something I don't understand;
>> GetNextExtent always return 0.
>> bool GetNext(int& x1, int& x2, int& y, int& z)
>> {
>>   // m_Y, m_Z and m_Iter == 0
>>   int maxX, maxY, maxZ, dump;
>>   m_ImageStencilData->GetExtent(dump, maxX, dump, maxY, dump, maxZ);
>>   maxX *= 2; maxY *= 2; maxZ *= 2;
>>
>>   for ( ; m_Z <= maxZ; ++m_Z)
>>   {
>>     for ( ; m_Y <= maxY; ++m_Y)
>>     {
>>       if (m_ImageStencilData->GetNextExtent(x1, x2, 0, maxX, m_Y, m_Z,
>> m_Iter))
>>       {
>>         y = m_Y; z = m_Z;
>>         return true;
>>       }
>>     }
>>   }
>>   return false;
>> }
>>
>> Is there a way to access all inside-voxels hidden in the
>> vtkPolyDataToImageStencil? By index or by index range, it's not
>> important. I just want to know to access them without useless work (like
>> creating an image) because it's gonna be called often; it needs to be fast.
>> Thank you for your time.
>>
>> Nil
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150430/fe280dc0/attachment.html>


More information about the vtkusers mailing list