Skip to content

Commit

Permalink
Merge branch 'openscad:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gsohler authored Mar 4, 2025
2 parents 192cd25 + 0b71f59 commit 7c0e669
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 285 deletions.
14 changes: 6 additions & 8 deletions cmake/Modules/FindNettle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ find_library(Nettle_LIBRARY
PATHS ${PC_Nettle_LIBRARY_DIRS}
)

# Extract version information from the header file
if(Nettle_INCLUDE_DIR)
# This file only exists in nettle>=3.0
if(EXISTS ${Nettle_INCLUDE_DIR}/nettle/version.h)
if(PC_Nettle_VERSION)
set(Nettle_VERSION ${PC_Nettle_VERSION})
elseif(EXISTS ${Nettle_INCLUDE_DIR}/nettle/version.h)
# Extract version information from the header file
# This file only exists in nettle>=3.0
file(STRINGS ${Nettle_INCLUDE_DIR}/nettle/version.h _ver_major_line
REGEX "^#define NETTLE_VERSION_MAJOR *[0-9]+"
LIMIT_COUNT 1)
Expand All @@ -100,11 +102,7 @@ if(Nettle_INCLUDE_DIR)
unset(_ver_major_line)
unset(_ver_minor_line)
else()
if(PC_Nettle_VERSION)
set(Nettle_VERSION ${PC_Nettle_VERSION})
else()
set(Nettle_VERSION "1.0")
endif()
set(Nettle_VERSION "1.0")
endif()
endif()

Expand Down
17 changes: 9 additions & 8 deletions src/glview/CsgInfo.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once

#include <memory>
#include <vector>

#include "core/CSGNode.h"
#include "core/CSGTreeEvaluator.h"
#include "core/Tree.h"
#include "geometry/GeometryEvaluator.h"
#include "core/CSGTreeEvaluator.h"
#include "glview/preview/CSGTreeNormalizer.h"
#include "glview/RenderSettings.h"
#include "utils/printutils.h"

#include <memory>
#include <vector>

