diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CSGTermEvaluator.cc | 2 | ||||
| -rw-r--r-- | src/OpenCSGRenderer.cc | 4 | ||||
| -rw-r--r-- | src/ThrownTogetherRenderer.cc | 6 | ||||
| -rw-r--r-- | src/colornode.h | 3 | ||||
| -rw-r--r-- | src/csgterm.cc | 7 | ||||
| -rw-r--r-- | src/csgterm.h | 8 | ||||
| -rw-r--r-- | src/linalg.h | 6 | ||||
| -rw-r--r-- | src/renderer.cc | 2 | ||||
| -rw-r--r-- | src/renderer.h | 2 | ||||
| -rw-r--r-- | src/state.h | 16 | 
10 files changed, 31 insertions, 25 deletions
| diff --git a/src/CSGTermEvaluator.cc b/src/CSGTermEvaluator.cc index 65209dd..4624d4c 100644 --- a/src/CSGTermEvaluator.cc +++ b/src/CSGTermEvaluator.cc @@ -159,7 +159,7 @@ Response CSGTermEvaluator::visit(State &state, const TransformNode &node)  Response CSGTermEvaluator::visit(State &state, const ColorNode &node)  {  	if (state.isPrefix()) { -		state.setColor(node.color); +		if (!state.color().isValid()) state.setColor(node.color);  	}  	if (state.isPostfix()) {  		applyToChildren(node, CSGT_UNION); diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc index 233124b..eb66687 100644 --- a/src/OpenCSGRenderer.cc +++ b/src/OpenCSGRenderer.cc @@ -86,7 +86,7 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,  			if (shaderinfo) glUseProgram(shaderinfo[0]);  			for (; j < i; j++) {  				const Transform3d &m = chain->matrices[j]; -				double *c = chain->colors[j]; +				const Color4f &c = chain->colors[j];  				glPushMatrix();  				glMultMatrixd(m.data());  				PolySet::csgmode_e csgmode = chain->types[j] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL; @@ -99,7 +99,7 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,  					csgmode = PolySet::csgmode_e(csgmode + 10);  				} else if (c[0] >= 0 || c[1] >= 0 || c[2] >= 0 || c[3] >= 0) {  					// User-defined color or alpha from source -					setColor(c, shaderinfo); +					setColor(c.data(), shaderinfo);  				} else if (chain->types[j] == CSGTerm::TYPE_DIFFERENCE) {  					setColor(COLORMODE_CUTOUT, shaderinfo);  				} else { diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc index 36f7b95..146d2e1 100644 --- a/src/ThrownTogetherRenderer.cc +++ b/src/ThrownTogetherRenderer.cc @@ -67,7 +67,7 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,  		if (polySetVisitMark[std::make_pair(chain->polysets[i].get(), &chain->matrices[i])]++ > 0)  			continue;  		const Transform3d &m = chain->matrices[i]; -		double *c = chain->colors[i]; +		const Color4f &c = chain->colors[i];  		glPushMatrix();  		glMultMatrixd(m.data());  		PolySet::csgmode_e csgmode  = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL; @@ -93,10 +93,10 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,  			else csgmode = PolySet::csgmode_e(csgmode);  			chain->polysets[i]->render_surface(csgmode, m);  		} else if (c[0] >= 0 || c[1] >= 0 || c[2] >= 0 || c[3] >= 0) { -			setColor(c); +			setColor(c.data());  			chain->polysets[i]->render_surface(csgmode, m);  			if (showedges) { -				glColor4d((c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0); +				glColor4f((c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0);  				chain->polysets[i]->render_edges(csgmode);  			}  		} else if (chain->types[i] == CSGTerm::TYPE_DIFFERENCE) { diff --git a/src/colornode.h b/src/colornode.h index b41e2a9..9323638 100644 --- a/src/colornode.h +++ b/src/colornode.h @@ -3,6 +3,7 @@  #include "node.h"  #include "visitor.h" +#include "linalg.h"  class ColorNode : public AbstractNode  { @@ -14,7 +15,7 @@ public:  	virtual std::string toString() const;  	virtual std::string name() const; -	double color[4]; +	Color4f color;  };  #endif diff --git a/src/csgterm.cc b/src/csgterm.cc index 56fcbb5..890b0c9 100644 --- a/src/csgterm.cc +++ b/src/csgterm.cc @@ -89,10 +89,9 @@ shared_ptr<CSGTerm> CSGTerm::createCSGTerm(type_e type, CSGTerm *left, CSGTerm *  	return createCSGTerm(type, shared_ptr<CSGTerm>(left), shared_ptr<CSGTerm>(right));  } -CSGTerm::CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const double color[4], const std::string &label) -	: type(TYPE_PRIMITIVE), polyset(polyset), label(label), m(matrix) +CSGTerm::CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const Color4f &color, const std::string &label) +	: type(TYPE_PRIMITIVE), polyset(polyset), label(label), m(matrix), color(color)  { -	for (int i = 0; i < 4; i++) this->color[i] = color[i];  	initBoundingBox();  } @@ -281,7 +280,7 @@ CSGChain::CSGChain()  {  } -void CSGChain::add(const shared_ptr<PolySet> &polyset, const Transform3d &m, double *color, CSGTerm::type_e type, std::string label) +void CSGChain::add(const shared_ptr<PolySet> &polyset, const Transform3d &m, const Color4f &color, CSGTerm::type_e type, std::string label)  {  	polysets.push_back(polyset);  	matrices.push_back(m); diff --git a/src/csgterm.h b/src/csgterm.h index 4930349..570af53 100644 --- a/src/csgterm.h +++ b/src/csgterm.h @@ -28,7 +28,7 @@ public:  	shared_ptr<CSGTerm> right;  	BoundingBox bbox; -	CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const double color[4], const std::string &label); +	CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const Color4f &color, const std::string &label);  	~CSGTerm();  	const BoundingBox &getBoundingBox() const { return this->bbox; } @@ -44,7 +44,7 @@ private:  	void initBoundingBox();  	Transform3d m; -	double color[4]; +	Color4f color;  	friend class CSGChain;  }; @@ -54,13 +54,13 @@ class CSGChain  public:  	std::vector<shared_ptr<PolySet> > polysets;  	std::vector<Transform3d> matrices; -	std::vector<double*> colors; +	std::vector<Color4f> colors;  	std::vector<CSGTerm::type_e> types;  	std::vector<std::string> labels;  	CSGChain(); -	void add(const shared_ptr<PolySet> &polyset, const Transform3d &m, double *color, CSGTerm::type_e type, std::string label); +	void add(const shared_ptr<PolySet> &polyset, const Transform3d &m, const Color4f &color, CSGTerm::type_e type, std::string label);  	void import(shared_ptr<CSGTerm> term, CSGTerm::type_e type = CSGTerm::TYPE_UNION);  	std::string dump(); diff --git a/src/linalg.h b/src/linalg.h index c1a14d1..15ef870 100644 --- a/src/linalg.h +++ b/src/linalg.h @@ -15,4 +15,10 @@ using Eigen::Transform3d;  BoundingBox operator*(const Transform3d &m, const BoundingBox &box); +class Color4f : public Eigen::Vector4f +{ +public: +	bool isValid() const { return this->minCoeff() >= 0.0f; } +}; +  #endif diff --git a/src/renderer.cc b/src/renderer.cc index b791673..5a767b8 100644 --- a/src/renderer.cc +++ b/src/renderer.cc @@ -2,7 +2,7 @@  #include "rendersettings.h"  #include <QColor> -void Renderer::setColor(const double color[4], GLint *shaderinfo) const +void Renderer::setColor(const float color[4], GLint *shaderinfo) const  {  	QColor col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR);  	double c[4] = {color[0], color[1], color[2], color[3]}; diff --git a/src/renderer.h b/src/renderer.h index 8deabe8..2bc482d 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -25,7 +25,7 @@ public:  		COLORMODE_BACKGROUND_EDGES  	}; -	virtual void setColor(const double color[4], GLint *shaderinfo = NULL) const; +	virtual void setColor(const float color[4], GLint *shaderinfo = NULL) const;  	virtual void setColor(ColorMode colormode, GLint *shaderinfo = NULL) const;  }; diff --git a/src/state.h b/src/state.h index 5dc74df..df202aa 100644 --- a/src/state.h +++ b/src/state.h @@ -9,8 +9,8 @@ class State  public:    State(const class AbstractNode *parent)       : parentnode(parent), isprefix(false), ispostfix(false), numchildren(0) { -		m = Transform3d::Identity(); -		for (int i=0;i<4;i++) this->c[i] = -1.0; +		this->matrix_ = Transform3d::Identity(); +		this->color_.fill(-1.0f);  	}    virtual ~State() {} @@ -18,15 +18,15 @@ public:    void setPostfix(bool on) { this->ispostfix = on; }    void setNumChildren(unsigned int numc) { this->numchildren = numc; }    void setParent(const AbstractNode *parent) { this->parentnode = parent; } -	void setMatrix(const Transform3d &m) { this->m = m; } -	void setColor(const double c[4]) { memcpy(this->c, c, 4*sizeof(double)); } +	void setMatrix(const Transform3d &m) { this->matrix_ = m; } +	void setColor(const Color4f &c) { this->color_ = c; }    bool isPrefix() const { return this->isprefix; }    bool isPostfix() const { return this->ispostfix; }    unsigned int numChildren() const { return this->numchildren; }    const AbstractNode *parent() const { return this->parentnode; } -	const Transform3d &matrix() const { return this->m; } -	const double *color() const { return this->c; } +	const Transform3d &matrix() const { return this->matrix_; } +	const Color4f &color() const { return this->color_; }  private:    const AbstractNode * parentnode; @@ -35,8 +35,8 @@ private:    unsigned int numchildren;  	// Transformation matrix and color. FIXME: Generalize such state variables? -	Transform3d m; -	double c[4]; +	Transform3d matrix_; +	Color4f color_;  };  #endif | 
