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 <type_traits> // For is_same_v.
41#include <complex>
42#include <fstream>
43
44namespace itk
45{
72
73class ITKIOMeshBase_EXPORT MeshIOBase : public LightProcessObject
74{
75public:
76 ITK_DISALLOW_COPY_AND_MOVE(MeshIOBase);
77
83
85 using ArrayOfExtensionsType = std::vector<std::string>;
86
88 using StreamOffsetType = std::streamoff;
89
91
92#ifndef ITK_LEGACY_REMOVE
98 class [[deprecated("This class is intended to be removed from ITK 6.")]] UnknownType
99 {};
100#endif
101
103 itkOverrideGetNameOfClassMacro(MeshIOBase);
104
107 itkSetStringMacro(FileName);
108 itkGetStringMacro(FileName);
110#if !defined(ITK_LEGACY_REMOVE)
112 static constexpr IOPixelEnum UNKNOWNPIXELTYPE = IOPixelEnum::UNKNOWNPIXELTYPE;
113 static constexpr IOPixelEnum SCALAR = IOPixelEnum::SCALAR;
114 static constexpr IOPixelEnum RGB = IOPixelEnum::RGB;
115 static constexpr IOPixelEnum RGBA = IOPixelEnum::RGBA;
116 static constexpr IOPixelEnum OFFSET = IOPixelEnum::OFFSET;
117 static constexpr IOPixelEnum VECTOR = IOPixelEnum::VECTOR;
118 static constexpr IOPixelEnum POINT = IOPixelEnum::POINT;
119 static constexpr IOPixelEnum COVARIANTVECTOR = IOPixelEnum::COVARIANTVECTOR;
120 static constexpr IOPixelEnum SYMMETRICSECONDRANKTENSOR = IOPixelEnum::SYMMETRICSECONDRANKTENSOR;
121 static constexpr IOPixelEnum DIFFUSIONTENSOR3D = IOPixelEnum::DIFFUSIONTENSOR3D;
122 static constexpr IOPixelEnum COMPLEX = IOPixelEnum::COMPLEX;
123 static constexpr IOPixelEnum FIXEDARRAY = IOPixelEnum::FIXEDARRAY;
124 static constexpr IOPixelEnum ARRAY = IOPixelEnum::ARRAY;
125 static constexpr IOPixelEnum MATRIX = IOPixelEnum::MATRIX;
126 static constexpr IOPixelEnum VARIABLELENGTHVECTOR = IOPixelEnum::VARIABLELENGTHVECTOR;
127 static constexpr IOPixelEnum VARIABLESIZEMATRIX = IOPixelEnum::VARIABLESIZEMATRIX;
128#endif
129
130#if !defined(ITK_LEGACY_REMOVE)
132 static constexpr IOComponentEnum UNKNOWNCOMPONENTTYPE = IOComponentEnum::UNKNOWNCOMPONENTTYPE;
133 static constexpr IOComponentEnum UCHAR = IOComponentEnum::UCHAR;
134 static constexpr IOComponentEnum CHAR = IOComponentEnum::CHAR;
135 static constexpr IOComponentEnum USHORT = IOComponentEnum::USHORT;
136 static constexpr IOComponentEnum SHORT = IOComponentEnum::SHORT;
137 static constexpr IOComponentEnum UINT = IOComponentEnum::UINT;
138 static constexpr IOComponentEnum INT = IOComponentEnum::INT;
139 static constexpr IOComponentEnum ULONG = IOComponentEnum::ULONG;
140 static constexpr IOComponentEnum LONG = IOComponentEnum::LONG;
141 static constexpr IOComponentEnum ULONGLONG = IOComponentEnum::ULONGLONG;
142 static constexpr IOComponentEnum LONGLONG = IOComponentEnum::LONGLONG;
143 static constexpr IOComponentEnum FLOAT = IOComponentEnum::FLOAT;
144 static constexpr IOComponentEnum DOUBLE = IOComponentEnum::DOUBLE;
145 static constexpr IOComponentEnum LDOUBLE = IOComponentEnum::LDOUBLE;
146#endif
147
148#if !defined(ITK_LEGACY_REMOVE)
150 static constexpr IOFileEnum ASCII = IOFileEnum::ASCII;
151 static constexpr IOFileEnum BINARY = IOFileEnum::BINARY;
152 static constexpr IOFileEnum TYPENOTAPPLICABLE = IOFileEnum::TYPENOTAPPLICABLE;
153#endif
154
155#if !defined(ITK_LEGACY_REMOVE)
157 static constexpr IOByteOrderEnum BigEndian = IOByteOrderEnum::BigEndian;
158 static constexpr IOByteOrderEnum LittleEndian = IOByteOrderEnum::LittleEndian;
159 static constexpr IOByteOrderEnum OrderNotApplicable = IOByteOrderEnum::OrderNotApplicable;
160#endif
161
162#if !defined(ITK_LEGACY_REMOVE)
164 static constexpr IOFileModeEnum ReadMode = IOFileModeEnum::ReadMode;
165 static constexpr IOFileModeEnum WriteMode = IOFileModeEnum::WriteMode;
166#endif
167
168#if !defined(ITK_LEGACY_REMOVE)
170 static constexpr CellGeometryEnum VERTEX_CELL = CellGeometryEnum::VERTEX_CELL;
171 static constexpr CellGeometryEnum LINE_CELL = CellGeometryEnum::LINE_CELL;
172 static constexpr CellGeometryEnum TRIANGLE_CELL = CellGeometryEnum::TRIANGLE_CELL;
173 static constexpr CellGeometryEnum QUADRILATERAL_CELL = CellGeometryEnum::QUADRILATERAL_CELL;
174 static constexpr CellGeometryEnum POLYGON_CELL = CellGeometryEnum::POLYGON_CELL;
175 static constexpr CellGeometryEnum TETRAHEDRON_CELL = CellGeometryEnum::TETRAHEDRON_CELL;
176 static constexpr CellGeometryEnum HEXAHEDRON_CELL = CellGeometryEnum::HEXAHEDRON_CELL;
177 static constexpr CellGeometryEnum QUADRATIC_EDGE_CELL = CellGeometryEnum::QUADRATIC_EDGE_CELL;
178 static constexpr CellGeometryEnum QUADRATIC_TRIANGLE_CELL = CellGeometryEnum::QUADRATIC_TRIANGLE_CELL;
179 static constexpr CellGeometryEnum LAST_ITK_CELL = CellGeometryEnum::LAST_ITK_CELL;
180 static constexpr CellGeometryEnum MAX_ITK_CELLS = CellGeometryEnum::MAX_ITK_CELLS;
181#endif
182
189 itkSetEnumMacro(PointPixelType, itk::CommonEnums::IOPixel);
190 itkGetEnumMacro(PointPixelType, itk::CommonEnums::IOPixel);
191 itkSetEnumMacro(CellPixelType, itk::CommonEnums::IOPixel);
192 itkGetEnumMacro(CellPixelType, itk::CommonEnums::IOPixel);
197 itkSetEnumMacro(PointComponentType, itk::CommonEnums::IOComponent);
198 itkGetEnumMacro(PointComponentType, itk::CommonEnums::IOComponent);
199 itkSetEnumMacro(CellComponentType, itk::CommonEnums::IOComponent);
200 itkGetEnumMacro(CellComponentType, itk::CommonEnums::IOComponent);
201 itkSetEnumMacro(PointPixelComponentType, itk::CommonEnums::IOComponent);
202 itkGetEnumMacro(PointPixelComponentType, itk::CommonEnums::IOComponent);
203 itkSetEnumMacro(CellPixelComponentType, itk::CommonEnums::IOComponent);
204 itkGetEnumMacro(CellPixelComponentType, itk::CommonEnums::IOComponent);
206
207 template <typename TComponent>
209 {
210 static constexpr IOComponentEnum CType =
211 std::is_same_v<TComponent, unsigned char> ? IOComponentEnum::UCHAR
212 : std::is_same_v<TComponent, char> ? IOComponentEnum::CHAR
213 : std::is_same_v<TComponent, short> ? IOComponentEnum::SHORT
214 : std::is_same_v<TComponent, unsigned short> ? IOComponentEnum::USHORT
215 : std::is_same_v<TComponent, int> ? IOComponentEnum::INT
216 : std::is_same_v<TComponent, unsigned int> ? IOComponentEnum::UINT
217 : std::is_same_v<TComponent, long> ? IOComponentEnum::LONG
218 : std::is_same_v<TComponent, unsigned long> ? IOComponentEnum::ULONG
219 : std::is_same_v<TComponent, long long> ? IOComponentEnum::LONGLONG
220 : std::is_same_v<TComponent, unsigned long long> ? IOComponentEnum::ULONGLONG
221 : std::is_same_v<TComponent, float> ? IOComponentEnum::FLOAT
222 : std::is_same_v<TComponent, double> ? IOComponentEnum::DOUBLE
223 : std::is_same_v<TComponent, long double> ? IOComponentEnum::LDOUBLE
224 : IOComponentEnum::UNKNOWNCOMPONENTTYPE;
225 };
226
227 template <typename T>
228 void
229 SetPixelType(const T & itkNotUsed(dummy), bool usePointPixel = true)
230 {
231 if (usePointPixel)
232 {
235 SetPointPixelType(IOPixelEnum::SCALAR);
236 }
237 else
238 {
241 SetCellPixelType(IOPixelEnum::SCALAR);
242 }
243 }
244
245 template <typename T>
246 void
247 SetPixelType(const RGBPixel<T> & itkNotUsed(dummy), bool usePointPixel = true)
248 {
249 if (usePointPixel)
250 {
253 SetPointPixelType(IOPixelEnum::RGB);
254 }
255 else
256 {
259 SetCellPixelType(IOPixelEnum::RGB);
260 }
261 }
262
263 template <typename T>
264 void
265 SetPixelType(const RGBAPixel<T> & itkNotUsed(dummy), bool usePointPixel = true)
266 {
267 if (usePointPixel)
268 {
271 SetPointPixelType(IOPixelEnum::RGBA);
272 }
273 else
274 {
277 SetCellPixelType(IOPixelEnum::RGBA);
278 }
279 }
280
281 template <typename T, unsigned int VLength>
282 void
283 SetPixelType(const Vector<T, VLength> & itkNotUsed(dummy), bool usePointPixel = true)
284 {
285 if (usePointPixel)
286 {
289 SetPointPixelType(IOPixelEnum::VECTOR);
290 }
291 else
292 {
295 SetCellPixelType(IOPixelEnum::VECTOR);
296 }
297 }
298
299 template <typename T, unsigned int VLength>
300 void
301 SetPixelType(const CovariantVector<T, VLength> & itkNotUsed(dummy), bool usePointPixel = true)
302 {
303 if (usePointPixel)
304 {
307 SetPointPixelType(IOPixelEnum::COVARIANTVECTOR);
308 }
309 else
310 {
313 SetCellPixelType(IOPixelEnum::COVARIANTVECTOR);
314 }
315 }
316
317 template <typename T, unsigned int VLength>
318 void
319 SetPixelType(const FixedArray<T, VLength> & itkNotUsed(dummy), bool usePointPixel = true)
320 {
321 if (usePointPixel)
322 {
325 SetPointPixelType(IOPixelEnum::FIXEDARRAY);
326 }
327 else
328 {
331 SetCellPixelType(IOPixelEnum::FIXEDARRAY);
332 }
333 }
334
335 template <typename T, unsigned int VLength>
336 void
337 SetPixelType(const SymmetricSecondRankTensor<T, VLength> itkNotUsed(dummy), bool usePointPixel = true)
338 {
339 if (usePointPixel)
340 {
341 SetNumberOfPointPixelComponents(VLength * (VLength + 1) / 2);
343 SetPointPixelType(IOPixelEnum::SYMMETRICSECONDRANKTENSOR);
344 }
345 else
346 {
347 SetNumberOfCellPixelComponents(VLength * (VLength + 1) / 2);
349 SetCellPixelType(IOPixelEnum::SYMMETRICSECONDRANKTENSOR);
350 }
351 }
352
353 template <typename T>
354 void
355 SetPixelType(const DiffusionTensor3D<T> & itkNotUsed(dummy), bool usePointPixel = true)
356 {
357 if (usePointPixel)
358 {
361 SetPointPixelType(IOPixelEnum::DIFFUSIONTENSOR3D);
362 }
363 else
364 {
367 SetCellPixelType(IOPixelEnum::DIFFUSIONTENSOR3D);
368 }
369 }
370
371 template <typename T, unsigned int VRows, unsigned int VColumns>
372 void
373 SetPixelType(const Matrix<T, VRows, VColumns> & itkNotUsed(dummy), bool usePointPixel = true)
374 {
375 if (usePointPixel)
376 {
377 SetNumberOfPointPixelComponents(VRows * VColumns);
379 SetPointPixelType(IOPixelEnum::MATRIX);
380 }
381 else
382 {
383 SetNumberOfCellPixelComponents(VRows * VColumns);
385 SetCellPixelType(IOPixelEnum::MATRIX);
386 }
387 }
388
389 template <typename T>
390 void
391 SetPixelType(const std::complex<T> & itkNotUsed(dummy), bool usePointPixel = true)
392 {
393 if (usePointPixel)
394 {
397 SetPointPixelType(IOPixelEnum::COMPLEX);
398 }
399 else
400 {
403 SetCellPixelType(IOPixelEnum::COMPLEX);
404 }
405 }
406
407 template <typename T>
408 void
409 SetPixelType(const Array<T> & array, bool usePointPixel = true)
410 {
411 if (usePointPixel)
412 {
415 SetPointPixelType(IOPixelEnum::ARRAY);
416 }
417 else
418 {
421 SetCellPixelType(IOPixelEnum::ARRAY);
422 }
423 }
424
425 template <typename T>
426 void
427 SetPixelType(const VariableLengthVector<T> & vector, bool usePointPixel = true)
428 {
429 if (usePointPixel)
430 {
431 SetNumberOfPointPixelComponents(vector.Size());
433 SetPointPixelType(IOPixelEnum::VARIABLELENGTHVECTOR);
434 }
435 else
436 {
437 SetNumberOfCellPixelComponents(vector.Size());
439 SetCellPixelType(IOPixelEnum::VARIABLELENGTHVECTOR);
440 }
441 }
442
443 template <typename T>
444 void
445 SetPixelType(const VariableSizeMatrix<T> & matrix, bool usePointPixel = true)
446 {
447 if (usePointPixel)
448 {
449 SetNumberOfPointPixelComponents(matrix.Rows() * matrix.Cols());
451 SetPointPixelType(IOPixelEnum::VARIABLESIZEMATRIX);
452 }
453 else
454 {
455 SetNumberOfCellPixelComponents(matrix.Rows() * matrix.Cols());
457 SetCellPixelType(IOPixelEnum::VARIABLESIZEMATRIX);
458 }
459 }
460
466 itkSetMacro(NumberOfPointPixelComponents, unsigned int);
467 itkGetConstMacro(NumberOfPointPixelComponents, unsigned int);
468 itkSetMacro(NumberOfCellPixelComponents, unsigned int);
469 itkGetConstMacro(NumberOfCellPixelComponents, unsigned int);
470 itkSetMacro(PointDimension, unsigned int);
471 itkGetConstMacro(PointDimension, unsigned int);
472 itkSetMacro(NumberOfPoints, SizeValueType);
473 itkGetConstMacro(NumberOfPoints, SizeValueType);
474 itkSetMacro(NumberOfCells, SizeValueType);
475 itkGetConstMacro(NumberOfCells, SizeValueType);
476 itkSetMacro(NumberOfPointPixels, SizeValueType);
477 itkGetConstMacro(NumberOfPointPixels, SizeValueType);
478 itkSetMacro(NumberOfCellPixels, SizeValueType);
479 itkGetConstMacro(NumberOfCellPixels, SizeValueType);
480 itkSetMacro(CellBufferSize, SizeValueType);
481 itkGetConstMacro(CellBufferSize, SizeValueType);
482 itkSetMacro(UpdatePoints, bool);
483 itkGetConstMacro(UpdatePoints, bool);
484 itkBooleanMacro(UpdatePoints);
485 itkSetMacro(UpdateCells, bool);
486 itkGetConstMacro(UpdateCells, bool);
487 itkBooleanMacro(UpdateCells);
488 itkSetMacro(UpdatePointData, bool);
489 itkGetConstMacro(UpdatePointData, bool);
490 itkBooleanMacro(UpdatePointData);
491 itkSetMacro(UpdateCellData, bool);
492 itkGetConstMacro(UpdateCellData, bool);
493 itkBooleanMacro(UpdateCellData);
495 unsigned int
496 GetComponentSize(IOComponentEnum componentType) const;
497
501
505
509 itkSetEnumMacro(FileType, IOFileEnum);
510 itkGetEnumMacro(FileType, IOFileEnum);
512 void
514 {
515 this->SetFileType(IOFileEnum::ASCII);
516 }
517
518 void
520 {
521 this->SetFileType(IOFileEnum::BINARY);
522 }
523
536 itkSetEnumMacro(ByteOrder, IOByteOrderEnum);
537 itkGetEnumMacro(ByteOrder, IOByteOrderEnum);
539 void
541 {
542 this->SetByteOrder(IOByteOrderEnum::BigEndian);
543 }
544
545 void
547 {
548 this->SetByteOrder(IOByteOrderEnum::LittleEndian);
549 }
550
553 itkSetMacro(UseCompression, bool);
554 itkGetConstMacro(UseCompression, bool);
555 itkBooleanMacro(UseCompression);
559 std::string GetFileTypeAsString(IOFileEnum) const;
560
564
565 /*-------- This part of the interfaces deals with reading data ----- */
568 virtual bool
569 CanReadFile(const char *) = 0;
570
573 virtual void
575
577 virtual void
578 ReadPoints(void * buffer) = 0;
579
580 virtual void
581 ReadCells(void * buffer) = 0;
582
583 virtual void
584 ReadPointData(void * buffer) = 0;
585
586 virtual void
587 ReadCellData(void * buffer) = 0;
588
589 /*-------- This part of the interfaces deals with writing data ----- */
590
593 virtual bool
594 CanWriteFile(const char *) = 0;
595
596 virtual void
598
599 virtual void
600 WritePoints(void * buffer) = 0;
601
602 virtual void
603 WriteCells(void * buffer) = 0;
604
605 virtual void
606 WritePointData(void * buffer) = 0;
607
608 virtual void
609 WriteCellData(void * buffer) = 0;
610
611 virtual void
612 Write() = 0;
613
620
627
628protected:
630 ~MeshIOBase() override = default;
631
632 void
633 PrintSelf(std::ostream & os, Indent indent) const override;
634
636 void
637 AddSupportedReadExtension(const char * extension);
638
640 void
641 AddSupportedWriteExtension(const char * extension);
642
644 template <typename T>
645 void
646 ReadBufferAsAscii(T * buffer, std::ifstream & inputFile, SizeValueType numberOfComponents)
647 {
648 for (SizeValueType i = 0; i < numberOfComponents; ++i)
649 {
650 inputFile >> buffer[i];
651 }
652 }
653
655 template <typename T>
656 void
657 ReadBufferAsBinary(T * buffer, std::ifstream & inputFile, SizeValueType numberOfComponents)
658 {
659 inputFile.read(reinterpret_cast<char *>(buffer), numberOfComponents * sizeof(T));
660
661 if (m_ByteOrder == IOByteOrderEnum::BigEndian)
662 {
664 {
665 itk::ByteSwapper<T>::SwapRangeFromSystemToBigEndian(buffer, numberOfComponents);
666 }
667 }
668 else if (m_ByteOrder == IOByteOrderEnum::LittleEndian)
669 {
671 {
673 }
674 }
675 }
676
678 template <typename T>
679 void
681 std::ofstream & outputFile,
682 SizeValueType numberOfLines,
683 SizeValueType numberOfComponents)
684 {
685 for (SizeValueType ii = 0; ii < numberOfLines; ++ii)
686 {
687 for (SizeValueType jj = 0; jj < numberOfComponents; ++jj)
688 {
689 outputFile << ConvertNumberToString(buffer[ii * numberOfComponents + jj]) << " ";
690 }
691 outputFile << '\n';
692 }
693 }
694
696 template <typename TOutput, typename TInput>
697 void
698 WriteBufferAsBinary(TInput * buffer, std::ofstream & outputFile, SizeValueType numberOfComponents)
699 {
700 if (typeid(TInput) == typeid(TOutput))
701 {
702 if (m_ByteOrder == IOByteOrderEnum::BigEndian && itk::ByteSwapper<TInput>::SystemIsLittleEndian())
703 {
705 }
706 else if (m_ByteOrder == IOByteOrderEnum::LittleEndian && itk::ByteSwapper<TInput>::SystemIsBigEndian())
707 {
709 }
710
711 outputFile.write(reinterpret_cast<char *>(buffer), numberOfComponents);
712 }
713 else
714 {
715 const auto data = make_unique_for_overwrite<TOutput[]>(numberOfComponents);
716 for (SizeValueType ii = 0; ii < numberOfComponents; ++ii)
717 {
718 data[ii] = static_cast<TOutput>(buffer[ii]);
719 }
720
721 if (m_ByteOrder == IOByteOrderEnum::BigEndian && itk::ByteSwapper<TOutput>::SystemIsLittleEndian())
722 {
723 itk::ByteSwapper<TOutput>::SwapRangeFromSystemToBigEndian(data.get(), numberOfComponents);
724 }
725 else if (m_ByteOrder == IOByteOrderEnum::LittleEndian && itk::ByteSwapper<TOutput>::SystemIsBigEndian())
726 {
728 }
729
730 outputFile.write(reinterpret_cast<char *>(data.get()), numberOfComponents);
731 }
732 }
733
737 template <typename TInput, typename TOutput>
738 void
739 ReadCellsBuffer(TInput * input, TOutput * output)
740 {
741 if (input && output)
742 {
743 SizeValueType inputIndex{};
744 SizeValueType outputIndex{};
745 for (SizeValueType ii = 0; ii < m_NumberOfCells; ++ii)
746 {
747 ++inputIndex; // ignore the cell type
748 auto numberOfPoints = static_cast<unsigned int>(input[inputIndex++]);
749 for (unsigned int jj = 0; jj < numberOfPoints; ++jj)
750 {
751 output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
752 }
753 }
754 }
755 }
756
760 template <typename TInput, typename TOutput>
761 void
762 ReadCellsBuffer(TInput * input, TOutput * output, CellGeometryEnum type)
763 {
764 if (input && output)
765 {
766 SizeValueType inputIndex{};
767 SizeValueType outputIndex{};
768
769 for (SizeValueType ii = 0; ii < m_NumberOfCells; ++ii)
770 {
771 auto cellType = static_cast<CellGeometryEnum>(input[inputIndex++]);
772 auto nn = static_cast<unsigned int>(input[inputIndex++]);
773 if (cellType == type)
774 {
775 output[outputIndex++] = nn;
776 for (unsigned int jj = 0; jj < nn; ++jj)
777 {
778 output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
779 }
780 }
781 else
782 {
783 inputIndex += nn;
784 }
785 }
786 }
787 }
788
791 template <typename TInput, typename TOutput>
792 void
793 WriteCellsBuffer(TInput * input,
794 TOutput * output,
795 CellGeometryEnum cellType,
796 unsigned int numberOfPoints,
797 SizeValueType numberOfCells)
798 {
799 if (input && output)
800 {
801 SizeValueType inputIndex{};
802 SizeValueType outputIndex{};
803 for (SizeValueType ii = 0; ii < numberOfCells; ++ii)
804 {
805 output[outputIndex++] = static_cast<TOutput>(cellType);
806 output[outputIndex++] = static_cast<TOutput>(numberOfPoints);
807 for (unsigned int jj = 0; jj < numberOfPoints; ++jj)
808 {
809 output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
810 }
811 }
812 }
813 }
814
817 template <typename TInput, typename TOutput>
818 void
819 WriteCellsBuffer(TInput * input, TOutput * output, CellGeometryEnum cellType, SizeValueType numberOfCells)
820 {
821 if (input && output)
822 {
823 SizeValueType inputIndex{};
824 SizeValueType outputIndex{};
825 for (SizeValueType ii = 0; ii < numberOfCells; ++ii)
826 {
827 auto numberOfPoints = static_cast<unsigned int>(input[inputIndex++]);
828 if (numberOfPoints > 2 && cellType == CellGeometryEnum::LINE_CELL)
829 {
830 output[outputIndex++] = static_cast<TOutput>(CellGeometryEnum::POLYLINE_CELL);
831 }
832 else
833 {
834 output[outputIndex++] = static_cast<TOutput>(cellType);
835 }
836 output[outputIndex++] = static_cast<TOutput>(numberOfPoints);
837
838 for (unsigned int jj = 0; jj < numberOfPoints; ++jj)
839 {
840 output[outputIndex++] = static_cast<TOutput>(input[inputIndex++]);
841 }
842 }
843 }
844 }
845
846protected:
848 IOByteOrderEnum m_ByteOrder{ IOByteOrderEnum::OrderNotApplicable };
849 IOFileEnum m_FileType{ IOFileEnum::ASCII };
850
852 std::string m_FileName{};
853
855 bool m_UseCompression{ false };
856
858 IOComponentEnum m_PointComponentType{ IOComponentEnum::UNKNOWNCOMPONENTTYPE };
859 IOComponentEnum m_CellComponentType{ IOComponentEnum::UNKNOWNCOMPONENTTYPE };
860 IOComponentEnum m_PointPixelComponentType{ IOComponentEnum::UNKNOWNCOMPONENTTYPE };
861 IOComponentEnum m_CellPixelComponentType{ IOComponentEnum::UNKNOWNCOMPONENTTYPE };
862
864 IOPixelEnum m_PointPixelType{ IOPixelEnum::SCALAR };
865 IOPixelEnum m_CellPixelType{ IOPixelEnum::SCALAR };
866
871
873 unsigned int m_PointDimension{ 3 };
874
880
883
886 bool m_UpdatePoints{ false };
887 bool m_UpdateCells{ false };
888 bool m_UpdatePointData{ false };
889 bool m_UpdateCellData{ false };
890
891private:
894};
895} // end namespace itk
896
897#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
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
static std::string GetComponentTypeAsString(IOComponentEnum)
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
static std::string GetPixelTypeAsString(IOPixelEnum)
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
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