ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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"
26#include "itkIntTypes.h"
28#include "itkMatrix.h"
29#include "itkRGBPixel.h"
30#include "itkRGBAPixel.h"
34#include "itkVector.h"
35#include "itkNumberToString.h"
36#include "itkCommonEnums.h"
38
39#include <string>
40#include <complex>
41#include <fstream>
42
43namespace itk
44{
71
72class ITKIOMeshBase_EXPORT MeshIOBase : public LightProcessObject
73{
74public:
75 ITK_DISALLOW_COPY_AND_MOVE(MeshIOBase);
76
82
84 using ArrayOfExtensionsType = std::vector<std::string>;
85
87 using StreamOffsetType = std::streamoff;
88
90
97 {};
98
100 itkOverrideGetNameOfClassMacro(MeshIOBase);
101
104 itkSetStringMacro(FileName);
105 itkGetStringMacro(FileName);
107#if !defined(ITK_LEGACY_REMOVE)
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)
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)
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)
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)
161 static constexpr IOFileModeEnum ReadMode = IOFileModeEnum::ReadMode;
162 static constexpr IOFileModeEnum WriteMode = IOFileModeEnum::WriteMode;
163#endif
164
165#if !defined(ITK_LEGACY_REMOVE)
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
186 itkSetEnumMacro(PointPixelType, itk::CommonEnums::IOPixel);
187 itkGetEnumMacro(PointPixelType, itk::CommonEnums::IOPixel);
188 itkSetEnumMacro(CellPixelType, itk::CommonEnums::IOPixel);
189 itkGetEnumMacro(CellPixelType, itk::CommonEnums::IOPixel);
194 itkSetEnumMacro(PointComponentType, itk::CommonEnums::IOComponent);
195 itkGetEnumMacro(PointComponentType, itk::CommonEnums::IOComponent);
196 itkSetEnumMacro(CellComponentType, itk::CommonEnums::IOComponent);
197 itkGetEnumMacro(CellComponentType, itk::CommonEnums::IOComponent);
198 itkSetEnumMacro(PointPixelComponentType, itk::CommonEnums::IOComponent);
199 itkGetEnumMacro(PointPixelComponentType, itk::CommonEnums::IOComponent);
200 itkSetEnumMacro(CellPixelComponentType, itk::CommonEnums::IOComponent);
201 itkGetEnumMacro(CellPixelComponentType, itk::CommonEnums::IOComponent);
203 template <typename T>
205 {
206 static constexpr IOComponentEnum CType = IOComponentEnum::UNKNOWNCOMPONENTTYPE;
207 };
208
209 template <typename T>
210 void
211 SetPixelType(const T & itkNotUsed(dummy), bool usePointPixel = true)
212 {
213 if (usePointPixel)
214 {
217 SetPointPixelType(IOPixelEnum::SCALAR);
218 }
219 else
220 {
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 {
235 SetPointPixelType(IOPixelEnum::RGB);
236 }
237 else
238 {
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 {
253 SetPointPixelType(IOPixelEnum::RGBA);
254 }
255 else
256 {
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 {
271 SetPointPixelType(IOPixelEnum::VECTOR);
272 }
273 else
274 {
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 {
289 SetPointPixelType(IOPixelEnum::COVARIANTVECTOR);
290 }
291 else
292 {
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 {
307 SetPointPixelType(IOPixelEnum::FIXEDARRAY);
308 }
309 else
310 {
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);
325 SetPointPixelType(IOPixelEnum::SYMMETRICSECONDRANKTENSOR);
326 }
327 else
328 {
329 SetNumberOfCellPixelComponents(VLength * (VLength + 1) / 2);
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 {
343 SetPointPixelType(IOPixelEnum::DIFFUSIONTENSOR3D);
344 }
345 else
346 {
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);
361 SetPointPixelType(IOPixelEnum::MATRIX);
362 }
363 else
364 {
365 SetNumberOfCellPixelComponents(VRows * VColumns);
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 {
379 SetPointPixelType(IOPixelEnum::COMPLEX);
380 }
381 else
382 {
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 {
397 SetPointPixelType(IOPixelEnum::ARRAY);
398 }
399 else
400 {
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());
415 SetPointPixelType(IOPixelEnum::VARIABLELENGTHVECTOR);
416 }
417 else
418 {
419 SetNumberOfCellPixelComponents(vector.Size());
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());
433 SetPointPixelType(IOPixelEnum::VARIABLESIZEMATRIX);
434 }
435 else
436 {
437 SetNumberOfCellPixelComponents(matrix.Rows() * matrix.Cols());
439 SetCellPixelType(IOPixelEnum::VARIABLESIZEMATRIX);
440 }
441 }
442
448 itkSetMacro(NumberOfPointPixelComponents, unsigned int);
449 itkGetConstMacro(NumberOfPointPixelComponents, unsigned int);
450 itkSetMacro(NumberOfCellPixelComponents, unsigned int);
451 itkGetConstMacro(NumberOfCellPixelComponents, unsigned int);
452 itkSetMacro(PointDimension, unsigned int);
453 itkGetConstMacro(PointDimension, unsigned int);
454 itkSetMacro(NumberOfPoints, SizeValueType);
455 itkGetConstMacro(NumberOfPoints, SizeValueType);
456 itkSetMacro(NumberOfCells, SizeValueType);
457 itkGetConstMacro(NumberOfCells, SizeValueType);
458 itkSetMacro(NumberOfPointPixels, SizeValueType);
459 itkGetConstMacro(NumberOfPointPixels, SizeValueType);
460 itkSetMacro(NumberOfCellPixels, SizeValueType);
461 itkGetConstMacro(NumberOfCellPixels, SizeValueType);
462 itkSetMacro(CellBufferSize, SizeValueType);
463 itkGetConstMacro(CellBufferSize, SizeValueType);
464 itkSetMacro(UpdatePoints, bool);
465 itkGetConstMacro(UpdatePoints, bool);
466 itkBooleanMacro(UpdatePoints);
467 itkSetMacro(UpdateCells, bool);
468 itkGetConstMacro(UpdateCells, bool);
469 itkBooleanMacro(UpdateCells);
470 itkSetMacro(UpdatePointData, bool);
471 itkGetConstMacro(UpdatePointData, bool);
472 itkBooleanMacro(UpdatePointData);
473 itkSetMacro(UpdateCellData, bool);
474 itkGetConstMacro(UpdateCellData, bool);
475 itkBooleanMacro(UpdateCellData);
477 unsigned int
478 GetComponentSize(IOComponentEnum componentType) const;
479
483
487
491 itkSetEnumMacro(FileType, IOFileEnum);
492 itkGetEnumMacro(FileType, IOFileEnum);
494 void
496 {
497 this->SetFileType(IOFileEnum::ASCII);
498 }
499
500 void
502 {
503 this->SetFileType(IOFileEnum::BINARY);
504 }
505
518 itkSetEnumMacro(ByteOrder, IOByteOrderEnum);
519 itkGetEnumMacro(ByteOrder, IOByteOrderEnum);
521 void
523 {
524 this->SetByteOrder(IOByteOrderEnum::BigEndian);
525 }
526
527 void
529 {
530 this->SetByteOrder(IOByteOrderEnum::LittleEndian);
531 }
532
535 itkSetMacro(UseCompression, bool);
536 itkGetConstMacro(UseCompression, bool);
537 itkBooleanMacro(UseCompression);
541 std::string GetFileTypeAsString(IOFileEnum) const;
542
546
547 /*-------- This part of the interfaces deals with reading data ----- */
550 virtual bool
551 CanReadFile(const char *) = 0;
552
555 virtual void
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
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
602
609
610protected:
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 }
635
637 template <typename T>
638 void
639 ReadBufferAsBinary(T * buffer, std::ifstream & inputFile, SizeValueType numberOfComponents)
640 {
641 inputFile.read(reinterpret_cast<char *>(buffer), numberOfComponents * sizeof(T));
642
643 if (m_ByteOrder == IOByteOrderEnum::BigEndian)
644 {
646 {
647 itk::ByteSwapper<T>::SwapRangeFromSystemToBigEndian(buffer, numberOfComponents);
648 }
649 }
650 else if (m_ByteOrder == IOByteOrderEnum::LittleEndian)
651 {
653 {
655 }
656 }
657 }
658
660 template <typename T>
661 void
663 std::ofstream & outputFile,
664 SizeValueType numberOfLines,
665 SizeValueType numberOfComponents)
666 {
667 for (SizeValueType ii = 0; ii < numberOfLines; ++ii)
668 {
669 for (SizeValueType jj = 0; jj < numberOfComponents; ++jj)
670 {
671 outputFile << ConvertNumberToString(buffer[ii * numberOfComponents + jj]) << " ";
672 }
673 outputFile << '\n';
674 }
675 }
676
678 template <typename TOutput, typename TInput>
679 void
680 WriteBufferAsBinary(TInput * buffer, std::ofstream & outputFile, SizeValueType numberOfComponents)
681 {
682 if (typeid(TInput) == typeid(TOutput))
683 {
684 if (m_ByteOrder == IOByteOrderEnum::BigEndian && itk::ByteSwapper<TInput>::SystemIsLittleEndian())
685 {
687 }
688 else if (m_ByteOrder == IOByteOrderEnum::LittleEndian && itk::ByteSwapper<TInput>::SystemIsBigEndian())
689 {
691 }
692
693 outputFile.write(reinterpret_cast<char *>(buffer), numberOfComponents);
694 }
695 else
696 {
697 const auto data = make_unique_for_overwrite<TOutput[]>(numberOfComponents);
698 for (SizeValueType ii = 0; ii < numberOfComponents; ++ii)
699 {
700 data[ii] = static_cast<TOutput>(buffer[ii]);
701 }
702
703 if (m_ByteOrder == IOByteOrderEnum::BigEndian && itk::ByteSwapper<TOutput>::SystemIsLittleEndian())
704 {
705 itk::ByteSwapper<TOutput>::SwapRangeFromSystemToBigEndian(data.get(), numberOfComponents);
706 }
707 else if (m_ByteOrder == IOByteOrderEnum::LittleEndian && itk::ByteSwapper<TOutput>::SystemIsBigEndian())
708 {
710 }
711
712 outputFile.write(reinterpret_cast<char *>(data.get()), numberOfComponents);
713 }
714 }
715
719 template <typename TInput, typename TOutput>
720 void
721 ReadCellsBuffer(TInput * input, TOutput * output)
722 {
723 if (input && output)
724 {
725 SizeValueType inputIndex{};
726 SizeValueType outputIndex{};
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 }
738
742 template <typename TInput, typename TOutput>
743 void
744 ReadCellsBuffer(TInput * input, TOutput * output, CellGeometryEnum type)
745 {
746 if (input && output)
747 {
748 SizeValueType inputIndex{};
749 SizeValueType outputIndex{};
750
751 for (SizeValueType ii = 0; ii < m_NumberOfCells; ++ii)
752 {
753 auto cellType = static_cast<CellGeometryEnum>(input[inputIndex++]);
754 auto nn = static_cast<unsigned int>(input[inputIndex++]);
755 if (cellType == type)
756 {
757 output[outputIndex++] = nn;
758 for (unsigned int jj = 0; jj < nn; ++jj)
759 {
760 output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
761 }
762 }
763 else
764 {
765 inputIndex += nn;
766 }
767 }
768 }
769 }
770
773 template <typename TInput, typename TOutput>
774 void
775 WriteCellsBuffer(TInput * input,
776 TOutput * output,
777 CellGeometryEnum cellType,
778 unsigned int numberOfPoints,
779 SizeValueType numberOfCells)
780 {
781 if (input && output)
782 {
783 SizeValueType inputIndex{};
784 SizeValueType outputIndex{};
785 for (SizeValueType ii = 0; ii < numberOfCells; ++ii)
786 {
787 output[outputIndex++] = static_cast<TOutput>(cellType);
788 output[outputIndex++] = static_cast<TOutput>(numberOfPoints);
789 for (unsigned int jj = 0; jj < numberOfPoints; ++jj)
790 {
791 output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
792 }
793 }
794 }
795 }
796
799 template <typename TInput, typename TOutput>
800 void
801 WriteCellsBuffer(TInput * input, TOutput * output, CellGeometryEnum cellType, SizeValueType numberOfCells)
802 {
803 if (input && output)
804 {
805 SizeValueType inputIndex{};
806 SizeValueType outputIndex{};
807 for (SizeValueType ii = 0; ii < numberOfCells; ++ii)
808 {
809 auto numberOfPoints = static_cast<unsigned int>(input[inputIndex++]);
810 if (numberOfPoints > 2 && cellType == CellGeometryEnum::LINE_CELL)
811 {
812 output[outputIndex++] = static_cast<TOutput>(CellGeometryEnum::POLYLINE_CELL);
813 }
814 else
815 {
816 output[outputIndex++] = static_cast<TOutput>(cellType);
817 }
818 output[outputIndex++] = static_cast<TOutput>(numberOfPoints);
819
820 for (unsigned int jj = 0; jj < numberOfPoints; ++jj)
821 {
822 output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
823 }
824 }
825 }
826 }
827
828protected:
830 IOByteOrderEnum m_ByteOrder{ IOByteOrderEnum::OrderNotApplicable };
831 IOFileEnum m_FileType{ IOFileEnum::ASCII };
832
834 std::string m_FileName{};
835
837 bool m_UseCompression{ false };
838
840 IOComponentEnum m_PointComponentType{ IOComponentEnum::UNKNOWNCOMPONENTTYPE };
841 IOComponentEnum m_CellComponentType{ IOComponentEnum::UNKNOWNCOMPONENTTYPE };
842 IOComponentEnum m_PointPixelComponentType{ IOComponentEnum::UNKNOWNCOMPONENTTYPE };
843 IOComponentEnum m_CellPixelComponentType{ IOComponentEnum::UNKNOWNCOMPONENTTYPE };
844
846 IOPixelEnum m_PointPixelType{ IOPixelEnum::SCALAR };
847 IOPixelEnum m_CellPixelType{ IOPixelEnum::SCALAR };
848
853
855 unsigned int m_PointDimension{ 3 };
856
862
865
868 bool m_UpdatePoints{ false };
869 bool m_UpdateCells{ false };
870 bool m_UpdatePointData{ false };
871 bool m_UpdateCellData{ false };
872
873private:
876};
877#define MESHIOBASE_TYPEMAP(type, ctype) \
878 template <> \
879 struct MeshIOBase::MapComponentType<type> \
880 { \
881 static constexpr IOComponentEnum CType = ctype; \
882 }
883
884MESHIOBASE_TYPEMAP(unsigned char, IOComponentEnum::UCHAR);
885MESHIOBASE_TYPEMAP(char, IOComponentEnum::CHAR);
886MESHIOBASE_TYPEMAP(unsigned short, IOComponentEnum::USHORT);
887MESHIOBASE_TYPEMAP(short, IOComponentEnum::SHORT);
888MESHIOBASE_TYPEMAP(unsigned int, IOComponentEnum::UINT);
889MESHIOBASE_TYPEMAP(int, IOComponentEnum::INT);
890MESHIOBASE_TYPEMAP(unsigned long, IOComponentEnum::ULONG);
891MESHIOBASE_TYPEMAP(long, IOComponentEnum::LONG);
892MESHIOBASE_TYPEMAP(unsigned long long, IOComponentEnum::ULONGLONG);
893MESHIOBASE_TYPEMAP(long long, IOComponentEnum::LONGLONG);
894MESHIOBASE_TYPEMAP(float, IOComponentEnum::FLOAT);
895MESHIOBASE_TYPEMAP(double, IOComponentEnum::DOUBLE);
896MESHIOBASE_TYPEMAP(long double, IOComponentEnum::LDOUBLE);
897#undef MESHIOBASE_TYPEMAP
898} // end namespace itk
899
900#endif
Array class with size defined at construction time.
Definition itkArray.h:48
SizeValueType Size() const
Definition itkArray.h:130
static constexpr bool SystemIsBigEndian()
static void SwapRangeFromSystemToLittleEndian(T *p, BufferSizeType num)
static constexpr bool SystemIsLittleEndian()
static void SwapRangeFromSystemToBigEndian(T *p, BufferSizeType num)
A templated class holding a n-Dimensional covariant vector.
Represent a diffusion tensor as used in DTI images.
Simulate a standard C array with copy semantics.
Control indentation during Print() invocation.
Definition itkIndent.h:50
A templated class holding a M x N size Matrix.
Definition itkMatrix.h:53
IOPixelEnum m_CellPixelType
virtual void SetFileType(const IOFileEnum _arg)
void ReadCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum type)
void WriteBufferAsBinary(TInput *buffer, std::ofstream &outputFile, SizeValueType numberOfComponents)
void SetPixelType(const FixedArray< T, VLength > &dummy, bool usePointPixel=true)
unsigned int m_NumberOfPointPixelComponents
IOByteOrderEnum m_ByteOrder
SmartPointer< Self > Pointer
std::string GetPixelTypeAsString(IOPixelEnum) const
virtual void SetPointPixelComponentType(const itk::CommonEnums::IOComponent _arg)
SizeValueType m_NumberOfPoints
void SetPixelType(const T &dummy, bool usePointPixel=true)
void WriteBufferAsAscii(T *buffer, std::ofstream &outputFile, SizeValueType numberOfLines, SizeValueType numberOfComponents)
virtual void Write()=0
IOFileEnum m_FileType
SizeValueType m_CellBufferSize
void SetFileTypeToBinary()
std::string GetFileTypeAsString(IOFileEnum) const
IdentifierType SizeValueType
void SetPixelType(const VariableSizeMatrix< T > &matrix, bool usePointPixel=true)
virtual void ReadPointData(void *buffer)=0
virtual void SetByteOrder(const IOByteOrderEnum _arg)
virtual void WritePoints(void *buffer)=0
std::string GetComponentTypeAsString(IOComponentEnum) const
ArrayOfExtensionsType m_SupportedReadExtensions
void SetPixelType(const RGBPixel< T > &dummy, bool usePointPixel=true)
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum cellType, unsigned int numberOfPoints, SizeValueType numberOfCells)
virtual void WriteMeshInformation()=0
virtual void WriteCells(void *buffer)=0
unsigned int m_PointDimension
unsigned int GetComponentSize(IOComponentEnum componentType) const
void AddSupportedReadExtension(const char *extension)
virtual void ReadMeshInformation()=0
virtual void ReadCells(void *buffer)=0
std::string m_FileName
virtual void SetNumberOfCellPixelComponents(unsigned int _arg)
IOPixelEnum m_PointPixelType
void SetPixelType(const Vector< T, VLength > &dummy, bool usePointPixel=true)
void SetPixelType(const RGBAPixel< T > &dummy, bool usePointPixel=true)
virtual bool CanReadFile(const char *)=0
void ReadBufferAsBinary(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
void SetPixelType(const std::complex< T > &dummy, bool usePointPixel=true)
SmartPointer< const Self > ConstPointer
const ArrayOfExtensionsType & GetSupportedReadExtensions() const
virtual void SetNumberOfPointPixelComponents(unsigned int _arg)
virtual void WriteCellData(void *buffer)=0
void SetPixelType(const VariableLengthVector< T > &vector, bool usePointPixel=true)
IOComponentEnum m_PointComponentType
std::string GetByteOrderAsString(IOByteOrderEnum) const
IOComponentEnum m_CellPixelComponentType
void ReadCellsBuffer(TInput *input, TOutput *output)
void PrintSelf(std::ostream &os, Indent indent) const override
void SetPixelType(const DiffusionTensor3D< T > &dummy, bool usePointPixel=true)
const ArrayOfExtensionsType & GetSupportedWriteExtensions() const
void SetPixelType(const SymmetricSecondRankTensor< T, VLength > dummy, bool usePointPixel=true)
SizeValueType m_NumberOfPointPixels
SizeValueType m_NumberOfCellPixels
virtual bool CanWriteFile(const char *)=0
void SetByteOrderToBigEndian()
IOComponentEnum m_PointPixelComponentType
std::streamoff StreamOffsetType
virtual void SetCellPixelComponentType(const itk::CommonEnums::IOComponent _arg)
void SetPixelType(const Matrix< T, VRows, VColumns > &dummy, bool usePointPixel=true)
~MeshIOBase() override=default
void SetByteOrderToLittleEndian()
void SetFileTypeToASCII()
virtual void WritePointData(void *buffer)=0
virtual void SetCellPixelType(const itk::CommonEnums::IOPixel _arg)
std::vector< std::string > ArrayOfExtensionsType
IOComponentEnum m_CellComponentType
LightProcessObject Superclass
MeshIOBase Self
virtual void ReadCellData(void *buffer)=0
void SetPixelType(const Array< T > &array, bool usePointPixel=true)
void AddSupportedWriteExtension(const char *extension)
ArrayOfExtensionsType m_SupportedWriteExtensions
virtual void ReadPoints(void *buffer)=0
void ReadBufferAsAscii(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
virtual void SetPointPixelType(const itk::CommonEnums::IOPixel _arg)
unsigned int m_NumberOfCellPixelComponents
void SetPixelType(const CovariantVector< T, VLength > &dummy, bool usePointPixel=true)
SizeValueType m_NumberOfCells
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum cellType, SizeValueType numberOfCells)
Represent Red, Green, Blue and Alpha components for color images.
Represent Red, Green and Blue components for color images.
Definition itkRGBPixel.h:59
Implements transparent reference counting.
Represent a symmetric tensor of second rank.
A templated class holding a M x N size Matrix.
A templated class holding a n-Dimensional vector.
Definition itkVector.h:63
#define MESHIOBASE_TYPEMAP(type, ctype)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
SizeValueType IdentifierType
Definition itkIntTypes.h:90
CommonEnums::IOComponent IOComponentEnum
std::string ConvertNumberToString(const TValue val)
CommonEnums::IOFile IOFileEnum
CommonEnums::IOByteOrder IOByteOrderEnum
CommonEnums::CellGeometry CellGeometryEnum
CommonEnums::IOPixel IOPixelEnum
CommonEnums::IOFileMode IOFileModeEnum
auto make_unique_for_overwrite(const vcl_size_t numberOfElements)
static constexpr IOComponentEnum CType