Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkTeemNRRDReader.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: vtkTeemNRRDReader.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: vtkTeemNRRDReader.h,v $
18 
19  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
20  All rights reserved.
21  See Copyright.txt or https://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 __vtkTeemNRRDReader_h
30 #define __vtkTeemNRRDReader_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 vtkTeemNRRDReader : public vtkMedicalImageReader2
55 {
56 public:
57  static vtkTeemNRRDReader *New();
58 
59  vtkTypeMacro(vtkTeemNRRDReader,vtkMedicalImageReader2);
60 
63  vtkMatrix4x4* GetRasToIjkMatrix();
64 
67  vtkMatrix4x4* GetMeasurementFrameMatrix();
68 
73  const char* GetHeaderKeys();
74 
78  const std::vector<std::string> GetHeaderKeysVector();
79 
83  const std::map<std::string, std::string> GetHeaderKeysMap();
84 
87  const char* GetHeaderValue(const char *key);
88 
90  const char* GetAxisLabel(unsigned int axis);
91 
93  const char* GetAxisUnit(unsigned int axis);
94 
95  void PrintSelf(ostream& os, vtkIndent indent) override;
96 
98  int CanReadFile(const char* filename) override;
99 
102  const char* GetFileExtensions() override
103  {
104  return ".nhdr .nrrd";
105  }
106 
109  const char* GetDescriptiveName() override
110  {
111  return "NRRD - Nearly Raw Raster Data";
112  }
113 
114  //Description:
118  vtkGetMacro(ReadStatus,int);
119 
122  vtkSetMacro(PointDataType,int);
123  vtkGetMacro(PointDataType,int);
124 
127  vtkSetMacro(DataType,int);
128  vtkGetMacro(DataType,int);
129 
131  //Number of components
132  vtkSetMacro(NumberOfComponents,int);
133  vtkGetMacro(NumberOfComponents,int);
134 
135 
139  {
140  UseNativeOrigin = true;
141  }
142 
146  {
147  UseNativeOrigin = false;
148  }
149 
155  vtkSetMacro(DataArrayName, std::string);
156  vtkGetMacro(DataArrayName, std::string);
157 
158  int NrrdToVTKScalarType( const int nrrdPixelType ) const
159  {
160  switch( nrrdPixelType )
161  {
162  default:
163  case nrrdTypeDefault:
164  return VTK_VOID;
165  break;
166  case nrrdTypeChar:
167  return VTK_CHAR;
168  break;
169  case nrrdTypeUChar:
170  return VTK_UNSIGNED_CHAR;
171  break;
172  case nrrdTypeShort:
173  return VTK_SHORT;
174  break;
175  case nrrdTypeUShort:
176  return VTK_UNSIGNED_SHORT;
177  break;
184  case nrrdTypeInt:
185  return VTK_INT;
186  break;
187  case nrrdTypeUInt:
188  return VTK_UNSIGNED_INT;
189  break;
190  case nrrdTypeFloat:
191  return VTK_FLOAT;
192  break;
193  case nrrdTypeDouble:
194  return VTK_DOUBLE;
195  break;
196  case nrrdTypeBlock:
197  return -1;
198  break;
199  }
200  }
201 
202  int VTKToNrrdPixelType( const int vtkPixelType ) const
203  {
204  switch( vtkPixelType )
205  {
206  default:
207  case VTK_VOID:
208  return nrrdTypeDefault;
209  break;
210  case VTK_CHAR:
211  return nrrdTypeChar;
212  break;
213  case VTK_UNSIGNED_CHAR:
214  return nrrdTypeUChar;
215  break;
216  case VTK_SHORT:
217  return nrrdTypeShort;
218  break;
219  case VTK_UNSIGNED_SHORT:
220  return nrrdTypeUShort;
221  break;
228  case VTK_INT:
229  return nrrdTypeInt;
230  break;
231  case VTK_UNSIGNED_INT:
232  return nrrdTypeUInt;
233  break;
234  case VTK_FLOAT:
235  return nrrdTypeFloat;
236  break;
237  case VTK_DOUBLE:
238  return nrrdTypeDouble;
239  break;
240  }
241  }
242 vtkImageData * AllocateOutputData(vtkDataObject *out, vtkInformation* outInfo) override;
243 void AllocateOutputData(vtkImageData *out, vtkInformation* outInfo, int *uExtent) override
244  { Superclass::AllocateOutputData(out, outInfo, uExtent); }
245 void AllocatePointData(vtkImageData *out, vtkInformation* outInfo);
246 
247 protected:
249  ~vtkTeemNRRDReader() override;
250 
251  static bool GetPointType(Nrrd* nrrdTemp, int& pointDataType, int &numOfComponents);
252 
253  vtkSmartPointer<vtkMatrix4x4> RasToIjkMatrix;
254  vtkSmartPointer<vtkMatrix4x4> MeasurementFrameMatrix;
255  vtkSmartPointer<vtkMatrix4x4> NRRDWorldToRasMatrix;
256 
257  std::string CurrentFileName;
258 
259  Nrrd *nrrd;
260 
262 
264  int DataType;
267  std::string DataArrayName;
268 
269  std::map <std::string, std::string> HeaderKeyValue;
270  std::string HeaderKeys; // buffer for returning key list
271 
272  std::map<unsigned int, std::string> AxisLabels;
273  std::map<unsigned int, std::string> AxisUnits;
274 
275  void ExecuteInformation() override;
276  void ExecuteDataWithInformation(vtkDataObject *output, vtkInformation* outInfo) override;
277 
278  int tenSpaceDirectionReduce(Nrrd *nout, const Nrrd *nin, double SD[9]);
279 
280 private:
281  vtkTeemNRRDReader(const vtkTeemNRRDReader&) = delete;
282  void operator=(const vtkTeemNRRDReader&) = delete;
283 
284 };
285 
286 #endif
const char * GetFileExtensions() override
Valid extentsions
vtkSmartPointer< vtkMatrix4x4 > NRRDWorldToRasMatrix
vtkSmartPointer< vtkMatrix4x4 > MeasurementFrameMatrix
std::string CurrentFileName
void AllocateOutputData(vtkImageData *out, vtkInformation *outInfo, int *uExtent) override
std::map< std::string, std::string > HeaderKeyValue
std::map< unsigned int, std::string > AxisLabels
int NrrdToVTKScalarType(const int nrrdPixelType) const
std::map< unsigned int, std::string > AxisUnits
vtkSmartPointer< vtkMatrix4x4 > RasToIjkMatrix
Reads Nearly Raw Raster Data files.
void SetUseNativeOriginOff()
Use image center as origin
void SetUseNativeOriginOn()
Use image origin from the file
int VTKToNrrdPixelType(const int vtkPixelType) const
std::string DataArrayName
const char * GetDescriptiveName() override
A descriptive name for this format