42 #ifdef HAVE_LLN_MATRIX 74 void run_tests()
override;
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;
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"))
121 shared_ptr<VoxelsOnCartesianGrid<float>>
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;
184 const Succeeded success = _output_file_format_sptr->write_to_file(_filename, *_image_to_write_sptr);
186 check(success == Succeeded::yes,
"failed writing");
194 _image_to_read_sptr = read_from_file<A>(_filename);
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())
208 / pow(2., static_cast<double>(_output_file_format_sptr->get_type_of_numbers().size_in_bits())));
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");
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");
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");
252 "test on read and written file via TimeFrameDefinitions::get_num_time_frames"))
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";
305 everything_ok =
false;
int get_length() const
return number of elements in this vector
Definition: VectorWithOffset.inl:534
This class is used to represent voxelised densities on a cuboid grid (3D).
Definition: FBP3DRPReconstruction.h:43
Class used for storing time frame durations.
Definition: TimeFrameDefinitions.h:38
unsigned int get_num_time_frames() const
Get number of frames.
Definition: TimeFrameDefinitions.cxx:92
Declaration of class stir::Succeeded.
#define _PI
The constant pi to high precision.
Definition: common.h:134
A class to parse Interfile headers.
Definition: KeyParser.h:161
elemT find_max() const
return maximum of all the elements
Definition: Array.inl:364
int get_min_index() const
get value of first valid index
Definition: VectorWithOffset.inl:116
CartesianCoordinate3D< float > get_voxel_size() const
is the same as get_grid_spacing(), but now returns CartesianCoordinate3D for convenience ...
Definition: VoxelsOnCartesianGrid.inl:27
int get_x_size() const
Definition: VoxelsOnCartesianGrid.inl:55
Definition of stir::is_null_ptr functions.
A simple class to test the OutputFileFormat function.
Definition: test_IO.h:69
A base class for making test classesWith a derived class, an application could look like...
Definition: RunTests.h:71
elemT find_min() const
return minimum of all the elements
Definition: Array.inl:390
a class for storing information about 1 exam (or scan)
Definition: ExamInfo.h:41
int get_max_index() const
get value of last valid index
Definition: VectorWithOffset.inl:123
const CartesianCoordinate3D< float > & get_origin() const
Return the origin.
Definition: DiscretisedDensity.inl:64
defines the stir::VoxelsOnCartesianGrid class
unsigned int get_num_frames() const
Get number of frames.
Definition: TimeFrameDefinitions.cxx:86
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
Declaration of stir::read_from_file functions (providing easy access to class stir::InputFileFormatRe...
defines the stir::RunTests class