1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkMetaImageWriter.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /**
16  * @class   vtkMetaImageWriter
17  * @brief   write a binary UNC meta image data
18  *
19  * One of the formats for which a reader is already available in the toolkit is
20  * the MetaImage file format. This is a fairly simple yet powerful format
21  * consisting of a text header and a binary data section. The following
22  * instructions describe how you can write a MetaImage header for the data that
23  * you download from the BrainWeb page.
24  *
25  * The minimal structure of the MetaImage header is the following:
26  *
27  *    NDims = 3
28  *    DimSize = 181 217 181
29  *    ElementType = MET_UCHAR
30  *    ElementSpacing = 1.0 1.0 1.0
31  *    ElementByteOrderMSB = False
32  *    ElementDataFile = brainweb1.raw
33  *
34  *    * NDims indicate that this is a 3D image. ITK can handle images of
35  *      arbitrary dimension.
36  *    * DimSize indicates the size of the volume in pixels along each
37  *      direction.
38  *    * ElementType indicate the primitive type used for pixels. In this case
39  *      is "unsigned char", implying that the data is digitized in 8 bits /
40  *      pixel.
41  *    * ElementSpacing indicates the physical separation between the center of
42  *      one pixel and the center of the next pixel along each direction in space.
43  *      The units used are millimeters.
44  *    * ElementByteOrderMSB indicates is the data is encoded in little or big
45  *      endian order. You might want to play with this value when moving data
46  *      between different computer platforms.
47  *    * ElementDataFile is the name of the file containing the raw binary data
48  *      of the image. This file must be in the same directory as the header.
49  *
50  * MetaImage headers are expected to have extension: ".mha" or ".mhd"
51  *
52  * Once you write this header text file, it should be possible to read the
53  * image into your ITK based application using the itk::FileIOToImageFilter
54  * class.
55  *
56  *
57  *
58  * @sa
59  * vtkImageWriter vtkMetaImageReader
60  */
61 
62 #ifndef vtkMetaImageWriter_h
63 #define vtkMetaImageWriter_h
64 
65 #include "vtkIOImageModule.h" // For export macro
66 #include "vtkImageWriter.h"
67 
68 namespace vtkmetaio
69 {
70 class MetaImage;
71 } // forward declaration
72 
73 class VTKIOIMAGE_EXPORT vtkMetaImageWriter : public vtkImageWriter
74 {
75 public:
76   vtkTypeMacro(vtkMetaImageWriter, vtkImageWriter);
77   void PrintSelf(ostream& os, vtkIndent indent) override;
78 
79   /**
80    * Construct object with FlipNormals turned off and Normals set to true.
81    */
82   static vtkMetaImageWriter* New();
83 
84   /**
85    * Specify file name of meta file
86    */
87   void SetFileName(VTK_FILEPATH const char* fname) override;
GetFileName()88   VTK_FILEPATH char* GetFileName() override { return this->MHDFileName; }
89 
90   ///@{
91   /**
92    * Specify the file name of the raw image data.
93    */
94   virtual void SetRAWFileName(VTK_FILEPATH const char* fname);
95   virtual VTK_FILEPATH char* GetRAWFileName();
96   ///@}
97 
SetCompression(bool compress)98   virtual void SetCompression(bool compress) { this->Compress = compress; }
GetCompression(void)99   virtual bool GetCompression(void) { return this->Compress; }
100 
101   // This is called by the superclass.
102   // This is the method you should override.
103   void Write() override;
104 
105 protected:
106   vtkMetaImageWriter();
107   ~vtkMetaImageWriter() override;
108 
109   vtkSetFilePathMacro(MHDFileName);
110   char* MHDFileName;
111   bool Compress;
112 
113 private:
114   vtkMetaImageWriter(const vtkMetaImageWriter&) = delete;
115   void operator=(const vtkMetaImageWriter&) = delete;
116 
117   vtkmetaio::MetaImage* MetaImagePtr;
118 };
119 
120 #endif
121