marRAW2Files Class Reference

#include <marDicomBase.h>

Inheritance diagram for marRAW2Files:
Inheritance graph
[legend]
Collaboration diagram for marRAW2Files:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 marRAW2Files (marParameters *p=NULL)
 ~marRAW2Files ()
virtual bool loadImage (int i)
virtual void loadActualSerie (wxGauge *gauge)
virtual void saveVolume (std::string directory, std::string filename, vtkImageData *vtkimagedata, int voi[6], double slope, double intercept)
void FlipY (vtkImageData *imagedata)
void SetLittreEndianBigEndian (int value)
int GetLittreEndianBigEndian ()
void reset ()
void copyFrom (const marObject &from)
virtual void copyFrom (const marObject &from)=0
bool save (std::ofstream &os)
bool save (std::string &nw)
bool load (std::ifstream &is)
bool load (std::string &nr)
virtual wxString GetPatientName ()
kVolume * getVolume ()
void SetVolume (kVolume *volume)
bool volumeLoaded ()
void freeVolume ()
std::vector< std::string * > * GetListImages ()
void CleanListImages ()
void ResetLstFileNotReaded ()
std::string GetMsgLstFile ()
void setParameters (marParameters *p)
void copyParameters (marParameters *p)
void makeACopyParameters ()
marParametersgetParameters ()
bool parametersOwned ()

Protected Attributes

std::vector< std::string * > _lstString
std::vector< char * > _lstFileNotReaded

Detailed Description

Definition at line 76 of file marDicomBase.h.


Constructor & Destructor Documentation

marRAW2Files::marRAW2Files ( marParameters p = NULL  ) 

Definition at line 410 of file marDicomBase.cpp.

00411 :  marRAWFiles(p)
00412 {
00413 }

marRAW2Files::~marRAW2Files (  ) 

Definition at line 415 of file marDicomBase.cpp.

00416 {
00417 }


Member Function Documentation

void marFilesBase::CleanListImages (  )  [inherited]

Definition at line 45 of file marDicomBase.cpp.

References marFilesBase::_lstString.

Referenced by loadActualSerie(), marRAW2AsciiFiles::loadActualSerie(), and marRAWFiles::loadActualSerie().

00046 {
00047         int i,size;
00048         size=this->_lstString.size();
00049         for(i=0;i<size;i++)
00050         {
00051                 delete _lstString[i];
00052         }
00053         _lstString.clear();
00054 }

Here is the caller graph for this function:

virtual void marObject::copyFrom ( const marObject from  )  [pure virtual, inherited]
void marRAWFiles::copyFrom ( const marObject from  )  [inherited]

Definition at line 269 of file marDicomBase.cpp.

00270 {
00271 }

void marObject::copyParameters ( marParameters p  )  [inherited]

Definition at line 42 of file marObject.cpp.

References marObject::_parameters, and marObject::_parametersCopied.

00043 {
00044     if( _parametersCopied && _parameters != NULL ) delete _parameters;
00045     _parameters = new marParameters( );
00046     *_parameters = *p;
00047     _parametersCopied = true;
00048 }

void marRAW2Files::FlipY ( vtkImageData *  imagedata  ) 

Definition at line 608 of file marDicomBase.cpp.

Referenced by loadActualSerie().

00609 {
00610         vtkImageData *vtkimagedata = imagedata;
00611         vtkimagedata->Update();
00612         int dim[3];
00613         vtkimagedata->GetDimensions(dim);
00614         unsigned short tmp;
00615         unsigned short *pp=(unsigned short*)vtkimagedata->GetScalarPointer(0,0,0);
00616         int xx,yy,zz;
00617         int sizeX  = dim[0];
00618         int sizeY  = dim[1];
00619         int sizeY2 = sizeY/2;
00620         int sizeZ  = dim[2];
00621         long int deltaZ;
00622         long int deltaA;
00623         long int deltaB;
00624 
00625         for ( zz=0 ; zz<sizeZ ; zz++ )
00626         {
00627                 deltaZ=zz*sizeX*sizeY;
00628                 for ( xx=0 ; xx<sizeX ; xx++ )
00629                 {
00630                 for ( yy=0 ; yy<sizeY2 ; yy++ )
00631                         {
00632                                 deltaA          = xx + yy*sizeX + deltaZ;
00633                                 deltaB          = xx + (sizeY-yy-1)*sizeX + deltaZ;
00634                                 tmp                     = pp[deltaA ];
00635                                 pp[deltaA]      = pp[deltaB ];
00636                                 pp[deltaB]      = tmp;
00637                                 }
00638                         }
00639                 }
00640    vtkimagedata->Update();
00641 
00642 }

Here is the caller graph for this function:

void marFilesBase::freeVolume (  )  [inherited]

Definition at line 31 of file marDicomBase.cpp.

References marFilesBase::_volume.

Referenced by InitExperiment_dll(), loadActualSerie(), marRAW2AsciiFiles::loadActualSerie(), marRAWFiles::loadActualSerie(), and marFilesBase::~marFilesBase().

00031                               {
00032         if( _volume ) delete _volume;
00033         _volume = NULL;
00034 }

Here is the caller graph for this function:

std::vector< std::string * > * marFilesBase::GetListImages (  )  [inherited]

Definition at line 39 of file marDicomBase.cpp.

References marFilesBase::_lstString.

00040 {
00041         return &_lstString;
00042 }

int marRAWFiles::GetLittreEndianBigEndian (  )  [inherited]

Definition at line 260 of file marDicomBase.cpp.

References marRAWFiles::_littreEndianBigEndian.

00261 {
00262         return _littreEndianBigEndian;
00263 }

std::string marFilesBase::GetMsgLstFile (  )  [inherited]

Definition at line 65 of file marDicomBase.cpp.

References marFilesBase::_lstFileNotReaded.

Referenced by LoadRangeImage::ForceToFinisReadActiveImages().

00066 {
00067         int i,sizeLst;
00068 //EEDx44
00069         std::string msgLstFile="";
00070         sizeLst=_lstFileNotReaded.size();
00071         for (i=0;i<sizeLst;i++)
00072         {
00073                 msgLstFile = msgLstFile + *(_lstFileNotReaded[i]) ;
00074                 msgLstFile = msgLstFile + "\n";
00075         }
00076 
00077         return msgLstFile;
00078 }

Here is the caller graph for this function:

marParameters* marObject::getParameters (  )  [inline, inherited]
virtual wxString marFilesBase::GetPatientName (  )  [inline, virtual, inherited]

Definition at line 26 of file marDicomBase.h.

00026 {return _T(""); };

kVolume * marFilesBase::getVolume (  )  [inherited]
bool marObject::load ( std::string &  nr  )  [inherited]

Definition at line 67 of file marObject.cpp.

References marObject::load().

Referenced by marObject::load().

