Hi Matt, <div><br></div><div>Thanks for replying. <b>ReadStreamFile(...)</b> is defined below. The &quot;bad_alloc&gt; caught: St9bad_alloc&quot; error seems to originate from this function. For clarity, <b>TPixelType = itk::Vector&lt;float, 3</b>&gt;</div>
<div><br></div><div><div>template&lt; typename TPixelType&gt;</div>
<div>void <b>ReadStreamFile</b>( std::string filename, std::vector&lt;TPixelType&gt; &amp;points )</div><div>{</div><div>   TPixelType dir;</div><div>   int num;</div><div>   std::vector&lt;float&gt; vec;</div><div>   std::ifstream indata( filename.c_str() ); // opens the file</div>

<div><br></div><div>   indata &gt;&gt; num;</div><div>   while ( !indata.eof() )  { // keep reading until end-of-file</div><div>      vec.push_back( num );</div><div>      indata &gt;&gt; num;}</div><div>   indata.close();</div>

<div>}</div><div><br></div><div>Best, </div><div>Arvind</div><br><div class="gmail_quote">On Wed, Apr 4, 2012 at 10:53 PM, Matt McCormick <span dir="ltr">&lt;<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Arvind,<br>
<br>
It looks like the error is happening inside ReadStreamFile, so please<br>
post how that is declared and defined.<br>
<br>
Thanks,<br>
Matt<br>
<div><div><br>
On Wed, Apr 4, 2012 at 8:57 PM, Arvind Rao &lt;<a href="mailto:arvind.sbia@gmail.com" target="_blank">arvind.sbia@gmail.com</a>&gt; wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; In order to read-in a variable number of points from a file I want to use a<br>
&gt; dynamically sized container like STD::VECTOR. The points are stored like so:<br>
&gt; ( points is the vector I use )<br>
&gt;<br>
&gt;       typedef itk::Image&lt; itk::Vector&lt;ComponentType, Dimension&gt;, Dimension&gt;<br>
&gt;                                 PeakImageType;<br>
&gt;       typedef PeakImageType::PixelType<br>
&gt;                                                        DirectionType;<br>
&gt;       std::vector&lt;DirectionType&gt;<br>
&gt;                                                                points<br>
&gt;<br>
&gt; However, the following try-catch statement gives, at run-time, &quot;bad_alloc<br>
&gt; caught: St9bad_alloc&quot;<br>
&gt;<br>
&gt;       try<br>
&gt;       {<br>
&gt;                 std::vector&lt;DirectionType&gt; points;<br>
&gt;                 ReadStreamFile&lt;DirectionType&gt;( streamArg.getValue(), points<br>
&gt; );<br>
&gt;       }<br>
&gt;      catch (std::bad_alloc&amp; ba)<br>
&gt;       {<br>
&gt;                 std::cerr &lt;&lt; &quot;bad_alloc caught: &quot; &lt;&lt; ba.what() &lt;&lt; std::endl;<br>
&gt;                 return 0;<br>
&gt;       }<br>
&gt;<br>
&gt; So, what is going on? Its seems like POINTS is not being allocated properly,<br>
&gt; but I&#39;m sure how to fix this.<br>
&gt;<br>
&gt; Thanks for any help you can provide.<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Arvind S. Rao, PhD<br>
&gt; Section of Biomedical Image Analysis<br>
&gt; Department of Radiology<br>
&gt; University of Pennsylvania<br>
&gt; 3600 Market Street, Suite 380<br>
&gt; Philadelphia, PA 19104<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><b>Arvind S. Rao, PhD</b><br>Section of Biomedical Image Analysis<br>Department of Radiology<br>University of Pennsylvania<br>3600 Market Street, Suite 380<br>

Philadelphia, PA 19104<div>tel: (267) 283-8959</div><br>
</div>