43 : mhd_header_file_(
""),
46 mhd_data_type_(
"MET_FLOAT")
48 GGcout(
"GGEMSMHDImage",
"GGEMSMHDImage", 3) <<
"GGEMSMHDImage creating..." <<
GGendl;
59 GGcout(
"GGEMSMHDImage",
"GGEMSMHDImage", 3) <<
"GGEMSMHDImage created!!!" <<
GGendl;
68 GGcout(
"GGEMSMHDImage",
"~GGEMSMHDImage", 3) <<
"GGEMSMHDImage erasing!!!" <<
GGendl;
70 GGcout(
"GGEMSMHDImage",
"~GGEMSMHDImage", 3) <<
"GGEMSMHDImage erased!!!" <<
GGendl;
80 GGsize found_mhd = filename.find(
".mhd");
81 if (found_mhd == std::string::npos) {
88 GGsize found_dir = filename.find_last_of(
"/\\");
89 if (found_dir != std::string::npos) {
91 mhd_raw_file_ = filename.substr(found_dir+1, found_mhd-found_dir-1) +
".raw";
131 GGcout(
"GGEMSMHDImage",
"Read", 2) <<
"Reading MHD Image..." <<
GGendl;
134 std::ifstream in_header_stream(image_mhd_header_filename, std::ios::in);
145 std::size_t found_dir = image_mhd_header_filename.find_last_of(
"/\\");
146 if (found_dir != std::string::npos) {
147 output_dir_ = image_mhd_header_filename.substr(0, found_dir+1);
151 std::string line(
"");
152 while (std::getline(in_header_stream, line)) {
165 if (!kKey.compare(
"DimSize")) {
170 else if (!kKey.compare(
"ElementSpacing")) {
173 else if (!kKey.compare(
"ElementType")) {
176 else if (!kKey.compare(
"ElementDataFile")) {
182 in_header_stream.close();
186 std::ostringstream oss(std::ostringstream::out);
187 oss <<
"Dimension invalid for the key 'DimSize'!!! The values have to be > 0";
192 std::ostringstream oss(std::ostringstream::out);
193 oss <<
"Voxel size invalid for the key 'ElementSpacing'!!! The values have to be > 0";
198 std::ostringstream oss(std::ostringstream::out);
199 oss <<
"Value invalid for the key 'ElementType'!!! The value have to be 'MET_DOUBLE' or 'MET_FLOAT' or 'MET_SHORT' or 'MET_USHORT' or 'MET_UCHAR' or 'MET_CHAR' or 'MET_UINT' or 'MET_INT'";
204 std::ostringstream oss(std::ostringstream::out);
205 oss <<
"Value invalid for the key 'ElementDataFile'!!! A filename for raw data has to be given";
210 for (
GGsize i = 0; i < 3; ++i) {
232 out_header_stream <<
"ObjectType = Image" << std::endl;
233 out_header_stream <<
"BinaryDataByteOrderMSB = False" << std::endl;
234 out_header_stream <<
"NDims = 3" << std::endl;
237 out_header_stream <<
"ElementType = " <<
mhd_data_type_ << std::endl;
238 out_header_stream <<
"ElementDataFile = " <<
mhd_raw_file_ << std::endl;
239 out_header_stream.close();
242 if (!
mhd_data_type_.compare(
"MET_CHAR")) WriteRaw<char>(image, thread_index);
243 else if (!
mhd_data_type_.compare(
"MET_UCHAR")) WriteRaw<unsigned char>(image, thread_index);
244 else if (!
mhd_data_type_.compare(
"MET_SHORT")) WriteRaw<GGshort>(image, thread_index);
245 else if (!
mhd_data_type_.compare(
"MET_USHORT")) WriteRaw<GGushort>(image, thread_index);
246 else if (!
mhd_data_type_.compare(
"MET_INT")) WriteRaw<GGint>(image, thread_index);
247 else if (!
mhd_data_type_.compare(
"MET_UINT")) WriteRaw<GGuint>(image, thread_index);
248 else if (!
mhd_data_type_.compare(
"MET_FLOAT")) WriteRaw<GGfloat>(image, thread_index);
249 else if (!
mhd_data_type_.compare(
"MET_DOUBLE")) WriteRaw<GGfloat>(image, thread_index);