/*
Small helper class for compiling and normalizing node trees into CSG products
Expand All @@ -26,16 +27,16 @@ class CsgInfo
auto& root_node = tree.root();
GeometryEvaluator geomevaluator(tree);
CSGTreeEvaluator evaluator(tree, &geomevaluator);
std::shared_ptr<CSGNode> csgRoot = evaluator.buildCSGTree(*root_node);
const std::shared_ptr<CSGNode> csgRoot = evaluator.buildCSGTree(*root_node);
std::vector<std::shared_ptr<CSGNode>> highlightNodes = evaluator.getHighlightNodes();
std::vector<std::shared_ptr<CSGNode>> backgroundNodes = evaluator.getBackgroundNodes();

LOG("Compiling design (CSG Products normalization)...");
CSGTreeNormalizer normalizer(RenderSettings::inst()->openCSGTermLimit);
if (csgRoot) {
std::shared_ptr<CSGNode> normalizedRoot = normalizer.normalize(csgRoot);
const std::shared_ptr<CSGNode> normalizedRoot = normalizer.normalize(csgRoot);
if (normalizedRoot) {
this->root_products.reset(new CSGProducts());
this->root_products = std::make_shared<CSGProducts>();
this->root_products->import(normalizedRoot);
LOG("Normalized CSG tree has %1$d elements", int(this->root_products->size()));
} else {
Expand All @@ -46,7 +47,7 @@ class CsgInfo

if (highlightNodes.size() > 0) {
LOG("Compiling highlights (%1$i CSG Trees)...", highlightNodes.size());
this->highlights_products.reset(new CSGProducts());
this->highlights_products = std::make_shared<CSGProducts>();
for (auto& highlightNode : highlightNodes) {
highlightNode = normalizer.normalize(highlightNode);
this->highlights_products->import(highlightNode);
Expand All @@ -55,7 +56,7 @@ class CsgInfo

if (backgroundNodes.size() > 0) {
LOG("Compiling background (%1$i CSG Trees)...", backgroundNodes.size());
this->background_products.reset(new CSGProducts());
this->background_products = std::make_shared<CSGProducts>();
for (auto& backgroundNode : backgroundNodes) {
backgroundNode = normalizer.normalize(backgroundNode);
this->background_products->import(backgroundNode);
Expand Down
52 changes: 24 additions & 28 deletions src/glview/NULLGL.cc
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
#include "glview/GLView.h"

#include <cassert>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <cstddef>
#include <string>
#include <vector>

GLView::GLView() {}
GLView::~GLView() {}
void GLView::setRenderer(std::shared_ptr<Renderer>) {}
void GLView::initializeGL() {}
void GLView::resizeGL(int w, int h) {}
void GLView::setCamera(const Camera& cam) {assert(false && "not implemented");}
void GLView::paintGL() {}
void GLView::showSmallaxes(const Color4f& col) {}
void GLView::showAxes(const Color4f& col) {}
void GLView::showCrosshairs(const Color4f& col) {}
void GLView::setColorScheme(const ColorScheme& cs){assert(false && "not implemented");}
void GLView::setColorScheme(const std::string& cs) {assert(false && "not implemented");}

#include "geometry/linalg.h"
#include "glview/Camera.h"
#include "glview/ColorMap.h"
#include "glview/Renderer.h"
#include "glview/fbo.h"
#include "glview/GLView.h"
#include "glview/OpenGLContext.h"
#include "glview/system-gl.h"

double gl_version() { return -1; }
bool FBO::resize(size_t, size_t) { return false; }
FBO::FBO(int, int, bool ) {}
GLuint FBO::bind() { return 0; }
GLView::~GLView() = default;
GLView::GLView() = default;
std::string gl_dump() { return {"GL Renderer: NULLGL\n"}; }
std::string gl_extensions_dump() { return {"NULLGL Extensions"}; }
bool report_glerror(const char *function) { return false; }

#include "glview/OpenGLContext.h"
std::unique_ptr<FBO> createFBO(int, int) {return nullptr;}
std::vector<uint8_t> OpenGLContext::getFramebuffer() const { return {}; }

#include "glview/fbo.h"

FBO::FBO(int, int, bool ) {}
bool FBO::resize(size_t, size_t) { return false; }
GLuint FBO::bind() { return 0; }
void FBO::unbind() {}
void FBO::destroy() {}
std::unique_ptr<FBO> createFBO(int, int) {return nullptr;}
void FBO::unbind() {}
void GLView::initializeGL() {}
void GLView::paintGL() {}
void GLView::resizeGL(int w, int h) {}
void GLView::setCamera(const Camera& /*cam*/) {assert(false && "not implemented");}
void GLView::setColorScheme(const ColorScheme& /*cs*/){assert(false && "not implemented");}
void GLView::setColorScheme(const std::string& /*cs*/) {assert(false && "not implemented");}
void GLView::setRenderer(std::shared_ptr<Renderer>) {}
void GLView::showAxes(const Color4f& col) {}
void GLView::showCrosshairs(const Color4f& col) {}
void GLView::showSmallaxes(const Color4f& col) {}
5 changes: 4 additions & 1 deletion src/glview/OffscreenContextNULL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include <memory>
#include <string>

#include "glview/OffscreenContext.h"

