Skip to content

Commit

Permalink
formatting and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed82008 committed Sep 24, 2023
1 parent d360b9f commit 0227771
Show file tree
Hide file tree
Showing 22 changed files with 1,734 additions and 1,042 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "blue"
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.1.1"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"
Expand Down
60 changes: 36 additions & 24 deletions src/GLMesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ function (scheme::ColouredScheme)(v)
0.0 <= v <= 1.0 || println("Warning: color value must be scaled between 0 and 1.")
if 0.0 <= v < 0.25
b = 1.0
g = v/0.25
g = v / 0.25
r = 0.0
elseif 0.25 <= v < 0.5
b = 1.0 - (v - 0.25)/0.25
b = 1.0 - (v - 0.25) / 0.25
g = 1.0
r = 0.0
elseif 0.5 <= v < 0.75
b = 0.0
g = 1.0
r = (v - 0.5)/0.25
r = (v - 0.5) / 0.25
else
b = 0.0
g = 1.0 - (v - 0.75)/0.25
g = 1.0 - (v - 0.75) / 0.25
r = 1.0
end
return r, g, b, scheme.opacity
Expand All @@ -29,7 +29,14 @@ function (::BlackScheme)(v)
return 0.7, 0.7, 0.7, v
end

function get_jl_mapped_colors(dataset::T, color_variable_name, component, opacity, color_scheme = BlackScheme(), scale = true) where {T<:AbstractVTKSimpleData}
function get_jl_mapped_colors(
dataset::T,
color_variable_name,
component,
opacity,
color_scheme=BlackScheme(),
scale=true,
) where {T<:AbstractVTKSimpleData}
if color_variable_name in keys(dataset.point_data)
point_color = true
_size = num_of_points(dataset)
Expand All @@ -54,70 +61,75 @@ function get_jl_mapped_colors(dataset::T, color_variable_name, component, opacit
else
color_variable = _color_variable
end

if color_variable !== nothing
if component == -1 || component == 1 && _var_dim == 1
if _var_dim == 1
_values = color_variable
cmin = minimum(_values)
cmax = maximum(_values)
else
@views _values = [norm(color_variable[:,i]) for i in 1:_size]
@views _values = [norm(color_variable[:, i]) for i in 1:_size]
cmin = minimum(_values)
cmax = maximum(_values)
end
else
if 1 <= component <= _var_dim
@views _values = color_variable[component,:]
@views _values = color_variable[component, :]
cmin = minimum(_values)
cmax = maximum(_values)
else
throw("Cannot use component $component of a $color. $color only has $_var_dim components.")
throw(
"Cannot use component $component of a $color. $color only has $_var_dim components.",
)
end
end
else
cmin = cmax = 1.0
_values = ones(_size)
end
jl_mapped_colors = Vector{RGBA{Float32}}(undef, _size)
if !(isapprox(cmax, cmin, atol = eps(Float32)))
if !(isapprox(cmax, cmin; atol=eps(Float32)))
scaled_values = (_values .- cmin) ./ (cmax - cmin)
else
scaled_values = (similar(_values) .= clamp(cmin, 0, 1))
end
function fill_jl_mapped_colors(i)
jl_mapped_colors[i] = RGBA{Float32}((color_scheme(scaled_values[i]))...)
return jl_mapped_colors[i] = RGBA{Float32}((color_scheme(scaled_values[i]))...)
end
map(fill_jl_mapped_colors, 1:_size)
return jl_mapped_colors, cmin, cmax
end

function GLMesh(rectilinear::AbstractVTKStructuredData; kwargs...)
GLMesh(VTKUnstructuredData(rectilinear); kwargs...)
return GLMesh(VTKUnstructuredData(rectilinear); kwargs...)
end
function GLMesh(dataset::AbstractVTKUnstructuredData; color::String="", component::Int=-1, opacity::Float64=1.0, color_scheme = BlackScheme())
function GLMesh(
dataset::AbstractVTKUnstructuredData;
color::String="",
component::Int=-1,
opacity::Float64=1.0,
color_scheme=BlackScheme(),
)
filter_cells!(dataset, [POINT_CELLS; LINE_CELLS])
tri_cell_data = color in keys(dataset.cell_data)
tri_dataset = triangulate(dataset, tri_cell_data, GLTriangle)
tri_dataset = tri_dataset |> remove_unused_vertices |> duplicate_vertices
tri_dataset = duplicate_vertices(remove_unused_vertices(tri_dataset))
if haskey(tri_dataset.cell_data, color)
celldata_to_pointdata!(tri_dataset)
end
color_vec, cmin, cmax = get_jl_mapped_colors( tri_dataset,
color,
component,
opacity,
color_scheme
)
color_vec, cmin, cmax = get_jl_mapped_colors(
tri_dataset, color, component, opacity, color_scheme
)
T = eltype(dataset.point_coords)
vertices = map(1:num_of_points(tri_dataset)) do i
@views coord = tri_dataset.point_coords[:,i]
@views coord = tri_dataset.point_coords[:, i]
if length(coord) == 2
Point{3, T}(coord..., zero(T))
Point{3,T}(coord..., zero(T))
else
Point{3, T}(coord...)
Point{3,T}(coord...)
end
end
faces = tri_dataset.cell_connectivity
return GLNormalVertexcolorMesh(vertices=vertices, faces=faces, color=color_vec)
return GLNormalVertexcolorMesh(; vertices=vertices, faces=faces, color=color_vec)
end
123 changes: 62 additions & 61 deletions src/VTKDataTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,65 +19,66 @@ include("triangulate.jl")
include("GLMesh.jl")
#include("surface.jl")

export AbstractVTKData,
AbstractStaticVTKData,
AbstractTimeSeriesVTKData,
AbstractVTKMultiblockData,
AbstractVTKSimpleData,
AbstractVTKUnstructuredData,
AbstractVTKStructuredData,
AbstractVTKRectilinearData,
VTKUnstructuredData,
VTKPolyData,
VTKStructuredData,
VTKRectilinearData,
VTKUniformRectilinearData,
VTKImageData,
VTKMultiblockData,
VTKTimeSeriesData,
VTK_CELL_TYPE,
endof,
same_geometry,
same_ordered_geometry,
same_geometry_shape,
same_data_shape,
coherent, extents,
cell_extents,
dim,
num_of_points,
num_of_cells,
num_of_point_vars,
num_of_cell_vars,
cell_type,
cell_connectivity,
has_var,
var_dim,
is_homogeneous,
filter_cells!,
keep_volume_cells_only!,
keep_face_cells_only!,
get_cell_ids,
get_lowest_index,
get_highest_index,
is_valid_cell,
add_new_cell!,
remove_cell!,
add_point_id_offset!,
append,
num_of_blocks,
insert_new_block!,
remove_block!,
timespan,
num_of_timesteps,
insert_timed_data!,
remove_timed_data!,
is_valid,
simple_block_generator,
increase_resolution!,
triangular,
triangulate,
decompose,
GLMesh,
bb,
pseudo_center
export AbstractVTKData,
AbstractStaticVTKData,
AbstractTimeSeriesVTKData,
AbstractVTKMultiblockData,
AbstractVTKSimpleData,
AbstractVTKUnstructuredData,
AbstractVTKStructuredData,
AbstractVTKRectilinearData,
VTKUnstructuredData,
VTKPolyData,
VTKStructuredData,
VTKRectilinearData,
VTKUniformRectilinearData,
VTKImageData,
VTKMultiblockData,
VTKTimeSeriesData,
VTK_CELL_TYPE,
endof,
same_geometry,
same_ordered_geometry,
same_geometry_shape,
same_data_shape,
coherent,
extents,
cell_extents,
dim,
num_of_points,
num_of_cells,
num_of_point_vars,
num_of_cell_vars,
cell_type,
cell_connectivity,
has_var,
var_dim,
is_homogeneous,
filter_cells!,
keep_volume_cells_only!,
keep_face_cells_only!,
get_cell_ids,
get_lowest_index,
get_highest_index,
is_valid_cell,
add_new_cell!,
remove_cell!,
add_point_id_offset!,
append,
num_of_blocks,
insert_new_block!,
remove_block!,
timespan,
num_of_timesteps,
insert_timed_data!,
remove_timed_data!,
is_valid,
simple_block_generator,
increase_resolution!,
triangular,
triangulate,
decompose,
GLMesh,
bb,
pseudo_center
end
Loading

0 comments on commit 0227771

Please sign in to comment.