Reader to read files in DKFZ-pic-format. More...
#include <mitkPicFileReader.h>
Public Types | |
typedef PicFileReader | Self |
typedef FileReader | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual void | SetFileName (const char *_arg) |
Specify the file to load. | |
virtual const char * | GetFileName () const |
Get the specified the file to load. | |
virtual void | SetFilePrefix (const char *_arg) |
Specify file prefix for the file(s) to load. | |
virtual const char * | GetFilePrefix () const |
Get the specified file prefix for the file(s) to load. | |
virtual void | SetFilePattern (const char *_arg) |
Specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePrefix and number. | |
virtual const char * | GetFilePattern () const |
Get the specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePrefix and number. | |
virtual void | EnlargeOutputRequestedRegion (itk::DataObject *output) |
Static Public Member Functions | |
static Pointer | New () |
static void | ConvertHandedness (mitkIpPicDescriptor *pic) |
static bool | CanReadFile (const std::string filename, const std::string filePrefix, const std::string filePattern) |
Protected Member Functions | |
virtual void | GenerateData () |
A version of GenerateData() specific for image processing filters. | |
virtual void | GenerateOutputInformation () |
PicFileReader () | |
~PicFileReader () | |
Protected Attributes | |
itk::TimeStamp | m_ReadHeaderTime |
int | m_StartFileIndex |
std::string | m_FileName |
std::string | m_FilePrefix |
std::string | m_FilePattern |
Reader to read files in DKFZ-pic-format.
Definition at line 30 of file mitkPicFileReader.h.
typedef itk::SmartPointer<const Self> mitk::PicFileReader::ConstPointer |
Definition at line 33 of file mitkPicFileReader.h.
typedef itk::SmartPointer<Self> mitk::PicFileReader::Pointer |
Definition at line 33 of file mitkPicFileReader.h.
Definition at line 33 of file mitkPicFileReader.h.
Definition at line 33 of file mitkPicFileReader.h.
mitk::PicFileReader::PicFileReader | ( | ) | [protected] |
Definition at line 337 of file mitkPicFileReader.cpp.
: m_FileName(""), m_FilePrefix(""), m_FilePattern("") { }
mitk::PicFileReader::~PicFileReader | ( | ) | [protected] |
Definition at line 342 of file mitkPicFileReader.cpp.
{ }
bool mitk::PicFileReader::CanReadFile | ( | const std::string | filename, |
const std::string | filePrefix, | ||
const std::string | filePattern | ||
) | [static] |
Definition at line 286 of file mitkPicFileReader.cpp.
{ // First check the extension if( filename == "" ) { //MITK_INFO<<"No filename specified."<<std::endl; return false; } // check if image is serie if( filePattern != "" && filePrefix != "" ) return false; bool extensionFound = false; std::string::size_type PICPos = filename.rfind(".pic"); if ((PICPos != std::string::npos) && (PICPos == filename.length() - 4)) { extensionFound = true; } PICPos = filename.rfind(".PIC"); if ((PICPos != std::string::npos) && (PICPos == filename.length() - 4)) { extensionFound = true; } PICPos = filename.rfind(".pic.gz"); if ((PICPos != std::string::npos) && (PICPos == filename.length() - 7)) { extensionFound = true; } PICPos = filename.rfind(".seq"); if ((PICPos != std::string::npos) && (PICPos == filename.length() - 4)) { extensionFound = true; } if( !extensionFound ) { //MITK_INFO<<"The filename extension is not recognized."<<std::endl; return false; } return true; }
void mitk::PicFileReader::ConvertHandedness | ( | mitkIpPicDescriptor * | pic ) | [static] |
Definition at line 151 of file mitkPicFileReader.cpp.
References mitkIpPicDescriptor.
Referenced by mitk::PicVolumeTimeSeriesReader::GenerateData(), and mitk::PicFileWriter::GenerateData().
{ //left to right handed conversion if(pic->dim>=3) { mitkIpPicDescriptor* slice=mitkIpPicCopyHeader(pic, NULL); slice->dim=2; size_t size=_mitkIpPicSize(slice); slice->data=malloc(size); size_t v, volumes = (pic->dim>3? pic->n[3] : 1); size_t volume_size = size*pic->n[2]; for(v=0; v<volumes; ++v) { unsigned char *p_first=(unsigned char *)pic->data; unsigned char *p_last=(unsigned char *)pic->data; p_first+=v*volume_size; p_last+=size*(pic->n[2]-1)+v*volume_size; size_t i, smid=pic->n[2]/2; for(i=0; i<smid;++i,p_last-=size, p_first+=size) { memcpy(slice->data, p_last, size); memcpy(p_last, p_first, size); memcpy(p_first, slice->data, size); } } mitkIpPicFree(slice); } }
void mitk::PicFileReader::EnlargeOutputRequestedRegion | ( | itk::DataObject * | output ) | [virtual] |
Definition at line 281 of file mitkPicFileReader.cpp.
{ output->SetRequestedRegionToLargestPossibleRegion(); }
void mitk::PicFileReader::GenerateData | ( | ) | [protected, virtual] |
A version of GenerateData() specific for image processing filters.
This implementation will split the processing across multiple threads. The buffer is allocated by this method. Then the BeforeThreadedGenerateData() method is called (if provided). Then, a series of threads are spawned each calling ThreadedGenerateData(). After all the threads have completed processing, the AfterThreadedGenerateData() method is called (if provided). If an image processing filter cannot be threaded, the filter should provide an implementation of GenerateData(). That implementation is responsible for allocating the output buffer. If a filter an be threaded, it should NOT provide a GenerateData() method but should provide a ThreadedGenerateData() instead.
Reimplemented from mitk::ImageSource.
Definition at line 183 of file mitkPicFileReader.cpp.
References mitkIpPicDescriptor, and MITKipPicGet().
{ Image::Pointer output = this->GetOutput(); // Check to see if we can read the file given the name or prefix // if ( m_FileName == "" && m_FilePrefix == "" ) { throw itk::ImageFileReaderException(__FILE__, __LINE__, "One of FileName or FilePrefix must be non-empty"); } if( m_FileName != "") { mitkIpPicDescriptor* pic=MITKipPicGet(const_cast<char *>(m_FileName.c_str()), output->GetPic()); // comes upside-down (in MITK coordinates) from PIC file ConvertHandedness(pic); mitkIpPicTSV_t *tsv; if ( (tsv = mitkIpPicQueryTag( pic, "SOURCE HEADER" )) != NULL) { if(tsv->n[0]>1e+06) { mitkIpPicTSV_t *tsvSH; tsvSH = mitkIpPicDelTag( pic, "SOURCE HEADER" ); mitkIpPicFreeTag(tsvSH); } } if ( (tsv = mitkIpPicQueryTag( pic, "ICON80x80" )) != NULL) { mitkIpPicTSV_t *tsvSH; tsvSH = mitkIpPicDelTag( pic, "ICON80x80" ); mitkIpPicFreeTag(tsvSH); } if ( (tsv = mitkIpPicQueryTag( pic, "VELOCITY" )) != NULL) { mitkIpPicDescriptor* header = mitkIpPicCopyHeader(pic, NULL); header->data = tsv->value; ConvertHandedness(header); output->SetChannel(header->data, 1); header->data = NULL; mitkIpPicFree(header); mitkIpPicDelTag( pic, "VELOCITY" ); } //slice-wise reading //currently much too slow. //else //{ // int sstart, smax; // int tstart, tmax; // sstart=output->GetRequestedRegion().GetIndex(2); // smax=sstart+output->GetRequestedRegion().GetSize(2); // tstart=output->GetRequestedRegion().GetIndex(3); // tmax=tstart+output->GetRequestedRegion().GetSize(3); // int s,t; // for(s=sstart; s<smax; ++s) // { // for(t=tstart; t<tmax; ++t) // { // mitkIpPicDescriptor* pic=mitkIpPicGetSlice(const_cast<char *>(m_FileName.c_str()), NULL, t*smax+s+1); // output->SetPicSlice(pic,s,t); // } // } //} } else { int position; mitkIpPicDescriptor* pic=NULL; int zDim=(output->GetDimension()>2?output->GetDimensions()[2]:1); printf("\n zdim is %u \n",zDim); for (position = 0; position < zDim; ++position) { char fullName[1024]; sprintf(fullName, m_FilePattern.c_str(), m_FilePrefix.c_str(), m_StartFileIndex+position); pic=MITKipPicGet(fullName, pic); if(pic==NULL) { itkDebugMacro("Pic file '" << fullName << "' does not exist."); } else if(output->SetPicSlice(pic, position)==false) { itkDebugMacro("Image '" << fullName << "' could not be added to Image."); } } if(pic!=NULL) mitkIpPicFree(pic); } }
void mitk::PicFileReader::GenerateOutputInformation | ( | ) | [protected, virtual] |
Definition at line 28 of file mitkPicFileReader.cpp.
References mitk::ImageSource::GetOutput(), m_FileName, m_FilePattern, m_FilePrefix, m_ReadHeaderTime, m_StartFileIndex, mitkIpPicDescriptor, and MITKipPicGetTags().
{ Image::Pointer output = this->GetOutput(); if ((output->IsInitialized()) && (this->GetMTime() <= m_ReadHeaderTime.GetMTime())) return; itkDebugMacro(<<"Reading file for GenerateOutputInformation()" << m_FileName); // Check to see if we can read the file given the name or prefix // if ( m_FileName == "" && m_FilePrefix == "" ) { throw itk::ImageFileReaderException(__FILE__, __LINE__, "One of FileName or FilePrefix must be non-empty"); } if( m_FileName != "") { mitkIpPicDescriptor* header=mitkIpPicGetHeader(const_cast<char *>(m_FileName.c_str()), NULL); header=MITKipPicGetTags(const_cast<char *>(m_FileName.c_str()), header); int channels = 1; mitkIpPicTSV_t *tsv; if ( (tsv = mitkIpPicQueryTag( header, "SOURCE HEADER" )) != NULL) { if(tsv->n[0]>1e+06) { mitkIpPicTSV_t *tsvSH; tsvSH = mitkIpPicDelTag( header, "SOURCE HEADER" ); mitkIpPicFreeTag(tsvSH); } } if ( (tsv = mitkIpPicQueryTag( header, "ICON80x80" )) != NULL) { mitkIpPicTSV_t *tsvSH; tsvSH = mitkIpPicDelTag( header, "ICON80x80" ); mitkIpPicFreeTag(tsvSH); } if ( (tsv = mitkIpPicQueryTag( header, "VELOCITY" )) != NULL) { ++channels; mitkIpPicDelTag( header, "VELOCITY" ); } if( header == NULL) { itk::ImageFileReaderException e(__FILE__, __LINE__); itk::OStringStream msg; msg << " Could not read file " << m_FileName.c_str(); e.SetDescription(msg.str().c_str()); throw e; return; } output->Initialize(header, channels); mitkIpPicFree ( header ); } else { int numberOfImages=0; m_StartFileIndex=0; mitkIpPicDescriptor* header=NULL; char fullName[1024]; while(m_StartFileIndex<10) { sprintf(fullName, m_FilePattern.c_str(), m_FilePrefix.c_str(), m_StartFileIndex+numberOfImages); FILE * f=fopen(fullName,"r"); if(f==NULL) { //already found an image? if(numberOfImages>0) break; //no? let's increase start ++m_StartFileIndex; } else { fclose(f); //only open the header of the first file found, //@warning what to do when images do not have the same size?? if(header==NULL) { header=mitkIpPicGetHeader(fullName, NULL); header=MITKipPicGetTags(fullName, header); } ++numberOfImages; } } printf("\n numberofimages %d\n",numberOfImages); if(numberOfImages==0) { itk::ImageFileReaderException e(__FILE__, __LINE__); itk::OStringStream msg; msg << "no images found"; e.SetDescription(msg.str().c_str()); throw e; return; } //@FIXME: was ist, wenn die Bilder nicht alle gleich gross sind? if(numberOfImages>1) { printf("\n numberofimages %d > 1\n",numberOfImages); header->dim=3; header->n[2]=numberOfImages; } printf(" \ninitialisize output\n"); output->Initialize(header); mitkIpPicFree ( header ); } m_ReadHeaderTime.Modified(); }
virtual const char* mitk::PicFileReader::GetClassName | ( | ) | const [virtual] |
virtual const char* mitk::PicFileReader::GetFileName | ( | ) | const [virtual] |
Get the specified the file to load.
Either the FileName or FilePrefix plus FilePattern are used to read.
Implements mitk::FileReader.
virtual const char* mitk::PicFileReader::GetFilePattern | ( | ) | const [virtual] |
Get the specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePrefix and number.
You should specify either a FileName or FilePrefix. Use FilePrefix if the data is stored in multiple files.
Implements mitk::FileReader.
virtual const char* mitk::PicFileReader::GetFilePrefix | ( | ) | const [virtual] |
Get the specified file prefix for the file(s) to load.
You should specify either a FileName or FilePrefix. Use FilePrefix if the data is stored in multiple files.
Implements mitk::FileReader.
static Pointer mitk::PicFileReader::New | ( | ) | [static] |
Method for creation through the object factory.
Reimplemented from mitk::ImageSource.
Referenced by main(), mitkPicFileIOTest(), mitkPicFileReaderTest(), mitkVtkPropRendererTest(), and TestDataStorage().
virtual void mitk::PicFileReader::SetFileName | ( | const char * | aFileName ) | [virtual] |
Specify the file to load.
Either the FileName or FilePrefix plus FilePattern are used to read.
Implements mitk::FileReader.
virtual void mitk::PicFileReader::SetFilePattern | ( | const char * | aFilePattern ) | [virtual] |
Specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePrefix and number.
You should specify either a FileName or FilePrefix. Use FilePrefix if the data is stored in multiple files.
Implements mitk::FileReader.
virtual void mitk::PicFileReader::SetFilePrefix | ( | const char * | aFilePrefix ) | [virtual] |
Specify file prefix for the file(s) to load.
You should specify either a FileName or FilePrefix. Use FilePrefix if the data is stored in multiple files.
Implements mitk::FileReader.
std::string mitk::PicFileReader::m_FileName [protected] |
Definition at line 68 of file mitkPicFileReader.h.
Referenced by GenerateOutputInformation().
std::string mitk::PicFileReader::m_FilePattern [protected] |
Definition at line 72 of file mitkPicFileReader.h.
Referenced by GenerateOutputInformation().
std::string mitk::PicFileReader::m_FilePrefix [protected] |
Definition at line 70 of file mitkPicFileReader.h.
Referenced by GenerateOutputInformation().
itk::TimeStamp mitk::PicFileReader::m_ReadHeaderTime [protected] |
Definition at line 64 of file mitkPicFileReader.h.
Referenced by GenerateOutputInformation().
int mitk::PicFileReader::m_StartFileIndex [protected] |
Definition at line 66 of file mitkPicFileReader.h.
Referenced by GenerateOutputInformation().