make_polyhedron Subroutine

private subroutine make_polyhedron(self)

The polyhedron's nodes, made again (if shown).

Arguments

Type IntentOptional Attributes Name
class(Polyhedron), intent(inout) :: self

Calls

proc~~make_polyhedron~~CallsGraph proc~make_polyhedron make_polyhedron interface~vkf_switch_create vkf_switch_create proc~make_polyhedron->interface~vkf_switch_create proc~add add proc~make_polyhedron->proc~add proc~line_node line_node proc~make_polyhedron->proc~line_node proc~marker_node marker_node proc~make_polyhedron->proc~marker_node proc~replace ShapeNodes%replace proc~make_polyhedron->proc~replace proc~surface_node surface_node proc~make_polyhedron->proc~surface_node proc~unit_normal unit_normal proc~make_polyhedron->proc~unit_normal proc~vertex_normals vertex_normals proc~make_polyhedron->proc~vertex_normals proc~vertices_sphere vertices_sphere proc~make_polyhedron->proc~vertices_sphere interface~vkf_node_add_child vkf_node_add_child proc~add->interface~vkf_node_add_child interface~vkf_node_delete vkf_node_delete proc~add->interface~vkf_node_delete proc~check_status check_status proc~add->proc~check_status interface~vkf_line_create vkf_line_create proc~line_node->interface~vkf_line_create proc~line_node->proc~check_status proc~line_set_points line_set_points proc~line_node->proc~line_set_points proc~line_set_segments line_set_segments proc~line_node->proc~line_set_segments proc~line_set_style line_set_style proc~line_node->proc~line_set_style interface~vkf_marker_create vkf_marker_create proc~marker_node->interface~vkf_marker_create proc~marker_node->proc~check_status proc~marker_node->proc~line_set_points proc~marker_set_style marker_set_style proc~marker_node->proc~marker_set_style interface~vkf_compile_node vkf_compile_node proc~replace->interface~vkf_compile_node proc~replace->interface~vkf_node_add_child proc~replace->interface~vkf_node_delete interface~vkf_node_remove_child vkf_node_remove_child proc~replace->interface~vkf_node_remove_child proc~replace->proc~check_status interface~vkf_mesh_array vkf_mesh_array proc~surface_node->interface~vkf_mesh_array interface~vkf_mesh_create vkf_mesh_create proc~surface_node->interface~vkf_mesh_create interface~vkf_mesh_set_bound vkf_mesh_set_bound proc~surface_node->interface~vkf_mesh_set_bound proc~surface_node->proc~check_status proc~mesh_arrays mesh_arrays proc~surface_node->proc~mesh_arrays proc~cross cross proc~unit_normal->proc~cross proc~vertex_normals->proc~cross interface~vkf_line_points vkf_line_points proc~line_set_points->interface~vkf_line_points interface~vkf_line_points_changed vkf_line_points_changed proc~line_set_points->interface~vkf_line_points_changed interface~vkf_line_style vkf_line_style proc~line_set_segments->interface~vkf_line_style interface~vkf_line_style_changed vkf_line_style_changed proc~line_set_segments->interface~vkf_line_style_changed proc~line_set_style->interface~vkf_line_style proc~line_set_style->interface~vkf_line_style_changed proc~marker_set_style->interface~vkf_line_style proc~marker_set_style->interface~vkf_line_style_changed proc~mesh_arrays->interface~vkf_mesh_array

Called by

proc~~make_polyhedron~~CalledByGraph proc~make_polyhedron make_polyhedron proc~poly_build_contents Polyhedron%poly_build_contents proc~poly_build_contents->proc~make_polyhedron proc~poly_set_draw_mode Polyhedron%poly_set_draw_mode proc~poly_set_draw_mode->proc~make_polyhedron proc~poly_set_line_color Polyhedron%poly_set_line_color proc~poly_set_line_color->proc~make_polyhedron proc~poly_set_line_width Polyhedron%poly_set_line_width proc~poly_set_line_width->proc~make_polyhedron proc~poly_set_opacity Polyhedron%poly_set_opacity proc~poly_set_opacity->proc~make_polyhedron proc~remove_vertex_colors Polyhedron%remove_vertex_colors proc~remove_vertex_colors->proc~make_polyhedron proc~set_edges Polyhedron%set_edges proc~set_edges->proc~make_polyhedron proc~set_face_color Polyhedron%set_face_color proc~set_face_color->proc~make_polyhedron proc~set_faces Polyhedron%set_faces proc~set_faces->proc~make_polyhedron proc~set_grid Polyhedron%set_grid proc~set_grid->proc~make_polyhedron proc~set_lit Polyhedron%set_lit proc~set_lit->proc~make_polyhedron proc~set_point_color Polyhedron%set_point_color proc~set_point_color->proc~make_polyhedron proc~set_point_size Polyhedron%set_point_size proc~set_point_size->proc~make_polyhedron proc~set_smooth Polyhedron%set_smooth proc~set_smooth->proc~make_polyhedron proc~set_triangles Polyhedron%set_triangles proc~set_triangles->proc~make_polyhedron proc~set_two_sided Polyhedron%set_two_sided proc~set_two_sided->proc~make_polyhedron proc~set_vertex_colors Polyhedron%set_vertex_colors proc~set_vertex_colors->proc~make_polyhedron proc~set_vertices Polyhedron%set_vertices proc~set_vertices->proc~make_polyhedron

