this works now!
This commit is contained in:
@@ -11,6 +11,6 @@ Pos=588,54
|
|||||||
Size=550,680
|
Size=550,680
|
||||||
|
|
||||||
[Window][Gradient settings]
|
[Window][Gradient settings]
|
||||||
Pos=173,209
|
Pos=176,208
|
||||||
Size=721,170
|
Size=721,170
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,14 @@
|
|||||||
#include "../imgui/backends/imgui_impl_opengl3.h"
|
#include "../imgui/backends/imgui_impl_opengl3.h"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
#include <future>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
std::mutex m;
|
||||||
|
std::atomic<bool> isGenerating{false};
|
||||||
|
std::future<void> generationFuture;
|
||||||
|
|
||||||
struct AnimationConfig {
|
struct AnimationConfig {
|
||||||
int width = 1024;
|
int width = 1024;
|
||||||
@@ -179,17 +187,21 @@ bool exportavi(std::vector<frame> frames, AnimationConfig config) {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainLogic(float f, int i1, int i2, int i3, int i4){
|
void mainLogic(const AnimationConfig& config) {
|
||||||
AnimationConfig config = AnimationConfig(i1, i2, i3, f, i4);
|
isGenerating = true;
|
||||||
// std::cout << "g2c2175" << std::endl;
|
try {
|
||||||
|
|
||||||
Grid2 grid = setup(config);
|
Grid2 grid = setup(config);
|
||||||
// std::cout << "g2c2178" << std::endl;
|
|
||||||
Preview(grid);
|
Preview(grid);
|
||||||
std::vector<std::tuple<size_t, Vec2, Vec4>> seeds = pickSeeds(grid,config);
|
std::vector<std::tuple<size_t, Vec2, Vec4>> seeds = pickSeeds(grid,config);
|
||||||
std::vector<frame> frames;
|
std::vector<frame> frames;
|
||||||
|
|
||||||
for (int i = 0; i < config.totalFrames; ++i){
|
for (int i = 0; i < config.totalFrames; ++i){
|
||||||
|
// Check if we should stop the generation
|
||||||
|
if (!isGenerating) {
|
||||||
|
std::cout << "Generation cancelled at frame " << i << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
expandPixel(grid,config,seeds);
|
expandPixel(grid,config,seeds);
|
||||||
|
|
||||||
// Print compression info for this frame
|
// Print compression info for this frame
|
||||||
@@ -198,16 +210,32 @@ void mainLogic(float f, int i1, int i2, int i3, int i4){
|
|||||||
std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl;
|
std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl;
|
||||||
bgrframe = grid.getGridAsFrame(frame::colormap::BGR);
|
bgrframe = grid.getGridAsFrame(frame::colormap::BGR);
|
||||||
bgrframe.printCompressionStats();
|
bgrframe.printCompressionStats();
|
||||||
//(bgrframe, i + 1);
|
|
||||||
frames.push_back(bgrframe);
|
frames.push_back(bgrframe);
|
||||||
//bgrframe.decompress();
|
//bgrframe.decompress();
|
||||||
//BMPWriter::saveBMP(std::format("output/grayscalesource.{}.bmp", i), bgrframe);
|
//BMPWriter::saveBMP(std::format("output/grayscalesource.{}.bmp", i), bgrframe);
|
||||||
bgrframe.compressFrameLZ78();
|
bgrframe.compressFrameLZ78();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
exportavi(frames,config);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "errored at: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
isGenerating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
exportavi(frames,config);
|
// Function to cancel ongoing generation
|
||||||
|
void cancelGeneration() {
|
||||||
|
if (isGenerating) {
|
||||||
|
isGenerating = false;
|
||||||
|
// Wait for the thread to finish (with timeout to avoid hanging)
|
||||||
|
if (generationFuture.valid()) {
|
||||||
|
auto status = generationFuture.wait_for(std::chrono::milliseconds(100));
|
||||||
|
if (status != std::future_status::ready) {
|
||||||
|
std::cout << "Waiting for generation thread to finish..." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glfw_error_callback(int error, const char* description)
|
static void glfw_error_callback(int error, const char* description)
|
||||||
@@ -287,8 +315,13 @@ int main() {
|
|||||||
bool show_demo_window = true;
|
bool show_demo_window = true;
|
||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
static float f = 30.0f;
|
||||||
|
static int i1 = 1024;
|
||||||
|
static int i2 = 1024;
|
||||||
|
static int i3 = 480;
|
||||||
|
static int i4 = 8;
|
||||||
|
|
||||||
|
std::future<void> mainlogicthread;
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
@@ -299,27 +332,37 @@ int main() {
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
static float f = 30.0f;
|
|
||||||
static int i1 = 1024;
|
|
||||||
static int i2 = 1024;
|
|
||||||
static int i3 = 480;
|
|
||||||
static int i4 = 8;
|
|
||||||
|
|
||||||
ImGui::Begin("Gradient settings"); // Create a window called "Hello, world!" and append into it.
|
ImGui::Begin("Gradient settings");
|
||||||
|
|
||||||
//ImGui::Text(""); // Display some text (you can use a format strings too)
|
ImGui::SliderFloat("fps", &f, 20.0f, 60.0f);
|
||||||
//ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
|
||||||
//ImGui::Checkbox("Another Window", &show_another_window);
|
|
||||||
ImGui::SliderFloat("fps", &f, 20.0f, 60.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
|
||||||
ImGui::SliderInt("width", &i1, 256, 4096);
|
ImGui::SliderInt("width", &i1, 256, 4096);
|
||||||
ImGui::SliderInt("height", &i2, 256, 4096);
|
ImGui::SliderInt("height", &i2, 256, 4096);
|
||||||
ImGui::SliderInt("framecount", &i3, 10, 5000);
|
ImGui::SliderInt("framecount", &i3, 10, 5000);
|
||||||
ImGui::SliderInt("numSeeds", &i4, 0, 10);
|
ImGui::SliderInt("numSeeds", &i4, 0, 10);
|
||||||
|
|
||||||
if (ImGui::Button("Generate Animation")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
// Disable button while generating
|
||||||
mainLogic(f,i1,i2,i3,i4);
|
if (isGenerating) {
|
||||||
ImGui::SameLine();
|
ImGui::BeginDisabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::Button("Generate Animation")) {
|
||||||
|
AnimationConfig config = AnimationConfig(i1, i2, i3, f, i4);
|
||||||
|
mainlogicthread = std::async(std::launch::async, mainLogic, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isGenerating) {
|
||||||
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
// Show cancel button and progress indicator
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Cancel")) {
|
||||||
|
cancelGeneration();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional: Show a progress indicator
|
||||||
|
ImGui::Text("Generating...");
|
||||||
|
}
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
@@ -334,8 +377,16 @@ int main() {
|
|||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
//mainlogicthread.join();
|
||||||
}
|
}
|
||||||
//ImGui::End();
|
cancelGeneration();
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
glfwDestroyWindow(window);
|
||||||
|
glfwTerminate();
|
||||||
FunctionTimer::printStats(FunctionTimer::Mode::ENHANCED);
|
FunctionTimer::printStats(FunctionTimer::Mode::ENHANCED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user