vtkMINCImageAttributes.h 12.2 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkMINCImageAttributes.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
/**
 * @class   vtkMINCImageAttributes
 * @brief   A container for a MINC image header.
 *
 * This class provides methods to access all of the information
 * contained in the MINC header.  If you read a MINC file into
 * VTK and then write it out again, you can use
 * writer->SetImageAttributes(reader->GetImageAttributes) to
 * ensure that all of the medical information contained in the
Kunda's avatar
Kunda committed
57
 * file is transferred from the reader to the writer.  If you
58 59 60 61 62 63 64 65 66
 * want to change any of the header information, you must
 * use ShallowCopy to make a copy of the reader's attributes
 * and then modify only the copy.
 * @sa
 * vtkMINCImageReader vtkMINCImageWriter
 * @par Thanks:
 * Thanks to David Gobbi for writing this class and Atamai Inc. for
 * contributing it to VTK.
*/
67

68 69
#ifndef vtkMINCImageAttributes_h
#define vtkMINCImageAttributes_h
70

71
#include "vtkIOMINCModule.h" // For export macro
72 73 74 75 76 77 78 79 80 81 82
#include "vtkObject.h"

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

// A special class that holds the attributes
class vtkMINCImageAttributeMap;

83
class VTKIOMINC_EXPORT vtkMINCImageAttributes : public vtkObject
84 85
{
public:
86
  vtkTypeMacro(vtkMINCImageAttributes,vtkObject);
87 88

  static vtkMINCImageAttributes *New();
89
  void PrintSelf(ostream& os, vtkIndent indent) override;
90

91 92 93 94
  /**
   * Reset all the attributes in preparation for loading
   * new information.
   */
95
  virtual void Reset();
96

97 98 99 100 101 102
  //@{
  /**
   * Get the name of the image, not including the path or
   * the extension.  This is only needed for printing the
   * header and there is usually no need to set it.
   */
103 104
  vtkSetStringMacro(Name);
  vtkGetStringMacro(Name);
105 106 107 108 109 110 111 112 113
  //@}

  //@{
  /**
   * Get the image data type, as stored on disk.  This information
   * is useful if the file was converted to floating-point when it
   * was loaded.  When writing a file from float or double image data,
   * you can use this method to prescribe the output type.
   */
114 115
  vtkSetMacro(DataType, int);
  vtkGetMacro(DataType, int);
116 117 118 119 120 121 122 123 124
  //@}

  //@{
  /**
   * Add the names of up to five dimensions. The ordering of these
   * dimensions will determine the dimension order of the file.  If
   * no DimensionNames are set, the writer will set the dimension
   * order of the file to be the same as the dimension order in memory.
   */
125 126 127
  virtual void AddDimension(const char *dimension) {
    this->AddDimension(dimension, 0); };
  virtual void AddDimension(const char *dimension, vtkIdType length);
128 129 130 131 132 133 134 135 136
  //@}

  /**
   * Get the dimension names.  The dimension names are same order
   * as written in the file, starting with the slowest-varying
   * dimension.  Use this method to get the array if you need to
   * change "space" dimensions to "frequency" after performing a
   * Fourier transform.
   */
137 138 139
  virtual vtkStringArray *GetDimensionNames() {
    return this->DimensionNames; };

140 141 142 143 144
  /**
   * Get the lengths of all the dimensions.  The dimension lengths
   * are informative, the vtkMINCImageWriter does not look at these values
   * but instead uses the dimension sizes of its input.
   */
145 146 147
  virtual vtkIdTypeArray *GetDimensionLengths() {
    return this->DimensionLengths; };

148 149 150
  /**
   * Get the names of all the variables.
   */
151 152 153
  virtual vtkStringArray *GetVariableNames() {
    return this->VariableNames; };

154 155 156 157
  /**
   * List the attribute names for a variable.  Set the variable
   * to the empty string to get a list of the global attributes.
   */
158 159
  virtual vtkStringArray *GetAttributeNames(const char *variable);

160 161 162 163 164 165
  //@{
  /**
   * Get the image min and max arrays. These are set by the reader,
   * but they aren't used by the writer except to compute the full
   * real data range of the original file.
   */
166 167 168 169
  virtual void SetImageMin(vtkDoubleArray *imageMin);
  virtual void SetImageMax(vtkDoubleArray *imageMax);
  virtual vtkDoubleArray *GetImageMin() { return this->ImageMin; };
  virtual vtkDoubleArray *GetImageMax() { return this->ImageMax; };
170
  //@}
171

172 173 174 175
  //@{
  /**
   * Get the number of ImageMinMax dimensions.
   */
176 177
  vtkGetMacro(NumberOfImageMinMaxDimensions, int);
  vtkSetMacro(NumberOfImageMinMaxDimensions, int);
178
  //@}
179

180 181 182
  /**
   * Check to see if a particular attribute exists.
   */
183 184
  virtual int HasAttribute(const char *variable, const char *attribute);

185 186 187 188 189
  //@{
  /**
   * Set attribute values for a variable as a vtkDataArray.
   * Set the variable to the empty string to access global attributes.
   */
190 191 192 193 194
  virtual void SetAttributeValueAsArray(const char *variable,
                                        const char *attribute,
                                        vtkDataArray *array);
  virtual vtkDataArray *GetAttributeValueAsArray(const char *variable,
                                                 const char *attribute);
195 196 197 198 199 200 201 202 203
  //@}

  //@{
  /**
   * Set an attribute value as a string.  Set the variable
   * to the empty string to access global attributes.
   * If you specify a variable that does not exist, it will be
   * created.
   */
204 205 206 207 208
  virtual void SetAttributeValueAsString(const char *variable,
                                         const char *attribute,
                                         const char *value);
  virtual const char *GetAttributeValueAsString(const char *variable,
                                                const char *attribute);
209 210 211 212 213 214 215 216 217
  //@}

  //@{
  /**
   * Set an attribute value as an int. Set the variable
   * to the empty string to access global attributes.
   * If you specify a variable that does not exist, it will be
   * created.
   */
218 219 220 221 222
  virtual void SetAttributeValueAsInt(const char *variable,
                                      const char *attribute,
                                      int value);
  virtual int GetAttributeValueAsInt(const char *variable,
                                     const char *attribute);
223 224 225 226 227 228 229 230 231
  //@}

  //@{
  /**
   * Set an attribute value as a double.  Set the variable
   * to the empty string to access global attributes.
   * If you specify a variable that does not exist, it will be
   * created.
   */
232 233 234 235 236
  virtual void SetAttributeValueAsDouble(const char *variable,
                                         const char *attribute,
                                         double value);
  virtual double GetAttributeValueAsDouble(const char *variable,
                                           const char *attribute);
237 238 239 240 241 242 243 244 245 246 247 248
  //@}


  /**
   * Validate a particular attribute.  This involves checking
   * that the attribute is a MINC standard attribute, and checking
   * whether it can be set (as opposed to being set automatically
   * from the image information).  The return values is 0 if
   * the attribute is set automatically and therefore should not
   * be copied from here, 1 if this attribute is valid and should
   * be set, and 2 if the attribute is non-standard.
   */
249 250 251 252
  virtual int ValidateAttribute(const char *varname,
                                const char *attname,
                                vtkDataArray *array);

253 254 255 256 257
  //@{
  /**
   * Set this to Off if you do not want to automatically validate
   * every attribute that is set.
   */
258 259 260
  vtkSetMacro(ValidateAttributes, vtkTypeBool);
  vtkBooleanMacro(ValidateAttributes, vtkTypeBool);
  vtkGetMacro(ValidateAttributes, vtkTypeBool);
261 262 263 264 265 266 267 268 269 270
  //@}

  /**
   * Do a shallow copy.  This will copy all the attributes
   * from the source.  It is much more efficient than a DeepCopy
   * would be, since it only copies pointers to the attribute values
   * instead of copying the arrays themselves.  You must use this
   * method to make a copy if you want to modify any MINC attributes
   * from a MINCReader before you pass them to a MINCWriter.
   */
271 272
  virtual void ShallowCopy(vtkMINCImageAttributes *source);

273 274 275 276
  /**
   * Find the valid range of the data from the information stored
   * in the attributes.
   */
277 278
  virtual void FindValidRange(double range[2]);

279 280 281 282
  /**
   * Find the image range of the data from the information stored
   * in the attributes.
   */
283 284
  virtual void FindImageRange(double range[2]);

285 286 287 288 289
  //@{
  /**
   * A diagnostic function.  Print the header of the file in
   * the same format as ncdump or mincheader.
   */
290 291
  virtual void PrintFileHeader();
  virtual void PrintFileHeader(ostream &os);
292
  //@}
293 294 295

protected:
  vtkMINCImageAttributes();
296
  ~vtkMINCImageAttributes() override;
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331

  const char *ConvertDataArrayToString(vtkDataArray *array);

  virtual int ValidateGlobalAttribute(const char *attrib,
                                      vtkDataArray *array);
  virtual int ValidateGeneralAttribute(const char *varname,
                                       const char *attname,
                                       vtkDataArray *array);
  virtual int ValidateDimensionAttribute(const char *varname,
                                         const char *attname,
                                         vtkDataArray *array);
  virtual int ValidateImageAttribute(const char *varname,
                                     const char *attname,
                                     vtkDataArray *array);
  virtual int ValidateImageMinMaxAttribute(const char *varname,
                                           const char *attname,
                                           vtkDataArray *array);
  virtual int ValidatePatientAttribute(const char *varname,
                                       const char *attname,
                                       vtkDataArray *array);
  virtual int ValidateStudyAttribute(const char *varname,
                                     const char *attname,
                                     vtkDataArray *array);
  virtual int ValidateAcquisitionAttribute(const char *varname,
                                           const char *attname,
                                           vtkDataArray *array);

  vtkStringArray *DimensionNames;
  vtkIdTypeArray *DimensionLengths;

  vtkStringArray *VariableNames;
  vtkMINCImageAttributeMap *AttributeNames;
  vtkMINCImageAttributeMap *AttributeValues;

  vtkStringArray *StringStore;
332

333 334 335 336 337 338 339
  vtkDoubleArray *ImageMin;
  vtkDoubleArray *ImageMax;
  int NumberOfImageMinMaxDimensions;

  int DataType;
  char *Name;

340
  vtkTypeBool ValidateAttributes;
341

342
private:
343 344
  vtkMINCImageAttributes(const vtkMINCImageAttributes&) = delete;
  void operator=(const vtkMINCImageAttributes&) = delete;
345 346 347

};

348
#endif /* vtkMINCImageAttributes_h */