1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkMNITagPointReader.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 /*========================================================================= 16 17 Copyright (c) 2006 Atamai, Inc. 18 19 Use, modification and redistribution of the software, in source or 20 binary forms, are permitted provided that the following terms and 21 conditions are met: 22 23 1) Redistribution of the source code, in verbatim or modified 24 form, must retain the above copyright notice, this license, 25 the following disclaimer, and any notices that refer to this 26 license and/or the following disclaimer. 27 28 2) Redistribution in binary form must include the above copyright 29 notice, a copy of this license and the following disclaimer 30 in the documentation or with other materials provided with the 31 distribution. 32 33 3) Modified copies of the source code must be clearly marked as such, 34 and must not be misrepresented as verbatim copies of the source code. 35 36 THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" 37 WITHOUT EXPRESSED OR IMPLIED WARRANTY INCLUDING, BUT NOT LIMITED TO, 38 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39 PURPOSE. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR OTHER PARTY WHO MAY 40 MODIFY AND/OR REDISTRIBUTE THE SOFTWARE UNDER THE TERMS OF THIS LICENSE 41 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES 42 (INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BECOMING INACCURATE 43 OR LOSS OF PROFIT OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF 44 THE USE OR INABILITY TO USE THE SOFTWARE, EVEN IF ADVISED OF THE 45 POSSIBILITY OF SUCH DAMAGES. 46 47 =========================================================================*/ 48 /** 49 * @class vtkMNITagPointReader 50 * @brief A reader for MNI tag files. 51 * 52 * The MNI .tag file format is used to store labeled points, it can 53 * store either one or two point sets. All point sets must have the 54 * same number of points and they will share the same labels. This 55 * file format was developed at the McConnell Brain Imaging Centre at 56 * the Montreal Neurological Institute and is used by their software. 57 * The labels are stored as a vtkStringArray in the PointData of the 58 * output dataset, which is a vtkPolyData. 59 * @sa 60 * vtkMINCImageReader vtkMNIObjectReader vtkMNITransformReader 61 * @par Thanks: 62 * Thanks to David Gobbi for contributing this class. 63 */ 64 65 #ifndef vtkMNITagPointReader_h 66 #define vtkMNITagPointReader_h 67 68 #include "vtkIOMINCModule.h" // For export macro 69 #include "vtkPolyDataAlgorithm.h" 70 #include "vtkStdString.h" // needed for std::string 71 72 class vtkPolyData; 73 class vtkPoints; 74 class vtkStringArray; 75 class vtkDoubleArray; 76 class vtkIntArray; 77 78 class VTKIOMINC_EXPORT vtkMNITagPointReader : public vtkPolyDataAlgorithm 79 { 80 public: 81 vtkTypeMacro(vtkMNITagPointReader, vtkPolyDataAlgorithm); 82 83 static vtkMNITagPointReader* New(); 84 void PrintSelf(ostream& os, vtkIndent indent) override; 85 86 ///@{ 87 /** 88 * Set the file name. 89 */ 90 vtkSetFilePathMacro(FileName); 91 vtkGetFilePathMacro(FileName); 92 ///@} 93 94 /** 95 * Get the extension for this file format. 96 */ GetFileExtensions()97 virtual const char* GetFileExtensions() { return ".tag"; } 98 99 /** 100 * Get the name of this file format. 101 */ GetDescriptiveName()102 virtual const char* GetDescriptiveName() { return "MNI tags"; } 103 104 /** 105 * Test whether the specified file can be read. 106 */ 107 virtual int CanReadFile(VTK_FILEPATH const char* name); 108 109 /** 110 * Get the number of volumes specified by the file, which will be 111 * equal to one or two. There will be an output point set for each 112 * volume, so really, this parameter just tells you the number of 113 * outputs to expect from this reader. 114 */ 115 virtual int GetNumberOfVolumes(); 116 117 /** 118 * Get the points. These are also provided in the first and 119 * second output ports of the reader. This method will return 120 * nullptr if there is no data. 121 */ 122 virtual vtkPoints* GetPoints(int port); GetPoints()123 virtual vtkPoints* GetPoints() { return this->GetPoints(0); } 124 125 /** 126 * Get the labels. These same labels are provided in the output 127 * point sets, as the PointData data array named "LabelText". 128 * This will return nullptr if there were no labels in the file. 129 */ 130 virtual vtkStringArray* GetLabelText(); 131 132 /** 133 * Get the weights. These are also provided in the output 134 * point sets, as the PointData data array named "Weights". 135 * This will return nullptr if there were no weights in the file. 136 */ 137 virtual vtkDoubleArray* GetWeights(); 138 139 /** 140 * Get the structure ids. These are also provided in the output 141 * point sets, as the PointData data array named "StructureIds". 142 * This will return nullptr if there were no ids in the file. 143 */ 144 virtual vtkIntArray* GetStructureIds(); 145 146 /** 147 * Get the patient ids. These are also provided in the output 148 * point sets, as the PointData data array named "PatientIds". 149 * This will return nullptr if there were no ids in the file. 150 */ 151 virtual vtkIntArray* GetPatientIds(); 152 153 /** 154 * Get any comments that are included in the file. 155 */ 156 virtual const char* GetComments(); 157 158 protected: 159 vtkMNITagPointReader(); 160 ~vtkMNITagPointReader() override; 161 162 char* FileName; 163 int NumberOfVolumes; 164 165 int LineNumber; 166 char* Comments; 167 168 int ReadLine(istream& infile, std::string& linetext, std::string::iterator& pos); 169 int ReadLineAfterComments(istream& infile, std::string& linetext, std::string::iterator& pos); 170 int SkipWhitespace(istream& infile, std::string& linetext, std::string::iterator& pos, int nl); 171 int ParseLeftHandSide( 172 istream& infile, std::string& linetext, std::string::iterator& pos, std::string& identifier); 173 int ParseStringValue( 174 istream& infile, std::string& linetext, std::string::iterator& pos, std::string& data); 175 int ParseIntValues( 176 istream& infile, std::string& linetext, std::string::iterator& pos, int* values, int count); 177 int ParseFloatValues( 178 istream& infile, std::string& linetext, std::string::iterator& pos, double* values, int count); 179 180 virtual int ReadFile(vtkPolyData* output1, vtkPolyData* output2); 181 182 int RequestData( 183 vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outInfo) override; 184 185 private: 186 vtkMNITagPointReader(const vtkMNITagPointReader&) = delete; 187 void operator=(const vtkMNITagPointReader&) = delete; 188 }; 189 190 #endif 191