mirror of https://github.com/vitalif/openscad
Ported color handling away from Qt
parent
5ac6b66dfb
commit
67fe0adb90
21
src/color.cc
21
src/color.cc
|
@ -31,8 +31,9 @@
|
|||
#include "printutils.h"
|
||||
#include <sstream>
|
||||
#include <assert.h>
|
||||
#include <QColor>
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/assign/std/vector.hpp>
|
||||
#include <boost/assign/list_of.hpp>
|
||||
using namespace boost::assign; // bring 'operator+=()' into scope
|
||||
|
||||
class ColorModule : public AbstractModule
|
||||
|
@ -40,8 +41,13 @@ class ColorModule : public AbstractModule
|
|||
public:
|
||||
ColorModule() { }
|
||||
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
|
||||
|
||||
private:
|
||||
static boost::unordered_map<std::string, Vector3f> colormap;
|
||||
};
|
||||
|
||||
#include "colormap.h"
|
||||
|
||||
AbstractNode *ColorModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const
|
||||
{
|
||||
ColorNode *node = new ColorNode(inst);
|
||||
|
@ -63,12 +69,13 @@ AbstractNode *ColorModule::evaluate(const Context *ctx, const ModuleInstantiatio
|
|||
node->color[i] = i < v.vec.size() ? v.vec[i]->num : 1.0;
|
||||
} else if (v.type == Value::STRING) {
|
||||
std::string colorname = v.text;
|
||||
QColor color;
|
||||
color.setNamedColor(QString::fromStdString(colorname));
|
||||
if (color.isValid()) {
|
||||
node->color[0] = color.redF();
|
||||
node->color[1] = color.greenF();
|
||||
node->color[2] = color.blueF();
|
||||
boost::algorithm::to_lower(colorname);
|
||||
Vector3f color;
|
||||
if (colormap.find(colorname) != colormap.end()) {
|
||||
color = colormap[colorname];
|
||||
node->color[0] = color[0]/255;
|
||||
node->color[1] = color[1]/255;
|
||||
node->color[2] = color[2]/255;
|
||||
} else {
|
||||
PRINTF_NOCACHE("WARNING: Color name \"%s\" unknown. Please see", colorname.c_str());
|
||||
PRINTF_NOCACHE("WARNING: http://en.wikipedia.org/wiki/Web_colors");
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
boost::unordered_map<std::string, Vector3f> ColorModule::colormap = map_list_of
|
||||
("aliceblue", Vector3f(240, 248, 255))
|
||||
("antiquewhite", Vector3f(250, 235, 215))
|
||||
("aqua", Vector3f(0, 255, 255))
|
||||
("aquamarine", Vector3f(127, 255, 212))
|
||||
("azure", Vector3f(240, 255, 255))
|
||||
("beige", Vector3f(245, 245, 220))
|
||||
("bisque", Vector3f(255, 228, 196))
|
||||
("black", Vector3f(0, 0, 0))
|
||||
("blanchedalmond", Vector3f(255, 235, 205))
|
||||
("blue", Vector3f(0, 0, 255))
|
||||
("blueviolet", Vector3f(138, 43, 226))
|
||||
("brown", Vector3f(165, 42, 42))
|
||||
("burlywood", Vector3f(222, 184, 135))
|
||||
("cadetblue", Vector3f(95, 158, 160))
|
||||
("chartreuse", Vector3f(127, 255, 0))
|
||||
("chocolate", Vector3f(210, 105, 30))
|
||||
("coral", Vector3f(255, 127, 80))
|
||||
("cornflowerblue", Vector3f(100, 149, 237))
|
||||
("cornsilk", Vector3f(255, 248, 220))
|
||||
("crimson", Vector3f(220, 20, 60))
|
||||
("cyan", Vector3f(0, 255, 255))
|
||||
("darkblue", Vector3f(0, 0, 139))
|
||||
("darkcyan", Vector3f(0, 139, 139))
|
||||
("darkgoldenrod", Vector3f(184, 134, 11))
|
||||
("darkgray", Vector3f(169, 169, 169))
|
||||
("darkgreen", Vector3f(0, 100, 0))
|
||||
("darkgrey", Vector3f(169, 169, 169))
|
||||
("darkkhaki", Vector3f(189, 183, 107))
|
||||
("darkmagenta", Vector3f(139, 0, 139))
|
||||
("darkolivegreen", Vector3f(85, 107, 47))
|
||||
("darkorange", Vector3f(255, 140, 0))
|
||||
("darkorchid", Vector3f(153, 50, 204))
|
||||
("darkred", Vector3f(139, 0, 0))
|
||||
("darksalmon", Vector3f(233, 150, 122))
|
||||
("darkseagreen", Vector3f(143, 188, 143))
|
||||
("darkslateblue", Vector3f(72, 61, 139))
|
||||
("darkslategray", Vector3f(47, 79, 79))
|
||||
("darkslategrey", Vector3f(47, 79, 79))
|
||||
("darkturquoise", Vector3f(0, 206, 209))
|
||||
("darkviolet", Vector3f(148, 0, 211))
|
||||
("deeppink", Vector3f(255, 20, 147))
|
||||
("deepskyblue", Vector3f(0, 191, 255))
|
||||
("dimgray", Vector3f(105, 105, 105))
|
||||
("dimgrey", Vector3f(105, 105, 105))
|
||||
("dodgerblue", Vector3f(30, 144, 255))
|
||||
("firebrick", Vector3f(178, 34, 34))
|
||||
("floralwhite", Vector3f(255, 250, 240))
|
||||
("forestgreen", Vector3f(34, 139, 34))
|
||||
("fuchsia", Vector3f(255, 0, 255))
|
||||
("gainsboro", Vector3f(220, 220, 220))
|
||||
("ghostwhite", Vector3f(248, 248, 255))
|
||||
("gold", Vector3f(255, 215, 0))
|
||||
("goldenrod", Vector3f(218, 165, 32))
|
||||
("gray", Vector3f(128, 128, 128))
|
||||
("green", Vector3f(0, 128, 0))
|
||||
("greenyellow", Vector3f(173, 255, 47))
|
||||
("grey", Vector3f(128, 128, 128))
|
||||
("honeydew", Vector3f(240, 255, 240))
|
||||
("hotpink", Vector3f(255, 105, 180))
|
||||
("indianred", Vector3f(205, 92, 92))
|
||||
("indigo", Vector3f(75, 0, 130))
|
||||
("ivory", Vector3f(255, 255, 240))
|
||||
("khaki", Vector3f(240, 230, 140))
|
||||
("lavender", Vector3f(230, 230, 250))
|
||||
("lavenderblush", Vector3f(255, 240, 245))
|
||||
("lawngreen", Vector3f(124, 252, 0))
|
||||
("lemonchiffon", Vector3f(255, 250, 205))
|
||||
("lightblue", Vector3f(173, 216, 230))
|
||||
("lightcoral", Vector3f(240, 128, 128))
|
||||
("lightcyan", Vector3f(224, 255, 255))
|
||||
("lightgoldenrodyellow", Vector3f(250, 250, 210))
|
||||
("lightgray", Vector3f(211, 211, 211))
|
||||
("lightgreen", Vector3f(144, 238, 144))
|
||||
("lightgrey", Vector3f(211, 211, 211))
|
||||
("lightpink", Vector3f(255, 182, 193))
|
||||
("lightsalmon", Vector3f(255, 160, 122))
|
||||
("lightseagreen", Vector3f(32, 178, 170))
|
||||
("lightskyblue", Vector3f(135, 206, 250))
|
||||
("lightslategray", Vector3f(119, 136, 153))
|
||||
("lightslategrey", Vector3f(119, 136, 153))
|
||||
("lightsteelblue", Vector3f(176, 196, 222))
|
||||
("lightyellow", Vector3f(255, 255, 224))
|
||||
("lime", Vector3f(0, 255, 0))
|
||||
("limegreen", Vector3f(50, 205, 50))
|
||||
("linen", Vector3f(250, 240, 230))
|
||||
("magenta", Vector3f(255, 0, 255))
|
||||
("maroon", Vector3f(128, 0, 0))
|
||||
("mediumaquamarine", Vector3f(102, 205, 170))
|
||||
("mediumblue", Vector3f(0, 0, 205))
|
||||
("mediumorchid", Vector3f(186, 85, 211))
|
||||
("mediumpurple", Vector3f(147, 112, 219))
|
||||
("mediumseagreen", Vector3f(60, 179, 113))
|
||||
("mediumslateblue", Vector3f(123, 104, 238))
|
||||
("mediumspringgreen", Vector3f(0, 250, 154))
|
||||
("mediumturquoise", Vector3f(72, 209, 204))
|
||||
("mediumvioletred", Vector3f(199, 21, 133))
|
||||
("midnightblue", Vector3f(25, 25, 112))
|
||||
("mintcream", Vector3f(245, 255, 250))
|
||||
("mistyrose", Vector3f(255, 228, 225))
|
||||
("moccasin", Vector3f(255, 228, 181))
|
||||
("navajowhite", Vector3f(255, 222, 173))
|
||||
("navy", Vector3f(0, 0, 128))
|
||||
("oldlace", Vector3f(253, 245, 230))
|
||||
("olive", Vector3f(128, 128, 0))
|
||||
("olivedrab", Vector3f(107, 142, 35))
|
||||
("orange", Vector3f(255, 165, 0))
|
||||
("orangered", Vector3f(255, 69, 0))
|
||||
("orchid", Vector3f(218, 112, 214))
|
||||
("palegoldenrod", Vector3f(238, 232, 170))
|
||||
("palegreen", Vector3f(152, 251, 152))
|
||||
("paleturquoise", Vector3f(175, 238, 238))
|
||||
("palevioletred", Vector3f(219, 112, 147))
|
||||
("papayawhip", Vector3f(255, 239, 213))
|
||||
("peachpuff", Vector3f(255, 218, 185))
|
||||
("peru", Vector3f(205, 133, 63))
|
||||
("pink", Vector3f(255, 192, 203))
|
||||
("plum", Vector3f(221, 160, 221))
|
||||
("powderblue", Vector3f(176, 224, 230))
|
||||
("purple", Vector3f(128, 0, 128))
|
||||
("red", Vector3f(255, 0, 0))
|
||||
("rosybrown", Vector3f(188, 143, 143))
|
||||
("royalblue", Vector3f(65, 105, 225))
|
||||
("saddlebrown", Vector3f(139, 69, 19))
|
||||
("salmon", Vector3f(250, 128, 114))
|
||||
("sandybrown", Vector3f(244, 164, 96))
|
||||
("seagreen", Vector3f(46, 139, 87))
|
||||
("seashell", Vector3f(255, 245, 238))
|
||||
("sienna", Vector3f(160, 82, 45))
|
||||
("silver", Vector3f(192, 192, 192))
|
||||
("skyblue", Vector3f(135, 206, 235))
|
||||
("slateblue", Vector3f(106, 90, 205))
|
||||
("slategray", Vector3f(112, 128, 144))
|
||||
("slategrey", Vector3f(112, 128, 144))
|
||||
("snow", Vector3f(255, 250, 250))
|
||||
("springgreen", Vector3f(0, 255, 127))
|
||||
("steelblue", Vector3f(70, 130, 180))
|
||||
("tan", Vector3f(210, 180, 140))
|
||||
("teal", Vector3f(0, 128, 128))
|
||||
("thistle", Vector3f(216, 191, 216))
|
||||
("tomato", Vector3f(255, 99, 71))
|
||||
("turquoise", Vector3f(64, 224, 208))
|
||||
("violet", Vector3f(238, 130, 238))
|
||||
("wheat", Vector3f(245, 222, 179))
|
||||
("white", Vector3f(255, 255, 255))
|
||||
("whitesmoke", Vector3f(245, 245, 245))
|
||||
("yellow", Vector3f(255, 255, 0))
|
||||
("yellowgreen", Vector3f(154, 205, 50));
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
using Eigen::Vector2d;
|
||||
using Eigen::Vector3d;
|
||||
using Eigen::Vector3f;
|
||||
typedef Eigen::AlignedBox<double, 3> BoundingBox;
|
||||
using Eigen::Matrix3f;
|
||||
using Eigen::Matrix3d;
|
||||
|
|
Loading…
Reference in New Issue