Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkNRRDReader.h
Go to the documentation of this file.
1 /*=auto=========================================================================
2 
3  Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
4 
5  See COPYRIGHT.txt
6  or http://www.slicer.org/copyright/copyright.txt for details.
7 
8  Program: 3D Slicer
9  Module: $RCSfile: vtkNRRDReader.h,v $
10  Date: $Date: 2007/06/12 19:13:59 $
11  Version: $Revision: 1.3.2.1 $
12 
13 =========================================================================auto=*/
14 /*=========================================================================
15 
16  Program: Visualization Toolkit
17  Module: $RCSfile: vtkNRRDReader.h,v $
18 
19  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
20  All rights reserved.
21  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
22 
23  This software is distributed WITHOUT ANY WARRANTY; without even
24  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
25  PURPOSE. See the above copyright notice for more information.
26 
27 =========================================================================*/
28 
29 #ifndef __vtkNRRDReader_h
30 #define __vtkNRRDReader_h
31 
32 #include <string>
33 #include <map>
34 #include <iostream>
35 
36 #include "vtkTeemConfigure.h"
37 #include "vtkMedicalImageReader2.h"
38 
39 //#include "vtkDataObject.h"
40 //#include "vtkImageData.h"
41 
42 #include <vtkMatrix4x4.h>
43 #include <vtkPointData.h>
44 #include <vtkSmartPointer.h>
45 #include <vtkVersion.h>
46 
47 #include "teem/nrrd.h"
48 
52 //
54 class VTK_Teem_EXPORT vtkNRRDReader : public vtkMedicalImageReader2
55 {
56 public:
57  static vtkNRRDReader *New();
58 
59  vtkTypeMacro(vtkNRRDReader,vtkMedicalImageReader2);
60 
63  vtkMatrix4x4* GetRasToIjkMatrix();
64 
67  vtkMatrix4x4* GetMeasurementFrameMatrix();
68 
73  const char* GetHeaderKeys();
74 
78  std::vector<std::string> GetHeaderKeysVector();
79 
82  const char* GetHeaderValue(const char *key);
83 
85  const char* GetAxisLabel(unsigned int axis);
86 
88  const char* GetAxisUnit(unsigned int axis);
89 
90  virtual void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
91 
93  virtual int CanReadFile(const char* filename) VTK_OVERRIDE;
94 
97  virtual const char* GetFileExtensions() VTK_OVERRIDE
98  {
99  return ".nhdr .nrrd";
100  }
101 
104  virtual const char* GetDescriptiveName() VTK_OVERRIDE
105  {
106  return "NRRD - Nearly Raw Raster Data";
107  }
108 
109  //Description:
113  vtkGetMacro(ReadStatus,int);
114 
117  vtkSetMacro(PointDataType,int);
118  vtkGetMacro(PointDataType,int);
119 
122  vtkSetMacro(DataType,int);
123  vtkGetMacro(DataType,int);
124 
126  //Number of components
127  vtkSetMacro(NumberOfComponents,int);
128  vtkGetMacro(NumberOfComponents,int);
129 
130 
134  {
135  UseNativeOrigin = true;
136  }
137 
141  {
142  UseNativeOrigin = false;
143  }
144 
145  int NrrdToVTKScalarType( const int nrrdPixelType ) const
146  {
147  switch( nrrdPixelType )
148  {
149  default:
150  case nrrdTypeDefault:
151  return VTK_VOID;
152  break;
153  case nrrdTypeChar:
154  return VTK_CHAR;
155  break;
156  case nrrdTypeUChar:
157  return VTK_UNSIGNED_CHAR;
158  break;
159  case nrrdTypeShort:
160  return VTK_SHORT;
161  break;
162  case nrrdTypeUShort:
163  return VTK_UNSIGNED_SHORT;
164  break;
171  case nrrdTypeInt:
172  return VTK_INT;
173  break;
174  case nrrdTypeUInt:
175  return VTK_UNSIGNED_INT;
176  break;
177  case nrrdTypeFloat:
178  return VTK_FLOAT;
179  break;
180  case nrrdTypeDouble:
181  return VTK_DOUBLE;
182  break;
183  case nrrdTypeBlock:
184  return -1;
185  break;
186  }
187  }
188 
189  int VTKToNrrdPixelType( const int vtkPixelType ) const
190  {
191  switch( vtkPixelType )
192  {
193  default:
194  case VTK_VOID:
195  return nrrdTypeDefault;
196  break;
197  case VTK_CHAR:
198  return nrrdTypeChar;
199  break;
200  case VTK_UNSIGNED_CHAR:
201  return nrrdTypeUChar;
202  break;
203  case VTK_SHORT:
204  return nrrdTypeShort;
205  break;
206  case VTK_UNSIGNED_SHORT:
207  return nrrdTypeUShort;
208  break;
215  case VTK_INT:
216  return nrrdTypeInt;
217  break;
218  case VTK_UNSIGNED_INT:
219  return nrrdTypeUInt;
220  break;
221  case VTK_FLOAT:
222  return nrrdTypeFloat;
223  break;
224  case VTK_DOUBLE:
225  return nrrdTypeDouble;
226  break;
227  }
228  }
229 virtual vtkImageData * AllocateOutputData(vtkDataObject *out, vtkInformation* outInfo) VTK_OVERRIDE;
230 virtual void AllocateOutputData(vtkImageData *out, vtkInformation* outInfo, int *uExtent) VTK_OVERRIDE
231  { Superclass::AllocateOutputData(out, outInfo, uExtent); }
232 void AllocatePointData(vtkImageData *out, vtkInformation* outInfo);
233 
234 protected:
235  vtkNRRDReader();
236  ~vtkNRRDReader();
237 
238  static bool GetPointType(Nrrd* nrrdTemp, int& pointDataType, int &numOfComponents);
239 
240  vtkSmartPointer<vtkMatrix4x4> RasToIjkMatrix;
241  vtkSmartPointer<vtkMatrix4x4> MeasurementFrameMatrix;
242  vtkSmartPointer<vtkMatrix4x4> NRRDWorldToRasMatrix;
243 
244  std::string CurrentFileName;
245 
246  Nrrd *nrrd;
247 
249 
251  int DataType;
254 
255  std::map <std::string, std::string> HeaderKeyValue;
256  std::string HeaderKeys; // buffer for returning key list
257 
258  std::map<unsigned int, std::string> AxisLabels;
259  std::map<unsigned int, std::string> AxisUnits;
260 
261  virtual void ExecuteInformation() VTK_OVERRIDE;
262  virtual void ExecuteDataWithInformation(vtkDataObject *output, vtkInformation* outInfo) VTK_OVERRIDE;
263 
264  int tenSpaceDirectionReduce(Nrrd *nout, const Nrrd *nin, double SD[9]);
265 
266 private:
267  vtkNRRDReader(const vtkNRRDReader&);
268  void operator=(const vtkNRRDReader&);
269 
270 };
271 
272 #endif
Reads Nearly Raw Raster Data files.
Definition: vtkNRRDReader.h:54
std::string HeaderKeys
std::map< std::string, std::string > HeaderKeyValue
void SetUseNativeOriginOff()
Use image center as origin.
int NrrdToVTKScalarType(const int nrrdPixelType) const
std::map< unsigned int, std::string > AxisLabels
std::map< unsigned int, std::string > AxisUnits
std::string CurrentFileName
virtual void AllocateOutputData(vtkImageData *out, vtkInformation *outInfo, int *uExtent) VTK_OVERRIDE
vtkSmartPointer< vtkMatrix4x4 > NRRDWorldToRasMatrix
vtkSmartPointer< vtkMatrix4x4 > MeasurementFrameMatrix
int VTKToNrrdPixelType(const int vtkPixelType) const
void SetUseNativeOriginOn()
Use image origin from the file.
virtual const char * GetFileExtensions() VTK_OVERRIDE
Valid extentsions.
Definition: vtkNRRDReader.h:97
virtual const char * GetDescriptiveName() VTK_OVERRIDE
A descriptive name for this format.
vtkSmartPointer< vtkMatrix4x4 > RasToIjkMatrix