ITK  6.0.0
Insight Toolkit
itkMeshIOBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkMeshIOBase_h
19 #define itkMeshIOBase_h
20 #include "ITKIOMeshBaseExport.h"
21 
22 #include "itkByteSwapper.h"
23 #include "itkCellInterface.h"
24 #include "itkCovariantVector.h"
25 #include "itkDiffusionTensor3D.h"
26 #include "itkIntTypes.h"
27 #include "itkLightProcessObject.h"
28 #include "itkMatrix.h"
29 #include "itkRGBPixel.h"
30 #include "itkRGBAPixel.h"
33 #include "itkVariableSizeMatrix.h"
34 #include "itkVector.h"
35 #include "itkNumberToString.h"
36 #include "itkCommonEnums.h"
38 
39 #include <string>
40 #include <complex>
41 #include <fstream>
42 
43 namespace itk
44 {
72 class ITKIOMeshBase_EXPORT MeshIOBase : public LightProcessObject
73 {
74 public:
75  ITK_DISALLOW_COPY_AND_MOVE(MeshIOBase);
76 
78  using Self = MeshIOBase;
82 
84  using ArrayOfExtensionsType = std::vector<std::string>;
85 
87  using StreamOffsetType = std::streamoff;
88 
90 
97  {};
98 
100  itkOverrideGetNameOfClassMacro(MeshIOBase);
101 
103  itkSetStringMacro(FileName);
104  itkGetStringMacro(FileName);
107 #if !defined(ITK_LEGACY_REMOVE)
108 
109  static constexpr IOPixelEnum UNKNOWNPIXELTYPE = IOPixelEnum::UNKNOWNPIXELTYPE;
110  static constexpr IOPixelEnum SCALAR = IOPixelEnum::SCALAR;
111  static constexpr IOPixelEnum RGB = IOPixelEnum::RGB;
112  static constexpr IOPixelEnum RGBA = IOPixelEnum::RGBA;
113  static constexpr IOPixelEnum OFFSET = IOPixelEnum::OFFSET;
114  static constexpr IOPixelEnum VECTOR = IOPixelEnum::VECTOR;
115  static constexpr IOPixelEnum POINT = IOPixelEnum::POINT;
116  static constexpr IOPixelEnum COVARIANTVECTOR = IOPixelEnum::COVARIANTVECTOR;
117  static constexpr IOPixelEnum SYMMETRICSECONDRANKTENSOR = IOPixelEnum::SYMMETRICSECONDRANKTENSOR;
118  static constexpr IOPixelEnum DIFFUSIONTENSOR3D = IOPixelEnum::DIFFUSIONTENSOR3D;
119  static constexpr IOPixelEnum COMPLEX = IOPixelEnum::COMPLEX;
120  static constexpr IOPixelEnum FIXEDARRAY = IOPixelEnum::FIXEDARRAY;
121  static constexpr IOPixelEnum ARRAY = IOPixelEnum::ARRAY;
122  static constexpr IOPixelEnum MATRIX = IOPixelEnum::MATRIX;
123  static constexpr IOPixelEnum VARIABLELENGTHVECTOR = IOPixelEnum::VARIABLELENGTHVECTOR;
124  static constexpr IOPixelEnum VARIABLESIZEMATRIX = IOPixelEnum::VARIABLESIZEMATRIX;
125 #endif
126 
127 #if !defined(ITK_LEGACY_REMOVE)
128 
129  static constexpr IOComponentEnum UNKNOWNCOMPONENTTYPE = IOComponentEnum::UNKNOWNCOMPONENTTYPE;
130  static constexpr IOComponentEnum UCHAR = IOComponentEnum::UCHAR;
131  static constexpr IOComponentEnum CHAR = IOComponentEnum::CHAR;
132  static constexpr IOComponentEnum USHORT = IOComponentEnum::USHORT;
133  static constexpr IOComponentEnum SHORT = IOComponentEnum::SHORT;
134  static constexpr IOComponentEnum UINT = IOComponentEnum::UINT;
135  static constexpr IOComponentEnum INT = IOComponentEnum::INT;
136  static constexpr IOComponentEnum ULONG = IOComponentEnum::ULONG;
137  static constexpr IOComponentEnum LONG = IOComponentEnum::LONG;
138  static constexpr IOComponentEnum ULONGLONG = IOComponentEnum::ULONGLONG;
139  static constexpr IOComponentEnum LONGLONG = IOComponentEnum::LONGLONG;
140  static constexpr IOComponentEnum FLOAT = IOComponentEnum::FLOAT;
141  static constexpr IOComponentEnum DOUBLE = IOComponentEnum::DOUBLE;
142  static constexpr IOComponentEnum LDOUBLE = IOComponentEnum::LDOUBLE;
143 #endif
144 
145 #if !defined(ITK_LEGACY_REMOVE)
146 
147  static constexpr IOFileEnum ASCII = IOFileEnum::ASCII;
148  static constexpr IOFileEnum BINARY = IOFileEnum::BINARY;
149  static constexpr IOFileEnum TYPENOTAPPLICABLE = IOFileEnum::TYPENOTAPPLICABLE;
150 #endif
151 
152 #if !defined(ITK_LEGACY_REMOVE)
153 
154  static constexpr IOByteOrderEnum BigEndian = IOByteOrderEnum::BigEndian;
155  static constexpr IOByteOrderEnum LittleEndian = IOByteOrderEnum::LittleEndian;
156  static constexpr IOByteOrderEnum OrderNotApplicable = IOByteOrderEnum::OrderNotApplicable;
157 #endif
158 
159 #if !defined(ITK_LEGACY_REMOVE)
160 
161  static constexpr IOFileModeEnum ReadMode = IOFileModeEnum::ReadMode;
162  static constexpr IOFileModeEnum WriteMode = IOFileModeEnum::WriteMode;
163 #endif
164 
165 #if !defined(ITK_LEGACY_REMOVE)
166 
167  static constexpr CellGeometryEnum VERTEX_CELL = CellGeometryEnum::VERTEX_CELL;
168  static constexpr CellGeometryEnum LINE_CELL = CellGeometryEnum::LINE_CELL;
169  static constexpr CellGeometryEnum TRIANGLE_CELL = CellGeometryEnum::TRIANGLE_CELL;
170  static constexpr CellGeometryEnum QUADRILATERAL_CELL = CellGeometryEnum::QUADRILATERAL_CELL;
171  static constexpr CellGeometryEnum POLYGON_CELL = CellGeometryEnum::POLYGON_CELL;
172  static constexpr CellGeometryEnum TETRAHEDRON_CELL = CellGeometryEnum::TETRAHEDRON_CELL;
173  static constexpr CellGeometryEnum HEXAHEDRON_CELL = CellGeometryEnum::HEXAHEDRON_CELL;
174  static constexpr CellGeometryEnum QUADRATIC_EDGE_CELL = CellGeometryEnum::QUADRATIC_EDGE_CELL;
175  static constexpr CellGeometryEnum QUADRATIC_TRIANGLE_CELL = CellGeometryEnum::QUADRATIC_TRIANGLE_CELL;
176  static constexpr CellGeometryEnum LAST_ITK_CELL = CellGeometryEnum::LAST_ITK_CELL;
177  static constexpr CellGeometryEnum MAX_ITK_CELLS = CellGeometryEnum::MAX_ITK_CELLS;
178 #endif
179 
185  itkSetEnumMacro(PointPixelType, itk::CommonEnums::IOPixel);
186  itkGetEnumMacro(PointPixelType, itk::CommonEnums::IOPixel);
187  itkSetEnumMacro(CellPixelType, itk::CommonEnums::IOPixel);
188  itkGetEnumMacro(CellPixelType, itk::CommonEnums::IOPixel);
193  itkSetEnumMacro(PointComponentType, itk::CommonEnums::IOComponent);
194  itkGetEnumMacro(PointComponentType, itk::CommonEnums::IOComponent);
195  itkSetEnumMacro(CellComponentType, itk::CommonEnums::IOComponent);
196  itkGetEnumMacro(CellComponentType, itk::CommonEnums::IOComponent);
197  itkSetEnumMacro(PointPixelComponentType, itk::CommonEnums::IOComponent);
198  itkGetEnumMacro(PointPixelComponentType, itk::CommonEnums::IOComponent);
199  itkSetEnumMacro(CellPixelComponentType, itk::CommonEnums::IOComponent);
200  itkGetEnumMacro(CellPixelComponentType, itk::CommonEnums::IOComponent);
203  template <typename T>
205  {
207  };
208 
209  template <typename T>
210  void
211  SetPixelType(const T & itkNotUsed(dummy), bool usePointPixel = true)
212  {
213  if (usePointPixel)
214  {
215  SetNumberOfPointPixelComponents(1);
216  SetPointPixelComponentType(MapComponentType<T>::CType);
217  SetPointPixelType(IOPixelEnum::SCALAR);
218  }
219  else
220  {
221  SetNumberOfCellPixelComponents(1);
222  SetCellPixelComponentType(MapComponentType<T>::CType);
223  SetCellPixelType(IOPixelEnum::SCALAR);
224  }
225  }
226 
227  template <typename T>
228  void
229  SetPixelType(const RGBPixel<T> & itkNotUsed(dummy), bool usePointPixel = true)
230  {
231  if (usePointPixel)
232  {
233  SetNumberOfPointPixelComponents(3);
234  SetPointPixelComponentType(MapComponentType<T>::CType);
235  SetPointPixelType(IOPixelEnum::RGB);
236  }
237  else
238  {
239  SetNumberOfCellPixelComponents(3);
240  SetCellPixelComponentType(MapComponentType<T>::CType);
241  SetCellPixelType(IOPixelEnum::RGB);
242  }
243  }
244 
245  template <typename T>
246  void
247  SetPixelType(const RGBAPixel<T> & itkNotUsed(dummy), bool usePointPixel = true)
248  {
249  if (usePointPixel)
250  {
251  SetNumberOfPointPixelComponents(4);
252  SetPointPixelComponentType(MapComponentType<T>::CType);
253  SetPointPixelType(IOPixelEnum::RGBA);
254  }
255  else
256  {
257  SetNumberOfCellPixelComponents(4);
258  SetCellPixelComponentType(MapComponentType<T>::CType);
259  SetCellPixelType(IOPixelEnum::RGBA);
260  }
261  }
262 
263  template <typename T, unsigned int VLength>
264  void
265  SetPixelType(const Vector<T, VLength> & itkNotUsed(dummy), bool usePointPixel = true)
266  {
267  if (usePointPixel)
268  {
269  SetNumberOfPointPixelComponents(VLength);
270  SetPointPixelComponentType(MapComponentType<T>::CType);
271  SetPointPixelType(IOPixelEnum::VECTOR);
272  }
273  else
274  {
275  SetNumberOfCellPixelComponents(VLength);
276  SetCellPixelComponentType(MapComponentType<T>::CType);
277  SetCellPixelType(IOPixelEnum::VECTOR);
278  }
279  }
280 
281  template <typename T, unsigned int VLength>
282  void
283  SetPixelType(const CovariantVector<T, VLength> & itkNotUsed(dummy), bool usePointPixel = true)
284  {
285  if (usePointPixel)
286  {
287  SetNumberOfPointPixelComponents(VLength);
288  SetPointPixelComponentType(MapComponentType<T>::CType);
289  SetPointPixelType(IOPixelEnum::COVARIANTVECTOR);
290  }
291  else
292  {
293  SetNumberOfCellPixelComponents(VLength);
294  SetCellPixelComponentType(MapComponentType<T>::CType);
295  SetCellPixelType(IOPixelEnum::COVARIANTVECTOR);
296  }
297  }
298 
299  template <typename T, unsigned int VLength>
300  void
301  SetPixelType(const FixedArray<T, VLength> & itkNotUsed(dummy), bool usePointPixel = true)
302  {
303  if (usePointPixel)
304  {
305  SetNumberOfPointPixelComponents(VLength);
306  SetPointPixelComponentType(MapComponentType<T>::CType);
307  SetPointPixelType(IOPixelEnum::FIXEDARRAY);
308  }
309  else
310  {
311  SetNumberOfCellPixelComponents(VLength);
312  SetCellPixelComponentType(MapComponentType<T>::CType);
313  SetCellPixelType(IOPixelEnum::FIXEDARRAY);
314  }
315  }
316 
317  template <typename T, unsigned int VLength>
318  void
319  SetPixelType(const SymmetricSecondRankTensor<T, VLength> itkNotUsed(dummy), bool usePointPixel = true)
320  {
321  if (usePointPixel)
322  {
323  SetNumberOfPointPixelComponents(VLength * (VLength + 1) / 2);
324  SetPointPixelComponentType(MapComponentType<T>::CType);
325  SetPointPixelType(IOPixelEnum::SYMMETRICSECONDRANKTENSOR);
326  }
327  else
328  {
329  SetNumberOfCellPixelComponents(VLength * (VLength + 1) / 2);
330  SetCellPixelComponentType(MapComponentType<T>::CType);
331  SetCellPixelType(IOPixelEnum::SYMMETRICSECONDRANKTENSOR);
332  }
333  }
334 
335  template <typename T>
336  void
337  SetPixelType(const DiffusionTensor3D<T> & itkNotUsed(dummy), bool usePointPixel = true)
338  {
339  if (usePointPixel)
340  {
341  SetNumberOfPointPixelComponents(6);
342  SetPointPixelComponentType(MapComponentType<T>::CType);
343  SetPointPixelType(IOPixelEnum::DIFFUSIONTENSOR3D);
344  }
345  else
346  {
347  SetNumberOfCellPixelComponents(6);
348  SetCellPixelComponentType(MapComponentType<T>::CType);
349  SetCellPixelType(IOPixelEnum::DIFFUSIONTENSOR3D);
350  }
351  }
352 
353  template <typename T, unsigned int VRows, unsigned int VColumns>
354  void
355  SetPixelType(const Matrix<T, VRows, VColumns> & itkNotUsed(dummy), bool usePointPixel = true)
356  {
357  if (usePointPixel)
358  {
359  SetNumberOfPointPixelComponents(VRows * VColumns);
360  SetPointPixelComponentType(MapComponentType<T>::CType);
361  SetPointPixelType(IOPixelEnum::MATRIX);
362  }
363  else
364  {
365  SetNumberOfCellPixelComponents(VRows * VColumns);
366  SetCellPixelComponentType(MapComponentType<T>::CType);
367  SetCellPixelType(IOPixelEnum::MATRIX);
368  }
369  }
370 
371  template <typename T>
372  void
373  SetPixelType(const std::complex<T> & itkNotUsed(dummy), bool usePointPixel = true)
374  {
375  if (usePointPixel)
376  {
377  SetNumberOfPointPixelComponents(2);
378  SetPointPixelComponentType(MapComponentType<T>::CType);
379  SetPointPixelType(IOPixelEnum::COMPLEX);
380  }
381  else
382  {
383  SetNumberOfCellPixelComponents(2);
384  SetCellPixelComponentType(MapComponentType<T>::CType);
385  SetCellPixelType(IOPixelEnum::COMPLEX);
386  }
387  }
388 
389  template <typename T>
390  void
391  SetPixelType(const Array<T> & array, bool usePointPixel = true)
392  {
393  if (usePointPixel)
394  {
395  SetNumberOfPointPixelComponents(array.Size());
396  SetPointPixelComponentType(MapComponentType<T>::CType);
397  SetPointPixelType(IOPixelEnum::ARRAY);
398  }
399  else
400  {
401  SetNumberOfCellPixelComponents(array.Size());
402  SetCellPixelComponentType(MapComponentType<T>::CType);
403  SetCellPixelType(IOPixelEnum::ARRAY);
404  }
405  }
406 
407  template <typename T>
408  void
409  SetPixelType(const VariableLengthVector<T> & vector, bool usePointPixel = true)
410  {
411  if (usePointPixel)
412  {
413  SetNumberOfPointPixelComponents(vector.Size());
414  SetPointPixelComponentType(MapComponentType<T>::CType);
415  SetPointPixelType(IOPixelEnum::VARIABLELENGTHVECTOR);
416  }
417  else
418  {
419  SetNumberOfCellPixelComponents(vector.Size());
420  SetCellPixelComponentType(MapComponentType<T>::CType);
421  SetCellPixelType(IOPixelEnum::VARIABLELENGTHVECTOR);
422  }
423  }
424 
425  template <typename T>
426  void
427  SetPixelType(const VariableSizeMatrix<T> & matrix, bool usePointPixel = true)
428  {
429  if (usePointPixel)
430  {
431  SetNumberOfPointPixelComponents(matrix.Rows() * matrix.Cols());
432  SetPointPixelComponentType(MapComponentType<T>::CType);
433  SetPointPixelType(IOPixelEnum::VARIABLESIZEMATRIX);
434  }
435  else
436  {
437  SetNumberOfCellPixelComponents(matrix.Rows() * matrix.Cols());
438  SetCellPixelComponentType(MapComponentType<T>::CType);
439  SetCellPixelType(IOPixelEnum::VARIABLESIZEMATRIX);
440  }
441  }
442 
447  itkSetMacro(NumberOfPointPixelComponents, unsigned int);
448  itkGetConstMacro(NumberOfPointPixelComponents, unsigned int);
449  itkSetMacro(NumberOfCellPixelComponents, unsigned int);
450  itkGetConstMacro(NumberOfCellPixelComponents, unsigned int);
451  itkSetMacro(PointDimension, unsigned int);
452  itkGetConstMacro(PointDimension, unsigned int);
453  itkSetMacro(NumberOfPoints, SizeValueType);
454  itkGetConstMacro(NumberOfPoints, SizeValueType);
455  itkSetMacro(NumberOfCells, SizeValueType);
456  itkGetConstMacro(NumberOfCells, SizeValueType);
457  itkSetMacro(NumberOfPointPixels, SizeValueType);
458  itkGetConstMacro(NumberOfPointPixels, SizeValueType);
459  itkSetMacro(NumberOfCellPixels, SizeValueType);
460  itkGetConstMacro(NumberOfCellPixels, SizeValueType);
461  itkSetMacro(CellBufferSize, SizeValueType);
462  itkGetConstMacro(CellBufferSize, SizeValueType);
463  itkSetMacro(UpdatePoints, bool);
464  itkGetConstMacro(UpdatePoints, bool);
465  itkBooleanMacro(UpdatePoints);
466  itkSetMacro(UpdateCells, bool);
467  itkGetConstMacro(UpdateCells, bool);
468  itkBooleanMacro(UpdateCells);
469  itkSetMacro(UpdatePointData, bool);
470  itkGetConstMacro(UpdatePointData, bool);
471  itkBooleanMacro(UpdatePointData);
472  itkSetMacro(UpdateCellData, bool);
473  itkGetConstMacro(UpdateCellData, bool);
474  itkBooleanMacro(UpdateCellData);
477  unsigned int
478  GetComponentSize(IOComponentEnum componentType) const;
479 
482  std::string GetComponentTypeAsString(IOComponentEnum) const;
483 
486  std::string GetPixelTypeAsString(IOPixelEnum) const;
487 
490  itkSetEnumMacro(FileType, IOFileEnum);
491  itkGetEnumMacro(FileType, IOFileEnum);
494  void
496  {
497  this->SetFileType(IOFileEnum::ASCII);
498  }
499 
500  void
502  {
503  this->SetFileType(IOFileEnum::BINARY);
504  }
505 
517  itkSetEnumMacro(ByteOrder, IOByteOrderEnum);
518  itkGetEnumMacro(ByteOrder, IOByteOrderEnum);
521  void
523  {
524  this->SetByteOrder(IOByteOrderEnum::BigEndian);
525  }
526 
527  void
529  {
530  this->SetByteOrder(IOByteOrderEnum::LittleEndian);
531  }
532 
534  itkSetMacro(UseCompression, bool);
535  itkGetConstMacro(UseCompression, bool);
536  itkBooleanMacro(UseCompression);
541  std::string GetFileTypeAsString(IOFileEnum) const;
542 
545  std::string GetByteOrderAsString(IOByteOrderEnum) const;
546 
547  /*-------- This part of the interfaces deals with reading data ----- */
550  virtual bool
551  CanReadFile(const char *) = 0;
552 
555  virtual void
556  ReadMeshInformation() = 0;
557 
559  virtual void
560  ReadPoints(void * buffer) = 0;
561 
562  virtual void
563  ReadCells(void * buffer) = 0;
564 
565  virtual void
566  ReadPointData(void * buffer) = 0;
567 
568  virtual void
569  ReadCellData(void * buffer) = 0;
570 
571  /*-------- This part of the interfaces deals with writing data ----- */
572 
575  virtual bool
576  CanWriteFile(const char *) = 0;
577 
578  virtual void
579  WriteMeshInformation() = 0;
580 
581  virtual void
582  WritePoints(void * buffer) = 0;
583 
584  virtual void
585  WriteCells(void * buffer) = 0;
586 
587  virtual void
588  WritePointData(void * buffer) = 0;
589 
590  virtual void
591  WriteCellData(void * buffer) = 0;
592 
593  virtual void
594  Write() = 0;
595 
600  const ArrayOfExtensionsType &
601  GetSupportedReadExtensions() const;
602 
607  const ArrayOfExtensionsType &
608  GetSupportedWriteExtensions() const;
609 
610 protected:
611  MeshIOBase();
612  ~MeshIOBase() override = default;
613 
614  void
615  PrintSelf(std::ostream & os, Indent indent) const override;
616 
618  void
619  AddSupportedReadExtension(const char * extension);
620 
622  void
623  AddSupportedWriteExtension(const char * extension);
624 
626  template <typename T>
627  void
628  ReadBufferAsAscii(T * buffer, std::ifstream & inputFile, SizeValueType numberOfComponents)
629  {
630  for (SizeValueType i = 0; i < numberOfComponents; ++i)
631  {
632  inputFile >> buffer[i];
633  }
634  }
638  template <typename T>
639  void
640  ReadBufferAsBinary(T * buffer, std::ifstream & inputFile, SizeValueType numberOfComponents)
641  {
642  inputFile.read(reinterpret_cast<char *>(buffer), numberOfComponents * sizeof(T));
643 
644  if (m_ByteOrder == IOByteOrderEnum::BigEndian)
645  {
647  {
648  itk::ByteSwapper<T>::SwapRangeFromSystemToBigEndian(buffer, numberOfComponents);
649  }
650  }
651  else if (m_ByteOrder == IOByteOrderEnum::LittleEndian)
652  {
654  {
655  itk::ByteSwapper<T>::SwapRangeFromSystemToLittleEndian(buffer, numberOfComponents);
656  }
657  }
658  }
659 
661  template <typename T>
662  void
663  WriteBufferAsAscii(T * buffer,
664  std::ofstream & outputFile,
665  SizeValueType numberOfLines,
666  SizeValueType numberOfComponents)
667  {
668  for (SizeValueType ii = 0; ii < numberOfLines; ++ii)
669  {
670  for (SizeValueType jj = 0; jj < numberOfComponents; ++jj)
671  {
672  outputFile << ConvertNumberToString(buffer[ii * numberOfComponents + jj]) << " ";
673  }
674  outputFile << '\n';
675  }
676  }
680  template <typename TOutput, typename TInput>
681  void
682  WriteBufferAsBinary(TInput * buffer, std::ofstream & outputFile, SizeValueType numberOfComponents)
683  {
684  if (typeid(TInput) == typeid(TOutput))
685  {
687  {
689  }
691  {
693  }
696  outputFile.write(reinterpret_cast<char *>(buffer), numberOfComponents);
697  }
698  else
699  {
700  const auto data = make_unique_for_overwrite<TOutput[]>(numberOfComponents);
701  for (SizeValueType ii = 0; ii < numberOfComponents; ++ii)
702  {
703  data[ii] = static_cast<TOutput>(buffer[ii]);
704  }
705 
707  {
708  itk::ByteSwapper<TOutput>::SwapRangeFromSystemToBigEndian(data.get(), numberOfComponents);
709  }
711  {
712  itk::ByteSwapper<TOutput>::SwapRangeFromSystemToLittleEndian(data.get(), numberOfComponents);
713  }
714 
715  outputFile.write(reinterpret_cast<char *>(data.get()), numberOfComponents);
716  }
717  }
718 
722  template <typename TInput, typename TOutput>
723  void
724  ReadCellsBuffer(TInput * input, TOutput * output)
725  {
726  if (input && output)
727  {
728  SizeValueType inputIndex{};
729  SizeValueType outputIndex{};
730  for (SizeValueType ii = 0; ii < m_NumberOfCells; ++ii)
731  {
732  ++inputIndex; // ignore the cell type
733  auto numberOfPoints = static_cast<unsigned int>(input[inputIndex++]);
734  for (unsigned int jj = 0; jj < numberOfPoints; ++jj)
735  {
736  output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
737  }
738  }
739  }
740  }
746  template <typename TInput, typename TOutput>
747  void
748  ReadCellsBuffer(TInput * input, TOutput * output, CellGeometryEnum type)
749  {
750  if (input && output)
751  {
752  SizeValueType inputIndex{};
753  SizeValueType outputIndex{};
756  for (SizeValueType ii = 0; ii < m_NumberOfCells; ++ii)
757  {
758  auto cellType = static_cast<CellGeometryEnum>(input[inputIndex++]);
759  auto nn = static_cast<unsigned int>(input[inputIndex++]);
760  if (cellType == type)
761  {
762  output[outputIndex++] = nn;
763  for (unsigned int jj = 0; jj < nn; ++jj)
764  {
765  output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
766  }
767  }
768  else
769  {
770  inputIndex += nn;
771  }
772  }
773  }
774  }
775 
778  template <typename TInput, typename TOutput>
779  void
780  WriteCellsBuffer(TInput * input,
781  TOutput * output,
782  CellGeometryEnum cellType,
783  unsigned int numberOfPoints,
784  SizeValueType numberOfCells)
785  {
786  if (input && output)
787  {
788  SizeValueType inputIndex{};
789  SizeValueType outputIndex{};
790  for (SizeValueType ii = 0; ii < numberOfCells; ++ii)
791  {
792  output[outputIndex++] = static_cast<TOutput>(cellType);
793  output[outputIndex++] = static_cast<TOutput>(numberOfPoints);
794  for (unsigned int jj = 0; jj < numberOfPoints; ++jj)
795  {
796  output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
797  }
798  }
799  }
800  }
805  template <typename TInput, typename TOutput>
806  void
807  WriteCellsBuffer(TInput * input, TOutput * output, CellGeometryEnum cellType, SizeValueType numberOfCells)
808  {
809  if (input && output)
810  {
811  SizeValueType inputIndex{};
812  SizeValueType outputIndex{};
813  for (SizeValueType ii = 0; ii < numberOfCells; ++ii)
814  {
815  auto numberOfPoints = static_cast<unsigned int>(input[inputIndex++]);
816  if (numberOfPoints > 2 && cellType == CellGeometryEnum::LINE_CELL)
817  {
818  output[outputIndex++] = static_cast<TOutput>(CellGeometryEnum::POLYLINE_CELL);
819  }
820  else
821  {
822  output[outputIndex++] = static_cast<TOutput>(cellType);
823  }
824  output[outputIndex++] = static_cast<TOutput>(numberOfPoints);
827  for (unsigned int jj = 0; jj < numberOfPoints; ++jj)
828  {
829  output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
830  }
831  }
832  }
833  }
834 
835 protected:
839 
841  std::string m_FileName{};
842 
844  bool m_UseCompression{ false };
845 
851 
853  IOPixelEnum m_PointPixelType{ IOPixelEnum::SCALAR };
854  IOPixelEnum m_CellPixelType{ IOPixelEnum::SCALAR };
855 
858  unsigned int m_NumberOfPointPixelComponents{ 0 };
859  unsigned int m_NumberOfCellPixelComponents{ 0 };
860 
862  unsigned int m_PointDimension{ 3 };
863 
865  SizeValueType m_NumberOfPoints{};
866  SizeValueType m_NumberOfCells{};
867  SizeValueType m_NumberOfPointPixels{};
868  SizeValueType m_NumberOfCellPixels{};
869 
871  SizeValueType m_CellBufferSize{};
872 
875  bool m_UpdatePoints{ false };
876  bool m_UpdateCells{ false };
877  bool m_UpdatePointData{ false };
878  bool m_UpdateCellData{ false };
879 
880 private:
881  ArrayOfExtensionsType m_SupportedReadExtensions{};
882  ArrayOfExtensionsType m_SupportedWriteExtensions{};
883 };
884 #define MESHIOBASE_TYPEMAP(type, ctype) \
885  template <> \
886  struct MeshIOBase::MapComponentType<type> \
887  { \
888  static constexpr IOComponentEnum CType = ctype; \
889  }
890 
904 #undef MESHIOBASE_TYPEMAP
905 } // end namespace itk
906 
907 #endif
itk::CommonEnums::IOComponent::UNKNOWNCOMPONENTTYPE
itk::MeshIOBase::ArrayOfExtensionsType
std::vector< std::string > ArrayOfExtensionsType
Definition: itkMeshIOBase.h:84
itk::CommonEnums::CellGeometry::LINE_CELL
itk::CommonEnums::CellGeometry::POLYGON_CELL
itk::MeshIOBase::SetPixelType
void SetPixelType(const RGBAPixel< T > &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:247
itk::LightProcessObject
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Definition: itkLightProcessObject.h:72
itk::CommonEnums::IOComponent::FLOAT
itk::CommonEnums::IOFileMode
IOFileMode
Definition: itkCommonEnums.h:111
itk::RGBPixel
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
itkCovariantVector.h
itk::MeshIOBase::WriteBufferAsBinary
void WriteBufferAsBinary(TInput *buffer, std::ofstream &outputFile, SizeValueType numberOfComponents)
Definition: itkMeshIOBase.h:682
itkByteSwapper.h
itk::CommonEnums::IOFile::TYPENOTAPPLICABLE
itkRGBPixel.h
itk::MeshIOBase::SetFileTypeToASCII
void SetFileTypeToASCII()
Definition: itkMeshIOBase.h:495
itk::MeshIOBase::SizeValueType
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:89
itk::CommonEnums::IOPixel::VARIABLESIZEMATRIX
itkVariableSizeMatrix.h
itk::CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL
itkMatrix.h
itk::CommonEnums::CellGeometry::HEXAHEDRON_CELL
itk::MeshIOBase::SetPixelType
void SetPixelType(const DiffusionTensor3D< T > &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:337
itk::CommonEnums::IOComponent::LDOUBLE
itk::CommonEnums::IOPixel::ARRAY
itk::CommonEnums::IOComponent::LONGLONG
itk::CommonEnums::IOComponent::INT
itkLightProcessObject.h
itkVariableLengthVector.h
itk::CommonEnums::IOByteOrder::BigEndian
itkDiffusionTensor3D.h
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::MeshIOBase::SetPixelType
void SetPixelType(const SymmetricSecondRankTensor< T, VLength >, bool usePointPixel=true)
Definition: itkMeshIOBase.h:319
itk::MeshIOBase
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:72
itk::CommonEnums::IOComponent::CHAR
itk::CommonEnums::IOComponent::SHORT
itk::DiffusionTensor3D
Represent a diffusion tensor as used in DTI images.
Definition: itkDiffusionTensor3D.h:79
itk::CommonEnums::IOFileMode::ReadMode
itkRGBAPixel.h
itk::MeshIOBase::SetPixelType
void SetPixelType(const Array< T > &array, bool usePointPixel=true)
Definition: itkMeshIOBase.h:391
itk::CommonEnums::IOFile::ASCII
itk::MeshIOBase::ReadCellsBuffer
void ReadCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum type)
Definition: itkMeshIOBase.h:748
itk::SmartPointer< const Self >
itk::CommonEnums::IOByteOrder::LittleEndian
itk::CommonEnums::IOComponent::DOUBLE
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::CommonEnums::IOPixel::POINT
itk::MeshIOBase::SetPixelType
void SetPixelType(const FixedArray< T, VLength > &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:301
itk::VariableSizeMatrix
A templated class holding a M x N size Matrix.
Definition: itkVariableSizeMatrix.h:45
itk::CommonEnums::IOPixel::COVARIANTVECTOR
itk::CommonEnums::IOByteOrder::OrderNotApplicable
itk::CommonEnums::IOPixel
IOPixel
Definition: itkCommonEnums.h:48
itk::CommonEnums::IOComponent
IOComponent
Definition: itkCommonEnums.h:74
itk::SymmetricSecondRankTensor
Represent a symmetric tensor of second rank.
Definition: itkSymmetricSecondRankTensor.h:75
itk::MeshIOBase::ReadBufferAsAscii
void ReadBufferAsAscii(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
Definition: itkMeshIOBase.h:628
itk::CommonEnums::CellGeometry
CellGeometry
Definition: itkCommonEnums.h:132
itk::MeshIOBase::SetPixelType
void SetPixelType(const VariableLengthVector< T > &vector, bool usePointPixel=true)
Definition: itkMeshIOBase.h:409
itk::MeshIOBase::WriteCellsBuffer
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum cellType, SizeValueType numberOfCells)
Definition: itkMeshIOBase.h:807
itk::MeshIOBase::SetPixelType
void SetPixelType(const Matrix< T, VRows, VColumns > &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:355
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkNumberToString.h
itk::MeshIOBase::WriteBufferAsAscii
void WriteBufferAsAscii(T *buffer, std::ofstream &outputFile, SizeValueType numberOfLines, SizeValueType numberOfComponents)
Definition: itkMeshIOBase.h:663
itk::MeshIOBase::ReadCellsBuffer
void ReadCellsBuffer(TInput *input, TOutput *output)
Definition: itkMeshIOBase.h:724
itk::ByteSwapper::SwapRangeFromSystemToBigEndian
static void SwapRangeFromSystemToBigEndian(T *p, BufferSizeType num)
itkSymmetricSecondRankTensor.h
itk::CommonEnums::CellGeometry::POLYLINE_CELL
itk::MeshIOBase::SetFileTypeToBinary
void SetFileTypeToBinary()
Definition: itkMeshIOBase.h:501
itk::ByteSwapper
Perform machine dependent byte swapping.
Definition: itkByteSwapper.h:50
itk::VariableSizeMatrix::Cols
unsigned int Cols() const
Definition: itkVariableSizeMatrix.h:247
itk::CommonEnums::CellGeometry::MAX_ITK_CELLS
itk::MeshIOBase::UnknownType
Definition: itkMeshIOBase.h:96
itk::MeshIOBase::ReadBufferAsBinary
void ReadBufferAsBinary(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
Definition: itkMeshIOBase.h:640
itk::CommonEnums::IOPixel::MATRIX
itk::MeshIOBase::MapComponentType
Definition: itkMeshIOBase.h:204
itk::MeshIOBase::SetPixelType
void SetPixelType(const VariableSizeMatrix< T > &matrix, bool usePointPixel=true)
Definition: itkMeshIOBase.h:427
itk::VariableLengthVector::Size
unsigned int Size() const
Definition: itkVariableLengthVector.h:587
itk::CommonEnums::IOFile
IOFile
Definition: itkCommonEnums.h:97
itk::MeshIOBase::SetPixelType
void SetPixelType(const CovariantVector< T, VLength > &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:283
itk::CommonEnums::IOPixel::COMPLEX
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itkIntTypes.h
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::CommonEnums::IOPixel::VECTOR
itk::CommonEnums::IOPixel::VARIABLELENGTHVECTOR
itk::Matrix
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:52
itk::CommonEnums::IOComponent::ULONG
itk::CommonEnums::CellGeometry::QUADRATIC_TRIANGLE_CELL
itk::CommonEnums::IOComponent::USHORT
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::CommonEnums::CellGeometry::QUADRILATERAL_CELL
itk::ConvertNumberToString
std::string ConvertNumberToString(const TValue val)
Definition: itkNumberToString.h:83
itk::RGBAPixel
Represent Red, Green, Blue and Alpha components for color images.
Definition: itkRGBAPixel.h:59
itk::CommonEnums::CellGeometry::TRIANGLE_CELL
itk::CommonEnums::IOFile::BINARY
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::CommonEnums::IOComponent::ULONGLONG
itk::CommonEnums::IOFileMode::WriteMode
itkCommonEnums.h
itkMakeUniqueForOverwrite.h
itk::CommonEnums::IOPixel::RGB
itkVector.h
itk::ByteSwapper::SwapRangeFromSystemToLittleEndian
static void SwapRangeFromSystemToLittleEndian(T *p, BufferSizeType num)
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::CommonEnums::CellGeometry::TETRAHEDRON_CELL
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itkCellInterface.h
itk::CommonEnums::IOComponent::UCHAR
itk::Array::Size
SizeValueType Size() const
Definition: itkArray.h:128
itk::MeshIOBase::SetPixelType
void SetPixelType(const RGBPixel< T > &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:229
itk::MeshIOBase::SetByteOrderToLittleEndian
void SetByteOrderToLittleEndian()
Definition: itkMeshIOBase.h:528
itk::MeshIOBase::WriteCellsBuffer
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum cellType, unsigned int numberOfPoints, SizeValueType numberOfCells)
Definition: itkMeshIOBase.h:780
itk::CommonEnums::IOPixel::FIXEDARRAY
itk::CommonEnums::IOPixel::SCALAR
itk::CommonEnums::IOPixel::SYMMETRICSECONDRANKTENSOR
itk::MESHIOBASE_TYPEMAP
MESHIOBASE_TYPEMAP(unsigned char, IOComponentEnum::UCHAR)
itk::CommonEnums::IOByteOrder
IOByteOrder
Definition: itkCommonEnums.h:122
itk::VariableSizeMatrix::Rows
unsigned int Rows() const
Definition: itkVariableSizeMatrix.h:240
itk::MeshIOBase::SetPixelType
void SetPixelType(const T &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:211
itk::CommonEnums::IOComponent::LONG
itk::CommonEnums::IOPixel::OFFSET
itk::MeshIOBase::SetPixelType
void SetPixelType(const std::complex< T > &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:373
itk::CommonEnums::IOPixel::RGBA
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
itk::MeshIOBase::SetPixelType
void SetPixelType(const Vector< T, VLength > &, bool usePointPixel=true)
Definition: itkMeshIOBase.h:265
itk::CommonEnums::IOPixel::UNKNOWNPIXELTYPE
itk::CommonEnums::IOPixel::DIFFUSIONTENSOR3D
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::CommonEnums::CellGeometry::VERTEX_CELL
itk::MeshIOBase::StreamOffsetType
std::streamoff StreamOffsetType
Definition: itkMeshIOBase.h:87
itk::CommonEnums::CellGeometry::LAST_ITK_CELL
itk::CommonEnums::IOComponent::UINT
itk::MeshIOBase::SetByteOrderToBigEndian
void SetByteOrderToBigEndian()
Definition: itkMeshIOBase.h:522