File indexing completed on 2025-09-17 08:59:58
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "SafetyImager.hh"
0010
0011 #include <fstream>
0012 #include <nlohmann/json.hpp>
0013
0014 #include "ImageIO.json.hh"
0015
0016 #include "detail/SafetyCalculator.hh"
0017
0018 namespace celeritas
0019 {
0020
0021
0022
0023
0024 template<class G>
0025 SafetyImager<G>::SafetyImager(SPConstGeo geo) : geo_{std::move(geo)}
0026 {
0027 CELER_EXPECT(geo_);
0028
0029 host_state_ = {geo_->host_ref(), 1};
0030 }
0031
0032
0033
0034
0035
0036 template<class G>
0037 void SafetyImager<G>::operator()(ImageParams const& image, std::string filename)
0038 {
0039 std::ofstream out{filename, std::ios::out | std::ios::trunc};
0040 CELER_VALIDATE(out, << "failed to open '" << filename << "'");
0041 out << nlohmann::json(image).dump() << std::endl;
0042
0043 auto const& scalars = image.scalars();
0044 real_type max_distance = celeritas::max(scalars.dims[0], scalars.dims[1])
0045 * scalars.pixel_width;
0046
0047 detail::SafetyCalculator calc_safety{
0048 GeoTrackView{geo_->host_ref(), host_state_.ref(), TrackSlotId{0}},
0049 image.host_ref(),
0050 max_distance};
0051
0052 std::vector<double> line;
0053 for (auto i : range(scalars.dims[0]))
0054 {
0055 line.clear();
0056 for (auto j : range(scalars.dims[1]))
0057 {
0058 line.push_back(calc_safety(j, i));
0059 }
0060 out << nlohmann::json(line).dump() << std::endl;
0061 }
0062 }
0063
0064
0065 }