plastimatch
Loading...
Searching...
No Matches
plm_image.h
Go to the documentation of this file.
1/* -----------------------------------------------------------------------
2 See COPYRIGHT.TXT and LICENSE.TXT for copyright and license information
3 ----------------------------------------------------------------------- */
4#ifndef _plm_image_h_
5#define _plm_image_h_
6
7#include "plmbase_config.h"
8#include "compiler_warnings.h"
9#include "itk_image.h"
10#include "metadata.h"
11#include "plm_image_type.h"
12#include "smart_pointer.h"
13#include "volume.h"
14
16class Plm_image;
19
28public:
31public:
32 Plm_image ();
33 Plm_image (const char* fname);
34 Plm_image (const std::string& fname);
35 Plm_image (const char* fname, Plm_image_type type);
36 Plm_image (const std::string& fname, Plm_image_type type);
37 Plm_image (UCharImageType::Pointer img);
38 Plm_image (CharImageType::Pointer img);
39 Plm_image (ShortImageType::Pointer img);
40 Plm_image (FloatImageType::Pointer img);
41 Plm_image (const Volume::Pointer& vol);
42 Plm_image (Volume* vol);
43 Plm_image (Plm_image_type type, const Plm_image_header& pih);
44 ~Plm_image ();
45
46public:
49
50 /* The actual image is one of the following. */
51 UCharImageType::Pointer m_itk_uchar;
52 CharImageType::Pointer m_itk_char;
53 UShortImageType::Pointer m_itk_ushort;
54 ShortImageType::Pointer m_itk_short;
55 UInt32ImageType::Pointer m_itk_uint32;
56 Int32ImageType::Pointer m_itk_int32;
57 UInt64ImageType::Pointer m_itk_uint64;
58 Int64ImageType::Pointer m_itk_int64;
59 FloatImageType::Pointer m_itk_float;
60 DoubleImageType::Pointer m_itk_double;
61 UCharVecImageType::Pointer m_itk_uchar_vec;
62
63private:
64 /* Please don't use copy constructors. They suck. */
66 }
67 /* Please don't use overloaded operators. They suck. */
68 Plm_image& operator= (Plm_image&) {
69 return *this;
70 }
71
72 void convert_to_itk_char ();
73 void convert_to_itk_uchar ();
74 void convert_to_itk_short ();
75 void convert_to_itk_ushort ();
76 void convert_to_itk_int32 ();
77 void convert_to_itk_uint32 ();
78 void convert_to_itk_float ();
79 void convert_to_itk_double ();
80 void convert_to_gpuit_short ();
81 void convert_to_gpuit_uint16 ();
82 void convert_to_gpuit_uint32 ();
83 void convert_to_gpuit_int32 ();
84 void convert_to_gpuit_float ();
85 void convert_to_gpuit_uchar ();
86 void convert_to_gpuit_uchar_vec ();
87
88public:
89 /* creation / destruction */
90 void init ();
91 void free ();
92 bool have_image ();
93 Plm_image::Pointer clone (void);
94 void create (Plm_image_type type, const Plm_image_header& pih);
95
96 /* Loading */
97 bool load (const char* fname, Plm_image_type type);
98 bool load (const std::string& fname, Plm_image_type type);
99 bool load_native (const char* fname);
100 bool load_native (const std::string& fn);
101 bool load_native_dicom (const char* fname);
102 bool load_native_nki (const char* fname);
103
104 /* Saving */
105 void save_image (const char* fname);
106 void save_image (const std::string& fname);
107 void convert_and_save (const char* fname, Plm_image_type new_type);
108 void convert_and_save (const std::string& fname, Plm_image_type new_type);
109
110 /* assignment */
111 void set (const Plm_image::Pointer& pli);
112 void set_volume (const Volume::Pointer& v, Plm_image_type type);
113 void set_volume (const Volume::Pointer& v);
114 void set_volume (Volume *v, Plm_image_type type);
115 void set_volume (Volume *v);
116 void set_itk (UCharImageType::Pointer img);
117 void set_itk (CharImageType::Pointer img);
118 void set_itk (UShortImageType::Pointer img);
119 void set_itk (ShortImageType::Pointer img);
120 void set_itk (UInt32ImageType::Pointer img);
121 void set_itk (Int32ImageType::Pointer img);
122 void set_itk (FloatImageType::Pointer img);
123 void set_itk (DoubleImageType::Pointer img);
124 void set_itk (UCharVecImageType::Pointer img);
125
126 /* conversion */
127 UCharImageType::Pointer& itk_uchar () {
128 convert_to_itk_uchar ();
129 return m_itk_uchar;
130 }
131 ShortImageType::Pointer& itk_short () {
132 convert_to_itk_short ();
133 return m_itk_short;
134 }
135 UShortImageType::Pointer& itk_ushort () {
136 convert_to_itk_ushort ();
137 return m_itk_ushort;
138 }
139 FloatImageType::Pointer& itk_float () {
140 convert_to_itk_float ();
141 return m_itk_float;
142 }
143 UCharVecImageType::Pointer& itk_uchar_vec () {
144 convert_to_itk_uchar_vec ();
145 return m_itk_uchar_vec;
146 }
147
148 Volume::Pointer& get_volume ();
149 Volume::Pointer& get_volume_uchar ();
150 Volume::Pointer& get_volume_short ();
151 Volume::Pointer& get_volume_float ();
152 Volume::Pointer& get_volume_uchar_vec ();
153
154 Volume* get_vol ();
155 const Volume* get_vol () const;
156
157 void convert (Plm_image_type new_type);
158 void convert_to_original_type (void);
159 void convert_to_itk (void);
160 void convert_to_itk_float_field (void);
161 void convert_to_itk_uchar_vec (void);
162
163 /* geometry */
164 int planes ();
165 size_t dim (size_t);
166 float origin (size_t);
167 float spacing (size_t);
168 void set_header (const Plm_image_header*);
169 void set_header (const Plm_image_header&);
170
171 /* debug */
172 void print ();
173
174 /* Static functions */
175 static int compare_headers (
176 const Plm_image::Pointer& pli1,
177 const Plm_image::Pointer& pli2);
178 static Plm_image::Pointer clone (const Plm_image::Pointer& pli);
179
180protected:
181 /* Utility functions */
182 void free_volume ();
183
184 /* Specific converters: implemented in plm_image_convert.cxx */
185 void convert_itk_uchar_to_itk_uchar_vec ();
186 void convert_itk_uint32_to_itk_uchar_vec ();
187 void convert_gpuit_uint32_to_itk_uchar_vec ();
188 void convert_gpuit_uchar_vec_to_itk_uchar_vec ();
189 void convert_itk_uchar_vec_to_gpuit_uchar_vec ();
190
191 /* Generic converters: implemented in plm_image_convert.cxx */
192 template<class T, class U> T convert_gpuit_to_itk (Volume *vol);
193 template<class T, class U> void convert_itk_to_gpuit (T img);
194};
195
196/* -----------------------------------------------------------------------
197 Public functions
198 ----------------------------------------------------------------------- */
200 const char* fname, Plm_image_type type);
202 const std::string& fname, Plm_image_type type);
204 const char* fname);
206 const std::string& fname);
207
208#endif
The Plm_image_header class defines the geometry of an image. It defines image origin,...
Definition plm_image_header.h:24
Definition plm_image_p.h:10
The Plm_image class represents a three-dimensional volume. The volume is an abstraction that can co...
Definition plm_image.h:27
Plm_image_private * d_ptr
Definition plm_image.h:30
FloatImageType::Pointer & itk_float()
Definition plm_image.h:139
UShortImageType::Pointer m_itk_ushort
Definition plm_image.h:53
Int32ImageType::Pointer m_itk_int32
Definition plm_image.h:56
FloatImageType::Pointer m_itk_float
Definition plm_image.h:59
std::shared_ptr< Self > Pointer
Definition plm_image.h:29
Plm_image_type m_original_type
Definition plm_image.h:47
CharImageType::Pointer m_itk_char
Definition plm_image.h:52
UCharVecImageType::Pointer & itk_uchar_vec()
Definition plm_image.h:143
UCharImageType::Pointer & itk_uchar()
Definition plm_image.h:127
DoubleImageType::Pointer m_itk_double
Definition plm_image.h:60
UInt32ImageType::Pointer m_itk_uint32
Definition plm_image.h:55
UShortImageType::Pointer & itk_ushort()
Definition plm_image.h:135
UInt64ImageType::Pointer m_itk_uint64
Definition plm_image.h:57
UCharVecImageType::Pointer m_itk_uchar_vec
Definition plm_image.h:61
ShortImageType::Pointer m_itk_short
Definition plm_image.h:54
UCharImageType::Pointer m_itk_uchar
Definition plm_image.h:51
Plm_image_type m_type
Definition plm_image.h:48
Int64ImageType::Pointer m_itk_int64
Definition plm_image.h:58
ShortImageType::Pointer & itk_short()
Definition plm_image.h:131
The Rt_study_metadata encapsulate DICOM metadata for an Rt_study. The Rt_study_metadata includes sepa...
Definition rt_study_metadata.h:27
The Volume class represents a three-dimensional volume on a uniform grid. The volume can be located a...
Definition volume.h:38
Plm_image::Pointer plm_image_load(const char *fname, Plm_image_type type)
Definition plm_image.cxx:242
Plm_image::Pointer plm_image_load_native(const char *fname)
Definition plm_image.cxx:260
Plm_image_type
Definition plm_image_type.h:11
#define PLMBASE_API
Definition plmbase_config.h:19
#define SMART_POINTER_SUPPORT(T)
Definition smart_pointer.h:19