Public Member Functions | Protected Member Functions

creaImageIO::UltrasonixImageReader Class Reference
[Image I/O classes]

Concrete image reader for ultrasonix 'rf' files. More...

#include <creaImageIOUltrasonixImageReader.h>

Inheritance diagram for creaImageIO::UltrasonixImageReader:
Inheritance graph
[legend]
Collaboration diagram for creaImageIO::UltrasonixImageReader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 UltrasonixImageReader ()
virtual ~UltrasonixImageReader ()
virtual void PushBackExtensions (std::vector< std::string > &)
 Add file extensions read by the reader.
virtual bool CanRead (const std::string &filename)
 Test if file is read by this reader.
virtual vtkImageData * ReadImage (const std::string &filename)
 return for a file a 2D VTkImage
virtual void ReadAttributes (const std::string &filename, tree::AttributeMapType &attr)
 Read the attributes for a file.
virtual void getAttributes (const std::string filename, std::map< std::string, std::string > &infos, std::vector< std::string > i_attr)
 Another function to read attributes for a file.
const std::string & GetName () const
 Get the reader's name.

Protected Member Functions

void SetName (const std::string &s)
 Set the reader's name.

Detailed Description

Concrete image reader for ultrasonix 'rf' files.

Definition at line 15 of file creaImageIOUltrasonixImageReader.h.


Constructor & Destructor Documentation

creaImageIO::UltrasonixImageReader::UltrasonixImageReader (  ) 

Definition at line 12 of file creaImageIOUltrasonixImageReader.cpp.

