summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-02-25 01:04:50 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-02-25 01:04:50 (GMT)
commit8738cdc03451803014ca84f8614bdff1ff393ca9 (patch)
treedb932377ea156d9caf5f47fec3b7bb9466273fe9
parenteb2c0d38f22f781cf59ca7078bfec260148ca584 (diff)
split out axes functions. begin to split out opencsg pre-rendering
-rw-r--r--src/GLView.cc117
-rw-r--r--src/GLView.h16
-rw-r--r--src/OffscreenView.cc36
-rw-r--r--src/QGLView.cc114
-rw-r--r--src/export_png.cc7
-rw-r--r--tests/csgtestcore.cc118
6 files changed, 197 insertions, 211 deletions
diff --git a/src/GLView.cc b/src/GLView.cc
index e92c2dd..0507492 100644
--- a/src/GLView.cc
+++ b/src/GLView.cc
@@ -3,6 +3,9 @@
#include "printutils.h"
#include "stdio.h"
+#include "linalg.h"
+#include "rendersettings.h"
+
#ifdef _WIN32
#include <GL/wglew.h>
#elif !defined(__APPLE__)
@@ -78,6 +81,7 @@ void GLView::setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center
{
this->camera_eye = pos;
this->camera_center = center;
+ viewer_distance = 10*3*(this->camera_center - this->camera_eye).norm();
}
void GLView::setupPerspective()
@@ -275,6 +279,119 @@ void GLView::initializeGL()
#endif
}
+void GLView::showSmallaxes()
+{
+ // Fixme - this modifies the camera and doesnt work in 'non-gimbal' camera mode
+
+ // Small axis cross in the lower left corner
+ glDepthFunc(GL_ALWAYS);
+
+ GLView::setupGimbalOrtho(1000,true);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glRotated(object_rot.x(), 1.0, 0.0, 0.0);
+ glRotated(object_rot.y(), 0.0, 1.0, 0.0);
+ glRotated(object_rot.z(), 0.0, 0.0, 1.0);
+
+ glLineWidth(1);
+ glBegin(GL_LINES);
+ glColor3d(1.0, 0.0, 0.0);
+ glVertex3d(0, 0, 0); glVertex3d(10, 0, 0);
+ glColor3d(0.0, 1.0, 0.0);
+ glVertex3d(0, 0, 0); glVertex3d(0, 10, 0);
+ glColor3d(0.0, 0.0, 1.0);
+ glVertex3d(0, 0, 0); glVertex3d(0, 0, 10);
+ glEnd();
+
+ GLdouble mat_model[16];
+ glGetDoublev(GL_MODELVIEW_MATRIX, mat_model);
+
+ GLdouble mat_proj[16];
+ glGetDoublev(GL_PROJECTION_MATRIX, mat_proj);
+
+ GLint viewport[4];
+ glGetIntegerv(GL_VIEWPORT, viewport);
+
+ GLdouble xlabel_x, xlabel_y, xlabel_z;
+ gluProject(12, 0, 0, mat_model, mat_proj, viewport, &xlabel_x, &xlabel_y, &xlabel_z);
+ xlabel_x = round(xlabel_x); xlabel_y = round(xlabel_y);
+
+ GLdouble ylabel_x, ylabel_y, ylabel_z;
+ gluProject(0, 12, 0, mat_model, mat_proj, viewport, &ylabel_x, &ylabel_y, &ylabel_z);
+ ylabel_x = round(ylabel_x); ylabel_y = round(ylabel_y);
+
+ GLdouble zlabel_x, zlabel_y, zlabel_z;
+ gluProject(0, 0, 12, mat_model, mat_proj, viewport, &zlabel_x, &zlabel_y, &zlabel_z);
+ zlabel_x = round(zlabel_x); zlabel_y = round(zlabel_y);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glTranslated(-1, -1, 0);
+ glScaled(2.0/viewport[2], 2.0/viewport[3], 1);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ // FIXME: This was an attempt to keep contrast with background, but is suboptimal
+ // (e.g. nearly invisible against a gray background).
+// int r,g,b;
+// r=g=b=0;
+// bgcol.getRgb(&r, &g, &b);
+// glColor3f((255.0f-r)/255.0f, (255.0f-g)/255.0f, (255.0f-b)/255.0f);
+ glColor3f(0.0f, 0.0f, 0.0f);
+ glBegin(GL_LINES);
+ // X Label
+ glVertex3d(xlabel_x-3, xlabel_y-3, 0); glVertex3d(xlabel_x+3, xlabel_y+3, 0);
+ glVertex3d(xlabel_x-3, xlabel_y+3, 0); glVertex3d(xlabel_x+3, xlabel_y-3, 0);
+ // Y Label
+ glVertex3d(ylabel_x-3, ylabel_y-3, 0); glVertex3d(ylabel_x+3, ylabel_y+3, 0);
+ glVertex3d(ylabel_x-3, ylabel_y+3, 0); glVertex3d(ylabel_x, ylabel_y, 0);
+ // Z Label
+ glVertex3d(zlabel_x-3, zlabel_y-3, 0); glVertex3d(zlabel_x+3, zlabel_y-3, 0);
+ glVertex3d(zlabel_x-3, zlabel_y+3, 0); glVertex3d(zlabel_x+3, zlabel_y+3, 0);
+ glVertex3d(zlabel_x-3, zlabel_y-3, 0); glVertex3d(zlabel_x+3, zlabel_y+3, 0);
+ glEnd();
+
+ //Restore perspective for next paint
+ if(!orthomode)
+ GLView::setupGimbalPerspective();
+}
+
+void GLView::showAxes()
+{
+ // Large gray axis cross inline with the model
+ // FIXME: This is always gray - adjust color to keep contrast with background
+ glLineWidth(1);
+ glColor3d(0.5, 0.5, 0.5);
+ glBegin(GL_LINES);
+ double l = viewer_distance/10;
+ glVertex3d(-l, 0, 0);
+ glVertex3d(+l, 0, 0);
+ glVertex3d(0, -l, 0);
+ glVertex3d(0, +l, 0);
+ glVertex3d(0, 0, -l);
+ glVertex3d(0, 0, +l);
+ glEnd();
+}
+
+void GLView::showCrosshairs()
+{
+ // FIXME: this might not work with non-gimbal camera?
+ // FIXME: Crosshairs and axes are lighted, this doesn't make sense and causes them
+ // to change color based on view orientation.
+ glLineWidth(3);
+ Color4f col = RenderSettings::inst()->color(RenderSettings::CROSSHAIR_COLOR);
+ glColor3f(col[0], col[1], col[2]);
+ glBegin(GL_LINES);
+ for (double xf = -1; xf <= +1; xf += 2)
+ for (double yf = -1; yf <= +1; yf += 2) {
+ double vd = viewer_distance/20;
+ glVertex3d(-xf*vd, -yf*vd, -vd);
+ glVertex3d(+xf*vd, +yf*vd, +vd);
+ }
+ glEnd();
+}
/*
diff --git a/src/GLView.h b/src/GLView.h
index 00d2da3..de8f65b 100644
--- a/src/GLView.h
+++ b/src/GLView.h
@@ -3,12 +3,15 @@
/* GLView: A basic OpenGL rectangle for rendering images.
-Inherited by QGLview (for Qt GUI) and OffscreenView (used in tests and
-for offscreen command-line rendering).
+Inherited by
+
+*QGLview (for Qt GUI)
+*OffscreenView (used in tests and for offscreen command-line rendering).
There are two different types of cameras. A 'gimbal' based camera set
using translation & euler-angles (object_trans/object_rot/distance) and a
'plain' camera set using eye-position, 'look at' center point, and 'up'
+The camera systems are not totally integrated or interchangable (yet)
*/
@@ -33,6 +36,7 @@ public:
void initializeGL();
void resizeGL(int w, int h);
+ virtual void paintGL() = 0;
void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance);
void setupGimbalPerspective();
@@ -42,6 +46,10 @@ public:
void setupPerspective();
void setupOrtho(bool offset=false);
+ void showCrosshairs();
+ void showAxes();
+ void showSmallaxes();
+
virtual bool save(const char *filename) = 0;
virtual std::string getRendererInfo() const = 0;
@@ -68,10 +76,6 @@ public:
bool opencsg_support;
int opencsg_id;
#endif
-/*
- void paintGL(); //
-*/
-
};
#endif
diff --git a/src/OffscreenView.cc b/src/OffscreenView.cc
index 723d8d7..b074910 100644
--- a/src/OffscreenView.cc
+++ b/src/OffscreenView.cc
@@ -46,26 +46,10 @@ void OffscreenView::paintGL()
this->camera_center[0], this->camera_center[1], this->camera_center[2],
0.0, 0.0, 1.0);
- // glRotated(object_rot[0], 1.0, 0.0, 0.0);
- // glRotated(object_rot[1], 0.0, 1.0, 0.0);
- // glRotated(object_rot[2], 0.0, 0.0, 1.0);
-
- // Large gray axis cross inline with the model
- // FIXME: This is always gray - adjust color to keep contrast with background
- if (showaxes)
- {
- glLineWidth(1);
- glColor3d(0.5, 0.5, 0.5);
- glBegin(GL_LINES);
- double l = 3*(this->camera_center - this->camera_eye).norm();
- glVertex3d(-l, 0, 0);
- glVertex3d(+l, 0, 0);
- glVertex3d(0, -l, 0);
- glVertex3d(0, +l, 0);
- glVertex3d(0, 0, -l);
- glVertex3d(0, 0, +l);
- glEnd();
- }
+ // fixme - showcrosshairs doesnt work with non-gimbal camera
+ // if (showcrosshairs) GLView::showCrosshairs();
+
+ if (showaxes) GLView::showAxes();
glDepthFunc(GL_LESS);
glCullFace(GL_BACK);
@@ -74,6 +58,9 @@ void OffscreenView::paintGL()
glLineWidth(2);
glColor3d(1.0, 0.0, 0.0);
+ //FIXME showSmallAxes wont work with non-gimbal camera
+ //if (showaxes) GLView::showSmallaxes();
+
if (this->renderer) {
this->renderer->draw(showfaces, showedges);
}
@@ -98,12 +85,3 @@ std::string OffscreenView::getRendererInfo() const
return out.str();
}
-
-/*
-void OffscreenView::setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center)
-{
- this->camera_eye = pos;
- this->camera_center = center;
-}
-
-*/
diff --git a/src/QGLView.cc b/src/QGLView.cc
index 4a17dd1..86dd78a 100644
--- a/src/QGLView.cc
+++ b/src/QGLView.cc
@@ -27,8 +27,8 @@
#include "QGLView.h"
#include "Preferences.h"
#include "renderer.h"
-#include "rendersettings.h"
-#include "linalg.h"
+//#include "rendersettings.h"
+//#include "linalg.h"
#include <QApplication>
#include <QWheelEvent>
@@ -163,41 +163,11 @@ void QGLView::paintGL()
glRotated(object_rot.y(), 0.0, 1.0, 0.0);
glRotated(object_rot.z(), 0.0, 0.0, 1.0);
- // FIXME: Crosshairs and axes are lighted, this doesn't make sense and causes them
- // to change color based on view orientation.
- if (showcrosshairs)
- {
- glLineWidth(3);
- Color4f col = RenderSettings::inst()->color(RenderSettings::CROSSHAIR_COLOR);
- glColor3f(col[0], col[1], col[2]);
- glBegin(GL_LINES);
- for (double xf = -1; xf <= +1; xf += 2)
- for (double yf = -1; yf <= +1; yf += 2) {
- double vd = viewer_distance/20;
- glVertex3d(-xf*vd, -yf*vd, -vd);
- glVertex3d(+xf*vd, +yf*vd, +vd);
- }
- glEnd();
- }
+ if (showcrosshairs) GLView::showCrosshairs();
glTranslated(object_trans.x(), object_trans.y(), object_trans.z());
- // Large gray axis cross inline with the model
- // FIXME: This is always gray - adjust color to keep contrast with background
- if (showaxes)
- {
- glLineWidth(1);
- glColor3d(0.5, 0.5, 0.5);
- glBegin(GL_LINES);
- double l = viewer_distance/10;
- glVertex3d(-l, 0, 0);
- glVertex3d(+l, 0, 0);
- glVertex3d(0, -l, 0);
- glVertex3d(0, +l, 0);
- glVertex3d(0, 0, -l);
- glVertex3d(0, 0, +l);
- glEnd();
- }
+ if (showaxes) GLView::showAxes();
glDepthFunc(GL_LESS);
glCullFace(GL_BACK);
@@ -215,81 +185,7 @@ void QGLView::paintGL()
}
// Small axis cross in the lower left corner
- if (showaxes)
- {
- glDepthFunc(GL_ALWAYS);
-
- GLView::setupGimbalOrtho(1000,true);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glRotated(object_rot.x(), 1.0, 0.0, 0.0);
- glRotated(object_rot.y(), 0.0, 1.0, 0.0);
- glRotated(object_rot.z(), 0.0, 0.0, 1.0);
-
- glLineWidth(1);
- glBegin(GL_LINES);
- glColor3d(1.0, 0.0, 0.0);
- glVertex3d(0, 0, 0); glVertex3d(10, 0, 0);
- glColor3d(0.0, 1.0, 0.0);
- glVertex3d(0, 0, 0); glVertex3d(0, 10, 0);
- glColor3d(0.0, 0.0, 1.0);
- glVertex3d(0, 0, 0); glVertex3d(0, 0, 10);
- glEnd();
-
- GLdouble mat_model[16];
- glGetDoublev(GL_MODELVIEW_MATRIX, mat_model);
-
- GLdouble mat_proj[16];
- glGetDoublev(GL_PROJECTION_MATRIX, mat_proj);
-
- GLint viewport[4];
- glGetIntegerv(GL_VIEWPORT, viewport);
-
- GLdouble xlabel_x, xlabel_y, xlabel_z;
- gluProject(12, 0, 0, mat_model, mat_proj, viewport, &xlabel_x, &xlabel_y, &xlabel_z);
- xlabel_x = round(xlabel_x); xlabel_y = round(xlabel_y);
-
- GLdouble ylabel_x, ylabel_y, ylabel_z;
- gluProject(0, 12, 0, mat_model, mat_proj, viewport, &ylabel_x, &ylabel_y, &ylabel_z);
- ylabel_x = round(ylabel_x); ylabel_y = round(ylabel_y);
-
- GLdouble zlabel_x, zlabel_y, zlabel_z;
- gluProject(0, 0, 12, mat_model, mat_proj, viewport, &zlabel_x, &zlabel_y, &zlabel_z);
- zlabel_x = round(zlabel_x); zlabel_y = round(zlabel_y);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glTranslated(-1, -1, 0);
- glScaled(2.0/viewport[2], 2.0/viewport[3], 1);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- // FIXME: This was an attempt to keep contrast with background, but is suboptimal
- // (e.g. nearly invisible against a gray background).
-// int r,g,b;
-// r=g=b=0;
-// bgcol.getRgb(&r, &g, &b);
-// glColor3f((255.0f-r)/255.0f, (255.0f-g)/255.0f, (255.0f-b)/255.0f);
- glColor3f(0.0f, 0.0f, 0.0f);
- glBegin(GL_LINES);
- // X Label
- glVertex3d(xlabel_x-3, xlabel_y-3, 0); glVertex3d(xlabel_x+3, xlabel_y+3, 0);
- glVertex3d(xlabel_x-3, xlabel_y+3, 0); glVertex3d(xlabel_x+3, xlabel_y-3, 0);
- // Y Label
- glVertex3d(ylabel_x-3, ylabel_y-3, 0); glVertex3d(ylabel_x+3, ylabel_y+3, 0);
- glVertex3d(ylabel_x-3, ylabel_y+3, 0); glVertex3d(ylabel_x, ylabel_y, 0);
- // Z Label
- glVertex3d(zlabel_x-3, zlabel_y-3, 0); glVertex3d(zlabel_x+3, zlabel_y-3, 0);
- glVertex3d(zlabel_x-3, zlabel_y+3, 0); glVertex3d(zlabel_x+3, zlabel_y+3, 0);
- glVertex3d(zlabel_x-3, zlabel_y-3, 0); glVertex3d(zlabel_x+3, zlabel_y+3, 0);
- glEnd();
-
- //Restore perspective for next paint
- if(!orthomode)
- GLView::setupGimbalPerspective();
- }
+ if (showaxes) GLView::showSmallaxes();
if (statusLabel) {
QString msg;
diff --git a/src/export_png.cc b/src/export_png.cc
index 2d6a4a2..179278a 100644
--- a/src/export_png.cc
+++ b/src/export_png.cc
@@ -49,7 +49,12 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output)
void export_png_with_opencsg(CGAL_Nef_polyhedron *root_N, std::ostream &output)
{
CsgInfo csgInfo;
- PRINT("not implemented: solid OpenSCAD_Model opencsg png export\n");
+ try {
+ csgInfo.glview = new OffscreenView(512,512);
+ } catch (int error) {
+ fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error);
+ return;
+ }
}
diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc
index 29f92e4..a4a036d 100644
--- a/tests/csgtestcore.cc
+++ b/tests/csgtestcore.cc
@@ -32,6 +32,8 @@
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
+#include "CsgInfo.h"
+
namespace po = boost::program_options;
namespace fs = boost::filesystem;
#include "boosty.h"
@@ -45,26 +47,6 @@ std::string commandline_commands;
//#define DEBUG
-class CsgInfo
-{
-public:
- CsgInfo();
- shared_ptr<CSGTerm> root_norm_term; // Normalized CSG products
- class CSGChain *root_chain;
- std::vector<shared_ptr<CSGTerm> > highlight_terms;
- CSGChain *highlights_chain;
- std::vector<shared_ptr<CSGTerm> > background_terms;
- CSGChain *background_chain;
- OffscreenView *glview;
-};
-
-CsgInfo::CsgInfo() {
- root_chain = NULL;
- highlights_chain = NULL;
- background_chain = NULL;
- glview = NULL;
-}
-
string info_dump(OffscreenView *glview)
{
assert(glview);
@@ -123,8 +105,53 @@ po::variables_map parse_options(int argc, char *argv[])
return vm;
}
-// glview->shaderinfo[9] = glview->width;
-// glview->shaderinfo[10] = glview->height;
+int opencsg_prep( Tree &tree, AbstractNode *root_node, CsgInfo_OpenCSG &csgInfo )
+{
+ CGALEvaluator cgalevaluator(tree);
+ CSGTermEvaluator evaluator(tree, &cgalevaluator.psevaluator);
+ shared_ptr<CSGTerm> root_raw_term = evaluator.evaluateCSGTerm(*root_node,
+ csgInfo.highlight_terms,
+ csgInfo.background_terms);
+
+ if (!root_raw_term) {
+ cerr << "Error: CSG generation failed! (no top level object found)\n";
+ return 1;
+ }
+
+ // CSG normalization
+ CSGTermNormalizer normalizer(5000);
+ csgInfo.root_norm_term = normalizer.normalize(root_raw_term);
+ if (csgInfo.root_norm_term) {
+ csgInfo.root_chain = new CSGChain();
+ csgInfo.root_chain->import(csgInfo.root_norm_term);
+ fprintf(stderr, "Normalized CSG tree has %d elements\n", int(csgInfo.root_chain->polysets.size()));
+ }
+ else {
+ csgInfo.root_chain = NULL;
+ fprintf(stderr, "WARNING: CSG normalization resulted in an empty tree\n");
+ }
+
+ if (csgInfo.highlight_terms.size() > 0) {
+ cerr << "Compiling highlights (" << csgInfo.highlight_terms.size() << " CSG Trees)...\n";
+
+ csgInfo.highlights_chain = new CSGChain();
+ for (unsigned int i = 0; i < csgInfo.highlight_terms.size(); i++) {
+ csgInfo.highlight_terms[i] = normalizer.normalize(csgInfo.highlight_terms[i]);
+ csgInfo.highlights_chain->import(csgInfo.highlight_terms[i]);
+ }
+ }
+
+ if (csgInfo.background_terms.size() > 0) {
+ cerr << "Compiling background (" << csgInfo.background_terms.size() << " CSG Trees)...\n";
+
+ csgInfo.background_chain = new CSGChain();
+ for (unsigned int i = 0; i < csgInfo.background_terms.size(); i++) {
+ csgInfo.background_terms[i] = normalizer.normalize(csgInfo.background_terms[i]);
+ csgInfo.background_chain->import(csgInfo.background_terms[i]);
+ }
+ }
+ return 0;
+}
int csgtestcore(int argc, char *argv[], test_type_e test_type)
{
@@ -187,51 +214,10 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type)
Tree tree(root_node);
- CsgInfo csgInfo = CsgInfo();
- CGALEvaluator cgalevaluator(tree);
- CSGTermEvaluator evaluator(tree, &cgalevaluator.psevaluator);
- shared_ptr<CSGTerm> root_raw_term = evaluator.evaluateCSGTerm(*root_node,
- csgInfo.highlight_terms,
- csgInfo.background_terms);
-
- if (!root_raw_term) {
- cerr << "Error: CSG generation failed! (no top level object found)\n";
- return 1;
- }
-
- // CSG normalization
- CSGTermNormalizer normalizer(5000);
- csgInfo.root_norm_term = normalizer.normalize(root_raw_term);
- if (csgInfo.root_norm_term) {
- csgInfo.root_chain = new CSGChain();
- csgInfo.root_chain->import(csgInfo.root_norm_term);
- fprintf(stderr, "Normalized CSG tree has %d elements\n", int(csgInfo.root_chain->polysets.size()));
- }
- else {
- csgInfo.root_chain = NULL;
- fprintf(stderr, "WARNING: CSG normalization resulted in an empty tree\n");
- }
+ CsgInfo_OpenCSG csgInfo = CsgInfo_OpenCSG();
+ int result = opencsg_prep( tree, root_node, csgInfo );
+ if ( result == 1 ) return result;
- if (csgInfo.highlight_terms.size() > 0) {
- cerr << "Compiling highlights (" << csgInfo.highlight_terms.size() << " CSG Trees)...\n";
-
- csgInfo.highlights_chain = new CSGChain();
- for (unsigned int i = 0; i < csgInfo.highlight_terms.size(); i++) {
- csgInfo.highlight_terms[i] = normalizer.normalize(csgInfo.highlight_terms[i]);
- csgInfo.highlights_chain->import(csgInfo.highlight_terms[i]);
- }
- }
-
- if (csgInfo.background_terms.size() > 0) {
- cerr << "Compiling background (" << csgInfo.background_terms.size() << " CSG Trees)...\n";
-
- csgInfo.background_chain = new CSGChain();
- for (unsigned int i = 0; i < csgInfo.background_terms.size(); i++) {
- csgInfo.background_terms[i] = normalizer.normalize(csgInfo.background_terms[i]);
- csgInfo.background_chain->import(csgInfo.background_terms[i]);
- }
- }
-
fs::current_path(original_path);
try {
contact: Jan Huwald // Impressum