diff --git a/.gitignore b/.gitignore index 9141573..e86b816 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ demo/allegro5/atomorph-gui demo/atomorph libatomorph.a +cmake-build-* +.idea \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/atomorph.iml b/.idea/atomorph.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/atomorph.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..323310f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..38a3db3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.16) +project("atomorph") + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_compile_options(-Wall -Wextra -Werror) + +option(WINDOWS "Whether the build target is Windows or not." OFF) +option(SHARED "Whether we should build a shared library, instead of a static one." OFF) + +if (NOT WINDOWS) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +else() + set(CMAKE_POSITION_INDEPENDENT_CODE OFF) +endif() + +set(LIBTYPE STATIC) +if (SHARED) + set(LIBTYPE SHARED) +endif (SHARED) + +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_link_options(-fuse-ld=lld) +endif () + +file(GLOB_RECURSE SRC_FILES "src/*.cpp") +add_library(atomorph ${LIBTYPE} ${SRC_FILES}) + +if (WINDOWS) + MESSAGE(WARNING, "Using Windows Build.") + # Add a definition for the compiler, so we can use it in C++ as well. + ADD_DEFINITIONS(-D WINDOWS=1) + # -m64: Build a 64 bit library + add_compile_options(-m64) + if (SHARED) + set_target_properties(atomorph PROPERTIES SUFFIX ".dll") + endif() +endif (WINDOWS) + +if (STATICC) + message("Linking dependencies statically.") + set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") + set(LINKS -static-libgcc -static-libstdc++ -Wl,-Bstatic -lm -lstdc++ -lpthread -Wl,-Bdynamic ${LINKS}) +endif(STATICC) +target_link_libraries(atomorph ${LINKS}) diff --git a/Makefile b/Makefile deleted file mode 100644 index 027b735..0000000 --- a/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -NAME = atomorph -CC = gcc -PROF = -O2 -C_FLAGS = -std=c++11 -Wall -pedantic $(PROF) -OBJ_DIR = obj - -SRC_FILES := $(wildcard *.cpp) -O_FILES := $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES)) - -OUT = ./lib$(NAME).a - -all: - @printf "\033[0mHINT: On errors, try \033[1;33m-std=gnu++11 -stdlib=libc++\033[0m compiler flags.\033[0m\n" - @printf "\033[0mHINT: Use \033[1;33mmake opencv\033[0m for OpenCV optimizations (experimental).\033[0m\n" - @printf "\033[0mHINT: Use \033[1;33mmake deprecated\033[0m to compile the old version.\033[0m\n" - @$(MAKE) $(OUT) -s - -opencv: DEFINES = -D ATOMORPH_OPENCV -opencv: $(O_FILES) - @ar rcs $(OUT) $(O_FILES) - @printf "\033[1;32mOpenCV dependent lib$(NAME).a DONE!\033[0m\n" - -deprecated: DEFINES = -D ATOMORPH_DEPRECATED -deprecated: $(O_FILES) - @ar rcs $(OUT) $(O_FILES) - @printf "\033[1;32mDeprecated lib$(NAME).a DONE!\033[0m\n" - -$(OUT): $(O_FILES) - @ar rcs $(OUT) $(O_FILES) - @printf "\033[1;32mlib$(NAME).a DONE!\033[0m\n" - -$(OBJ_DIR)/%.o: %.cpp - @printf "\033[1m\033[31mCompiling \033[37m....\033[34m %-20s\t\033[33m%6s\033[31m lines\033[0m \n" $*.cpp "`wc -l $*.cpp | cut -f1 -d' '`" - @$(CC) $(INCLUDE) $< $(DEFINES) $(C_FLAGS) -c -o $@ - -clean: - @printf "\033[1;36mCleaning \033[37m ...." - @rm -f $(O_FILES) $(OUT) *~ *.bak *.orig *.rej - @printf "\033[1;37m lib$(NAME).a cleaned!\033[0m\n" diff --git a/demo/allegro5/AtoMorph-GUI.cbp b/demo/allegro5/AtoMorph-GUI.cbp deleted file mode 100644 index 3a2dbf6..0000000 --- a/demo/allegro5/AtoMorph-GUI.cbp +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - diff --git a/demo/allegro5/Makefile b/demo/allegro5/Makefile deleted file mode 100644 index 1da2c57..0000000 --- a/demo/allegro5/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -NAME = atomorph-gui -CC = gcc -PROF = -O2 -C_FLAGS = -std=c++11 -Wall $(PROF) -L_FLAGS = ../../libatomorph.a -lm -lstdc++ $(PROF) -OBJ_DIR = obj -DEFINES = -D ATOMORPH_DEPRECATED - -#Change the LIB_DIR to the path where the MODULES are located: -LIB_DIR = /usr/lib/ -MODULES = allegro.so allegro_image.so allegro_font.so allegro_primitives.so - -SRC_FILES := $(wildcard *.cpp) -LIB_FILES := $(patsubst %,$(LIB_DIR)/lib%,$(MODULES)) -O_FILES := $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES)) - -OUT = ./$(NAME) - -all: - @printf "\033[0mHINT: libatomorph.a has to be compiled using the \033[1;33mmake deprecated\033[0m command.\033[0m\n" - @printf "\033[0mHINT: Use \033[1;33mmake static\033[0m to link statically.\033[0m\n" - @$(MAKE) dynamically_linked -s - -static: - @$(MAKE) statically_linked -s - -statically_linked: $(O_FILES) - @printf "\033[1;33mMaking \033[37m ...." - $(CC) -static -o ./$(NAME) $(O_FILES) $(LIB_FILES) $(L_FLAGS) - @printf "\033[1;32m Statically linked %s DONE!\033[0m\n" $(NAME) - -dynamically_linked: $(O_FILES) - @printf "\033[1;33mMaking \033[37m ...." - $(CC) -o ./$(NAME) $(O_FILES) $(LIB_FILES) $(L_FLAGS) - @printf "\033[1;32m Dynamically linked %s DONE!\033[0m\n" $(NAME) - -$(OBJ_DIR)/%.o: %.cpp - @printf "\033[1m\033[31mCompiling \033[37m....\033[34m %-20s\t\033[33m%6s\033[31m lines\033[0m \n" $*.cpp "`wc -l $*.cpp | cut -f1 -d' '`" - @$(CC) $< $(DEFINES) $(C_FLAGS) -c -o $@ - -clean: - @printf "\033[1;36mCleaning \033[37m ...." - @rm -f $(O_FILES) $(OUT) *~ *.bak *.orig *.rej - @printf "\033[1;37m $(NAME) cleaned!\033[0m\n" diff --git a/demo/allegro5/README b/demo/allegro5/README deleted file mode 100644 index ff7ad76..0000000 --- a/demo/allegro5/README +++ /dev/null @@ -1,15 +0,0 @@ -This AtoMorph-GUI implementation is deprecated because it uses -an older version of the AtoMorph Library. The latter has to be -compiled using the `deprecated` build target. - -AtoMorph-GUI requires Allegro5.1 installed on your system. - -Build instructions: - Run make in this folder. - Edit the Makefile if needed. - -Alternative build instructions: - Use CodeBlocks and open AtoMorph-GUI.cbp. - -If you like this software, please consider making a donation -by sending Bitcoins to 1Erich1YUdkUAp9ynf4Rfw2ug8nBtuUmMu. diff --git a/demo/allegro5/data/fixed_font.tga b/demo/allegro5/data/fixed_font.tga deleted file mode 100755 index bc75123..0000000 Binary files a/demo/allegro5/data/fixed_font.tga and /dev/null differ diff --git a/demo/allegro5/main.cpp b/demo/allegro5/main.cpp deleted file mode 100644 index 8fd7ca9..0000000 --- a/demo/allegro5/main.cpp +++ /dev/null @@ -1,561 +0,0 @@ -/* - * See Copyright Notice in main.h - */ -#include -#include - -#include "main.h" - -const float FPS = 60.0; // Maximum FPS. -const int SCREEN_W = 800; -const int SCREEN_H = 600; -const int MORPH_W = 128; // Width of the morph. Should be at most the width of the input image. -const int MORPH_H = 128; // Height of the morph. Should be at most the height of the input image. -const int ATOMS = 10000; // Number of atoms used in one thread. -const size_t THREAD_N = 5; // Number of threads to use to find a perfect morph. -const size_t SLOWNESS = 50; // How many frames to render per animation cycle. - -size_t morph_time = 0; -int view_frame = 0; -bool pressed_keys[ALLEGRO_KEY_MAX]; - -size_t active_thread = 0; // When render is ON, morph only one thread at a time. -int color_fade = AM_NONE; // Color interpolation method. -int trajectory = AM_NONE; // Atom trajectory interpolation method. -bool median_combining = false; // Noise reduction method. FALSE for averaging. -bool stop_morphing = false; // To halt the morph time temporarily. -bool no_render = false; // When TRUE no blending is done, just atom morphing. - -ALLEGRO_DISPLAY *display = NULL; -ALLEGRO_EVENT_QUEUE *event_queue = NULL; -ALLEGRO_TIMER *timer = NULL; -ALLEGRO_FONT *font = NULL; -ALLEGRO_BITMAP *morph_bmp = NULL; // Holds the final morph as a bitmap. -ALLEGRO_BITMAP *thread_bmp[THREAD_N]; // Holds the results of the morphing threads. - -// Helper function to initially populate the AM_SCENE object according to the provided -// image file. -bool fill_scene(AM_SCENE *scene, size_t frame, const char *png_file) { - std::random_device rd; - std::default_random_engine re(rd()); - std::uniform_real_distribution uniform_dist(0.0, 1.0); - - ALLEGRO_BITMAP * bmp = al_load_bitmap(png_file); - int bmp_w = al_get_bitmap_width(bmp); - int bmp_h = al_get_bitmap_height(bmp); - - al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); - - for (int j=0; jpush_atom(frame, am_create_atom(px,py,r,g,b,a)); - } - } - - al_unlock_bitmap(bmp); - al_destroy_bitmap(bmp); - return true; -} - -int main(int argc, char **argv) { - if (!init(argc, argv)) { - fprintf(stderr, "Failed to initialize!\n"); - return -1; - } - - std::random_device rd; - std::default_random_engine seed_engine(rd()); - std::uniform_int_distribution uniform_dist(1, std::numeric_limits::max()); - - morph_bmp = al_create_bitmap(MORPH_W, MORPH_H); - al_set_target_bitmap(morph_bmp); - al_clear_to_color(al_map_rgba(0,0,0,0)); - - AM_BLENDER blender; // Used to combine the thread results into the final morph. - blender.set_resolution(MORPH_W, MORPH_H); - blender.set_median_combining(median_combining); - blender.start(); - - AM_THREAD scene_thread[THREAD_N]; // Each of these will morph its own version of the animation. - AM_SCENE scene_buf [THREAD_N]; // Temporarily holds the last results of the morphing threads. - AM_IMAGE image_buf [THREAD_N]; // Used to render the final image of the provided scene. - - { - AM_SCENE scene; // Needed temporarily to store the raw input data. - - scene.init(ATOMS, 6); // Reserve 6 frames for this scene. - fill_scene(&scene, 0, "../tests/data/battlelord_1.png"); - fill_scene(&scene, 1, "../tests/data/battlelord_2.png"); - fill_scene(&scene, 2, "../tests/data/battlelord_3.png"); - fill_scene(&scene, 3, "../tests/data/battlelord_4.png"); - fill_scene(&scene, 4, "../tests/data/battlelord_5.png"); - fill_scene(&scene, 5, "../tests/data/battlelord_6.png"); - - for (size_t i=0; ipixel_count(); - for (size_t i=0; iget_xy(i, &x, &y); - img->get_rgba(i, &r, &g, &b, &a); - - al_put_pixel(x, y, al_map_rgba(r,g,b,a)); - } - - // Finally unlock the bitmap: - if (lock) al_unlock_bitmap(to); -} - -void blend_morphs(AM_BLENDER *blender, ALLEGRO_BITMAP *to) { - // Clear old bitmap: - al_set_target_bitmap(to); - al_set_blender(ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); - al_draw_filled_rectangle(0.0, 0.0, MORPH_W, MORPH_H, al_map_rgba(0,0,0,255)); - - // Prepare to render: - al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); - ALLEGRO_LOCKED_REGION * lock = al_lock_bitmap(to,ALLEGRO_PIXEL_FORMAT_ANY,ALLEGRO_LOCK_READWRITE); - if (lock == NULL) return; - - // Put the pixels: - size_t pixels = blender->pixel_count(); - for (size_t i=0; iget_xy(i, &x, &y); - blender->get_rgba(i, &r, &g, &b, &a); - - al_put_pixel(x, y, al_map_rgba(r,g,b,a)); - } - - // Finally unlock the bitmap: - if (lock) al_unlock_bitmap(to); -} - -bool init(int argc, char **argv) { - if (true == (am_get_warning()&AM_WARN_POINTER_SIZE)) { - fprintf(stderr, "Pointer size is insufficiently small.\n"); - } - if (true == (am_get_warning()&AM_WARN_ATOM_SIZE)) { - fprintf(stderr, "Atom size (%lu) is larger than optimal (%lu).\n", - sizeof(AM_ATOM), - sizeof(void *) - ); - } - - if(!al_init()) { - fprintf(stderr, "failed to initialize allegro!\n"); - return false; - } - - if(!al_install_keyboard()) { - fprintf(stderr, "failed to initialize the keyboard!\n"); - return false; - } - - al_install_mouse(); - al_init_image_addon(); - al_init_font_addon(); - al_init_primitives_addon(); - - timer = al_create_timer(1.0 / FPS); - if(!timer) { - fprintf(stderr, "failed to create timer!\n"); - return false; - } - - display = al_create_display(SCREEN_W, SCREEN_H); - if(!display) { - fprintf(stderr, "failed to create display!\n"); - al_destroy_timer(timer); - return false; - } - - al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR|ALLEGRO_MIN_LINEAR); - - font = al_load_font("data/fixed_font.tga", 0, 0); - if (font==NULL) { - fprintf(stderr, "failed to load font!\n"); - al_destroy_display(display); - al_destroy_timer(timer); - return false; - } - - al_set_target_bitmap(al_get_backbuffer(display)); - - event_queue = al_create_event_queue(); - if(!event_queue) { - fprintf(stderr, "failed to create event_queue!\n"); - al_destroy_display(display); - al_destroy_timer(timer); - al_destroy_font(font); - return false; - } - - al_register_event_source(event_queue, al_get_display_event_source(display)); - al_register_event_source(event_queue, al_get_timer_event_source(timer)); - al_register_event_source(event_queue, al_get_keyboard_event_source()); - al_register_event_source(event_queue, al_get_mouse_event_source()); - - al_clear_to_color(al_map_rgb(0,0,0)); - al_draw_textf(font, al_map_rgb(0,255,0), SCREEN_W/2, SCREEN_H/2, - ALLEGRO_ALIGN_CENTRE, - "LOADING..."); - - al_flip_display(); - - al_start_timer(timer); - calculate_fps(); - - return true; -} - -int round_int( double r ) { - return (r > 0.0) ? (r + 0.5) : (r - 0.5); -} - -int calculate_fps() { - static int times = 0; - static double old_time = 0.0; - static double delta_sum = 0.0; - static int old_fps = -1; - - static bool first = true; - if (first) { - first = false; - old_time = al_get_time(); - return -1; - } - - int rec_times = 0; - int max_times = round_int(FPS); - double new_time = al_get_time(); - double delta = new_time - old_time; - delta_sum += delta; - old_time = new_time; - double p = delta_sum * max_times; - rec_times = round_int(p); - - if (times > rec_times) { - return -1; - } - times++; - - int fps = 0; - if (delta_sum >= 1.0 || times>=max_times) { - fps = times; - old_fps = fps; - times=0; - delta_sum=0.0; - } - else { - if (old_fps == -1) fps = times; - else fps = old_fps; - } - - return fps; -} diff --git a/demo/allegro5/main.h b/demo/allegro5/main.h deleted file mode 100644 index 3836b3a..0000000 --- a/demo/allegro5/main.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * AtoMorph Demo - Simple Demo showing what AtoMorph is capable of doing. - * See Copyright Notice at the end of this file. - */ - -#include "../../atomorph.h" - -#include -#include -#include -#include -#include - -extern const float FPS; -extern const int SCREEN_W; -extern const int SCREEN_H; - -extern ALLEGRO_DISPLAY *display ; -extern ALLEGRO_EVENT_QUEUE *event_queue ; -extern ALLEGRO_TIMER *timer ; -extern ALLEGRO_FONT *font ; - -bool init(int argc, char **argv); -int calculate_fps(); -void draw(AM_SCENE *scene, ALLEGRO_BITMAP *to, double t, double weight); -void render_morph(AM_IMAGE *img, ALLEGRO_BITMAP *to); -void blend_morphs(AM_BLENDER *b, ALLEGRO_BITMAP *to); -/* -The MIT License (MIT) - -Copyright (c) 2013-2014 Erich Erstu - -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. -*/ diff --git a/demo/allegro5/obj/.gitignore b/demo/allegro5/obj/.gitignore deleted file mode 100644 index 5e7d273..0000000 --- a/demo/allegro5/obj/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/atomorph.cpp b/src/atomorph.cpp similarity index 100% rename from atomorph.cpp rename to src/atomorph.cpp diff --git a/atomorph.h b/src/atomorph.h similarity index 99% rename from atomorph.h rename to src/atomorph.h index e7cbe05..89905aa 100644 --- a/atomorph.h +++ b/src/atomorph.h @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef ATOMORPH_OPENCV #include diff --git a/color.cpp b/src/color.cpp similarity index 100% rename from color.cpp rename to src/color.cpp diff --git a/color.h b/src/color.h similarity index 97% rename from color.h rename to src/color.h index f235e12..d1b3ddd 100644 --- a/color.h +++ b/src/color.h @@ -1,7 +1,9 @@ /* * See Copyright Notice in atomorph.h */ - + +#include + namespace am { typedef struct color { diff --git a/fluidmodel.cpp b/src/fluidmodel.cpp similarity index 99% rename from fluidmodel.cpp rename to src/fluidmodel.cpp index 4c5a8a0..b6e5b7e 100644 --- a/fluidmodel.cpp +++ b/src/fluidmodel.cpp @@ -162,7 +162,7 @@ FluidModel::~FluidModel() { } -void FluidModel::step(size_t steps_left, double freedom_radius, double morph_time) { +void FluidModel::step(size_t steps_left, double freedom_radius, [[maybe_unused]]double morph_time) { bool drag = false; double mdx = 0.0, mdy = 0.0; diff --git a/fluidmodel.h b/src/fluidmodel.h similarity index 100% rename from fluidmodel.h rename to src/fluidmodel.h diff --git a/morph.cpp b/src/morph.cpp similarity index 100% rename from morph.cpp rename to src/morph.cpp diff --git a/morph.h b/src/morph.h similarity index 100% rename from morph.h rename to src/morph.h diff --git a/perlin.cpp b/src/perlin.cpp similarity index 100% rename from perlin.cpp rename to src/perlin.cpp diff --git a/perlin.h b/src/perlin.h similarity index 100% rename from perlin.h rename to src/perlin.h diff --git a/spline.cpp b/src/spline.cpp similarity index 100% rename from spline.cpp rename to src/spline.cpp diff --git a/spline.h b/src/spline.h similarity index 100% rename from spline.h rename to src/spline.h diff --git a/thread.cpp b/src/thread.cpp similarity index 100% rename from thread.cpp rename to src/thread.cpp diff --git a/thread.h b/src/thread.h similarity index 99% rename from thread.h rename to src/thread.h index a4d48c5..78862f0 100644 --- a/thread.h +++ b/src/thread.h @@ -1,7 +1,8 @@ /* * See Copyright Notice in atomorph.h - */ + */ +#include #include "atomorph.h" namespace am { diff --git a/vec3d.h b/src/vec3d.h similarity index 100% rename from vec3d.h rename to src/vec3d.h