Hi Matt,<div><br></div><div>After some investigation I&#39;ve learned that my error was purely a result of how I handle the file stream, within the ReadStreamFile(...)<br>function. And now I&#39;m working on properly parsing the input file. </div>
<div><br></div><div>Thanks so much for taking my question.</div><div><br></div><div>Best wishes, </div><div>Arvind</div><div><br></div><div><br><div class="gmail_quote">On Thu, Apr 5, 2012 at 9:53 AM, Arvind Rao <span dir="ltr">&lt;<a href="mailto:arvind.sbia@gmail.com">arvind.sbia@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi Matt,</div><div><br></div>My apologizes. For brevity and debugging I removed the portion of code which fills points. The full code for <b>ReadStreamFle</b> is below.<div>
<br></div><div><div class="im"><div>template&lt; typename TPixelType&gt;</div>
<div>void ReadStreamFile( 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><br></div><div>

   std::ifstream indata( filename.c_str() ); // opens the file</div></div><div>   if(!indata) { // file couldn&#39;t be opened</div><div>      cerr &lt;&lt; &quot;Error: file could not be opened&quot; &lt;&lt; endl;</div>
<div>      exit(1);</div><div class="im">
<div>   }</div><div><br></div><div>   indata &gt;&gt; num;</div><div>   while ( !indata.eof() )</div><div>   { // keep reading until end-of-file</div><div>      vec.push_back( num );</div><div>      indata &gt;&gt; num;</div>

<div>   }</div><div>   indata.close();</div></div><div>   std::cout &lt;&lt; vec.size() &lt;&lt; &quot;\n&quot;;</div><div><br></div><div>   for(int j=0; j &lt; int(vec.size()); j=+3) </div><div>   {</div><div>      dir[0] = vec[j];</div>

<div>      dir[1] = vec[j+1];</div><div>      dir[2] = vec[j+2];</div><div>      points.push_back( dir );</div><div>   }</div><div>}</div><div><br></div><div>Best, </div><span class="HOEnZb"><font color="#888888"><div>Arvind</div>
</font></span><div><div class="h5"><br><div class="gmail_quote">On Thu, Apr 5, 2012 at 12:59 AM, 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>
That cannot be all of the function because &quot;points&quot; is not used inside.<br>
<span><font color="#888888"><br>
Matt<br>
</font></span><div><div><br>
On Thu, Apr 5, 2012 at 12:34 AM, Arvind Rao &lt;<a href="mailto:arvind.sbia@gmail.com" target="_blank">arvind.sbia@gmail.com</a>&gt; wrote:<br>
&gt; Hi Matt,<br>
&gt;<br>
&gt; Thanks for replying. ReadStreamFile(...) is defined below. The &quot;bad_alloc&gt;<br>
&gt; caught: St9bad_alloc&quot; error seems to originate from this function. For<br>
&gt; clarity, TPixelType = itk::Vector&lt;float, 3&gt;<br>
&gt;<br>
&gt; template&lt; typename TPixelType&gt;<br>
&gt; void ReadStreamFile( std::string filename, std::vector&lt;TPixelType&gt; &amp;points )<br>
&gt; {<br>
&gt;    TPixelType dir;<br>
&gt;    int num;<br>
&gt;    std::vector&lt;float&gt; vec;<br>
&gt;    std::ifstream indata( filename.c_str() ); // opens the file<br>
&gt;<br>
&gt;    indata &gt;&gt; num;<br>
&gt;    while ( !indata.eof() )  { // keep reading until end-of-file<br>
&gt;       vec.push_back( num );<br>
&gt;       indata &gt;&gt; num;}<br>
&gt;    indata.close();<br>
&gt; }<br>
&gt;<br>
&gt; Best,<br>
&gt; Arvind<br>
&gt;<br>
&gt; On Wed, Apr 4, 2012 at 10:53 PM, Matt McCormick &lt;<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi Arvind,<br>
&gt;&gt;<br>
&gt;&gt; It looks like the error is happening inside ReadStreamFile, so please<br>
&gt;&gt; post how that is declared and defined.<br>
&gt;&gt;<br>
&gt;&gt; Thanks,<br>
&gt;&gt; Matt<br>
&gt;&gt;<br>
&gt;&gt; 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;&gt; &gt; Hi all,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; In order to read-in a variable number of points from a file I want to<br>
&gt;&gt; &gt; use a<br>
&gt;&gt; &gt; dynamically sized container like STD::VECTOR. The points are stored like<br>
&gt;&gt; &gt; so:<br>
&gt;&gt; &gt; ( points is the vector I use )<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;       typedef itk::Image&lt; itk::Vector&lt;ComponentType, Dimension&gt;,<br>
&gt;&gt; &gt; Dimension&gt;<br>
&gt;&gt; &gt;                                 PeakImageType;<br>
&gt;&gt; &gt;       typedef PeakImageType::PixelType<br>
&gt;&gt; &gt;                                                        DirectionType;<br>
&gt;&gt; &gt;       std::vector&lt;DirectionType&gt;<br>
&gt;&gt; &gt;                                                                points<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; However, the following try-catch statement gives, at<br>
&gt;&gt; &gt; run-time, &quot;bad_alloc<br>
&gt;&gt; &gt; caught: St9bad_alloc&quot;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;       try<br>
&gt;&gt; &gt;       {<br>
&gt;&gt; &gt;                 std::vector&lt;DirectionType&gt; points;<br>
&gt;&gt; &gt;                 ReadStreamFile&lt;DirectionType&gt;( streamArg.getValue(),<br>
&gt;&gt; &gt; points<br>
&gt;&gt; &gt; );<br>
&gt;&gt; &gt;       }<br>
&gt;&gt; &gt;      catch (std::bad_alloc&amp; ba)<br>
&gt;&gt; &gt;       {<br>
&gt;&gt; &gt;                 std::cerr &lt;&lt; &quot;bad_alloc caught: &quot; &lt;&lt; ba.what() &lt;&lt;<br>
&gt;&gt; &gt; std::endl;<br>
&gt;&gt; &gt;                 return 0;<br>
&gt;&gt; &gt;       }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; So, what is going on? Its seems like POINTS is not being allocated<br>
&gt;&gt; &gt; properly,<br>
&gt;&gt; &gt; but I&#39;m sure how to fix this.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks for any help you can provide.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; Arvind S. Rao, PhD<br>
&gt;&gt; &gt; Section of Biomedical Image Analysis<br>
&gt;&gt; &gt; Department of Radiology<br>
&gt;&gt; &gt; University of Pennsylvania<br>
&gt;&gt; &gt; 3600 Market Street, Suite 380<br>
&gt;&gt; &gt; Philadelphia, PA 19104<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _____________________________________<br>
&gt;&gt; &gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Visit other Kitware open-source projects at<br>
&gt;&gt; &gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt;&gt; &gt; <a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt;&gt; &gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt; &gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;&gt; &gt;<br>
&gt;<br>
&gt;<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; tel: (267) 283-8959<br>
&gt;<br>
</div></div></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></div></div>
</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>