<div dir="ltr"><div>Hi Nil,</div><div><br></div><div>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).</div><div><br></div><div>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":</div><div><br></div><div>bool GetNext(int& x1, int& x2, int& y, int& z)</div><div>{</div><div> int maxX, maxY, maxZ, dump;</div><div> m_ImageStencilData->GetExtent(dump, maxX, dump, maxY, dump, maxZ);</div><div><br></div><div> bool gotExtent = false;</div><div> while (!gotExtent) </div><div> {</div><div> gotExtent = m_ImageStencilData->GetNextExtent(</div><div> x1, x2, 0, maxX, m_Y, m_Z, m_Iter) > 0;</div><div><br></div><div> if (!gotExtent) { m_Iter = 0; ++m_Y; }</div><div> if (m_Y > maxY) { m_Y = 0; ++m_Z; }</div><div> if (m_Z > maxZ) { m_Z = 0; break; }</div><div> }</div><div><br></div><div> y = m_Y; z = m_Z;</div><div> return gotExtent;</div><div>}</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 30, 2015 at 11:54 AM, Nil Goyette <span dir="ltr"><<a href="mailto:nil.goyette@imeka.ca" target="_blank">nil.goyette@imeka.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Hi David,<br>
<br>
Haha, wow, I was totally not understanding this method! It does
make sense now. Thank you :)<br>
<br>
One last question, just to be sure, what does the <tt>y</tt> and <tt>z</tt>
parameters become? Here's the complete method, for clarity and for
the next vtk users:<br>
<small><span class=""><tt>bool GetNext(int& x1, int& x2, int& y,
int& z)</tt><tt><br>
</tt><tt>{</tt><tt><br>
</tt></span><span class=""><tt> int maxX, maxY, maxZ, dump;</tt><tt><br>
</tt><tt> m_ImageStencilData->GetExtent(dump, maxX, dump,
maxY, dump, maxZ);</tt><tt><br>
<br>
</tt></span><span class=""><tt> bool gotExtent = false;</tt><tt><br>
</tt><tt> while (!gotExtent) </tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> gotExtent = m_ImageStencilData->GetNextExtent(</tt><tt><br>
</tt></span><tt> x1, x2, 0, maxX, m_Y, m_Z, m_Iter) > 0;</tt><tt><br>
</tt><tt><br>
</tt><tt> if (!gotExtent) { m_Iter = 0; ++m_Y; }</tt><tt><br>
</tt><tt> if (m_Y > maxY) { m_Y = 0; ++m_Z; }</tt><tt><br>
</tt><tt> if (m_Z > maxZ) { m_Z = 0; return false; }</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt><br>
</tt><tt> y = m_Y; z = m_Z;</tt><tt> // <font color="#ff0000"><b>y
and z ???</b></font><br>
</tt><tt> return true;</tt><tt><br>
</tt><tt>}</tt></small><span class="HOEnZb"><font color="#888888"><br>
<br>
Nil</font></span><div><div class="h5"><br>
<br>
<div>Le 2015-04-30 12:55, David Gobbi a
écrit :<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">On Thu, Apr 30, 2015 at 9:53 AM,
David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">
<div>Hi Nil,</div>
<div><br>
</div>
<div>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:</div>
<a href="https://github.com/dgobbi/AIRS/blob/master/ImageSegmentation/vtkImageRegionIterator.h" target="_blank">https://github.com/dgobbi/AIRS/blob/master/ImageSegmentation/vtkImageRegionIterator.h</a><br>
<div class="gmail_extra"><br>
</div>
<div class="gmail_extra">In order for your GetNext()
function to work as an iterator function, it should
not have any loops, just conditionals:</div>
<div class="gmail_extra"><br>
</div>
<div class="gmail_extra">if ->GetNextExtent() returns
zero, it should reset m_Iter to zero and increment m_Y<br>
</div>
<div class="gmail_extra">if m_Y > maxY, it should
reset m_Y to zero and increment m_Z</div>
<div class="gmail_extra">if m_Z > maxZ, it should
reset m_Z to zero and return false</div>
</div>
</blockquote>
<div><br>
</div>
<div>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:</div>
<div><br>
</div>
<div> bool gotExtent = false;</div>
<div> while (!gotExtent)</div>
<div> {</div>
<div> gotExtent = m_ImageStencilData->GetNextExtent()</div>
<div> if gotExtent is zero, it should reset m_Iter to
zero and increment m_Y</div>
<div>
<div class="gmail_extra"> if m_Y > maxY, it should
reset m_Y to zero and increment m_Z</div>
<div class="gmail_extra"> if m_Z > maxZ, it should
reset m_Z to zero and return false</div>
</div>
<div> }</div>
<div><br>
</div>
<div>No guarantees, of course, since it's completely
untested pseudocode.</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
<div><br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">
<div>
<div>
<div class="gmail_extra">
<div class="gmail_quote">On Thu, Apr 30, 2015 at
8:54 AM, Nil Goyette <span dir="ltr"><<a href="mailto:nil.goyette@imeka.ca" target="_blank">nil.goyette@imeka.ca</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> Hi all,<br>
<br>
I'm using <tt>vtkPolyDataToImageStencil</tt>
to get all voxels index inside of a surface.
If I understand correctly, I have only two
choices here:<br>
- <tt>vtkImageStencil</tt> to create a new
image<br>
- <tt>vtkImageStencilIterator</tt> to
iterate on the values (of another image)<br>
The problem is, I have a different goal in
mind. I need the index of all voxels inside
a surface.<br>
<br>
I read the <tt>vtkPolyDataToImageStencil</tt>
code and tried to create my own "iterator"
but there's probably something I don't
understand; <tt>GetNextExtent</tt> always
return 0.<br>
<small><tt>bool GetNext(int& x1,
int& x2, int& y, int& z)</tt><tt><br>
</tt><tt>{</tt><tt><br>
// m_Y, m_Z and m_Iter == 0</tt></small><small><tt><br>
int maxX, maxY, maxZ, dump;</tt><tt><br>
</tt><tt>
m_ImageStencilData->GetExtent(dump,
maxX, dump, maxY, dump, maxZ);</tt><tt><br>
</tt><tt> maxX *= 2; maxY *= 2; maxZ *=
2;</tt><tt><br>
</tt><tt><br>
</tt><tt> for ( ; m_Z <= maxZ; ++m_Z)</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> for ( ; m_Y <= maxY;
++m_Y)</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> if
(m_ImageStencilData->GetNextExtent(x1,
x2, 0, maxX, m_Y, m_Z, m_Iter))</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> y = m_Y; z = m_Z;</tt><tt><br>
</tt><tt> return true;</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> return false;</tt><tt><br>
</tt><tt>}</tt></small><br>
<br>
Is there a way to access all inside-voxels
hidden in the <tt>vtkPolyDataToImageStencil</tt>?
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.<span><font color="#888888"><br>
<br>
Nil<br>
</font></span></div>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br></div>