summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/CMakeLists.txt17
-rw-r--r--tests/cgalpngtest.cc224
2 files changed, 240 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 088871c..533517a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -147,6 +147,18 @@ set_target_properties(cgaltest PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CX
target_link_libraries(cgaltest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${OPENGL_LIBRARY})
#
+# cgalpngtest
+#
+add_executable(cgalpngtest cgalpngtest.cc OffscreenView.cc OffscreenContext.mm
+ ../src/CGALRenderer.cc ../src/CGAL_Nef_polyhedron.cc
+ ../src/CSGTermEvaluator.cc ../src/CGALEvaluator.cc
+ ../src/PolySetCGALEvaluator.cc ../src/qhash.cc
+ ../src/CGAL_Nef_polyhedron_DxfData.cc ../src/cgaladv_minkowski2.cc
+ ${COMMON_SOURCES})
+set_target_properties(cgalpngtest PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
+target_link_libraries(cgalpngtest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${GLEW_LIBRARY} ${COCOA_LIBRARY} ${OPENGL_LIBRARY})
+
+#
# opencsgtest
#
add_executable(opencsgtest opencsgtest.cc OffscreenView.cc OffscreenContext.mm
@@ -186,9 +198,12 @@ add_cmdline_test(csgtexttest txt ${MINIMAL_FILES})
add_cmdline_test(csgtermtest txt ${MINIMAL_FILES})
# Add cgaltest tests to CTest
+add_cmdline_test(cgaltest stl ${CGALTEST_FILES})
+
+# Add cgalpngtest tests to CTest
LIST(APPEND CGALTEST_FILES ${FEATURES_FILES})
LIST(APPEND CGALTEST_FILES ${CMAKE_SOURCE_DIR}/../examples/example001.scad)
-add_cmdline_test(cgaltest stl ${CGALTEST_FILES})
+add_cmdline_test(cgaltest stl ${CGALPNGTEST_FILES})
# Add opencsg tests to CTest
LIST(APPEND OPENCSGTEST_FILES ${CGALTEST_FILES})
diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc
new file mode 100644
index 0000000..e864090
--- /dev/null
+++ b/tests/cgalpngtest.cc
@@ -0,0 +1,224 @@
+/*
+ * OpenSCAD (www.openscad.at)
+ * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * As a special exception, you have permission to link this program
+ * with the CGAL library and distribute executables, as long as you
+ * follow the requirements of the GNU GPL in regard to all of the
+ * software in the executable aside from CGAL.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "myqhash.h"
+#include "openscad.h"
+#include "node.h"
+#include "module.h"
+#include "polyset.h"
+#include "context.h"
+#include "value.h"
+#include "export.h"
+#include "builtin.h"
+#include "Tree.h"
+#include "CGAL_Nef_polyhedron.h"
+#include "CGALEvaluator.h"
+#include "PolySetCGALEvaluator.h"
+#include "CGALRenderer.h"
+#include "OffscreenView.h"
+
+#include <QApplication>
+#include <QFile>
+#include <QDir>
+#include <QSet>
+#include <QTextStream>
+#include <getopt.h>
+#include <iostream>
+#include <assert.h>
+
+QString commandline_commands;
+const char *make_command = NULL;
+QSet<QString> dependencies;
+QString currentdir;
+QString examplesdir;
+QString librarydir;
+
+using std::string;
+
+void handle_dep(QString filename)
+{
+ if (filename.startsWith("/"))
+ dependencies.insert(filename);
+ else
+ dependencies.insert(QDir::currentPath() + QString("/") + filename);
+ if (!QFile(filename).exists() && make_command) {
+ char buffer[4096];
+ snprintf(buffer, 4096, "%s '%s'", make_command, filename.replace("'", "'\\''").toUtf8().data());
+ system(buffer); // FIXME: Handle error
+ }
+}
+
+// FIXME: enforce some maximum cache size (old version had 100K vertices as limit)
+QHash<std::string, CGAL_Nef_polyhedron> cache;
+
+void cgalTree(Tree &tree)
+{
+ assert(tree.root());
+
+ CGALEvaluator evaluator(cache, tree);
+ Traverser evaluate(evaluator, *tree.root(), Traverser::PRE_AND_POSTFIX);
+ evaluate.execute();
+}
+
+struct CsgInfo
+{
+ OffscreenView *glview;
+};
+
+int main(int argc, char **argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <file.scad>\n", argv[0]);
+ exit(1);
+ }
+
+ const char *filename = argv[1];
+
+ initialize_builtin_functions();
+ initialize_builtin_modules();
+
+ QApplication app(argc, argv, false);
+ QDir original_path = QDir::current();
+
+ currentdir = QDir::currentPath();
+
+ QDir libdir(QApplication::instance()->applicationDirPath());
+#ifdef Q_WS_MAC
+ libdir.cd("../Resources"); // Libraries can be bundled
+ if (!libdir.exists("libraries")) libdir.cd("../../..");
+#elif defined(Q_OS_UNIX)
+ if (libdir.cd("../share/openscad/libraries")) {
+ librarydir = libdir.path();
+ } else
+ if (libdir.cd("../../share/openscad/libraries")) {
+ librarydir = libdir.path();
+ } else
+ if (libdir.cd("../../libraries")) {
+ librarydir = libdir.path();
+ } else
+#endif
+ if (libdir.cd("libraries")) {
+ librarydir = libdir.path();
+ }
+
+ Context root_ctx;
+ root_ctx.functions_p = &builtin_functions;
+ root_ctx.modules_p = &builtin_modules;
+ root_ctx.set_variable("$fn", Value(0.0));
+ root_ctx.set_variable("$fs", Value(1.0));
+ root_ctx.set_variable("$fa", Value(12.0));
+ root_ctx.set_variable("$t", Value(0.0));
+
+ Value zero3;
+ zero3.type = Value::VECTOR;
+ zero3.append(new Value(0.0));
+ zero3.append(new Value(0.0));
+ zero3.append(new Value(0.0));
+ root_ctx.set_variable("$vpt", zero3);
+ root_ctx.set_variable("$vpr", zero3);
+
+
+ AbstractModule *root_module;
+ ModuleInstantiation root_inst;
+ AbstractNode *root_node;
+
+ QFileInfo fileInfo(filename);
+ handle_dep(filename);
+ FILE *fp = fopen(filename, "rt");
+ if (!fp) {
+ fprintf(stderr, "Can't open input file `%s'!\n", filename);
+ exit(1);
+ } else {
+ QString text;
+ char buffer[513];
+ int ret;
+ while ((ret = fread(buffer, 1, 512, fp)) > 0) {
+ buffer[ret] = 0;
+ text += buffer;
+ }
+ fclose(fp);
+ root_module = parse((text+commandline_commands).toAscii().data(), fileInfo.absolutePath().toLocal8Bit(), false);
+ if (!root_module) {
+ exit(1);
+ }
+ }
+
+ QDir::setCurrent(fileInfo.absolutePath());
+
+ AbstractNode::resetIndexCounter();
+ root_node = root_module->evaluate(&root_ctx, &root_inst);
+
+ Tree tree(root_node);
+
+ CsgInfo csgInfo;
+ QHash<std::string, CGAL_Nef_polyhedron> cache;
+ CGALEvaluator cgalevaluator(cache, tree);
+ PolySetCGALEvaluator psevaluator(cgalevaluator);
+
+ CGAL_Nef_polyhedron N = cgalevaluator.evaluateCGALMesh(*root_node);
+
+ QDir::setCurrent(original_path.absolutePath());
+
+ csgInfo.glview = new OffscreenView(512,512);
+// FIXME: Get bbox from CGAL mesh BoundingBox bbox = csgInfo.root_chain->getBoundingBox();
+ BoundingBox bbox;
+
+ Vector3d center = (bbox.min() + bbox.max()) / 2;
+ double radius = (bbox.max() - bbox.min()).norm() / 2;
+
+
+ Vector3d cameradir(1, 1, -0.5);
+ Vector3d camerapos = center - radius*1.5*cameradir;
+ csgInfo.glview->setCamera(camerapos, center);
+
+ glewInit();
+#ifdef DEBUG
+ cout << "GLEW version " << glewGetString(GLEW_VERSION) << "\n";
+ cout << (const char *)glGetString(GL_RENDERER) << "(" << (const char *)glGetString(GL_VENDOR) << ")\n"
+ << "OpenGL version " << (const char *)glGetString(GL_VERSION) << "\n";
+ cout << "Extensions: " << (const char *)glGetString(GL_EXTENSIONS) << "\n";
+
+
+ if (GLEW_ARB_framebuffer_object) {
+ cout << "ARB_FBO supported\n";
+ }
+ if (GLEW_EXT_framebuffer_object) {
+ cout << "EXT_FBO supported\n";
+ }
+ if (GLEW_EXT_packed_depth_stencil) {
+ cout << "EXT_packed_depth_stencil\n";
+ }
+#endif
+
+ CGALRenderer cgalRenderer(N);
+ csgInfo.glview->setRenderer(&cgalRenderer);
+ csgInfo.glview->paintGL();
+ csgInfo.glview->save("/dev/stdout");
+
+ destroy_builtin_functions();
+ destroy_builtin_modules();
+
+ return 0;
+}
contact: Jan Huwald // Impressum