]> Creatis software - clitk.git/commitdiff
Added ImagX file format from RTK
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 20 Nov 2012 16:30:21 +0000 (17:30 +0100)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 20 Nov 2012 16:30:21 +0000 (17:30 +0100)
common/CMakeLists.txt
common/clitkIO.cxx
common/rtkImagXImageIO.cxx [new file with mode: 0644]
common/rtkImagXImageIO.h [new file with mode: 0644]
common/rtkImagXImageIOFactory.cxx [new file with mode: 0644]
common/rtkImagXImageIOFactory.h [new file with mode: 0644]
common/rtkImagXLookupTableImageFilter.h [new file with mode: 0644]
common/rtkImagXRawToAttenuationImageFilter.h [new file with mode: 0644]
common/rtkImagXRawToAttenuationImageFilter.txx [new file with mode: 0644]
common/rtkImagXXMLFileReader.cxx [new file with mode: 0644]
common/rtkImagXXMLFileReader.h [new file with mode: 0644]

index a6edaf4d1349be8ad1c9017652bc0ec0eb16194d..3c7a5803ed801494be97bbb0580604cb7d42a50a 100644 (file)
@@ -24,6 +24,9 @@ SET(clitkCommon_SRC
   rtkHndImageIOFactory.cxx
   rtkEdfImageIO.cxx
   rtkEdfImageIOFactory.cxx
+  rtkImagXImageIO.cxx
+  rtkImagXImageIOFactory.cxx
+  rtkImagXXMLFileReader.cxx
   clitkEsrfHstImageIO.cxx  
   clitkEsrfHstImageIOFactory.cxx
   clitkEsrfHstXMLFileReader.cxx
index 74284ea94449396aad0cf731b0c3a7825253028d..8b159e7828bb13cbca487c20f517c7586ce47c1a 100644 (file)
@@ -33,6 +33,7 @@
 #include "rtkHisImageIOFactory.h"
 #include "rtkHndImageIOFactory.h"
 #include "rtkEdfImageIOFactory.h"
+#include "rtkImagXImageIOFactory.h"
 #include "clitkEsrfHstImageIOFactory.h"
 #include "clitkGateAsciiImageIOFactory.h"
 #include "clitkConfiguration.h"
@@ -62,6 +63,7 @@ void clitk::RegisterClitkFactories()
   rtk::HisImageIOFactory::RegisterOneFactory();
   rtk::HndImageIOFactory::RegisterOneFactory();
   rtk::EdfImageIOFactory::RegisterOneFactory();
+  rtk::ImagXImageIOFactory::RegisterOneFactory();
   clitk::EsrfHstImageIOFactory::RegisterOneFactory();
 } ////
 
diff --git a/common/rtkImagXImageIO.cxx b/common/rtkImagXImageIO.cxx
new file mode 100644 (file)
index 0000000..d197ed7
--- /dev/null
@@ -0,0 +1,192 @@
+/*=========================================================================
+ *
+ *  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)
+{
+} ////
+
diff --git a/common/rtkImagXImageIO.h b/common/rtkImagXImageIO.h
new file mode 100644 (file)
index 0000000..8188b04
--- /dev/null
@@ -0,0 +1,72 @@
+/*=========================================================================
+ *
+ *  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
+
diff --git a/common/rtkImagXImageIOFactory.cxx b/common/rtkImagXImageIOFactory.cxx
new file mode 100644 (file)
index 0000000..47520a9
--- /dev/null
@@ -0,0 +1,30 @@
+/*=========================================================================
+ *
+ *  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() );
+}
+
diff --git a/common/rtkImagXImageIOFactory.h b/common/rtkImagXImageIOFactory.h
new file mode 100644 (file)
index 0000000..5170d45
--- /dev/null
@@ -0,0 +1,78 @@
+/*=========================================================================
+ *
+ *  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
+
diff --git a/common/rtkImagXLookupTableImageFilter.h b/common/rtkImagXLookupTableImageFilter.h
new file mode 100644 (file)
index 0000000..c6271cc
--- /dev/null
@@ -0,0 +1,97 @@
+/*=========================================================================
+ *
+ *  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
diff --git a/common/rtkImagXRawToAttenuationImageFilter.h b/common/rtkImagXRawToAttenuationImageFilter.h
new file mode 100644 (file)
index 0000000..6ee663a
--- /dev/null
@@ -0,0 +1,94 @@
+/*=========================================================================
+ *
+ *  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
diff --git a/common/rtkImagXRawToAttenuationImageFilter.txx b/common/rtkImagXRawToAttenuationImageFilter.txx
new file mode 100644 (file)
index 0000000..5e02cee
--- /dev/null
@@ -0,0 +1,85 @@
+/*=========================================================================
+ *
+ *  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
diff --git a/common/rtkImagXXMLFileReader.cxx b/common/rtkImagXXMLFileReader.cxx
new file mode 100644 (file)
index 0000000..f415f0d
--- /dev/null
@@ -0,0 +1,109 @@
+/*=========================================================================
+ *
+ *  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];
+}
+
+}
diff --git a/common/rtkImagXXMLFileReader.h b/common/rtkImagXXMLFileReader.h
new file mode 100644 (file)
index 0000000..1a948e2
--- /dev/null
@@ -0,0 +1,75 @@
+/*=========================================================================
+ *
+ *  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