From a053e875050c113d6a6bb286ed419d03c1ccac1f Mon Sep 17 00:00:00 2001 From: mattderstine Date: Sun, 5 Dec 2021 20:08:22 -0800 Subject: [PATCH 1/5] barely working prototype code --- src/Examples/managed figure tests-examples.jl | 351 ++++++++++++++++++ src/Vis/ManagedFigures.jl | 196 ++++++++++ src/Vis/Vis.jl | 2 + src/Vis/Visualization.jl | 177 ++++++--- 4 files changed, 680 insertions(+), 46 deletions(-) create mode 100644 src/Examples/managed figure tests-examples.jl create mode 100644 src/Vis/ManagedFigures.jl diff --git a/src/Examples/managed figure tests-examples.jl b/src/Examples/managed figure tests-examples.jl new file mode 100644 index 000000000..f489e62a3 --- /dev/null +++ b/src/Examples/managed figure tests-examples.jl @@ -0,0 +1,351 @@ + +using OpticSim +using OpticSim.GlassCat +using OpticSim.Geometry +using OpticSim.Vis +using OpticSim.Emitters +using OpticSim.Examples +using GLMakie + +using DataFrames +using LinearAlgebra + +using StaticArrays +using FileIO + +## +Vis.activateFigureView(true) + +lens = SphericalLens(OpticSim.GlassCat.SCHOTT.N_BK7, 0.0, 10.0, 10.0, 5.0, 5.0) +Vis.draw(lens) +## +topsurf = Plane( + SVector(0.0, 0.0, 1.0), + SVector(0.0, 0.0, 0.0), + interface = FresnelInterface{Float64}(SCHOTT.N_BK7, Air), + vishalfsizeu = 12.00075, + vishalfsizev = 12.00075) +botsurf = AcceleratedParametricSurface(ZernikeSurface( + 12.00075, + radius = -1.14659768e+4, + aspherics = [(4, 3.68090959e-7), (6, 2.73643352e-11), (7, 1.0e-18), (8, 3.20036892e-14)]), + 17, + interface = FresnelInterface{Float64}(SCHOTT.N_BK7, Air)) +coverlens = Cylinder(12.00075, 1.4) ∩ topsurf ∩ leaf(botsurf, Transform(rotmatd(0, 180, 0), Makie.Vec3(0.0, 0.0, -0.65))) +Vis.draw(coverlens) + + # big mirror with a hole in it + frontsurfacereflectance = 1.0 + bigmirror = ( + ConicLens(SCHOTT.N_BK7, -72.65, -95.2773500000134, 0.077235, Inf, 0.0, 0.2, 12.18263; frontsurfacereflectance) - + leaf(Cylinder(4.0, 0.3, interface = opaqueinterface()), Geometry.translation(0.0, 0.0, -72.75)) + ) +Vis.draw!(bigmirror) +## + +g1, g2 = SCHOTT.N_SK16, GlassCat.SCHOTT.N_SF2 +Vis.draw(AxisymmetricOpticalSystem{Float64}(DataFrame( + SurfaceType = ["Object", "Standard", "Standard", "Standard", "Stop", "Standard", "Standard", "Image"], + Radius = [Inf, 26.777, 66.604, -35.571, 35.571, 35.571, -26.777, Inf ], + Thickness = [Inf, 4.0, 2.0, 4.0, 2.0, 4.0, 44.748, missing], + Material = [Air, g1, Air, g2, Air, g1, Air, missing], + SemiDiameter = [Inf, 8.580, 7.513, 7.054, 6.033, 7.003, 7.506, 15.0 ], + ))) + +## + +function draw_cooketriplet(filename::Union{Nothing,AbstractString} = nothing) + g1, g2 = SCHOTT.N_SK16, GlassCat.SCHOTT.N_SF2 + sys = AxisymmetricOpticalSystem{Float64}(DataFrame( + SurfaceType = ["Object", "Standard", "Standard", "Standard", "Stop", "Standard", "Standard", "Image"], + Radius = [Inf, 26.777, 66.604, -35.571, 35.571, 35.571, -26.777, Inf ], + Thickness = [Inf, 4.0, 2.0, 4.0, 2.0, 4.0, 44.748, missing], + Material = [Air, g1, Air, g2, Air, g1, Air, missing], + SemiDiameter = [Inf, 8.580, 7.513, 7.054, 6.033, 7.003, 7.506, 15.0 ], + )) + + origins = Origins.Hexapolar(8, 15.0, 15.0) + directions = Directions.Constant(0.0, 0.0, -1.0) + s1 = Sources.Source(; origins, directions, sourcenum=1) + + transform = Transform(rotmatd(10, 0, 0), unitZ3()) + s2 = Sources.Source(; transform, origins, directions, sourcenum=2) + + raygenerator = Sources.CompositeSource(Transform(), [s1, s2]) + + trackallrays = test = colorbysourcenum = true; resolution = (1000, 700) + Vis.drawtracerays(sys; raygenerator, trackallrays, test, colorbysourcenum, resolution) + return sys +end + +sys = draw_cooketriplet() + +sys + +## + +function draw_zoomlenses(filenames::Vector{<:Union{Nothing,AbstractString}} = repeat([nothing], 3)) + stops = [2.89, 3.99, 4.90] + zooms = [9.48, 4.48, 2.00] + dists = [4.46970613, 21.21, 43.81] + + transform = Geometry.translation(0.0, 0.0, 10.0) + origins = Origins.Hexapolar(8, 10.0, 10.0) + directions = Directions.Constant(0.0, 0.0, -1.0) + raygenerator = Sources.Source(; transform, origins, directions) + + aspherics = [ + ["4" => 1.0386E-04, "6" => 1.4209E-07, "8" => -8.8495E-09, "10" => 1.2477E-10, "12" => -1.0367E-12, "14" => 3.6556E-15], + ["4" => 4.2721E-05, "6" => 1.2484E-07, "8" => 9.7079E-09, "10" => -1.8444E-10, "12" => 1.8644E-12, "14" => -7.7975E-15], + ["4" => 1.1339E-04, "6" => 4.8165E-07, "8" => 1.8778E-08, "10" => -5.7571E-10, "12" => 8.9994E-12, "14" => -4.6768E-14], + ] + syss = [ + AxisymmetricOpticalSystem{Float64}(DataFrame( + SurfaceType = ["Object", "Stop", "Standard", "Standard", "Standard", "Aspheric", "Standard", "Standard", "Aspheric", "Aspheric", "Standard", "Standard", "Standard", "Standard", "Standard", "Standard", "Image"], + Radius = [Inf64, Inf64, -1.6202203499676E+01, -4.8875855327468E+01, 1.5666614444619E+01, -4.2955326460481E+01, 1.0869565217391E+02, 2.3623907394283E+01, -1.6059097478722E+01, -4.2553191489362E+02, -3.5435861091425E+01, -1.4146272457208E+01, -2.5125628140704E+02, -2.2502250225023E+01, -1.0583130489999E+01, -4.4444444444444E+01, Inf64], + Parameters = [missing, missing, missing, missing, missing, aspherics[1], missing, missing, aspherics[2], aspherics[3], missing, missing, missing, missing, missing, missing, missing], + Thickness = [Inf64, 0.0, 5.18, 0.10, 4.40, 0.16, 1.0, 4.96, zoom, 4.04, 1.35, 1.0, 2.80, 3.0, 1.22, dist, missing], + Material = [Air, Air, OHARA.S_LAH66, Air, NIKON.LLF6, Air, OHARA.S_TIH6, OHARA.S_FSL5, Air, OHARA.S_FSL5, Air, OHARA.S_LAL8, OHARA.S_FSL5, Air, OHARA.S_LAH66, Air, missing], + SemiDiameter = [Inf64, stop, 3.85433218451, 3.85433218451, 4.36304692871, 4.36304692871, 4.72505505439, 4.72505505439, 4.72505505439, 4.45240784026, 4.45240784026, 4.50974054117, 4.50974054117, 4.50974054117, 4.76271114409, 4.76271114409, 15.0])) + for (stop, zoom, dist) in zip(stops, zooms, dists)] + + for (sys, filename) in zip(syss, filenames) + fV = FigureView(figureName = filename) + Vis.drawtracerays!(sys; raygenerator, trackallrays=true, test=true, numdivisions=50) + end + return syss +end + +draw_zoomlenses() + +## + +function draw_schmidtcassegraintelescope(filename::Union{Nothing,AbstractString} = nothing) + # glass entrance lens on telescope + topsurf = Plane( + SVector(0.0, 0.0, 1.0), + SVector(0.0, 0.0, 0.0), + interface = FresnelInterface{Float64}(SCHOTT.N_BK7, Air), + vishalfsizeu = 12.00075, + vishalfsizev = 12.00075) + botsurf = AcceleratedParametricSurface(ZernikeSurface( + 12.00075, + radius = -1.14659768e+4, + aspherics = [(4, 3.68090959e-7), (6, 2.73643352e-11), (7, 1.0e-18), (8, 3.20036892e-14)]), + 17, + interface = FresnelInterface{Float64}(SCHOTT.N_BK7, Air)) + coverlens = Cylinder(12.00075, 1.4) ∩ topsurf ∩ leaf(botsurf, Transform(rotmatd(0, 180, 0), Vec3(0.0, 0.0, -0.65))) + + # big mirror with a hole in it + frontsurfacereflectance = 1.0 + bigmirror = ( + ConicLens(SCHOTT.N_BK7, -72.65, -95.2773500000134, 0.077235, Inf, 0.0, 0.2, 12.18263; frontsurfacereflectance) - + leaf(Cylinder(4.0, 0.3, interface = opaqueinterface()), translation(0.0, 0.0, -72.75)) + ) + + # small mirror supported on a spider + backsurfacereflectance = 1.0 + smallmirror = SphericalLens(SCHOTT.N_BK7, -40.65, Inf, -49.6845, 1.13365, 4.3223859; backsurfacereflectance) + + obscuration1 = Circle(4.5, SVector(0.0, 0.0, 1.0), SVector(0.0, 0.0, -40.649), interface = opaqueinterface()) + obscurations2 = Spider(3, 0.5, 12.0, SVector(0.0, 0.0, -40.65)) + + # put it together with the detector + la = LensAssembly(coverlens(), bigmirror(), smallmirror(), obscuration1, obscurations2...) + det = Circle(3.0, SVector(0.0, 0.0, 1.0), SVector(0.0, 0.0, -92.4542988), interface = opaqueinterface()) + sys = CSGOpticalSystem(la, det) + + # define ray generator + transform = translation(0.0, 0.0, 10.0) + origins = Origins.Hexapolar(8, 20.0, 20.0) + directions = Directions.Constant(0.0, 0.0, -1.0) + raygenerator = Sources.Source(; transform, origins, directions) + + # draw and output + Vis.drawtracerays(sys; raygenerator, trackallrays = true, colorbynhits = true, test = true, numdivisions = 100, drawgen = false) + return nothing +end + +draw_schmidtcassegraintelescope() + +## + +function draw_stackedbeamsplitters(filenames::Vector{<:Union{Nothing,AbstractString}} = repeat([nothing], 3)) + # ReflectOrTransmit: nondeterministic + # Transmit: deterministic, all beamsplitters transmissive + # Reflect: deterministic, all beamsplitters reflective + interfacemodes = [ReflectOrTransmit, Transmit, Reflect] + + for (interfacemode, filename) in zip(interfacemodes, filenames) + interface = FresnelInterface{Float64}(SCHOTT.N_BK7, Air; reflectance=0.5, transmission=0.5, interfacemode) + bs_1 = OpticSim.transform( + Cuboid(10.0, 20.0, 2.0, interface=interface), + translation(0.0, 0.0, -30.0-2*sqrt(2))*rotationX(π/4)) + + l1 = OpticSim.transform( + SphericalLens(SCHOTT.N_BK7, -70.0, 30.0, Inf, 5.0, 10.0), + translation(0.0, -1.34, 0.0)) + + bs_2 = OpticSim.transform( + Cuboid(10.0, 20.0, 2.0, interface=interface), + translation(0.0, 40.0, -30.0+2*sqrt(2))*rotationX(π/4)) + + l2 = OpticSim.transform( + SphericalLens(SCHOTT.N_BK7, -70.0, 30.0, Inf, 5.0, 10.0), + translation(0.0, 40.0, 0.0)) + + la = LensAssembly(bs_1(), l1(), bs_2(), l2()) + + detector = Rectangle(20.0, 40.0, SVector(0.0, 0.0, 1.0), SVector(0.0, 20.0, -130.0); interface = opaqueinterface()) + sys = CSGOpticalSystem(la, detector) + + Vis.drawtracerays(sys; trackallrays=true, rayfilter=nothing, colorbynhits=true) + end + return nothing +end + +draw_stackedbeamsplitters() + + +## + +book = [ + -.240408 0.0 0.0; + 0 .130825 .501818; + 0 -.501818 -.710275 + ] + + + + + + # surface, radius, thickness, index + patent1 = [0 Inf -0.20 1 + 1 1.962 1.19 1.471 + 2 33.398 0.93 1 + 3 -2.182 0.75 1.603 + 4 -6.367 0.10 1 + 5 5.694 0.89 1.510 + 6 9.192 0.16 1 + 7 1.674 0.85 1.510 + 8 1.509 0.70 1 + 9 Inf 0.40 1.516 + 10 Inf 0.64 1] + + # after transpose A3, A4, A5, A6, A7, A8, A9, A10 + patent2 = transpose([ + -1.895E-02 -4.966E-03 -4.388E-02 -1.131E-01 -7.876E-02 9.694E-03 7.429E-02 1.767E-03 + 2.426E-02 -1.434E-02 -2.555E-02 -7.863E-02 7.020E-02 -2.516E-03 -6.933E-02 -4.652E-02 + -5.123E-02 -6.139E-03 5.160E-02 1.094E-01 1.575E-03 -3.606E-03 -5.811E-03 1.625E-02 + 8.371E-04 -9.284E-05 -4.307E-02 6.228E-03 -9.958E-03 -2.497E-04 2.396E-03 -3.522E-03 + 7.850E-03 6.438E-03 -2.831E-02 -2.916E-02 -7.322E-03 -6.840E-04 2.100E-03 -7.106E-04 + 4.091E-03 -5.720E-03 3.162E-02 -5.890E-03 6.914E-04 -1.414E-04 -3.119E-04 3.825E-04 + -7.732E-03 -2.385E-02 4.630E-02 4.123E-03 2.540E-03 2.932E-04 -5.552E-05 6.271E-05 + -4.265E-03 1.108E-02 -4.877E-02 1.041E-03 -7.650E-04 -7.284E-05 7.969E-06 -2.631E-05 + ]) +x,y = size(patent2) +aspherics = [[string(j+2)=>patent2[i,j] for j in 1:y] for i in 1:x] + + + K=Array([ 2.153E+00 4.018E+01 2.105E+00 3.382E+00 -2.211E+02 9.331E-01 -7.617E+00 -2.707E+00][:]) + + names =["stop", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "image"] + apers = [0.5 * 5.57/2.8, 1.2, 1.2, 1.2, 1.2, 2.1, 2.1, 2.5, 2.5, 2.7, 2.7, 3.] + + + +function draw_cellPhoneCameraLens(filenames::Vector{<:Union{Nothing,AbstractString}} = repeat([nothing], 3)) + + # surface, radius, thickness, index + patentTable1 = [ + -1 Inf64 Inf64 1 + 0 Inf64 -0.20 1 + 1 1.962 1.19 1.471 + 2 33.398 0.93 1 + 3 -2.182 0.75 1.603 + 4 -6.367 0.10 1 + 5 5.694 0.89 1.510 + 6 9.192 0.16 1 + 7 1.674 0.85 1.510 + 8 1.509 0.70 1 + 9 Inf 0.40 1.516 + 10 Inf 0.64 1 + 11 Inf missing 1] + + # after transpose A3, A4, A5, A6, A7, A8, A9, A10 + patentTable2 = transpose([ + -1.895E-02 -4.966E-03 -4.388E-02 -1.131E-01 -7.876E-02 9.694E-03 7.429E-02 1.767E-03 + 2.426E-02 -1.434E-02 -2.555E-02 -7.863E-02 7.020E-02 -2.516E-03 -6.933E-02 -4.652E-02 + -5.123E-02 -6.139E-03 5.160E-02 1.094E-01 1.575E-03 -3.606E-03 -5.811E-03 1.625E-02 + 8.371E-04 -9.284E-05 -4.307E-02 6.228E-03 -9.958E-03 -2.497E-04 2.396E-03 -3.522E-03 + 7.850E-03 6.438E-03 -2.831E-02 -2.916E-02 -7.322E-03 -6.840E-04 2.100E-03 -7.106E-04 + 4.091E-03 -5.720E-03 3.162E-02 -5.890E-03 6.914E-04 -1.414E-04 -3.119E-04 3.825E-04 + -7.732E-03 -2.385E-02 4.630E-02 4.123E-03 2.540E-03 2.932E-04 -5.552E-05 6.271E-05 + -4.265E-03 1.108E-02 -4.877E-02 1.041E-03 -7.650E-04 -7.284E-05 7.969E-06 -2.631E-05 + ]) + + + K=Array([ 2.153E+00 4.018E+01 2.105E+00 3.382E+00 -2.211E+02 9.331E-01 -7.617E+00 -2.707E+00][:]) + conicConstants = K .- 1.0 + names =["image", "stop", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "image"] + apers = [Inf, 0.5 * 5.57/2.8, 1.2, 1.2, 1.2, 1.2, 2.1, 2.1, 2.5, 2.5, 2.7, 2.7, 3.] + + + transform = translation(0.0, 0.0, 10.0) + origins = Origins.Hexapolar(8, 10.0, 10.0) + directions = Directions.Constant(0.0, 0.0, -1.0) + raygenerator = Sources.Source(; transform, origins, directions) + ix,jy = size(patent2) + aspherics = [[string(j+2)=>patentTable2[i, j] for j in 1:jy] for i in 1:ix] + materials = map(refIndex -> modelglass(refIndex, 1000.0, 0.0), patentTable1[:, 4]) + + sys = AxisymmetricOpticalSystem{Float64}(DataFrame( + SurfaceType = ["Object", "Stop", "Aspheric", "Aspheric","Aspheric","Aspheric","Aspheric","Aspheric","Aspheric","Aspheric","Standard", "Standard","Image"], + Radius = patentTable1[:,2], + Conic = [missing, missing, conicConstants..., missing, missing, missing], + Parameters = [missing, missing, aspherics..., missing, missing,missing], + Thickness = patentTable1[:,3], + Material = materials, + SemiDiameter = apers + )) + + visplane = Plane(SVector(1.0, 0., 0.), SVector(0.0, 0.0,0.0)) + Vis.draw(sys ;resolution=(1600, 1000)) + + #Vis.drawtracerays(sys; raygenerator, trackallrays=true, test=true, numdivisions=50, resolution=(1600, 1000)) + #Vis.make2dy() + #Vis.save(filename) + + return sys +end + +draw_cellPhoneCameraLens() + +## + +brain = load(assetpath("brain.stl")) + +b = Meshes.Mesh(brain) +Meshes.boundingbox(brain) + +m = mesh( + brain, + color = [tri[1][2] for tri in brain for i in 1:3], + colormap = Reverse(:magma) +) + + +r = Rect(0.0, 0.0, 0.0, 60.0, 60., 60.) + +c = Cuboid(100.0, 10.0, 100.0) + +r ∩ c + +m1 = mesh( + brain ∩ c, + color = [tri[1][2] for tri in brain for i in 1:3], + colormap = Reverse(:magma) +) + +display(m) + diff --git a/src/Vis/ManagedFigures.jl b/src/Vis/ManagedFigures.jl new file mode 100644 index 000000000..eabe5bc90 --- /dev/null +++ b/src/Vis/ManagedFigures.jl @@ -0,0 +1,196 @@ + + +const defaultResolution = (1200,900) + +## + +mutable struct FigureView + figure::Makie.Figure + name::AbstractString + saveFileStub::AbstractString + saveDir::AbstractString + buttons::Union{Nothing, Vector{Makie.Button}} #maybe: Union{Nothing, Vector{Button}} + statusGrid::Any #grid with status and buttons + buttonGrid::Any #buttons for figures + userGrid::Any #buttons for user of FigureView + utilGrid::Any #buttons for savescreen etc + workingGrid::Any #main area, as a grid + saveRegion::Any #region to save with SaveScreen + function FigureView(figure, name, saveFileStub, saveDir) + new(figure, name, saveFileStub, saveDir, nothing, nothing, nothing, nothing, nothing, nothing, nothing) + end +end + +global numActiveFig = 0 +global numNextFigPos = 1 +global logo = nothing +global figureViewList = [] +global currentFigure = nothing +global currentUserGrid = nothing +global activeFigureView = false + + +function FigureView(; figureName = string(numNextFigPos), fileNameStub = nothing, dir = nothing, activeButtonColor = Makie.RGBf0(0.8, 0.94, 0.8), resolution = defaultResolution) + global logo + global currentUserGrid + global numActiveFig + global currentFigure + global numNextFigPos + global activeFigureView + activeFigureView = true #direct drawing to managed figures + + if numActiveFig == 0 #first time through + logo = load("logo.png") + #Makie.set_window_config!(title = "OpticSim") + else + resolution = Makie.size(currentFigure.scene) + end + + filename = fileNameStub === nothing ? figureName : fileNameStub + dir = dir===nothing || !isdir(dir) ? pwd() : dir #if dir isn't valid use current directory. + + figc = Makie.Figure(resolution = resolution, backgroundcolor = Makie.RGBf0(0.98, 0.98, 0.98), ) + currentFigure = figc + curFigView = FigureView(figc, figureName, filename, dir) + push!(figureViewList, curFigView) + numActiveFig += 1 + numNextFigPos += 1 + + if numActiveFig > 0 #Add new buttons to exisiting figures + for figView in figureViewList[1:end-1] + button = figView.buttonGrid[numActiveFig, 1] = Makie.Button(figView.figure, label = figureName) + push!(figView.buttons, button) + Makie.on(button.clicks) do n + currentFigure = figc + Makie.display(figc) + end + end + end + # normally the items would be defined and then included in the constuctor. Some of the Makie objects have unexpected actions + # when being assigned, so assign directly onto the FigureView fields. + + figc[1,1] = curFigView.statusGrid = Makie.GridLayout(tellwidth = true, tellheight=false) + + curFigView.statusGrid[1, 1] = curFigView.buttonGrid = Makie.GridLayout(tellwidth = true, tellheight=false) + curFigView.statusGrid[2, 1] = curFigView.userGrid = Makie.GridLayout(tellwidth = true, tellheight=false) + currentUserGrid=curFigView.userGrid + curFigView.statusGrid[3, 1] = curFigView.utilGrid = Makie.GridLayout(tellwidth = true, tellheight=false) + + figc[1,2] = curFigView.workingGrid = Makie.GridLayout(tellwidth = true, tellheight=true) + curFigView.saveRegion = figc #workinggrid + + # there is a different "savebutton" on each Figure. inside this method, we define the new one. + savebutton = curFigView.utilGrid[1,1] = Makie.Button(figc, label = "Save Screen") + Makie.on(savebutton.clicks) do n + #println("$(button.label[]) was clicked $n times.") + saveFigure(dir, filename, figc) + end + + #display the logo + makieLogo, = Makie.image(curFigView.utilGrid[2,1], rotr90(logo), axis = (aspect = Makie.DataAspect(),title="OpticSim")) + Makie.hidedecorations!(makieLogo) #just the image + Makie.hidespines!(makieLogo) + + # put figure selection buttons on new Figure + + curFigView.buttons = curFigView.buttonGrid[1:numActiveFig, 1] = [Makie.Button(figc, label = figView.name) for figView in figureViewList] + curFigView.buttons[end].buttoncolor[] = activeButtonColor + + #link the new buttons to actions + for (button, fig) in zip(curFigView.buttons,figureViewList) + Makie.on(button.clicks) do n + currentFigure = fig.figure + display(currentFigure) + end + end + Makie.display(figc) + return curFigView +end + +Makie.display(a::FigureView) = Makie.display(a.figure) + +function clearFigureView() + global numActiveFig = 0 + global numNextFigPos = 1 + global logo = nothing + global figureViewList = [] + global currentFigure = nothing + global currentUserGrid = nothing +end + +function activateFigureView(stat = true) + global activeFigureView + activeFigureView = stat +end + + +global visPlaneX = Plane(SVector(1.0, 0., 0.), SVector(0.0, 0.0,0.0)) +global visPlaneY = Plane(SVector(0.0, 1.0, 0.0), SVector(0.0, 0.0, 0.0)) + +mutable struct DrawingInR + fV::FigureView + lscene1::Makie.LScene + lscene2::Makie.LScene + lscene3::Makie.LScene + oneButton::Makie.Button + twoButton::Makie.Button + oneswap::Bool + twoswap::Bool + xRegion + yRegion +end + +Makie.display(a::DrawingInR) = Makie.display(a.fV) + +global currentDrawingInR= nothing + +function DrawingInR(; name = "Draw-$numNextFigPos", xRegion = visPlaneX, yRegion = visPlaneY, fileNameStub = nothing, dir = nothing, resolution = defaultResolution) + global currentDrawingInR + fV = FigureView(;figureName = name, fileNameStub, dir, resolution) + lscene1 = Makie.LScene(fV.workingGrid[1,1], scenekw = (camera = Makie.cam3d_cad!, raw = false)) + lscene2 = Makie.LScene(fV.userGrid[1,1], scenekw = (camera = Makie.cam3d_cad!, raw = false)) + oneButton = Makie.Button(fV.userGrid[2,1], label = "Y") + lscene3 = Makie.LScene(fV.userGrid[3,1], scenekw = (camera = Makie.cam3d_cad!, raw = false)) + twoButton = Makie.Button(fV.userGrid[4,1], label = "X") + + dInR = DrawingInR(fV, lscene1, lscene2, lscene3, oneButton, twoButton, false, false, xRegion, yRegion) + + Makie.on(dInR.oneButton.clicks) do n + if dInR.oneswap + dInR.fV.workingGrid[1,1] = lscene1 + dInR.V.userGrid[1,1] = lscene2 + dInR.fV.userGrid[3,1] = lscene3 + dInR.oneswap = false + else + dInR.fV.workingGrid[1,1] = lscene2 + dInR.fV.userGrid[1,1] = lscene1 + dInR.fV.userGrid[3,1] = lscene3 + dInR.oneswap = true + end + dInR.twoswap = false + Makie.display(dInR) + end + + Makie.on(dInR.twoButton.clicks) do n + if dInR.twoswap + dInR.fV.workingGrid[1,1] = lscene1 + dInR.fV.userGrid[3,1] = lscene3 + dInR.fV.userGrid[1,1] = lscene2 + dInR.twoswap = false + else + dInR.fV.workingGrid[1,1] = lscene3 + dInR.fV.userGrid[3,1] = lscene1 + dInR.fV.userGrid[1,1] = lscene2 + dInR.twoswap = true + end + dInR.oneswap = false + Makie.display(dInR) + end + + currentDrawingInR = dInR + return dInR +end + + + + diff --git a/src/Vis/Vis.jl b/src/Vis/Vis.jl index f04e3038d..b41c0565b 100644 --- a/src/Vis/Vis.jl +++ b/src/Vis/Vis.jl @@ -18,11 +18,13 @@ using ColorSchemes using StaticArrays using LinearAlgebra import Makie +import GLMakie import GeometryBasics import Plots import Luxor using FileIO +include("ManagedFigures.jl") include("Visualization.jl") include("Emitters.jl") include("VisRepeatingStructures.jl") diff --git a/src/Vis/Visualization.jl b/src/Vis/Visualization.jl index a6af04d8f..819cf6b88 100644 --- a/src/Vis/Visualization.jl +++ b/src/Vis/Visualization.jl @@ -220,13 +220,20 @@ Draw an object in a new scene. `kwargs` depends on the object type. """ function draw(ob; resolution = (1000, 1000), kwargs...) - scene, lscene = Vis.scene(resolution) - draw!(lscene, ob; kwargs...) - display(scene) + if activeFigureView && !(get_current_mode() == :pluto || get_current_mode() == :docs) + dInR = DrawingInR() + draw!(dInR, ob; kwargs...) + display(dInR) + else + scene, lscene = Vis.scene(resolution) + draw!(lscene, ob; kwargs...) + display(scene) - if (get_current_mode() == :pluto || get_current_mode() == :docs) - return scene + if (get_current_mode() == :pluto || get_current_mode() == :docs) + return scene + end end + end """ @@ -236,17 +243,27 @@ Draw an object in an existing scene. `kwargs` depends on the object type. """ function draw!(ob; kwargs...) - if current_3d_scene === nothing - scene, lscene = Vis.scene() - else - scene = current_main_scene - lscene = current_3d_scene - end - draw!(lscene, ob; kwargs...) - display(scene) + if get_current_mode() == :pluto || get_current_mode() == :docs || !activeFigureView + if current_3d_scene === nothing + scene, lscene = Vis.scene() + else + scene = current_main_scene + lscene = current_3d_scene + end + draw!(lscene, ob; kwargs...) + display(scene) - if (get_current_mode() == :pluto || get_current_mode() == :docs) - return scene + if (get_current_mode() == :pluto || get_current_mode() == :docs) + return scene + end + else + if currentDrawingInR === nothing + dInR = DrawingInR() + else + dInR = currentDrawingInR + end + draw!(dInR, ob; kwargs...) + display(dInR) end end @@ -337,14 +354,14 @@ end ## GEOMETRY """ - draw!(scene::Makie.LScene, surf::Surface{T}; numdivisions = 20, normals = false, normalcolor = :blue, kwargs...) + draw!(scene, surf::Surface{T}; numdivisions = 20, normals = false, normalcolor = :blue, kwargs...) Transforms `surf` into a mesh using [`makemesh`](@ref) and draws the result. `normals` of the surface can be drawn at evenly sampled points with provided `normalcolor`. `numdivisions` determines the resolution with which the mesh is triangulated. `kwargs` is passed on to the [`TriangleMesh`](@ref) drawing function. """ -function draw!(scene::Makie.LScene, surf::Surface{T}; numdivisions::Int = 30, normals::Bool = false, normalcolor = :blue, kwargs...) where {T<:Real} +function draw!(scene::Union{Makie.LScene, DrawingInR} , surf::Surface{T}; numdivisions::Int = 30, normals::Bool = false, normalcolor = :blue, kwargs...) where {T<:Real} mesh = makemesh(surf, numdivisions) if nothing === mesh return @@ -357,6 +374,19 @@ function draw!(scene::Makie.LScene, surf::Surface{T}; numdivisions::Int = 30, no end end +function Makie.arrows!(dInR::DrawingInR, norigins, ndirs; arrowsize = 0.2, arrowcolor = normalcolor, linecolor = normalcolor, linewidth = 2) + Makie.arrows!(dInR.lscene1, norigins, ndirs, arrowsize = arrowsize, arrowcolor = arrowcolor, linecolor = linecolor, linewidth = linewidth) + for (origin, dir) in zip(norigins, ndirs) + if inside(visPlaneY, SVector{3, Float64}(origin)) + Makie.arrows!(dInR.lscene2, [origin], [dir], arrowsize = arrowsize, arrowcolor = arrowcolor, linecolor = linecolor, linewidth = linewidth) + elseif inside(visPlaneX, SVector{3, Float64}(origin)) + Makie.arrows!(dInR.lscene3, norigins, ndirs, arrowsize = arrowsize, arrowcolor = arrowcolor, linecolor = linecolor, linewidth = linewidth) + end + end +end + + + """ draw!(scene::Makie.LScene, tmesh::TriangleMesh{T}; linewidth = 3, shaded = true, wireframe = false, color = :orange, normals = false, normalcolor = :blue, transparency = false, kwargs...) @@ -385,13 +415,14 @@ function draw!(scene::Makie.LScene, tmesh::TriangleMesh{T}; linewidth = 3, shade end end + """ draw!(scene::Makie.LScene, meshes::Vararg{S}; colors::Bool = false, kwargs...) where {T<:Real,S<:Union{TriangleMesh{T},Surface{T}}} Draw a series of [`TriangleMesh`](@ref) or [`Surface`](@ref) objects, if `colors` is true then each mesh will be colored automatically with a diverse series of colors. `kwargs` are is passed on to the drawing function for each element. """ -function draw!(scene::Makie.LScene, meshes::Vararg{S}; colors::Bool = false, kwargs...) where {T<:Real,S<:Union{TriangleMesh{T},Surface{T}}} +function draw!(scene::Union{Makie.LScene, DrawingInR} , meshes::Vararg{S}; colors::Bool = false, kwargs...) where {T<:Real,S<:Union{TriangleMesh{T},Surface{T}}} for i in 1:length(meshes) if colors col = indexedcolor2(i) @@ -403,11 +434,17 @@ function draw!(scene::Makie.LScene, meshes::Vararg{S}; colors::Bool = false, kwa end function draw(meshes::Vararg{S}; kwargs...) where {T<:Real,S<:Union{TriangleMesh{T},Surface{T}}} - scene, lscene = Vis.scene() - draw!(lscene, meshes...; kwargs...) - Makie.display(scene) - if (get_current_mode() == :pluto || get_current_mode() == :docs) - return scene + if activeFigureView && !(get_current_mode() == :pluto || get_current_mode() == :docs) + dInR = DrawingInR() + draw!(dInR, meshes...; kwargs...) + display(dInR) + else + scene, lscene = Vis.scene(resolution) + draw!(lscene, meshes...; kwargs...) + Makie.display(scene) + if (get_current_mode() == :pluto || get_current_mode() == :docs) + return scene + end end end @@ -417,7 +454,18 @@ end Convert a CSG object ([`CSGTree`](@ref) or [`CSGGenerator`](@ref)) to a mesh using [`makemesh`](@ref) with resolution set by `numdivisions` and draw the resulting [`TriangleMesh`](@ref). """ draw!(scene::Makie.LScene, csg::CSGTree{T}; numdivisions::Int = 30, kwargs...) where {T<:Real} = draw!(scene, makemesh(csg, numdivisions); kwargs...) -draw!(scene::Makie.LScene, csg::CSGGenerator{T}; kwargs...) where {T<:Real} = draw!(scene, csg(); kwargs...) + +draw!(scene::Makie.LScene , csg::CSGGenerator{T}; kwargs...) where {T<:Real} = draw!(scene, csg(); kwargs...) + +# this method SHOULD take care of all LensAssembly entries before they become meshes where the interesection operators don't work. It does not. +# Apparently about in AxisymmetricOpticalSystem creates and stores the trees instead of CSGGenertor objects (???) +function draw!(dInR::DrawingInR, csg::CSGGenerator; kwargs...) where {T<:Real} + draw!(dInR.lscene1, csg(); kwargs...) + draw!(dInR.lscene2, (csg ∩ dInR.yRegion)(); kwargs...) + draw!(dInR.lscene3, (csg ∩ dInR.xRegion)(); kwargs...) + return dInR +end + """ draw!(scene::Makie.LScene, bbox::BoundingBox{T}; kwargs...) @@ -436,6 +484,14 @@ function draw!(scene::Makie.LScene, bbox::BoundingBox{T}; kwargs...) where {T<:R Makie.linesegments!(scene, [p1, p2, p2, p3, p3, p4, p4, p1, p1, p5, p2, p6, p3, p7, p4, p8, p5, p6, p6, p7, p7, p8, p8, p5]; kwargs...) end +function draw!(dInR::DrawingInR, bbox::BoundingBox{T}; kwargs...) where {T<:Real} + draw!(dInR.lscene1, bbox; kwargs...) + draw!(dInR.lscene2, bbox; kwargs...) #don't trim wireframe of bounding box + draw!(dInR.lscene3, bbox; kwargs...) + +end + + ## OPTICS """ @@ -443,7 +499,7 @@ end Draw each element in a [`LensAssembly`](@ref), with each element automatically colored differently. """ -function draw!(scene::Makie.LScene, ass::LensAssembly{T}; kwargs...) where {T<:Real} +function draw!(scene::Union{Makie.LScene, DrawingInR} , ass::LensAssembly{T}; kwargs...) where {T<:Real} for (i, e) in enumerate(elements(ass)) draw!(scene, e; kwargs..., color = indexedcolor2(i)) end @@ -454,12 +510,12 @@ end Draw each element in the lens assembly of an [`AbstractOpticalSystem`](@ref), with each element automatically colored differently, as well as the detector of the system. """ -function draw!(scene::Makie.LScene, sys::CSGOpticalSystem{T}; kwargs...) where {T<:Real} +function draw!(scene::Union{Makie.LScene, DrawingInR} , sys::CSGOpticalSystem{T}; kwargs...) where {T<:Real} draw!(scene, sys.assembly; kwargs...) draw!(scene, sys.detector; kwargs...) end -draw!(scene::Makie.LScene, sys::AxisymmetricOpticalSystem{T}; kwargs...) where {T<:Real} = draw!(scene, sys.system; kwargs...) +draw!(scene::Union{Makie.LScene, DrawingInR} , sys::AxisymmetricOpticalSystem{T}; kwargs...) where {T<:Real} = draw!(scene, sys.system; kwargs...) onlydetectorrays(system::Q, tracevalue::LensTrace{T,3}) where {T<:Real,Q<:AbstractOpticalSystem{T}} = onsurface(detector(system), point(tracevalue)) @@ -478,19 +534,29 @@ Also `drawtracerays!` to add to an existing scene, with `drawsys` and `drawgen` """ function drawtracerays(system::Q; raygenerator::S = Source(transform = translation(0.0,0.0,10.0), origins = Origins.RectGrid(10.0,10.0,25,25),directions = Constant(0.0,0.0,-1.0)), test::Bool = false, trackallrays::Bool = false, colorbysourcenum::Bool = false, colorbynhits::Bool = false, rayfilter::Union{Nothing,Function} = onlydetectorrays, verbose::Bool = false, resolution::Tuple{Int,Int} = (1000, 1000), kwargs...) where {T<:Real,Q<:AbstractOpticalSystem{T},S<:AbstractRayGenerator{T}} verbose && println("Drawing System...") - s, ls = Vis.scene(resolution) - - drawtracerays!(ls, system, raygenerator = raygenerator, test = test, colorbysourcenum = colorbysourcenum, colorbynhits = colorbynhits, rayfilter = rayfilter, trackallrays = trackallrays, verbose = verbose, drawsys = true, drawgen = true; kwargs...) - - display(s) - if (get_current_mode() == :pluto || get_current_mode() == :docs) - return s + if activeFigureView && !(get_current_mode() == :pluto || get_current_mode() == :docs) + dInR = DrawingInR() + drawtracerays!(dInR, system, raygenerator = raygenerator, test = test, colorbysourcenum = colorbysourcenum, colorbynhits = colorbynhits, rayfilter = rayfilter, trackallrays = trackallrays, verbose = verbose, drawsys = true, drawgen = true; kwargs...) + display(dInR) + else + s, ls = Vis.scene(resolution) + drawtracerays!(ls, system, raygenerator = raygenerator, test = test, colorbysourcenum = colorbysourcenum, colorbynhits = colorbynhits, rayfilter = rayfilter, trackallrays = trackallrays, verbose = verbose, drawsys = true, drawgen = true; kwargs...) + display(s) + if (get_current_mode() == :pluto || get_current_mode() == :docs) + return s + end end end -drawtracerays!(system::Q; kwargs...) where {T<:Real,Q<:AbstractOpticalSystem{T}} = drawtracerays!(current_3d_scene, system; kwargs...) +function drawtracerays!(system::Q; kwargs...) where {T<:Real,Q<:AbstractOpticalSystem{T}} + if get_current_mode() == :pluto || get_current_mode() == :docs || !activeFigureView + drawtracerays!(current_3d_scene, system; kwargs...) + else + drawtracerays!(dInR, system; kwargs...) + end +end -function drawtracerays!(scene::Makie.LScene, system::Q; raygenerator::S = Source(transform = translation(0.0,0.0,10.0), origins = Origins.RectGrid(10.0,10.0,25,25),directions = Constant(0.0,0.0,-1.0)), test::Bool = false, trackallrays::Bool = false, colorbysourcenum::Bool = false, colorbynhits::Bool = false, rayfilter::Union{Nothing,Function} = onlydetectorrays, verbose::Bool = false, drawsys::Bool = false, drawgen::Bool = false, kwargs...) where {T<:Real,Q<:AbstractOpticalSystem{T},S<:AbstractRayGenerator{T}} +function drawtracerays!(scene::Union{Makie.LScene, DrawingInR} , system::Q; raygenerator::S = Source(transform = translation(0.0,0.0,10.0), origins = Origins.RectGrid(10.0,10.0,25,25),directions = Constant(0.0,0.0,-1.0)), test::Bool = false, trackallrays::Bool = false, colorbysourcenum::Bool = false, colorbynhits::Bool = false, rayfilter::Union{Nothing,Function} = onlydetectorrays, verbose::Bool = false, drawsys::Bool = false, drawgen::Bool = false, kwargs...) where {T<:Real,Q<:AbstractOpticalSystem{T},S<:AbstractRayGenerator{T}} raylines = Vector{LensTrace{T,3}}(undef, 0) drawgen && draw!(scene, raygenerator, norays = true; kwargs...) @@ -557,7 +623,7 @@ end Draw a vector of [`Ray`](@ref) or [`OpticalRay`](@ref) objects. """ -function draw!(scene::Makie.LScene, rays::AbstractVector{<:AbstractRay{T,N}}; kwargs...) where {T<:Real,N} +function draw!(scene::Union{Makie.LScene, DrawingInR} , rays::AbstractVector{<:AbstractRay{T,N}}; kwargs...) where {T<:Real,N} for r in rays draw!(scene, r; kwargs...) end @@ -568,7 +634,7 @@ end Draw a vector of [`LensTrace`](@ref) objects. """ -function draw!(scene::Makie.LScene, traces::AbstractVector{LensTrace{T,N}}; kwargs...) where {T<:Real,N} +function draw!(scene::Union{Makie.LScene, DrawingInR} , traces::AbstractVector{LensTrace{T,N}}; kwargs...) where {T<:Real,N} for t in traces draw!(scene, t; kwargs...) end @@ -580,7 +646,7 @@ end Draw a [`LensTrace`](@ref) as a line which can be colored automatically by its `sourcenum` or `nhits` attributes. The alpha is determined by the `power` attribute of `trace`. """ -function draw!(scene::Makie.LScene, trace::LensTrace{T,N}; colorbysourcenum::Bool = false, colorbynhits::Bool = false, kwargs...) where {T<:Real,N} +function draw!(scene::Union{Makie.LScene, DrawingInR} , trace::LensTrace{T,N}; colorbysourcenum::Bool = false, colorbynhits::Bool = false, kwargs...) where {T<:Real,N} if colorbysourcenum color = indexedcolor(sourcenum(trace)) elseif colorbynhits @@ -598,7 +664,7 @@ Draw an [`OpticalRay`](@ref) which can be colored automatically by its `sourcenu The alpha of the ray is determined by the `power` attribute of `ray`. `kwargs` are passed to `draw!(scene, ray::Ray)`. """ -function draw!(scene::Makie.LScene, r::OpticalRay{T,N}; colorbysourcenum::Bool = false, colorbynhits::Bool = false, kwargs...) where {T<:Real,N} +function draw!(scene::Union{Makie.LScene, DrawingInR} , r::OpticalRay{T,N}; colorbysourcenum::Bool = false, colorbynhits::Bool = false, kwargs...) where {T<:Real,N} if colorbysourcenum color = indexedcolor(sourcenum(r)) elseif colorbynhits @@ -620,12 +686,19 @@ function draw!(scene::Makie.LScene, ray::AbstractRay{T,N}; color = :yellow, rays Makie.arrows!(scene, [Makie.Point3f0(origin(ray))], [Makie.Point3f0(rayscale * direction(ray))]; kwargs..., arrowsize = arrow_size, arrowcolor = color, linecolor = color, linewidth=arrow_size * 0.5) end +function draw!(dInR::DrawingInR, ray::AbstractRay{T,N}; color = :yellow, rayscale = 1.0, kwargs...) where {T<:Real,N} + arrow_size = min(0.05, rayscale * 0.05) + Makie.arrows!(dInR.lscene1, [Makie.Point3f0(origin(ray))], [Makie.Point3f0(rayscale * direction(ray))]; kwargs..., arrowsize = arrow_size, arrowcolor = color, linecolor = color, linewidth=arrow_size * 0.5) + Makie.arrows!(dInR.lscene2, [Makie.Point3f0(origin(ray))], [Makie.Point3f0(rayscale * direction(ray))]; kwargs..., arrowsize = arrow_size, arrowcolor = color, linecolor = color, linewidth=arrow_size * 0.5) + Makie.arrows!(dInR.lscene3, [Makie.Point3f0(origin(ray))], [Makie.Point3f0(rayscale * direction(ray))]; kwargs..., arrowsize = arrow_size, arrowcolor = color, linecolor = color, linewidth=arrow_size * 0.5) +end + """ draw!(scene::Makie.LScene, du::DisjointUnion{T}; kwargs...) Draw each [`Interval`](@ref) in a [`DisjointUnion`](@ref). """ -function draw!(scene::Makie.LScene, du::DisjointUnion{T}; kwargs...) where {T<:Real} +function draw!(scene::Union{Makie.LScene, DrawingInR} , du::DisjointUnion{T}; kwargs...) where {T<:Real} draw!(scene, intervals(du); kwargs...) end @@ -634,7 +707,7 @@ end Draw a vector of [`Interval`](@ref)s. """ -function draw!(scene::Makie.LScene, intervals::AbstractVector{Interval{T}}; kwargs...) where {T<:Real} +function draw!(scene::Union{Makie.LScene, DrawingInR} , intervals::AbstractVector{Interval{T}}; kwargs...) where {T<:Real} for i in intervals draw!(scene, i; kwargs...) end @@ -645,7 +718,7 @@ end Draw an [`Interval`](@ref) as a line with circles at each [`Intersection`](@ref) point. """ -function draw!(scene::Makie.LScene, interval::Interval{T}; kwargs...) where {T<:Real} +function draw!(scene::Union{Makie.LScene, DrawingInR} , interval::Interval{T}; kwargs...) where {T<:Real} if !(interval isa EmptyInterval) l = lower(interval) u = upper(interval) @@ -670,7 +743,7 @@ end Draw an [`Intersection`](@ref) as a circle, optionally showing the surface normal at the point. """ -function draw!(scene::Makie.LScene, intersection::Intersection; normal::Bool = false, kwargs...) +function draw!(scene::Union{Makie.LScene, DrawingInR} , intersection::Intersection; normal::Bool = false, kwargs...) draw!(scene, point(intersection); kwargs...) if normal draw!(scene, Ray(point(intersection), normal(intersection)); kwargs...) @@ -682,7 +755,7 @@ end Draw a vector of lines. """ -function draw!(scene::Makie.LScene, lines::AbstractVector{Tuple{P,P}}; kwargs...) where {T<:Real,P<:AbstractVector{T}} +function draw!(scene::Union{Makie.LScene, DrawingInR} , lines::AbstractVector{Tuple{P,P}}; kwargs...) where {T<:Real,P<:AbstractVector{T}} for l in lines draw!(scene, l; kwargs...) end @@ -697,12 +770,18 @@ function draw!(scene::Makie.LScene, line::Tuple{P,P}; color = :yellow, kwargs... Makie.linesegments!(scene, [line[1], line[2]]; kwargs..., color = color) end +function draw!(dInR::DrawingInR, line::Tuple{P,P}; color = :yellow, kwargs...) where {T<:Real,P<:AbstractVector{T}} + Makie.linesegments!(dInR.lscene1, [line[1], line[2]]; kwargs..., color = color) + Makie.linesegments!(dInR.lscene2, [line[1], line[2]]; kwargs..., color = color) + Makie.linesegments!(dInR.lscene2, [line[1], line[2]]; kwargs..., color = color) +end + """ draw!(s::Makie.LScene, point::AbstractVector{T}; kwargs...) Draw a single point, `kwargs` are passed to `draw!(scene, points::AbstractVector{AbstractVector{T}})`. """ -function draw!(s::Makie.LScene, point::AbstractVector{T}; kwargs...) where {T<:Real} +function draw!(s::Union{Makie.LScene, DrawingInR} , point::AbstractVector{T}; kwargs...) where {T<:Real} draw!(s, [point]; kwargs...) end @@ -716,6 +795,12 @@ function draw!(scene::Makie.LScene, points::AbstractVector{P}; markersize = 20, Makie.scatter!(scene, points, markersize = markersize, color = color, strokewidth = 0; kwargs...) end +function draw!(dInR::DrawingInR, points::AbstractVector{P}; markersize = 20, color = :black, kwargs...) where {T<:Real,P<:AbstractVector{T}} + Makie.scatter!(dInR.lscene1, points, markersize = markersize, color = color, strokewidth = 0; kwargs...) + Makie.scatter!(dInR.lscene2, points, markersize = markersize, color = color, strokewidth = 0; kwargs...) + Makie.scatter!(dInR.lscene3, points, markersize = markersize, color = color, strokewidth = 0; kwargs...) +end + ####################################################### function plotOPD!(sys::AxisymmetricOpticalSystem{T}; label = nothing, color = nothing, collimated::Bool = true, axis::Int = 1, samples::Int = 5, wavelength::T = 0.55, sourcepos::SVector{3,T} = SVector{3,T}(0.0, 0.0, 10.0), kwargs...) where {T<:Real} From eb1c2f3dd1954fd092e4728699f5872025051f5b Mon Sep 17 00:00:00 2001 From: mattderstine Date: Sun, 5 Dec 2021 20:35:21 -0800 Subject: [PATCH 2/5] add logo.png file --- src/Examples/logo.png | Bin 0 -> 5192 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/Examples/logo.png diff --git a/src/Examples/logo.png b/src/Examples/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..890b17dd0b7061be84653ee9ab6d244065df35d3 GIT binary patch literal 5192 zcmai2c|6qX_n*a1Db!e!X|iRRF|v-4Jxi1|vSk|#W-&7|)(oQT+f_taBV9zUEz3lf zR%^%>Ay-D0N@eRe)b}pGd%wTmAD@|dp7%NL=bZOB&-uJwbIts$;XW>5E&u?q&)7)c zlKJhyd=xp@n4e|J;Vl3FOEuQoj$&tKigG95;I1A7Hw>JLBQkLS0IfwOy1M&fC{Q)*Tu?O0!xLqxfBL60bEOIM zrcj6|1R^jn5FU6EP9S+9km~B{2n9uiqM|(0LY^Fir?^t(@#N#X6hAohF=TfVmPo-8 z@X%dOS2sccMH2>N;?SSu7%KKpc0BoK`b;4Zy9fdaS3vyLoPzcIFXp?*Kg@~V1PX!d zO(6b}z~7Ge1OA62Q@($9p}G?P&DhNB|2D_r{+0%rVsMEm#7|NG7Sn$YAX^6!F$hZx znGis7#~56~;3>!Vl-Sh;Wsap{{Ot6xI1HZ5R96#*R8aU|=!L(a%6|d%2z~^T6|<`_ zOs_qkUFlH9I9D%>E!KnL{U_OiD^9$H5t_>c`%trA~GP^%9O_-`8 z;xFf1_*dwUN}%?_Gb4B~qdU1r_$Oqnr)N$gcw+sS7}?TL7iw&vr-D>hQIS`K|2TnJ zHWbqr>lvi)N?}?lDkvi5kw|$(6>FqAN(qTlR+d*#L;cih&zgA~JX|TR|DXMCPeaj6 z4>L2A5td9Lkb?HMel)rj#{b9a$I=hG*Wpm;UY${{?z@Rv)<^!u^Ly!^~5g7{;MFc*IeA`G56eMrnP)AQ?x4*&p=hGmxJALRf5q*DV@ z-^fN;2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001 From 8f8ffca9a9f5e124dc33b69795c821582db42c8b Mon Sep 17 00:00:00 2001 From: mattderstine Date: Tue, 7 Dec 2021 19:17:04 -0800 Subject: [PATCH 3/5] spelling mistake in DrawingInR --- src/Vis/ManagedFigures.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Vis/ManagedFigures.jl b/src/Vis/ManagedFigures.jl index eabe5bc90..bfeab229c 100644 --- a/src/Vis/ManagedFigures.jl +++ b/src/Vis/ManagedFigures.jl @@ -158,7 +158,7 @@ function DrawingInR(; name = "Draw-$numNextFigPos", xRegion = visPlaneX, yRegio Makie.on(dInR.oneButton.clicks) do n if dInR.oneswap dInR.fV.workingGrid[1,1] = lscene1 - dInR.V.userGrid[1,1] = lscene2 + dInR.fV.userGrid[1,1] = lscene2 dInR.fV.userGrid[3,1] = lscene3 dInR.oneswap = false else From 8cd9f72f1aabed965d47eba3d00c13cf430204be Mon Sep 17 00:00:00 2001 From: mattderstine <59268355+mattderstine@users.noreply.github.com> Date: Mon, 2 Jun 2025 15:49:39 -0700 Subject: [PATCH 4/5] working on managed figures --- src/Vis/ManagedFigures.jl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Vis/ManagedFigures.jl b/src/Vis/ManagedFigures.jl index bfeab229c..ae7726af1 100644 --- a/src/Vis/ManagedFigures.jl +++ b/src/Vis/ManagedFigures.jl @@ -30,6 +30,23 @@ global currentUserGrid = nothing global activeFigureView = false +function getFilePath(directory, fileNameStub) + name = joinpath(directory, fileNameStub * ".png") + n = 1 + while isfile(name) + name = joinpath(directory, fileNameStub * "-" * string(n, pad=3) * ".png") + n += 1 + end + return name +end + +function saveFigure(dir, fileNameStub, fig) + filename = getFilePath(dir, fileNameStub) + Makie.save(filename, fig) + display(currentFigure) +end + + function FigureView(; figureName = string(numNextFigPos), fileNameStub = nothing, dir = nothing, activeButtonColor = Makie.RGBf0(0.8, 0.94, 0.8), resolution = defaultResolution) global logo global currentUserGrid @@ -69,12 +86,12 @@ function FigureView(; figureName = string(numNextFigPos), fileNameStub = nothing # normally the items would be defined and then included in the constuctor. Some of the Makie objects have unexpected actions # when being assigned, so assign directly onto the FigureView fields. - figc[1,1] = curFigView.statusGrid = Makie.GridLayout(tellwidth = true, tellheight=false) + figc[1,1] = curFigView.statusGrid = Makie.GridLayout(tellwidth = true, tellheight=true) - curFigView.statusGrid[1, 1] = curFigView.buttonGrid = Makie.GridLayout(tellwidth = true, tellheight=false) - curFigView.statusGrid[2, 1] = curFigView.userGrid = Makie.GridLayout(tellwidth = true, tellheight=false) + curFigView.statusGrid[1, 1] = curFigView.buttonGrid = Makie.GridLayout(tellwidth = true, tellheight=true) + curFigView.statusGrid[2, 1] = curFigView.userGrid = Makie.GridLayout(tellwidth = true, tellheight=true) currentUserGrid=curFigView.userGrid - curFigView.statusGrid[3, 1] = curFigView.utilGrid = Makie.GridLayout(tellwidth = true, tellheight=false) + curFigView.statusGrid[3, 1] = curFigView.utilGrid = Makie.GridLayout(tellwidth = true, tellheight=true) figc[1,2] = curFigView.workingGrid = Makie.GridLayout(tellwidth = true, tellheight=true) curFigView.saveRegion = figc #workinggrid From 7a6e91848c0c57df5e993004ee13a85ed45b30e8 Mon Sep 17 00:00:00 2001 From: mattderstine <59268355+mattderstine@users.noreply.github.com> Date: Mon, 2 Jun 2025 15:51:21 -0700 Subject: [PATCH 5/5] ignore DS_Store file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 60474ca48..2c69b7ef0 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,5 @@ Manifest.toml # Cloud config file src/Cloud/amlconf + +.DS_Store