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