ippl icon indicating copy to clipboard operation
ippl copied to clipboard

Rendering

Open manuel5975p opened this issue 1 year ago • 0 comments

Synopsis

Add Kokkos-contained rendering for Fields and particles.

  • Image class representing an image with save functionality (png, bmp or jpg)
  • 3D Rendering functionality
  • 2D Cross section rendering functionality
  • Colormaps

Data flow

graph LR
F[Field] --> DF[Draw 3D Fog]
F[Field] --> DCS[Draw Cross-Section]
P[Particles] --> DP[Draw 3D Particles]
P[Particles] --> DPR[Draw 2D Particles]
F[Field] -- Mesh Extents --> DP
F[Field] -- Mesh Extents --> DPR
DF --> I[Image]
DCS --> I[Image]
DP --> I[Image]
DPR --> I[Image]
I --> Coll[Collect on Rank 0]
Coll --> png[Save to PNG]
Coll --> bmp[Save to BMP]
Coll --> Pipe[Write to Pipe]
Pipe --> ffmpeg

Added functions and types

Image

    /**
     * @brief Struct representing an image with depth and color
     * 
     */
    struct Image{
        //Color type, representing an RGBA color with values in [0,1]
        using color_type = Vector<float, 4>;
        //Depth type, representing framebuffer depth
        using depth_type = float;

        //Resolution of the image
        uint32_t width, height;

        //Color buffer (Kokkos::View<color_type*>), width * height elements
        color_buffer_type color_buffer;
        //Depth buffer (Kokkos::View<depth_type*>), width * height elements
        depth_buffer_type depth_buffer;
}

axis

An axis represents to which axis a cut plane for cross section plots should be perpendicular to.

    enum struct axis : unsigned{
        x, y, z
    };

drawFieldFog

    /**
     * @brief Draw a fog representation of a 3D Field with raymarching
     * 
     * @tparam T Scalar type of the mesh, should be an actual scalar and not a vector
     * @tparam field_valuetype Value type of the field
     * @tparam color_map A function mapping field_valuetype to either Vector<float, 3> or Vector<float, 4>
     * @return An image containing the rendered field. 
     * @details The contained depth info is as if the field was an opaque cube.
     */
    template<typename T, typename field_valuetype, typename color_map>
        requires (std::is_invocable_r_v<ippl::Vector<float, 3>, color_map, field_valuetype> || 
                  std::is_invocable_r_v<ippl::Vector<float, 4>, color_map, field_valuetype>)
    Image drawFieldFog(const Field<field_valuetype, 3, UniformCartesian<T, 3>, typename UniformCartesian<T, 3>::DefaultCentering>& f, const uint32_t width, const uint32_t height, rm::camera cam, color_map cmap, Image already_drawn = Image());

drawParticles

/**
     * @brief Draw particles as size-corrected circles to the screen as seen from a certain point
     * 
     * @tparam vector_type 
     * @param position_view Kokkos View containing position vectors
     * @param count Amount of particles to be visualized, must be <= position_view.extent(0)
     * @param width Output image width
     * @param height Output image height
     * @param cam Point of view camera
     * @param radius Visible particle radius
     * @param particle_color Visible particle color
     */
    template<typename vector_type>
        requires(vector_type::dim == 3)
    Image drawParticles(Kokkos::View<vector_type*> position_view, size_t count, int width, int height, rm::camera cam, float particle_radius, Vector<float, 4> particle_color);

drawFieldCrossSection

    /**
     * @brief Draws an axis-aligned cross section of a field
     * 
     * @tparam T Scalar type of the mesh, should be an actual scalar and not a vector
     * @tparam field_valuetype Value type of the field
     * @tparam color_map A function mapping field_valuetype to either Vector<float, 3> or Vector<float, 4>
     * @param width Image width
     * @param height Image height
     * @param axis_index 0 for yz plane, 1 for xz plane, 2 for xy plane
     * @param offset Offset along cross section plane normal
     */
    template<typename T, typename field_valuetype, typename color_map>
        requires (std::is_invocable_r_v<ippl::Vector<float, 3>, color_map, field_valuetype> || 
                  std::is_invocable_r_v<ippl::Vector<float, 4>, color_map, field_valuetype>)
    Image drawFieldCrossSection(const Field<field_valuetype, 3, UniformCartesian<T, 3>, typename UniformCartesian<T, 3>::DefaultCentering>& f, const uint32_t width, const uint32_t height, axis perpendicular_to, T offset, color_map cmap)

drawBunchProjection

/**
     * @brief Project particles onto a plane and draw them. Requires a domain for scaling
     * 
     * @param position_attrib ParticleAttribute describing the particles' positions
     * @param count Amount of particles to be drawn, must be < position_attrib.extent(0)
     * @param width Image width
     * @param height Image height
     * @param axis Projection plane axis, either ippl::axis::x, ippl::axis::y or ippl::axis::z
     * @param domain the domain to fit onto the screen
     * @param particle_radius On-Screen radii of drawn particles
     * @param particle_color On-Screen fill color of particles
     * 
     * 
     * @tparam vector_type Position vector type
     */
    template<typename vector_type, class... Properties>
        requires(vector_type::dim == 3)
    Image drawBunchProjection(ippl::ParticleAttrib<vector_type, Properties...> position_attrib, int width, int height, const axis orthogonal_to, aabb<typename vector_type::value_type, 3> dom, float particle_radius, Vector<float, 4> particle_color)

manuel5975p avatar May 05 '24 18:05 manuel5975p