78 virtual void create_image() = 0;
79 virtual void write_image();
80 virtual void read_image();
81 virtual void check_result() = 0;
82 shared_ptr<VoxelsOnCartesianGrid<float>> create_single_image();
87 shared_ptr<OutputFileFormat<A>> _output_file_format_sptr;
89 std::string _filename;
90 shared_ptr<A> _image_to_write_sptr;
91 shared_ptr<A> _image_to_read_sptr;
95IOTests<A>::IOTests(std::istream& in)
103 _filename =
"STIRtmp";
105 _output_file_format_sptr.reset();
106 _parser.add_start_key(
"Test OutputFileFormat Parameters");
107 _parser.add_parsing_key(
"output file format type", &_output_file_format_sptr);
108 _parser.add_stop_key(
"END");
110 std::cerr <<
"Testing OutputFileFormat parsing function..." << std::endl;
111 std::cerr <<
"WARNING: will overwite files called STIRtmp*\n";
113 if (!check(_parser.parse(_in),
"parsing failed"))
116 if (!check(!is_null_ptr(_output_file_format_sptr),
"parsing failed to set _output_file_format_sptr"))
121shared_ptr<VoxelsOnCartesianGrid<float>>
122IOTests<A>::create_single_image()
125#ifdef HAVE_LLN_MATRIX
127 USING_NAMESPACE_ECAT6
130 const bool supports_different_xy_pixel_sizes
131 =
dynamic_cast<ECAT6OutputFileFormat const* const
>(_output_file_format_sptr.get()) == 0 ? true :
false;
132 const bool supports_origin_z_shift
133 =
dynamic_cast<ECAT6OutputFileFormat const* const
>(_output_file_format_sptr.get()) == 0 ? true :
false;
134 const bool supports_origin_xy_shift =
true;
136 const bool supports_different_xy_pixel_sizes =
true;
137 const bool supports_origin_z_shift =
true;
138 const bool supports_origin_xy_shift =
true;
142 if (supports_origin_xy_shift)
147 if (supports_origin_z_shift)
156 shared_ptr<ExamInfo> exam_info_sptr(
new ExamInfo);
157 exam_info_sptr->time_frame_definitions.set_num_time_frames(1);
158 exam_info_sptr->time_frame_definitions.set_time_frame(1, 10, 100);
159 exam_info_sptr->start_time_in_secs_since_1970 = double(1277478034);
160 exam_info_sptr->set_high_energy_thres(100.);
161 exam_info_sptr->set_low_energy_thres(5.);
163 shared_ptr<VoxelsOnCartesianGrid<float>> single_image_sptr(
169 for (
int z = single_image.get_min_z(); z <= single_image.get_max_z(); ++z)
170 for (
int y = single_image.get_min_y(); y <= single_image.get_max_y(); ++y)
171 for (
int x = single_image.get_min_x(); x <= single_image.get_max_x(); ++x)
172 single_image[z][y][x] = 3 * sin(
static_cast<float>(x *
_PI) / single_image.get_max_x())
173 * sin(
static_cast<float>(y + 10 *
_PI) / single_image.get_max_y())
174 * cos(
static_cast<float>(z *
_PI / 3) / single_image.get_max_z());
176 return single_image_sptr;
181IOTests<A>::write_image()
184 const Succeeded success = _output_file_format_sptr->write_to_file(_filename, *_image_to_write_sptr);
186 check(success == Succeeded::yes,
"failed writing");
191IOTests<A>::read_image()
196 check(!is_null_ptr(_image_to_read_sptr),
"failed reading");
203 set_tolerance(.000001);
205 if (_output_file_format_sptr->get_type_of_numbers().integer_type())
207 set_tolerance(10. * im_1.find_max()
208 / pow(2.,
static_cast<double>(_output_file_format_sptr->get_type_of_numbers().size_in_bits())));
211 check_if_equal(im_1.get_voxel_size(), im_2.get_voxel_size(),
"test on read and written file via image voxel size");
212 check_if_equal(im_1.get_length(), im_2.get_length(),
"test on read and written file via image length");
213 check_if_equal(im_1.get_lengths(), im_2.get_lengths(),
"test on read and written file via image lengths");
214 check_if_equal(im_1.get_max_index(), im_2.get_max_index(),
"test on read and written file via image max index");
215 check_if_equal(im_1.get_max_indices(), im_2.get_max_indices(),
"test on read and written file via image max indices");
216 check_if_equal(im_1.get_max_x(), im_2.get_max_x(),
"test on read and written file via image max x");
217 check_if_equal(im_1.get_max_y(), im_2.get_max_y(),
"test on read and written file via image max y");
218 check_if_equal(im_1.get_max_z(), im_2.get_max_z(),
"test on read and written file via image max z");
219 check_if_equal(im_1.get_min_index(), im_2.get_min_index(),
"test on read and written file via image min index");
220 check_if_equal(im_1.get_min_indices(), im_2.get_min_indices(),
"test on read and written file via image min indices");
221 check_if_equal(im_1.get_min_x(), im_2.get_min_x(),
"test on read and written file via image min x");
222 check_if_equal(im_1.get_min_y(), im_2.get_min_y(),
"test on read and written file via image min y");
223 check_if_equal(im_1.get_min_z(), im_2.get_min_z(),
"test on read and written file via image min z");
224 check_if_equal(im_1.get_x_size(), im_2.get_x_size(),
"test on read and written file via image x size");
225 check_if_equal(im_1.get_y_size(), im_2.get_y_size(),
"test on read and written file via image y size");
226 check_if_equal(im_1.get_z_size(), im_2.get_z_size(),
"test on read and written file via image z size");
227 check_if_equal(im_1.find_max(), im_2.find_max(),
"test on read and written file via image max");
228 check_if_equal(im_1.find_min(), im_2.find_min(),
"test on read and written file via image min");
230 check_if_equal(im_1, im_2,
"test on read and written file");
232 set_tolerance(.00001);
234 check_if_equal(im_1.get_origin(), im_2.get_origin(),
"test on read and written file via image origin");
239IOTests<A>::check_exam_info(
const ExamInfo& exm_inf_1,
const ExamInfo& exm_inf_2)
250 if (!check_if_equal(im_1_time_frames.get_num_time_frames(),
251 im_2_time_frames.get_num_time_frames(),
252 "test on read and written file via TimeFrameDefinitions::get_num_time_frames"))
256 for (
unsigned i = 1; i <= im_1_time_frames.get_num_frames(); i++)
258 check_if_equal(im_1_time_frames.get_end_time(i),
259 im_2_time_frames.get_end_time(i),
260 "test on read and written file via TimeFrameDefinitions::get_end_time");
261 check_if_equal(im_1_time_frames.get_start_time(i),
262 im_2_time_frames.get_start_time(i),
263 "test on read and written file via TimeFrameDefinitions::get_start_time");
277 this->create_single_image();
281 this->create_image();
285 std::cerr <<
"\nAbout to write the image to disk...\n";
289 std::cerr <<
"OK!\n";
291 std::cerr <<
"\nAbout to read the image back from disk...\n";
295 std::cerr <<
"OK!\n";
297 std::cerr <<
"\nAbout to check the consistency between the two images...\n";
298 this->check_result();
301 std::cerr <<
"OK!\n";