ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkSCIFIOImageIO.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 #ifndef itkSCIFIOImageIO_h
19 #define itkSCIFIOImageIO_h
20 
21 #include "SCIFIOExport.h"
23 
24 #include "itksys/Process.h"
25 #include "itksys/SystemTools.hxx"
26 
27 #include <sstream>
28 
29 namespace itk
30 {
80 class SCIFIO_EXPORT SCIFIOImageIO : public StreamingImageIOBase
81 {
82 public:
87 
89  itkNewMacro(Self);
90 
92  itkTypeMacro(SCIFIOImageIO, Superclass);
93 
94  virtual bool SupportsDimension( unsigned long dim );
95 
98  virtual bool CanReadFile(const char* FileNameToRead);
99 
100  /* Sets the series to read in a multi-series dataset */
101  virtual bool SetSeries(int series);
102 
103  /* Sets the series to read in a multi-series dataset */
104  virtual int GetSeriesCount();
105 
106  /* Set the spacing and dimension information for the set file name */
107  virtual void ReadImageInformation();
108 
109  /* Read the data from the disk into provided memory buffer */
110  virtual void Read(void* buffer);
111 
114  virtual bool CanWriteFile(const char* FileNameToWrite);
115 
116  /* Set the spacing and dimension information for the set file name */
117  virtual void WriteImageInformation();
118 
119  /* Write the data to the disk from the provided memory buffer */
120  virtual void Write(const void* buffer);
121 
122 protected:
123  SCIFIOImageIO();
124  ~SCIFIOImageIO();
125 
126  virtual SizeType GetHeaderSize() const { return 0; }
127 
128 private:
129  void CreateJavaProcess();
130  void DestroyJavaProcess();
131  std::string FindDimensionOrder(const ImageIORegion & region );
132  std::string WaitForNewLines(int pipedatalength);
133  void CheckError(std::string message);
134 
135  char ** toCArray( std::vector< std::string > & args )
136  {
137  char **argv = new char *[args.size() + 1];
138  for( int i = 0; i < static_cast< int >( args.size() ); i++ )
139  {
140  itkDebugMacro( "SCIFIOImageIO::toCArray::args["<<i<<"] = " << args[i]);
141  argv[i] = (char*)args[i].c_str();
142  }
143  argv[args.size()] = NULL;
144  return argv;
145  }
146 
148  {
149  switch ( pixelType )
150  {
151  case 0:
152  return CHAR;
153  case 1:
154  return UCHAR;
155  case 2:
156  return SHORT;
157  case 3:
158  return USHORT;
159  case 4:
160  return INT;
161  case 5:
162  return UINT;
163  case 6:
164  return FLOAT;
165  default:
166  return DOUBLE;
167  }
168  }
169 
171  {
172  switch ( cmp )
173  {
174  case CHAR:
175  return 0;
176  case UCHAR:
177  return 1;
178  case SHORT:
179  return 2;
180  case USHORT:
181  return 3;
182  case INT:
183  return 4;
184  case UINT:
185  return 5;
186  case FLOAT:
187  return 6;
188  case LONG:
189  case ULONG:
190  case DOUBLE:
191  default:
192  return 7;
193  }
194  }
195 
197  std::vector< std::string > m_Args;
198  char ** m_Argv;
199  itksysProcess_Pipe_Handle m_Pipe[2];
200  itksysProcess * m_Process;
201 };
202 } // end namespace itk
203 
204 #endif // itkSCIFIOImageIO_h
Light weight base class for most itk classes.
An ImageIORegion represents a structured region of data.
Abstract superclass defines image IO interface.
A base class for specific ImageIO file formats which support streaming.
Interface to the OME SCIFIO Java Library.
ImageIOBase::IOComponentType scifioToITKComponentType(int pixelType)
itksysProcess * m_Process
SCIFIOImageIO Self
ImageIOBase Superclass
char ** toCArray(std::vector< std::string > &args)
::itk::intmax_t SizeType
Provides a mechanism for storing a collection of arbitrary data types.
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
int itkToSCIFIOPixelType(ImageIOBase::IOComponentType cmp)
std::vector< std::string > m_Args
MetaDataDictionary m_MetaDataDictionary
virtual SizeType GetHeaderSize() const
Returns the size of the header in the file.
Base class for most ITK classes.
Definition: itkObject.h:57