Source Code

    subroutine make_polyhedron(self)
        class(Polyhedron), intent(inout) :: self
        type(c_ptr) :: group
        real(wp) :: rgba(4), sphere(4)
        real(wp), allocatable :: v(:,:), normals(:,:), colors(:,:), segments(:,:)
        integer, allocatable :: idx(:,:)
        integer :: i, k, m
        if (.not. c_associated(self%nodes%contents)) return
        group = vkf_switch_create()
        if (iand(self%mode, POLY_FACES) /= 0 .and. size(self%tri, 2) > 0) then
            rgba = self%face_color_
            if (allocated(self%vertex_colors_)) rgba = [1.0_wp, 1.0_wp, 1.0_wp, 1.0_wp]
            rgba(4) = rgba(4) * self%opacity_
            call vertices_sphere(self%v, sphere(1:3), sphere(4))
            if (.not. self%lit_) then
                if (allocated(self%vertex_colors_)) then
                    call add(group, surface_node(self%v, self%tri, rgba, colors=self%vertex_colors_))
                else
                    call add(group, surface_node(self%v, self%tri, rgba))
                end if
            else if (self%smooth_) then                          ! shared vertices, normals averaged
                normals = vertex_normals(self%v, self%tri)
                if (allocated(self%vertex_colors_)) then
                    call add(group, surface_node(self%v, self%tri, rgba, normals, self%vertex_colors_, self%two_sided_, &
                                                 sphere))
                else
                    call add(group, surface_node(self%v, self%tri, rgba, normals, two_sided=self%two_sided_, &
                                                 sphere=sphere))
                end if
            else                                                ! flat: each triangle its own vertices
                m = size(self%tri, 2)
                allocate(v(3, 3 * m), normals(3, 3 * m), idx(3, m))
                do k = 1, m
                    do i = 1, 3
                        v(:, 3 * (k - 1) + i) = self%v(:, self%tri(i, k))
                    end do
                    normals(:, 3 * k - 2) = unit_normal(v(:, 3 * k - 2), v(:, 3 * k - 1), v(:, 3 * k))
                    normals(:, 3 * k - 1) = normals(:, 3 * k - 2)
                    normals(:, 3 * k) = normals(:, 3 * k - 2)
                    idx(:, k) = [3 * k - 2, 3 * k - 1, 3 * k]
                end do
                if (allocated(self%vertex_colors_)) then
                    allocate(colors(4, 3 * m))
                    do k = 1, m
                        do i = 1, 3
                            colors(:, 3 * (k - 1) + i) = self%vertex_colors_(:, self%tri(i, k))
                        end do
                    end do
                    call add(group, surface_node(v, idx, rgba, normals, colors, self%two_sided_, sphere))
                else
                    call add(group, surface_node(v, idx, rgba, normals, two_sided=self%two_sided_, sphere=sphere))
                end if
            end if
        end if
        if (iand(self%mode, POLY_EDGES) /= 0 .and. size(self%edge, 2) > 0) then
            allocate(segments(3, 2 * size(self%edge, 2)))
            do k = 1, size(self%edge, 2)
                segments(:, 2 * k - 1) = self%v(:, self%edge(1, k))
                segments(:, 2 * k) = self%v(:, self%edge(2, k))
            end do
            call add(group, line_node(segments, self%line_color_, self%width_, .true.))
        end if
        if (iand(self%mode, POLY_VERTICES) /= 0 .and. size(self%v, 2) > 0) &
            call add(group, marker_node(self%v, self%point_color_, self%point_size_, MARKER_DISK, 0.0_wp, c_null_ptr))
        call self%nodes%replace(group)
    end subroutine make_polyhedron