forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageData.hh
134 lines (114 loc) · 4 KB
/
ImageData.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
128
129
130
131
132
133
134
//----------------------------------*-C++-*----------------------------------//
// Copyright 2020-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/ImageData.hh
//---------------------------------------------------------------------------//
#pragma once
#include "corecel/Assert.hh"
#include "corecel/cont/Array.hh"
#include "corecel/data/Collection.hh"
#include "corecel/data/CollectionBuilder.hh"
#include "geocel/Types.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Scalar properties for building a rasterized image.
*
* These properties specify a "window" that's a slice of a 3D geometry. It uses
* graphics conventions of making the upper left corner the origin.
*
* The \c down basis vector corresponds to increasing \em j and is used for
* track initialization. The \c right basis vector corresponds to increasing
* \em i and is used for track movement. Because the user-specified window may
* not have an integer ratio of the two sides, we have a "max length" for
* raytracing to the right. This also lets us round up the image dimensions to
* a convenient alignment.
*
* All units are "native" length.
*/
struct ImageParamsScalars
{
using Size2 = Array<size_type, 2>;
Real3 origin{}; //!< Upper left corner
Real3 down{}; //!< Downward basis vector
Real3 right{}; //!< Rightward basis vector (increasing i, track movement)
real_type pixel_width{}; //!< Width of a pixel
Size2 dims{}; //!< Image dimensions (rows, columns)
real_type max_length{}; //!< Maximum distance along rightward to trace
//! Whether the interface is initialized
explicit CELER_FUNCTION operator bool() const
{
return pixel_width > 0 && dims[0] > 0 && dims[1] > 0 && max_length > 0;
}
};
//---------------------------------------------------------------------------//
/*!
* Persistent data used to construct an image.
*
* TODO: add material/cell -> RGB for inline rendering?
*/
template<Ownership W, MemSpace M>
struct ImageParamsData
{
//// DATA ////
ImageParamsScalars scalars;
//// METHODS ////
//! True if assigned
explicit CELER_FUNCTION operator bool() const
{
return static_cast<bool>(scalars);
}
//! Assign from another set of data
template<Ownership W2, MemSpace M2>
ImageParamsData& operator=(ImageParamsData<W2, M2> const& other)
{
CELER_EXPECT(other);
scalars = other.scalars;
return *this;
}
};
//---------------------------------------------------------------------------//
/*!
* Image state data.
*
* This is just a representation of the image itself.
*/
template<Ownership W, MemSpace M>
struct ImageStateData
{
//// TYPES ////
template<class T>
using Items = celeritas::Collection<T, W, M>;
//// DATA ////
Items<int> image; //!< Stored image [i][j]
//// METHODS ////
//! True if sizes are consistent and nonzero
explicit CELER_FUNCTION operator bool() const { return !image.empty(); }
//! Number of pixels
CELER_FUNCTION size_type size() const { return image.size(); }
//! Assign from another set of data
template<Ownership W2, MemSpace M2>
ImageStateData& operator=(ImageStateData<W2, M2>& other)
{
CELER_EXPECT(other);
image = other.image;
return *this;
}
};
//---------------------------------------------------------------------------//
/*!
* Resize geometry tracking states.
*/
template<MemSpace M>
inline void resize(ImageStateData<Ownership::value, M>* data,
HostCRef<ImageParamsData> const& params)
{
CELER_EXPECT(data);
CELER_EXPECT(params);
resize(&data->image, params.scalars.dims[0] * params.scalars.dims[1]);
}
//---------------------------------------------------------------------------//
} // namespace celeritas