class OffscreenContextNULL : public OffscreenContext {
public:
OffscreenContextNULL() : OffscreenContext(0, 0) {}
~OffscreenContextNULL() {}
~OffscreenContextNULL() override = default;

std::string getInfo() const override {
return "GL context creator: NULLGL";
}
Expand Down
43 changes: 26 additions & 17 deletions src/glview/cgal/CGALRenderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,40 @@
#include <limits>
#include <utility>
#include <memory>
#include <cstddef>
#include <vector>
#include <cmath>

#ifdef _MSC_VER
// Boost conflicts with MPFR under MSVC (google it)
#include <mpfr.h>
#endif

#include "core/Selection.h"
#include "geometry/cgal/cgal.h"
#include "geometry/Geometry.h"
#include "geometry/GeometryUtils.h"
#include "geometry/linalg.h"
#include "Feature.h"
#include "geometry/PolySet.h"
#include "geometry/PolySetUtils.h"
#include "glview/cgal/CGALRenderUtils.h"
#include "glview/ColorMap.h"
#include "glview/Renderer.h"
#include "glview/ShaderUtils.h"
#include "glview/system-gl.h"
#include "glview/VBOBuilder.h"
#include "glview/VertexState.h"
#include "utils/printutils.h"

#include "glview/cgal/CGALRenderUtils.h"
#ifdef ENABLE_CGAL
#include <CGAL/Bbox_3.h>
#include "CGAL/OGL_helper.h"
#include "glview/cgal/VBOPolyhedron.h"
#endif
#ifdef ENABLE_MANIFOLD
#include "geometry/manifold/ManifoldGeometry.h"
#endif

#include <cstddef>
#include <vector>

// #include "gui/Preferences.h"

CGALRenderer::CGALRenderer(const std::shared_ptr<const class Geometry> &geom) {
this->addGeometry(geom);
Expand Down Expand Up @@ -257,9 +266,9 @@ void CGALRenderer::draw(bool showedges, const ShaderUtils::ShaderInfo * /*shader
PRINTD("draw()");
// grab current state to restore after
GLfloat current_point_size, current_line_width;
GLboolean origVertexArrayState = glIsEnabled(GL_VERTEX_ARRAY);
GLboolean origNormalArrayState = glIsEnabled(GL_NORMAL_ARRAY);
GLboolean origColorArrayState = glIsEnabled(GL_COLOR_ARRAY);
const GLboolean origVertexArrayState = glIsEnabled(GL_VERTEX_ARRAY);
const GLboolean origNormalArrayState = glIsEnabled(GL_NORMAL_ARRAY);
const GLboolean origColorArrayState = glIsEnabled(GL_COLOR_ARRAY);

GL_CHECKD(glGetFloatv(GL_POINT_SIZE, &current_point_size));
GL_CHECKD(glGetFloatv(GL_LINE_WIDTH, &current_line_width));
Expand Down Expand Up @@ -298,7 +307,7 @@ BoundingBox CGALRenderer::getBoundingBox() const {

#ifdef ENABLE_CGAL
for (const auto &p : this->getPolyhedrons()) {
CGAL::Bbox_3 cgalbbox = p->bbox();
const CGAL::Bbox_3 cgalbbox = p->bbox();
bbox.extend(BoundingBox(
Vector3d(cgalbbox.xmin(), cgalbbox.ymin(), cgalbbox.zmin()),
Vector3d(cgalbbox.xmax(), cgalbbox.ymax(), cgalbbox.zmax())));
Expand All @@ -314,8 +323,8 @@ BoundingBox CGALRenderer::getBoundingBox() const {
}

std::vector<SelectedObject>
CGALRenderer::findModelObject(Vector3d near_pt, Vector3d far_pt, int mouse_x,
int mouse_y, double tolerance) {
CGALRenderer::findModelObject(Vector3d near_pt, Vector3d far_pt, int /*mouse_x*/,
int /*mouse_y*/, double tolerance) {
double dist_near;
double dist_nearest = std::numeric_limits<double>::max();
Vector3d pt1_nearest;
Expand All @@ -337,7 +346,7 @@ CGALRenderer::findModelObject(Vector3d near_pt, Vector3d far_pt, int mouse_x,
find_nearest_point(ps->vertices);
}
if (dist_nearest < std::numeric_limits<double>::max()) {
SelectedObject obj = {
const SelectedObject obj = {
.type = SelectionType::SELECTION_POINT,
.p1 = pt1_nearest
};
Expand All @@ -347,10 +356,10 @@ CGALRenderer::findModelObject(Vector3d near_pt, Vector3d far_pt, int mouse_x,
const auto find_nearest_line = [&](const std::vector<Vector3d> &vertices, const PolygonIndices& indices) {
for (const auto &poly : indices) {
for (int i = 0; i < poly.size(); i++) {
int ind1 = poly[i];
int ind2 = poly[(i + 1) % poly.size()];
const int ind1 = poly[i];
const int ind2 = poly[(i + 1) % poly.size()];
double dist_lat;
double dist_norm = fabs(calculateLineLineDistance(
const double dist_norm = std::fabs(calculateLineLineDistance(
vertices[ind1], vertices[ind2], near_pt, far_pt, dist_lat));
if (dist_lat >= 0 && dist_lat <= 1 && dist_norm < tolerance) {
dist_nearest = dist_lat;
Expand All @@ -367,7 +376,7 @@ CGALRenderer::findModelObject(Vector3d near_pt, Vector3d far_pt, int mouse_x,
find_nearest_line(ps->vertices, ps->indices);
}
if (dist_nearest < std::numeric_limits<double>::max()) {
SelectedObject obj = {
const SelectedObject obj = {
.type = SelectionType::SELECTION_LINE,
.p1 = pt1_nearest,
.p2 = pt2_nearest,
Expand Down
4 changes: 4 additions & 0 deletions src/glview/cgal/CGALRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "geometry/Geometry.h"
#include "geometry/linalg.h"
#include "geometry/Polygon2d.h"
#include "glview/ShaderUtils.h"
#include "glview/ColorMap.h"
#include "core/Selection.h"
#include "glview/VertexState.h"
#ifdef ENABLE_CGAL
#include "geometry/cgal/CGAL_Nef_polyhedron.h"
#endif
Expand Down
33 changes: 17 additions & 16 deletions src/glview/cgal/VBOPolyhedron.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@

#pragma once

#include "CGAL/OGL_helper.h"
#include <cassert>
#include <utility>
#include <memory>
#include <cstdlib>
#include <vector>

#include <CGAL/IO/Color.h>

#include "CGAL/OGL_helper.h"
#include "glview/ColorMap.h"
#include "glview/VertexState.h"
#include "glview/system-gl.h"
#include "glview/VBOBuilder.h"
#include "glview/ColorMap.h"

#include <cassert>
#include <utility>
#include <memory>
#include <cstdlib>
#include <vector>
#include "utils/printutils.h"

class VBOPolyhedron : public CGAL::OGL::Polyhedron
{
Expand All @@ -63,8 +65,7 @@ class VBOPolyhedron : public CGAL::OGL::Polyhedron
setColor(CGALColorIndex::UNMARKED_EDGE_COLOR, ColorMap::getColor(cs, RenderColor::CGAL_EDGE_FRONT_COLOR));
}

~VBOPolyhedron() override {
}
~VBOPolyhedron() override = default;

void draw(Vertex_iterator v, VBOBuilder& vbo_builder) const {
PRINTD("draw(Vertex_iterator)");
Expand All @@ -79,9 +80,9 @@ class VBOPolyhedron : public CGAL::OGL::Polyhedron
void draw(Edge_iterator e, VBOBuilder& vbo_builder) const {
PRINTD("draw(Edge_iterator)");

Double_point p = e->source(), q = e->target();
CGAL::Color c = getEdgeColor(e);
Color4f color(c.red(), c.green(), c.blue());
const Double_point p = e->source(), q = e->target();
const CGAL::Color c = getEdgeColor(e);
const Color4f color(c.red(), c.green(), c.blue());

vbo_builder.createVertex({Vector3d(p.x(), p.y(), p.z())},
{},
Expand Down Expand Up @@ -230,7 +231,7 @@ class VBOPolyhedron : public CGAL::OGL::Polyhedron
size_t last_size = 0;
size_t elements_offset = 0;

size_t num_vertices = vertices_.size() + edges_.size() * 2, elements_size = 0;
const size_t num_vertices = vertices_.size() + edges_.size() * 2, elements_size = 0;
points_edges_builder.allocateBuffers(num_vertices);

// Points
Expand Down Expand Up @@ -338,9 +339,9 @@ class VBOPolyhedron : public CGAL::OGL::Polyhedron
PRINTDB("VBO draw(showedges = %d)", showedges);
// grab current state to restore after
GLfloat current_point_size, current_line_width;
GLboolean origVertexArrayState = glIsEnabled(GL_VERTEX_ARRAY);
GLboolean origNormalArrayState = glIsEnabled(GL_NORMAL_ARRAY);
GLboolean origColorArrayState = glIsEnabled(GL_COLOR_ARRAY);
const GLboolean origVertexArrayState = glIsEnabled(GL_VERTEX_ARRAY);
const GLboolean origNormalArrayState = glIsEnabled(GL_NORMAL_ARRAY);
const GLboolean origColorArrayState = glIsEnabled(GL_COLOR_ARRAY);

GL_CHECKD(glGetFloatv(GL_POINT_SIZE, &current_point_size));
GL_CHECKD(glGetFloatv(GL_LINE_WIDTH, &current_line_width));
Expand Down
Loading

0 comments on commit 7c0e669

Please sign in to comment.