diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GLView.cc | 117 | ||||
-rw-r--r-- | src/GLView.h | 16 | ||||
-rw-r--r-- | src/OffscreenView.cc | 36 | ||||
-rw-r--r-- | src/QGLView.cc | 114 | ||||
-rw-r--r-- | src/export_png.cc | 7 |
5 files changed, 145 insertions, 145 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 ¢er { 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 ¢er) -{ - 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; + } } |