00068 {
00069     std::ifstream is( nr.c_str( ) );
00070 
00071     if( is ) {
00072 
00073         load( is );
00074         is.close( );
00075         return( true );
00076 
00077     } // fi
00078 
00079     return( false );
00080 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool marRAWFiles::load ( std::ifstream &  is  )  [virtual, inherited]

Implements marObject.

Definition at line 278 of file marDicomBase.cpp.

00279 {
00280         return true;
00281 }

void marRAW2Files::loadActualSerie ( wxGauge *  gauge  )  [virtual]

Reimplemented from marRAWFiles.

Definition at line 427 of file marDicomBase.cpp.

References marFilesBase::_lstString, marFilesBase::CleanListImages(), marParameters::e_RescaleIntercept, marParameters::e_RescaleSlope, marParameters::e_voxel_x_dimension, marParameters::e_voxel_y_dimension, marParameters::e_voxel_z_dimension, FlipY(), marFilesBase::freeVolume(), marObject::getParameters(), marFilesBase::getVolume(), marParameters::setDoubleParam(), and marFilesBase::SetVolume().

00428 {
00429 
00430         // Read File List
00431         FILE *ff;
00432         ff = fopen( _lstString[0] -> c_str() , "r"); 
00433         char tmp[255];
00434 
00435         // type
00436         fscanf(ff,"%s",tmp);
00437         fscanf(ff,"%s",tmp);
00438         //int type =    atoi(tmp);  // 200  // JPRx
00439 
00440         //size x,y,z
00441         fscanf(ff,"%s",tmp);
00442         fscanf(ff,"%s",tmp);
00443         int wx  =       atoi(tmp);
00444         fscanf(ff,"%s",tmp);
00445         fscanf(ff,"%s",tmp);
00446         int wy  =       atoi(tmp);
00447 //      fscanf(ff,"%s",tmp);
00448 //      fscanf(ff,"%s",tmp);
00449 //      int wz  =       atoi(tmp);
00450 
00451         fscanf(ff,"%s",tmp);
00452         fscanf(ff,"%s",tmp);
00453         int wz1 =       atoi(tmp);
00454         fscanf(ff,"%s",tmp);
00455         fscanf(ff,"%s",tmp);
00456         int wz2 =       atoi(tmp);
00457 
00458         int wz = wz2-wz1;
00459         
00460         // spacing x,y,z
00461         fscanf(ff,"%s",tmp);
00462         fscanf(ff,"%s",tmp);
00463         double spx      =       atof(tmp);
00464         fscanf(ff,"%s",tmp);
00465         fscanf(ff,"%s",tmp);
00466         double spy      =       atof(tmp);
00467         fscanf(ff,"%s",tmp);
00468         fscanf(ff,"%s",tmp);
00469         double spz      =       atof(tmp);
00470 
00471         // Intercept Slope
00472         fscanf(ff,"%s",tmp);
00473         fscanf(ff,"%s",tmp);
00474         double intercept        =       atof(tmp);
00475         fscanf(ff,"%s",tmp);
00476         fscanf(ff,"%s",tmp);
00477         double slope            =       atof(tmp);
00478 
00479         // L/B
00480         fscanf(ff,"%s",tmp);
00481         fscanf(ff,"%s",tmp);
00482         int littleBig   =       atoi(tmp);
00483 
00484         // bits
00485         fscanf(ff,"%s",tmp);
00486         fscanf(ff,"%s",tmp);
00487         int bits        =       atoi(tmp);
00488 
00489         if ((bits!=8) && (bits!=16)){
00490                 bits=16;
00491         }
00492         
00493         fscanf(ff,"%s",tmp);
00494         std::string file(tmp);
00495         std::string namefile( *_lstString[1] );  // directory
00496         namefile=namefile+"/";                   // +  
00497         namefile=namefile+file;                  // file
00498 
00499         fclose(ff);
00500 
00501 
00502         this->CleanListImages();
00503 
00504         // Create Free Memory block image
00505         freeVolume();
00506 
00507         if (wz==0)
00508         {
00509                 wz=1;
00510         }
00511 
00512 
00513         kVolume *vol =new kVolume( kVolume::USHORT, wx, wy, wz,spx, spy, spz, malloc(sizeof(unsigned short)*wx*wy*wz ) );
00514         SetVolume( vol );
00515 
00516 
00517         // Define Spacing
00518         getParameters( )->setDoubleParam( marParameters::e_voxel_x_dimension, spx );
00519         getParameters( )->setDoubleParam( marParameters::e_voxel_y_dimension, spy );
00520         getParameters( )->setDoubleParam( marParameters::e_voxel_z_dimension, spz );
00521 
00522         // Define Intercept Slope
00523         getParameters( )->setDoubleParam( marParameters::e_RescaleIntercept , 0 );
00524         getParameters( )->setDoubleParam( marParameters::e_RescaleSlope     , 1 );
00525 
00526         void *p_vol=(void*)getVolume( )->castVtk()->GetScalarPointer(0,0,0);
00527         FILE *fff=fopen( (char*)namefile.c_str() , "r+" );
00528     if (bits==16)
00529     {
00530                 fseek( fff , wx*wy*wz1*2 , SEEK_CUR );
00531         fread( (char*)p_vol , wx*wy*wz*2,1, fff);
00532             fclose(fff);
00533 
00534 
00535         // littleBigEndien
00536                 if (littleBig==1){
00537                         long int                ii;
00538                         char                    tmpB;
00539                         char                    *pp = (char*)p_vol;
00540                         unsigned short   *valueA;
00541                         long int dataSize       = wx*wy*wz;
00542                         for (ii=0;ii<dataSize;ii++)
00543                         {
00544                                 tmpB            = *pp;
00545                                 *pp                     = *(pp+1);
00546                                 *(pp+1)         = tmpB;
00547                                 
00548                                 valueA= ((unsigned short*)pp);
00549                                 if (*valueA>=32000)
00550                                 {
00551                                         *valueA=0;
00552                                 } 
00553                                 pp              = pp+2;
00554 
00555                         }
00556                 }
00557 
00558                 unsigned short                  *pp = (unsigned short*)p_vol;
00559                 int tmpInt;
00560                 int ii, dataSize        = wx*wy*wz;
00561                 for (ii=0;ii<dataSize;ii++)
00562                 {
00563                         tmpInt = (int) (*pp);
00564                         tmpInt  = (int)  ( tmpInt*slope+intercept );
00565                         if (tmpInt<0)
00566                         {
00567                                 tmpInt=0;
00568                         } 
00569                         if (tmpInt>65535) 
00570                         {
00571                                 tmpInt=65535;
00572                         }
00573                         (*pp) = (unsigned short)tmpInt;
00574                         pp              = pp+1;
00575                 }
00576 
00577     } else {
00578         unsigned short *pShort=(unsigned short*)p_vol;
00579         int i8bitImage,size8bitImage = wx*wy*wz;
00580         unsigned char *pChar=(unsigned char*)malloc( size8bitImage );
00581                 fseek( fff , wx*wy*wz1 , SEEK_CUR );
00582         fread( (unsigned char*)pChar , size8bitImage,1, fff);
00583             fclose(fff);
00584                 double tmpDouble;
00585         for ( i8bitImage=0 ; i8bitImage < size8bitImage ; i8bitImage++ )
00586         {
00587                         
00588                         tmpDouble=(float)pChar[ i8bitImage ];
00589                         tmpDouble=tmpDouble*slope+intercept;
00590                         if (tmpDouble<0)
00591                         {
00592                                 tmpDouble=0;
00593                         } 
00594                 pShort[ i8bitImage ] = (unsigned short)tmpDouble;
00595         }
00596         free (pChar);
00597     }
00598 
00599 // Y- Flip
00600         FlipY( getVolume( )->castVtk() );
00601         
00602 }

Here is the call graph for this function:

bool marRAW2Files::loadImage ( int  i  )  [virtual]

Reimplemented from marRAWFiles.

Definition at line 419 of file marDicomBase.cpp.

00420 {
00421         return true;
00422 }

void marObject::makeACopyParameters (  )  [inline, inherited]

Definition at line 48 of file marObject.h.

00049     {
00050             copyParameters( _parameters );
00051     }

bool marObject::parametersOwned (  )  [inline, inherited]

Definition at line 56 of file marObject.h.

00056 { return( _parametersCopied ); };

void marRAWFiles::reset (  )  [virtual, inherited]

Virtual general methods (must be defined in each sub-class).

Implements marObject.

Definition at line 265 of file marDicomBase.cpp.

00266 {
00267 }

void marFilesBase::ResetLstFileNotReaded (  )  [inherited]

Definition at line 58 of file marDicomBase.cpp.

References marFilesBase::_lstFileNotReaded.

Referenced by LoadRangeImage::Start().

00059 {
00060         _lstFileNotReaded.clear();
00061 }

Here is the caller graph for this function:

bool marObject::save ( std::string &  nw  )  [inherited]

Persistence methods

Definition at line 51 of file marObject.cpp.

References marObject::save().

00052 {
00053     std::ofstream os( nw.c_str( ) );
00054 
00055     if( os ) {
00056 
00057         save( os );
00058         os.close( );
00059         return( true );
00060 
00061     } // fi
00062 
00063     return( false );
00064 }

Here is the call graph for this function:

bool marRAWFiles::save ( std::ofstream &  os  )  [virtual, inherited]

Virtual persistence methods (must be defined in each sub-class).

Implements marObject.

Definition at line 273 of file marDicomBase.cpp.

00274 {
00275         return true;
00276 }

void marRAW2Files::saveVolume ( std::string  directory,
std::string  filename,
vtkImageData *  vtkimagedata,
int  voi[6],
double  slope,
double  intercept 
) [virtual]

Definition at line 646 of file marDicomBase.cpp.

Referenced by marAxisCT::generateFile(), wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(), and wxMaracasImageBrowser02::OnBtSaveVOIData().

00647 {
00648 
00649         std::string filename             = directory+"/"+name;
00650 
00651                 // Crop
00652         vtkExtractVOI *crop = vtkExtractVOI::New();
00653         crop->SetInput( imagedata );
00654         crop->SetVOI( voi );
00655         crop->Update();
00656 
00657         int dim[3];
00658         int ext[6];
00659         double spc[3];
00660         crop->GetOutput()->GetDimensions(dim);
00661         crop->GetOutput()->GetSpacing(spc);
00662         crop->GetOutput()->GetExtent(ext);
00663 
00664 
00665         vtkImageChangeInformation* change = vtkImageChangeInformation::New();
00666         change->SetInput( crop->GetOutput() );
00667 
00668 
00669 //      change->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
00670    
00671 
00672         change->SetOutputSpacing ( spc[0] , spc[1] , spc[2] );
00673         change->Update();    //important
00674 
00675 //   change->SetExtentTranslation( ext[0], ext[2], ext[4] );
00676 //      change->Update();
00677 
00678 
00679         // write mdh file
00680    std::string nameMW            = filename+".mhd";
00681 
00682         vtkMetaImageWriter *writer = vtkMetaImageWriter::New( );
00683         writer->SetInput( change->GetOutput() );
00684         writer->SetFileName( nameMW.c_str() );
00685         writer->SetFileDimensionality( 3 );
00686         writer->Write( );
00687 
00688                 // write maracas file
00689         std::string nameM=filename+".maracas";
00690 
00691 
00692         FILE *ff;
00693         ff=fopen(nameM.c_str(),"w");
00694                 fprintf(ff,"MaracasType 200\n" );
00695                 fprintf(ff,"sizeX %d\n",dim[0] );
00696                 fprintf(ff,"sizeY %d\n",dim[1] );
00697                 fprintf(ff,"sizeZ1 %d\n",0 );
00698                 fprintf(ff,"sizeZ2 %d\n",dim[2] );
00699                 fprintf(ff,"spcX %f\n",spc[0]  );
00700                 fprintf(ff,"spcY %f\n",spc[1]  );
00701                 fprintf(ff,"spcZ %f\n",spc[2]  );
00702                 fprintf(ff,"intercept %f\n",intercept );
00703                 fprintf(ff,"slope %f\n",slope );
00704                 fprintf(ff,"LB %d\n",0 );
00705                 fprintf(ff,"bits %d\n",16 );
00706                 fprintf(ff,"%s.raw\n", name.c_str() );
00707         fclose(ff);
00708 
00709         writer  -> Delete();
00710         change  -> Delete();
00711         crop    -> Delete();
00712 }

Here is the caller graph for this function:

void marRAWFiles::SetLittreEndianBigEndian ( int  value  )  [inherited]

Definition at line 255 of file marDicomBase.cpp.

References marRAWFiles::_littreEndianBigEndian.

Referenced by marRAWFiles::loadActualSerie().

00256 {
00257         _littreEndianBigEndian = value;
00258 }

Here is the caller graph for this function:

void marObject::setParameters ( marParameters p  )  [inherited]

Parameters assignation methods.

You can assign a marParameters object by reference (setParameters) or by value (copyParameters). Besides, if you want to make your actual reference to be by value, call makeACopyParameters.

Definition at line 34 of file marObject.cpp.

References marObject::_parameters, and marObject::_parametersCopied.

00035 {
00036     if( _parametersCopied && _parameters != NULL ) delete _parameters;
00037     _parameters = p;
00038     _parametersCopied = false;
00039 }

void marFilesBase::SetVolume ( kVolume *  volume  )  [inherited]

Definition at line 23 of file marDicomBase.cpp.

References marFilesBase::_volume.

Referenced by loadActualSerie(), marRAW2AsciiFiles::loadActualSerie(), marRAWFiles::loadActualSerie(), marSimpleDicom::loadVolumeDXMM(), and wxMaracasFrame::OnStartExperiment().

00023                                               {
00024         _volume=volume;
00025 }

Here is the caller graph for this function:

bool marFilesBase::volumeLoaded (  )  [inherited]

Definition at line 27 of file marDicomBase.cpp.

References marFilesBase::_volume.

00027                                 {
00028         return( _volume != NULL );
00029 }


Member Data Documentation

std::vector< char*> marFilesBase::_lstFileNotReaded [protected, inherited]
std::vector< std::string*> marFilesBase::_lstString [protected, inherited]

The documentation for this class was generated from the following files:

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1