creaImageIO_lib
creaImageIO::UltrasonixImageReader Class Reference

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

#include <creaImageIOUltrasonixImageReader.h>

Inheritance diagram for creaImageIO::UltrasonixImageReader:
Collaboration diagram for creaImageIO::UltrasonixImageReader:

Public Member Functions

 UltrasonixImageReader ()
 
virtual ~UltrasonixImageReader ()
 
virtual void PushBackExtensions (std::vector< std::string > &)
 Add file extensions read by the reader. More...
 
virtual bool CanRead (const std::string &filename)
 Test if file is read by this reader. More...
 
virtual vtkImageData * ReadImage (const std::string &filename)
 return for a file a 2D VTkImage More...
 
virtual void ReadAttributes (const std::string &filename, tree::AttributeMapType &attr)
 Read the attributes for a file. More...
 
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. More...
 
const std::string & GetName () const
 Get the reader's name. More...
 

Protected Member Functions

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

Detailed Description

Concrete image reader for ultrasonix 'rf' files.

Definition at line 43 of file creaImageIOUltrasonixImageReader.h.

Constructor & Destructor Documentation

creaImageIO::UltrasonixImageReader::UltrasonixImageReader ( )

Definition at line 47 of file creaImageIOUltrasonixImageReader.cpp.

References creaImageIO::AbstractImageReader::SetName().

48  {
49  SetName("Ultrasonix");
50  }

Here is the call graph for this function:

creaImageIO::UltrasonixImageReader::~UltrasonixImageReader ( )
virtual

Definition at line 54 of file creaImageIOUltrasonixImageReader.cpp.

55  {
56  }

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 88 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.

89  {
90  long size = -1;
91  bool ok = false;
92  FILE *Ultrasonix_file=fopen(filename.c_str(), "rb");
93  if (Ultrasonix_file)
94  {
95  Ultrasonix_header h;
96  if (!ReadHeader(Ultrasonix_file, h) )
97  {
98  fclose(Ultrasonix_file);
99  std::cout << "cannot read Ultrasonix header for file [" << filename << "]" << std::endl;
100  return false;
101  }
102 
103  fseek(Ultrasonix_file,0,SEEK_END); // go to end of file
104  if (h.type == TYPE_RF)
105  size = (ftell(Ultrasonix_file) - (HEADER_SIZE+h.frame) * sizeof(int)) / sizeof(short);
106  else if (h.type == 1)//TYPE_B8)
107  size = (ftell(Ultrasonix_file) - (HEADER_SIZE+h.frame+4) * sizeof(int)) / sizeof(char);
108  else if (h.type == TYPE_B32)
109  size = (ftell(Ultrasonix_file) - HEADER_SIZE * sizeof(int)) / sizeof(int);
110 
111  // check if the data size corresponds to the dimensions of the images
112  if (size == h.width * h.height * h.frame )
113  ok = true;
114 
115  fclose(Ultrasonix_file);
116  }
117  return ok;
118  }

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 120 of file creaImageIOUltrasonixImageReader.cpp.

122  {
123  //TO DO
124  }
const std::string& creaImageIO::AbstractImageReader::GetName ( ) const
inlineinherited

Get the reader's name.

Definition at line 56 of file creaImageIOAbstractImageReader.h.

References creaImageIO::AbstractImageReader::mName.

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

56 { return mName; }

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 213 of file creaImageIOUltrasonixImageReader.cpp.

214  {
215  v.push_back("Ultrasonix");
216  }
void creaImageIO::UltrasonixImageReader::ReadAttributes ( const std::string &  filename,
tree::AttributeMapType attr 
)
virtual

Read the attributes for a file.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 222 of file creaImageIOUltrasonixImageReader.cpp.

References creaImageIO::Ultrasonix_header::frame, creaImageIO::Ultrasonix_header::frequency, GimmickMessage, creaImageIO::Ultrasonix_header::height, creaImageIO::ReadHeader(), creaImageIO::Ultrasonix_header::samplingRate, and creaImageIO::Ultrasonix_header::width.

