Skip to content

Commit

Permalink
Port from previous VPL
Browse files Browse the repository at this point in the history
  • Loading branch information
AleMorales committed Jul 3, 2023
1 parent 4d580e2 commit 1ab1b19
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 20 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI
on:
push:
branches:
- master
tags: '*'
pull_request:
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
version:
- '1'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v1
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- run: julia --project -e 'using Pkg; Pkg.add(url="https://github.com/VirtualPlantLab/VPLGeom.jl")'
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
files: lcov.info
1 change: 1 addition & 0 deletions JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "sciml"
25 changes: 24 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,28 @@ uuid = "358bd95d-d12c-439f-94b7-04b17e500c7f"
authors = ["Alejandro Morales Sierra <[email protected]> and contributors"]
version = "0.0.1"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Unrolled = "9602ed7d-8fef-5bc8-8597-8f21381861e8"
VPLGeom = "7eef3cc5-4580-4ff0-8f6f-933507db6664"

[compat]
julia = "1.9"
ColorTypes = "0.11.4"
FileIO = "1.16.1"
GeometryBasics = "0.4.7"
Makie = "0.19.6"
Unrolled = "0.1.5"
VPLGeom = "0.0.1"
julia = "1.9"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Aqua", "GLMakie"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# VPLViz

[![Build Status](https://travis-ci.com/VirtualPlantLab/VPLViz.jl.svg?branch=master)](https://travis-ci.com/VirtualPlantLab/VPLViz.jl)
[![CI](https://github.com/VirtualPlantLab/VPLViz.jl/actions/workflows/main.yml/badge.svg)](https://github.com/VirtualPlantLab/VPLViz.jl/actions/workflows/main.yml)
[![Coverage](https://codecov.io/gh/VirtualPlantLab/VPLViz.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/VirtualPlantLab/VPLViz.jl)
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)

This package is a component of the VPL ecosystem.
This package is a component of the VPL ecosystem.
22 changes: 10 additions & 12 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using VPLViz
using Documenter

DocMeta.setdocmeta!(VPLViz, :DocTestSetup, :(using VPLViz); recursive=true)
DocMeta.setdocmeta!(VPLViz, :DocTestSetup, :(using VPLViz); recursive = true)

makedocs(;
modules=[VPLViz],
authors="Alejandro Morales Sierra <[email protected]> and contributors",
repo="https://github.com/AleMorales/VPLViz.jl/blob/{commit}{path}#{line}",
sitename="VPLViz.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
edit_link="master",
assets=String[],
modules = [VPLViz],
authors = "Alejandro Morales Sierra <[email protected]> and contributors",
repo = "https://github.com/AleMorales/VPLViz.jl/blob/{commit}{path}#{line}",
sitename = "VPLViz.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
edit_link = "master",
assets = String[],
),
pages=[
"Home" => "index.md",
],
pages = ["Home" => "index.md"],
)
34 changes: 34 additions & 0 deletions src/Makie.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


# Optionally add wireframe and/or arrows representing normal vectors (for debugging)
function scene_additions!(m, normals, wireframe)
@inbounds FT = eltype(m[1][1])
if wireframe
Makie.wireframe!(m, linewidth = FT(1.5))
end
if normals
pos = calc_arrows(m)
Makie.linesegments!(pos, color = :black, linewidth = FT(1.5))
end
return nothing
end

# Auxilliary functions to create arrows to depict Normals
function calc_arrows(m)
nt = length(GeometryBasics.faces(m))
[calc_arrow(i, m) for i = 1:nt]
end

@inbounds function calc_arrow(i, m)
face = GeometryBasics.faces(m)[i]
v1, v2, v3 = GeometryBasics.coordinates(m)[face]
center = (v1 .+ v2 .+ v3) ./ 3
norm = normal(v1, v2, v3)
center => center .+ norm ./ 2
end

function normal(v1, v2, v3)
e1 = v2 .- v1
e2 = v3 .- v1
normalize(e2 × e1)
end
100 changes: 100 additions & 0 deletions src/Render.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

##################
##### Meshes #####
##################

"""
render(m::Mesh; kwargs...)
Render a mesh. This will create a new visualization (see Documentation for
details). Keyword arguments are passed to the `render(scene::VPLGeom.Scene)` method
and any unmatched keywords will be passed along to `Makie.mesh()`.
"""
function render(m::VPLGeom.Mesh; kwargs...)
render(VPLGeom.GLMesh(m); kwargs...)
end

"""
render!(m::Mesh; kwargs...)
Add a mesh to the visualization currently active. This will create a new
visualization (see Documentation for details). Keyword arguments are passed to
the `render!(scene::VPLGeom.Scene)` method and any unmatched keywords will be passed
along to `Makie.mesh!()`.
"""
function render!(m::VPLGeom.Mesh; kwargs...)
render!(VPLGeom.GLMesh(m); kwargs...)
end

# Basic rendering of a triangular mesh that is already in the right format
function render(
m::GeometryBasics.Mesh;
color = :green,
normals::Bool = false,
wireframe::Bool = false,
axes::Bool = true,
resolution = (1920, 1080),
kwargs...,
)
fig = Makie.Figure(resolution = resolution)
lscene = Makie.LScene(fig[1, 1], show_axis = axes)
Makie.mesh!(lscene, m, color = color, near = 0; kwargs...)
scene_additions!(m, normals, wireframe)
fig
end
function render!(
m::GeometryBasics.Mesh;
color = :green,
normals::Bool = false,
wireframe::Bool = false,
kwargs...,
)
Makie.mesh!(m, color = color, near = 0; kwargs...)
scene_additions!(m, normals, wireframe)
end



##################
##### Scenes #####
##################

"""
render(scene::Scene; normals::Bool = false, wireframe::Bool = false, kwargs...)
Render a `Scene` object. This will create a new visualization (see
Documentation for details). `normals = true` will draw arrows in the direction
of the normal vector for each triangle in the mesh, `wireframe = true` will draw
the edges of each triangle with black lines. Keyword arguments are passed to
`Makie.mesh()`.
"""
function render(
scene::VPLGeom.Scene;
normals::Bool = false,
wireframe::Bool = false,
kwargs...,
)
render(
VPLGeom.mesh(scene);
color = VPLGeom.colors(scene),
normals = normals,
wireframe = wireframe,
kwargs...,
)
end

#######################
##### Save output #####
#######################

"""
export_scene(;scene, filename, kwargs...)
Export a screenshot of the current visualization (stored as `scene` as output of
a call to `render`) as a PNG file store in the path given by `filename`
(including `.png` extension). Keyword arguments will be passed along to the
corresponding `save` method from Makie (see VPL documentation for details).
"""
function export_scene(; scene, filename, kwargs...)
FileIO.save(filename, scene; kwargs...)
end
14 changes: 13 additions & 1 deletion src/VPLViz.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
module VPLViz

# Write your package code here.
import Makie
import GeometryBasics
import LinearAlgebra: normalize, ×
import ColorTypes: Colorant, RGB, RGBA
import FileIO
import Unrolled: @unroll
import VPLGeom

export render, render!, export_scene

include("Render.jl")
include("Makie.jl")


end
3 changes: 0 additions & 3 deletions test/Project.toml

This file was deleted.

14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
using VPLViz
using Test
import Aqua

@testset "VPLViz.jl" begin
# Write your tests here.

# Aqua
@testset "Aqua" begin
Aqua.test_all(VPLViz, ambiguities = false)
Aqua.test_ambiguities([VPLViz])
end

# Rendering meshes of primitives
@testset "primitives" begin
include("test_primitives.jl")
end

end
87 changes: 87 additions & 0 deletions test/test_primitives.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using VPLViz
using VPLGeom
import GLMakie # import native backend for rendering -> NOT "using"!
GLMakie.activate!(inline=false)

#let

# Triangle
t = Triangle(length = 2.0, width = 2.0)
render(t, wireframe = true, normals = true)
t = Triangle(length = 2.0f0, width = 2.0f0)
render(t, wireframe = true, normals = true)


# Rectangle
r = Rectangle(length = 2.0, width = 1.0);
render(r, wireframe = true, normals = true)
r = Rectangle(length = 2.0f0, width = 1.0f0);
render(r, wireframe = true, normals = true)

# Trapezoid
t = Trapezoid(length = 2.0, width = 1.0, ratio = 0.5);
render(t, wireframe = true, normals = true)
t = Trapezoid(length = 2.0f0, width = 1.0f0, ratio = 0.5f0);
render(t, wireframe = true, normals = true)

# Ellipse
e = Ellipse(length = 2.0, width = 2.0, n = 20);
render(e, wireframe = true, normals = true)
e = Ellipse(length = 2.0f0, width = 2.0f0, n = 20);
render(e, wireframe = true, normals = true)

# BBox
b = BBox(Vec(0.0, 0.0, 0.0), Vec(1.0, 1.0, 1.0));
render(b, wireframe = true, normals = true)
b = BBox(Vec(0.0f0, 0.0f0, 0.0f0), Vec(1.0f0, 1.0f0, 1.0f0));
render(b, wireframe = true, normals = true)

# Solid cone
c = SolidCone(length = 2.0, width = 1.0, height = 1.0, n = 40);
render(c, wireframe = true, normals = true)
c = SolidCone(length = 2.0f0, width = 1.0f0, height = 1.0f0, n = 40);
render(c, wireframe = true, normals = true)

# Solid cube
c = SolidCube(length = 1.0, width = 1.0, height = 1.0);
render(c, wireframe = true, normals = true)
c = SolidCube(length = 1.0f0, width = 1.0f0, height = 1.0f0);
render(c, wireframe = true, normals = true)

# Solid cylinder
c = SolidCylinder(length = 2.0, width = 1.0, height = 1.0, n = 80);
render(c, wireframe = true, normals = true)
c = SolidCylinder(length = 2.0f0, width = 1.0f0, height = 1.0f0, n = 80);
render(c, wireframe = true, normals = true)

# Solid frustum
f = SolidFrustum(length = 2.0, width = 1.0, height = 1.0, ratio = 0.5, n = 80);
render(f, wireframe = true, normals = true)
f = SolidFrustum(length = 2.0f00, width = 1.0f00, height = 1.0f00, ratio = 0.5f0, n = 80);
render(f, wireframe = true, normals = true)

# Hollow cone
c = HollowCone(length = 2.0, width = 1.0, height = 1.0, n = 20);
render(c, wireframe = true, normals = true)
c = HollowCone(length = 2.0f0, width = 1.0f0, height = 1.0f0, n = 20);
render(c, wireframe = true, normals = true)

# Hollow cube
c = HollowCube(length = 1.0, width = 1.0, height = 1.0);
render(c, wireframe = true, normals = true)
c = HollowCube(length = 1.0f0, width = 1.0f0, height = 1.0f0);
render(c, wireframe = true, normals = true)

# Hollow cylinder
c = HollowCylinder(length = 2.0, width = 1.0, height = 1.0, n = 40);
render(c, wireframe = true, normals = true)
c = HollowCylinder(length = 2.0f0, width = 1.0f0, height = 1.0f0, n = 40);
render(c, wireframe = true, normals = true)

# Hollow frustum
f = HollowFrustum(length = 2.0, width = 1.0, height = 1.0, ratio = 0.5, n = 40);
render(f, wireframe = true, normals = true)
f = HollowFrustum(length = 2.0f0, width = 1.0f0, height = 1.0f0, ratio = 0.5f0, n = 40);
render(f, wireframe = true, normals = true)

#end

0 comments on commit 1ab1b19

Please sign in to comment.