ITK  5.2.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  * http://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"
37 
38 #include <string>
39 #include <complex>
40 #include <fstream>
41 
42 namespace itk
43 {
71 class ITKIOMeshBase_EXPORT MeshIOBase : public LightProcessObject
72 {
73 public:
74  ITK_DISALLOW_COPY_AND_MOVE(MeshIOBase);
75 
77  using Self = MeshIOBase;
81 
83  using ArrayOfExtensionsType = std::vector<std::string>;
84 
86  using StreamOffsetType = std::streamoff;
87 
89 
96  {};
97 
99  itkTypeMacro(MeshIOBase, LightProcessObject);
100 
102  itkSetStringMacro(FileName);
103  itkGetStringMacro(FileName);
105 
106 #if !defined(ITK_LEGACY_REMOVE)
107 
108  static constexpr IOPixelEnum UNKNOWNPIXELTYPE = IOPixelEnum::UNKNOWNPIXELTYPE;
109  static constexpr IOPixelEnum SCALAR = IOPixelEnum::SCALAR;
110  static constexpr IOPixelEnum RGB = IOPixelEnum::RGB;
111  static constexpr IOPixelEnum RGBA = IOPixelEnum::RGBA;
112  static constexpr IOPixelEnum OFFSET = IOPixelEnum::OFFSET;
113  static constexpr IOPixelEnum VECTOR = IOPixelEnum::VECTOR;
114  static constexpr IOPixelEnum POINT = IOPixelEnum::POINT;
115  static constexpr IOPixelEnum COVARIANTVECTOR = IOPixelEnum::COVARIANTVECTOR;
116  static constexpr IOPixelEnum SYMMETRICSECONDRANKTENSOR = IOPixelEnum::SYMMETRICSECONDRANKTENSOR;
117  static constexpr IOPixelEnum DIFFUSIONTENSOR3D = IOPixelEnum::DIFFUSIONTENSOR3D;
118  static constexpr IOPixelEnum COMPLEX = IOPixelEnum::COMPLEX;
119  static constexpr IOPixelEnum FIXEDARRAY = IOPixelEnum::FIXEDARRAY;
120  static constexpr IOPixelEnum ARRAY = IOPixelEnum::ARRAY;
121  static constexpr IOPixelEnum MATRIX = IOPixelEnum::MATRIX;
122  static constexpr IOPixelEnum VARIABLELENGTHVECTOR = IOPixelEnum::VARIABLELENGTHVECTOR;
123  static constexpr IOPixelEnum VARIABLESIZEMATRIX = IOPixelEnum::VARIABLESIZEMATRIX;
124 #endif
125 
126 #if !defined(ITK_LEGACY_REMOVE)
127 
128  static constexpr IOComponentEnum UNKNOWNCOMPONENTTYPE = IOComponentEnum::UNKNOWNCOMPONENTTYPE;
129  static constexpr IOComponentEnum UCHAR = IOComponentEnum::UCHAR;
130  static constexpr IOComponentEnum CHAR = IOComponentEnum::CHAR;
131  static constexpr IOComponentEnum USHORT = IOComponentEnum::USHORT;
132  static constexpr IOComponentEnum SHORT = IOComponentEnum::SHORT;
133  static constexpr IOComponentEnum UINT = IOComponentEnum::UINT;
134  static constexpr IOComponentEnum INT = IOComponentEnum::INT;
135  static constexpr IOComponentEnum ULONG = IOComponentEnum::ULONG;
136  static constexpr IOComponentEnum LONG = IOComponentEnum::LONG;
137  static constexpr IOComponentEnum ULONGLONG = IOComponentEnum::ULONGLONG;
138  static constexpr IOComponentEnum LONGLONG = IOComponentEnum::LONGLONG;
139  static constexpr IOComponentEnum FLOAT = IOComponentEnum::FLOAT;
140  static constexpr IOComponentEnum DOUBLE = IOComponentEnum::DOUBLE;
141  static constexpr IOComponentEnum LDOUBLE = IOComponentEnum::LDOUBLE;
142 #endif
143 
144 #if !defined(ITK_LEGACY_REMOVE)
145 
146  static constexpr IOFileEnum ASCII = IOFileEnum::ASCII;
147  static constexpr IOFileEnum BINARY = IOFileEnum::BINARY;
148  static constexpr IOFileEnum TYPENOTAPPLICABLE = IOFileEnum::TYPENOTAPPLICABLE;
149 #endif
150 
151 #if !defined(ITK_LEGACY_REMOVE)
152 
153  static constexpr IOByteOrderEnum BigEndian = IOByteOrderEnum::BigEndian;
154  static constexpr IOByteOrderEnum LittleEndian = IOByteOrderEnum::LittleEndian;
155  static constexpr IOByteOrderEnum OrderNotApplicable = IOByteOrderEnum::OrderNotApplicable;
156 #endif
157 
158 #if !defined(ITK_LEGACY_REMOVE)
159 
160  static constexpr IOFileModeEnum ReadMode = IOFileModeEnum::ReadMode;
161  static constexpr IOFileModeEnum WriteMode = IOFileModeEnum::WriteMode;
162 #endif
163 
164 #if !defined(ITK_LEGACY_REMOVE)
165 
166  static constexpr CellGeometryEnum VERTEX_CELL = CellGeometryEnum::VERTEX_CELL;
167  static constexpr CellGeometryEnum LINE_CELL = CellGeometryEnum::LINE_CELL;
168  static constexpr CellGeometryEnum TRIANGLE_CELL = CellGeometryEnum::TRIANGLE_CELL;
169  static constexpr CellGeometryEnum QUADRILATERAL_CELL = CellGeometryEnum::QUADRILATERAL_CELL;
170  static constexpr CellGeometryEnum POLYGON_CELL = CellGeometryEnum::POLYGON_CELL;
171  static constexpr CellGeometryEnum TETRAHEDRON_CELL = CellGeometryEnum::TETRAHEDRON_CELL;
172  static constexpr CellGeometryEnum HEXAHEDRON_CELL = CellGeometryEnum::HEXAHEDRON_CELL;
173  static constexpr CellGeometryEnum QUADRATIC_EDGE_CELL = CellGeometryEnum::QUADRATIC_EDGE_CELL;
174  static constexpr CellGeometryEnum QUADRATIC_TRIANGLE_CELL = CellGeometryEnum::QUADRATIC_TRIANGLE_CELL;
175  static constexpr CellGeometryEnum LAST_ITK_CELL = CellGeometryEnum::LAST_ITK_CELL;
176  static constexpr CellGeometryEnum MAX_ITK_CELLS = CellGeometryEnum::MAX_ITK_CELLS;
177 #endif
178 
184  itkSetEnumMacro(PointPixelType, ::itk::CommonEnums::IOPixel);
185  itkGetEnumMacro(PointPixelType, ::itk::CommonEnums::IOPixel);
186  itkSetEnumMacro(CellPixelType, ::itk::CommonEnums::IOPixel);
187  itkGetEnumMacro(CellPixelType, ::itk::CommonEnums::IOPixel);
189 
192  itkSetEnumMacro(PointComponentType, ::itk::CommonEnums::IOComponent);
193  itkGetEnumMacro(PointComponentType, ::itk::CommonEnums::IOComponent);
194  itkSetEnumMacro(CellComponentType, ::itk::CommonEnums::IOComponent);
195  itkGetEnumMacro(CellComponentType, ::itk::CommonEnums::IOComponent);
196  itkSetEnumMacro(PointPixelComponentType, ::itk::CommonEnums::IOComponent);
197  itkGetEnumMacro(PointPixelComponentType, ::itk::CommonEnums::IOComponent);
198  itkSetEnumMacro(CellPixelComponentType, ::itk::CommonEnums::IOComponent);
199  itkGetEnumMacro(CellPixelComponentType, ::itk::CommonEnums::IOComponent);
201 
202  template <typename T>
204  {
206  };
207 
208  template <typename T>
209  void
210  SetPixelType(const T & itkNotUsed(dummy), bool UsePointPixel = true)
211  {
212  if (UsePointPixel)
213  {
214  SetNumberOfPointPixelComponents(1);
215  SetPointPixelComponentType(MapComponentType<T>::CType);
216  SetPointPixelType(IOPixelEnum::SCALAR);
217  }
218  else
219  {
220  SetNumberOfCellPixelComponents(1);
221  SetCellPixelComponentType(MapComponentType<T>::CType);
222  SetCellPixelType(IOPixelEnum::SCALAR);
223  }
224  }
225 
226  template <typename T>
227  void
228  SetPixelType(const RGBPixel<T> & itkNotUsed(dummy), bool UsePointPixel = true)
229  {
230  if (UsePointPixel)
231  {
232  SetNumberOfPointPixelComponents(3);
233  SetPointPixelComponentType(MapComponentType<T>::CType);
234  SetPointPixelType(IOPixelEnum::RGB);
235  }
236  else
237  {
238  SetNumberOfCellPixelComponents(3);
239  SetCellPixelComponentType(MapComponentType<T>::CType);
240  SetCellPixelType(IOPixelEnum::RGB);
241  }
242  }
243 
244  template <typename T>
245  void
246  SetPixelType(const RGBAPixel<T> & itkNotUsed(dummy), bool UsePointPixel = true)
247  {
248  if (UsePointPixel)
249  {
250  SetNumberOfPointPixelComponents(4);
251  SetPointPixelComponentType(MapComponentType<T>::CType);
252  SetPointPixelType(IOPixelEnum::RGBA);
253  }
254  else
255  {
256  SetNumberOfCellPixelComponents(4);
257  SetCellPixelComponentType(MapComponentType<T>::CType);
258  SetCellPixelType(IOPixelEnum::RGBA);
259  }
260  }
261 
262  template <typename T, unsigned int VLength>
263  void
264  SetPixelType(const Vector<T, VLength> & itkNotUsed(dummy), bool UsePointPixel = true)
265  {
266  if (UsePointPixel)
267  {
268  SetNumberOfPointPixelComponents(VLength);
269  SetPointPixelComponentType(MapComponentType<T>::CType);
270  SetPointPixelType(IOPixelEnum::VECTOR);
271  }
272  else
273  {
274  SetNumberOfCellPixelComponents(VLength);
275  SetCellPixelComponentType(MapComponentType<T>::CType);
276  SetCellPixelType(IOPixelEnum::VECTOR);
277  }
278  }
279 
280  template <typename T, unsigned int VLength>
281  void
282  SetPixelType(const CovariantVector<T, VLength> & itkNotUsed(dummy), bool UsePointPixel = true)
283  {
284  if (UsePointPixel)
285  {
286  SetNumberOfPointPixelComponents(VLength);
287  SetPointPixelComponentType(MapComponentType<T>::CType);
288  SetPointPixelType(IOPixelEnum::COVARIANTVECTOR);
289  }
290  else
291  {
292  SetNumberOfCellPixelComponents(VLength);
293  SetCellPixelComponentType(MapComponentType<T>::CType);
294  SetCellPixelType(IOPixelEnum::COVARIANTVECTOR);
295  }
296  }
297 
298  template <typename T, unsigned int VLength>
299  void
300  SetPixelType(const FixedArray<T, VLength> & itkNotUsed(dummy), bool UsePointPixel = true)
301  {
302  if (UsePointPixel)
303  {
304  SetNumberOfPointPixelComponents(VLength);
305  SetPointPixelComponentType(MapComponentType<T>::CType);
306  SetPointPixelType(IOPixelEnum::FIXEDARRAY);
307  }
308  else
309  {
310  SetNumberOfCellPixelComponents(VLength);
311  SetCellPixelComponentType(MapComponentType<T>::CType);
312  SetCellPixelType(IOPixelEnum::FIXEDARRAY);
313  }
314  }
315 
316  template <typename T, unsigned int VLength>
317  void
318  SetPixelType(const SymmetricSecondRankTensor<T, VLength> itkNotUsed(dummy), bool UsePointPixel = true)
319  {
320  if (UsePointPixel)
321  {
322  SetNumberOfPointPixelComponents(VLength * (VLength + 1) / 2);
323  SetPointPixelComponentType(MapComponentType<T>::CType);
324  SetPointPixelType(IOPixelEnum::SYMMETRICSECONDRANKTENSOR);
325  }
326  else
327  {
328  SetNumberOfCellPixelComponents(VLength * (VLength + 1) / 2);
329  SetCellPixelComponentType(MapComponentType<T>::CType);
330  SetCellPixelType(IOPixelEnum::SYMMETRICSECONDRANKTENSOR);
331  }
332  }
333 
334  template <typename T>
335  void
336  SetPixelType(const DiffusionTensor3D<T> & itkNotUsed(dummy), bool UsePointPixel = true)
337  {
338  if (UsePointPixel)
339  {
340  SetNumberOfPointPixelComponents(6);
341  SetPointPixelComponentType(MapComponentType<T>::CType);
342  SetPointPixelType(IOPixelEnum::DIFFUSIONTENSOR3D);
343  }
344  else
345  {
346  SetNumberOfCellPixelComponents(6);
347  SetCellPixelComponentType(MapComponentType<T>::CType);
348  SetCellPixelType(IOPixelEnum::DIFFUSIONTENSOR3D);
349  }
350  }
351 
352  template <typename T, unsigned int NR, unsigned int NC>
353  void
354  SetPixelType(const Matrix<T, NR, NC> & itkNotUsed(dummy), bool UsePointPixel = true)
355  {
356  if (UsePointPixel)
357  {
358  SetNumberOfPointPixelComponents(NR * NC);
359  SetPointPixelComponentType(MapComponentType<T>::CType);
360  SetPointPixelType(IOPixelEnum::MATRIX);
361  }
362  else
363  {
364  SetNumberOfCellPixelComponents(NR * NC);
365  SetCellPixelComponentType(MapComponentType<T>::CType);
366  SetCellPixelType(IOPixelEnum::MATRIX);
367  }
368  }
369 
370  template <typename T>
371  void
372  SetPixelType(const std::complex<T> & itkNotUsed(dummy), bool UsePointPixel = true)
373  {
374  if (UsePointPixel)
375  {
376  SetNumberOfPointPixelComponents(2);
377  SetPointPixelComponentType(MapComponentType<T>::CType);
378  SetPointPixelType(IOPixelEnum::COMPLEX);
379  }
380  else
381  {
382  SetNumberOfCellPixelComponents(2);
383  SetCellPixelComponentType(MapComponentType<T>::CType);
384  SetCellPixelType(IOPixelEnum::COMPLEX);
385  }
386  }
387 
388  template <typename T>
389  void
390  SetPixelType(const Array<T> & array, bool UsePointPixel = true)
391  {
392  if (UsePointPixel)
393  {
394  SetNumberOfPointPixelComponents(array.Size());
395  SetPointPixelComponentType(MapComponentType<T>::CType);
396  SetPointPixelType(IOPixelEnum::ARRAY);
397  }
398  else
399  {
400  SetNumberOfCellPixelComponents(array.Size());
401  SetCellPixelComponentType(MapComponentType<T>::CType);
402  SetCellPixelType(IOPixelEnum::ARRAY);
403  }
404  }
405 
406  template <typename T>
407  void
408  SetPixelType(const VariableLengthVector<T> & vector, bool UsePointPixel = true)
409  {
410  if (UsePointPixel)
411  {
412  SetNumberOfPointPixelComponents(vector.Size());
413  SetPointPixelComponentType(MapComponentType<T>::CType);
414  SetPointPixelType(IOPixelEnum::VARIABLELENGTHVECTOR);
415  }
416  else
417  {
418  SetNumberOfCellPixelComponents(vector.Size());
419  SetCellPixelComponentType(MapComponentType<T>::CType);
420  SetCellPixelType(IOPixelEnum::VARIABLELENGTHVECTOR);
421  }
422  }
423 
424  template <typename T>
425  void
426  SetPixelType(const VariableSizeMatrix<T> & matrix, bool UsePointPixel = true)
427  {
428  if (UsePointPixel)
429  {
430  SetNumberOfPointPixelComponents(matrix.Rows() * matrix.Cols());
431  SetPointPixelComponentType(MapComponentType<T>::CType);
432  SetPointPixelType(IOPixelEnum::VARIABLESIZEMATRIX);
433  }
434  else
435  {
436  SetNumberOfCellPixelComponents(matrix.Rows() * matrix.Cols());
437  SetCellPixelComponentType(MapComponentType<T>::CType);
438  SetCellPixelType(IOPixelEnum::VARIABLESIZEMATRIX);
439  }
440  }
441 
446  itkSetMacro(NumberOfPointPixelComponents, unsigned int);
447  itkGetConstMacro(NumberOfPointPixelComponents, unsigned int);
448  itkSetMacro(NumberOfCellPixelComponents, unsigned int);
449  itkGetConstMacro(NumberOfCellPixelComponents, unsigned int);
450  itkSetMacro(PointDimension, unsigned int);
451  itkGetConstMacro(PointDimension, unsigned int);
452  itkSetMacro(NumberOfPoints, SizeValueType);
453  itkGetConstMacro(NumberOfPoints, SizeValueType);
454  itkSetMacro(NumberOfCells, SizeValueType);
455  itkGetConstMacro(NumberOfCells, SizeValueType);
456  itkSetMacro(NumberOfPointPixels, SizeValueType);
457  itkGetConstMacro(NumberOfPointPixels, SizeValueType);
458  itkSetMacro(NumberOfCellPixels, SizeValueType);
459  itkGetConstMacro(NumberOfCellPixels, SizeValueType);
460  itkSetMacro(CellBufferSize, SizeValueType);
461  itkGetConstMacro(CellBufferSize, SizeValueType);
462  itkSetMacro(UpdatePoints, bool);
463  itkGetConstMacro(UpdatePoints, bool);
464  itkSetMacro(UpdateCells, bool);
465  itkGetConstMacro(UpdateCells, bool);
466  itkSetMacro(UpdatePointData, bool);
467  itkGetConstMacro(UpdatePointData, bool);
468  itkSetMacro(UpdateCellData, bool);
469  itkGetConstMacro(UpdateCellData, bool);
471 
472  unsigned int
473  GetComponentSize(IOComponentEnum componentType) const;
474 
477  std::string GetComponentTypeAsString(IOComponentEnum) const;
478 
481  std::string GetPixelTypeAsString(IOPixelEnum) const;
482 
485  itkSetEnumMacro(FileType, IOFileEnum);
486  itkGetEnumMacro(FileType, IOFileEnum);
488 
489  void
491  {
492  this->SetFileType(IOFileEnum::ASCII);
493  }
494 
495  void
497  {
498  this->SetFileType(IOFileEnum::BINARY);
499  }
500 
512  itkSetEnumMacro(ByteOrder, IOByteOrderEnum);
513  itkGetEnumMacro(ByteOrder, IOByteOrderEnum);
515 
516  void
518  {
519  this->SetByteOrder(IOByteOrderEnum::BigEndian);
520  }
521 
522  void
524  {
525  this->SetByteOrder(IOByteOrderEnum::LittleEndian);
526  }
527 
529  itkSetMacro(UseCompression, bool);
530  itkGetConstMacro(UseCompression, bool);
531  itkBooleanMacro(UseCompression);
533 
536  std::string GetFileTypeAsString(IOFileEnum) const;
537 
540  std::string GetByteOrderAsString(IOByteOrderEnum) const;
541 
542  /*-------- This part of the interfaces deals with reading data ----- */
545  virtual bool
546  CanReadFile(const char *) = 0;
547 
550  virtual void
551  ReadMeshInformation() = 0;
552 
554  virtual void
555  ReadPoints(void * buffer) = 0;
556 
557  virtual void
558  ReadCells(void * buffer) = 0;
559 
560  virtual void
561  ReadPointData(void * buffer) = 0;
562 
563  virtual void
564  ReadCellData(void * buffer) = 0;
565 
566  /*-------- This part of the interfaces deals with writing data ----- */
567 
570  virtual bool
571  CanWriteFile(const char *) = 0;
572 
573  virtual void
574  WriteMeshInformation() = 0;
575 
576  virtual void
577  WritePoints(void * buffer) = 0;
578 
579  virtual void
580  WriteCells(void * buffer) = 0;
581 
582  virtual void
583  WritePointData(void * buffer) = 0;
584 
585  virtual void
586  WriteCellData(void * buffer) = 0;
587 
588  virtual void
589  Write() = 0;
590 
595  const ArrayOfExtensionsType &
596  GetSupportedReadExtensions() const;
597 
602  const ArrayOfExtensionsType &
603  GetSupportedWriteExtensions() const;
604 
605 protected:
606  MeshIOBase();
607  ~MeshIOBase() override = default;
608 
609  void
610  PrintSelf(std::ostream & os, Indent indent) const override;
611 
613  void
614  AddSupportedReadExtension(const char * extension);
615 
617  void
618  AddSupportedWriteExtension(const char * extension);
619 
621  template <typename T>
622  void
623  ReadBufferAsAscii(T * buffer, std::ifstream & inputFile, SizeValueType numberOfComponents)
624  {
625  for (SizeValueType i = 0; i < numberOfComponents; i++)
626  {
627  inputFile >> buffer[i];
628  }
629  }
631 
633  template <typename T>
634  void
635  ReadBufferAsBinary(T * buffer, std::ifstream & inputFile, SizeValueType numberOfComponents)
636  {
637  inputFile.read(reinterpret_cast<char *>(buffer), numberOfComponents * sizeof(T));
638 
639  if (m_ByteOrder == IOByteOrderEnum::BigEndian)
640  {
642  {
643  itk::ByteSwapper<T>::SwapRangeFromSystemToBigEndian(buffer, numberOfComponents);
644  }
645  }
646  else if (m_ByteOrder == IOByteOrderEnum::LittleEndian)
647  {
649  {
650  itk::ByteSwapper<T>::SwapRangeFromSystemToLittleEndian(buffer, numberOfComponents);
651  }
652  }
653  }
654 
656  template <typename T>
657  void
658  WriteBufferAsAscii(T * buffer,
659  std::ofstream & outputFile,
660  SizeValueType numberOfLines,
661  SizeValueType numberOfComponents)
662  {
663  NumberToString<T> convert;
664  for (SizeValueType ii = 0; ii < numberOfLines; ii++)
665  {
666  for (SizeValueType jj = 0; jj < numberOfComponents; jj++)
667  {
668  outputFile << convert(buffer[ii * numberOfComponents + jj]) << " ";
669  }
670  outputFile << '\n';
671  }
672  }
674 
676  template <typename TOutput, typename TInput>
677  void
678  WriteBufferAsBinary(TInput * buffer, std::ofstream & outputFile, SizeValueType numberOfComponents)
679  {
680  if (typeid(TInput) == typeid(TOutput))
681  {
683  {
685  }
687  {
689  }
691 
692  outputFile.write(reinterpret_cast<char *>(buffer), numberOfComponents);
693  }
694  else
695  {
696  auto * data = new TOutput[numberOfComponents];
697  for (SizeValueType ii = 0; ii < numberOfComponents; ii++)
698  {
699  data[ii] = static_cast<TOutput>(buffer[ii]);
700  }
701 
703  {
705  }
707  {
709  }
710 
711  outputFile.write(reinterpret_cast<char *>(data), numberOfComponents);
712  delete[] data;
713  }
714  }
715 
719  template <typename TInput, typename TOutput>
720  void
721  ReadCellsBuffer(TInput * input, TOutput * output)
722  {
723  if (input && output)
724  {
727  for (SizeValueType ii = 0; ii < m_NumberOfCells; ii++)
728  {
729  inputIndex++; // ignore the cell type
730  auto numberOfPoints = static_cast<unsigned int>(input[inputIndex++]);
731  for (unsigned int jj = 0; jj < numberOfPoints; jj++)
732  {
733  output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
734  }
735  }
736  }
737  }
739 
743  template <typename TInput, typename TOutput>
744  void
745  ReadCellsBuffer(TInput * input, TOutput * output, CellGeometryEnum type)
746  {
747  if (input && output)
748  {
752 
753  for (SizeValueType ii = 0; ii < m_NumberOfCells; ii++)
754  {
755  auto cellType = static_cast<CellGeometryEnum>(input[inputIndex++]);
756  auto nn = static_cast<unsigned int>(input[inputIndex++]);
757  if (cellType == type)
758  {
759  output[outputIndex++] = nn;
760  for (unsigned int jj = 0; jj < nn; jj++)
761  {
762  output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
763  }
764  }
765  else
766  {
767  inputIndex += nn;
768  }
769  }
770  }
771  }
772 
775  template <typename TInput, typename TOutput>
776  void
777  WriteCellsBuffer(TInput * input,
778  TOutput * output,
779  CellGeometryEnum cellType,
780  unsigned int numberOfPoints,
781  SizeValueType numberOfCells)
782  {
783  if (input && output)
784  {
787  for (SizeValueType ii = 0; ii < numberOfCells; ii++)
788  {
789  output[outputIndex++] = static_cast<TOutput>(cellType);
790  output[outputIndex++] = static_cast<TOutput>(numberOfPoints);
791  for (unsigned int jj = 0; jj < numberOfPoints; jj++)
792  {
793  output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
794  }
795  }
796  }
797  }
799 
802  template <typename TInput, typename TOutput>
803  void
804  WriteCellsBuffer(TInput * input, TOutput * output, CellGeometryEnum cellType, SizeValueType numberOfCells)
805  {
806  if (input && output)
807  {
810  for (SizeValueType ii = 0; ii < numberOfCells; ii++)
811  {
812  auto numberOfPoints = static_cast<unsigned int>(input[inputIndex++]);
813  output[outputIndex++] = static_cast<TOutput>(cellType);
814  output[outputIndex++] = static_cast<TOutput>(numberOfPoints);
815  for (unsigned int jj = 0; jj < numberOfPoints; jj++)
816  {
817  output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
818  }
819  }
820  }
821  }
823 
824 protected:
828 
830  std::string m_FileName;
831 
833  bool m_UseCompression{ false };
834 
840 
842  IOPixelEnum m_PointPixelType{ IOPixelEnum::SCALAR };
843  IOPixelEnum m_CellPixelType{ IOPixelEnum::SCALAR };
844 
847  unsigned int m_NumberOfPointPixelComponents{ 0 };
848  unsigned int m_NumberOfCellPixelComponents{ 0 };
849 
851  unsigned int m_PointDimension{ 3 };
852 
858 
861 
864  bool m_UpdatePoints{ false };
865  bool m_UpdateCells{ false };
866  bool m_UpdatePointData{ false };
867  bool m_UpdateCellData{ false };
868 
869 private:
872 };
873 #define MESHIOBASE_TYPEMAP(type, ctype) \
874  template <> \
875  struct MeshIOBase::MapComponentType<type> \
876  { \
877  static constexpr IOComponentEnum CType = ctype; \
878  }
879 
893 #undef MESHIOBASE_TYPEMAP
894 } // end namespace itk
895 
896 #endif
itk::MeshIOBase::SetPixelType
void SetPixelType(const Matrix< T, NR, NC > &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:354
itk::CommonEnums::IOByteOrder::LittleEndian
itk::MeshIOBase::ArrayOfExtensionsType
std::vector< std::string > ArrayOfExtensionsType
Definition: itkMeshIOBase.h:83
itk::CommonEnums::IOComponent::CHAR
itk::MeshIOBase::SetPixelType
void SetPixelType(const VariableSizeMatrix< T > &matrix, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:426
itk::CommonEnums::IOPixel::RGBA
itk::LightProcessObject
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Definition: itkLightProcessObject.h:72
itk::CommonEnums::IOPixel::OFFSET
itk::RGBPixel
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
itk::NumberToString
Convert floating and fixed point numbers to strings.
Definition: itkNumberToString.h:42
itk::CommonEnums::IOFile
IOFile
Definition: itkCommonEnums.h:100
itk::CommonEnums::IOFile::BINARY
itk::CommonEnums::IOByteOrder::BigEndian
itkCovariantVector.h
itk::MeshIOBase::WriteBufferAsBinary
void WriteBufferAsBinary(TInput *buffer, std::ofstream &outputFile, SizeValueType numberOfComponents)
Definition: itkMeshIOBase.h:678
itkByteSwapper.h
itk::MeshIOBase::SetPixelType
void SetPixelType(const T &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:210
itkRGBPixel.h
itk::MeshIOBase::SetFileTypeToASCII
void SetFileTypeToASCII()
Definition: itkMeshIOBase.h:490
itk::CommonEnums::IOComponent::USHORT
itk::CommonEnums::CellGeometry::MAX_ITK_CELLS
itk::MeshIOBase::SizeValueType
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:88
itk::CommonEnums::IOPixel::ARRAY
itk::MeshIOBase::SetPixelType
void SetPixelType(const SymmetricSecondRankTensor< T, VLength >, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:318
itkVariableSizeMatrix.h
itkMatrix.h
itk::CommonEnums::IOByteOrder
IOByteOrder
Definition: itkCommonEnums.h:127
itk::CommonEnums::CellGeometry::LINE_CELL
itk::CommonEnums::IOComponent::SHORT
itk::CommonEnums::CellGeometry::VERTEX_CELL
itk::CommonEnums::IOPixel::VECTOR
itk::CommonEnums::IOPixel::SCALAR
itk::CommonEnums::CellGeometry::TRIANGLE_CELL
itkLightProcessObject.h
itk::CommonEnums::IOFileMode
IOFileMode
Definition: itkCommonEnums.h:115
itkVariableLengthVector.h
itk::CommonEnums::IOComponent::ULONG
itk::CommonEnums::IOComponent::UINT
itkDiffusionTensor3D.h
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::MeshIOBase
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:71
itk::DiffusionTensor3D
Represent a diffusion tensor as used in DTI images.
Definition: itkDiffusionTensor3D.h:79
itk::CommonEnums::CellGeometry::QUADRATIC_TRIANGLE_CELL
itkRGBAPixel.h
itk::CommonEnums::IOPixel::COVARIANTVECTOR
itk::MeshIOBase::ReadCellsBuffer
void ReadCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum type)
Definition: itkMeshIOBase.h:745
itk::SmartPointer< const Self >
itk::CommonEnums::IOPixel::SYMMETRICSECONDRANKTENSOR
itk::CommonEnums::IOComponent
IOComponent
Definition: itkCommonEnums.h:76
itk::MeshIOBase::SetPixelType
void SetPixelType(const RGBPixel< T > &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:228
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::CommonEnums::CellGeometry::HEXAHEDRON_CELL
itk::CommonEnums::IOComponent::UCHAR
itk::MeshIOBase::SetPixelType
void SetPixelType(const DiffusionTensor3D< T > &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:336
itk::VariableSizeMatrix
A templated class holding a M x N size Matrix.
Definition: itkVariableSizeMatrix.h:45
itk::MeshIOBase::m_NumberOfPointPixels
SizeValueType m_NumberOfPointPixels
Definition: itkMeshIOBase.h:856
itk::CommonEnums::IOPixel
IOPixel
Definition: itkCommonEnums.h:49
itk::CommonEnums::IOComponent::DOUBLE
itk::MeshIOBase::m_SupportedReadExtensions
ArrayOfExtensionsType m_SupportedReadExtensions
Definition: itkMeshIOBase.h:870
itk::MeshIOBase::m_NumberOfPoints
SizeValueType m_NumberOfPoints
Definition: itkMeshIOBase.h:854
itk::CommonEnums::IOComponent::LONGLONG
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:623
itk::MeshIOBase::WriteCellsBuffer
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum cellType, SizeValueType numberOfCells)
Definition: itkMeshIOBase.h:804
itk::CommonEnums::IOPixel::DIFFUSIONTENSOR3D
itk::MeshIOBase::m_CellBufferSize
SizeValueType m_CellBufferSize
Definition: itkMeshIOBase.h:860
itk::MeshIOBase::SetPixelType
void SetPixelType(const RGBAPixel< T > &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:246
itk::MeshIOBase::SetPixelType
void SetPixelType(const CovariantVector< T, VLength > &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:282
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL
itk::CommonEnums::IOPixel::FIXEDARRAY
itkNumberToString.h
itk::MeshIOBase::WriteBufferAsAscii
void WriteBufferAsAscii(T *buffer, std::ofstream &outputFile, SizeValueType numberOfLines, SizeValueType numberOfComponents)
Definition: itkMeshIOBase.h:658
itk::MeshIOBase::ReadCellsBuffer
void ReadCellsBuffer(TInput *input, TOutput *output)
Definition: itkMeshIOBase.h:721
itk::CommonEnums::IOPixel::MATRIX
itk::CommonEnums::IOComponent::LONG
itk::ByteSwapper::SwapRangeFromSystemToBigEndian
static void SwapRangeFromSystemToBigEndian(T *p, BufferSizeType num)
itk::MeshIOBase::m_NumberOfCells
SizeValueType m_NumberOfCells
Definition: itkMeshIOBase.h:855
itk::CommonEnums::IOPixel::RGB
itkSymmetricSecondRankTensor.h
itk::CommonEnums::IOFileMode::WriteMode
itk::MeshIOBase::SetFileTypeToBinary
void SetFileTypeToBinary()
Definition: itkMeshIOBase.h:496
itk::ByteSwapper
Perform machine dependent byte swapping.
Definition: itkByteSwapper.h:50
itk::CommonEnums::IOByteOrder::OrderNotApplicable
itk::VariableSizeMatrix::Cols
unsigned int Cols() const
Definition: itkVariableSizeMatrix.h:238
itk::CommonEnums::IOPixel::POINT
itk::MeshIOBase::UnknownType
Definition: itkMeshIOBase.h:95
itk::MeshIOBase::ReadBufferAsBinary
void ReadBufferAsBinary(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
Definition: itkMeshIOBase.h:635
itk::CommonEnums::IOComponent::ULONGLONG
itk::MeshIOBase::SetPixelType
void SetPixelType(const Array< T > &array, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:390
itk::MeshIOBase::MapComponentType
Definition: itkMeshIOBase.h:203
itk::MeshIOBase::SetPixelType
void SetPixelType(const VariableLengthVector< T > &vector, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:408
itk::CommonEnums::IOComponent::INT
itk::VariableLengthVector::Size
unsigned int Size() const
Definition: itkVariableLengthVector.h:592
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:52
itk::CommonEnums::CellGeometry
CellGeometry
Definition: itkCommonEnums.h:138
itk::Matrix
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:51
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itk::CommonEnums::IOPixel::VARIABLESIZEMATRIX
itk::RGBAPixel
Represent Red, Green, Blue and Alpha components for color images.
Definition: itkRGBAPixel.h:59
itk::CommonEnums::CellGeometry::TETRAHEDRON_CELL
itk::CommonEnums::IOPixel::UNKNOWNPIXELTYPE
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkCommonEnums.h
itk::MeshIOBase::SetPixelType
void SetPixelType(const Vector< T, VLength > &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:264
itk::CommonEnums::IOPixel::COMPLEX
itk::MeshIOBase::SetPixelType
void SetPixelType(const FixedArray< T, VLength > &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:300
itkVector.h
itk::CommonEnums::IOFile::ASCII
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::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::CommonEnums::IOComponent::UNKNOWNCOMPONENTTYPE
itkCellInterface.h
itk::Array::Size
SizeValueType Size() const
Definition: itkArray.h:131
itk::MeshIOBase::SetPixelType
void SetPixelType(const std::complex< T > &, bool UsePointPixel=true)
Definition: itkMeshIOBase.h:372
itk::MeshIOBase::m_FileName
std::string m_FileName
Definition: itkMeshIOBase.h:830
itk::MeshIOBase::SetByteOrderToLittleEndian
void SetByteOrderToLittleEndian()
Definition: itkMeshIOBase.h:523
itk::MeshIOBase::WriteCellsBuffer
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum cellType, unsigned int numberOfPoints, SizeValueType numberOfCells)
Definition: itkMeshIOBase.h:777
itk::MeshIOBase::m_SupportedWriteExtensions
ArrayOfExtensionsType m_SupportedWriteExtensions
Definition: itkMeshIOBase.h:871
itk::CommonEnums::IOFile::TYPENOTAPPLICABLE
itk::MESHIOBASE_TYPEMAP
MESHIOBASE_TYPEMAP(unsigned char, IOComponentEnum::UCHAR)
itk::VariableSizeMatrix::Rows
unsigned int Rows() const
Definition: itkVariableSizeMatrix.h:231
itk::CommonEnums::CellGeometry::POLYGON_CELL
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
itk::CommonEnums::IOComponent::FLOAT
itk::CommonEnums::IOPixel::VARIABLELENGTHVECTOR
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::MeshIOBase::StreamOffsetType
std::streamoff StreamOffsetType
Definition: itkMeshIOBase.h:86
itk::CommonEnums::IOComponent::LDOUBLE
itk::CommonEnums::CellGeometry::LAST_ITK_CELL
itk::CommonEnums::IOFileMode::ReadMode
itk::MeshIOBase::m_NumberOfCellPixels
SizeValueType m_NumberOfCellPixels
Definition: itkMeshIOBase.h:857
itk::CommonEnums::CellGeometry::QUADRILATERAL_CELL
itk::MeshIOBase::SetByteOrderToBigEndian
void SetByteOrderToBigEndian()
Definition: itkMeshIOBase.h:517