Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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//
54class VTK_Teem_EXPORT vtkTeemNRRDReader : public vtkMedicalImageReader2
55{
56public:
58
59 vtkTypeMacro(vtkTeemNRRDReader, vtkMedicalImageReader2);
60
63 vtkMatrix4x4* GetRasToIjkMatrix();
64
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 { return ".nhdr .nrrd"; }
103
106 const char* GetDescriptiveName() override { return "NRRD - Nearly Raw Raster Data"; }
107
108 // Description:
112 vtkGetMacro(ReadStatus, int);
113
116 vtkSetMacro(PointDataType, int);
117 vtkGetMacro(PointDataType, int);
118
121 vtkSetMacro(DataType, int);
122 vtkGetMacro(DataType, int);
123
125 // Number of components
126 vtkSetMacro(NumberOfComponents, int);
127 vtkGetMacro(NumberOfComponents, int);
128
132
136
142 vtkSetMacro(DataArrayName, std::string);
143 vtkGetMacro(DataArrayName, std::string);
144
145 int NrrdToVTKScalarType(const int nrrdPixelType) const
146 {
147 switch (nrrdPixelType)
148 {
149 default:
150 case nrrdTypeDefault: return VTK_VOID; break;
151 case nrrdTypeChar: return VTK_CHAR; break;
152 case nrrdTypeUChar: return VTK_UNSIGNED_CHAR; break;
153 case nrrdTypeShort: return VTK_SHORT; break;
154 case nrrdTypeUShort:
155 return VTK_UNSIGNED_SHORT;
156 break;
163 case nrrdTypeInt: return VTK_INT; break;
164 case nrrdTypeUInt: return VTK_UNSIGNED_INT; break;
165 case nrrdTypeFloat: return VTK_FLOAT; break;
166 case nrrdTypeDouble: return VTK_DOUBLE; break;
167 case nrrdTypeBlock: return -1; break;
168 }
169 }
170
171 int VTKToNrrdPixelType(const int vtkPixelType) const
172 {
173 switch (vtkPixelType)
174 {
175 default:
176 case VTK_VOID: return nrrdTypeDefault; break;
177 case VTK_CHAR: return nrrdTypeChar; break;
178 case VTK_UNSIGNED_CHAR: return nrrdTypeUChar; break;
179 case VTK_SHORT: return nrrdTypeShort; break;
180 case VTK_UNSIGNED_SHORT:
181 return nrrdTypeUShort;
182 break;
189 case VTK_INT: return nrrdTypeInt; break;
190 case VTK_UNSIGNED_INT: return nrrdTypeUInt; break;
191 case VTK_FLOAT: return nrrdTypeFloat; break;
192 case VTK_DOUBLE: return nrrdTypeDouble; break;
193 }
194 }
195 vtkImageData* AllocateOutputData(vtkDataObject* out, vtkInformation* outInfo) override;
196 void AllocateOutputData(vtkImageData* out, vtkInformation* outInfo, int* uExtent) override { Superclass::AllocateOutputData(out, outInfo, uExtent); }
197 void AllocatePointData(vtkImageData* out, vtkInformation* outInfo);
198
199protected:
202
203 static bool GetPointType(Nrrd* nrrdTemp, int& pointDataType, int& numOfComponents);
204
205 vtkSmartPointer<vtkMatrix4x4> RasToIjkMatrix;
206 vtkSmartPointer<vtkMatrix4x4> MeasurementFrameMatrix;
207 vtkSmartPointer<vtkMatrix4x4> NRRDWorldToRasMatrix;
208
209 std::string CurrentFileName;
210
211 Nrrd* nrrd;
212
214
219 std::string DataArrayName;
220
221 std::map<std::string, std::string> HeaderKeyValue;
222 std::string HeaderKeys; // buffer for returning key list
223
224 std::map<unsigned int, std::string> AxisLabels;
225 std::map<unsigned int, std::string> AxisUnits;
226
227 void ExecuteInformation() override;
228 void ExecuteDataWithInformation(vtkDataObject* output, vtkInformation* outInfo) override;
229
230 int tenSpaceDirectionReduce(Nrrd* nout, const Nrrd* nin, double SD[9]);
231
232private:
233 vtkTeemNRRDReader(const vtkTeemNRRDReader&) = delete;
234 void operator=(const vtkTeemNRRDReader&) = delete;
235};
236
237#endif
const char * GetAxisLabel(unsigned int axis)
Get label for specified axis.
void SetUseNativeOriginOff()
Use image center as origin.
static vtkTeemNRRDReader * New()
vtkSmartPointer< vtkMatrix4x4 > MeasurementFrameMatrix
const char * GetAxisUnit(unsigned int axis)
Get unit for specified axis.
const std::map< std::string, std::string > GetHeaderKeysMap()
int tenSpaceDirectionReduce(Nrrd *nout, const Nrrd *nin, double SD[9])
void ExecuteDataWithInformation(vtkDataObject *output, vtkInformation *outInfo) override
vtkSmartPointer< vtkMatrix4x4 > RasToIjkMatrix
vtkImageData * AllocateOutputData(vtkDataObject *out, vtkInformation *outInfo) override
int VTKToNrrdPixelType(const int vtkPixelType) const
vtkMatrix4x4 * GetMeasurementFrameMatrix()
Returns the measurement frame matrix used for tensor valued data.
int NrrdToVTKScalarType(const int nrrdPixelType) const
void PrintSelf(ostream &os, vtkIndent indent) override
static bool GetPointType(Nrrd *nrrdTemp, int &pointDataType, int &numOfComponents)
std::string CurrentFileName
void AllocatePointData(vtkImageData *out, vtkInformation *outInfo)
void AllocateOutputData(vtkImageData *out, vtkInformation *outInfo, int *uExtent) override
int CanReadFile(const char *filename) override
is the given file name a NRRD file?
const char * GetDescriptiveName() override
A descriptive name for this format.
const std::vector< std::string > GetHeaderKeysVector()
vtkSmartPointer< vtkMatrix4x4 > NRRDWorldToRasMatrix
vtkMatrix4x4 * GetRasToIjkMatrix()
Returns a IJK to RAS transformation matrix.
std::map< std::string, std::string > HeaderKeyValue
std::map< unsigned int, std::string > AxisLabels
const char * GetFileExtensions() override
Valid extensions.
void SetUseNativeOriginOn()
Use image origin from the file.
const char * GetHeaderValue(const char *key)
Get a value given a key in the header.
~vtkTeemNRRDReader() override
std::map< unsigned int, std::string > AxisUnits
void ExecuteInformation() override
const char * GetHeaderKeys()