1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 /** 19 * \file itkPhilipsRECImageIO.h 20 * The code for this file reader was written based on 21 * examination of Philips REC/PAR image files acquired at the 22 * Center for NMR Research at the Penn State Milton S. Hershey 23 * Medical Center. 24 * 25 * 26 * \author Don C. Bigler 27 * The Pennsylvania State University 2005 28 * 29 * This implementation was contributed as a paper to the Insight Journal 30 * https://hdl.handle.net/1926/1381 31 * 32 */ 33 34 #ifndef itkPhilipsRECImageIO_h 35 #define itkPhilipsRECImageIO_h 36 #include "ITKIOPhilipsRECExport.h" 37 38 39 #include "itkImageIOBase.h" 40 #include "itkVectorContainer.h" 41 #include "vnl/vnl_vector_fixed.h" 42 43 namespace itk 44 { 45 /** \class PhilipsRECImageIO 46 * \author Don C. Bigler 47 * \brief Reads Philips REC/PAR image files. 48 * 49 * This class supports reading only and not writing. 50 * \ingroup IOFilters 51 * \ingroup ITKIOPhilipsREC 52 */ 53 54 class ITKIOPhilipsREC_EXPORT PhilipsRECImageIO:public ImageIOBase 55 { 56 public: 57 ITK_DISALLOW_COPY_AND_ASSIGN(PhilipsRECImageIO); 58 59 /** Standard class type aliases. */ 60 using Self = PhilipsRECImageIO; 61 using Superclass = ImageIOBase; 62 using Pointer = SmartPointer< Self >; 63 64 /** Method for creation through the object factory. */ 65 itkNewMacro(Self); 66 67 /** Run-time type information (and related methods). */ 68 itkTypeMacro(PhilipsRECImageIO, Superclass); 69 70 /** Special types used for Philips PAR meta data. */ 71 using EchoTimesContainerType = VectorContainer< unsigned int, double >; 72 using TriggerTimesContainerType = VectorContainer< unsigned int, double >; 73 using RepetitionTimesContainerType = VectorContainer< unsigned int, double >; 74 using ScanResolutionType = vnl_vector_fixed< int, 2 >; 75 using FOVType = vnl_vector_fixed< float, 3 >; 76 using AngulationMidSliceType = vnl_vector_fixed< double, 3 >; 77 using OffCentreMidSliceType = vnl_vector_fixed< double, 3 >; 78 using PhaseEncodingVelocityType = vnl_vector_fixed< float, 3 >; 79 /** Image types: 80 * 0 = Magnitude, 81 * 1 = Real, 82 * 2 = Imaginary, 83 * 3 = Phase, 84 * 4 = Special/Processed. */ 85 using ImageTypesType = vnl_vector_fixed< int, 8 >; 86 using ScanningSequencesType = vnl_vector_fixed< int, 8 >; 87 using IndexValueType = Superclass::IndexValueType; 88 using SliceIndexType = std::vector< IndexValueType >; 89 using ImageTypeRescaleValuesType = vnl_vector_fixed< double, 3 >; 90 91 using ImageTypeRescaleValuesContainerType = VectorContainer< unsigned int, ImageTypeRescaleValuesType >; 92 using ImageTypeRescaleValuesContainerTypePtr = ImageTypeRescaleValuesContainerType::Pointer; 93 using ScanningSequenceImageTypeRescaleValuesContainerType = VectorContainer< unsigned int, 94 ImageTypeRescaleValuesContainerTypePtr >; 95 using GradientBvalueType = double; 96 using GradientBvalueContainerType = VectorContainer< unsigned int, GradientBvalueType >; 97 using GradientDirectionType = vnl_vector_fixed< double, 3 >; 98 using GradientDirectionContainerType = VectorContainer< unsigned int, GradientDirectionType >; 99 using LabelTypesASLContainerType = VectorContainer< unsigned int, int >; 100 101 /*-------- This part of the interfaces deals with reading data. ----- */ 102 103 /** Determine if the file can be read with this ImageIO implementation. 104 * \author Don C. Bigler 105 * \param FileNameToRead The name of the file to test for reading. 106 * \return Returns true if this ImageIO can read the file specified. 107 */ 108 bool CanReadFile(const char *FileNameToRead) override; 109 110 /** Set the spacing and dimension information for the set filename. */ 111 void ReadImageInformation() override; 112 113 /** Reads the data from disk into the memory buffer provided. */ 114 void Read(void *buffer) override; 115 116 /*-------- This part of the interfaces deals with writing data. ----- */ 117 118 /** Determine if the file can be written with this ImageIO implementation. 119 * FileNameToWrite The name of the file to test for writing. 120 * \author Don C. Bigler 121 * \post This function will always return false (Not implemented). 122 * \return Returns true if this ImageIO can write the file specified. 123 */ CanWriteFile(const char * itkNotUsed (FileNameToWrite))124 bool CanWriteFile( const char *itkNotUsed(FileNameToWrite) ) override 125 { 126 return false; 127 } 128 129 /** Set the spacing and dimension information for the set filename. */ WriteImageInformation()130 void WriteImageInformation() override 131 { 132 return; 133 } 134 135 /** Writes the data to disk from the memory buffer provided. Make sure 136 * that the IORegions has been set properly. */ Write(const void * itkNotUsed (buffer))137 void Write( const void *itkNotUsed(buffer) ) override 138 { 139 return; 140 } 141 142 protected: 143 PhilipsRECImageIO(); 144 ~PhilipsRECImageIO() override; 145 void PrintSelf(std::ostream & os, Indent indent) const override; 146 147 private: 148 149 void SwapBytesIfNecessary(void *buffer, SizeValueType numberOfPixels); 150 151 IndexValueType GetSliceIndex(IndexValueType index) const; 152 153 SliceIndexType * m_SliceIndex; 154 ImageIOBase::ByteOrder m_MachineByteOrder; 155 }; 156 } // end namespace itk 157 158 #endif // itkPhilipsRECImageIO_h 159