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"
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{
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
103 itkSetStringMacro(FileName);
104 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
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);
326 }
327 else
328 {
329 SetNumberOfCellPixelComponents(VLength * (VLength + 1) / 2);
330 SetCellPixelComponentType(MapComponentType<T>::CType);
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
483
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
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 }
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 {
656 }
657 }
658 }
659
661 template <typename T>
662 void
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 {
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
835protected:
839
841 std::string m_FileName{};
842
844 bool m_UseCompression{ false };
845
851
853 IOPixelEnum m_PointPixelType{ 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
880private:
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
Array class with size defined at construction time.
Definition: itkArray.h:48
SizeValueType Size() const
Definition: itkArray.h:128
Perform machine dependent byte swapping.
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.
Definition: itkFixedArray.h:54
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:53
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:73
void ReadCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum type)
void WriteBufferAsBinary(TInput *buffer, std::ofstream &outputFile, SizeValueType numberOfComponents)
void SetPixelType(const RGBPixel< T > &, bool usePointPixel=true)
std::string GetPixelTypeAsString(IOPixelEnum) const
void WriteBufferAsAscii(T *buffer, std::ofstream &outputFile, SizeValueType numberOfLines, SizeValueType numberOfComponents)
virtual void Write()=0
void SetFileTypeToBinary()
std::string GetFileTypeAsString(IOFileEnum) const
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:89
void SetPixelType(const VariableSizeMatrix< T > &matrix, bool usePointPixel=true)
virtual void ReadPointData(void *buffer)=0
void SetPixelType(const FixedArray< T, VLength > &, bool usePointPixel=true)
virtual void WritePoints(void *buffer)=0
std::string GetComponentTypeAsString(IOComponentEnum) const
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 GetComponentSize(IOComponentEnum componentType) const
void AddSupportedReadExtension(const char *extension)
void SetPixelType(const T &, bool usePointPixel=true)
virtual void ReadMeshInformation()=0
virtual void ReadCells(void *buffer)=0
void SetPixelType(const SymmetricSecondRankTensor< T, VLength >, bool usePointPixel=true)
virtual bool CanReadFile(const char *)=0
void ReadBufferAsBinary(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
const ArrayOfExtensionsType & GetSupportedReadExtensions() const
virtual void WriteCellData(void *buffer)=0
void SetPixelType(const VariableLengthVector< T > &vector, bool usePointPixel=true)
std::string GetByteOrderAsString(IOByteOrderEnum) const
void ReadCellsBuffer(TInput *input, TOutput *output)
void PrintSelf(std::ostream &os, Indent indent) const override
const ArrayOfExtensionsType & GetSupportedWriteExtensions() const
virtual bool CanWriteFile(const char *)=0
void SetPixelType(const RGBAPixel< T > &, bool usePointPixel=true)
void SetByteOrderToBigEndian()
std::streamoff StreamOffsetType
Definition: itkMeshIOBase.h:87
~MeshIOBase() override=default
void SetByteOrderToLittleEndian()
void SetFileTypeToASCII()
virtual void WritePointData(void *buffer)=0
void SetPixelType(const Matrix< T, VRows, VColumns > &, bool usePointPixel=true)
std::vector< std::string > ArrayOfExtensionsType
Definition: itkMeshIOBase.h:84
void SetPixelType(const DiffusionTensor3D< T > &, bool usePointPixel=true)
void SetPixelType(const std::complex< T > &, bool usePointPixel=true)
virtual void ReadCellData(void *buffer)=0
void SetPixelType(const Array< T > &array, bool usePointPixel=true)
void AddSupportedWriteExtension(const char *extension)
void SetPixelType(const CovariantVector< T, VLength > &, bool usePointPixel=true)
virtual void ReadPoints(void *buffer)=0
void SetPixelType(const Vector< T, VLength > &, bool usePointPixel=true)
void ReadBufferAsAscii(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryEnum cellType, SizeValueType numberOfCells)
Base class for most ITK classes.
Definition: itkObject.h:62
Represent Red, Green, Blue and Alpha components for color images.
Definition: itkRGBAPixel.h:60
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:59
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....
std::string ConvertNumberToString(const TValue val)
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
MESHIOBASE_TYPEMAP(unsigned char, IOComponentEnum::UCHAR)