Skip to content

Commit

Permalink
New geoCSG demo
Browse files Browse the repository at this point in the history
Keyboard file nav is now an option in SimpleMeshApplication
  • Loading branch information
BrunoLevy committed Jun 17, 2024
1 parent 40f4640 commit 037bf2a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_subdirectory(geodump)
if(GEOGRAM_WITH_GRAPHICS)
add_subdirectory(vorpaview)
add_subdirectory(geobox)
add_subdirectory(geoCSG)
if(GEOGRAM_WITH_LUA)
add_subdirectory(geocod)
endif()
Expand Down
9 changes: 9 additions & 0 deletions src/bin/geoCSG/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(${PROJECT_SOURCE_DIR}/cmake/opengl.cmake)
set(APP_NAME geoCSG)

aux_source_directories(SOURCES "" .)
add_executable(${APP_NAME} ${SOURCES})
target_link_libraries(${APP_NAME} geogram_gfx geogram ${GLFW_LIBRARIES})
install_runtime_targets(${APP_NAME})

set_target_properties(${APP_NAME} PROPERTIES FOLDER "GEOGRAM/Programs")
94 changes: 94 additions & 0 deletions src/bin/geoCSG/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2000-2022 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ALICE Project-Team nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Contact: Bruno Levy
*
* https://www.inria.fr/fr/bruno-levy
*
* Inria,
* Domaine de Voluceau,
* 78150 Le Chesnay - Rocquencourt
* FRANCE
*
*/

#include <geogram_gfx/gui/simple_mesh_application.h>
#include <geogram/mesh/mesh_CSG.h>

namespace GEO {
class CSGApplication : public SimpleMeshApplication {
public:
CSGApplication(): SimpleMeshApplication("GeoCSG") {
use_text_editor_ = true;
add_key_func("F5", [this](void) { run(); }, "Compile CSG tree");
}

/**
* \copydoc SimpleApplication::load()
*/
bool load(const std::string& filename) override {
geo_argused(filename);
return false;
}

/**
* \copydoc SimpleApplication::save()
*/
bool save(const std::string& filename) override {
geo_argused(filename);
return false;
}

protected:
void run() {
mesh_.clear();

CSGCompiler CSG;
CSGMesh_var result = CSG.compile_string(text_editor_.text());
if(!result.is_null()) {
mesh_.copy(*result);
}

double xyzmin[3];
double xyzmax[3];
get_bbox(mesh_, xyzmin, xyzmax, false);
set_region_of_interest(
xyzmin[0], xyzmin[1], xyzmin[2],
xyzmax[0], xyzmax[1], xyzmax[2]
);
mesh_gfx_.set_mesh(&mesh_);
}
};
}

int main(int argc, char** argv) {
// A SimpleMeshApplication is already a mesh viewer (nothing to do !)
GEO::CSGApplication app;
app.start(argc, argv);
return 0;
}
1 change: 1 addition & 0 deletions src/bin/geobox/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,7 @@ namespace {

int main(int argc, char** argv) {
GeoBoxApplication app;
app.install_key_file_navigation();
app.start(argc, argv);
return 0;
}
2 changes: 1 addition & 1 deletion src/bin/geoshade/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace {
glsl_frame_ = 0;
glsl_start_time_ = Stopwatch::now();
if(text_editor_.text().find("<GLUP/ShaderToy.h>") != std::string::npos) {
glsl_program_ = glupCompileProgram(text_editor_.text().c_str());
glsl_program_ = glupCompileProgram(text_editor_.text().c_str());
} else {
std::string source = (
"//stage GL_FRAGMENT_SHADER\n"
Expand Down
1 change: 1 addition & 0 deletions src/bin/vorpaview/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
int main(int argc, char** argv) {
// A SimpleMeshApplication is already a mesh viewer (nothing to do !)
GEO::SimpleMeshApplication app("GeoView");
app.install_key_file_navigation();
app.start(argc, argv);
return 0;
}
4 changes: 3 additions & 1 deletion src/lib/geogram_gfx/gui/simple_mesh_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ namespace GEO {
add_key_func("t", increment_anim_time_callback, "+ anim speed");
add_key_func("x", decrement_cells_shrink_callback, "- cells shrink");
add_key_func("w", increment_cells_shrink_callback, "+ cells shrink");
}


void SimpleMeshApplication::install_key_file_navigation() {
add_key_func("down", next_file, "load next file");
add_key_func("up", prev_file, "load previous file");

add_key_func("home", first_file, "load first file in directory");
add_key_func("end", last_file, "load last file in directory");
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/geogram_gfx/gui/simple_mesh_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ namespace GEO {
*/
SimpleMeshApplication(const std::string& name);

/**
* \brief Installs key navigation callbacks.
* \details up,down,home,end keys navigate files in
* current directory.
*/
void install_key_file_navigation();

protected:

/**
Expand Down Expand Up @@ -116,6 +123,7 @@ namespace GEO {
return result;
}


protected:

/**
Expand Down

0 comments on commit 037bf2a

Please sign in to comment.