vtkMINCImageReader.h 6.68 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkMINCImageReader.h

6 7 8 9 10 11 12 13 14 15 16
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*=========================================================================

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
Copyright (c) 2006 Atamai, Inc.

Use, modification and redistribution of the software, in source or
binary forms, are permitted provided that the following terms and
conditions are met:

1) Redistribution of the source code, in verbatim or modified
   form, must retain the above copyright notice, this license,
   the following disclaimer, and any notices that refer to this
   license and/or the following disclaimer.

2) Redistribution in binary form must include the above copyright
   notice, a copy of this license and the following disclaimer
   in the documentation or with other materials provided with the
   distribution.

3) Modified copies of the source code must be clearly marked as such,
   and must not be misrepresented as verbatim copies of the source code.

THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS"
WITHOUT EXPRESSED OR IMPLIED WARRANTY INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR OTHER PARTY WHO MAY
MODIFY AND/OR REDISTRIBUTE THE SOFTWARE UNDER THE TERMS OF THIS LICENSE
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BECOMING INACCURATE
OR LOSS OF PROFIT OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF
THE USE OR INABILITY TO USE THE SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

=========================================================================*/
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/**
 * @class   vtkMINCImageReader
 * @brief   A reader for MINC files.
 *
 * MINC is a NetCDF-based medical image file format that was developed
 * at the Montreal Neurological Institute in 1992.
 * This class will read a MINC file into VTK, rearranging the data to
 * match the VTK x, y, and z dimensions, and optionally rescaling
 * real-valued data to VTK_FLOAT if RescaleRealValuesOn() is set.
 * If RescaleRealValues is off, then the data will be stored in its
 * original data type and the GetRescaleSlope(), GetRescaleIntercept()
 * method can be used to retrieve global rescaling parameters.
 * If the original file had a time dimension, the SetTimeStep() method
 * can be used to specify a time step to read.
 * All of the original header information can be accessed though the
 * GetImageAttributes() method.
 * @sa
 * vtkMINCImageWriter vtkMINCImageAttributes
 * @par Thanks:
 * Thanks to David Gobbi for writing this class and Atamai Inc. for
 * contributing it to VTK.
*/
70

71 72
#ifndef vtkMINCImageReader_h
#define vtkMINCImageReader_h
73

74
#include "vtkIOMINCModule.h" // For export macro
75 76 77 78 79 80 81 82
#include "vtkImageReader2.h"

class vtkStringArray;
class vtkIdTypeArray;
class vtkDoubleArray;
class vtkMatrix4x4;

// A special class that holds the attributes
83
class vtkMINCImageAttributes;
84

85
class VTKIOMINC_EXPORT vtkMINCImageReader : public vtkImageReader2
86 87
{
public:
88
  vtkTypeMacro(vtkMINCImageReader,vtkImageReader2);
89 90

  static vtkMINCImageReader *New();
91
  void PrintSelf(ostream& os, vtkIndent indent) override;
92

93 94 95
  /**
   * Set the file name.
   */
96
  void SetFileName(const char *name) override;
97

98 99 100
  /**
   * Get the entension for this file format.
   */
101
  const char* GetFileExtensions() override {
102 103
    return ".mnc"; }

104 105 106
  /**
   * Get the name of this file format.
   */
107
  const char* GetDescriptiveName() override {
108 109
    return "MINC"; }

110 111 112
  /**
   * Test whether the specified file can be read.
   */
113
  int CanReadFile(const char* name) override;
114

115 116 117 118 119
  /**
   * Get a matrix that describes the orientation of the data.
   * The three columns of the matrix are the direction cosines
   * for the x, y and z dimensions respectively.
   */
120
  virtual vtkMatrix4x4 *GetDirectionCosines();
121

122 123 124 125 126 127
  //@{
  /**
   * Get the slope and intercept for rescaling the scalar values
   * to real data values.  To convert scalar values to real values,
   * use the equation y = x*RescaleSlope + RescaleIntercept.
   */
128 129
  virtual double GetRescaleSlope();
  virtual double GetRescaleIntercept();
130 131 132 133 134 135 136 137
  //@}

  //@{
  /**
   * Rescale real data values to float.  If this is done, the
   * RescaleSlope and RescaleIntercept will be set to 1 and 0
   * respectively.  This is off by default.
   */
138 139 140
  vtkSetMacro(RescaleRealValues, vtkTypeBool);
  vtkBooleanMacro(RescaleRealValues, vtkTypeBool);
  vtkGetMacro(RescaleRealValues, vtkTypeBool);
141 142 143 144 145 146 147 148 149
  //@}

  //@{
  /**
   * Get the scalar range of the output from the information in
   * the file header.  This is more efficient that computing the
   * scalar range, but in some cases the MINC file stores an
   * incorrect valid_range and the DataRange will be incorrect.
   */
Ben Boeckel's avatar
Ben Boeckel committed
150
  virtual double *GetDataRange() VTK_SIZEHINT(2);
151 152
  virtual void GetDataRange(double range[2]) {
    double *r = this->GetDataRange();
153
    range[0] = r[0]; range[1] = r[1]; };
154
  //@}
155

156 157 158
  /**
   * Get the number of time steps in the file.
   */
159
  virtual int GetNumberOfTimeSteps();
160

161 162 163 164
  //@{
  /**
   * Set the time step to read.
   */
165 166
  vtkSetMacro(TimeStep, int);
  vtkGetMacro(TimeStep, int);
167
  //@}
168

169 170 171 172
  /**
   * Get the image attributes, which contain patient information and
   * other useful metadata.
   */
173
  virtual vtkMINCImageAttributes *GetImageAttributes();
174 175 176

protected:
  vtkMINCImageReader();
177
  ~vtkMINCImageReader() override;
178 179 180

  int MINCImageType;
  int MINCImageTypeSigned;
181 182 183

  double ValidRange[2];
  double ImageRange[2];
184
  double DataRange[2];
185

186 187
  int NumberOfTimeSteps;
  int TimeStep;
188
  vtkMatrix4x4 *DirectionCosines;
189 190
  double RescaleSlope;
  double RescaleIntercept;
191
  vtkTypeBool RescaleRealValues;
192
  vtkMINCImageAttributes *ImageAttributes;
193 194 195 196 197 198 199

  int FileNameHasChanged;

  virtual int OpenNetCDFFile(const char *filename, int& ncid);
  virtual int CloseNetCDFFile(int ncid);
  virtual int IndexFromDimensionName(const char *dimName);
  virtual int ReadMINCFileAttributes();
200
  virtual void FindRangeAndRescaleValues();
201 202
  static int ConvertMINCTypeToVTKType(int minctype, int mincsigned);

203 204
  void ExecuteInformation() override;
  void ExecuteDataWithInformation(vtkDataObject *out, vtkInformation *outInfo) override;
205 206

private:
207 208
  vtkMINCImageReader(const vtkMINCImageReader&) = delete;
  void operator=(const vtkMINCImageReader&) = delete;
209 210 211 212

};

#endif