Colormap functionality from pull request #816, mostly by Don Bright, includes new colormaps by shaina

master
Marius Kintel 2014-08-14 17:16:24 -04:00
parent c5050b03b7
commit e70bc04197
27 changed files with 446 additions and 344 deletions

View File

@ -221,6 +221,7 @@ HEADERS += src/typedefs.h \
src/parsersettings.h \
src/renderer.h \
src/rendersettings.h \
src/colormap.h \
src/ThrownTogetherRenderer.h \
src/CGAL_renderer.h \
src/OGL_helper.h \
@ -378,6 +379,7 @@ SOURCES += src/version_check.cc \
src/export_png.cc \
src/import.cc \
src/renderer.cc \
src/colormap.cc \
src/ThrownTogetherRenderer.cc \
src/CSGTermEvaluator.cc \
src/svg.cc \

View File

@ -32,6 +32,7 @@
// dxfdata.h must come first for Eigen SIMD alignment issues
#include "dxfdata.h"
#include "polyset.h"
#include "printutils.h"
#include "CGALRenderer.h"
#include "CGAL_renderer.h"
@ -51,19 +52,7 @@ CGALRenderer::CGALRenderer(shared_ptr<const class Geometry> geom)
else if (shared_ptr<const CGAL_Nef_polyhedron> new_N = dynamic_pointer_cast<const CGAL_Nef_polyhedron>(geom)) {
assert(new_N->getDimension() == 3);
if (!new_N->isEmpty()) {
this->polyhedron.reset(new Polyhedron());
// FIXME: Make independent of Preferences
// this->polyhedron->setColor(Polyhedron::CGAL_NEF3_MARKED_FACET_COLOR,
// Preferences::inst()->color(Preferences::CGAL_FACE_BACK_COLOR).red(),
// Preferences::inst()->color(Preferences::CGAL_FACE_BACK_COLOR).green(),
// Preferences::inst()->color(Preferences::CGAL_FACE_BACK_COLOR).blue());
// this->polyhedron->setColor(Polyhedron::CGAL_NEF3_UNMARKED_FACET_COLOR,
// Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).red(),
// Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).green(),
// Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).blue());
CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron3>::convert_to_OGLPolyhedron(*new_N->p3, this->polyhedron.get());
this->polyhedron->init();
this->N = new_N;
}
}
}
@ -72,9 +61,37 @@ CGALRenderer::~CGALRenderer()
{
}
shared_ptr<class Polyhedron> CGALRenderer::getPolyhedron() const
{
if (this->N && !this->polyhedron) buildPolyhedron();
return this->polyhedron;
}
void CGALRenderer::buildPolyhedron() const
{
PRINTD("buildPolyhedron");
this->polyhedron.reset(new Polyhedron(*this->colorscheme));
CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron3>::convert_to_OGLPolyhedron(*this->N->p3, this->polyhedron.get());
// CGAL_NEF3_MARKED_FACET_COLOR <- CGAL_FACE_BACK_COLOR
// CGAL_NEF3_UNMARKED_FACET_COLOR <- CGAL_FACE_FRONT_COLOR
this->polyhedron->init();
PRINTD("buildPolyhedron() end");
}
// Overridden from Renderer
void CGALRenderer::setColorScheme(const ColorScheme &cs)
{
PRINTD("setColorScheme");
Renderer::setColorScheme(cs);
this->polyhedron.reset(); // Mark as dirty
PRINTD("setColorScheme done");
}
void CGALRenderer::draw(bool showfaces, bool showedges) const
{
PRINTD("draw()");
if (this->polyset) {
PRINTD("draw() polyset");
if (this->polyset->getDimension() == 2) {
// Draw 2D polygons
glDisable(GL_LIGHTING);
@ -106,27 +123,33 @@ void CGALRenderer::draw(bool showfaces, bool showedges) const
this->polyset->render_surface(CSGMODE_NORMAL, Transform3d::Identity(), NULL);
}
}
else if (this->polyhedron) {
if (showfaces) this->polyhedron->set_style(SNC_BOUNDARY);
else this->polyhedron->set_style(SNC_SKELETON);
this->polyhedron->draw(showfaces && showedges);
}
else {
shared_ptr<class Polyhedron> polyhedron = getPolyhedron();
if (polyhedron) {
PRINTD("draw() polyhedron");
if (showfaces) polyhedron->set_style(SNC_BOUNDARY);
else polyhedron->set_style(SNC_SKELETON);
polyhedron->draw(showfaces && showedges);
}
}
PRINTD("draw() end");
}
BoundingBox CGALRenderer::getBoundingBox() const
{
BoundingBox bbox;
if (this->polyhedron) {
CGAL::Bbox_3 cgalbbox = this->polyhedron->bbox();
bbox = BoundingBox(
Vector3d(cgalbbox.xmin(), cgalbbox.ymin(), cgalbbox.zmin()),
Vector3d(cgalbbox.xmax(), cgalbbox.ymax(), cgalbbox.zmax()) );
}
else if (this->polyset) {
if (this->polyset) {
bbox = this->polyset->getBoundingBox();
}
else {
shared_ptr<class Polyhedron> polyhedron = getPolyhedron();
if (polyhedron) {
CGAL::Bbox_3 cgalbbox = polyhedron->bbox();
bbox = BoundingBox(
Vector3d(cgalbbox.xmin(), cgalbbox.ymin(), cgalbbox.zmin()),
Vector3d(cgalbbox.xmax(), cgalbbox.ymax(), cgalbbox.zmax()));
}
}
return bbox;
}

View File

@ -1,16 +1,22 @@
#pragma once
#include "renderer.h"
#include "CGAL_Nef_polyhedron.h"
class CGALRenderer : public Renderer
{
public:
CGALRenderer(shared_ptr<const class Geometry> geom);
virtual ~CGALRenderer();
~CGALRenderer();
virtual void draw(bool showfaces, bool showedges) const;
virtual void setColorScheme(const ColorScheme &cs);
virtual BoundingBox getBoundingBox() const;
public:
shared_ptr<class Polyhedron> polyhedron;
private:
shared_ptr<class Polyhedron> getPolyhedron() const;
void buildPolyhedron() const;
mutable shared_ptr<class Polyhedron> polyhedron;
shared_ptr<const CGAL_Nef_polyhedron> N;
shared_ptr<const class PolySet> polyset;
};

View File

@ -27,14 +27,11 @@
#pragma once
#ifndef NULLGL
#include "OGL_helper.h"
#undef CGAL_NEF3_MARKED_VERTEX_COLOR
#undef CGAL_NEF3_MARKED_EDGE_COLOR
#undef CGAL_NEF3_MARKED_FACET_COLOR
#undef CGAL_NEF3_UNMARKED_VERTEX_COLOR
#undef CGAL_NEF3_UNMARKED_EDGE_COLOR
#undef CGAL_NEF3_UNMARKED_FACET_COLOR
#include "colormap.h"
#include "rendersettings.h"
#include "OGL_helper.h"
#include "printutils.h"
using CGAL::OGL::SNC_BOUNDARY;
using CGAL::OGL::SNC_SKELETON;
@ -53,16 +50,18 @@ public:
NUM_COLORS
};
Polyhedron() {
Polyhedron(const ColorScheme &cs) {
PRINTD("Polyhedron()");
// Set default colors.
setColor(CGAL_NEF3_MARKED_VERTEX_COLOR,0xb7,0xe8,0x5c);
setColor(CGAL_NEF3_MARKED_EDGE_COLOR,0xab,0xd8,0x56);
setColor(CGAL_NEF3_MARKED_FACET_COLOR,0x9d,0xcb,0x51);
setColor(CGAL_NEF3_UNMARKED_VERTEX_COLOR,0xff,0xf6,0x7c);
setColor(CGAL_NEF3_UNMARKED_EDGE_COLOR,0xff,0xec,0x5e);
setColor(CGAL_NEF3_UNMARKED_FACET_COLOR,0xf9,0xd7,0x2c);
// Face and Edge colors are taken from default colorscheme
setColorScheme(cs);
PRINTD("Polyhedron() end");
}
void draw(bool showedges) const {
PRINTD("draw()");
if(this->style == SNC_BOUNDARY) {
glCallList(this->object_list_+2);
if(showedges) {
@ -75,27 +74,51 @@ public:
glCallList(this->object_list_+1);
glCallList(this->object_list_);
}
PRINTD("draw() end");
}
// overrides function in OGL_helper.h
CGAL::Color getVertexColor(Vertex_iterator v) const {
PRINTD("getVertexColor");
CGAL::Color c = v->mark() ? colors[CGAL_NEF3_UNMARKED_VERTEX_COLOR] : colors[CGAL_NEF3_MARKED_VERTEX_COLOR];
return c;
}
// overrides function in OGL_helper.h
CGAL::Color getEdgeColor(Edge_iterator e) const {
PRINTD("getEdgeColor");
CGAL::Color c = e->mark() ? colors[CGAL_NEF3_UNMARKED_EDGE_COLOR] : colors[CGAL_NEF3_MARKED_EDGE_COLOR];
return c;
}
CGAL::Color getFacetColor(Halffacet_iterator f) const {
// overrides function in OGL_helper.h
CGAL::Color getFacetColor(Halffacet_iterator f, bool is_back_facing) const {
PRINTD("getFacetColor");
CGAL::Color c = f->mark() ? colors[CGAL_NEF3_UNMARKED_FACET_COLOR] : colors[CGAL_NEF3_MARKED_FACET_COLOR];
return c;
}
void setColor(Polyhedron::RenderColor color_index, const Color4f &c) {
PRINTDB("setColor %i %f %f %f",color_index%c[0]%c[1]%c[2]);
this->colors[color_index] = CGAL::Color(c[0]*255,c[1]*255,c[2]*255);
}
void setColor(Polyhedron::RenderColor color_index,
unsigned char r, unsigned char g, unsigned char b) {
assert(color_index < Polyhedron::NUM_COLORS);
PRINTDB("setColor %i %i %i %i",color_index%r%g%b);
this->colors[color_index] = CGAL::Color(r,g,b);
}
// set this->colors based on the given colorscheme. vertex colors
// are not set here as colorscheme doesnt yet hold vertex colors.
void setColorScheme(const ColorScheme &cs) {
PRINTD("setColorScheme");
setColor(CGAL_NEF3_MARKED_FACET_COLOR, ColorMap::getColor(cs, CGAL_FACE_BACK_COLOR));
setColor(CGAL_NEF3_UNMARKED_FACET_COLOR, ColorMap::getColor(cs, CGAL_FACE_FRONT_COLOR));
setColor(CGAL_NEF3_MARKED_EDGE_COLOR, ColorMap::getColor(cs, CGAL_EDGE_BACK_COLOR));
setColor(CGAL_NEF3_UNMARKED_EDGE_COLOR, ColorMap::getColor(cs, CGAL_EDGE_FRONT_COLOR));
}
private:
CGAL::Color colors[NUM_COLORS];

View File

@ -5,6 +5,7 @@
Camera::Camera(enum CameraType camtype) :
type(camtype), projection(Camera::PERSPECTIVE), fov(45), height(60), viewall(false)
{
PRINTD("Camera()");
if (this->type == Camera::GIMBAL) {
object_trans << 0,0,0;
object_rot << 35,0,25;
@ -92,6 +93,10 @@ void Camera::viewAll(const BoundingBox &bbox, float scalefactor)
}
break;
}
PRINTDB("modified center x y z %f %f %f",center.x() % center.y() % center.z());
PRINTDB("modified eye x y z %f %f %f",eye.x() % eye.y() % eye.z());
PRINTDB("modified obj trans x y z %f %f %f",object_trans.x() % object_trans.y() % object_trans.z());
PRINTDB("modified obj rot x y z %f %f %f",object_rot.x() % object_rot.y() % object_rot.z());
}
void Camera::zoom(int delta)

View File

@ -1,8 +1,10 @@
#include "GLView.h"
#include "stdio.h"
#include "colormap.h"
#include "rendersettings.h"
#include "mathc99.h"
#include "printutils.h"
#include "renderer.h"
#ifdef _WIN32
@ -22,6 +24,7 @@ GLView::GLView()
showaxes = false;
showcrosshairs = false;
renderer = NULL;
colorscheme = &ColorMap::inst()->defaultColorScheme();
cam = Camera();
far_far_away = RenderSettings::inst()->far_gl_clip_limit;
#ifdef ENABLE_OPENCSG
@ -39,6 +42,32 @@ void GLView::setRenderer(Renderer* r)
renderer = r;
}
/* update the color schemes of the Renderer attached to this GLView
to match the colorscheme of this GLView.*/
void GLView::updateColorScheme()
{
if (this->renderer) this->renderer->setColorScheme(*this->colorscheme);
}
/* change this GLView's colorscheme to the one given, and update the
Renderer attached to this GLView as well. */
void GLView::setColorScheme(const ColorScheme &cs)
{
this->colorscheme = &cs;
this->updateColorScheme();
}
void GLView::setColorScheme(const std::string &cs)
{
const ColorScheme *colorscheme = ColorMap::inst()->findColorScheme(cs);
if (colorscheme) {
setColorScheme(*colorscheme);
}
else {
PRINTB("WARNING: GLView: unknown colorscheme %s", cs);
}
}
void GLView::resizeGL(int w, int h)
{
#ifdef ENABLE_OPENCSG
@ -125,7 +154,7 @@ void GLView::paintGL()
setupCamera();
Color4f bgcol = RenderSettings::inst()->color(RenderSettings::BACKGROUND_COLOR);
Color4f bgcol = ColorMap::getColor(*this->colorscheme, BACKGROUND_COLOR);
glClearColor(bgcol[0], bgcol[1], bgcol[2], 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@ -440,7 +469,7 @@ void GLView::showCrosshairs()
// 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);
Color4f col = ColorMap::getColor(*this->colorscheme, CROSSHAIR_COLOR);
glColor3f(col[0], col[1], col[2]);
glBegin(GL_LINES);
for (double xf = -1; xf <= +1; xf += 2)

View File

@ -26,6 +26,7 @@ Some actions (showCrossHairs) only work properly on Gimbal Camera.
#include "system-gl.h"
#include <iostream>
#include "Camera.h"
#include "colormap.h"
class GLView
{
@ -45,11 +46,16 @@ public:
void showAxes();
void showSmallaxes();
void setColorScheme(const ColorScheme &cs);
void setColorScheme(const std::string &cs);
void updateColorScheme();
virtual bool save(const char *filename) = 0;
virtual std::string getRendererInfo() const = 0;
virtual float getDPI() { return 1.0f; }
Renderer *renderer;
const ColorScheme *colorscheme;
Camera cam;
double far_far_away;
size_t width;

View File

@ -79,6 +79,7 @@ private slots:
void updateUndockMode(bool undockMode);
void setFileName(const QString &filename);
void setFont(const QString &family, uint size);
void setColorScheme(const QString &cs);
void showProgress();
void openCSGSettingsChanged();

View File

@ -17,6 +17,8 @@
//
// Author(s) : Peter Hachenberger <hachenberger@mpi-sb.mpg.de>
// Modified for OpenSCAD
#pragma once
#include <CGAL/Nef_S2/OGL_base_object.h>
@ -25,16 +27,18 @@
#include "system-gl.h"
#include <cstdlib>
#define CGAL_NEF3_MARKED_VERTEX_COLOR 183,232,92
#define CGAL_NEF3_MARKED_EDGE_COLOR 171,216,86
#define CGAL_NEF3_MARKED_FACET_COLOR 157,203,81
#define CGAL_NEF3_MARKED_BACK_FACET_COLOR 157,103,181
#define CGAL_NEF3_UNMARKED_VERTEX_COLOR 255,246,124
#define CGAL_NEF3_UNMARKED_EDGE_COLOR 255,236,94
#define CGAL_NEF3_UNMARKED_FACET_COLOR 249,215,44
#define CGAL_NEF3_UNMARKED_BACK_FACET_COLOR 249,115,144
// Overridden in CGAL_renderer
/*
#define CGAL_NEF3_OGL_MARKED_VERTEX_COLOR 183,232,92
#define CGAL_NEF3_OGL_MARKED_EDGE_COLOR 171,216,86
#define CGAL_NEF3_OGL_MARKED_FACET_COLOR 157,203,81
#define CGAL_NEF3_OGL_MARKED_BACK_FACET_COLOR 157,103,181
#define CGAL_NEF3_OGL_UNMARKED_VERTEX_COLOR 255,246,124
#define CGAL_NEF3_OGL_UNMARKED_EDGE_COLOR 255,236,94
#define CGAL_NEF3_OGL_UNMARKED_FACET_COLOR 249,215,44
#define CGAL_NEF3_OGL_UNMARKED_BACK_FACET_COLOR 249,115,144
*/
const bool cull_backfaces = false;
const bool color_backfaces = false;
@ -362,18 +366,24 @@ namespace OGL {
Bbox_3 bbox() const { return bbox_; }
Bbox_3& bbox() { return bbox_; }
// Overridden in CGAL_renderer
virtual CGAL::Color getVertexColor(Vertex_iterator v) const
{
CGAL::Color cf(CGAL_NEF3_MARKED_VERTEX_COLOR),
ct(CGAL_NEF3_UNMARKED_VERTEX_COLOR); // more blue-ish
CGAL::Color c = v->mark() ? ct : cf;
PRINTD("getVertexColor()");
(void)v;
// CGAL::Color cf(CGAL_NEF3_OGL_MARKED_VERTEX_COLOR),
// ct(CGAL_NEF3_OGL_UNMARKED_VERTEX_COLOR); // more blue-ish
// CGAL::Color c = v->mark() ? ct : cf;
CGAL::Color c(0,0,200);
return c;
}
void draw(Vertex_iterator v) const {
PRINTD("draw( Vertex_iterator )");
// CGAL_NEF_TRACEN("drawing vertex "<<*v);
CGAL::Color c = getVertexColor(v);
glPointSize(10);
//glPointSize(1);
glColor3ub(c.red(), c.green(), c.blue());
glBegin(GL_POINTS);
glVertex3d(v->x(),v->y(),v->z());
@ -384,19 +394,26 @@ namespace OGL {
glEnd();
}
// Overridden in CGAL_renderer
virtual CGAL::Color getEdgeColor(Edge_iterator e) const
{
CGAL::Color cf(CGAL_NEF3_MARKED_EDGE_COLOR),
ct(CGAL_NEF3_UNMARKED_EDGE_COLOR); // more blue-ish
CGAL::Color c = e->mark() ? ct : cf;
PRINTD("getEdgeColor)");
(void)e;
// CGAL::Color cf(CGAL_NEF3_OGL_MARKED_EDGE_COLOR),
// ct(CGAL_NEF3_OGL_UNMARKED_EDGE_COLOR); // more blue-ish
// CGAL::Color c = e->mark() ? ct : cf;
// Overridden in CGAL_renderer
CGAL::Color c(200,0,0);
return c;
}
void draw(Edge_iterator e) const {
PRINTD("draw(Edge_iterator)");
// CGAL_NEF_TRACEN("drawing edge "<<*e);
Double_point p = e->source(), q = e->target();
CGAL::Color c = getEdgeColor(e);
glLineWidth(5);
//glLineWidth(1);
glColor3ub(c.red(),c.green(),c.blue());
glBegin(GL_LINE_STRIP);
glVertex3d(p.x(), p.y(), p.z());
@ -404,18 +421,32 @@ namespace OGL {
glEnd();
}
// Overridden in CGAL_renderer
virtual CGAL::Color getFacetColor(Halffacet_iterator f, bool is_back_facing) const
{
PRINTD("getFacetColor");
/*
(void)f;
// CGAL::Color cf(CGAL_NEF3_OGL_MARKED_FACET_COLOR),
// ct(CGAL_NEF3_OGL_UNMARKED_FACET_COLOR); // more blue-ish
// CGAL::Color c = (f->mark() ? ct : cf);
*/
CGAL::Color c(0,200,0);
return c;
/*
if (is_back_facing) return !f->mark()
? CGAL::Color(CGAL_NEF3_MARKED_BACK_FACET_COLOR)
: CGAL::Color(CGAL_NEF3_UNMARKED_BACK_FACET_COLOR);
? CGAL::Color(CGAL_NEF3_OGL_MARKED_BACK_FACET_COLOR)
: CGAL::Color(CGAL_NEF3_OGL_UNMARKED_BACK_FACET_COLOR);
else return !f->mark()
? CGAL::Color(CGAL_NEF3_MARKED_FACET_COLOR)
: CGAL::Color(CGAL_NEF3_UNMARKED_FACET_COLOR);
? CGAL::Color(CGAL_NEF3_OGL_MARKED_FACET_COLOR)
: CGAL::Color(CGAL_NEF3_OGL_UNMARKED_FACET_COLOR);
*/
}
void draw(Halffacet_iterator f, bool is_back_facing) const {
PRINTD("draw(Halffacet_iterator)");
// CGAL_NEF_TRACEN("drawing facet "<<(f->debug(),""));
GLUtesselator* tess_ = gluNewTess();
gluTessCallback(tess_, GLenum(GLU_TESS_VERTEX_DATA),
@ -458,6 +489,7 @@ namespace OGL {
void construct_axes() const
{
PRINTD("construct_axes");
glLineWidth(2.0);
// red x-axis
glColor3f(1.0,0.0,0.0);
@ -491,6 +523,7 @@ namespace OGL {
void fill_display_lists() {
PRINTD("fill_display_lists");
glNewList(object_list_, GL_COMPILE);
Vertex_iterator v;
for(v=vertices_.begin();v!=vertices_.end();++v)
@ -528,6 +561,7 @@ namespace OGL {
}
void init() {
PRINTD("init()");
if (init_) return;
init_ = true;
switches[SNC_AXES] = false;
@ -535,11 +569,13 @@ namespace OGL {
object_list_ = glGenLists(4);
CGAL_assertion(object_list_);
fill_display_lists();
PRINTD("init() end");
}
void draw() const
{
PRINTD("draw()");
if (!is_initialized()) const_cast<Polyhedron&>(*this).init();
double l = (std::max)( (std::max)( bbox().xmax() - bbox().xmin(),
bbox().ymax() - bbox().ymin()),
@ -562,6 +598,7 @@ namespace OGL {
glCallList(object_list_+1); // edges
glCallList(object_list_); // vertices
if (switches[SNC_AXES]) glCallList(object_list_+3); // axis
PRINTD("draw() end");
}
void debug(std::ostream& os = std::cerr) const

View File

@ -37,6 +37,8 @@
#ifdef ENABLE_CGAL
#include "CGALCache.h"
#endif
#include "colormap.h"
#include "rendersettings.h"
Preferences *Preferences::instance = NULL;
@ -87,7 +89,6 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
this->fontSize->setEditText( QString("%1").arg( savedsize ) );
// Setup default settings
this->defaultmap["3dview/colorscheme"] = this->colorSchemeChooser->currentItem()->text();
this->defaultmap["advanced/opencsg_show_warning"] = true;
this->defaultmap["advanced/enable_opencsg_opengl1x"] = true;
this->defaultmap["advanced/polysetCacheSize"] = uint(GeometryCache::instance()->maxSize());
@ -120,38 +121,7 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
this->actionTriggered(this->prefsAction3DView);
// 3D View pane
this->colorschemes["Cornfield"][RenderSettings::BACKGROUND_COLOR] = Color4f(0xff, 0xff, 0xe5);
this->colorschemes["Cornfield"][RenderSettings::OPENCSG_FACE_FRONT_COLOR] = Color4f(0xf9, 0xd7, 0x2c);
this->colorschemes["Cornfield"][RenderSettings::OPENCSG_FACE_BACK_COLOR] = Color4f(0x9d, 0xcb, 0x51);
this->colorschemes["Cornfield"][RenderSettings::CGAL_FACE_FRONT_COLOR] = Color4f(0xf9, 0xd7, 0x2c);
this->colorschemes["Cornfield"][RenderSettings::CGAL_FACE_BACK_COLOR] = Color4f(0x9d, 0xcb, 0x51);
this->colorschemes["Cornfield"][RenderSettings::CGAL_FACE_2D_COLOR] = Color4f(0x00, 0xbf, 0x99);
this->colorschemes["Cornfield"][RenderSettings::CGAL_EDGE_FRONT_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Cornfield"][RenderSettings::CGAL_EDGE_BACK_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Cornfield"][RenderSettings::CGAL_EDGE_2D_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Cornfield"][RenderSettings::CROSSHAIR_COLOR] = Color4f(0x80, 0x00, 0x00);
this->colorschemes["Metallic"][RenderSettings::BACKGROUND_COLOR] = Color4f(0xaa, 0xaa, 0xff);
this->colorschemes["Metallic"][RenderSettings::OPENCSG_FACE_FRONT_COLOR] = Color4f(0xdd, 0xdd, 0xff);
this->colorschemes["Metallic"][RenderSettings::OPENCSG_FACE_BACK_COLOR] = Color4f(0xdd, 0x22, 0xdd);
this->colorschemes["Metallic"][RenderSettings::CGAL_FACE_FRONT_COLOR] = Color4f(0xdd, 0xdd, 0xff);
this->colorschemes["Metallic"][RenderSettings::CGAL_FACE_BACK_COLOR] = Color4f(0xdd, 0x22, 0xdd);
this->colorschemes["Metallic"][RenderSettings::CGAL_FACE_2D_COLOR] = Color4f(0x00, 0xbf, 0x99);
this->colorschemes["Metallic"][RenderSettings::CGAL_EDGE_FRONT_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Metallic"][RenderSettings::CGAL_EDGE_BACK_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Metallic"][RenderSettings::CGAL_EDGE_2D_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Metallic"][RenderSettings::CROSSHAIR_COLOR] = Color4f(0x80, 0x00, 0x00);
this->colorschemes["Sunset"][RenderSettings::BACKGROUND_COLOR] = Color4f(0xaa, 0x44, 0x44);
this->colorschemes["Sunset"][RenderSettings::OPENCSG_FACE_FRONT_COLOR] = Color4f(0xff, 0xaa, 0xaa);
this->colorschemes["Sunset"][RenderSettings::OPENCSG_FACE_BACK_COLOR] = Color4f(0x88, 0x22, 0x33);
this->colorschemes["Sunset"][RenderSettings::CGAL_FACE_FRONT_COLOR] = Color4f(0xff, 0xaa, 0xaa);
this->colorschemes["Sunset"][RenderSettings::CGAL_FACE_BACK_COLOR] = Color4f(0x88, 0x22, 0x33);
this->colorschemes["Sunset"][RenderSettings::CGAL_FACE_2D_COLOR] = Color4f(0x00, 0xbf, 0x99);
this->colorschemes["Sunset"][RenderSettings::CGAL_EDGE_FRONT_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Sunset"][RenderSettings::CGAL_EDGE_BACK_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Sunset"][RenderSettings::CGAL_EDGE_2D_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colorschemes["Sunset"][RenderSettings::CROSSHAIR_COLOR] = Color4f(0x80, 0x00, 0x00);
this->defaultmap["3dview/colorscheme"] = "Cornfield";
// Advanced pane
QValidator *validator = new QIntValidator(this);
@ -163,8 +133,6 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
setupFeaturesPage();
updateGUI();
RenderSettings::inst()->setColors(this->colorschemes[getValue("3dview/colorscheme").toString()]);
}
Preferences::~Preferences()
@ -275,10 +243,7 @@ void Preferences::on_colorSchemeChooser_itemSelectionChanged()
QString scheme = this->colorSchemeChooser->currentItem()->text();
QSettings settings;
settings.setValue("3dview/colorscheme", scheme);
RenderSettings::inst()->setColors(this->colorschemes[scheme]);
emit requestRedraw();
emit colorSchemeChanged( scheme );
}
void Preferences::on_fontChooser_activated(const QString &family)

View File

@ -3,9 +3,7 @@
#include <QMainWindow>
#include <QSettings>
#include "ui_Preferences.h"
#include "rendersettings.h"
#include "linalg.h"
#include <map>
#include "colormap.h"
class Preferences : public QMainWindow, public Ui::Preferences
{
@ -43,6 +41,7 @@ signals:
void updateMdiMode(bool mdi) const;
void updateUndockMode(bool mdi) const;
void fontChanged(const QString &family, uint size) const;
void colorSchemeChanged(const QString &scheme) const;
void openCSGSettingsChanged() const;
void syntaxHighlightChanged(const QString &s);
@ -55,7 +54,6 @@ private:
void addPrefPage(QActionGroup *group, QAction *action, QWidget *widget);
QSettings::SettingsMap defaultmap;
QHash<QString, std::map<RenderSettings::RenderColor, Color4f> > colorschemes;
QHash<const QAction *, QWidget *> prefPages;
static Preferences *instance;

View File

@ -44,6 +44,12 @@
</item>
<item>
<widget class="QListWidget" name="colorSchemeChooser">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alternatingRowColors">
<bool>false</bool>
</property>
@ -65,6 +71,26 @@
<string>Sunset</string>
</property>
</item>
<item>
<property name="text">
<string>Starnight</string>
</property>
</item>
<item>
<property name="text">
<string>BeforeDawn</string>
</property>
</item>
<item>
<property name="text">
<string>Nature</string>
</property>
</item>
<item>
<property name="text">
<string>DeepOcean</string>
</property>
</item>
</widget>
</item>
</layout>
@ -89,6 +115,9 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
@ -170,7 +199,7 @@
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_9">
<widget class="QLabel" name="label_syntax_h">
<property name="font">
<font>
<weight>75</weight>

View File

@ -27,6 +27,7 @@
#include "ThrownTogetherRenderer.h"
#include "polyset.h"
#include "csgterm.h"
#include "printutils.h"
#include "system-gl.h"
@ -43,6 +44,7 @@ ThrownTogetherRenderer::ThrownTogetherRenderer(CSGChain *root_chain,
void ThrownTogetherRenderer::draw(bool /*showfaces*/, bool showedges) const
{
PRINTD("Thrown draw");
if (this->root_chain) {
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
@ -62,6 +64,7 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,
bool background, bool showedges,
bool fberror) const
{
PRINTD("Thrown renderCSGChain");
glDepthFunc(GL_LEQUAL);
boost::unordered_map<std::pair<const Geometry*,const Transform3d*>,int> geomVisitMark;
BOOST_FOREACH(const CSGChainObject &obj, chain->objects) {

View File

@ -35,18 +35,18 @@
#include <boost/assign/std/vector.hpp>
#include <boost/assign/list_of.hpp>
using namespace boost::assign; // bring 'operator+=()' into scope
#include "colormap.h"
class ColorModule : public AbstractModule
{
public:
ColorModule() { }
ColorModule() : webcolors(ColorMap::inst()->webColors()) { }
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, const EvalContext *evalctx) const;
private:
static boost::unordered_map<std::string, Color4f> colormap;
const boost::unordered_map<std::string, Color4f> &webcolors;
};
#include "colormap.h"
AbstractNode *ColorModule::instantiate(const Context *ctx, const ModuleInstantiation *inst, const EvalContext *evalctx) const
{
ColorNode *node = new ColorNode(inst);
@ -72,8 +72,8 @@ AbstractNode *ColorModule::instantiate(const Context *ctx, const ModuleInstantia
std::string colorname = v.toString();
boost::algorithm::to_lower(colorname);
Color4f color;
if (colormap.find(colorname) != colormap.end()) {
node->color = colormap[colorname];
if (webcolors.find(colorname) != webcolors.end()) {
node->color = webcolors.at(colorname);
} else {
PRINTB_NOCACHE("WARNING: Color name \"%s\" unknown. Please see", colorname);
PRINT_NOCACHE("WARNING: http://en.wikipedia.org/wiki/Web_colors");

View File

@ -1,149 +1,43 @@
boost::unordered_map<std::string, Color4f> ColorModule::colormap = map_list_of
("aliceblue", Color4f(240, 248, 255))
("antiquewhite", Color4f(250, 235, 215))
("aqua", Color4f(0, 255, 255))
("aquamarine", Color4f(127, 255, 212))
("azure", Color4f(240, 255, 255))
("beige", Color4f(245, 245, 220))
("bisque", Color4f(255, 228, 196))
("black", Color4f(0, 0, 0))
("blanchedalmond", Color4f(255, 235, 205))
("blue", Color4f(0, 0, 255))
("blueviolet", Color4f(138, 43, 226))
("brown", Color4f(165, 42, 42))
("burlywood", Color4f(222, 184, 135))
("cadetblue", Color4f(95, 158, 160))
("chartreuse", Color4f(127, 255, 0))
("chocolate", Color4f(210, 105, 30))
("coral", Color4f(255, 127, 80))
("cornflowerblue", Color4f(100, 149, 237))
("cornsilk", Color4f(255, 248, 220))
("crimson", Color4f(220, 20, 60))
("cyan", Color4f(0, 255, 255))
("darkblue", Color4f(0, 0, 139))
("darkcyan", Color4f(0, 139, 139))
("darkgoldenrod", Color4f(184, 134, 11))
("darkgray", Color4f(169, 169, 169))
("darkgreen", Color4f(0, 100, 0))
("darkgrey", Color4f(169, 169, 169))
("darkkhaki", Color4f(189, 183, 107))
("darkmagenta", Color4f(139, 0, 139))
("darkolivegreen", Color4f(85, 107, 47))
("darkorange", Color4f(255, 140, 0))
("darkorchid", Color4f(153, 50, 204))
("darkred", Color4f(139, 0, 0))
("darksalmon", Color4f(233, 150, 122))
("darkseagreen", Color4f(143, 188, 143))
("darkslateblue", Color4f(72, 61, 139))
("darkslategray", Color4f(47, 79, 79))
("darkslategrey", Color4f(47, 79, 79))
("darkturquoise", Color4f(0, 206, 209))
("darkviolet", Color4f(148, 0, 211))
("deeppink", Color4f(255, 20, 147))
("deepskyblue", Color4f(0, 191, 255))
("dimgray", Color4f(105, 105, 105))
("dimgrey", Color4f(105, 105, 105))
("dodgerblue", Color4f(30, 144, 255))
("firebrick", Color4f(178, 34, 34))
("floralwhite", Color4f(255, 250, 240))
("forestgreen", Color4f(34, 139, 34))
("fuchsia", Color4f(255, 0, 255))
("gainsboro", Color4f(220, 220, 220))
("ghostwhite", Color4f(248, 248, 255))
("gold", Color4f(255, 215, 0))
("goldenrod", Color4f(218, 165, 32))
("gray", Color4f(128, 128, 128))
("green", Color4f(0, 128, 0))
("greenyellow", Color4f(173, 255, 47))
("grey", Color4f(128, 128, 128))
("honeydew", Color4f(240, 255, 240))
("hotpink", Color4f(255, 105, 180))
("indianred", Color4f(205, 92, 92))
("indigo", Color4f(75, 0, 130))
("ivory", Color4f(255, 255, 240))
("khaki", Color4f(240, 230, 140))
("lavender", Color4f(230, 230, 250))
("lavenderblush", Color4f(255, 240, 245))
("lawngreen", Color4f(124, 252, 0))
("lemonchiffon", Color4f(255, 250, 205))
("lightblue", Color4f(173, 216, 230))
("lightcoral", Color4f(240, 128, 128))
("lightcyan", Color4f(224, 255, 255))
("lightgoldenrodyellow", Color4f(250, 250, 210))
("lightgray", Color4f(211, 211, 211))
("lightgreen", Color4f(144, 238, 144))
("lightgrey", Color4f(211, 211, 211))
("lightpink", Color4f(255, 182, 193))
("lightsalmon", Color4f(255, 160, 122))
("lightseagreen", Color4f(32, 178, 170))
("lightskyblue", Color4f(135, 206, 250))
("lightslategray", Color4f(119, 136, 153))
("lightslategrey", Color4f(119, 136, 153))
("lightsteelblue", Color4f(176, 196, 222))
("lightyellow", Color4f(255, 255, 224))
("lime", Color4f(0, 255, 0))
("limegreen", Color4f(50, 205, 50))
("linen", Color4f(250, 240, 230))
("magenta", Color4f(255, 0, 255))
("maroon", Color4f(128, 0, 0))
("mediumaquamarine", Color4f(102, 205, 170))
("mediumblue", Color4f(0, 0, 205))
("mediumorchid", Color4f(186, 85, 211))
("mediumpurple", Color4f(147, 112, 219))
("mediumseagreen", Color4f(60, 179, 113))
("mediumslateblue", Color4f(123, 104, 238))
("mediumspringgreen", Color4f(0, 250, 154))
("mediumturquoise", Color4f(72, 209, 204))
("mediumvioletred", Color4f(199, 21, 133))
("midnightblue", Color4f(25, 25, 112))
("mintcream", Color4f(245, 255, 250))
("mistyrose", Color4f(255, 228, 225))
("moccasin", Color4f(255, 228, 181))
("navajowhite", Color4f(255, 222, 173))
("navy", Color4f(0, 0, 128))
("oldlace", Color4f(253, 245, 230))
("olive", Color4f(128, 128, 0))
("olivedrab", Color4f(107, 142, 35))
("orange", Color4f(255, 165, 0))
("orangered", Color4f(255, 69, 0))
("orchid", Color4f(218, 112, 214))
("palegoldenrod", Color4f(238, 232, 170))
("palegreen", Color4f(152, 251, 152))
("paleturquoise", Color4f(175, 238, 238))
("palevioletred", Color4f(219, 112, 147))
("papayawhip", Color4f(255, 239, 213))
("peachpuff", Color4f(255, 218, 185))
("peru", Color4f(205, 133, 63))
("pink", Color4f(255, 192, 203))
("plum", Color4f(221, 160, 221))
("powderblue", Color4f(176, 224, 230))
("purple", Color4f(128, 0, 128))
("red", Color4f(255, 0, 0))
("rosybrown", Color4f(188, 143, 143))
("royalblue", Color4f(65, 105, 225))
("saddlebrown", Color4f(139, 69, 19))
("salmon", Color4f(250, 128, 114))
("sandybrown", Color4f(244, 164, 96))
("seagreen", Color4f(46, 139, 87))
("seashell", Color4f(255, 245, 238))
("sienna", Color4f(160, 82, 45))
("silver", Color4f(192, 192, 192))
("skyblue", Color4f(135, 206, 235))
("slateblue", Color4f(106, 90, 205))
("slategray", Color4f(112, 128, 144))
("slategrey", Color4f(112, 128, 144))
("snow", Color4f(255, 250, 250))
("springgreen", Color4f(0, 255, 127))
("steelblue", Color4f(70, 130, 180))
("tan", Color4f(210, 180, 140))
("teal", Color4f(0, 128, 128))
("thistle", Color4f(216, 191, 216))
("tomato", Color4f(255, 99, 71))
("transparent", Color4f(0, 0, 0, 0))
("turquoise", Color4f(64, 224, 208))
("violet", Color4f(238, 130, 238))
("wheat", Color4f(245, 222, 179))
("white", Color4f(255, 255, 255))
("whitesmoke", Color4f(245, 245, 245))
("yellow", Color4f(255, 255, 0))
("yellowgreen", Color4f(154, 205, 50));
#pragma once
#include <map>
#include <string>
#include <list>
#include "linalg.h"
#include <boost/unordered/unordered_map.hpp>
enum RenderColor {
BACKGROUND_COLOR,
OPENCSG_FACE_FRONT_COLOR,
OPENCSG_FACE_BACK_COLOR,
CGAL_FACE_FRONT_COLOR,
CGAL_FACE_2D_COLOR,
CGAL_FACE_BACK_COLOR,
CGAL_EDGE_FRONT_COLOR,
CGAL_EDGE_BACK_COLOR,
CGAL_EDGE_2D_COLOR,
CROSSHAIR_COLOR
};
typedef std::map<RenderColor, Color4f> ColorScheme;
class ColorMap
{
public:
static ColorMap *inst(bool erase = false);
const ColorScheme &defaultColorScheme() const;
const boost::unordered_map<std::string, Color4f> &webColors() const { return webcolors; }
const ColorScheme *findColorScheme(const std::string &name) const;
std::list<std::string> colorSchemeNames() const;
static Color4f getColor(const ColorScheme &cs, const RenderColor rc);
private:
ColorMap();
~ColorMap() {}
boost::unordered_map<std::string, Color4f> webcolors;
boost::unordered_map<std::string, ColorScheme> colorschemes;
};

View File

@ -38,6 +38,7 @@ void export_png(const Geometry *root_geom, Camera &cam, std::ostream &output)
glview->setCamera(cam);
glview->setRenderer(&cgalRenderer);
glview->setColorScheme(RenderSettings::inst()->colorscheme);
glview->paintGL();
glview->save(output);
}
@ -85,6 +86,7 @@ void export_png_preview_common(Tree &tree, Camera &cam, std::ostream &output, Pr
OpenCSG::setContext(0);
OpenCSG::setOption(OpenCSG::OffscreenSetting, OpenCSG::FrameBufferObject);
#endif
csgInfo.glview->setColorScheme(RenderSettings::inst()->colorscheme);
csgInfo.glview->paintGL();
csgInfo.glview->save(output);
}

View File

@ -3,7 +3,7 @@
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <Eigen/Dense>
#include<Eigen/StdVector>
#include <Eigen/StdVector>
EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Vector2d)
using Eigen::Vector2d;

View File

@ -28,6 +28,7 @@
#include "ModuleCache.h"
#include "MainWindow.h"
#include "parsersettings.h"
#include "rendersettings.h"
#include "Preferences.h"
#include "printutils.h"
#include "node.h"
@ -409,8 +410,13 @@ MainWindow::MainWindow(const QString &filename)
this, SLOT(openCSGSettingsChanged()));
connect(Preferences::inst(), SIGNAL(syntaxHighlightChanged(const QString&)),
editor, SLOT(setHighlightScheme(const QString&)));
connect(Preferences::inst(), SIGNAL(colorSchemeChanged(const QString&)),
this, SLOT(setColorScheme(const QString&)));
Preferences::inst()->apply();
QString cs = Preferences::inst()->getValue("3dview/colorscheme").toString();
this->setColorScheme(cs);
connect(this->findTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectFindType(int)));
connect(this->findInputField, SIGNAL(returnPressed()), this->nextButton, SLOT(animateClick()));
find_panel->installEventFilter(this);
@ -1917,7 +1923,7 @@ void MainWindow::actionExportCSG()
return;
}
std::ofstream fstream(csg_filename.toUtf8());
std::ofstream fstream(csg_filename.toLocal8Bit());
if (!fstream.is_open()) {
PRINTB("Can't open file \"%s\" for export", csg_filename.toLocal8Bit().constData());
}
@ -1979,6 +1985,7 @@ void MainWindow::viewModePreview()
viewModeActionsUncheck();
viewActionPreview->setChecked(true);
this->qglview->setRenderer(this->opencsgRenderer ? (Renderer *)this->opencsgRenderer : (Renderer *)this->thrownTogetherRenderer);
this->qglview->updateColorScheme();
this->qglview->updateGL();
} else {
viewModeThrownTogether();
@ -1995,6 +2002,7 @@ void MainWindow::viewModeSurface()
viewActionSurfaces->setChecked(true);
this->qglview->setShowFaces(true);
this->qglview->setRenderer(this->cgalRenderer);
this->qglview->updateColorScheme();
this->qglview->updateGL();
}
@ -2004,6 +2012,7 @@ void MainWindow::viewModeWireframe()
viewActionWireframe->setChecked(true);
this->qglview->setShowFaces(false);
this->qglview->setRenderer(this->cgalRenderer);
this->qglview->updateColorScheme();
this->qglview->updateGL();
}
@ -2014,6 +2023,7 @@ void MainWindow::viewModeThrownTogether()
viewModeActionsUncheck();
viewActionThrownTogether->setChecked(true);
this->qglview->setRenderer(this->thrownTogetherRenderer);
this->qglview->updateColorScheme();
this->qglview->updateGL();
}
@ -2352,6 +2362,13 @@ MainWindow::preferences()
Preferences::inst()->raise();
}
void MainWindow::setColorScheme(const QString &scheme)
{
RenderSettings::inst()->colorscheme = scheme.toStdString();
this->qglview->setColorScheme(scheme.toStdString());
this->qglview->updateGL();
}
void MainWindow::setFont(const QString &family, uint size)
{
QFont font;

View File

@ -114,6 +114,7 @@ static void help(const char *progname)
"%2%[ --viewall ] \\\n"
"%2%[ --imgsize=width,height ] [ --projection=(o)rtho|(p)ersp] \\\n"
"%2%[ --render | --preview[=throwntogether] ] \\\n"
"%2%[ --colorscheme=[Cornfield|Sunset|Metallic|Starnight|BeforeDawn|Nature|DeepOcean] ] \\\n"
"%2%[ --csglimit=num ]"
#ifdef ENABLE_EXPERIMENTAL
" [ --enable=<feature> ]"
@ -152,7 +153,7 @@ static void info()
exit(0);
}
Camera get_camera( po::variables_map vm )
Camera get_camera(po::variables_map vm)
{
Camera camera;
@ -623,6 +624,7 @@ int main(int argc, char **argv)
("viewall", "adjust camera to fit object")
("imgsize", po::value<string>(), "=width,height for exporting png")
("projection", po::value<string>(), "(o)rtho or (p)erspective when exporting png")
("colorscheme", po::value<string>(), "colorscheme")
("debug", po::value<string>(), "special debug info")
("o,o", po::value<string>(), "out-file")
("s,s", po::value<string>(), "stl-file")
@ -723,6 +725,19 @@ int main(int argc, char **argv)
}
#endif
if (vm.count("colorscheme")) {
std::string colorscheme = vm["colorscheme"].as<string>();
if (ColorMap::inst()->findColorScheme(colorscheme)) {
RenderSettings::inst()->colorscheme = colorscheme;
} else {
PRINT("Unknown color scheme. Valid schemes:");
BOOST_FOREACH (const std::string &name, ColorMap::inst()->colorSchemeNames()) {
PRINT(name);
}
exit(1);
}
}
currentdir = boosty::stringy(fs::current_path());
Camera camera = get_camera(vm);

View File

@ -239,6 +239,7 @@ static void gl_draw_triangle(GLint *shaderinfo, const Vector3d &p0, const Vector
void PolySet::render_surface(Renderer::csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo) const
{
PRINTD("Polyset render");
bool mirrored = m.matrix().determinant() < 0;
#ifdef ENABLE_OPENCSG
if (shaderinfo) {

View File

@ -3,47 +3,46 @@
#include "Geometry.h"
#include "polyset.h"
#include "Polygon2d.h"
#include "colormap.h"
#include "printutils.h"
bool Renderer::getColor(Renderer::ColorMode colormode, Color4f &col) const
{
switch (colormode) {
case COLORMODE_NONE:
return false;
break;
case COLORMODE_MATERIAL:
col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR);
break;
case COLORMODE_CUTOUT:
col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_BACK_COLOR);
break;
case COLORMODE_HIGHLIGHT:
col.setRgb(255, 81, 81, 128);
break;
case COLORMODE_BACKGROUND:
col.setRgb(180, 180, 180, 128);
break;
case COLORMODE_MATERIAL_EDGES:
col.setRgb(255, 236, 94);
break;
case COLORMODE_CUTOUT_EDGES:
col.setRgb(171, 216, 86);
break;
case COLORMODE_HIGHLIGHT_EDGES:
col.setRgb(255, 171, 86, 128);
break;
case COLORMODE_BACKGROUND_EDGES:
col.setRgb(150, 150, 150, 128);
break;
default:
return false;
break;
if (colormode==COLORMODE_NONE) return false;
if (colormap.count(colormode) > 0) {
col = colormap.at(colormode);
return true;
}
return true;
return false;
}
Renderer::Renderer() : colorscheme(NULL)
{
PRINTD("Renderer() start");
// Setup default colors
// The main colors, MATERIAL and CUTOUT, come from this object's
// colorscheme. Colorschemes don't currently hold information
// for Highlight/Background colors
// but it wouldn't be too hard to make them do so.
// MATERIAL is set by this object's colorscheme
// CUTOUT is set by this object's colorscheme
colormap[COLORMODE_HIGHLIGHT] = Color4f(255, 81, 81, 128);
colormap[COLORMODE_BACKGROUND] = Color4f(180, 180, 180, 128);
// MATERIAL_EDGES is set by this object's colorscheme
// CUTOUT_EDGES is set by this object's colorscheme
colormap[COLORMODE_HIGHLIGHT_EDGES] = Color4f(255, 171, 86, 128);
colormap[COLORMODE_BACKGROUND_EDGES] = Color4f(150, 150, 150, 128);
setColorScheme(ColorMap::inst()->defaultColorScheme());
PRINTD("Renderer() end");
}
void Renderer::setColor(const float color[4], GLint *shaderinfo) const
{
Color4f col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR);
PRINTD("setColor a");
Color4f col;
getColor(COLORMODE_MATERIAL,col);
float c[4] = {color[0], color[1], color[2], color[3]};
if (c[0] < 0) c[0] = col[0];
if (c[1] < 0) c[1] = col[1];
@ -60,6 +59,7 @@ void Renderer::setColor(const float color[4], GLint *shaderinfo) const
void Renderer::setColor(ColorMode colormode, const float color[4], GLint *shaderinfo) const
{
PRINTD("setColor b");
Color4f basecol;
if (getColor(colormode, basecol)) {
if (colormode == COLORMODE_BACKGROUND) {
@ -80,10 +80,25 @@ void Renderer::setColor(ColorMode colormode, const float color[4], GLint *shader
void Renderer::setColor(ColorMode colormode, GLint *shaderinfo) const
{
PRINTD("setColor c");
float c[4] = {-1,-1,-1,-1};
setColor(colormode, c, shaderinfo);
}
/* fill this->colormap with matching entries from the colorscheme. note
this does not change Highlight or Background colors as they are not
represented in the colorscheme (yet). Also edgecolors are currently the
same for CGAL & OpenCSG */
void Renderer::setColorScheme(const ColorScheme &cs) {
PRINTD("setColorScheme");
colormap[COLORMODE_MATERIAL] = ColorMap::getColor(cs, OPENCSG_FACE_FRONT_COLOR);
colormap[COLORMODE_CUTOUT] = ColorMap::getColor(cs, OPENCSG_FACE_BACK_COLOR);
colormap[COLORMODE_MATERIAL_EDGES] = ColorMap::getColor(cs, CGAL_EDGE_FRONT_COLOR);
colormap[COLORMODE_CUTOUT_EDGES] = ColorMap::getColor(cs, CGAL_EDGE_BACK_COLOR);
colormap[COLORMODE_EMPTY_SPACE] = ColorMap::getColor(cs, BACKGROUND_COLOR);
this->colorscheme = &cs;
}
void Renderer::render_surface(shared_ptr<const Geometry> geom, csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo)
{
shared_ptr<const PolySet> ps;

View File

@ -3,6 +3,7 @@
#include "system-gl.h"
#include "linalg.h"
#include "memory.h"
#include "colormap.h"
#ifdef _MSC_VER // NULL
#include <cstdlib>
@ -11,6 +12,7 @@
class Renderer
{
public:
Renderer();
virtual ~Renderer() {}
virtual void draw(bool showfaces, bool showedges) const = 0;
virtual BoundingBox getBoundingBox() const = 0;
@ -35,14 +37,20 @@ public:
COLORMODE_MATERIAL_EDGES,
COLORMODE_CUTOUT_EDGES,
COLORMODE_HIGHLIGHT_EDGES,
COLORMODE_BACKGROUND_EDGES
COLORMODE_BACKGROUND_EDGES,
COLORMODE_EMPTY_SPACE
};
virtual bool getColor(ColorMode colormode, Color4f &col) const;
virtual void setColor(const float color[4], GLint *shaderinfo = NULL) const;
virtual void setColor(ColorMode colormode, GLint *shaderinfo = NULL) const;
virtual void setColor(ColorMode colormode, const float color[4], GLint *shaderinfo = NULL) const;
virtual void setColorScheme(const ColorScheme &cs);
static void render_surface(shared_ptr<const class Geometry> geom, csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo = NULL);
static void render_edges(shared_ptr<const Geometry> geom, csgmode_e csgmode);
protected:
std::map<ColorMode,Color4f> colormap;
const ColorScheme *colorscheme;
};

View File

@ -1,4 +1,6 @@
#include "rendersettings.h"
#include "colormap.h"
#include "printutils.h"
RenderSettings *RenderSettings::inst(bool erase)
{
@ -16,24 +18,5 @@ RenderSettings::RenderSettings()
far_gl_clip_limit = 100000.0;
img_width = 512;
img_height = 512;
this->colors[BACKGROUND_COLOR] = Color4f(0xff, 0xff, 0xe5);
this->colors[OPENCSG_FACE_FRONT_COLOR] = Color4f(0xf9, 0xd7, 0x2c);
this->colors[OPENCSG_FACE_BACK_COLOR] = Color4f(0x9d, 0xcb, 0x51);
this->colors[CGAL_FACE_FRONT_COLOR] = Color4f(0xf9, 0xd7, 0x2c);
this->colors[CGAL_FACE_BACK_COLOR] = Color4f(0x9d, 0xcb, 0x51);
this->colors[CGAL_FACE_2D_COLOR] = Color4f(0x00, 0xbf, 0x99);
this->colors[CGAL_EDGE_FRONT_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colors[CGAL_EDGE_BACK_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colors[CGAL_EDGE_2D_COLOR] = Color4f(0xff, 0x00, 0x00);
this->colors[CROSSHAIR_COLOR] = Color4f(0x80, 0x00, 0x00);
}
Color4f RenderSettings::color(RenderColor idx)
{
return this->colors[idx];
}
void RenderSettings::setColors(const std::map<RenderColor, Color4f> &colors)
{
this->colors = colors;
colorscheme = "Cornfield";
}

View File

@ -2,33 +2,17 @@
#include <map>
#include "linalg.h"
#include "colormap.h"
class RenderSettings
{
public:
static RenderSettings *inst(bool erase = false);
enum RenderColor {
BACKGROUND_COLOR,
OPENCSG_FACE_FRONT_COLOR,
OPENCSG_FACE_BACK_COLOR,
CGAL_FACE_FRONT_COLOR,
CGAL_FACE_2D_COLOR,
CGAL_FACE_BACK_COLOR,
CGAL_EDGE_FRONT_COLOR,
CGAL_EDGE_BACK_COLOR,
CGAL_EDGE_2D_COLOR,
CROSSHAIR_COLOR
};
void setColors(const std::map<RenderColor, Color4f> &colors);
Color4f color(RenderColor idx);
unsigned int openCSGTermLimit, img_width, img_height;
double far_gl_clip_limit;
std::string colorscheme;
private:
RenderSettings();
~RenderSettings() {}
std::map<RenderColor, Color4f> colors;
};

View File

@ -2,13 +2,14 @@
#include <string>
#include <vector>
#include <utility>
#include <boost/shared_ptr.hpp>
class Assignment : public std::pair<std::string, boost::shared_ptr<class Expression> >
{
public:
Assignment(std::string name) : pair(name, boost::shared_ptr<class Expression>()) {}
Assignment(std::string name, boost::shared_ptr<class Expression> expr) : pair(name, expr) {}
Assignment(std::string name) { first = name; second = boost::shared_ptr<class Expression>(); }
Assignment(std::string name, boost::shared_ptr<class Expression> expr) { first = name; second = expr; }
};
typedef std::vector<Assignment> AssignmentList;

View File

@ -622,6 +622,7 @@ set(CORE_SOURCES
../src/parsersettings.cc
../src/mathc99.cc
../src/linalg.cc
../src/colormap.cc
../src/Camera.cc
../src/handle_dep.cc
../src/value.cc
@ -905,6 +906,18 @@ function(add_cmdline_test TESTCMD_BASENAME)
if (${DISABLED} EQUAL -1)
set(EXPERIMENTAL_OPTION "")
string(REGEX MATCH "csgtexttest" match_result1 ${TEST_FULLNAME})
string(REGEX MATCH "cgalstlsanity" match_result2 ${TEST_FULLNAME})
string(REGEX MATCH "dumptest" match_result3 ${TEST_FULLNAME})
if( "${match_result1}" STREQUAL "" )
if( "${match_result2}" STREQUAL "" )
if( "${match_result3}" STREQUAL "" )
set(EXPERIMENTAL_OPTION "--enable=text")
endif()
endif()
endif()
# 2D tests should be viewed from the top, not an angle.
set(CAMERA_OPTION "")
foreach(test2d IN LISTS TESTS_2D)
@ -933,7 +946,7 @@ function(add_cmdline_test TESTCMD_BASENAME)
set(FILENAME_OPTION -f ${FILE_BASENAME})
endif()
add_test(NAME ${TEST_FULLNAME} ${CONFARG} ${CONFVAL} COMMAND ${PYTHON_EXECUTABLE} ${tests_SOURCE_DIR}/test_cmdline_tool.py --comparator=${COMPARATOR} -c ${IMAGE_COMPARE_EXECUTABLE} -s ${TESTCMD_SUFFIX} ${EXTRA_OPTIONS} ${TESTNAME_OPTION} ${FILENAME_OPTION} ${TESTCMD_EXE} ${TESTCMD_SCRIPT} "${SCADFILE}" ${CAMERA_OPTION} ${TESTCMD_ARGS})
add_test(NAME ${TEST_FULLNAME} ${CONFARG} ${CONFVAL} COMMAND ${PYTHON_EXECUTABLE} ${tests_SOURCE_DIR}/test_cmdline_tool.py --comparator=${COMPARATOR} -c ${IMAGE_COMPARE_EXECUTABLE} -s ${TESTCMD_SUFFIX} ${EXTRA_OPTIONS} ${TESTNAME_OPTION} ${FILENAME_OPTION} ${TESTCMD_EXE} ${TESTCMD_SCRIPT} "${SCADFILE}" ${CAMERA_OPTION} ${EXPERIMENTAL_OPTION} ${TESTCMD_ARGS})
set_property(TEST ${TEST_FULLNAME} PROPERTY ENVIRONMENT "${CTEST_ENVIRONMENT}")
endif()
endforeach()
@ -1028,6 +1041,8 @@ disable_tests(
offpngtest_iteration
stlpngtest_fractal
offpngtest_fractal
stlpngtest_logo_and_text
offpngtest_logo_and_text
)
# mark which tests are 2d (regex match inside add_cmdline_test)
@ -1085,7 +1100,23 @@ set_test_config(Heavy cgalpngtest_rotate_extrude-tests
cgalpngtest_linear_extrude-scale-zero-tests
csgpngtest_linear_extrude-scale-zero-tests
cgalpngtest_sphere-tests
csgpngtest_resize-tests)
csgpngtest_resize-tests
csgpngtest_resize-tests
stlpngtest_fence
stlpngtest_surface
stlpngtest_demo_cut
stlpngtest_search
stlpngtest_rounded_box
stlpngtest_difference
stlpngtest_translation
offpngtest_fence
offpngtest_surface
offpngtest_demo_cut
offpngtest_search
offpngtest_rounded_box
offpngtest_difference
offpngtest_translation
)
# Bugs
@ -1313,11 +1344,35 @@ add_cmdline_test(openscad-cameyeortho-viewall EXE ${OPENSCAD_BINPATH}
SUFFIX png
FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/features/camera-tests.scad)
# Colorscheme tests
add_cmdline_test(openscad-colorscheme-cornfield EXE ${OPENSCAD_BINPATH}
ARGS --colorscheme=Cornfield -o
SUFFIX png
FILES ${CMAKE_SOURCE_DIR}/../examples/Basics/difference_cube.scad)
add_cmdline_test(openscad-colorscheme-metallic EXE ${OPENSCAD_BINPATH}
ARGS --colorscheme=Metallic -o
SUFFIX png
FILES ${CMAKE_SOURCE_DIR}/../examples/Basics/difference_cube.scad)
add_cmdline_test(openscad-colorscheme-metallic-render EXE ${OPENSCAD_BINPATH}
ARGS --colorscheme=Metallic --render -o
SUFFIX png
FILES ${CMAKE_SOURCE_DIR}/../examples/Basics/difference_cube.scad)
add_cmdline_test(openscad-colorscheme-sunset EXE ${OPENSCAD_BINPATH}
ARGS --colorscheme=Sunset -o
SUFFIX png
FILES ${CMAKE_SOURCE_DIR}/../examples/Basics/difference_cube.scad)
add_cmdline_test(openscad-colorscheme-starnight EXE ${OPENSCAD_BINPATH}
ARGS --colorscheme=Starnight -o
SUFFIX png
FILES ${CMAKE_SOURCE_DIR}/../examples/Basics/difference_cube.scad)
add_cmdline_test(openscad-colorscheme-monotone EXE ${OPENSCAD_BINPATH}
ARGS --colorscheme=Monotone -o
SUFFIX png
FILES ${CMAKE_SOURCE_DIR}/../examples/Basics/difference_cube.scad)
#message("Available test configurations: ${TEST_CONFIGS}")
#foreach(CONF ${TEST_CONFIGS})
# message("${CONF}: ${${CONF}_TEST_CONFIG}")
#endforeach()
message("CPPFLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CPPFLAGS: ${CMAKE_CXX_FLAGS}")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 22 KiB