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

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


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 wrote:
> Dear all,
> 
> I use the itk::fem::MaterialLinearElasticity class. And I want to set
> the public attributes (E, A, I, nu, h, RhoC) of an object of this class
> to different values than the default ones.
> 
> If I write for instance these code lines, the code works without problem:
> 
>  itk::fem::MaterialLinearElasticity::Pointer mat_1;
>  mat_1 = itk::fem::MaterialLinearElasticity::New();
>  mat_1->GN=0;
>  mat_1->E = 5;
>  mat_1->A = 5;
>  mat_1->I = 5;
>  mat_1->nu = 5;
>  mat_1->h = 5;
>  mat_1->RhoC = 5;
> 
> But I would like to use the itk::fem::MaterialLinearElasticity::Read 
> (std::istream & f, void * info) member function.
> So I create a text file  (mat1.txt) wherein I write:
> 
> E : 5.0
> A : 5.0
>  I : 5.0
> nu : 5.0
> h : 5.0
> RhoC : 5.0
> 
> Then, I write in my program the following code lines:
> 
> itk::fem::MaterialLinearElasticity::Pointer mat_1;
> mat_1 = itk::fem::MaterialLinearElasticity::New();
> 
> // open the file mat1.txt associated before with matfilename1
>  filebuf fb;
>  if (fb.open(matfilename1.c_str(), ios::in) == 0) {
>     throw_error("Unable to open input file");
>   }
>   std::istream istr(&fb);
> 
>  mat_1->GN=0;
>  mat_1->Read((std::istream&) istr,(void*) NULL);
> 
> // I try also:
> // void *ptr;
> // mat_1->Read((std::istream&) istr,(void*) ptr);
>  
> 
> This code compiles but when I execute it, it aborts at the appeal of Read
> method.
> 
> Remarks:
> (1) I use a NULL pointer because I don't need more information for the
> MaterialLinearElasticity class.
> 
> (2) In the first case, I try also to keep values of E, A, ... from the
> text file to see if problems could be due to the opening of the file but it
> works correctly.
> 
> Does anyone know what's wrong with my code?
> 
> Thanks a lot,
> 
> Lara
>  
>  
>  
>  
> 
> -- 
> 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
> 
>