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

New fract4dc interface #85

Merged
merged 32 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b9efac8
created new python extension type "controller" to provide new fract4d…
mindhells Apr 7, 2020
3c9284b
fract4dc: extend controller interface
mindhells Apr 13, 2020
fbace44
fract4dc: clean unused code on site classes
mindhells Apr 13, 2020
d3a8b44
fix: set interrupt flag to false when starting calculations
mindhells Apr 13, 2020
cff91e5
fract4dc controller: resource deallocation
mindhells Apr 15, 2020
37264a3
created a basic fractal creation sample script
mindhells Apr 15, 2020
3a66362
move pysite and calcargs out from model
mindhells Apr 16, 2020
7b72be3
move colorutils, vectors and threadpool into model
mindhells Apr 17, 2020
81bf2a5
created cpp standalone mandelbrot example
mindhells Apr 17, 2020
bbbe798
fix: include not updated
mindhells Apr 17, 2020
061cb0a
update examples readme
mindhells Apr 17, 2020
82b8eb8
python > fract4d_new > add test_calculation_messages_are_handled
Apr 20, 2020
a385904
generalize exmaples infrastructure
mindhells Apr 20, 2020
d687d7a
update helper bash scripts
Apr 20, 2020
d988911
pylint > ignore PIL module
Apr 20, 2020
4cbd5f2
docker > update dockerfile, remove useless deps and update scripts
Apr 20, 2020
f8c6a27
tox > remove test.py from pytest commands
Apr 20, 2020
6408166
pipeline > update travis and tox deps
Apr 20, 2020
d242297
created a new example
mindhells Apr 21, 2020
87fc87d
fix typo
mindhells Apr 22, 2020
f6cd7b7
raw mandelbrot example
mindhells Apr 23, 2020
5ec254f
review c compatibility headers inclusion
mindhells Apr 24, 2020
7d3b222
avoid using NULL C macro to compare to check nullptr
mindhells Apr 24, 2020
923612b
using smart pointers on cpp examples
mindhells Apr 24, 2020
610834c
cpp examples improvements
mindhells Apr 24, 2020
587df89
cpp examples: more improvements
mindhells Apr 24, 2020
56c830d
pylint: PEP8 extrict checker for new python code
guanchor Apr 27, 2020
b6bceb5
docker: keep .so files in workspace when using docker scripts
guanchor Apr 27, 2020
0652478
tests: fix tearDownClass in testbase
guanchor Apr 27, 2020
028516b
tests: more testing to cover the new fractdc interface
guanchor Apr 27, 2020
4dbc081
custom formula cpp example
mindhells Apr 30, 2020
0674dcf
use reinterpret_cast instead C-style to load symbols with dlsym to pr…
mindhells May 4, 2020
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ before_install:
sudo apt-get install -y libgirepository1.0-dev gir1.2-gtk-3.0
install:
- python setup.py build
- pip install tox-travis pillow pygobject pylint
- pip install tox-travis pylint
script:
- ./bin/pylint.sh
- ./bin/pylint.sh || travis_terminate 1;
- tox
notifications:
email: false
4 changes: 2 additions & 2 deletions fract4d/b.sh → bin/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
pushd ..

