![]() |
|
|||
File indexing completed on 2025-09-15 08:59:51
0001 //------------------------------- -*- C++ -*- -------------------------------// 0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details 0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0004 //---------------------------------------------------------------------------// 0005 //! \file geocel/rasterize/ImageData.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include "corecel/Assert.hh" 0010 #include "corecel/cont/Array.hh" 0011 #include "corecel/data/Collection.hh" 0012 #include "corecel/data/CollectionBuilder.hh" 0013 #include "geocel/Types.hh" 0014 0015 namespace celeritas 0016 { 0017 //---------------------------------------------------------------------------// 0018 /*! 0019 * Scalar properties for building a rasterized image. 0020 * 0021 * These properties specify a "window" that's a slice of a 3D geometry. It uses 0022 * graphics conventions of making the upper left corner the origin. 0023 * 0024 * The \c down basis vector corresponds to increasing \em j and is used for 0025 * track initialization. The \c right basis vector corresponds to increasing 0026 * \em i and is used for track movement. Because the user-specified window may 0027 * not have an integer ratio of the two sides, we have a "max length" for 0028 * raytracing to the right. This also lets us round up the image dimensions to 0029 * a convenient alignment. 0030 * 0031 * All units are "native" length. 0032 */ 0033 struct ImageParamsScalars 0034 { 0035 Real3 origin{}; //!< Upper left corner 0036 Real3 down{}; //!< Downward basis vector 0037 Real3 right{}; //!< Rightward basis vector (increasing i, track movement) 0038 real_type pixel_width{}; //!< Width of a pixel 0039 Size2 dims{}; //!< Image dimensions (row, column) = (y, x) 0040 real_type max_length{}; //!< Maximum distance along rightward to trace 0041 0042 //! Whether the interface is initialized 0043 explicit CELER_FUNCTION operator bool() const 0044 { 0045 return pixel_width > 0 && dims[0] > 0 && dims[1] > 0 && max_length > 0; 0046 } 0047 }; 0048 0049 //---------------------------------------------------------------------------// 0050 /*! 0051 * Persistent data used to construct an image. 0052 * 0053 * TODO: add material/cell -> RGB for inline rendering? 0054 */ 0055 template<Ownership W, MemSpace M> 0056 struct ImageParamsData 0057 { 0058 //// DATA //// 0059 0060 ImageParamsScalars scalars; 0061 0062 //// METHODS //// 0063 0064 //! True if assigned 0065 explicit CELER_FUNCTION operator bool() const 0066 { 0067 return static_cast<bool>(scalars); 0068 } 0069 0070 //! Assign from another set of data 0071 template<Ownership W2, MemSpace M2> 0072 ImageParamsData& operator=(ImageParamsData<W2, M2> const& other) 0073 { 0074 CELER_EXPECT(other); 0075 scalars = other.scalars; 0076 return *this; 0077 } 0078 }; 0079 0080 //---------------------------------------------------------------------------// 0081 /*! 0082 * Image state data. 0083 * 0084 * This is just a representation of the image itself. 0085 */ 0086 template<Ownership W, MemSpace M> 0087 struct ImageStateData 0088 { 0089 //// TYPES //// 0090 0091 template<class T> 0092 using Items = celeritas::Collection<T, W, M>; 0093 0094 //// DATA //// 0095 0096 Items<int> image; //!< Stored image [i][j] 0097 0098 //// METHODS //// 0099 0100 //! True if sizes are consistent and nonzero 0101 explicit CELER_FUNCTION operator bool() const { return !image.empty(); } 0102 0103 //! Number of pixels 0104 CELER_FUNCTION size_type size() const { return image.size(); } 0105 0106 //! Assign from another set of data 0107 template<Ownership W2, MemSpace M2> 0108 ImageStateData& operator=(ImageStateData<W2, M2>& other) 0109 { 0110 CELER_EXPECT(other); 0111 image = other.image; 0112 return *this; 0113 } 0114 }; 0115 0116 //---------------------------------------------------------------------------// 0117 /*! 0118 * Resize geometry tracking states. 0119 */ 0120 template<MemSpace M> 0121 inline void resize(ImageStateData<Ownership::value, M>* data, 0122 HostCRef<ImageParamsData> const& params) 0123 { 0124 CELER_EXPECT(data); 0125 CELER_EXPECT(params); 0126 0127 resize(&data->image, params.scalars.dims[0] * params.scalars.dims[1]); 0128 } 0129 0130 //---------------------------------------------------------------------------// 0131 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |