[vtkusers] vtkPolyDataToImageStencil
David Gobbi
david.gobbi at gmail.com
Thu Apr 30 14:19:30 EDT 2015
Hi Nil,
I'm not sure what you mean by "what will they become". Each time your
GetNext() method is called and returns "true", the values (x1, x2, y, z)
will define a horizontal line segment between (x1,y,z) and (x2,y,z).
Thanks for writing out the method in full. Now that I see the code I think
it looks better if the last condition calls "break" instead of "return
false":
bool GetNext(int& x1, int& x2, int& y, int& z)
{
int maxX, maxY, maxZ, dump;
m_ImageStencilData->GetExtent(dump, maxX, dump, maxY, dump, maxZ);
bool gotExtent = false;
while (!gotExtent)
{
gotExtent = m_ImageStencilData->GetNextExtent(
x1, x2, 0, maxX, m_Y, m_Z, m_Iter) > 0;
if (!gotExtent) { m_Iter = 0; ++m_Y; }
if (m_Y > maxY) { m_Y = 0; ++m_Z; }
if (m_Z > maxZ) { m_Z = 0; break; }
}
y = m_Y; z = m_Z;
return gotExtent;
}
On Thu, Apr 30, 2015 at 11:54 AM, Nil Goyette <nil.goyette at imeka.ca> wrote:
> Hi David,
>
> Haha, wow, I was totally not understanding this method! It does make
> sense now. Thank you :)
>
> One last question, just to be sure, what does the y and z parameters
> become? Here's the complete method, for clarity and for the next vtk users:
> bool GetNext(int& x1, int& x2, int& y, int& z)
> {
> int maxX, maxY, maxZ, dump;
> m_ImageStencilData->GetExtent(dump, maxX, dump, maxY, dump, maxZ);
>
> bool gotExtent = false;
> while (!gotExtent)
> {
> gotExtent = m_ImageStencilData->GetNextExtent(
> x1, x2, 0, maxX, m_Y, m_Z, m_Iter) > 0;
>
> if (!gotExtent) { m_Iter = 0; ++m_Y; }
> if (m_Y > maxY) { m_Y = 0; ++m_Z; }
> if (m_Z > maxZ) { m_Z = 0; return false; }
> }
>
> y = m_Y; z = m_Z; // *y and z ???*
> return true;
> }
>
> Nil
>
>
> Le 2015-04-30 12:55, David Gobbi a écrit :
>
> 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/0c7eff12/attachment.html>
More information about the vtkusers
mailing list