Git Product home page Git Product logo

collapse's Introduction

Build Status

collapse

The wavefunction collapse algorithm, reimplemented in Rust, with a nice CLI.

Inspired by the reference implementation here.

Features

  • An accurate progress bar! (the time estimate seems to be based on a first derivative approximation, and this algorithm tends to accelerate over time. So TODO: a different progress bar.)
  • More options than the original! Full control over augmenting the sample with symmetries, and over which axes are periodic in the input/output.
  • Coming soon: Built-in support for animations and voxels, as well as approximate comparisons instead of exact equality tests when colliding samples. The goal with the approximate equality testing is to make the algorithm work with images that have larger palettes.

Running/building it

Cargo is required to compile and run this repository.

To install it, simply run cargo build --release && cargo install. The installed binary will be named runcollapse. Check out the command-line interface with runcollapse --help. Building with --release is heavily recommended, as it speeds up runtimes by a ridiculous amount anecdotally determined to be at least ten-fold.

Features:

runcollapse 2d

The two-dimensional case of the wavefunction collapse algorithm. Options:

runcollapse-2d
The 2D case of the wavefunction collapse algorithm. Samples an input image and produces an output image.

USAGE:
    runcollapse 2d [FLAGS] [OPTIONS] <INPUT> <OUTPUT> -d <x, y> [--] [ARGS]

FLAGS:
        --all-symmetry    Augment the sample image with rotations/reflections, using all members of the relevant symmetry group. This is the default symmetry setting.
    -h, --help            Prints help information
        --no-symmetry     Do not augment the sample image with rotations/reflections.
    -V, --version         Prints version information

OPTIONS:
    -n <x, y>
            The sample dimensions; expects two positive nonzero integers, corresponding to the width and height of the rectangle to be used for sampling the input. Defaults to 3
            for both axes.
    -d <x, y>
            The dimensions of the output image.
    -p, --periodic-input <x, y>
            The input periodicity; expects two booleans, corresponding to the x and y axes. If true, then the input will be processed as wrapping on that axis. Defaults to false
            for both axes.
    -P, --periodic-output <x, y>
            The output periodicity; expects two booleans, corresponding to the x and y axes. If true, then the output will be processed as wrapping on that axis. Defaults to true
            for both axes.
    -c <source x, source y, output x (optionally a range x0..x1, x0 inclusive, x1 exclusive), output y (optionally a range y0..y1, y0 inclusive, y1 exclusive)>...        

ARGS:
    <INPUT>              The input file to sample.
    <OUTPUT>             The output file to generate.
    <identity>           The original image, since the identity transformation is a no-op. Don't forget this if you're building up a custom set of symmetries.
    <reflect-x>          Reflect over the x axis.
    <reflect-y>          Reflect over the y axis.
    <reflect-y-rot90>    Reflect over the y axis, and then rotate by 90 degrees. This is equivalent to a reflection over the line y = -x.
    <reflect-x-rot90>    Reflect the over the x axis, and then rotate by 90 degrees. This is equivalent to a reflection over the line y = x.
    <rot90>              Rotate the image 90 degrees clockwise.
    <rot180>             Rotate the image 180 degrees clockwise.
    <rot270>             Rotate the image 270 degrees clockwise.

To change symmetries, one can either use the flag --all-symmetries, --no-symmetries to disable all symmetry augmentations other than the original image, or a combination of the identity, reflect-x, reflect-y, etc. options to enable specific symmetries.

An example command, using this specific symmetry selection:

runcollapse 2d resources/City.png output/City.png -d=64,64 --periodic-input=true,false --periodic-output=true,false identity reflect-x -c 0,-1,0,-1 0,0,0..63,0

This runs with the input and output wrapping on the x axis only, the identity and horizontally reflected symmetries enabled, and requiring that the pixel at (0, -1) in the input appears at (0, -1) in the output. This translates to the pixel one pixel from the bottom in the input appearing one pixel from the bottom in the output (negative indices wrap, Python-style.) The second constraint requires that the pixel at (0, 0) in the input appears in the range from (0, 0) to (63, 0) in the output - so, the entire top row of pixels. The output size is set to be 64 by 64 pixels.

runcollapse 2d-anim

Coming soon - uses the three-dimensional case, and stacks input animation frames to form a 3D volume before running the algorithm on it.

runcollapse 3d

Coming soon - voxels!

collapse's People

Contributors

sdleffler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

collapse's Issues

Restructure Project

A lot of the code base goes against how a Rust project should be structured. For example: The formatting in many places doesn't look write and we should really be using extern crate here.

I would be happy to work on this myself but I recognise that this repo is fairly old and I likely completely inactive

error compiling clap

I'm having trouble building collapse. Could I please ask for help figuring this out?

cargo --version
cargo 1.28.0 (96a2c7d16 2018-07-13)

rustc --version
rustc 1.28.0 (9634041f0 2018-07-30)

cargo build --release

   Compiling clap v2.32.0
error[E0583]: file not found for module `option`
  --> /Users/slowikow/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.32.0/src/args/arg_builder/mod.rs:10:5
   |
10 | mod option;
   |     ^^^^^^
   |
   = help: name the file either option.rs or option/mod.rs inside the directory "/Users/slowikow/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.32.0/src/args/arg_builder"

error: aborting due to previous error

For more information about this error, try `rustc --explain E0583`.
error: Could not compile `clap`.
warning: build failed, waiting for other jobs to finish...
error: build failed
rustc --explain E0583