224  {
225  GimmickMessage(2,"Reading attributes from '" << filename << std::endl);
226 
227  FILE *Ultrasonix_file = fopen(filename.c_str(), "rb");
228  if (!Ultrasonix_file)
229  {
230  std::cout << "cannot open RF file [" << filename << "]" << std::endl;
231  return;
232  }
233 
234  Ultrasonix_header h;
235  if (!ReadHeader(Ultrasonix_file, h))
236  {
237  fclose(Ultrasonix_file);
238  std::cout << "cannot read Ultrasonix Attributes for RF file [" << filename << "]" << std::endl;
239  return;
240  }
241 
242  fclose(Ultrasonix_file);
243 
244  // Columns
245  char cols[128];
246  sprintf(cols,"%i", h.width);
247  // Rows
248  char rows[128];
249  sprintf(rows,"%i", h.height);
250  // Planes
251  char planes[128];
252  sprintf(planes,"%i", h.frame);
253  // Sampling frequency
254  char samplingFrequency[128];
255  sprintf(samplingFrequency,"%i", h.samplingRate);
256  // Transducer frequency
257  char transducerFrequency[128];
258  sprintf(transducerFrequency,"%i", h.frequency);
259 
260  //
261  std::map<std::string,std::string>::iterator i;
262  if ( (i = attr.find("FullFileName")) != attr.end())
263  {
264  i->second = filename;
265  }
266  if ( (i = attr.find("D0004_1500")) != attr.end())
267  {
268  boost::filesystem::path full_path(filename);
269  std::string f = full_path.leaf().string();
270  i->second = f;
271  }
272  if ( (i = attr.find("D0028_0010")) != attr.end())
273  {
274  i->second = rows;
275  }
276  if ( (i = attr.find("D0028_0011")) != attr.end())
277  {
278  i->second = cols;
279  }
280  if ( (i = attr.find("D0028_0012")) != attr.end())
281  {
282  i->second = planes;
283  }
284  if ( (i = attr.find("D003a_001a")) != attr.end())
285  {
286  i->second = samplingFrequency;
287  }
288  if ( (i = attr.find("D0018_6030")) != attr.end())
289  {
290  i->second = transducerFrequency;
291  }
292 
293  GimmickMessage(2,"Attributes map:"<<std::endl<<attr<<std::endl);
294  return;
295 }

Here is the call graph for this function:

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

return for a file a 2D VTkImage

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 127 of file creaImageIOUltrasonixImageReader.cpp.

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

128  {
129  FILE *Ultrasonix_file=fopen(filename.c_str(),"rb");
130  if (!Ultrasonix_file)
131  {
132  std::cout << "cannot open file [" << filename << "]" << std::endl;
133  return 0;
134  }
135  Ultrasonix_header h;
136  if (!ReadHeader(Ultrasonix_file,h))
137  {
138  std::cout << "cannot read Ultrasonix header for file [" << filename << "]" << std::endl;
139  fclose(Ultrasonix_file);
140  return 0;
141  }
142 
143  long frame_size = h.height * h.width;
144  long im_size = frame_size * h.frame;
145 
146  short *dataRF, *ptrRF;
147  char *dataB8, *ptrB8;
148  int *dataB32, *ptrB32;
149  vtkImageData* im;
150  int temp;
151 
152  switch (h.type)
153  {
154  case TYPE_RF:
155  dataRF = (short*)malloc(sizeof(short)*im_size);
156  ptrRF = dataRF;
157 
158  for (int k=0; k<h.frame; k++)
159  {
160  int frame_number;
161  fread(&frame_number, sizeof(int), 1, Ultrasonix_file);
162  fread(ptrRF,sizeof(short), frame_size, Ultrasonix_file);
163  ptrRF += frame_size;
164  }
165  fclose(Ultrasonix_file);
166 
167  im = crea::NewVtkImageDataFromRaw( dataRF, h.width, h.height, h.frame);
168  break;
169 
170  case TYPE_B8:
171  dataB8 = (char*)malloc(sizeof(char)*im_size);
172  ptrB8 = dataB8;
173  for (int k=0; k<h.frame; k++)
174  {
175  fread(ptrB8,sizeof(char), frame_size, Ultrasonix_file);
176  ptrB8 += frame_size;
177  }
178  // in mode b frames width and height are inverted
179  temp = h.width;
180  h.width = h.height;
181  h.height = temp;
182 
183  fclose(Ultrasonix_file);
184 
185  im = crea::NewVtkImageDataFromRaw( dataB8, h.width, h.height, h.frame);
186  break;
187 
188  case TYPE_B32:
189  dataB32 = (int*)malloc(sizeof(int)*im_size);
190  ptrB32 = dataB32;
191  for (int k=0; k<h.frame; k++)
192  {
193  fread(ptrB32, sizeof(int), frame_size, Ultrasonix_file);
194  ptrB32 += frame_size;
195  }
196  // in B mode frames width and height are inverted
197  temp = h.width;
198  h.width = h.height;
199  h.height = temp;
200 
201  fclose(Ultrasonix_file);
202 
203  im = crea::NewVtkImageDataFromRaw( dataB32, h.width, h.height, h.frame);
204  break;
205  }
206 
207  return im;
208 }

Here is the call graph for this function:

void creaImageIO::AbstractImageReader::SetName ( const std::string &  s)
inlineprotectedinherited

Set the reader's name.

Definition at line 79 of file creaImageIOAbstractImageReader.h.

References creaImageIO::AbstractImageReader::mName.

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

79 { mName = s; }

Here is the caller graph for this function:


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