Slicer  4.10
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 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 __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  virtual void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
96 
98  virtual int CanReadFile(const char* filename) VTK_OVERRIDE;
99 
102  virtual const char* GetFileExtensions() VTK_OVERRIDE
103  {
104  return ".nhdr .nrrd";
105  }
106 
109  virtual const char* GetDescriptiveName() VTK_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 
150  int NrrdToVTKScalarType( const int nrrdPixelType ) const
151  {
152  switch( nrrdPixelType )
153  {
154  default:
155  case nrrdTypeDefault:
156  return VTK_VOID;
157  break;
158  case nrrdTypeChar:
159  return VTK_CHAR;
160  break;
161  case nrrdTypeUChar:
162  return VTK_UNSIGNED_CHAR;
163  break;
164  case nrrdTypeShort:
165  return VTK_SHORT;
166  break;
167  case nrrdTypeUShort:
168  return VTK_UNSIGNED_SHORT;
169  break;
176  case nrrdTypeInt:
177  return VTK_INT;
178  break;
179  case nrrdTypeUInt:
180  return VTK_UNSIGNED_INT;
181  break;
182  case nrrdTypeFloat:
183  return VTK_FLOAT;
184  break;
185  case nrrdTypeDouble:
186  return VTK_DOUBLE;
187  break;
188  case nrrdTypeBlock:
189  return -1;
190  break;
191  }
192  }
193 
194  int VTKToNrrdPixelType( const int vtkPixelType ) const
195  {
196  switch( vtkPixelType )
197  {
198  default:
199  case VTK_VOID:
200  return nrrdTypeDefault;
201  break;
202  case VTK_CHAR:
203  return nrrdTypeChar;
204  break;
205  case VTK_UNSIGNED_CHAR:
206  return nrrdTypeUChar;
207  break;
208  case VTK_SHORT:
209  return nrrdTypeShort;
210  break;
211  case VTK_UNSIGNED_SHORT:
212  return nrrdTypeUShort;
213  break;
220  case VTK_INT:
221  return nrrdTypeInt;
222  break;
223  case VTK_UNSIGNED_INT:
224  return nrrdTypeUInt;
225  break;
226  case VTK_FLOAT:
227  return nrrdTypeFloat;
228  break;
229  case VTK_DOUBLE:
230  return nrrdTypeDouble;
231  break;
232  }
233  }
234 virtual vtkImageData * AllocateOutputData(vtkDataObject *out, vtkInformation* outInfo) VTK_OVERRIDE;
235 virtual void AllocateOutputData(vtkImageData *out, vtkInformation* outInfo, int *uExtent) VTK_OVERRIDE
236  { Superclass::AllocateOutputData(out, outInfo, uExtent); }
237 void AllocatePointData(vtkImageData *out, vtkInformation* outInfo);
238 
239 protected:
242 
243  static bool GetPointType(Nrrd* nrrdTemp, int& pointDataType, int &numOfComponents);
244 
245  vtkSmartPointer<vtkMatrix4x4> RasToIjkMatrix;
246  vtkSmartPointer<vtkMatrix4x4> MeasurementFrameMatrix;
247  vtkSmartPointer<vtkMatrix4x4> NRRDWorldToRasMatrix;
248 
249  std::string CurrentFileName;
250 
251  Nrrd *nrrd;
252 
254 
256  int DataType;
259 
260  std::map <std::string, std::string> HeaderKeyValue;
261  std::string HeaderKeys; // buffer for returning key list
262 
263  std::map<unsigned int, std::string> AxisLabels;
264  std::map<unsigned int, std::string> AxisUnits;
265 
266  virtual void ExecuteInformation() VTK_OVERRIDE;
267  virtual void ExecuteDataWithInformation(vtkDataObject *output, vtkInformation* outInfo) VTK_OVERRIDE;
268 
269  int tenSpaceDirectionReduce(Nrrd *nout, const Nrrd *nin, double SD[9]);
270 
271 private:
273  void operator=(const vtkTeemNRRDReader&);
274 
275 };
276 
277 #endif
vtkSmartPointer< vtkMatrix4x4 > NRRDWorldToRasMatrix
virtual const char * GetFileExtensions() VTK_OVERRIDE
Valid extentsions
virtual const char * GetDescriptiveName() VTK_OVERRIDE
A descriptive name for this format
vtkSmartPointer< vtkMatrix4x4 > MeasurementFrameMatrix
std::string CurrentFileName
std::map< std::string, std::string > HeaderKeyValue
std::map< unsigned int, std::string > AxisLabels
virtual void AllocateOutputData(vtkImageData *out, vtkInformation *outInfo, int *uExtent) VTK_OVERRIDE
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