A file wasn't found for an out-of-line module.

Erroneous code example:

```
mod file_that_doesnt_exist; // error: file not found for module

fn main() {}
```

Please be sure that a file corresponding to the module exists. If you
want to use a module named `file_that_doesnt_exist`, you need to have a file
named `file_that_doesnt_exist.rs` or `file_that_doesnt_exist/mod.rs` in the
same directory.
$ cargo build --release
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating git repository `https://github.com/sdleffler/vosealias-rs`
 Downloading ndarray v0.6.10
 Downloading image v0.20.1
 Downloading bitflags v0.7.0
 Downloading bit-set v0.4.0
 Downloading bit-vec v0.4.4
 Downloading log v0.3.9
 Downloading pbr v0.3.1
 Downloading regex v0.1.80
 Downloading itertools v0.5.10
 Downloading num-traits v0.1.43
 Downloading matrixmultiply v0.1.15
 Downloading num-complex v0.1.43
 Downloading num-traits v0.2.6
 Downloading rawpointer v0.1.0
 Downloading tiff v0.2.1
 Downloading num-rational v0.2.1
 Downloading png v0.12.0
 Downloading lzw v0.10.0
 Downloading gif v0.10.1
 Downloading scoped_threadpool v0.1.9
 Downloading jpeg-decoder v0.1.15
 Downloading byteorder v1.2.7
 Downloading num-iter v0.1.37
 Downloading num-derive v0.2.3
 Downloading proc-macro2 v0.4.23
 Downloading quote v0.6.10
 Downloading syn v0.15.20
 Downloading inflate v0.4.3
 Downloading deflate v0.7.19
 Downloading adler32 v1.0.3
 Downloading color_quant v1.0.1
 Downloading rayon v1.0.3
 Downloading cfg-if v0.1.6
 Downloading lazy_static v1.2.0
 Downloading nodrop v0.1.13
 Downloading log v0.4.6
 Downloading winapi v0.2.8
 Downloading kernel32-sys v0.2.2
 Downloading winapi-build v0.1.1
 Downloading thread_local v0.2.7
 Downloading regex-syntax v0.3.9
 Downloading aho-corasick v0.5.3
 Downloading memchr v0.1.11
 Downloading utf8-ranges v0.1.3
 Downloading thread-id v2.0.0
   Compiling proc-macro2 v0.4.23
   Compiling cfg-if v0.1.6
   Compiling nodrop v0.1.13
   Compiling scopeguard v0.3.3
   Compiling unicode-xid v0.1.0
   Compiling memoffset v0.2.1
   Compiling lazy_static v1.2.0
   Compiling num-traits v0.2.6
   Compiling winapi-build v0.1.1
   Compiling libc v0.2.43
   Compiling rayon-core v1.4.1
   Compiling num-integer v0.1.39
   Compiling num-derive v0.2.3
   Compiling rayon v1.0.3
   Compiling num-iter v0.1.37
   Compiling winapi v0.2.8
   Compiling adler32 v1.0.3
   Compiling either v1.5.0
   Compiling byteorder v1.2.7
   Compiling num-rational v0.2.1
   Compiling matrixmultiply v0.1.15
   Compiling lzw v0.10.0
   Compiling rawpointer v0.1.0
   Compiling unicode-width v0.1.5
   Compiling ndarray v0.6.10
   Compiling bitflags v1.0.4
   Compiling color_quant v1.0.1
   Compiling vec_map v0.8.1
   Compiling strsim v0.7.0
   Compiling regex-syntax v0.3.9
   Compiling bit-vec v0.4.4
   Compiling ansi_term v0.11.0
   Compiling utf8-ranges v0.1.3
   Compiling scoped_threadpool v0.1.9
   Compiling bitflags v0.7.0
   Compiling lazy_static v0.2.11
   Compiling crossbeam-utils v0.2.2
   Compiling log v0.4.6
   Compiling arrayvec v0.4.7
   Compiling kernel32-sys v0.2.2
   Compiling num_cpus v1.8.0
   Compiling rand v0.4.3
   Compiling memchr v0.1.11
   Compiling time v0.1.40
   Compiling atty v0.2.11
   Compiling inflate v0.4.3
   Compiling itertools v0.5.10
   Compiling textwrap v0.10.0
   Compiling deflate v0.7.19
   Compiling bit-set v0.4.0
   Compiling gif v0.10.1
   Compiling log v0.3.9
   Compiling crossbeam-epoch v0.3.1
   Compiling aho-corasick v0.5.3
   Compiling clap v2.32.0
error[E0583]: file not found for module `option`
  --> /Users/slowikow/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.32.0/src/args/arg_builder/mod.rs:10:5
   |
10 | mod option;
   |     ^^^^^^
   |
   = help: name the file either option.rs or option/mod.rs inside the directory "/Users/slowikow/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.32.0/src/args/arg_builder"

error: aborting due to previous error

For more information about this error, try rustc --explain E0583.
error: Could not compile clap.
warning: build failed, waiting for other jobs to finish...
error: build failed

Significantly slower than the reference implementation

I ran this on both windows as well as ubuntu linux subsystem on windows. I am going to try this on mac as well.

When generating a 50x150 output image (using 3x3 sampling) from an approximately 50x50 source, with "level 3 symmetry", the reference C# implementation generates 2 images in under a minute, while the rust implementation

I'm opening this issue primarily to document my experience, I intend to continue by profiling my workload and diagnose the cause of the slowness.

  • Provide my system info (both windows

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.