|
|
|||
File indexing completed on 2025-11-05 09:43:05
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/Image.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <memory> 0010 0011 #include "corecel/Types.hh" 0012 #include "corecel/data/CollectionMirror.hh" 0013 #include "corecel/data/ParamsDataInterface.hh" 0014 0015 #include "ImageData.hh" 0016 #include "ImageInterface.hh" 0017 0018 namespace celeritas 0019 { 0020 //---------------------------------------------------------------------------// 0021 /*! 0022 * Image construction arguments. 0023 * 0024 * Image scale in this struct is *native* units, but JSON I/O defaults to 0025 * centimeters for the window coordinates and accepts an optional "_units" 0026 * parameter that can take values of cgs, si, or clhep to interpret the input 0027 * as centimeters, meters, or millimeters. 0028 */ 0029 struct ImageInput 0030 { 0031 //!@{ 0032 //! Coordinates of the window [length] 0033 Real3 lower_left{0, 0, 0}; 0034 Real3 upper_right{}; 0035 //!@} 0036 0037 //! Rightward basis vector, the new "x" axis 0038 Real3 rightward{1, 0, 0}; 0039 0040 //! Number of vertical pixels, aka threads when raytracing 0041 size_type vertical_pixels{}; 0042 0043 //! Round the number of horizontal pixels to this value 0044 size_type horizontal_divisor{CELER_USE_DEVICE ? 128 / sizeof(int) : 1}; 0045 0046 //! True if the input is unassigned 0047 explicit operator bool() const 0048 { 0049 return vertical_pixels != 0 && lower_left != upper_right; 0050 } 0051 }; 0052 0053 //---------------------------------------------------------------------------// 0054 /*! 0055 * Manage properties of an image. 0056 * 0057 * An image is a "window", a 2D rectangle slice of 3D space. As with computer 0058 * GUI windows, matplotlib \c imshow, and other visual rendering layouts, the 0059 * pixel order is like text on a page: left to right, then top to bottom. 0060 * Because this is vertically flipped from "mathematical" ordering, we store 0061 * the upper left coordinate and a \em -y basis vector rather than a lower left 0062 * coordinate and a \em +y basis vector. 0063 * 0064 * The same image params can be used to construct multiple images (using 0065 * different ray tracing methods or different geometries or on host vs device). 0066 */ 0067 class ImageParams final : public ParamsDataInterface<ImageParamsData> 0068 { 0069 public: 0070 // Construct with image properties 0071 explicit ImageParams(ImageInput const&); 0072 0073 //! Access scalar image properties 0074 ImageParamsScalars const& scalars() const 0075 { 0076 return this->host_ref().scalars; 0077 } 0078 0079 //! Number of pixels in an image created from these params 0080 size_type num_pixels() const 0081 { 0082 auto const& dims = this->scalars().dims; 0083 return dims[0] * dims[1]; 0084 } 0085 0086 //! Number of horizontal lines to be used for raytracing 0087 size_type num_lines() const { return this->scalars().dims[0]; } 0088 0089 //! Access properties on the host 0090 HostRef const& host_ref() const final { return data_.host_ref(); } 0091 0092 //! Access properties on the device 0093 DeviceRef const& device_ref() const final { return data_.device_ref(); } 0094 0095 private: 0096 CollectionMirror<ImageParamsData> data_; 0097 }; 0098 0099 //---------------------------------------------------------------------------// 0100 /*! 0101 * Implement an image on host or device. 0102 */ 0103 template<MemSpace M> 0104 class Image final : public ImageInterface 0105 { 0106 public: 0107 //!@{ 0108 //! \name Type aliases 0109 using Value = ImageStateData<Ownership::value, M>; 0110 using Ref = ImageStateData<Ownership::reference, M>; 0111 //!@} 0112 0113 public: 0114 // Construct from parameters 0115 explicit Image(SPConstParams params); 0116 0117 //! Access image properties 0118 SPConstParams const& params() const final { return params_; } 0119 0120 // Write the image to a stream in binary format 0121 void copy_to_host(SpanInt) const final; 0122 0123 //! Access the mutable state data 0124 Ref const& ref() { return ref_; } 0125 0126 private: 0127 SPConstParams params_; 0128 Value value_; 0129 Ref ref_; 0130 }; 0131 0132 //---------------------------------------------------------------------------// 0133 } // 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 |
|