ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkVTKImageIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 /*=========================================================================
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 {
49 class ITKIOVTK_EXPORT VTKImageIO:
51 {
52 public:
53  ITK_DISALLOW_COPY_AND_ASSIGN(VTKImageIO);
54 
56  using Self = VTKImageIO;
60 
62  itkNewMacro(Self);
63 
65  itkTypeMacro(VTKImageIO, StreamingImageIOBase);
66 
67 // see super class for documentation
68  //
69  // overidden to return true only when supported
70  bool CanStreamWrite() override;
71 
72  // see super class for documentation
73  //
74  // overidden to return true only when supported
75  bool CanStreamRead() override;
76 
77 
78  /*-------- This part of the interface deals with reading data. ------ */
79 
82  bool CanReadFile(const char *) override;
83 
85  void ReadImageInformation() override;
86 
88  void Read(void *buffer) override;
89 
90  /*-------- This part of the interfaces deals with writing data. ----- */
91 
94  bool CanWriteFile(const char *) override;
95 
98  void WriteImageInformation() override {}
99 
102  void Write(const void *buffer) override;
103 
105  SizeType GetHeaderSize() const override { return this->m_HeaderSize; }
106 
107 protected:
108  VTKImageIO();
109  ~VTKImageIO() override;
110 
111  void PrintSelf(std::ostream & os, Indent indent) const override;
112 
113  void InternalReadImageInformation(std::ifstream & file);
114 
115  // Internal function to get next line from a given file (*.vtk)
116  int GetNextLine(std::ifstream& ifs, std::string& line, bool lowerCase = true, SizeValueType count= 0);
117 
118  void WriteImageInformation(const void *buffer);
119 
120  void ReadHeaderSize(std::ifstream & file);
121 
123  void ReadBufferAsASCII(std::istream & os, void *buffer,
124  IOComponentType ctype,
125  SizeType numberOfBytesToBeRead) override;
126 
128  void WriteBufferAsASCII(std::ostream & os, const void *buffer,
129  IOComponentType ctype,
130  SizeType numberOfBytesToWrite) override;
131 
134  virtual void ReadSymmetricTensorBufferAsBinary(std::istream& os,
135  void *buffer,
137 
140  virtual void WriteSymmetricTensorBufferAsBinary(std::ostream& os,
141  const void *buffer,
143 
144 private:
145  void SetPixelTypeFromString(const std::string & pixelType);
146  std::string GetComponentTypeAsString(IOComponentType);
147 
149  SizeType GetIORegionSizeInPixels() const;
150 
152  SizeType GetIORegionSizeInBytes() const;
153 
156  SizeType GetIORegionSizeInComponents() const;
157 
159 };
160 } // end namespace itk
161 
162 #endif // itkVTKImageIO_h
void WriteImageInformation() override
Definition: itkVTKImageIO.h:98
Light weight base class for most itk classes.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
A base class for specific ImageIO file formats which support streaming.
::itk::intmax_t SizeType
ImageIO class for reading VTK images.
Definition: itkVTKImageIO.h:49
SizeType m_HeaderSize
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:60
SizeType GetHeaderSize() const override