#=========================================================
# CLITK = Command Line ITK
+PROJECT(clitk)
cmake_minimum_required(VERSION 2.8)
cmake_policy(VERSION 2.8)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
-PROJECT(clitk)
IF(NOT DEFINED CLITK_SOURCE_DIR)
SET(CLITK_SOURCE_DIR ${PROJECT_SOURCE_DIR})
ENDIF(NOT DEFINED CLITK_SOURCE_DIR)
clitkVoxImageIOFactory.cxx
clitkVfImageIO.cxx
clitkVfImageIOFactory.cxx
- clitkHisImageIO.cxx
- clitkHisImageIOFactory.cxx
clitkXdrImageIOReader.cxx
clitkXdrImageIOWriter.cxx
clitkXdrImageIOFactory.cxx
- clitkHndImageIO.cxx
- clitkHndImageIOFactory.cxx
+ rtkHisImageIO.cxx
+ rtkHisImageIOFactory.cxx
+ rtkHndImageIO.cxx
+ rtkHndImageIOFactory.cxx
+ rtkEdfImageIO.cxx
+ rtkEdfImageIOFactory.cxx
+ rtkImagXImageIO.cxx
+ rtkImagXImageIOFactory.cxx
+ rtkImagXXMLFileReader.cxx
+ clitkEsrfHstImageIO.cxx
+ clitkEsrfHstImageIOFactory.cxx
+ clitkEsrfHstXMLFileReader.cxx
clitkDicomRTDoseIO.cxx
clitkDicomRTDoseIOFactory.cxx
clitkOrientation.cxx
TARGET_LINK_LIBRARIES(clitkCommon statgrab)
ENDIF(NOT ${LIBSTATGRAB} MATCHES "LIBSTATGRAB-NOTFOUND")
-TARGET_LINK_LIBRARIES(clitkCommon vtkCommon vtkImaging ${ITK_LIBRARIES})
+### Check if ITK was compiled with SYSTEM_GDCM = ON and set the gdcm libraries accordingly
+SET(CLITK_USE_SYSTEM_GDCM FALSE)
+IF(ITK_VERSION_MAJOR LESS "4")
+ IF(ITK_USE_SYSTEM_GDCM)
+ SET(CLITK_USE_SYSTEM_GDCM TRUE)
+ ENDIF(ITK_USE_SYSTEM_GDCM)
+ELSE(ITK_VERSION_MAJOR LESS "4")
+ SET(GDCM_INCLUDE_INSTALL ".*include/gdcm-.*")
+ SET(GDCM_INCLUDE_BUILD ".*/Source/MediaStorageAndFileFormat")
+ IF(ITKGDCM_INCLUDE_DIRS MATCHES ${GDCM_INCLUDE_BUILD} OR ITKGDCM_INCLUDE_DIRS MATCHES ${GDCM_INCLUDE_INSTALL})
+ SET(CLITK_USE_SYSTEM_GDCM TRUE)
+ ENDIF(ITKGDCM_INCLUDE_DIRS MATCHES ${GDCM_INCLUDE_BUILD} OR ITKGDCM_INCLUDE_DIRS MATCHES ${GDCM_INCLUDE_INSTALL})
+ENDIF(ITK_VERSION_MAJOR LESS "4")
+
+IF(CLITK_USE_SYSTEM_GDCM)
+ SET(CLITK_GDCM_LIBRARIES gdcmDSED)
+ENDIF(CLITK_USE_SYSTEM_GDCM)
+
+TARGET_LINK_LIBRARIES(clitkCommon vtkCommon vtkImaging ${ITK_LIBRARIES} ${CLITK_GDCM_LIBRARIES})
ADD_LIBRARY(clitkDicomRTStruct STATIC
clitkDicomRT_Contour.cxx
clitkDicomRTStruct2ImageFilter.cxx
)
-TARGET_LINK_LIBRARIES(clitkDicomRTStruct vtkHybrid)
+TARGET_LINK_LIBRARIES(clitkDicomRTStruct vtkHybrid ${CLITK_GDCM_LIBRARIES})
#ADD_LIBRARY(clitkCommonShared SHARED ${clitkCommon_SRC})
#SET_TARGET_PROPERTIES(clitkCommonShared PROPERTIES COMPILE_FLAGS -fPIC)
//Verify if the file is a RT-Structure-Set dicom file
if (!gdcm::Util::DicomStringEqual(mFile->GetEntryValue(0x0008,0x0016),"1.2.840.10008.5.1.4.1.1.481.3"))
return false;
- if (!gdcm::Util::DicomStringEqual(mFile->GetEntryValue(0x0008,0x0060),"RTSTRUCT")) return false;
+ if (!gdcm::Util::DicomStringEqual(mFile->GetEntryValue(0x0008,0x0060),"RTSTRUCT"))
+ return false;
+
+ return true;
#endif
}
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+
+#include "clitkEsrfHstImageIO.h"
+#include "clitkEsrfHstXMLFileReader.h"
+#include "clitkDD.h"
+
+// itk include (for itkReadRawBytesAfterSwappingMacro)
+#include <itkRawImageIO.h>
+#include <itksys/SystemTools.hxx>
+#include <itkMetaDataObject.h>
+
+//--------------------------------------------------------------------
+// Read Image Information
+void clitk::EsrfHstImageIO::ReadImageInformation()
+{
+ clitk::EsrfHstXMLFileReader::Pointer hstXmlReader;
+ hstXmlReader = clitk::EsrfHstXMLFileReader::New();
+ hstXmlReader->SetFilename(m_XmlFileName);
+ hstXmlReader->GenerateOutputInformation();
+ itk::MetaDataDictionary &dic = *(hstXmlReader->GetOutputObject() );
+
+ typedef itk::MetaDataObject< double > MetaDataDoubleType;
+ typedef itk::MetaDataObject< std::string > MetaDataStringType;
+ typedef itk::MetaDataObject< int > MetaDataIntType;
+ SetComponentType(itk::ImageIOBase::FLOAT);
+ SetNumberOfDimensions(3);
+ SetDimensions(0, dynamic_cast<MetaDataIntType *>(dic["SIZEX"].GetPointer() )->GetMetaDataObjectValue());
+ SetDimensions(1, dynamic_cast<MetaDataIntType *>(dic["SIZEY"].GetPointer() )->GetMetaDataObjectValue());
+ SetDimensions(2, dynamic_cast<MetaDataIntType *>(dic["SIZEZ"].GetPointer() )->GetMetaDataObjectValue());
+ SetSpacing(0, dynamic_cast<MetaDataDoubleType *>(dic["voxelsize"].GetPointer() )->GetMetaDataObjectValue());
+ SetSpacing(1, GetSpacing(0));
+ SetSpacing(2, GetSpacing(0));
+ SetOrigin(0, GetSpacing(0)*(dynamic_cast<MetaDataIntType *>(dic["ORIGINX"].GetPointer() )->GetMetaDataObjectValue()-1));
+ SetOrigin(1, GetSpacing(0)*(dynamic_cast<MetaDataIntType *>(dic["ORIGINY"].GetPointer() )->GetMetaDataObjectValue()-1));
+ SetOrigin(2, GetSpacing(0)*(dynamic_cast<MetaDataIntType *>(dic["ORIGINZ"].GetPointer() )->GetMetaDataObjectValue()-1));
+ if(std::string("LOWBYTEFIRST") == dynamic_cast<MetaDataStringType*>(dic["SUBVOLUME_NAME"].GetPointer() )->GetMetaDataObjectValue())
+ this->SetByteOrder(BigEndian);
+ else
+ this->SetByteOrder(LittleEndian);
+
+ // Prepare raw file name
+ m_RawFileName = itksys::SystemTools::GetFilenamePath(m_XmlFileName);
+ if(m_RawFileName != "")
+ m_RawFileName += std::string("/");
+ m_RawFileName += dynamic_cast<MetaDataStringType*>(dic["SUBVOLUME_NAME"].GetPointer() )->GetMetaDataObjectValue();
+} ////
+
+//--------------------------------------------------------------------
+// Read Image Information
+bool clitk::EsrfHstImageIO::CanReadFile(const char* FileNameToRead)
+{
+ std::string ext = itksys::SystemTools::GetFilenameLastExtension(FileNameToRead);
+ if( ext!=std::string(".xml") && ext!=std::string(".vol") )
+ return false;
+
+ m_XmlFileName = std::string(FileNameToRead);
+ if( ext==std::string(".vol") )
+ m_XmlFileName += std::string(".xml");
+
+ std::ifstream is(m_XmlFileName.c_str());
+ if(! is.is_open() )
+ return false;
+
+ std::string firstLine;
+ std::getline(is, firstLine);
+ if(firstLine != std::string("<!-- PyHST VOLUME XML FILE -->") )
+ return false;
+
+ return true;
+} ////
+
+//--------------------------------------------------------------------
+// Read Image Content
+void clitk::EsrfHstImageIO::Read(void * buffer)
+{
+ // Adapted from itkRawImageIO
+ std::ifstream is(m_RawFileName.c_str(), std::ios::binary);
+ if(! is.is_open() )
+ itkExceptionMacro(<<"Could not open file " << m_RawFileName);
+
+ unsigned long numberOfBytesToBeRead = GetComponentSize();
+ for(unsigned int i=0; i<GetNumberOfDimensions(); i++) numberOfBytesToBeRead *= GetDimensions(i);
+
+ if(!this->ReadBufferAsBinary(is, buffer, numberOfBytesToBeRead)) {
+ itkExceptionMacro(<<"Read failed: Wanted "
+ << numberOfBytesToBeRead
+ << " bytes, but read "
+ << is.gcount() << " bytes.");
+ }
+ itkDebugMacro(<< "Reading Done");
+
+ // Adapted from itkRawImageIO
+ {
+ using namespace itk;
+ // Swap bytes if necessary
+ if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
+ else if itkReadRawBytesAfterSwappingMacro( short, SHORT )
+ else if itkReadRawBytesAfterSwappingMacro( char, CHAR )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
+ else if itkReadRawBytesAfterSwappingMacro( int, INT )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned int, ULONG )
+ else if itkReadRawBytesAfterSwappingMacro( int, LONG )
+ else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+ else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+ }
+}
+
+//--------------------------------------------------------------------
+// Write Image Information
+void clitk::EsrfHstImageIO::WriteImageInformation(bool keepOfStream)
+{
+}
+
+//--------------------------------------------------------------------
+// Write Image Information
+bool clitk::EsrfHstImageIO::CanWriteFile(const char* FileNameToWrite)
+{
+ return false;
+}
+
+//--------------------------------------------------------------------
+// Write Image
+void clitk::EsrfHstImageIO::Write(const void * buffer)
+{
+} ////
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+
+#ifndef __clitkEsrfHstImageIO_h
+#define __clitkEsrfHstImageIO_h
+
+#include <itkImageIOBase.h>
+#include <fstream>
+#include <string.h>
+
+namespace clitk
+{
+
+//====================================================================
+// Class for reading Esrf Hst Image file format
+class EsrfHstImageIO: public itk::ImageIOBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef EsrfHstImageIO Self;
+ typedef itk::ImageIOBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+
+ EsrfHstImageIO():Superclass() { }
+
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(EsrfHstImageIO, ImageIOBase);
+
+ /*-------- This part of the interface deals with reading data. ------ */
+ virtual void ReadImageInformation();
+ virtual bool CanReadFile( const char* FileNameToRead );
+ virtual void Read(void * buffer);
+
+ /*-------- This part of the interfaces deals with writing data. ----- */
+ virtual void WriteImageInformation(bool keepOfStream);
+ virtual void WriteImageInformation() { WriteImageInformation(false); }
+ virtual bool CanWriteFile(const char* filename);
+ virtual void Write(const void* buffer);
+
+protected:
+ std::string m_XmlFileName;
+ std::string m_RawFileName;
+};
+
+} // end namespace
+
+#endif
+
Authors belong to:
- University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://www.centreleonberard.fr
+ - Léon Bérard cancer center http://www.centreleonberard.fr
- CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
This software is distributed WITHOUT ANY WARRANTY; without even
- CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
===========================================================================**/
-#include "clitkHndImageIOFactory.h"
+#include "clitkEsrfHstImageIOFactory.h"
//====================================================================
-clitk::HndImageIOFactory::HndImageIOFactory()
+clitk::EsrfHstImageIOFactory::EsrfHstImageIOFactory()
{
this->RegisterOverride("itkImageIOBase",
- "HndImageIO",
- "Hnd Image IO",
+ "EsrfHstImageIO",
+ "Esrf Hst Image IO",
1,
- itk::CreateObjectFunction<HndImageIO>::New());
+ itk::CreateObjectFunction<EsrfHstImageIO>::New());
}
+
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+
+#ifndef __clitkEsrfHstImageIOFactory_h
+#define __clitkEsrfHstImageIOFactory_h
+
+#include "clitkEsrfHstImageIO.h"
+#include <itkImageIOBase.h>
+#include <itkObjectFactoryBase.h>
+#include <itkVersion.h>
+
+namespace clitk
+{
+
+//====================================================================
+// Factory for reading Esrf Hst Image file format
+class EsrfHstImageIOFactory: public itk::ObjectFactoryBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef EsrfHstImageIOFactory Self;
+ typedef itk::ObjectFactoryBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef itk::SmartPointer<const Self> ConstPointer;
+
+ /** Class methods used to interface with the registered factories. */
+ const char* GetITKSourceVersion(void) const {
+ return ITK_SOURCE_VERSION;
+ }
+
+ const char* GetDescription(void) const {
+ return "Esrf Hst ImageIO Factory, allows the loading of Esrf Hst images into insight";
+ }
+
+ /** Method for class instantiation. */
+ itkFactorylessNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(EsrfHstImageIOFactory, ObjectFactoryBase);
+
+ /** Register one factory of this type */
+ static void RegisterOneFactory(void) {
+ ObjectFactoryBase::RegisterFactory( Self::New() );
+ }
+
+protected:
+ EsrfHstImageIOFactory();
+ ~EsrfHstImageIOFactory() {};
+ typedef EsrfHstImageIOFactory myProductType;
+ const myProductType* m_MyProduct;
+
+private:
+ EsrfHstImageIOFactory(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+};
+
+} // end namespace
+
+#endif
+
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+
+#include "clitkEsrfHstXMLFileReader.h"
+#include "itkMacro.h"
+
+#include <itksys/SystemTools.hxx>
+#include <itkMetaDataObject.h>
+
+namespace clitk
+{
+
+int
+EsrfHstXMLFileReader::
+CanReadFile(const char *name)
+{
+ if(!itksys::SystemTools::FileExists(name) ||
+ itksys::SystemTools::FileIsDirectory(name) ||
+ itksys::SystemTools::FileLength(name) == 0)
+ return 0;
+ return 1;
+}
+
+void
+EsrfHstXMLFileReader::
+StartElement(const char * itkNotUsed(name),const char ** itkNotUsed(atts))
+{
+ m_CurCharacterData = "";
+}
+
+void
+EsrfHstXMLFileReader::
+EndElement(const char *name)
+{
+#define ENCAPLULATE_META_DATA_DOUBLE(metaName) \
+ if(itksys::SystemTools::Strucmp(name, metaName) == 0) { \
+ double d = atof(m_CurCharacterData.c_str() ); \
+ itk::EncapsulateMetaData<double>(m_Dictionary, metaName, d); \
+ }
+
+#define ENCAPLULATE_META_DATA_INT(metaName) \
+ if(itksys::SystemTools::Strucmp(name, metaName) == 0) { \
+ double d = atof(m_CurCharacterData.c_str() ); \
+ itk::EncapsulateMetaData<int>(m_Dictionary, metaName, d); \
+ }
+
+#define ENCAPLULATE_META_DATA_STRING(metaName) \
+ if(itksys::SystemTools::Strucmp(name, metaName) == 0) { \
+ itk::EncapsulateMetaData<std::string>(m_Dictionary, metaName, m_CurCharacterData); \
+ }
+
+ ENCAPLULATE_META_DATA_INT("idAc");
+ ENCAPLULATE_META_DATA_STRING("SUBVOLUME_NAME");
+ ENCAPLULATE_META_DATA_INT("SIZEX");
+ ENCAPLULATE_META_DATA_INT("SIZEY");
+ ENCAPLULATE_META_DATA_INT("SIZEZ");
+ ENCAPLULATE_META_DATA_INT("ORIGINX");
+ ENCAPLULATE_META_DATA_INT("ORIGINY");
+ ENCAPLULATE_META_DATA_INT("ORIGINZ");
+ ENCAPLULATE_META_DATA_INT("DIM_REC");
+ ENCAPLULATE_META_DATA_DOUBLE("voxelsize");
+ ENCAPLULATE_META_DATA_STRING("BYTE_ORDER");
+}
+
+void
+EsrfHstXMLFileReader::
+CharacterDataHandler(const char *inData, int inLength)
+{
+ for(int i = 0; i < inLength; i++)
+ m_CurCharacterData = m_CurCharacterData + inData[i];
+}
+
+}
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+
+#ifndef __clitkEsrfHstXMLFileReader_h
+#define __clitkEsrfHstXMLFileReader_h
+
+#ifdef _MSC_VER
+#pragma warning ( disable : 4786 )
+#endif
+
+#include <itkXMLFile.h>
+#include <itkMetaDataDictionary.h>
+
+#include <map>
+
+namespace clitk
+{
+
+/** \class EsrfHstXMLFileReader
+ *
+ * Reads the XML-format file written by the software High Speed Tomography
+ * at the European Synchrotron Radiation Facility
+ */
+class EsrfHstXMLFileReader : public itk::XMLReader<itk::MetaDataDictionary>
+{
+public:
+ /** Standard typedefs */
+ typedef EsrfHstXMLFileReader Self;
+ typedef itk::XMLReader<itk::MetaDataDictionary> Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(EsrfHstXMLFileReader, itk::XMLReader);
+
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
+
+ /** Determine if a file can be read */
+ int CanReadFile(const char* name);
+
+protected:
+ EsrfHstXMLFileReader() {m_OutputObject = &m_Dictionary;};
+ virtual ~EsrfHstXMLFileReader() {};
+
+ virtual void StartElement(const char * name,const char **atts);
+
+ virtual void EndElement(const char *name);
+
+ void CharacterDataHandler(const char *inData, int inLength);
+
+private:
+ EsrfHstXMLFileReader(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+
+ itk::MetaDataDictionary m_Dictionary;
+ std::string m_CurCharacterData;
+};
+
+}
+#endif
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://www.centreleonberard.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHISIMAGEIO_H
-#define CLITKHISIMAGEIO_H
-/**
- ===================================================================
- * @file clitkHisImageIO.h
- * @author Simon Rit <simon.rit@gmail.com>
- * @date 16 Feb 2010
-
- * @brief
-
- ===================================================================*/
-
-// itk include
-#include "itkImageIOBase.h"
-
-namespace clitk {
-
- //====================================================================
- // Class for reading His Image file format
- class HisImageIO: public itk::ImageIOBase
- {
- public:
- /** Standard class typedefs. */
- typedef HisImageIO Self;
- typedef itk::ImageIOBase Superclass;
- typedef itk::SmartPointer<Self> Pointer;
- typedef signed short int PixelType;
-
- HisImageIO():Superclass() {;}
-
- /** Method for creation through the object factory. */
- itkNewMacro(Self);
-
- /** Run-time type information (and related methods). */
- itkTypeMacro(HisImageIO, ImageIOBase);
-
- /*-------- This part of the interface deals with reading data. ------ */
- virtual void ReadImageInformation();
- virtual bool CanReadFile( const char* FileNameToRead );
- virtual void Read(void * buffer);
-
- /*-------- This part of the interfaces deals with writing data. ----- */
- virtual void WriteImageInformation(bool keepOfStream) { ; }
- virtual void WriteImageInformation() { WriteImageInformation(false); }
- virtual bool CanWriteFile(const char* filename);
- virtual void Write(const void* buffer);
-
- protected:
- int m_HeaderSize;
-
- }; // end class HisImageIO
-} // end namespace
-
- // explicit template instantiation
-//template class itk::CreateObjectFunction<clitk::HisImageIO>;
-
-#endif /* end #define CLITKHISIMAGEIO_H */
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://www.centreleonberard.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHISIMAGEIOFACTORY_CXX
-#define CLITKHISIMAGEIOFACTORY_CXX
-/**
- =================================================
- * @file clitkHisImageIOFactory.cxx
- * @author Simon Rit <simon.rit@gmail.com>
- * @date 16 Feb 2010
- *
- * @brief
- *
- *
- =================================================*/
-
-#include "clitkHisImageIOFactory.h"
-
-#include <fstream>
-
-//====================================================================
-clitk::HisImageIOFactory::HisImageIOFactory()
-{
- this->RegisterOverride("itkImageIOBase",
- "HisImageIO",
- "His Image IO",
- 1,
- itk::CreateObjectFunction<HisImageIO>::New());
-}
-
-
-#endif /* end #define CLITKHISIMAGEIOFACTORY_CXX */
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://www.centreleonberard.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHISIMAGEIOFACTORY_H
-#define CLITKHISIMAGEIOFACTORY_H
-/**
- ===================================================================
- * @file clitkHisImageIOFactory.h
- * @author Simon Rit <simon.rit@gmail.com>
- * @date 16 Feb 2010
-
- * @brief
-
- ===================================================================*/
-
-// clitk include
-#include "clitkHisImageIO.h"
-
-// itk include
-#include "itkImageIOBase.h"
-#include "itkObjectFactoryBase.h"
-#include "itkVersion.h"
-
-namespace clitk {
-
- //====================================================================
- // Factory for reading His Image file format
- class HisImageIOFactory: public itk::ObjectFactoryBase
- {
- public:
- /** Standard class typedefs. */
- typedef HisImageIOFactory Self;
- typedef itk::ObjectFactoryBase Superclass;
- typedef itk::SmartPointer<Self> Pointer;
- typedef itk::SmartPointer<const Self> ConstPointer;
-
- /** Class methods used to interface with the registered factories. */
- const char* GetITKSourceVersion(void) const {
- return ITK_SOURCE_VERSION;
- }
-
- const char* GetDescription(void) const {
- return "His ImageIO Factory, allows the loading of His images into insight";
- }
-
- /** Method for class instantiation. */
- itkFactorylessNewMacro(Self);
-
- /** Run-time type information (and related methods). */
- itkTypeMacro(HisImageIOFactory, ObjectFactoryBase);
-
- /** Register one factory of this type */
- static void RegisterOneFactory(void) {
- ObjectFactoryBase::RegisterFactory( Self::New() );
- }
-
- protected:
- HisImageIOFactory();
- ~HisImageIOFactory() {};
- typedef HisImageIOFactory myProductType;
- const myProductType* m_MyProduct;
-
- private:
- HisImageIOFactory(const Self&); //purposely not implemented
- void operator=(const Self&); //purposely not implemented
- };
-
-} // end namespace
-
-#endif /* end #define CLITKHISIMAGEIOFACTORY_H */
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://www.centreleonberard.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-
-// std include
-#include <stdio.h>
-
-// clitk include
-#include "clitkHndImageIO.h"
-#include "clitkCommon.h"
-
-// itk include
-#include <itkMetaDataObject.h>
-
-//--------------------------------------------------------------------
-// Read Image Information
-void clitk::HndImageIO::ReadImageInformation()
-{
- Hnd_header hnd;
- FILE *fp;
-
- fp = fopen (m_FileName.c_str(), "rb");
- if (fp == NULL)
- itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
-
- fread ((void *) hnd.sFileType, sizeof(char), 32, fp);
- fread ((void *) &hnd.FileLength, sizeof(uint32_t), 1, fp);
- fread ((void *) hnd.sChecksumSpec, sizeof(char), 4, fp);
- fread ((void *) &hnd.nCheckSum, sizeof(uint32_t), 1, fp);
- fread ((void *) hnd.sCreationDate, sizeof(char), 8, fp);
- fread ((void *) hnd.sCreationTime, sizeof(char), 8, fp);
- fread ((void *) hnd.sPatientID, sizeof(char), 16, fp);
- fread ((void *) &hnd.nPatientSer, sizeof(uint32_t), 1, fp);
- fread ((void *) hnd.sSeriesID, sizeof(char), 16, fp);
- fread ((void *) &hnd.nSeriesSer, sizeof(uint32_t), 1, fp);
- fread ((void *) hnd.sSliceID, sizeof(char), 16, fp);
- fread ((void *) &hnd.nSliceSer, sizeof(uint32_t), 1, fp);
- fread ((void *) &hnd.SizeX, sizeof(uint32_t), 1, fp);
- fread ((void *) &hnd.SizeY, sizeof(uint32_t), 1, fp);
- fread ((void *) &hnd.dSliceZPos, sizeof(double), 1, fp);
- fread ((void *) hnd.sModality, sizeof(char), 16, fp);
- fread ((void *) &hnd.nWindow, sizeof(uint32_t), 1, fp);
- fread ((void *) &hnd.nLevel, sizeof(uint32_t), 1, fp);
- fread ((void *) &hnd.nPixelOffset, sizeof(uint32_t), 1, fp);
- fread ((void *) hnd.sImageType, sizeof(char), 4, fp);
- fread ((void *) &hnd.dGantryRtn, sizeof(double), 1, fp);
- fread ((void *) &hnd.dSAD, sizeof(double), 1, fp);
- fread ((void *) &hnd.dSFD, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCollX1, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCollX2, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCollY1, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCollY2, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCollRtn, sizeof(double), 1, fp);
- fread ((void *) &hnd.dFieldX, sizeof(double), 1, fp);
- fread ((void *) &hnd.dFieldY, sizeof(double), 1, fp);
- fread ((void *) &hnd.dBladeX1, sizeof(double), 1, fp);
- fread ((void *) &hnd.dBladeX2, sizeof(double), 1, fp);
- fread ((void *) &hnd.dBladeY1, sizeof(double), 1, fp);
- fread ((void *) &hnd.dBladeY2, sizeof(double), 1, fp);
- fread ((void *) &hnd.dIDUPosLng, sizeof(double), 1, fp);
- fread ((void *) &hnd.dIDUPosLat, sizeof(double), 1, fp);
- fread ((void *) &hnd.dIDUPosVrt, sizeof(double), 1, fp);
- fread ((void *) &hnd.dIDUPosRtn, sizeof(double), 1, fp);
- fread ((void *) &hnd.dPatientSupportAngle, sizeof(double), 1, fp);
- fread ((void *) &hnd.dTableTopEccentricAngle, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCouchVrt, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCouchLng, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCouchLat, sizeof(double), 1, fp);
- fread ((void *) &hnd.dIDUResolutionX, sizeof(double), 1, fp);
- fread ((void *) &hnd.dIDUResolutionY, sizeof(double), 1, fp);
- fread ((void *) &hnd.dImageResolutionX, sizeof(double), 1, fp);
- fread ((void *) &hnd.dImageResolutionY, sizeof(double), 1, fp);
- fread ((void *) &hnd.dEnergy, sizeof(double), 1, fp);
- fread ((void *) &hnd.dDoseRate, sizeof(double), 1, fp);
- fread ((void *) &hnd.dXRayKV, sizeof(double), 1, fp);
- fread ((void *) &hnd.dXRayMA, sizeof(double), 1, fp);
- fread ((void *) &hnd.dMetersetExposure, sizeof(double), 1, fp);
- fread ((void *) &hnd.dAcqAdjustment, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCTProjectionAngle, sizeof(double), 1, fp);
- fread ((void *) &hnd.dCTNormChamber, sizeof(double), 1, fp);
- fread ((void *) &hnd.dGatingTimeTag, sizeof(double), 1, fp);
- fread ((void *) &hnd.dGating4DInfoX, sizeof(double), 1, fp);
- fread ((void *) &hnd.dGating4DInfoY, sizeof(double), 1, fp);
- fread ((void *) &hnd.dGating4DInfoZ, sizeof(double), 1, fp);
- fread ((void *) &hnd.dGating4DInfoTime, sizeof(double), 1, fp);
- fclose (fp);
-
- /* Convert hnd to ITK image information */
- SetNumberOfDimensions(2);
- SetDimensions(0, hnd.SizeX);
- SetDimensions(1, hnd.SizeY);
- SetSpacing(0, hnd.dIDUResolutionX);
- SetSpacing(1, hnd.dIDUResolutionY);
- SetOrigin(0, -0.5*(hnd.SizeX-1)*hnd.dIDUResolutionX); //SR: assumed centered
- SetOrigin(1, -0.5*(hnd.SizeY-1)*hnd.dIDUResolutionY); //SR: assumed centered
- SetComponentType(itk::ImageIOBase::UINT);
-
- /* Store important meta information in the meta data dictionary */
- itk::EncapsulateMetaData<double>(this->GetMetaDataDictionary(), "dCTProjectionAngle", hnd.dCTProjectionAngle);
- //itk::ExposeMetaData<double>( this->GetMetaDataDictionary(), &(hnd.dCTProjectionAngle), "dCTProjectionAngle");
-}
-
-//--------------------------------------------------------------------
-bool clitk::HndImageIO::CanReadFile(const char* FileNameToRead)
-{
- std::string filename(FileNameToRead);
- std::string filenameext = GetExtension(filename);
- if (filenameext != std::string("hnd")) return false;
- return true;
-}
-
-//--------------------------------------------------------------------
-// Read Image Content
-void clitk::HndImageIO::Read(void * buffer)
-{
- FILE *fp;
-
- uint32_t* buf = (uint32_t*)buffer;
- unsigned char *pt_lut;
- uint32_t a;
- unsigned char v;
- int lut_idx, lut_off;
- size_t num_read;
- char dc;
- short ds;
- long dl, diff=0;
- uint32_t i;
-
- fp = fopen (m_FileName.c_str(), "rb");
- if (fp == NULL)
- itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
-
- pt_lut = (unsigned char*) malloc (sizeof (unsigned char) * GetDimensions(0) * GetDimensions(1));
-
- /* Read LUT */
- fseek (fp, 1024, SEEK_SET);
- fread (pt_lut, sizeof(unsigned char), (GetDimensions(1)-1)*GetDimensions(0) / 4, fp);
-
- /* Read first row */
- for (i = 0; i < GetDimensions(0); i++) {
- fread (&a, sizeof(uint32_t), 1, fp);
- buf[i] = a;
- }
-
- /* Read first pixel of second row */
- fread (&a, sizeof(uint32_t), 1, fp);
- buf[i++] = a;
-
- /* Decompress the rest */
- lut_idx = 0;
- lut_off = 0;
- while (i < GetDimensions(0) * GetDimensions(1)) {
- uint32_t r11, r12, r21;
-
- r11 = buf[i-GetDimensions(0)-1];
- r12 = buf[i-GetDimensions(0)];
- r21 = buf[i-1];
- v = pt_lut[lut_idx];
- switch (lut_off) {
- case 0:
- v = v & 0x03;
- lut_off ++;
- break;
- case 1:
- v = (v & 0x0C) >> 2;
- lut_off ++;
- break;
- case 2:
- v = (v & 0x30) >> 4;
- lut_off ++;
- break;
- case 3:
- v = (v & 0xC0) >> 6;
- lut_off = 0;
- lut_idx ++;
- break;
- }
- switch (v) {
- case 0:
- num_read = fread (&dc, sizeof(unsigned char), 1, fp);
- if (num_read != 1) goto read_error;
- diff = dc;
- break;
- case 1:
- num_read = fread (&ds, sizeof(unsigned short), 1, fp);
- if (num_read != 1) goto read_error;
- diff = ds;
- break;
- case 2:
- num_read = fread (&dl, sizeof(uint32_t), 1, fp);
- if (num_read != 1) goto read_error;
- diff = dl;
- break;
- }
-
- buf[i] = r21 + r12 + diff - r11;
- i++;
- }
-
- /* Clean up */
- free (pt_lut);
- fclose (fp);
- return;
-
-read_error:
-
- itkGenericExceptionMacro(<< "Error reading hnd file");
- free (pt_lut);
- fclose (fp);
- return;
-}
-
-//--------------------------------------------------------------------
-bool clitk::HndImageIO::CanWriteFile(const char* FileNameToWrite)
-{
- return false;
-}
-
-//--------------------------------------------------------------------
-// Write Image
-void clitk::HndImageIO::Write(const void* buffer)
-{
-}
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://www.centreleonberard.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHNDIMAGEIO_H
-#define CLITKHNDIMAGEIO_H
-
-// itk include
-#include "itkImageIOBase.h"
-
-#if defined (_MSC_VER) && (_MSC_VER < 1600)
-//SR: taken from
-//#include "msinttypes/stdint.h"
-typedef unsigned int uint32_t;
-#else
-#include <stdint.h>
-#endif
-
-namespace clitk {
-
- //====================================================================
- // Class for reading Hnd Image file format
- class HndImageIO: public itk::ImageIOBase
- {
- public:
- /** Standard class typedefs. */
- typedef HndImageIO Self;
- typedef itk::ImageIOBase Superclass;
- typedef itk::SmartPointer<Self> Pointer;
- typedef signed short int PixelType;
-
- typedef struct hnd_header {
- char sFileType[32];
- uint32_t FileLength;
- char sChecksumSpec[4];
- uint32_t nCheckSum;
- char sCreationDate[8];
- char sCreationTime[8];
- char sPatientID[16];
- uint32_t nPatientSer;
- char sSeriesID[16];
- uint32_t nSeriesSer;
- char sSliceID[16];
- uint32_t nSliceSer;
- uint32_t SizeX;
- uint32_t SizeY;
- double dSliceZPos;
- char sModality[16];
- uint32_t nWindow;
- uint32_t nLevel;
- uint32_t nPixelOffset;
- char sImageType[4];
- double dGantryRtn;
- double dSAD;
- double dSFD;
- double dCollX1;
- double dCollX2;
- double dCollY1;
- double dCollY2;
- double dCollRtn;
- double dFieldX;
- double dFieldY;
- double dBladeX1;
- double dBladeX2;
- double dBladeY1;
- double dBladeY2;
- double dIDUPosLng;
- double dIDUPosLat;
- double dIDUPosVrt;
- double dIDUPosRtn;
- double dPatientSupportAngle;
- double dTableTopEccentricAngle;
- double dCouchVrt;
- double dCouchLng;
- double dCouchLat;
- double dIDUResolutionX;
- double dIDUResolutionY;
- double dImageResolutionX;
- double dImageResolutionY;
- double dEnergy;
- double dDoseRate;
- double dXRayKV;
- double dXRayMA;
- double dMetersetExposure;
- double dAcqAdjustment;
- double dCTProjectionAngle;
- double dCTNormChamber;
- double dGatingTimeTag;
- double dGating4DInfoX;
- double dGating4DInfoY;
- double dGating4DInfoZ;
- double dGating4DInfoTime;
- } Hnd_header;
-
- HndImageIO():Superclass() {;}
-
- /** Method for creation through the object factory. */
- itkNewMacro(Self);
-
- /** Run-time type information (and related methods). */
- itkTypeMacro(HndImageIO, ImageIOBase);
-
- /*-------- This part of the interface deals with reading data. ------ */
- virtual void ReadImageInformation();
- virtual bool CanReadFile( const char* FileNameToRead );
- virtual void Read(void * buffer);
-
- /*-------- This part of the interfaces deals with writing data. ----- */
- virtual void WriteImageInformation(bool keepOfStream) { ; }
- virtual void WriteImageInformation() { WriteImageInformation(false); }
- virtual bool CanWriteFile(const char* filename);
- virtual void Write(const void* buffer);
-
- protected:
- int m_HeaderSize;
-
- }; // end class HndImageIO
-} // end namespace
-
-// explicit template instantiation
-//template class itk::CreateObjectFunction<clitk::HndImageIO>;
-
-#endif /* end #define CLITKHNDIMAGEIO_H */
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://www.centreleonberard.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHNDIMAGEIOFACTORY_H
-#define CLITKHNDIMAGEIOFACTORY_H
-
-// clitk include
-#include "clitkHndImageIO.h"
-
-// itk include
-#include "itkImageIOBase.h"
-#include "itkObjectFactoryBase.h"
-#include "itkVersion.h"
-
-namespace clitk {
-
- //====================================================================
- // Factory for reading Hnd Image file format
- class HndImageIOFactory: public itk::ObjectFactoryBase
- {
- public:
- /** Standard class typedefs. */
- typedef HndImageIOFactory Self;
- typedef itk::ObjectFactoryBase Superclass;
- typedef itk::SmartPointer<Self> Pointer;
- typedef itk::SmartPointer<const Self> ConstPointer;
-
- /** Class methods used to interface with the registered factories. */
- const char* GetITKSourceVersion(void) const {
- return ITK_SOURCE_VERSION;
- }
-
- const char* GetDescription(void) const {
- return "Hnd ImageIO Factory, allows the loading of Hnd images into insight";
- }
-
- /** Method for class instantiation. */
- itkFactorylessNewMacro(Self);
-
- /** Run-time type information (and related methods). */
- itkTypeMacro(HndImageIOFactory, ObjectFactoryBase);
-
- /** Register one factory of this type */
- static void RegisterOneFactory(void) {
- ObjectFactoryBase::RegisterFactory( Self::New() );
- }
-
- protected:
- HndImageIOFactory();
- ~HndImageIOFactory() {};
- typedef HndImageIOFactory myProductType;
- const myProductType* m_MyProduct;
-
- private:
- HndImageIOFactory(const Self&); //purposely not implemented
- void operator=(const Self&); //purposely not implemented
- };
-
-} // end namespace
-
-#endif /* end #define CLITKHNDIMAGEIOFACTORY_H */
-
#include "clitkImageCommon.h"
#include "clitkDicomRTDoseIOFactory.h"
#include "clitkVoxImageIOFactory.h"
-#include "clitkHisImageIOFactory.h"
#include "clitkVfImageIOFactory.h"
#include "clitkXdrImageIOFactory.h"
-#include "clitkHndImageIOFactory.h"
+#include "rtkHisImageIOFactory.h"
+#include "rtkHndImageIOFactory.h"
+#include "rtkEdfImageIOFactory.h"
+#include "rtkImagXImageIOFactory.h"
+#include "clitkEsrfHstImageIOFactory.h"
#include "clitkGateAsciiImageIOFactory.h"
#include "clitkConfiguration.h"
#if CLITK_PRIVATE_FEATURES
#endif
clitk::VoxImageIOFactory::RegisterOneFactory();
clitk::VfImageIOFactory::RegisterOneFactory();
- clitk::HisImageIOFactory::RegisterOneFactory();
clitk::XdrImageIOFactory::RegisterOneFactory();
- clitk::HndImageIOFactory::RegisterOneFactory();
+ rtk::HisImageIOFactory::RegisterOneFactory();
+ rtk::HndImageIOFactory::RegisterOneFactory();
+ rtk::EdfImageIOFactory::RegisterOneFactory();
+ rtk::ImagXImageIOFactory::RegisterOneFactory();
+ clitk::EsrfHstImageIOFactory::RegisterOneFactory();
} ////
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#include "rtkEdfImageIO.h"
+
+// itk include (for itkReadRawBytesAfterSwappingMacro)
+#include <itkRawImageIO.h>
+#include <itk_zlib.h>
+
+//--------------------------------------------------------------------
+/* Find value_ptr as pointer to the parameter of the given key in the header.
+ * Returns NULL on success.
+ */
+char*
+rtk::EdfImageIO::edf_findInHeader( char* header, const char* key )
+{
+ char *value_ptr = strstr( header, key );
+
+ if (!value_ptr) return NULL;
+ /* an edf line is "key = value ;" */
+ value_ptr = 1 + strchr( value_ptr + strlen(key), '=' );
+ while (isspace(*value_ptr) ) value_ptr++;
+ return value_ptr;
+}
+
+//--------------------------------------------------------------------
+// Read Image Information
+void rtk::EdfImageIO::ReadImageInformation()
+{
+ int k;
+ char * header = NULL;
+ int header_size = 0;
+ char * p;
+ gzFile inp;
+
+ inp = gzopen(m_FileName.c_str(), "rb");
+ if (!inp)
+ itkGenericExceptionMacro(<< "Cannot open input file " << m_FileName);
+
+ // read header: it is a multiple of 512 B ending by "}\n"
+ while (header_size == 0 || strncmp(&header[header_size-2],"}\n",2) ) {
+ int header_size_prev = header_size;
+ header_size += 512;
+ if (!header)
+ header = (char*)malloc(header_size+1);
+ else
+ header = (char*)realloc(header, header_size+1);
+ header[header_size_prev] = 0; /* protection against empty file */
+ // fread(header+header_size_prev, 512, 1, fp);
+ k = gzread(inp, header+header_size_prev, 512);
+ if (k < 512) { /* protection against infinite loop */
+ gzclose(inp);
+ free(header);
+ itkGenericExceptionMacro(<< "Damaged EDF header of "
+ << m_FileName
+ << ": not multiple of 512 B.");
+ }
+ header[header_size] = 0; /* end of string: protection against strstr later
+ on */
+ }
+
+ // parse the header
+ int dim1 = -1, dim2 = -1, datalen = -1;
+ char *otherfile_name = 0; // this file, or another file with the data (EDF vs
+ // EHF formats)
+ int otherfile_skip = 0;
+
+ if ( (p = edf_findInHeader(header, "EDF_BinaryFileName") ) ) {
+ int plen = strcspn(p, " ;\n");
+ otherfile_name = (char*)realloc(otherfile_name, plen+1);
+ strncpy(otherfile_name, p, plen);
+ otherfile_name[plen] = '\0';
+ if ( (p = edf_findInHeader(header, "EDF_BinaryFilePosition") ) )
+ otherfile_skip = atoi(p);
+ }
+
+ if ( (p = edf_findInHeader(header, "Dim_1") ) )
+ dim1 = atoi(p);
+ if ( (p = edf_findInHeader(header, "Dim_2") ) )
+ dim2 = atoi(p);
+
+// int orig1 = -1, orig2 = -1;
+// if ((p = edf_findInHeader(header, "row_beg")))
+// orig1 = atoi(p);
+// if ((p = edf_findInHeader(header, "col_beg")))
+// orig2 = atoi(p);
+
+ static const struct table3 edf_datatype_table[] =
+ {
+ { "UnsignedByte", U_CHAR_DATATYPE, 1 },
+ { "SignedByte", CHAR_DATATYPE, 1 },
+ { "UnsignedShort", U_SHORT_DATATYPE, 2 },
+ { "SignedShort", SHORT_DATATYPE, 2 },
+ { "UnsignedInteger", U_INT_DATATYPE, 4 },
+ { "SignedInteger", INT_DATATYPE, 4 },
+ { "UnsignedLong", U_L_INT_DATATYPE, 4 },
+ { "SignedLong", L_INT_DATATYPE, 4 },
+ { "FloatValue", FLOAT_DATATYPE, 4 },
+ { "DoubleValue", DOUBLE_DATATYPE, 8 },
+ { "Float", FLOAT_DATATYPE, 4 }, // Float and FloatValue
+ // are synonyms
+ { "Double", DOUBLE_DATATYPE, 8 }, // Double and DoubleValue
+ // are synonyms
+ { NULL, -1, -1 }
+ };
+ if ( (p = edf_findInHeader(header, "DataType") ) ) {
+ k = lookup_table3_nth(edf_datatype_table, p);
+ if (k < 0) { // unknown EDF DataType
+ gzclose(inp);
+ free(header);
+ itkGenericExceptionMacro( <<"Unknown EDF datatype \""
+ << p
+ << "\"");
+ }
+ datalen = edf_datatype_table[k].sajzof;
+ switch(k) {
+ case U_CHAR_DATATYPE:
+ SetComponentType(itk::ImageIOBase::UCHAR);
+ break;
+ case CHAR_DATATYPE:
+ SetComponentType(itk::ImageIOBase::CHAR);
+ break;
+ case U_SHORT_DATATYPE:
+ SetComponentType(itk::ImageIOBase::USHORT);
+ break;
+ case SHORT_DATATYPE:
+ SetComponentType(itk::ImageIOBase::SHORT);
+ break;
+ case U_INT_DATATYPE:
+ SetComponentType(itk::ImageIOBase::UINT);
+ break;
+ case INT_DATATYPE:
+ SetComponentType(itk::ImageIOBase::INT);
+ break;
+ case U_L_INT_DATATYPE:
+ SetComponentType(itk::ImageIOBase::ULONG);
+ break;
+ case L_INT_DATATYPE:
+ SetComponentType(itk::ImageIOBase::LONG);
+ break;
+ case FLOAT_DATATYPE:
+ SetComponentType(itk::ImageIOBase::FLOAT);
+ break;
+ case DOUBLE_DATATYPE:
+ SetComponentType(itk::ImageIOBase::DOUBLE);
+ break;
+ }
+ }
+
+ static const struct table edf_byteorder_table[] =
+ {
+ { "LowByteFirst", LittleEndian }, /* little endian */
+ { "HighByteFirst", BigEndian }, /* big endian */
+ { NULL, -1 }
+ };
+
+ int byteorder = LittleEndian;
+ if ( (p = edf_findInHeader(header, "ByteOrder") ) ) {
+ k = lookup_table_nth(edf_byteorder_table, p);
+ if (k >= 0) {
+
+ byteorder = edf_byteorder_table[k].value;
+ if(byteorder==LittleEndian)
+ this->SetByteOrder(LittleEndian);
+ else
+ this->SetByteOrder(BigEndian);
+ }
+ } else
+ itkWarningMacro(<<"ByteOrder not specified in the header! Not swapping bytes (figure may not be correct).");
+ // Get and verify size of the data:
+ int datasize = dim1 * dim2 * datalen;
+ if ( (p = edf_findInHeader(header, "Size") ) ) {
+ int d = atoi(p);
+ if (d != datasize) {
+ itkWarningMacro(<< "Size " << datasize << " is not "
+ << dim1 << 'x' << dim2 << "x" << datalen
+ << " = " << d << ". Supposing the latter.");
+ }
+ }
+
+ // EHF files: binary data are in another file than the header file
+ m_BinaryFileName = m_FileName;
+ m_BinaryFileSkip = header_size;
+ if (otherfile_name) {
+ m_BinaryFileName = std::string(otherfile_name);
+ m_BinaryFileSkip = otherfile_skip;
+ }
+
+ double spacing = 1.;
+ if ( (p = edf_findInHeader(header, "optic_used") ) )
+ spacing = atof(p);
+
+ free(header);
+ gzclose(inp);
+
+ SetNumberOfDimensions(2);
+ SetDimensions(0, dim1);
+ SetDimensions(1, dim2);
+ SetSpacing(0, spacing);
+ SetSpacing(1, spacing);
+ SetOrigin(0, 0.);
+ SetOrigin(1, 0.);
+} ////
+
+//--------------------------------------------------------------------
+// Read Image Information
+bool rtk::EdfImageIO::CanReadFile(const char* FileNameToRead)
+{
+ std::string filename(FileNameToRead);
+ const std::string::size_type it = filename.find_last_of( "." );
+ std::string fileExt( filename, it+1, filename.length() );
+
+ if (fileExt != std::string("edf") ) return false;
+ return true;
+} ////
+
+//--------------------------------------------------------------------
+// Read Image Content
+void rtk::EdfImageIO::Read(void * buffer)
+{
+ gzFile inp;
+
+ inp = gzopen(m_BinaryFileName.c_str(), "rb");
+ if (!inp)
+ itkGenericExceptionMacro(<< "Cannot open file \"" << m_FileName << "\"");
+ gzseek(inp, m_BinaryFileSkip, SEEK_SET);
+
+ // read the data (image)
+ long numberOfBytesToBeRead = GetComponentSize();
+ for(unsigned int i=0; i<GetNumberOfDimensions(); i++) numberOfBytesToBeRead *= GetDimensions(i);
+
+ if (numberOfBytesToBeRead != gzread(inp, buffer, numberOfBytesToBeRead) )
+ itkGenericExceptionMacro(<< "The image " << m_BinaryFileName << " cannot be read completely.");
+
+ gzclose(inp);
+
+ // Adapted from itkRawImageIO
+ {
+ using namespace itk;
+ // Swap bytes if necessary
+ if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
+ else if itkReadRawBytesAfterSwappingMacro( short, SHORT )
+ else if itkReadRawBytesAfterSwappingMacro( char, CHAR )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
+ else if itkReadRawBytesAfterSwappingMacro( int, INT )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned int, ULONG )
+ else if itkReadRawBytesAfterSwappingMacro( int, LONG )
+ else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+ else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+ }
+}
+
+//--------------------------------------------------------------------
+// Write Image Information
+void rtk::EdfImageIO::WriteImageInformation(bool keepOfStream)
+{
+}
+
+//--------------------------------------------------------------------
+// Write Image Information
+bool rtk::EdfImageIO::CanWriteFile(const char* FileNameToWrite)
+{
+ return false;
+}
+
+//--------------------------------------------------------------------
+// Write Image
+void rtk::EdfImageIO::Write(const void * buffer)
+{
+} ////
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkEdfImageIO_h
+#define __rtkEdfImageIO_h
+
+#include <itkImageIOBase.h>
+#include <fstream>
+#include <string.h>
+
+namespace rtk {
+
+/** \class EdfImageIO
+ * \brief Class for reading Edf image file format. Edf is the format of
+ * X-ray projection images at the ESRF.
+ *
+ * \author Simon Rit
+ *
+ * \ingroup IOFilters
+ */
+class EdfImageIO : public itk::ImageIOBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef EdfImageIO Self;
+ typedef itk::ImageIOBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+
+ EdfImageIO() : Superclass() {
+ }
+
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(EdfImageIO, ImageIOBase);
+
+ /*-------- This part of the interface deals with reading data. ------ */
+ virtual void ReadImageInformation();
+
+ virtual bool CanReadFile( const char* FileNameToRead );
+
+ virtual void Read(void * buffer);
+
+ /*-------- This part of the interfaces deals with writing data. ----- */
+ virtual void WriteImageInformation(bool keepOfStream);
+
+ virtual void WriteImageInformation() {
+ WriteImageInformation(false);
+ }
+
+ virtual bool CanWriteFile(const char* filename);
+
+ virtual void Write(const void* buffer);
+
+protected:
+ std::string m_BinaryFileName;
+ int m_BinaryFileSkip;
+
+ static char* edf_findInHeader( char* header, const char* key );
+
+ /* List of EDF supported datatypes
+ */
+ enum DataType {
+ U_CHAR_DATATYPE = 0, CHAR_DATATYPE, // 8 bits = 1 B
+ U_SHORT_DATATYPE, SHORT_DATATYPE, // 16 bits = 2 B
+ U_INT_DATATYPE, INT_DATATYPE, // 32 bits = 4 B
+ U_L_INT_DATATYPE, L_INT_DATATYPE, // 32 bits = 4 B
+ FLOAT_DATATYPE, DOUBLE_DATATYPE, // 4 B, 8 B
+ UNKNOWN_DATATYPE = -1
+ };
+
+ /* Note - compatibility:
+ Unsigned8 = 1, Signed8, Unsigned16, Signed16,
+ Unsigned32, Signed32, Unsigned64, Signed64,
+ FloatIEEE32, DoubleIEEE64
+ */
+
+ /***************************************************************************
+ * Tables
+ ***************************************************************************/
+
+ // table key-value structure
+ struct table {
+ const char *key;
+ int value;
+ };
+
+ struct table3 {
+ const char *key;
+ int value;
+ short sajzof;
+ };
+
+ /* Returns index of the table tbl whose key matches the beginning of the
+ * search string search_str.
+ * It returns index into the table or -1 if there is no match.
+ */
+ static int
+ lookup_table_nth( const struct table *tbl, const char *search_str )
+ {
+ int k = -1;
+
+ while (tbl[++k].key)
+ if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key) ) )
+ return k;
+ return -1; // not found
+ }
+
+ static int
+ lookup_table3_nth( const struct table3 *tbl, const char *search_str )
+ {
+ int k = -1;
+
+ while (tbl[++k].key)
+ if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key) ) )
+ return k;
+ return -1; // not found
+ }
+
+ ///* Orientation of axes of the raster, as the binary matrix is saved in
+ // * the file. (Determines the scanning direction, or the "fastest" index
+ // * of the matrix in the data file.)
+ // */
+ //enum EdfRasterAxes {
+ // RASTER_AXES_XrightYdown, // matricial format: rows, columns
+ // RASTER_AXES_XrightYup // cartesian coordinate system
+ // // other 6 combinations not available (not needed until now)
+ //};
+
+ //static const struct table rasteraxes_table[] =
+ //{
+ // { "XrightYdown", RASTER_AXES_XrightYdown },
+ // { "XrightYup", RASTER_AXES_XrightYup },
+ // { NULL, -1 }
+ //};
+
+}; // end class EdfImageIO
+
+} // end namespace
+
+#endif
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#include "rtkEdfImageIOFactory.h"
+
+//====================================================================
+rtk::EdfImageIOFactory::EdfImageIOFactory()
+{
+ this->RegisterOverride("itkImageIOBase",
+ "EdfImageIO",
+ "Edf Image IO",
+ 1,
+ itk::CreateObjectFunction<EdfImageIO>::New() );
+}
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkEdfImageIOFactory_h
+#define __rtkEdfImageIOFactory_h
+
+#include "rtkEdfImageIO.h"
+#include <itkImageIOBase.h>
+#include <itkObjectFactoryBase.h>
+#include <itkVersion.h>
+
+namespace rtk {
+
+/** \class EdfImageIOFactory
+ * \brief ITK factory for Edf file I/O.
+ *
+ * \author Simon Rit
+ */
+class EdfImageIOFactory : public itk::ObjectFactoryBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef EdfImageIOFactory Self;
+ typedef itk::ObjectFactoryBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef itk::SmartPointer<const Self> ConstPointer;
+
+ /** Class methods used to interface with the registered factories. */
+ const char* GetITKSourceVersion(void) const {
+ return ITK_SOURCE_VERSION;
+ }
+
+ const char* GetDescription(void) const {
+ return "Edf ImageIO Factory, allows the loading of Edf images into insight";
+ }
+
+ /** Method for class instantiation. */
+ itkFactorylessNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(EdfImageIOFactory, ObjectFactoryBase);
+
+ /** Register one factory of this type */
+ static void RegisterOneFactory(void) {
+ ObjectFactoryBase::RegisterFactory( Self::New() );
+ }
+
+protected:
+ EdfImageIOFactory();
+ ~EdfImageIOFactory() {}
+
+ typedef EdfImageIOFactory myProductType;
+ const myProductType* m_MyProduct;
+private:
+ EdfImageIOFactory(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+
+};
+
+} // end namespace
+
+#endif
/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://www.centreleonberard.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
+#define HEADER_INFO_SIZE 68
- It is distributed under dual licence
+// Based on a true story by the Nederlands Kanker Instituut (AVS_HEIMANN.CPP
+// from the 20090608)
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHISIMAGEIO_CXX
-#define CLITKHISIMAGEIO_CXX
-#define HEADER_INFO_SIZE 68
-/**
- -------------------------------------------------
- * @file clitkHisImageIO.cxx
- * @author Simon Rit <simon.rit@gmail.com>
- * @date 16 Feb 2010
- *
- * @brief
- *
- *
- -------------------------------------------------*/
-
-// Based on a true story by the Nederlands Kanker Instituut (AVS_HEIMANN.CPP from the 20090608)
-
-// std include
+// Includes
#include <fstream>
-
-// clitk include
-#include "clitkHisImageIO.h"
-#include "clitkCommon.h"
+#include "rtkHisImageIO.h"
//--------------------------------------------------------------------
// Read Image Information
-void clitk::HisImageIO::ReadImageInformation()
+void rtk::HisImageIO::ReadImageInformation()
{
// open file
std::ifstream file(m_FileName.c_str(), std::ios::in | std::ios::binary);
+
if ( file.fail() )
- itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
+ itkGenericExceptionMacro(<< "Could not open file (for reading): "
+ << m_FileName);
// read header
char header[HEADER_INFO_SIZE];
file.read(header, HEADER_INFO_SIZE);
if (header[0]!=0 || header[1]!=112 || header[2]!=68 || header[3]!=0) {
- itkExceptionMacro(<< "clitk::HisImageIO::ReadImageInformation: file " << m_FileName << " not in Heimann HIS format version 100");
+ itkExceptionMacro(<< "rtk::HisImageIO::ReadImageInformation: file "
+ << m_FileName
+ << " not in Heimann HIS format version 100");
return;
- }
+ }
int nrframes, type, ulx, uly, brx, bry;
m_HeaderSize = header[10] + (header[11]<<8);
- ulx = header[12] + (header[13]<<8);
- uly = header[14] + (header[15]<<8);
- brx = header[16] + (header[17]<<8);
- bry = header[18] + (header[19]<<8);
- nrframes = header[20] + (header[21]<<8);
- type = header[32] + (header[34]<<8);
-
- switch(type) {
- case 4:
- SetComponentType(itk::ImageIOBase::USHORT);
- break;
+ ulx = header[12] + (header[13]<<8);
+ uly = header[14] + (header[15]<<8);
+ brx = header[16] + (header[17]<<8);
+ bry = header[18] + (header[19]<<8);
+ nrframes = header[20] + (header[21]<<8);
+ type = header[32] + (header[34]<<8);
+
+ switch(type)
+ {
+ case 4:
+ SetComponentType(itk::ImageIOBase::USHORT);
+ break;
// case 8: SetComponentType(itk::ImageIOBase::INT); break;
// case 16: SetComponentType(itk::ImageIOBase::FLOAT); break;
// case 32: SetComponentType(itk::ImageIOBase::INT); break;
- default:
- SetComponentType(itk::ImageIOBase::USHORT);
- break;
- }
-
- switch(nrframes) {
- case 1:
- SetNumberOfDimensions(2);
- break;
- default:
- SetNumberOfDimensions(3);
- break;
- }
+ default:
+ SetComponentType(itk::ImageIOBase::USHORT);
+ break;
+ }
+
+ switch(nrframes)
+ {
+ case 1:
+ SetNumberOfDimensions(2);
+ break;
+ default:
+ SetNumberOfDimensions(3);
+ break;
+ }
SetDimensions(0, bry-uly+1);
SetDimensions(1, brx-ulx+1);
if (nrframes>1)
SetDimensions(2, nrframes);
- SetSpacing(0, 409.6/GetDimensions(0));
- SetSpacing(1, 409.6/GetDimensions(1));
+ SetSpacing(0, 409.6/GetDimensions(0) );
+ SetSpacing(1, 409.6/GetDimensions(1) );
- SetOrigin(0, -0.5*(GetDimensions(0)-1)*GetSpacing(0));
- SetOrigin(1, -0.5*(GetDimensions(1)-1)*GetSpacing(1));
+ SetOrigin(0, -0.5*(GetDimensions(0)-1)*GetSpacing(0) );
+ SetOrigin(1, -0.5*(GetDimensions(1)-1)*GetSpacing(1) );
} ////
//--------------------------------------------------------------------
// Read Image Information
-bool clitk::HisImageIO::CanReadFile(const char* FileNameToRead)
+bool rtk::HisImageIO::CanReadFile(const char* FileNameToRead)
{
- std::string filename(FileNameToRead);
- std::string filenameext = GetExtension(filename);
- if (filenameext != std::string("his")) return false;
+ std::string filename(FileNameToRead);
+ const std::string::size_type it = filename.find_last_of( "." );
+ std::string fileExt( filename, it+1, filename.length() );
+
+ if (fileExt != std::string("his") )
+ return false;
return true;
} ////
//--------------------------------------------------------------------
// Read Image Content
-void clitk::HisImageIO::Read(void * buffer)
+void rtk::HisImageIO::Read(void * buffer)
{
// open file
std::ifstream file(m_FileName.c_str(), std::ios::in | std::ios::binary);
+
if ( file.fail() )
itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
-
file.seekg(m_HeaderSize+HEADER_INFO_SIZE, std::ios::beg);
if ( file.fail() )
itkExceptionMacro(<<"File seek failed (His Read)");
-
- file.read((char*)buffer, GetImageSizeInBytes());
+ file.read( (char*)buffer, GetImageSizeInBytes() );
if ( file.fail() )
itkExceptionMacro(<<"Read failed: Wanted "
<< GetImageSizeInBytes()
<< " bytes, but read "
<< file.gcount() << " bytes. The current state is: "
- << file.rdstate());
+ << file.rdstate() );
}
//--------------------------------------------------------------------
-bool clitk::HisImageIO::CanWriteFile(const char* FileNameToWrite)
+bool rtk::HisImageIO::CanWriteFile(const char* FileNameToWrite)
{
- std::string filename(FileNameToWrite);
- std::string filenameext = GetExtension(filename);
- if (filenameext != std::string("his")) return false;
- return true;
+ return CanReadFile(FileNameToWrite);
}
//--------------------------------------------------------------------
// Write Image
-void clitk::HisImageIO::Write(const void* buffer)
+void rtk::HisImageIO::Write(const void* buffer)
{
std::ofstream file(m_FileName.c_str(), std::ios::out | std::ios::binary);
+
if ( file.fail() )
itkGenericExceptionMacro(<< "Could not open file (for writing): " << m_FileName);
0xFE, 0x2A, 0x49, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
- };
+ };
/* Fill into the header the essentials
The 'iheader' in previous module is fixed to 0x20, and is included in szHeader.
the image.
*/
const unsigned int ndim = GetNumberOfDimensions();
- if ((ndim < 2) || (ndim > 3))
+ if ( (ndim < 2) || (ndim > 3) )
itkExceptionMacro( <<"Only 2D or 3D support");
- szHeader[16] = (char)(GetDimensions(0) % 256); // X-size lsb
- szHeader[17] = (char)(GetDimensions(0) / 256); // X-size msb
- szHeader[18] = (char)(GetDimensions(1) % 256); // Y-size lsb
- szHeader[19] = (char)(GetDimensions(1) / 256); // Y-size msb
+ szHeader[16] = (char)(GetDimensions(0) % 256); // X-size lsb
+ szHeader[17] = (char)(GetDimensions(0) / 256); // X-size msb
+ szHeader[18] = (char)(GetDimensions(1) % 256); // Y-size lsb
+ szHeader[19] = (char)(GetDimensions(1) / 256); // Y-size msb
if (ndim == 3) {
- szHeader[20] = (char)(GetDimensions(0) % 256); // NbFrames lsb
- szHeader[21] = (char)(GetDimensions(0) / 256); // NbFrames msb
- }
-
- switch (GetComponentType()) {
- case itk::ImageIOBase::USHORT:
- szHeader[32] = 4;
- break;
+ szHeader[20] = (char)(GetDimensions(0) % 256); // NbFrames lsb
+ szHeader[21] = (char)(GetDimensions(0) / 256); // NbFrames msb
+ }
+
+ switch (GetComponentType())
+ {
+ case itk::ImageIOBase::USHORT:
+ szHeader[32] = 4;
+ break;
//case AVS_TYPE_INTEGER:
// szHeader[32] = 8;
// break;
//case AVS_TYPE_REAL:
// szHeader[32] = 16;
// break;
- default:
- itkExceptionMacro(<< "Unsupported field type");
- break;
- }
+ default:
+ itkExceptionMacro(<< "Unsupported field type");
+ break;
+ }
file.write(szHeader, m_HeaderSize);
- file.write((const char *)buffer, GetImageSizeInBytes());
+ file.write( (const char *)buffer, GetImageSizeInBytes() );
file.close();
} ////
-
-#endif /* end #define CLITKHISIMAGEIO_CXX */
-
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkHisImageIO_h
+#define __rtkHisImageIO_h
+
+// itk include
+#include <itkImageIOBase.h>
+
+namespace rtk
+{
+
+/** \class HisImageIO
+ * \brief Class for reading His Image file format
+ *
+ * The his image file format is used by Perkin Elmer flat panels.
+ *
+ * \author Simon Rit
+ *
+ * \ingroup IOFilters
+ */
+class HisImageIO : public itk::ImageIOBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef HisImageIO Self;
+ typedef itk::ImageIOBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef signed short int PixelType;
+
+ HisImageIO() : Superclass() {
+ ;
+ }
+
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(HisImageIO, itk::ImageIOBase);
+
+ /*-------- This part of the interface deals with reading data. ------ */
+ virtual void ReadImageInformation();
+
+ virtual bool CanReadFile( const char* FileNameToRead );
+
+ virtual void Read(void * buffer);
+
+ /*-------- This part of the interfaces deals with writing data. ----- */
+ virtual void WriteImageInformation(bool /*keepOfStream*/) {
+ ;
+ }
+
+ virtual void WriteImageInformation() {
+ WriteImageInformation(false);
+ }
+
+ virtual bool CanWriteFile(const char* filename);
+
+ virtual void Write(const void* buffer);
+
+protected:
+ int m_HeaderSize;
+
+}; // end class HisImageIO
+} // end namespace
+
+#endif /* end #define __rtkHisImageIO_h */
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#include "rtkHisImageIOFactory.h"
+
+#include <fstream>
+
+//====================================================================
+rtk::HisImageIOFactory::HisImageIOFactory()
+{
+ this->RegisterOverride("itkImageIOBase",
+ "HisImageIO",
+ "His Image IO",
+ 1,
+ itk::CreateObjectFunction<HisImageIO>::New() );
+}
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkHisImageIOFactory_h
+#define __rtkHisImageIOFactory_h
+
+#include "rtkHisImageIO.h"
+
+// itk include
+#include <itkImageIOBase.h>
+#include <itkObjectFactoryBase.h>
+#include <itkVersion.h>
+
+namespace rtk
+{
+
+/** \class HisImageIOFactory
+ * \brief ITK factory for His file I/O.
+ *
+ * \author Simon Rit
+ */
+class HisImageIOFactory : public itk::ObjectFactoryBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef HisImageIOFactory Self;
+ typedef itk::ObjectFactoryBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef itk::SmartPointer<const Self> ConstPointer;
+
+ /** Class methods used to interface with the registered factories. */
+ const char* GetITKSourceVersion(void) const {
+ return ITK_SOURCE_VERSION;
+ }
+
+ const char* GetDescription(void) const {
+ return "His ImageIO Factory, allows the loading of His images into insight";
+ }
+
+ /** Method for class instantiation. */
+ itkFactorylessNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(HisImageIOFactory, itk::ObjectFactoryBase);
+
+ /** Register one factory of this type */
+ static void RegisterOneFactory(void) {
+ ObjectFactoryBase::RegisterFactory( Self::New() );
+ }
+
+protected:
+ HisImageIOFactory();
+ ~HisImageIOFactory() {};
+ typedef HisImageIOFactory myProductType;
+ const myProductType* m_MyProduct;
+
+private:
+ HisImageIOFactory(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+
+};
+
+} // end namespace
+
+#endif /* end #define __rtkHisImageIOFactory_h */
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+// std include
+#include <stdio.h>
+
+#include "rtkHndImageIO.h"
+#include <itkMetaDataObject.h>
+
+//--------------------------------------------------------------------
+// Read Image Information
+void rtk::HndImageIO::ReadImageInformation()
+{
+ Hnd_header hnd;
+ FILE * fp;
+
+ fp = fopen (m_FileName.c_str(), "rb");
+ if (fp == NULL)
+ itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
+
+ size_t nelements = 0;
+ nelements += fread ( (void *) hnd.sFileType, sizeof(char), 32, fp);
+ nelements += fread ( (void *) &hnd.FileLength, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) hnd.sChecksumSpec, sizeof(char), 4, fp);
+ nelements += fread ( (void *) &hnd.nCheckSum, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) hnd.sCreationDate, sizeof(char), 8, fp);
+ nelements += fread ( (void *) hnd.sCreationTime, sizeof(char), 8, fp);
+ nelements += fread ( (void *) hnd.sPatientID, sizeof(char), 16, fp);
+ nelements += fread ( (void *) &hnd.nPatientSer, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) hnd.sSeriesID, sizeof(char), 16, fp);
+ nelements += fread ( (void *) &hnd.nSeriesSer, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) hnd.sSliceID, sizeof(char), 16, fp);
+ nelements += fread ( (void *) &hnd.nSliceSer, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) &hnd.SizeX, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) &hnd.SizeY, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) &hnd.dSliceZPos, sizeof(double), 1, fp);
+ nelements += fread ( (void *) hnd.sModality, sizeof(char), 16, fp);
+ nelements += fread ( (void *) &hnd.nWindow, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) &hnd.nLevel, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) &hnd.nPixelOffset, sizeof(uint32_t), 1, fp);
+ nelements += fread ( (void *) hnd.sImageType, sizeof(char), 4, fp);
+ nelements += fread ( (void *) &hnd.dGantryRtn, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dSAD, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dSFD, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCollX1, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCollX2, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCollY1, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCollY2, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCollRtn, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dFieldX, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dFieldY, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dBladeX1, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dBladeX2, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dBladeY1, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dBladeY2, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dIDUPosLng, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dIDUPosLat, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dIDUPosVrt, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dIDUPosRtn, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dPatientSupportAngle, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dTableTopEccentricAngle, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCouchVrt, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCouchLng, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCouchLat, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dIDUResolutionX, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dIDUResolutionY, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dImageResolutionX, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dImageResolutionY, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dEnergy, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dDoseRate, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dXRayKV, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dXRayMA, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dMetersetExposure, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dAcqAdjustment, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCTProjectionAngle, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dCTNormChamber, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dGatingTimeTag, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dGating4DInfoX, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dGating4DInfoY, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dGating4DInfoZ, sizeof(double), 1, fp);
+ nelements += fread ( (void *) &hnd.dGating4DInfoTime, sizeof(double), 1, fp);
+
+ if(nelements != /*char*/120 + /*uint32_t*/10 + /*double*/41)
+ itkGenericExceptionMacro(<< "Could not read header data in " << m_FileName);
+
+ if(fclose (fp) != 0)
+ itkGenericExceptionMacro(<< "Could not close file: " << m_FileName);
+
+ /* Convert hnd to ITK image information */
+ SetNumberOfDimensions(2);
+ SetDimensions(0, hnd.SizeX);
+ SetDimensions(1, hnd.SizeY);
+ SetSpacing(0, hnd.dIDUResolutionX);
+ SetSpacing(1, hnd.dIDUResolutionY);
+ SetOrigin(0, -0.5*(hnd.SizeX-1)*hnd.dIDUResolutionX); //SR: assumed centered
+ SetOrigin(1, -0.5*(hnd.SizeY-1)*hnd.dIDUResolutionY); //SR: assumed centered
+ SetComponentType(itk::ImageIOBase::UINT);
+
+ /* Store important meta information in the meta data dictionary */
+ itk::EncapsulateMetaData<double>(this->GetMetaDataDictionary(), "dCTProjectionAngle", hnd.dCTProjectionAngle);
+}
+
+//--------------------------------------------------------------------
+bool rtk::HndImageIO::CanReadFile(const char* FileNameToRead)
+{
+ std::string filename(FileNameToRead);
+ const std::string::size_type it = filename.find_last_of( "." );
+ std::string fileExt( filename, it+1, filename.length() );
+
+ if (fileExt != std::string("hnd") )
+ return false;
+ return true;
+}
+
+//--------------------------------------------------------------------
+// Read Image Content
+void rtk::HndImageIO::Read(void * buffer)
+{
+ FILE *fp;
+
+ uint32_t* buf = (uint32_t*)buffer;
+ unsigned char *pt_lut;
+ uint32_t a;
+ unsigned char v;
+ int lut_idx, lut_off;
+ size_t num_read;
+ char dc;
+ short ds;
+ long dl, diff=0;
+ uint32_t i;
+
+ fp = fopen (m_FileName.c_str(), "rb");
+ if (fp == NULL)
+ itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
+
+ pt_lut = (unsigned char*) malloc (sizeof (unsigned char) * GetDimensions(0) * GetDimensions(1) );
+
+ /* Read LUT */
+ if(fseek (fp, 1024, SEEK_SET) != 0)
+ itkGenericExceptionMacro(<< "Could not seek to image data in: " << m_FileName);
+
+ size_t nbytes = (GetDimensions(1)-1)*GetDimensions(0) / 4;
+ if(nbytes != fread (pt_lut, sizeof(unsigned char), nbytes, fp))
+ itkGenericExceptionMacro(<< "Could not read image LUT in: " << m_FileName);
+
+ /* Read first row */
+ for (i = 0; i < GetDimensions(0); i++) {
+ if(1 != fread (&a, sizeof(uint32_t), 1, fp))
+ itkGenericExceptionMacro(<< "Could not read first row in: " << m_FileName);
+ buf[i] = a;
+ }
+
+ /* Read first pixel of second row */
+ if(1 != fread (&a, sizeof(uint32_t), 1, fp))
+ itkGenericExceptionMacro(<< "Could not read first pixel of second row");
+ buf[i++] = a;
+
+ /* Decompress the rest */
+ lut_idx = 0;
+ lut_off = 0;
+ while (i < GetDimensions(0) * GetDimensions(1) ) {
+ uint32_t r11, r12, r21;
+
+ r11 = buf[i-GetDimensions(0)-1];
+ r12 = buf[i-GetDimensions(0)];
+ r21 = buf[i-1];
+ v = pt_lut[lut_idx];
+ switch (lut_off) {
+ case 0:
+ v = v & 0x03;
+ lut_off++;
+ break;
+ case 1:
+ v = (v & 0x0C) >> 2;
+ lut_off++;
+ break;
+ case 2:
+ v = (v & 0x30) >> 4;
+ lut_off++;
+ break;
+ case 3:
+ v = (v & 0xC0) >> 6;
+ lut_off = 0;
+ lut_idx++;
+ break;
+ }
+ switch (v) {
+ case 0:
+ num_read = fread (&dc, sizeof(unsigned char), 1, fp);
+ if (num_read != 1) goto read_error;
+ diff = dc;
+ break;
+ case 1:
+ num_read = fread (&ds, sizeof(unsigned short), 1, fp);
+ if (num_read != 1) goto read_error;
+ diff = ds;
+ break;
+ case 2:
+ num_read = fread (&dl, sizeof(uint32_t), 1, fp);
+ if (num_read != 1) goto read_error;
+ diff = dl;
+ break;
+ }
+
+ buf[i] = r21 + r12 + diff - r11;
+ i++;
+ }
+
+ /* Clean up */
+ free (pt_lut);
+ if(fclose (fp) != 0)
+ itkGenericExceptionMacro(<< "Could not close file: " << m_FileName);
+ return;
+
+read_error:
+
+ itkGenericExceptionMacro(<< "Error reading hnd file");
+ free (pt_lut);
+ if(fclose (fp) != 0)
+ itkGenericExceptionMacro(<< "Could not close file: " << m_FileName);
+ return;
+}
+
+//--------------------------------------------------------------------
+bool rtk::HndImageIO::CanWriteFile(const char* itkNotUsed(FileNameToWrite))
+{
+ return false;
+}
+
+//--------------------------------------------------------------------
+// Write Image
+void rtk::HndImageIO::Write(const void* itkNotUsed(buffer))
+{
+ //TODO?
+}
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkHndImageIO_h
+#define __rtkHndImageIO_h
+
+// itk include
+#include <itkImageIOBase.h>
+
+#if defined (_MSC_VER) && (_MSC_VER < 1600)
+//SR: taken from
+//#include "msinttypes/stdint.h"
+#else
+#include <stdint.h>
+#endif
+
+namespace rtk {
+
+/** \class HndImageIO
+ * \brief Class for reading Hnd Image file format
+ *
+ * Reads Hnd files (file format used by Varian for Obi raw data).
+ *
+ * \author Simon Rit
+ *
+ * \ingroup IOFilters
+ */
+class HndImageIO : public itk::ImageIOBase
+{
+public:
+/** Standard class typedefs. */
+ typedef HndImageIO Self;
+ typedef itk::ImageIOBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef signed short int PixelType;
+
+ typedef struct hnd_header {
+ char sFileType[32];
+ unsigned int FileLength;
+ char sChecksumSpec[4];
+ unsigned int nCheckSum;
+ char sCreationDate[8];
+ char sCreationTime[8];
+ char sPatientID[16];
+ unsigned int nPatientSer;
+ char sSeriesID[16];
+ unsigned int nSeriesSer;
+ char sSliceID[16];
+ unsigned int nSliceSer;
+ unsigned int SizeX;
+ unsigned int SizeY;
+ double dSliceZPos;
+ char sModality[16];
+ unsigned int nWindow;
+ unsigned int nLevel;
+ unsigned int nPixelOffset;
+ char sImageType[4];
+ double dGantryRtn;
+ double dSAD;
+ double dSFD;
+ double dCollX1;
+ double dCollX2;
+ double dCollY1;
+ double dCollY2;
+ double dCollRtn;
+ double dFieldX;
+ double dFieldY;
+ double dBladeX1;
+ double dBladeX2;
+ double dBladeY1;
+ double dBladeY2;
+ double dIDUPosLng;
+ double dIDUPosLat;
+ double dIDUPosVrt;
+ double dIDUPosRtn;
+ double dPatientSupportAngle;
+ double dTableTopEccentricAngle;
+ double dCouchVrt;
+ double dCouchLng;
+ double dCouchLat;
+ double dIDUResolutionX;
+ double dIDUResolutionY;
+ double dImageResolutionX;
+ double dImageResolutionY;
+ double dEnergy;
+ double dDoseRate;
+ double dXRayKV;
+ double dXRayMA;
+ double dMetersetExposure;
+ double dAcqAdjustment;
+ double dCTProjectionAngle;
+ double dCTNormChamber;
+ double dGatingTimeTag;
+ double dGating4DInfoX;
+ double dGating4DInfoY;
+ double dGating4DInfoZ;
+ double dGating4DInfoTime;
+ } Hnd_header;
+
+ HndImageIO() : Superclass() {}
+
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(HndImageIO, itk::ImageIOBase);
+
+ /*-------- This part of the interface deals with reading data. ------ */
+ virtual void ReadImageInformation();
+
+ virtual bool CanReadFile( const char* FileNameToRead );
+
+ virtual void Read(void * buffer);
+
+ /*-------- This part of the interfaces deals with writing data. ----- */
+ virtual void WriteImageInformation(bool /*keepOfStream*/) { }
+
+ virtual void WriteImageInformation() { WriteImageInformation(false); }
+
+ virtual bool CanWriteFile(const char* filename);
+
+ virtual void Write(const void* buffer);
+
+}; // end class HndImageIO
+
+} // end namespace
+
+#endif /* end #define __rtkHndImageIO_h */
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#include "rtkHndImageIOFactory.h"
+
+#include <fstream>
+
+//====================================================================
+rtk::HndImageIOFactory::HndImageIOFactory()
+{
+ this->RegisterOverride("itkImageIOBase",
+ "HndImageIO",
+ "Hnd Image IO",
+ 1,
+ itk::CreateObjectFunction<HndImageIO>::New() );
+}
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+//#ifndef ITKHNDIMAGEIOFACTORY_H
+//#define ITKHNDIMAGEIOFACTORY_H
+
+#ifndef __rtkHndImageIOFactory_h
+#define __rtkHndImageIOFactory_h
+
+#include "rtkHndImageIO.h"
+
+// itk include
+#include <itkImageIOBase.h>
+#include <itkObjectFactoryBase.h>
+#include <itkVersion.h>
+
+namespace rtk
+{
+
+/** \class HndImageIOFactory
+ * \brief ITK factory for Hnd file I/O.
+ *
+ * \author Simon Rit
+ */
+class HndImageIOFactory : public itk::ObjectFactoryBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef HndImageIOFactory Self;
+ typedef itk::ObjectFactoryBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef itk::SmartPointer<const Self> ConstPointer;
+
+ /** Class methods used to interface with the registered factories. */
+ const char* GetITKSourceVersion(void) const {
+ return ITK_SOURCE_VERSION;
+ }
+
+ const char* GetDescription(void) const {
+ return "His ImageIO Factory, allows the loading of His images into insight";
+ }
+
+ /** Method for class instantiation. */
+ itkFactorylessNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(HndImageIOFactory, itk::ObjectFactoryBase);
+
+ /** Register one factory of this type */
+ static void RegisterOneFactory(void) {
+ ObjectFactoryBase::RegisterFactory( Self::New() );
+ }
+
+protected:
+ HndImageIOFactory();
+ ~HndImageIOFactory() {};
+ typedef HndImageIOFactory myProductType;
+ const myProductType* m_MyProduct;
+
+private:
+ HndImageIOFactory(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+
+};
+
+} // end namespace
+
+#endif // __rtkHndImageIOFactory_h
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#include "rtkImagXImageIO.h"
+#include "rtkImagXXMLFileReader.h"
+
+// itk include (for itkReadRawBytesAfterSwappingMacro)
+#include <itkRawImageIO.h>
+#include <itksys/SystemTools.hxx>
+#include <itkMetaDataObject.h>
+#include <itkMatrix.h>
+
+//--------------------------------------------------------------------
+// Read Image Information
+void rtk::ImagXImageIO::ReadImageInformation()
+{
+ rtk::ImagXXMLFileReader::Pointer xmlReader;
+
+ xmlReader = rtk::ImagXXMLFileReader::New();
+ xmlReader->SetFilename(m_FileName);
+ xmlReader->GenerateOutputInformation();
+
+ itk::MetaDataDictionary &dic = *(xmlReader->GetOutputObject() );
+
+ typedef itk::MetaDataObject< double > MetaDataDoubleType;
+ typedef itk::MetaDataObject< std::string > MetaDataStringType;
+ typedef itk::MetaDataObject< int > MetaDataIntType;
+
+ std::string pixelType = dynamic_cast<MetaDataStringType*>(dic["pixelFormat"].GetPointer() )->GetMetaDataObjectValue();
+ if(pixelType=="Type_uint8")
+ SetComponentType(itk::ImageIOBase::UCHAR);
+ if(pixelType=="Type_sint8")
+ SetComponentType(itk::ImageIOBase::CHAR);
+ if(pixelType=="Type_uint16")
+ SetComponentType(itk::ImageIOBase::USHORT);
+ if(pixelType=="Type_sint16")
+ SetComponentType(itk::ImageIOBase::SHORT);
+ if(pixelType=="Type_uint32")
+ SetComponentType(itk::ImageIOBase::UINT);
+ if(pixelType=="Type_sint32")
+ SetComponentType(itk::ImageIOBase::INT);
+ if(pixelType=="Type_float")
+ SetComponentType(itk::ImageIOBase::FLOAT);
+
+ if(dic["dimensions"].GetPointer()==NULL)
+ SetNumberOfDimensions(3);
+ else
+ SetNumberOfDimensions( ( dynamic_cast<MetaDataIntType *>(dic["dimensions"].GetPointer() )->GetMetaDataObjectValue() ) );
+
+ SetDimensions(0, dynamic_cast<MetaDataIntType *>(dic["x"].GetPointer() )->GetMetaDataObjectValue() );
+ SetSpacing(0, dynamic_cast<MetaDataDoubleType *>(dic["spacing_x"].GetPointer() )->GetMetaDataObjectValue() );
+ if(GetNumberOfDimensions()>1)
+ {
+ SetDimensions(1, dynamic_cast<MetaDataIntType *>(dic["y"].GetPointer() )->GetMetaDataObjectValue() );
+ SetSpacing(1, dynamic_cast<MetaDataDoubleType *>(dic["spacing_y"].GetPointer() )->GetMetaDataObjectValue() );
+ }
+ if(GetNumberOfDimensions()>2)
+ {
+ SetDimensions(2, dynamic_cast<MetaDataIntType *>(dic["z"].GetPointer() )->GetMetaDataObjectValue() );
+ SetSpacing(2, dynamic_cast<MetaDataDoubleType *>(dic["spacing_z"].GetPointer() )->GetMetaDataObjectValue() );
+ }
+
+ std::istringstream iss(
+ dynamic_cast<MetaDataStringType*>(dic["matrixTransform"].GetPointer() )->GetMetaDataObjectValue() );
+ itk::Matrix<double, 4, 4> matrix;
+ for(unsigned int j=0; j<4; j++)
+ for(unsigned int i=0; i<4; i++)
+ iss >> matrix[j][i];
+ matrix /= matrix[3][3];
+
+ std::vector<double> direction;
+ for(unsigned int i=0; i<GetNumberOfDimensions(); i++)
+ {
+ direction.clear();
+ for(unsigned int j=0; j<GetNumberOfDimensions(); j++)
+ direction.push_back(matrix[i][j]);
+ SetDirection(i, direction);
+ SetOrigin(i, matrix[i][3]);
+ }
+
+ if(std::string("LSB") == dynamic_cast<MetaDataStringType*>(dic["byteOrder"].GetPointer() )->GetMetaDataObjectValue() )
+ this->SetByteOrder(LittleEndian);
+ else
+ this->SetByteOrder(BigEndian);
+
+ // Prepare raw file name
+ m_RawFileName = itksys::SystemTools::GetFilenamePath(m_FileName);
+ if(m_RawFileName != "")
+ m_RawFileName += std::string("/");
+ m_RawFileName += dynamic_cast<MetaDataStringType*>(dic["rawFile"].GetPointer() )->GetMetaDataObjectValue();
+} ////
+
+//--------------------------------------------------------------------
+// Read Image Information
+bool rtk::ImagXImageIO::CanReadFile(const char* FileNameToRead)
+{
+ std::string ext = itksys::SystemTools::GetFilenameLastExtension(FileNameToRead);
+
+ if( ext!=std::string(".xml") )
+ return false;
+
+ std::ifstream is(FileNameToRead);
+ if(!is.is_open() )
+ return false;
+
+ // If the XML file has "<image name=" at the beginning of the first or second
+ // line, we assume this is an ImagX file
+ std::string line;
+
+ std::getline(is, line);
+ if(line.substr(0, 12) == std::string("<image name=") )
+ return true;
+
+ std::getline(is, line);
+ if(line.substr(0, 12) == std::string("<image name=") )
+ return true;
+
+ return false;
+} ////
+
+//--------------------------------------------------------------------
+// Read Image Content
+void rtk::ImagXImageIO::Read(void * buffer)
+{
+ // Adapted from itkRawImageIO
+ std::ifstream is(m_RawFileName.c_str(), std::ios::binary);
+
+ if(!is.is_open() )
+ itkExceptionMacro(<<"Could not open file " << m_RawFileName);
+
+ unsigned long numberOfBytesToBeRead = GetComponentSize();
+ for(unsigned int i=0; i<GetNumberOfDimensions(); i++) numberOfBytesToBeRead *= GetDimensions(i);
+
+ if(!this->ReadBufferAsBinary(is, buffer, numberOfBytesToBeRead) ) {
+ itkExceptionMacro(<<"Read failed: Wanted "
+ << numberOfBytesToBeRead
+ << " bytes, but read "
+ << is.gcount() << " bytes.");
+ }
+ itkDebugMacro(<< "Reading Done");
+
+ // Adapted from itkRawImageIO
+ {
+ using namespace itk;
+ // Swap bytes if necessary
+ if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
+ else if itkReadRawBytesAfterSwappingMacro( short, SHORT )
+ else if itkReadRawBytesAfterSwappingMacro( char, CHAR )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
+ else if itkReadRawBytesAfterSwappingMacro( int, INT )
+ else if itkReadRawBytesAfterSwappingMacro( unsigned int, ULONG )
+ else if itkReadRawBytesAfterSwappingMacro( int, LONG )
+ else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+ else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+ }
+}
+
+//--------------------------------------------------------------------
+// Write Image Information
+void rtk::ImagXImageIO::WriteImageInformation(bool keepOfStream)
+{
+}
+
+//--------------------------------------------------------------------
+// Write Image Information
+bool rtk::ImagXImageIO::CanWriteFile(const char* FileNameToWrite)
+{
+ return false;
+}
+
+//--------------------------------------------------------------------
+// Write Image
+void rtk::ImagXImageIO::Write(const void * buffer)
+{
+} ////
+
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkImagXImageIO_h
+#define __rtkImagXImageIO_h
+
+#include <itkImageIOBase.h>
+#include <fstream>
+#include <string.h>
+
+namespace rtk
+{
+
+/** \class ImagXImageIO
+ *
+ * TODO
+ *
+ */
+class ImagXImageIO : public itk::ImageIOBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef ImagXImageIO Self;
+ typedef itk::ImageIOBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+
+ ImagXImageIO() : Superclass() {}
+
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(ImagXImageIO, ImageIOBase);
+
+ /*-------- This part of the interface deals with reading data. ------ */
+ virtual void ReadImageInformation();
+
+ virtual bool CanReadFile( const char* FileNameToRead );
+
+ virtual void Read(void * buffer);
+
+ /*-------- This part of the interfaces deals with writing data. ----- */
+ virtual void WriteImageInformation(bool keepOfStream);
+
+ virtual void WriteImageInformation() { WriteImageInformation(false); }
+ virtual bool CanWriteFile(const char* filename);
+
+ virtual void Write(const void* buffer);
+
+protected:
+ std::string m_RawFileName;
+};
+
+} // end namespace
+
+#endif
+
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#include "rtkImagXImageIOFactory.h"
+
+//====================================================================
+rtk::ImagXImageIOFactory::ImagXImageIOFactory()
+{
+ this->RegisterOverride("itkImageIOBase",
+ "ImagXImageIO",
+ "ImagX Image IO",
+ 1,
+ itk::CreateObjectFunction<ImagXImageIO>::New() );
+}
+
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkImagXImageIOFactory_h
+#define __rtkImagXImageIOFactory_h
+
+#include "rtkImagXImageIO.h"
+#include <itkImageIOBase.h>
+#include <itkObjectFactoryBase.h>
+#include <itkVersion.h>
+
+namespace rtk
+{
+
+/** \class ImagXImageIOFactory
+ *
+ * TODO
+ *
+ */
+class ImagXImageIOFactory : public itk::ObjectFactoryBase
+{
+public:
+ /** Standard class typedefs. */
+ typedef ImagXImageIOFactory Self;
+ typedef itk::ObjectFactoryBase Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef itk::SmartPointer<const Self> ConstPointer;
+
+ /** Class methods used to interface with the registered factories. */
+ const char* GetITKSourceVersion(void) const {
+ return ITK_SOURCE_VERSION;
+ }
+
+ const char* GetDescription(void) const {
+ return "ImagX ImageIO Factory, allows the loading of ImagX images into insight";
+ }
+
+ /** Method for class instantiation. */
+ itkFactorylessNewMacro(Self);
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(EsrfHstImageIOFactory, ObjectFactoryBase);
+
+ /** Register one factory of this type */
+ static void RegisterOneFactory(void) {
+ ObjectFactoryBase::RegisterFactory( Self::New() );
+ }
+
+protected:
+ ImagXImageIOFactory();
+ ~ImagXImageIOFactory() {}
+ typedef ImagXImageIOFactory myProductType;
+ const myProductType* m_MyProduct;
+private:
+ ImagXImageIOFactory(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+
+};
+
+} // end namespace
+
+#endif
+
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkImagXLookupTableImageFilter_h
+#define __rtkImagXLookupTableImageFilter_h
+
+#include "rtkLookupTableImageFilter.h"
+#include <itkNumericTraits.h>
+
+namespace rtk
+{
+
+/** \class ImagXLookupTableImageFilter
+ * \brief Lookup table for ImagX data.
+ *
+ * The lookup table converts the raw values measured by the panel to the
+ * logarithm of the value divided by the maximum numerical value. This could
+ * be improved with a calibration of the air value.
+ *
+ * \author Simon Rit
+ *
+ * \ingroup ImageToImageFilter
+ */
+template <class TInputImage, class TOutputImage>
+class ITK_EXPORT ImagXLookupTableImageFilter : public LookupTableImageFilter<TInputImage, TOutputImage>
+{
+
+public:
+ /** Standard class typedefs. */
+ typedef ImagXLookupTableImageFilter Self;
+ typedef LookupTableImageFilter<TInputImage, TOutputImage> Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef itk::SmartPointer<const Self> ConstPointer;
+
+ typedef typename TInputImage::PixelType InputImagePixelType;
+ typedef typename TOutputImage::PixelType OutputImagePixelType;
+ typedef typename Superclass::FunctorType::LookupTableType LookupTableType;
+
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
+
+ /** Runtime information support. */
+ itkTypeMacro(ImagXLookupTableImageFilter, LookupTableImageFilter);
+protected:
+ ImagXLookupTableImageFilter();
+ virtual ~ImagXLookupTableImageFilter() {
+ }
+
+private:
+ ImagXLookupTableImageFilter(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+
+};
+
+} // end namespace rtk
+
+template <class TInputImage, class TOutputImage>
+rtk::ImagXLookupTableImageFilter<TInputImage, TOutputImage>::ImagXLookupTableImageFilter()
+{
+ // Create the lut
+ typename LookupTableType::Pointer lut = LookupTableType::New();
+ typename LookupTableType::SizeType size;
+ size[0] = itk::NumericTraits<InputImagePixelType>::max()-itk::NumericTraits<InputImagePixelType>::min()+1;
+ lut->SetRegions( size );
+ lut->Allocate();
+
+ OutputImagePixelType logRef = log(OutputImagePixelType(size[0]) );
+
+ // Iterate and set lut
+ itk::ImageRegionIteratorWithIndex<LookupTableType> it( lut, lut->GetBufferedRegion() );
+ it.GoToBegin();
+ while( !it.IsAtEnd() )
+ {
+ it.Set( logRef - log(it.GetIndex()[0]+1.) );
+ ++it;
+ }
+
+ // Set the lut to member and functor
+ this->SetLookupTable(lut);
+}
+
+#endif
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkImagXRawToAttenuationImageFilter_h
+#define __rtkImagXRawToAttenuationImageFilter_h
+
+#include <itkImageToImageFilter.h>
+#include <itkCropImageFilter.h>
+
+#include "rtkImagXLookupTableImageFilter.h"
+#include "rtkBoellaardScatterCorrectionImageFilter.h"
+
+/** \class ImagXRawToAttenuationImageFilter
+ * \brief Convert raw ImagX data to attenuation images
+ *
+ * TODO
+ *
+ * \author Simon Rit
+ *
+ * \ingroup ImageToImageFilter
+ */
+namespace rtk
+{
+
+template<class TInputImage, class TOutputImage=TInputImage>
+class ITK_EXPORT ImagXRawToAttenuationImageFilter :
+ public itk::ImageToImageFilter<TInputImage, TOutputImage>
+{
+public:
+ /** Standard class typedefs. */
+ typedef ImagXRawToAttenuationImageFilter Self;
+ typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef itk::SmartPointer<const Self> ConstPointer;
+
+ /** Some convenient typedefs. */
+ typedef TInputImage InputImageType;
+ typedef TOutputImage OutputImageType;
+
+ /** Standard New method. */
+ itkNewMacro(Self);
+
+ /** Runtime information support. */
+ itkTypeMacro(ImagXRawToAttenuationImageFilter, itk::ImageToImageFilter);
+protected:
+ ImagXRawToAttenuationImageFilter();
+ ~ImagXRawToAttenuationImageFilter(){
+ }
+
+ /** Apply changes to the input image requested region. */
+ virtual void GenerateInputRequestedRegion();
+
+ void GenerateOutputInformation();
+
+ /** Single-threaded version of GenerateData. This filter delegates
+ * to other filters. */
+ void GenerateData();
+
+private:
+ //purposely not implemented
+ ImagXRawToAttenuationImageFilter(const Self&);
+ void operator=(const Self&);
+
+ typedef itk::CropImageFilter<InputImageType, InputImageType> CropFilterType;
+ typedef rtk::BoellaardScatterCorrectionImageFilter<InputImageType, InputImageType> ScatterFilterType;
+ typedef rtk::ImagXLookupTableImageFilter<InputImageType, OutputImageType> LookupTableFilterType;
+
+ typename LookupTableFilterType::Pointer m_LookupTableFilter;
+ typename CropFilterType::Pointer m_CropFilter;
+ typename ScatterFilterType::Pointer m_ScatterFilter;
+}; // end of class
+
+} // end namespace rtk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "rtkImagXRawToAttenuationImageFilter.txx"
+#endif
+
+#endif
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkImagXRawToAttenuationImageFilter_txx
+#define __rtkImagXRawToAttenuationImageFilter_txx
+
+#include <itkImageFileWriter.h>
+
+namespace rtk
+{
+
+template<class TInputImage, class TOutputImage>
+void
+ImagXRawToAttenuationImageFilter<TInputImage, TOutputImage>
+::GenerateInputRequestedRegion()
+{
+ typename Superclass::InputImagePointer inputPtr =
+ const_cast< TInputImage * >( this->GetInput() );
+ if ( !inputPtr )
+ return;
+
+ m_CropFilter->SetInput(inputPtr); //SR: this is most likely useless
+ m_LookupTableFilter->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion() );
+ m_LookupTableFilter->GetOutput()->PropagateRequestedRegion();
+}
+
+template <class TInputImage, class TOutputImage>
+ImagXRawToAttenuationImageFilter<TInputImage, TOutputImage>
+::ImagXRawToAttenuationImageFilter()
+{
+ m_CropFilter = CropFilterType::New();
+ m_ScatterFilter = ScatterFilterType::New();
+ m_LookupTableFilter = LookupTableFilterType::New();
+
+ //Permanent internal connections
+ m_ScatterFilter->SetInput( m_CropFilter->GetOutput() );
+ m_LookupTableFilter->SetInput( m_ScatterFilter->GetOutput() );
+
+ //Default filter parameters
+ typename CropFilterType::SizeType border = m_CropFilter->GetLowerBoundaryCropSize();
+ border[0] = 4;
+ border[1] = 4;
+ m_CropFilter->SetBoundaryCropSize(border);
+}
+
+template<class TInputImage, class TOutputImage>
+void
+ImagXRawToAttenuationImageFilter<TInputImage, TOutputImage>
+::GenerateOutputInformation()
+{
+ m_CropFilter->SetInput(this->GetInput() );
+ m_LookupTableFilter->UpdateOutputInformation();
+ this->GetOutput()->SetOrigin( m_LookupTableFilter->GetOutput()->GetOrigin() );
+ this->GetOutput()->SetSpacing( m_LookupTableFilter->GetOutput()->GetSpacing() );
+ this->GetOutput()->SetDirection( m_LookupTableFilter->GetOutput()->GetDirection() );
+ this->GetOutput()->SetLargestPossibleRegion( m_LookupTableFilter->GetOutput()->GetLargestPossibleRegion() );
+}
+
+template<class TInputImage, class TOutputImage>
+void
+ImagXRawToAttenuationImageFilter<TInputImage, TOutputImage>
+::GenerateData()
+{
+ m_CropFilter->SetInput(this->GetInput() );
+ m_LookupTableFilter->Update();
+ this->GraftOutput( m_LookupTableFilter->GetOutput() );
+}
+
+} // end namespace rtk
+#endif
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#include "rtkImagXXMLFileReader.h"
+#include "itkMacro.h"
+
+#include <itksys/SystemTools.hxx>
+#include <itkMetaDataObject.h>
+
+namespace rtk
+{
+
+int
+ImagXXMLFileReader::
+CanReadFile(const char *name)
+{
+ if(!itksys::SystemTools::FileExists(name) ||
+ itksys::SystemTools::FileIsDirectory(name) ||
+ itksys::SystemTools::FileLength(name) == 0)
+ return 0;
+ return 1;
+}
+
+void
+ImagXXMLFileReader::
+StartElement(const char * name, const char ** atts)
+{
+#define ENCAPLULATE_META_DATA_INT(metaName) \
+ if(itksys::SystemTools::Strucmp(atts[i], metaName) == 0) { \
+ double d = atof(atts[i+1]); \
+ itk::EncapsulateMetaData<int>(m_Dictionary, metaName, d); \
+ }
+
+#define ENCAPLULATE_META_DATA_STRING(metaName) \
+ if(itksys::SystemTools::Strucmp(atts[i], metaName) == 0) { \
+ itk::EncapsulateMetaData<std::string>(m_Dictionary, metaName, atts[i+1]); \
+ }
+
+ if(std::string(name) == std::string("image") )
+ {
+ for(int i=0; atts[i] != NULL; i+=2)
+ {
+ ENCAPLULATE_META_DATA_STRING("name");
+ ENCAPLULATE_META_DATA_INT("bitDepth");
+ ENCAPLULATE_META_DATA_STRING("pixelFormat");
+ ENCAPLULATE_META_DATA_STRING("byteOrder");
+ ENCAPLULATE_META_DATA_STRING("modality");
+ ENCAPLULATE_META_DATA_STRING("matrixTransform");
+ ENCAPLULATE_META_DATA_INT("dimensions");
+ ENCAPLULATE_META_DATA_INT("sequence");
+ ENCAPLULATE_META_DATA_STRING("rawFile");
+ }
+ }
+ if(std::string(name) == std::string("size") )
+ {
+ for(int i=0; atts[i] != NULL; i+=2)
+ {
+ ENCAPLULATE_META_DATA_INT("x");
+ ENCAPLULATE_META_DATA_INT("y");
+ ENCAPLULATE_META_DATA_INT("z");
+ }
+ }
+ if(std::string(name) == std::string("spacing") )
+ {
+#define ENCAPLULATE_META_DATA_DOUBLE(metaName) \
+ if(itksys::SystemTools::Strucmp(atts[i], metaName) == 0) { \
+ double d = atof(atts[i+1]); \
+ itk::EncapsulateMetaData<double>(m_Dictionary, std::string("spacing_") + std::string(metaName), d); \
+ }
+ for(int i=0; atts[i] != NULL; i+=2)
+ {
+ ENCAPLULATE_META_DATA_DOUBLE("x");
+ ENCAPLULATE_META_DATA_DOUBLE("y");
+ ENCAPLULATE_META_DATA_DOUBLE("z");
+ }
+ }
+ m_CurCharacterData = "";
+}
+
+void
+ImagXXMLFileReader::
+EndElement(const char *name)
+{
+}
+
+void
+ImagXXMLFileReader::
+CharacterDataHandler(const char *inData, int inLength)
+{
+ for(int i = 0; i < inLength; i++)
+ m_CurCharacterData = m_CurCharacterData + inData[i];
+}
+
+}
--- /dev/null
+/*=========================================================================
+ *
+ * Copyright RTK Consortium
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkImagXXMLFileReader_h
+#define __rtkImagXXMLFileReader_h
+
+#ifdef _MSC_VER
+#pragma warning ( disable : 4786 )
+#endif
+
+#include <itkXMLFile.h>
+#include <itkMetaDataDictionary.h>
+
+#include <map>
+
+namespace rtk
+{
+
+/** \class ImagXXMLFileReader
+ *
+ * TODO
+ *
+ */
+class ImagXXMLFileReader : public itk::XMLReader<itk::MetaDataDictionary>
+{
+public:
+ /** Standard typedefs */
+ typedef ImagXXMLFileReader Self;
+ typedef itk::XMLReader<itk::MetaDataDictionary> Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(ImagXXMLFileReader, itk::XMLReader);
+
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
+
+ /** Determine if a file can be read */
+ int CanReadFile(const char* name);
+
+protected:
+ ImagXXMLFileReader() {m_OutputObject = &m_Dictionary;}
+ virtual ~ImagXXMLFileReader() {}
+
+ virtual void StartElement(const char * name,const char **atts);
+
+ virtual void EndElement(const char *name);
+
+ void CharacterDataHandler(const char *inData, int inLength);
+
+private:
+ ImagXXMLFileReader(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+
+ itk::MetaDataDictionary m_Dictionary;
+ std::string m_CurCharacterData;
+};
+
+}
+#endif
TARGET_LINK_LIBRARIES(clitkConvertBSplineDeformableTransformToVF clitkCommon ${ITK_LIBRARIES})
SET(REGISTRATION_INSTALL ${REGISTRATION_INSTALL} clitkConvertBSplineDeformableTransformToVF)
- SET_TARGET_PROPERTIES(${REGISTRATION_INSTALL} PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}" )
+# SET_TARGET_PROPERTIES(${REGISTRATION_INSTALL} PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}" )
INSTALL (TARGETS ${REGISTRATION_INSTALL} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
ENDIF(CLITK_BUILD_REGISTRATION)
ADD_EXECUTABLE(clitkRegionGrowing clitkRegionGrowing.cxx ${clitkRegionGrowing_GGO_C} ${clitkRelativePosition_GGO_C})
TARGET_LINK_LIBRARIES(clitkRegionGrowing clitkCommon ${ITK_LIBRARIES})
- SET_TARGET_PROPERTIES(${SEGMENTATION_INSTALL} PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}" )
+# SET_TARGET_PROPERTIES(${SEGMENTATION_INSTALL} PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}" )
INSTALL (TARGETS ${SEGMENTATION_INSTALL} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
ENDIF(CLITK_BUILD_SEGMENTATION)
else {
std::string s = m_MapOfTag[tag];
// Read the file
- image = readImage<ImageType>(GetPath()+"/"+s);
+ if (s[0] != '/')
+ image = readImage<ImageType>(GetPath() + "/" + s);
+ else
+ image = readImage<ImageType>(s);
// I add a reference count because the cache is not a smartpointer
image->SetReferenceCount(image->GetReferenceCount()+1);
// Insert into the cache
opening->Update();
typename SlicerFilterType::Pointer slicer = SlicerFilterType::New();
+#if ITK_VERSION_MAJOR >= 4
+ slicer->SetDirectionCollapseToIdentity();
+#endif
slicer->SetInput(opening->GetOutput());
// label result
DEPENDS QT VTK ITK
SOURCE_DIR ${source_prefix}/vv
GIT_REPOSITORY git://git.creatis.insa-lyon.fr/clitk
- GIT_TAG v1.3.0
INSTALL_COMMAND ${MAKE_COMMAND} package
CMAKE_ARGS
-DQT_QMAKE_EXECUTABLE:FILEPATH=${qmake_executable}
SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkDicomRTPlan2Gate)
ENDIF(ITK_VERSION_MAJOR VERSION_LESS 4)
- SET_TARGET_PROPERTIES(${TOOLS_INSTALL} PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}" )
+# SET_TARGET_PROPERTIES(${TOOLS_INSTALL} PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}" )
INSTALL (TARGETS ${TOOLS_INSTALL} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
ENDIF(CLITK_BUILD_TOOLS)
#=========================================================
# Install options (also used by CPack)
IF(UNIX OR APPLE)
- SET_TARGET_PROPERTIES(vv
- PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}")
+# SET_TARGET_PROPERTIES(vv
+# PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}")
INSTALL (TARGETS vv DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
# INSTALL (FILES ${CMAKE_CURRENT_SOURCE_DIR}/icons/ducky.png DESTINATION .)
mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
std::vector<std::string> vector;
- unsigned int currentDim = 0;
- std::vector<double> currentSpacing;
- std::vector<int> currentSize;
- std::vector<double> currentOrigin;
-
- for (int i = 0; i < files.size(); i++) {
- itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
- files[i].toStdString().c_str(), itk::ImageIOFactory::ReadMode);
- if (reader) {
- reader->SetFileName(files[i].toStdString().c_str());
- reader->ReadImageInformation();
- if (i == 0)
- currentDim = reader->GetNumberOfDimensions();
- bool IsOk = true;
- for (unsigned int j = 0; j < currentDim; j++) {
- if (i == 0) {
- if (j == 0) {
- currentSpacing.resize(currentDim);
- currentSize.resize(currentDim);
- currentOrigin.resize(currentDim);
- }
- currentOrigin[j] = reader->GetOrigin(j);
- currentSpacing[j] = reader->GetSpacing(j);
- currentSize[j] = reader->GetDimensions(j);
- } else if (currentDim != reader->GetNumberOfDimensions()
- || currentSpacing[j] != reader->GetSpacing(j)
- || currentSize[j] != (int)reader->GetDimensions(j)
- || currentOrigin[j] != reader->GetOrigin(j)) {
- QString error = "Cannot read file (too different from others ";
- error += files[i].toStdString().c_str();
- QMessageBox::information(this,tr("Reading problem"),error);
- IsOk = false;
- break;
- }
- }
- if (IsOk)
- vector.push_back(files[i].toStdString());
- } else {
- QString error = "Cannot read file info for ";
- error += files[i].toStdString().c_str();
- error += "\n";
- error += "Maybe you're trying to open an image in an unsupported format?\n";
- QMessageBox::information(this,tr("Reading problem"),error);
- }
- }
+ for (int i = 0; i < files.size(); i++)
+ vector.push_back(files[i].toStdString());
sort(vector.begin(),vector.end());
if (vector.size() > 1)
LoadImages(vector, vvImageReader::MERGEDWITHTIME);
QString Extensions = "Images ( *.mhd)";
Extensions += ";;Images ( *.mha)";
- Extensions += ";;Images ( *.vf)";
+ Extensions += ";;VF Images ( *.vf)";
+ Extensions += ";;nii Images ( *.nii)";
+ Extensions += ";;nrrd Images ( *.nrrd)";
+ Extensions += ";;nhdr Images ( *.nhdr)";
+ Extensions += ";;All Files (*)";
QString file = QFileDialog::getOpenFileName(this,tr("Load deformation field"),mInputPathName,Extensions);
if (!file.isEmpty())
AddField(file,index);