Hi Matt, <div><br></div><div>Thanks for replying. <b>ReadStreamFile(...)</b> is defined below. The "bad_alloc> caught: St9bad_alloc" error seems to originate from this function. For clarity, <b>TPixelType = itk::Vector<float, 3</b>></div>
<div><br></div><div><div>template< typename TPixelType></div>
<div>void <b>ReadStreamFile</b>( std::string filename, std::vector<TPixelType> &points )</div><div>{</div><div> TPixelType dir;</div><div> int num;</div><div> std::vector<float> vec;</div><div> std::ifstream indata( filename.c_str() ); // opens the file</div>
<div><br></div><div> indata >> num;</div><div> while ( !indata.eof() ) { // keep reading until end-of-file</div><div> vec.push_back( num );</div><div> indata >> 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"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></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 <<a href="mailto:arvind.sbia@gmail.com" target="_blank">arvind.sbia@gmail.com</a>> wrote:<br>
> Hi all,<br>
><br>
> In order to read-in a variable number of points from a file I want to use a<br>
> dynamically sized container like STD::VECTOR. The points are stored like so:<br>
> ( points is the vector I use )<br>
><br>
> typedef itk::Image< itk::Vector<ComponentType, Dimension>, Dimension><br>
> PeakImageType;<br>
> typedef PeakImageType::PixelType<br>
> DirectionType;<br>
> std::vector<DirectionType><br>
> points<br>
><br>
> However, the following try-catch statement gives, at run-time, "bad_alloc<br>
> caught: St9bad_alloc"<br>
><br>
> try<br>
> {<br>
> std::vector<DirectionType> points;<br>
> ReadStreamFile<DirectionType>( streamArg.getValue(), points<br>
> );<br>
> }<br>
> catch (std::bad_alloc& ba)<br>
> {<br>
> std::cerr << "bad_alloc caught: " << ba.what() << std::endl;<br>
> return 0;<br>
> }<br>
><br>
> So, what is going on? Its seems like POINTS is not being allocated properly,<br>
> but I'm sure how to fix this.<br>
><br>
> Thanks for any help you can provide.<br>
><br>
><br>
> --<br>
> Arvind S. Rao, PhD<br>
> Section of Biomedical Image Analysis<br>
> Department of Radiology<br>
> University of Pennsylvania<br>
> 3600 Market Street, Suite 380<br>
> Philadelphia, PA 19104<br>
><br>
><br>
><br>
</div></div>> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><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>