Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swapped submodule #150

Merged
merged 4 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ wincertstore==0.2
moviepy==1.0.3
tracery==0.1.1
arrdem.datalog==2.0.1
scipy
numpy
1 change: 0 additions & 1 deletion wfc
Submodule wfc deleted from 524d28
3 changes: 3 additions & 0 deletions wfc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
/output/*
/build
21 changes: 21 additions & 0 deletions wfc/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Isaac Karth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 50 additions & 0 deletions wfc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# wfc_2019f

This is my research implementation of WaveFunctionCollapse in Python. It has two goals:

* Make it easier to understand how the algorithm operates
* Provide a testbed for experimenting with alternate heuristics and features

For more general-purpose WFC information, the original reference repository remains the best resource: https://github.com/mxgmn/WaveFunctionCollapse

## Running WFC

If you want direct control over running WFC, call `wfc_control.execute_wfc()`.

The arguments it accepts are:

- `filename`: path to the input image file
- `tile_size=1`: size of the tiles it uses (1 is fine for pixel images, larger is for things like a Super Metroid map)
- `pattern_width=2`: size of the patterns; usually 2 or 3 because bigger gets slower and
- `rotations=8`: how many reflections and/or rotations to use with the patterns
- `output_size=[48,48]`: how big the output image is
- `ground=None`: which patterns should be placed along the bottom-most line
- `attempt_limit=10`: stop after this many tries
- `output_periodic=True`: the output wraps at the edges
- `input_periodic=True`: the input wraps at the edges
- `loc_heuristic="lexical"`: what location heuristic to use; `entropy` is the original WFC behavior. The heuristics that are implemented are `lexical`, `hilbert`, `spiral`, `entropy`, `anti-entropy`, `simple`, `random`, but when in doubt stick with `entropy`.
- `choice_heuristic="lexical"`: what choice heuristic to use; `weighted` is the original WFC behavior.
- `visualize=True`: write intermediate images to disk?
- `global_constraint=False`: what global constraint to use. Currently the only one implemented is `allpatterns`
- `backtracking=False`: do we use backtracking if we run into a contradiction?
- `log_filename="log"`: what should the log file be named?
- `logging=True`: should we write to a log file?
- `log_stats_to_output=None`

## Test

```
pytest
```

## Documentation

```
python setup.py build_sphinx
```

With linux the doculentation can be displayed with:

```
xdg-open build/sphinx/index.html
```
56 changes: 56 additions & 0 deletions wfc/doc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'wfc_python'
copyright = '2020, Isaac Karth'
author = 'Isaac Karth'

# The full version, including alpha/beta/rc tags
release = '0.1'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.graphviz',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['static']
16 changes: 16 additions & 0 deletions wfc/doc/dot/chain.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
digraph {
read_xml_command -> import_image -> make_tile_catalog -> make_pattern_catalog -> make_adjacency_matrix -> solve_constraint_problem -> output_solution_image
make_tile_catalog -> output_solution_image
make_tile_catalog -> instrumentation [color=gray]
make_pattern_catalog -> instrumentation [color=gray]
make_adjacency_matrix -> instrumentation [color=gray]
solve_constraint_problem -> instrumentation [color=gray]
output_solution_image -> visualization [color=gray]
make_tile_catalog -> visualization [color=gray]
make_pattern_catalog -> visualization [color=gray]
make_adjacency_matrix -> visualization [color=gray]
solve_constraint_problem -> visualization [color=gray]
visualization [color=gray, fontcolor=gray]
instrumentation [color=gray, fontcolor=gray]
visualization -> make_tile_catalog [color=magenta]
}
37 changes: 37 additions & 0 deletions wfc/doc/dot/dependency.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
digraph {
wfc_run -> wfc_control
wfc_control -> wfc_utilities
wfc_control -> wfc_solver
wfc_solver -> numpy
wfc_tiles -> numpy
wfc_patterns -> numpy
wfc_tiles -> wfc_utilities
wfc_control -> wfc_tiles
wfc_control -> wfc_patterns
wfc_patterns -> wfc_utilities
wfc_tiles -> imageio
wfc_control -> wfc_adjacency
wfc_control -> wfc_visualize
wfc_visualize -> matplotlib
wfc_visualize -> wfc_utilities
wfc_adjacency -> wfc_utilities
wfc_adjacency -> numpy
wfc_control -> wfc_instrumentation

implemented [style=filled, fillcolor=gray]
partial [style=filled, fillcolor=cyan]
unimplemented [style=filled, fillcolor=firebrick]
wfc_run
wfc_control []
wfc_solver
numpy [color=gray, fontcolor=gray]
wfc_tiles
wfc_patterns [style=filled, fillcolor=cyan]
wfc_utilities
imageio [color=gray, fontcolor=gray]
wfc_adjacency
wfc_visualize [style=filled, fillcolor=cyan]
matplotlib [color=gray, fontcolor=gray]
wfc_instrumentation [style=filled, fillcolor=firebrick]
label="Modules in WFC 19f"
}
89 changes: 89 additions & 0 deletions wfc/doc/dot/design.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
digraph {
things_to_implement [label="{Things that aren't implemented yet|Intermediate visualization|timing and profiling|performance statistics|outputting images|most heuristics|removing ground patterns|rotated patterns}", shape=record, fillcolor="cyan", style=filled]
read_data [label="Read data from XML", fillcolor="cyan", shape=box, style=filled]
read_data -> input_data
input_data [shape=record, label="XML"]
input_data -> execute_wfc
solver [label="Solver", shape=house]
solver -> make_wave
make_wave -> remove_patterns
remove_patterns [label="Remove ground patterns", fillcolor="cyan", style=filled]
input_data -> remove_patterns
input_data -> solver
remove_patterns -> solver_run [headport=n]
subgraph cluster_solver_run {
label="wfc_solver.py"

solver_run [label="solver.run()"]
solver_observe [label="solver.observe()"]
solver_propagate [label="solver.propagate()"]
solver_on_backtrack [label="solver.onBacktrack()", shape=invhouse]
solver_on_choice [label="solver.onChoice()", shape=invhouse]
on_choice [label="onChoice()", shape=note]
on_backtrack [label="onBacktrack()", shape=note, fillcolor="cyan", style=filled]
solver_if_backtracking [label="if backtracking", shape=diamond]
pattern_heuristic [label="pattern heuristic", shape=note]
location_heuristic [label="location heuristic", shape=note]


{rank=same pattern_heuristic location_heuristic}
solver_run -> solver_check_feasible
solver_check_feasible -> solver_propagate
solver_propagate -> solver_observe
solver_observe -> pattern_heuristic
solver_observe -> location_heuristic
solver_observe -> solver_on_choice
solver_on_choice -> on_choice
solver_recurse -> except_contradictions [color=red]
solver_on_choice -> solver_if_finished
solver_recurse -> solver_run [headport=n, tailport=w]
solver_if_finished [shape=diamond]
solver_if_finished -> solver_recurse [splines=polyline, dir=both, arrowhead=dotvee, arrowtail=dot, tailport=s, headport=n, color="black:green:black"]
except_contradictions -> solver_if_backtracking
solver_if_backtracking -> solver_on_backtrack [label="Yes"]
solver_on_backtrack -> on_backtrack
on_backtrack -> solver_run [headport=n]
solver_if_backtracking -> cant_solve [splines=curved, label="No", dir=both, arrowhead=dotvee, arrowtail=dot, tailport=e, headport=ne, color="grey"]
}
solver_if_finished -> solver_solution [tailport=w, color="black:blue:black"]

execute_wfc [shape=invhouse, fillcolor="cyan", style=filled]
execute_wfc -> import_image
import_image [shape=box]
import_image -> make_tile_catalog
subgraph cluster_tile_py {
label="wfc_tiles.py"
make_tile_catalog -> image_to_tiles
}
image_to_tiles -> tile_catalog
tile_catalog [label="Tile Catalog|{dictionary of tiles|image in tile IDs|set of tiles|frequency of tile occurance}", shape=record]
subgraph cluster_patterns {
label="wfc_patterns.py"
tile_catalog -> make_pattern_catalog
{rank=same unique_patterns_2d rotate_or_reflect}
make_pattern_catalog -> unique_patterns_2d -> rotate_or_reflect -> unique_patterns_2d
make_pattern_catalog [fillcolor="cyan", style=filled]
rotate_or_reflect [fillcolor="cyan", style=filled]
}
unique_patterns_2d -> pattern_catalog
pattern_catalog [label="Pattern Catalog|{dictionary of patterns|ordered list of pattern weights|ordered list of pattern contents}", shape=record]
pattern_catalog -> extract_adjacency
subgraph cluster_adjacency {
extract_adjacency -> is_valid_overlap
}
extract_adjacency -> adjacency_relations
adjacency_relations [label="{Adjacency Relations|tuples of (edge,pattern,pattern)}", shape=record]
adjacency_relations -> combine_inputs
combine_inputs -> adjacency_matrix
adjacency_matrix [label="{Adjacency Matrix|boolean matrix of pattern x pattern x direction}", shape=record]
adjacency_matrix -> solver
pattern_catalog -> solver
cant_solve [label="Can't Solve", shape=box]
solver_solution [shape=record, label="Solution|grid of pattern IDs"]
solver_solution -> visualizer
visualizer -> output_image
output_image [shape=box, label="Output Image", style=filled, fillcolor=cyan]
pattern_catalog -> visualizer
tile_catalog -> visualizer
visualizer [fillcolor=cyan, style=filled]
}
17 changes: 17 additions & 0 deletions wfc/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Documentation
=============

Module dependencies
-------------------

.. graphviz:: dot/dependency.dot

Design
------

.. graphviz:: dot/design.dot

Chain
-----

.. graphviz:: dot/chain.dot
Binary file added wfc/images/samples/3Bricks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wfc/images/samples/Angular.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wfc/images/samples/Castle/bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading