vtkMNITransformReader.h 5.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkMNITransformReader.h

  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.

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

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
/**
 * @class   vtkMNITransformReader
 * @brief   A reader for MNI transformation files.
 *
 * The MNI .xfm file format is used to store geometrical
 * transformations.  Three kinds of transformations are supported by
 * the file format: affine, thin-plate spline, and grid transformations.
 * This file format was developed at the McConnell Brain Imaging Centre
 * at the Montreal Neurological Institute and is used by their software.
 * @sa
 * vtkMINCImageReader vtkMNITransformWriter
 * @par Thanks:
 * Thanks to David Gobbi for writing this class and Atamai Inc. for
 * contributing it to VTK.
*/
63

64 65
#ifndef vtkMNITransformReader_h
#define vtkMNITransformReader_h
66

67
#include "vtkIOMINCModule.h" // For export macro
68 69 70 71 72 73
#include "vtkAlgorithm.h"

class vtkAbstractTransform;
class vtkDoubleArray;
class vtkCollection;

74
class VTKIOMINC_EXPORT vtkMNITransformReader : public vtkAlgorithm
75 76 77 78 79
{
public:
  vtkTypeMacro(vtkMNITransformReader,vtkAlgorithm);

  static vtkMNITransformReader *New();
80
  void PrintSelf(ostream& os, vtkIndent indent) override;
81

82 83 84 85
  //@{
  /**
   * Set the file name.
   */
86 87
  vtkSetStringMacro(FileName);
  vtkGetStringMacro(FileName);
88
  //@}
89

90 91 92
  /**
   * Get the entension for this file format.
   */
93 94 95
  virtual const char* GetFileExtensions() {
    return ".xfm"; }

96 97 98
  /**
   * Get the name of this file format.
   */
99 100 101
  virtual const char* GetDescriptiveName() {
    return "MNI Transform"; }

102 103 104
  /**
   * Test whether the specified file can be read.
   */
105 106
  virtual int CanReadFile(const char* name);

107 108 109
  /**
   * Get the number of transforms in the file.
   */
110 111
  virtual int GetNumberOfTransforms();

112 113 114
  /**
   * Get one of the transforms listed in the file.
   */
115 116
  virtual vtkAbstractTransform *GetNthTransform(int i);

117 118 119 120 121
  /**
   * Get the transform that results from concatenating all
   * of the transforms in the file.  This will return null
   * if you have not specified a file name.
   */
122 123
  virtual vtkAbstractTransform *GetTransform();

124 125 126
  /**
   * Get any comments that are included in the file.
   */
127 128 129 130
  virtual const char *GetComments();

protected:
  vtkMNITransformReader();
131
  ~vtkMNITransformReader() override;
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161

  char *FileName;
  vtkAbstractTransform *Transform;
  vtkCollection *Transforms;
  int LineNumber;
  char *Comments;

  void SetTransform(vtkAbstractTransform *transform);

  int ReadLine(istream &infile, char result[256]);
  int ReadLineAfterComments(istream &infile, char result[256]);
  int SkipWhitespace(istream &infile, char linetext[256], char **cpp);
  int ParseLeftHandSide(istream &infile, char linetext[256], char **cpp,
                        char identifier[256]);
  int ParseStringValue(istream &infile, char linetext[256], char **cpp,
                       char data[256]);
  int ParseFloatValues(istream &infile, char linetext[256], char **cpp,
                       vtkDoubleArray *array);
  int ParseInvertFlagValue(istream &infile, char linetext[256], char **cpp,
                           int *invertFlag);

  int ReadLinearTransform(istream &infile, char linetext[256], char **cp);
  int ReadThinPlateSplineTransform(istream &infile, char linetext[256],
                                   char **cp);
  int ReadGridTransform(istream &infile, char linetext[256], char **cp);

  virtual int ReadNextTransform(istream &infile, char linetext[256]);

  virtual int ReadFile();

162
  int ProcessRequest(vtkInformation* request,
163
                             vtkInformationVector** inInfo,
164
                             vtkInformationVector* outInfo) override;
165 166

private:
167 168
  vtkMNITransformReader(const vtkMNITransformReader&) = delete;
  void operator=(const vtkMNITransformReader&) = delete;
169 170 171 172

};

#endif