forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image.hh
127 lines (105 loc) · 3.68 KB
/
Image.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//----------------------------------*-C++-*----------------------------------//
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file geocel/rasterize/Image.hh
//---------------------------------------------------------------------------//
#pragma once
#include <memory>
#include "corecel/Types.hh"
#include "corecel/data/CollectionMirror.hh"
#include "corecel/data/ParamsDataInterface.hh"
#include "ImageData.hh"
#include "ImageInterface.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Image construction arguments.
*
* Image scale in this struct is *native* units, but JSON I/O defaults to
* centimeters for the window coordinates and accepts an optional "_units"
* parameter that can take values of cgs, si, or clhep to interpret the input
* as centimeters, meters, or millimeters.
*/
struct ImageInput
{
//!@{
//! Coordinates of the window [length]
Real3 lower_left{0, 0, 0};
Real3 upper_right{};
//!@}
//! Rightward basis vector, the new "x" axis
Real3 rightward{1, 0, 0};
//! Number of vertical pixels, aka threads when raytracing
size_type vertical_pixels{};
//! Round the number of horizontal pixels to this value
size_type horizontal_divisor{CELER_USE_DEVICE ? 128 / sizeof(int) : 1};
//! True if the input is unassigned
explicit operator bool() const
{
return vertical_pixels != 0 && lower_left != upper_right;
}
};
//---------------------------------------------------------------------------//
/*!
* Manage properties of an image.
*
* The same image params can be used to construct multiple images (using
* different ray tracing methods or different geometries or on host vs device).
*/
class ImageParams final : public ParamsDataInterface<ImageParamsData>
{
public:
// Construct with image properties
explicit ImageParams(ImageInput const&);
//! Access scalar image properties
ImageParamsScalars const& scalars() const
{
return this->host_ref().scalars;
}
//! Number of pixels in an image created from these params
size_type num_pixels() const
{
auto const& dims = this->scalars().dims;
return dims[0] * dims[1];
}
//! Number of horizontal lines to be used for raytracing
size_type num_lines() const { return this->scalars().dims[0]; }
//! Access properties on the host
HostRef const& host_ref() const final { return data_.host_ref(); }
//! Access properties on the device
DeviceRef const& device_ref() const final { return data_.device_ref(); }
private:
CollectionMirror<ImageParamsData> data_;
};
//---------------------------------------------------------------------------//
/*!
* Implement an image on host or device.
*/
template<MemSpace M>
class Image final : public ImageInterface
{
public:
//!@{
//! \name Type aliases
using Value = ImageStateData<Ownership::value, M>;
using Ref = ImageStateData<Ownership::reference, M>;
//!@}
public:
// Construct from parameters
explicit Image(SPConstParams params);
//! Access image properties
SPConstParams const& params() const final { return params_; }
// Write the image to a stream in binary format
void copy_to_host(SpanInt) const final;
//! Access the mutable state data
Ref const& ref() { return ref_; }
private:
SPConstParams params_;
Value value_;
Ref ref_;
};
//---------------------------------------------------------------------------//
} // namespace celeritas