[Insight-users] itk::fem::MaterialLinearElasticity::Read

Luis Ibanez luis . ibanez at kitware . com
Thu, 22 May 2003 13:10:53 -0400


Hi Lara,

Thanks for you detailed test.

It looks like the ifstream is being invalidated
just after entering Read() in FEMLightObject.

Could you please check if there is one (or
several) empty lines at the top of you data file ?

The first thing that Read() does is to skip white
spaces and get the first number in the line.

It maybe that an empty line is confusing the parsing.

Please let us know what you find.


Thanks


    Luis


-------------------
Lara Vigneron wrote:
> Hi Luis,
> 
> I work on a Linux platform. This is what I obtain when I use the 
> Exception for the code:
> 
>  itk::fem::MaterialLinearElasticity::Pointer mat_1;
>  mat_1 = itk::fem::MaterialLinearElasticity::New();
>  
>  std::ifstream  inFile;
>  inFile.open( matfilename1.c_str() );
> 
>  if ( inFile.fail() ) cout<<"inFile is not open\n";
>  cout<<"matfilename="<<matfilename1<<"\n";
> 
>   if (!inFile) cout<<"inFile is false\n";
>   else cout<<"inFile is true\n";
>  
>  try
>    {
>      mat_1->Read( inFile ,(void*) NULL);
>    }
>  catch( itk::ExceptionObject & ee )
>    {
>      std::cerr << "Exception caught " << std::endl;
>      std::cerr << ee << std::endl;
>    }
>  catch( ... )
>    {
>      std::cerr << "Unknown exception caught" << std::endl;
>    }
>  
> 
>     inFile.close();
>  
>  
> 
> This is what I obtain:
> 
> matfilename=mat1.txt  //so it's correct
> inFile is true
> 
> Exception caught
>  
> itk::FEMExceptionIO (0x82334f0)
> Location: "FEMLightObject::Read"
> File: 
> /home/vigneron/InsightToolkit-1.2.0/Code/Numerics/FEM/itkFEMLightObject.cxx
> Line: 48
> Description: IO error in FEM class: Error reading FEM object!
>  
>  
>  
> 
> And this line 48 corresponds in the function void FEMLightObject::Read( 
> std::istream& f, void* ) to:
> 
> if( !f )
>   {
>     throw FEMExceptionIO(__FILE__,__LINE__,"FEMLightObject::Read","Error 
> reading FEM object!");
>   }
> 
> Do you have an idea of the problem?
> 
> Thank you, Lara
>  
>  
> 
> Luis Ibanez wrote:
> 
>> Hi Lara,
>>
>> Does the program 'aborts' ?
>>
>> In that case you may be facing an uncaught exception.
>> It will be helpful to put the Read in between a
>> try/catch block like
>>
>> try
>> {
>>    ..Read..
>> }
>> catch( itk::ExceptionObject & ee )
>> {
>>     std::cerr << "Exception caught " << std::endl;
>>     std::cerr << ee << std::endl;
>> }
>> catch( ... )
>> {
>>     std::cerr << "Unknown exception caught" << std::endl;
>> }
>>
>> The printed message may provide enough information
>> to figure out the real source of the problem.
>>
>> In what platform are you running  ?
>> Could you run in a debugger ?
>>
>> Please let us know what you find.
>>
>>    Luis
>>
>> ---------------------------------------
>> Lara Vigneron wrote:
>> > Hi Luis,
>> >
>> > Thank you for your suggestion. I try to open the file with your code
>> > lines but
>> > it doesn't seem to change anything...
>> >
>> > Do you think to some other reason my program aborts?
>> >
>> > Thank you,
>> >
>> > Lara
>> >
>> >
>> >
>> > Luis Ibanez wrote:
>> >
>> >> Hi Lara,
>> >>
>> >> Is there any reason for opening the file
>> >> in the way you are doing now ?
>> >>
>> >> A far simpler way may be the following:
>> >>
>> >>     std::ifstream  inFile;
>> >>     inFile.open( matfilename1.c_str() );
>> >>
>> >>     if( inFile.fail() ) return -1;
>> >>
>> >> and then
>> >>
>> >>     mat_1->Read( inFile ,(void*) NULL);
>> >>
>> >>     inFile.close();
>> >>
>> >> The NULL seems to be ok, since the
>> >> MaterialLinearElasticity doesn't use
>> >> this argument in the Read() method.
>> >>
>> >> Regards,
>> >>
>> >>    Luis
>> >>
>> >>
>> > --
>> > Lara VIGNERON
>> >
>> > Signal Processing Group
>> >
>> > University of Liege
>> > Institut Montefiore
>> > Sart-Tilman, Batiment B28
>> > B-4000 Liege
>> > BELGIUM
>> >
>> > Tel: +32-(0)4-366.26.42
>> > Fax: +32-(0)4-366.29.84
>> > Lara . Vigneron at ulg . ac . be
>> >
>> >
>>
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at public . kitware . com
>> http://public . kitware . com/mailman/listinfo/insight-users
>>
> -- 
> Lara VIGNERON
> 
> Signal Processing Group
> 
> University of Liege
> Institut Montefiore
> Sart-Tilman, Batiment B28
> B-4000 Liege
> BELGIUM
> 
> Tel: +32-(0)4-366.26.42
> Fax: +32-(0)4-366.29.84
> Lara . Vigneron at ulg . ac . be
> 
>