ITK  4.9.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:
54  typedef VTKImageIO Self;
58 
60  itkNewMacro(Self);
61 
63  itkTypeMacro(VTKImageIO, StreamingImageIOBase);
64 
65 // see super class for documentation
66  //
67  // overidden to return true only when supported
68  virtual bool CanStreamWrite(void) ITK_OVERRIDE;
69 
70  // see super class for documentation
71  //
72  // overidden to return true only when supported
73  virtual bool CanStreamRead(void) ITK_OVERRIDE;
74 
75 
76  /*-------- This part of the interface deals with reading data. ------ */
77 
80  virtual bool CanReadFile(const char *) ITK_OVERRIDE;
81 
83  virtual void ReadImageInformation() ITK_OVERRIDE;
84 
86  virtual void Read(void *buffer) ITK_OVERRIDE;
87 
88  /*-------- This part of the interfaces deals with writing data. ----- */
89 
92  virtual bool CanWriteFile(const char *) ITK_OVERRIDE;
93 
96  virtual void WriteImageInformation() ITK_OVERRIDE {}
97 
100  virtual void Write(const void *buffer) ITK_OVERRIDE;
101 
103  virtual SizeType GetHeaderSize() const ITK_OVERRIDE { return this->m_HeaderSize; }
104 
105 protected:
106  VTKImageIO();
107  ~VTKImageIO();
108 
109  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
110 
111  void InternalReadImageInformation(std::ifstream & file);
112 
113  // Internal function to get next line from a given file (*.vtk)
114  int GetNextLine(std::ifstream& ifs, std::string& line, bool lowerCase = true, SizeValueType count= 0);
115 
116  void WriteImageInformation(const void *buffer);
117 
118  void ReadHeaderSize(std::ifstream & file);
119 
121  virtual void ReadBufferAsASCII(std::istream & os, void *buffer,
122  IOComponentType ctype,
123  SizeType numberOfBytesToBeRead) ITK_OVERRIDE;
124 
126  virtual void WriteBufferAsASCII(std::ostream & os, const void *buffer,
127  IOComponentType ctype,
128  SizeType numberOfBytesToWrite) ITK_OVERRIDE;
129 
132  virtual void ReadSymmetricTensorBufferAsBinary(std::istream& os,
133  void *buffer,
135 
138  virtual void WriteSymmetricTensorBufferAsBinary(std::ostream& os,
139  const void *buffer,
141 
142 private:
143  VTKImageIO(const Self &) ITK_DELETE_FUNCTION;
144  void operator=(const Self &) ITK_DELETE_FUNCTION;
145  void SetPixelTypeFromString(const std::string & pixelType);
146 
148  SizeType GetIORegionSizeInPixels() const;
149 
151  SizeType GetIORegionSizeInBytes() const;
152 
155  SizeType GetIORegionSizeInComponents() const;
156 
157  SizeType m_HeaderSize;
158 };
159 } // end namespace itk
160 
161 #endif // itkVTKImageIO_h
Light weight base class for most itk classes.
A base class for specific ImageIO file formats which support streaming.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
virtual SizeType GetHeaderSize() const override
::itk::intmax_t SizeType
SmartPointer< Self > Pointer
Definition: itkVTKImageIO.h:56
ImageIO class for reading VTK images.
Definition: itkVTKImageIO.h:49
VTKImageIO Self
Definition: itkVTKImageIO.h:54
Control indentation during Print() invocation.
Definition: itkIndent.h:49
SmartPointer< const Self > ConstPointer
Definition: itkVTKImageIO.h:57
StreamingImageIOBase Superclass
Definition: itkVTKImageIO.h:55