creaImageIO_lib
creaImageIO::VtkImageReader Class Reference

Concrete image reader based on a vtkImageReader2. More...

#include <creaImageIOVtkImageReader.h>

Inheritance diagram for creaImageIO::VtkImageReader:
Collaboration diagram for creaImageIO::VtkImageReader:

Public Member Functions

 VtkImageReader (vtkImageReader2 *reader, const std::string &name="", const std::string &extensions="")
 
virtual ~VtkImageReader ()
 
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...
 

Private Attributes

vtkImageReader2 * mReader
 
std::string mExtensions
 

Detailed Description

Concrete image reader based on a vtkImageReader2.

Definition at line 46 of file creaImageIOVtkImageReader.h.

Constructor & Destructor Documentation

creaImageIO::VtkImageReader::VtkImageReader ( vtkImageReader2 *  reader,
const std::string &  name = "",
const std::string &  extensions = "" 
)

Definition at line 39 of file creaImageIOVtkImageReader.cpp.

References mReader, and creaImageIO::AbstractImageReader::SetName().

42  : mReader(r), mExtensions(extensions)
43  {
44 
45  //EED 21 mars 2012 FLIP probleme ..PLOP..
46  mReader->FileLowerLeftOff();
47 
48  if (name.size() == 0)
49  {
50  const char *test =mReader->GetDescriptiveName();
51  //warning: comparison with string literal results in unspecified behaviour
52  //if(test != "")
53  std::string emptyString("");
54  if(test != emptyString)
55  {
56  SetName ( "toto");// mReader->GetDescriptiveName());
57  }
58  }
59  else
60  {
61  SetName ( name );
62  }
63 
64 
65  }

Here is the call graph for this function:

creaImageIO::VtkImageReader::~VtkImageReader ( )
virtual

Definition at line 69 of file creaImageIOVtkImageReader.cpp.

References mReader.

70  {
71 
72  mReader->Delete();
73  }

Member Function Documentation

bool creaImageIO::VtkImageReader::CanRead ( const std::string &  filename)
virtual

Test if file is read by this reader.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 77 of file creaImageIOVtkImageReader.cpp.

References mReader.

78  {
79 
80  return (mReader->CanReadFile(filename.c_str())!=0);
81 /* if(filename != "")
82  {
83  return (mReader->CanReadFile(filename.c_str())!=0);
84  }
85  else
86  {
87  return false;
88  }*/
89  }
void creaImageIO::VtkImageReader::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 91 of file creaImageIOVtkImageReader.cpp.

93  {
94  }
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 ReadImage().

56 { return mName; }

Here is the caller graph for this function:

void creaImageIO::VtkImageReader::PushBackExtensions ( std::vector< std::string > &  v)
virtual

Add file extensions read by the reader.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 186 of file creaImageIOVtkImageReader.cpp.

References mExtensions, mReader, and creaImageIO::SplitExtensionsString().

187  {
188  std::string ext = mExtensions;
189  if (ext.size()==0) ext = mReader->GetFileExtensions ();
190 
191  SplitExtensionsString(ext," ",v);
192  }

Here is the call graph for this function:

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

Read the attributes for a file.

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 198 of file creaImageIOVtkImageReader.cpp.

References mReader.

200  {
201 
202  // Get image dimensions
203  // How to get the image info without loading it in vtk ?
204  mReader->SetFileName(filename.c_str());
205  mReader->Update(); //OpenFile();
206  int ext[6];
207  mReader->GetDataExtent(ext);
208  // Columns
209  char cols[128];
210  sprintf(cols,"%i",ext[1]-ext[0]);
211  // Rows
212  char rows[128];
213  sprintf(rows,"%i",ext[3]-ext[2]);
214  // Planes
215  char planes[128];
216  sprintf(planes,"%i",ext[5]-ext[4]);
217 
218  std::map<std::string,std::string>::iterator i;
219  if ( (i = attr.find("FullFileName")) != attr.end())
220  {
221  i->second = filename;
222  }
223  if ( (i = attr.find("D0004_1500")) != attr.end())
224  {
225  boost::filesystem::path full_path(filename);
226  std::string f = full_path.leaf().string();
227  i->second = f;
228  }
229  if ( (i = attr.find("D0028_0010")) != attr.end())
230  {
231  i->second = rows;
232  }
233  if ( (i = attr.find("D0028_0011")) != attr.end())
234  {
235  i->second = cols;
236  }
237 
238  if ( (i = attr.find("D0028_0012")) != attr.end())
239  {
240  i->second = planes;
241  }
242  if ( (i = attr.find("FullFileDirectory")) != attr.end())
243  {
244  std::string::size_type last_pos = filename.find_last_of("//");
245  i->second = filename.substr(0, last_pos);
246  }
247 
248 
249  }
vtkImageData * creaImageIO::VtkImageReader::ReadImage ( const std::string &  filename)
virtual

return for a file a 2D VTkImage

Reimplemented from creaImageIO::AbstractImageReader.

Definition at line 96 of file creaImageIOVtkImageReader.cpp.

References creaImageIO::AbstractImageReader::GetName(), and mReader.

97  {
98  vtkImageData* im = 0;
99  try
100  {
101  printf("EED VtkImageReader::ReadImage Name:%s\n", GetName().c_str() );
102  mReader->SetFileName( filename.c_str() );
103  mReader->Update();
104  im = vtkImageData::New();
105 
106  im->ShallowCopy(mReader->GetOutput());
107 
108 
109 printf("EED ......\n");
110 printf("EED ......\n");
111 printf("EED VtkImageReader::ReadImage line 108 Missing FlipImage for JPEG, PNG, etc\n");
112 printf("EED ......\n");
113 printf("EED ......\n");
114 /*
115  im=FlipImageY(im);
116 
117  if ( (GetName()=="JPEG") || (GetName()=="PNG") )
118  {
119 
120  im->Update();
121  int inputdims[3];
122  im->GetDimensions (inputdims);
123 
124  int nbScalComp = im->GetNumberOfScalarComponents();
125  int scalarSize = im->GetScalarSize();
126  int lineSize = inputdims[0]*scalarSize*nbScalComp;
127  int planeSize = inputdims[1]*lineSize;
128  int volumeSize = inputdims[2]*planeSize;
129  char *pixelsIn = (char *)im->GetScalarPointer();
130  char *pixelsOut = (char *)mImageOut->GetScalarPointer();
131 
132  char *lineIn;
133  char *lineOut;
134  char *debPlanIn;
135  char *debPlanOut;
136  int i,j,k;
137 
138  for(k=0; k<inputdims[2]; k++) // iterate planes
139  {
140  debPlanIn = pixelsIn+k*planeSize;
141  debPlanOut = pixelsOut+k*planeSize;
142  for(j=0; j<inputdims[1]; j++) // iterates rows
143  {
144  lineIn = debPlanIn+j*lineSize;
145  lineOut = debPlanOut+(inputdims[1]-1-j)*lineSize;
146  memcpy(lineOut, lineIn, lineSize);
147  } // for j
148  } // for k
149  } // FLIP : JPEG PNG
150 */
151  }
152  catch (...)
153  {
154  if (im!=0) im->Delete();
155  im = 0;
156  }
157  return im;
158  }

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(), creaImageIO::UltrasonixImageReader::UltrasonixImageReader(), and VtkImageReader().

79 { mName = s; }

Here is the caller graph for this function:

Member Data Documentation

std::string creaImageIO::VtkImageReader::mExtensions
private

Definition at line 71 of file creaImageIOVtkImageReader.h.

Referenced by PushBackExtensions().

vtkImageReader2* creaImageIO::VtkImageReader::mReader
private

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