Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
latticeExtensions (#215)
Browse files Browse the repository at this point in the history
* Extensions to existing lattic code.

* adding code for repeating structures

* rewrote lattice functions. Much simpler now.

* generalized lattice type so it works in any dimension

* optimized LatticeBasis constructor by tweaking type annotation. 50x faster than before.

* documentation changes in Lattice.jl

* documentation change in Lattice.jl

* added const ring1 ring2 definitions using diagonal arrows which Julia is not accepting as variable names.

* added code to Lattice.jl to create the 1 and 2 ring hex patterns.

* added hex to ring1,ring2 function names

* small simplifications to hexring functions in Lattice.jl

* changing lattice rings to generate both i,j indices of ring hexagons and positions of centers.

* changed hexring functions to generate i,j coordinate offsets rather than absolute x,y positions for ring hex centers. More convenient for indexing into a hexagon array.

* comment change

* doc change

* generalizing hexagonal lattice code so up down, etc. work regardless of basis.

* new hex code simplies bases and ring calculation.

* moved using statements from Visualization.jl to Vis.jl because Vis.jl defines the module.

* added VisRepeatingStructures.jl

* added hexgrid visualization code. Fixed hex basis errors.

* comment change

* got ring1 and ring2 hexagons working and rewrote hexpoints to work with i,j coordinates rather than 2D points.

* simplifying ring function to make it completely general.

* last offset in hexcycle was hexdownleft() should have been hexdownright()

* made hexcycle const

* changed hexcellsinbox to return a 1D array and added color option to drawhexcells

* documentation change

* cleaned up code gave hex lattice functions more informative names, better doc strings, removed unused functions.

* working on documentation for repeating structures.

* changed hexup(), etc. to take a number of steps arg. This will be useful for computing the centers of ring n hexagonal clusters.

* more name changes and doc changes

* scaled text to be proportional to size of hex cell so it is more readable. improved color choice when user doesn't specify colors.

changed function names in HexagonalLattice.jl to be more descriptive.

* added license notice

* added license header

* added examples for repeating structures. changed docs to include neighbors and basis as part of the interface of the Basis abstract type.

* added license line

* example code change

* modified Vis.jl file to have same import/usings as used to be in Visualization.jl

* updated comment in Vis.jl about precompiled sysimage

* fixed examples for repeating structures.

* Update docs/make.jl

Co-authored-by: Charlie Hewitt <[email protected]>

* file name change, hexregion -> region(::LatticeBasis...) first crack at Repeating structures documentation.

* tweaking repeat documentation

* added tilevertices to interface for lattice so vertices of unit tile are associated with the lattice basis vectors.

* removed call to Vis.save because that only works with Makie, not Luxor.

* updated project.toml to makie 0.14.2

* documentation for repeating structures module.

* repeat structure documentation improvements.

* documentation improvements for repeat

* more doc improvements for repeat

* typo in repeat documentation

* fixes to repeat documentation

* documentation changes for repeat

* added Luxor to project.toml in docs project. small changes to vis of hex cells.

* example illustrations for repeat didn't show up because forgot to use full package name.

* type in repeat docs

* typo in repeat docs. Visualization doesn't return luxor drawing properly. Not obvious how to do this.

* adding VSCodeCounter directory to .gitignore

* added .VSCodeCounter directory to .gitignore

* added the bility to produce a repeatable drawing in different formats: png and svg to better support the docs creation. (#235)

* removed Luxor from the docs project and fixed the Vis.drawhexcells to support the native julia way of displaying a drawing by using the Luxor.preview function which will return a drawing that will be drawn according to the correct context. (#245)

Co-authored-by: Charlie Hewitt <[email protected]>
Co-authored-by: Ran Gal <[email protected]>
  • Loading branch information
3 people authored Jul 20, 2021
1 parent a8b2025 commit 465625d
Show file tree
Hide file tree
Showing 18 changed files with 628 additions and 82 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Sumita.jl

## Julia.gitignore ##

# files generated by VSCode Counter
.VSCodeCounter/

# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov
Expand Down
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ makedocs(
"Geometry" => [
"Basic Types" => "basic_types.md",
"Primitives" => "primitives.md",
"CSG" => "csg.md"
"CSG" => "csg.md",
"Repeating Structures" => "repeat.md"
],
"Optical" => [
"Systems" => "systems.md",
Expand Down
60 changes: 60 additions & 0 deletions docs/src/repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Repeating Structures

The Repeat module contains functions for creating regular repeated patterns. This could be pixels in a display grid, or mirrors in an active optics telescope. Repeated patterns are defined by creating an object that inherits from the abstract type [`Basis`](@ref sources).

Subtypes supporting the Basis interface should implement these functions:

Returns the neighbors in ring n surrounding centerpoint, excluding centerpoint
```
neighbors(::Type{B},centerpoint::Tuple{T,T},neighborhoodsize::Int) where{T<:Real,B<:Basis}
```
Returns the lattice basis vectors that define the lattice
```
basis(a::S) where{S<:Basis}
```
Returns the vertices of the unit polygon for the basis that tiles the plane
```
tilevertices(a::S) where{S<:Basis}
```

A lattice is described by a set of lattice vectors eᵢ which are stored in a [`Basis`](@ref sources) object. You can create bases in any dimension. Points in the lattice are indexed by integer coordinates. These lattice coordinates can be converted to Cartesian coordinates by indexing the LatticeBasis object.
``` @example example
using OpticSim, OpticSim.Repeat
a = LatticeBasis([1.0,5.0],[0.0,1.0])
a[3,3]
```

The Lattice points are defined by a weighted sum of the basis vectors:
```
latticepoint = ∑αᵢ*eᵢ
```
where the αᵢ are integer weights.

The [`HexBasis1`](@ref sources) constructor defines a symmetric basis for hexagonal lattices
```@example
using OpticSim, OpticSim.Repeat
basis(HexBasis1())
```
The [`rectangularlattice`](@ref sources) function creates a rectangular lattice basis.

There are a few visualization functions for special 2D lattices. [`Vis.drawhexcells`](@ref sources) draws a set of hexagonal cells. Using [`Repeat.hexcellsinbox`](@ref sources) we can draw all the hexagonal cells that fit in a rectangular box:

```@example
using OpticSim
Vis.drawhexcells(50,Repeat.hexcellsinbox(2,2))
```

There is also a function to compute the n rings of a cell x, i.e., the cells which can be reached by taking no more than n steps along the lattice from x:

```@example
using OpticSim
Vis.drawhexcells(50,Repeat.neighbors(Repeat.HexBasis1,(0,0),2))
```

You can also draw all the cells contained within an n ring:

```@example
using OpticSim
Vis.drawhexcells(50,Repeat.region(Repeat.HexBasis1,(0,0),2))
```

137 changes: 137 additions & 0 deletions luxor-drawing-163404_864.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/Examples/Examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ using ..OpticSim.Vis
using ..OpticSim.Geometry
using ..OpticSim.Emitters
using ..OpticSim.GlassCat
using ..OpticSim.Repeat

using StaticArrays
using DataFrames: DataFrame
using Images
using Unitful
using Plots
using LinearAlgebra
import Luxor

include("docs_examples.jl")
include("other_examples.jl")
include("repeating_structure_examples.jl.jl")

end #module Examples
export Examples
23 changes: 23 additions & 0 deletions src/Examples/repeating_structure_examples.jl.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# MIT license
# Copyright (c) Microsoft Corporation. All rights reserved.
# See LICENSE in the project root for full license information.



#############################################################################

"""draw the 2 neighbors of the hex cell at coordinates (0,0)"""
drawhexneighbors() = Luxor.@svg Vis.drawhexcells(50,Repeat.neighbors(Repeat.HexBasis1,(0,0),2))
export drawneighbors

"""draw hex cell at coordinates (0,0) and the 1 and 2 neighbors"""
drawhexregion() = Luxor.@svg Vis.drawhexcells(50,Repeat.region(Repeat.HexBasis1,(0,0),2))
export drawhexregion

"""draw hex cells that fit within a rectangular box centered at coordinates (0,0). Use fill color yellow."""
drawhexrect() = Luxor.@svg Vis.drawhexcells(50,Repeat.hexcellsinbox(2,2),"yellow")
export drawhexrect

"""draw hex cells that fit within a rectangular box centered at coordinates (0,0). Use random fill colors selected for maximum distinguishability."""
drawhexrectcolors() = Luxor.@svg Vis.drawhexcells(50,Repeat.hexcellsinbox(4,4))
export drawhexrectcolors
1 change: 1 addition & 0 deletions src/OpticSim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import .GlassCat: plot_indices, index, polyfit_indices, absairindex, absorption,

include("Geometry/Geometry.jl")
include("Optical/Optical.jl")
include("RepeatingStructures/Repeat.jl")
include("Vis/Vis.jl")
include("Examples/Examples.jl")
include("Optimization/Optimization.jl")
Expand Down
Loading

0 comments on commit 465625d

Please sign in to comment.