rm -rf build
rm fract4d/*.so
./setup.py build
popd
6 changes: 6 additions & 0 deletions bin/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

rm -rf build
rm fract4d/*.so
rm -rf .pytest_cache
rm -rf .tox
17 changes: 15 additions & 2 deletions bin/pylint.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
#!/bin/sh
pylint *.py fract4d fract4d_compiler fract4dgui
#!/bin/bash

pylint --rcfile pylintrc *.py fract4d fract4d_compiler fract4dgui
if [[ $? > 0 ]]
then
exit 1
fi

pylint --rcfile pylintrc_new fract4d/fract4d_new
if [[ $? > 0 ]]
then
exit 1
fi

echo "pylint passed successfully"
16 changes: 12 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ RUN \
apt-get -y upgrade && \
apt-get -y install libpng-dev libjpeg-dev python3-dev gtk3.0 libcairo2-dev python3-cairo python3-gi-cairo pkg-config python3-pip xvfb

# bin/run_builds.sh deps
RUN apt-get -y install software-properties-common && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get -y install python3.5 python3.5-dev python3.6 python3.6-dev python3.7 python3.7-dev python3.8 python3.8-dev

# deps for bin/run_*.sh scripts
RUN pip3 install pillow pylint pytest tox
# bin/run_pylint.sh deps
RUN pip3 install pylint

# other deps
RUN apt-get -y install libgirepository1.0-dev gir1.2-gtk-3.0
# bin/run_pytest.sh deps
RUN pip3 install pytest

# bin/run_tox.sh deps
RUN apt-get -y install libgirepository1.0-dev
RUN pip3 install tox

# Xvfb (in memory x11 server) setup
ENV DISPLAY :99
Expand Down
9 changes: 9 additions & 0 deletions docker/bin/run_builds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

docker-compose up -d --build
docker-compose exec server bash -c "rm -rf build"
docker-compose exec server bash -c "python3.5 ./setup.py build && \
python3.6 ./setup.py build && \
python3.7 ./setup.py build && \
python3.8 ./setup.py build"
docker-compose down
8 changes: 8 additions & 0 deletions docker/bin/run_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

docker-compose up -d
docker-compose exec server bash -c "rm -rf build && \
rm fract4d/*.so && \
rm -rf .pytest_cache && \
rm -rf .tox"
docker-compose down
3 changes: 0 additions & 3 deletions docker/bin/run_lint.sh

This file was deleted.

7 changes: 7 additions & 0 deletions docker/bin/run_pylint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

docker-compose up -d --build
docker-compose exec server bash -c "rm -rf build"
docker-compose exec server bash -c "python3 setup.py build && \
./bin/pylint.sh"
docker-compose down
7 changes: 5 additions & 2 deletions docker/bin/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

docker-compose up -d --build
# docker-compose exec server bash -c "pytest -s test.py::Test::testGenerateMandelbrot"
docker-compose exec server bash -c "rm -rf build && python3 setup.py build && ./test.py"
docker-compose exec server bash -c "rm -rf build"
docker-compose exec server bash -c "python3 setup.py build && \
./test.py"
docker-compose down
9 changes: 8 additions & 1 deletion docker/bin/run_tox.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#!/bin/bash

docker-compose up -d --build
docker-compose exec server bash -c "rm -rf build && python3 setup.py build && tox"
docker-compose exec server bash -c "rm -rf build"
docker-compose exec server bash -c "python3.5 ./setup.py build && \
python3.6 ./setup.py build && \
python3.7 ./setup.py build && \
python3.8 ./setup.py build && \
tox"
docker-compose down
155 changes: 155 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# EXAMPLES

*Note: for all exmples make sure you have performed the setup previously:*
```
./setup.py build
```

## Python examples
### Creating a simple mandelbrot using fract4dc.controller

Execute:
```
examples/python/simple_mandelbrot.py
```
Then you should see a new file under `examples/output`.

---

## C++ examples
For these examples you'll need [docker](https://docs.docker.com/get-docker/)

### Creating a simple mandelbrot
Execute:
```
examples/cpp/simple_mandelbrot.sh
```
Then you should see a new file under `examples/output`.



### Creating a simple mandelbrot using multiple threads
Execute:
```
examples/cpp/multithread_mandelbrot.sh
```
Then you should see a new file under `examples/output`.



### Creating a simple mandelbrot using no high level model entities (fractfunc, workers, pointfunc)
In this example we use the compiled formula directly to calculate the fractal with no postprocessing (antialiasing) or improvements (ie. autodeepen)
Execute:
```
examples/cpp/raw_mandelbrot.sh
```
Then you should see a new file under `examples/output`.



### Creating a simple mandelbrot using no high level model entities (fractfunc, workers, pointfunc)
### plus: using a custom formula source (not generated by compiler)

In this example we use the compiled formula directly to calculate the fractal with no postprocessing (antialiasing) or improvements (ie. autodeepen)

The forumula sources `examples/cpp/custom_mandelbrot_formula.c` were generated using gnofract4d and then modified introducing comments and eliminating some temporary vars to clarify calculations

These are the formulas used to generate the sources to begin with:

* main formula: __The Mandelbrot set__
```
Mandelbrot {
; The classic Mandelbrot set
init:
z = #zwpixel
loop:
z = sqr(z) + #pixel
bailout:
@bailfunc(z) < @bailout
default:
float param bailout
default = 4.0
endparam
float func bailfunc
default = cmag
endfunc
}
```
* outer transfer function: __Continuous Potential__
```
continuous_potential {
final:
float ed = @bailout/(|z| + 1.0e-9)
#index = (#numiter + ed) / 256.0
default:
float param bailout
default = 4.0
endparam
}
```
* inner transfer function: __Zero__
```
zero (BOTH) {
final:
#solid = true
}
```
Each of these formulas has its own params, you cam see them on the GUI (fractal settings):

![Formula](readme/formula.png)
![Outer](readme/outer.png)
![Inner](readme/inner.png)

Except for the functions (bailfunc in the Formula and transfer functions in Inner and Outer) all the param values are passed to the formula through the init function.
> Have in mind the formula sources are written in C. This is how you pass the params to the formula: `pf_handle->vtbl->init(pf_handle, const_cast<double *>(pos_params), params.get(), param_len);`

> Actually there's no reason but to keep the interface to send the `pos_param`(x,y,z,w ...) in the init call. The formula params are kept in the state of the pf_handle and used afterwards in the calc method.

> If you look at the code that the compiler spits out there's some parts that seem to have been left behind and are no longer needed: `get_defaults` interface and almost all the state props in `pf_real`struct.

> bailfunc and transfer functions (with values cmag, ident and ident respectively) are not passed along with the params but instead they are coded by the compiler.

If you compare `examples/cpp/custom_mandelbrot_formula.c` with the code generated by running `./gnofract4d --nogui --buildonly mandelbrot -f gf4d.frm#Mandelbrot` you'll find the temporary variables and unused code we disposed for this example to make the code easy to understand.

Back to the Mandelbrot Set formula you can see in the screenshots above or in the file `formulas/gf4d.frm`. There you can identify sections (ended with a colon) init,
loop, bailout... In the source you'll find those sections wrapped by goto labels and some comments we introduced for this example:
* init:
```C++
t__start_finit:;
// init: z = #zwpixel
z_re = t__h_zwpixel_re;
z_im = t__h_zwpixel_im;
goto t__end_finit;
t__end_finit:;
```
* loop:
```C++
t__start_floop:;
// loop: (z = sqr(z) + #pixel) same as (z = z*z + #pixel)
// complex x complex -> (a+bi)⋅(c+di)=(ac−bd)+(ad+bc)i
t__f5 = (z_re * z_re - z_im * z_im) + pixel_re;
t__f6 = (2.00000000000000000 * z_re * z_im) + pixel_im;
z_re = t__f5;
z_im = t__f6;
goto t__end_floop;
t__end_floop:;
```
* bailout:
```C++
t__start_fbailout:;
// this is the bailout function, in this case "cmag" -> "square modulus"
// cmag(a,bi) is equivalent to a*a+b*b
f__bailout = (z_re * z_re + z_im * z_im) < t__a_fbailout;
goto t__end_fbailout;
t__end_fbailout:;
```

This example is intended only to demonstrate how the sources generated by the compiler work for an specific case "The Mandelbrot" with scpecific transfer functions and paramters.

The compiler is capable to handle more complex scenarios, functions and special parameters. You can find more information about that in [the manual](http://fract4d.github.io/gnofract4d/manual/formref.html).

Execute:
```
examples/cpp/custom_formula.sh
```
Then you should see a new file under `examples/output`.
48 changes: 48 additions & 0 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.10)
project(simple_mandelbrot)

set(CMAKE_CXX_STANDARD 17)

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/model)

FILE(GLOB MODELFILES ${PROJECT_SOURCE_DIR}/model/*.cpp)

set(CMAKE_CXX_FLAGS "-ffast-math")

# MAIN

add_executable(example main.cpp ${MODELFILES})

find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
target_link_libraries(example ${PNG_LIBRARY})

find_package(JPEG REQUIRED)
include_directories(${JPEG_INCLUDE_DIR})
target_link_libraries(example ${JPEG_LIBRARY})

find_package(Threads REQUIRED)
target_link_libraries(example ${CMAKE_THREAD_LIBS_INIT})

target_link_libraries(example ${CMAKE_DL_LIBS})

add_definitions(-DTHREADS -D_REENTRANT -DPNG_ENABLED -DJPG_ENABLED)

# FRACT_STDLIB

add_library(fract_stdlib SHARED
${PROJECT_SOURCE_DIR}/fract_stdlib.cpp
${PROJECT_SOURCE_DIR}/model/colorutils.cpp
${PROJECT_SOURCE_DIR}/model/colormap.cpp
${PROJECT_SOURCE_DIR}/model/image.cpp)

set_target_properties(fract_stdlib PROPERTIES PREFIX "")
set_target_properties(fract_stdlib PROPERTIES SUFFIX ".so")

# FORMULA LIB

add_library(formula SHARED
${PROJECT_SOURCE_DIR}/formula.c)
set_target_properties(formula PROPERTIES SUFFIX ".so")
set_target_properties(formula PROPERTIES PREFIX "")
22 changes: 22 additions & 0 deletions examples/cpp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:18.04

ENV TZ=Europe/Minsk
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y build-essential git cmake autoconf libtool pkg-config libpng-dev libjpeg-dev

WORKDIR /src

ARG main_source
ARG formula_source

COPY examples/cpp/${main_source} ./main.cpp
COPY examples/cpp/CMakeLists.txt ./
COPY fract4d/c/fract_stdlib.cpp fract4d/c/fract_stdlib.h fract4d/c/pf.h ./
COPY fract4d/c/model/ ./model
COPY ${formula_source} ./formula.c

RUN cmake . && make

CMD ["./example"]
Loading