ITK  5.4.0
Insight Toolkit
itkVTKImageIO.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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkVTKImageIO_h
29 #define itkVTKImageIO_h
30 #include "ITKIOVTKExport.h"
31 
32 
33 #include <fstream>
35 
36 namespace itk
37 {
50 class ITKIOVTK_EXPORT VTKImageIO : public StreamingImageIOBase
51 {
52 public:
53  ITK_DISALLOW_COPY_AND_MOVE(VTKImageIO);
54 
56  using Self = VTKImageIO;
60 
62  itkNewMacro(Self);
63 
65  itkOverrideGetNameOfClassMacro(VTKImageIO);
66 
67  // see super class for documentation
68  //
69  // overridden to return true only when supported
70  bool
71  CanStreamWrite() override;
72 
73  // see super class for documentation
74  //
75  // overridden to return true only when supported
76  bool
77  CanStreamRead() override;
78 
79 
80  /*-------- This part of the interface deals with reading data. ------ */
81 
84  bool
85  CanReadFile(const char *) override;
86 
88  void
89  ReadImageInformation() override;
90 
92  void
93  Read(void * buffer) override;
94 
95  /*-------- This part of the interfaces deals with writing data. ----- */
96 
99  bool
100  CanWriteFile(const char *) override;
101 
104  void
106  {}
107 
110  void
111  Write(const void * buffer) override;
112 
114  SizeType
115  GetHeaderSize() const override
116  {
117  return this->m_HeaderSize;
118  }
119 
120 protected:
121  VTKImageIO();
122  ~VTKImageIO() override;
123 
124  void
125  PrintSelf(std::ostream & os, Indent indent) const override;
126 
127  void
128  InternalReadImageInformation(std::ifstream & file);
129 
130  // Internal function to get next line from a given file (*.vtk)
131  int
132  GetNextLine(std::ifstream & ifs, std::string & line, bool lowerCase = true, SizeValueType count = 0);
133 
134  void
135  WriteImageInformation(const void * buffer);
136 
137  void
138  ReadHeaderSize(std::ifstream & file);
139 
141  void
142  ReadBufferAsASCII(std::istream & is, void * buffer, IOComponentEnum ctype, SizeType numComp) override;
143 
145  void
146  WriteBufferAsASCII(std::ostream & os, const void * buffer, IOComponentEnum ctype, SizeType numComp) override;
147 
150  virtual void
151  ReadSymmetricTensorBufferAsBinary(std::istream & is, void * buffer, StreamingImageIOBase::SizeType num);
152 
155  virtual void
156  WriteSymmetricTensorBufferAsBinary(std::ostream & os, const void * buffer, StreamingImageIOBase::SizeType num);
157 
158 private:
159  void
160  SetPixelTypeFromString(const std::string & pixelType);
161  std::string GetComponentTypeAsString(IOComponentEnum);
162 
164  SizeType
165  GetIORegionSizeInPixels() const;
166 
168  SizeType
169  GetIORegionSizeInBytes() const;
170 
173  SizeType
174  GetIORegionSizeInComponents() const;
175 
176  SizeType m_HeaderSize{};
177 };
178 } // end namespace itk
179 
180 #endif // itkVTKImageIO_h
itkStreamingImageIOBase.h
itk::StreamingImageIOBase
A base class for specific ImageIO file formats which support streaming.
Definition: itkStreamingImageIOBase.h:52
itk::VTKImageIO::GetHeaderSize
SizeType GetHeaderSize() const override
Definition: itkVTKImageIO.h:115
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::SmartPointer< Self >
itk::CommonEnums::IOComponent
IOComponent
Definition: itkCommonEnums.h:76
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::VTKImageIO::WriteImageInformation
void WriteImageInformation() override
Definition: itkVTKImageIO.h:105
itk::VTKImageIO
ImageIO class for reading VTK images.
Definition: itkVTKImageIO.h:50
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageIOBase::SizeType
itk::intmax_t SizeType
Definition: itkImageIOBase.h:395
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83