References creaImageIO::AbstractImageReader::SetName().

  {

Here is the call graph for this function:

creaImageIO::UltrasonixImageReader::~UltrasonixImageReader (  )  [virtual]

Definition at line 19 of file creaImageIOUltrasonixImageReader.cpp.


Member Function Documentation

bool creaImageIO::UltrasonixImageReader::CanRead ( const std::string &  filename  )  [virtual]

Test if file is read by this reader.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 53 of file creaImageIOUltrasonixImageReader.cpp.

References creaImageIO::Ultrasonix_header::frame, HEADER_SIZE, creaImageIO::Ultrasonix_header::height, creaImageIO::ReadHeader(), creaImageIO::Ultrasonix_header::type, TYPE_B32, TYPE_RF, and creaImageIO::Ultrasonix_header::width.

  { 
    long size = -1;
    bool ok = false;
    FILE *Ultrasonix_file=fopen(filename.c_str(), "rb");
    if (Ultrasonix_file) 
    {
        Ultrasonix_header h;
        if (!ReadHeader(Ultrasonix_file, h) )
        {
                fclose(Ultrasonix_file);
                std::cout << "cannot read Ultrasonix header for file [" << filename << "]" << std::endl;                                
                return false;   
        }

        fseek(Ultrasonix_file,0,SEEK_END);              // go to end of file
        if (h.type == TYPE_RF)
                size = (ftell(Ultrasonix_file) - (HEADER_SIZE+h.frame) * sizeof(int)) / sizeof(short);
        else if (h.type == 1)//TYPE_B8)
                size = (ftell(Ultrasonix_file) - (HEADER_SIZE+h.frame+4) *  sizeof(int)) / sizeof(char);
        else if (h.type == TYPE_B32)
                size = (ftell(Ultrasonix_file) - HEADER_SIZE * sizeof(int)) / sizeof(int);

        // check if the data size corresponds to the dimensions of the images
        if (size == h.width * h.height * h.frame )
                ok = true;

        fclose(Ultrasonix_file);

Here is the call graph for this function:

void creaImageIO::UltrasonixImageReader::getAttributes ( const std::string  filename,
std::map< std::string, std::string > &  infos,
std::vector< std::string >  i_attr 
) [virtual]

Another function to read attributes for a file.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 85 of file creaImageIOUltrasonixImageReader.cpp.

  {

const std::string& creaImageIO::AbstractImageReader::GetName (  )  const [inline, inherited]

Get the reader's name.

Definition at line 16 of file creaImageIOAbstractImageReader.h.

Referenced by creaImageIO::VtkImageReader::VtkImageReader().

{

Here is the caller graph for this function:

void creaImageIO::UltrasonixImageReader::PushBackExtensions ( std::vector< std::string > &  v  )  [virtual]

Add file extensions read by the reader.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 178 of file creaImageIOUltrasonixImageReader.cpp.

  {

virtual void creaImageIO::UltrasonixImageReader::ReadAttributes ( const std::string &  filename,
tree::AttributeMapType attr 
) [virtual]

Read the attributes for a file.

Reimplemented from creaImageIO::AbstractImageReader.

vtkImageData * creaImageIO::UltrasonixImageReader::ReadImage ( const std::string &  filename  )  [virtual]

return for a file a 2D VTkImage

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 92 of file creaImageIOUltrasonixImageReader.cpp.

  {
    FILE *Ultrasonix_file=fopen(filename.c_str(),"rb");
    if (!Ultrasonix_file) 
    {
        std::cout << "cannot open file [" << filename << "]" << std::endl;
        return 0;
    }
    Ultrasonix_header h;
    if (!ReadHeader(Ultrasonix_file,h)) 
    {
        std::cout << "cannot read Ultrasonix header for file [" << filename << "]" << std::endl;
        fclose(Ultrasonix_file);  
        return 0;
    }

    long frame_size = h.height   * h.width;      
    long im_size    = frame_size * h.frame;

    short *dataRF,  *ptrRF;
    char  *dataB8,  *ptrB8;
    int   *dataB32, *ptrB32;
    vtkImageData* im;
    int temp;

    switch (h.type)
    {
        case TYPE_RF:
                dataRF = (short*)malloc(sizeof(short)*im_size);
                ptrRF  = dataRF;

                for (int k=0; k<h.frame; k++)
                {
                        int frame_number;
                        fread(&frame_number, sizeof(int), 1, Ultrasonix_file);
                        fread(ptrRF,sizeof(short), frame_size, Ultrasonix_file);
                        ptrRF += frame_size;
                }
                fclose(Ultrasonix_file);  

                im = crea::NewVtkImageDataFromRaw( dataRF, h.width, h.height, h.frame);
        break;

        case TYPE_B8:
                dataB8 = (char*)malloc(sizeof(char)*im_size);
                ptrB8  = dataB8;
                for (int k=0; k<h.frame; k++)
                {
                        fread(ptrB8,sizeof(char), frame_size, Ultrasonix_file);
                        ptrB8 += frame_size;
                }
                // in mode b frames width and height are inverted
                temp     = h.width;
                h.width  = h.height;
                h.height = temp;

                fclose(Ultrasonix_file);  

        im = crea::NewVtkImageDataFromRaw( dataB8, h.width, h.height, h.frame);
        break;

        case TYPE_B32:
                dataB32 = (int*)malloc(sizeof(int)*im_size);
                ptrB32  = dataB32;
                for (int k=0; k<h.frame; k++)
                {
                        fread(ptrB32, sizeof(int), frame_size, Ultrasonix_file);
                        ptrB32 += frame_size;
                }
                // in B mode frames width and height are inverted
                temp     = h.width;
                h.width  = h.height;
                h.height = temp;

                fclose(Ultrasonix_file);  

                im = crea::NewVtkImageDataFromRaw( dataB32, h.width, h.height, h.frame);
        break;
    }

void creaImageIO::AbstractImageReader::SetName ( const std::string &  s  )  [inline, protected, inherited]

Set the reader's name.

Definition at line 36 of file creaImageIOAbstractImageReader.h.

Referenced by creaImageIO::DicomImageReader::DicomImageReader(), UltrasonixImageReader(), and creaImageIO::VtkImageReader::VtkImageReader().

Here is the caller graph for this function:


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