ITK  4.13.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 ) ITK_OVERRIDE;
95 
98  virtual bool CanReadFile(const char* FileNameToRead) ITK_OVERRIDE;
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() ITK_OVERRIDE;
108 
109  /* Read the data from the disk into provided memory buffer */
110  virtual void Read(void* buffer) ITK_OVERRIDE;
111 
114  virtual bool CanWriteFile(const char* FileNameToWrite) ITK_OVERRIDE;
115 
116  /* Set the spacing and dimension information for the set file name */
117  virtual void WriteImageInformation() ITK_OVERRIDE;
118 
119  /* Write the data to the disk from the provided memory buffer */
120  virtual void Write(const void* buffer) ITK_OVERRIDE;
121 
122 protected:
123  SCIFIOImageIO();
124  ~SCIFIOImageIO();
125 
126  virtual SizeType GetHeaderSize() const ITK_OVERRIDE { 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  bool CheckJavaPath(std::string javaHome, std::string &javaCmd);
135  std::string RemoveFinalSlash(std::string path) const;
136 
137  char ** toCArray( std::vector< std::string > & args )
138  {
139  char **argv = new char *[args.size() + 1];
140  for( int i = 0; i < static_cast< int >( args.size() ); i++ )
141  {
142  itkDebugMacro( "SCIFIOImageIO::toCArray::args["<<i<<"] = " << args[i]);
143  argv[i] = (char*)args[i].c_str();
144  }
145  argv[args.size()] = NULL;
146  return argv;
147  }
148 
150  {
151  switch ( pixelType )
152  {
153  case 0:
154  return CHAR;
155  case 1:
156  return UCHAR;
157  case 2:
158  return SHORT;
159  case 3:
160  return USHORT;
161  case 4:
162  return INT;
163  case 5:
164  return UINT;
165  case 6:
166  return FLOAT;
167  default:
168  return DOUBLE;
169  }
170  }
171 
173  {
174  switch ( cmp )
175  {
176  case CHAR:
177  return 0;
178  case UCHAR:
179  return 1;
180  case SHORT:
181  return 2;
182  case USHORT:
183  return 3;
184  case INT:
185  return 4;
186  case UINT:
187  return 5;
188  case FLOAT:
189  return 6;
190  case LONG:
191  case ULONG:
192  case DOUBLE:
193  default:
194  return 7;
195  }
196  }
197 
199  std::vector< std::string > m_Args;
200  char ** m_Argv;
201  itksysProcess_Pipe_Handle m_Pipe[2];
202  itksysProcess * m_Process;
203 };
204 } // end namespace itk
205 
206 #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
Base class for most ITK classes.
Definition: itkObject.h:59