<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">One more thought.<div><br></div><div>If you are generating the list of sample points once and then using them multiple times to sample there are perhaps other interesting things which could be done.</div><div><br></div><div>CPU likes to access memory in a linear fashion. Depending on your density, and the size of the neighborhood etc.. If you access your random points in a sequential fashion you may see benefits. That is 1) generate a sequential set of random points 2) sample the points in order. Step 2 should may see some benefits... Now under what conditions does it out weight the first? </div><div><br></div><div>Brad</div><div><br><div><div>On May 13, 2013, at 11:49 AM, "Gao, Yi" <<a href="mailto:gaoyi.cn@gmail.com">gaoyi.cn@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><div dir="ltr"><div><div><div><div>Hi Brad,<br><br>Thank you for the suggestion!<br><br></div>Sorry in my previous code I had the mistake for randomly picking position for the center point. Now I changed it to be in the inner region.<br>
index[0] = rg.lrand32(1, size[0] - 2);<br>index[1] = rg.lrand32(1, size[1] - 2);<br>index[2] = rg.lrand32(1, size[2] - 2);<br><br></div>And I also turn off the boundary condition by:<br>it.NeedToUseBoundaryConditionOff();<br>
<br></div>Now with the same parameters, nbhditerator is around 4 seconds (vs direct access 5.5 seconds)!<br><br></div>I will modify my code to take advantage of this! <br><br>Thank you!<br><div><br>Best,<br>yi<br><div>
<br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 13, 2013 at 11:34 AM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<div class="im"><br>
On May 13, 2013, at 11:03 AM, "Gao, Yi" <<a href="mailto:gaoyi.cn@gmail.com">gaoyi.cn@gmail.com</a>> wrote:<br>
> When using NeighborhoodIterator, i'm not sure if the boundary checking is automatically turned on. I guess if that is by default on, then there is not much speed gain with it.<br>
<br>
<br>
</div>Because the region you specify to the Iterator is on the boundary it will turn on the boundary checking. You can either turn off the condition:<br>
<br>
<a href="http://www.itk.org/Doxygen/html/classitk_1_1ConstNeighborhoodIterator.html#a438cb0146b802b04a771a2461952cff8" target="_blank">http://www.itk.org/Doxygen/html/classitk_1_1ConstNeighborhoodIterator.html#a438cb0146b802b04a771a2461952cff8</a><br>
<br>
or you can change the region size you initialize the Iterator with.<br>
<br>
You can just use the operator<< to check what the iterator is doing.<br>
<br>
Also consider using a large type for the accumulation type, such as itk::NumericTraits<T>::AccumulatorType;<br>
<br>
And consider using std::accumulate(it.Begin(), it.End(), 0 )<br>
<br>
Brad</blockquote></div><br></div>
</blockquote></div><br></div></body></html>