00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _UT_Ramp_
00022 #define _UT_Ramp_
00023
00024 #include "UT_API.h"
00025
00026
00027
00028
00029 #include <iostream.h>
00030 #include <SYS/SYS_Types.h>
00031 #include "UT_AssocArray.h"
00032 #include "UT_Color.h"
00033 #include "UT_Spline.h"
00034
00035 class UT_Raster;
00036 class UT_RGBA;
00037 class UT_BIG_RGBA;
00038 class UT_IStream;
00039 class UT_IntArray;
00040
00041 enum UT_RampOrient {
00042 UT_RAMP_HORIZONTAL,
00043 UT_RAMP_VERTICAL,
00044 UT_RAMP_RADIAL,
00045 UT_RAMP_CONCENTRIC
00046 };
00047
00048 class UT_API UT_FRGBA {
00049 public:
00050 UT_FRGBA() {};
00051 UT_FRGBA(fpreal red, fpreal green, fpreal blue, fpreal alpha)
00052 { r = red; g = green; b = blue; a = alpha; }
00053
00054 float r, g, b, a;
00055 };
00056
00057 class UT_API UT_ColorNode {
00058 public:
00059 UT_ColorNode() {}
00060 UT_ColorNode(fpreal offset, const UT_FRGBA &color,
00061 UT_SPLINE_BASIS basis_ = UT_SPLINE_LINEAR,
00062 bool enable_pos_ = true,
00063 bool enable_val_ = true,
00064 bool enable_interp_ = true)
00065 {
00066 t = offset;
00067 rgba = color;
00068 basis = basis_;
00069 enable_pos = enable_pos_;
00070 enable_val = enable_val_;
00071 enable_interp = enable_interp_;
00072 }
00073
00074 float t;
00075 UT_FRGBA rgba;
00076 UT_SPLINE_BASIS basis;
00077 bool enable_pos:1,
00078 enable_val:1,
00079 enable_interp:1;
00080 };
00081
00082
00083
00084 class UT_API UT_Ramp {
00085 public:
00086 UT_Ramp();
00087 UT_Ramp(const UT_Ramp ©);
00088 ~UT_Ramp();
00089
00090 void setColorType(UT_ColorType color_space)
00091 { myColorType = color_space; }
00092 UT_ColorType getColorType() const
00093 { return myColorType; }
00094
00095 void clearAndDestroy();
00096
00097 bool getGlobalEnable() const
00098 { return myGlobalEnable; }
00099 void setGlobalEnable(bool enable)
00100 { myGlobalEnable = enable; }
00101
00102 int getNodeCount() const { return myNumNodes; };
00103 const UT_ColorNode *getNode(int i) const;
00104
00105 UT_ColorNode *getRamp() { return myNodes; };
00106 const UT_ColorNode *getRamp() const { return myNodes; };
00107
00108 void convertToRaster( UT_Raster *raster,
00109 UT_RampOrient dir,
00110 int doInterping = 1,
00111
00112
00113 fpreal cx = 0.0f,
00114 fpreal cy = 0.0f,
00115 fpreal phase = 0.0f,
00116
00117 fpreal radius = 1.0f);
00118
00119 const UT_ColorNode *getClosestNode(fpreal pos) const;
00120 int getClosestNodeIndex(fpreal pos) const;
00121
00122 const UT_ColorNode *getCurrentNode() const;
00123 int getCurrentNodeIndex() const;
00124 void setCurrentNodeIndex(int i, bool add_to_selection);
00125
00126 void getColor(fpreal pos, UT_FRGBA *clr,
00127 int doInterping = 1) const;
00128 void getColor(fpreal pos, float fvals[4],
00129 int doInterping = 1) const;
00130 void getColor(UT_FRGBA *values, int num,
00131 int doInterping = 1) const;
00132
00133 void setColorAt(int i, float fvals[4]);
00134 void setColorAt(int i, const UT_FRGBA &clr);
00135 void setCurrentNodeColor(float fvals[4]);
00136 void setCurrentNodeColor(const UT_FRGBA &clr);
00137
00138 void setCurrentNodeBasis(UT_SPLINE_BASIS basis);
00139 void setNodeBasis(int i, UT_SPLINE_BASIS basis);
00140
00141 void setEnable(int i, bool enable_pos, bool enable_val,
00142 bool enable_interp);
00143 bool getEnablePos(int i) const;
00144 bool getEnableVal(int i) const;
00145 bool getEnableInterp(int i) const;
00146
00147 void clearSelection();
00148 bool isNodeSelected(int i);
00149 void selectNode(int i, bool add);
00150 void selectRange(int first_i, int last_i, bool add);
00151 void deselectNode(int i);
00152 void toggleSelectNode(int i);
00153 void getSelectionIndices(UT_IntArray &indices);
00154 void setSelectionIndices(const UT_IntArray &indices);
00155
00156 void addNode(fpreal pos);
00157 void addNode(fpreal pos, float fvals[4],
00158 UT_SPLINE_BASIS basis = UT_SPLINE_LINEAR);
00159 void addNode(fpreal pos, const UT_FRGBA &color,
00160 UT_SPLINE_BASIS basis = UT_SPLINE_LINEAR);
00161
00162 bool deleteNode(fpreal pos);
00163 bool deleteNodeAt(int i);
00164 void deleteSelectedNodes();
00165
00166 void moveNode(const UT_ColorNode *node, fpreal pos);
00167
00168 int load(const char *pathname);
00169 bool load(UT_IStream &is);
00170 int save(const char *pathname) const;
00171 int save(ostream &os) const;
00172
00173 UT_Ramp &operator=(const UT_Ramp &from);
00174
00175 void setRamp(const UT_ColorNode *r, int size);
00176
00177 void rampLookup(fpreal pos, float values[4]) const;
00178 void rampLookupNoInterp(fpreal pos, float values[4]) const;
00179 void rampLookup(fpreal u0, fpreal u1, float values[4],
00180 int ns) const;
00181 void rampLookupNoInterp(fpreal u0, fpreal u1, float values[4],
00182 int ns) const;
00183
00184 private:
00185 UT_RGBA *sampleColors (int nsamples, int doInterp);
00186 UT_BIG_RGBA *sampleColors16(int nsamples, int doInterp);
00187 void convertToRaster8 (UT_Raster *raster,UT_RampOrient dir,
00188 int doInterp, fpreal cx, fpreal cy, fpreal phase,
00189 fpreal radius);
00190 void convertToRaster16(UT_Raster *raster,UT_RampOrient dir,
00191 int doInterp, fpreal cx, fpreal cy, fpreal phase,
00192 fpreal radius);
00193
00194 void getColorAndMultiply(fpreal pos, int do_interp,
00195 UT_RGBA *pixel);
00196 void getColorAndMultiply(fpreal pos, int do_interp,
00197 UT_BIG_RGBA *pixel);
00198
00199 void interpColor(fpreal pos, int i1, float vals[4]) const;
00200
00201 void updateSpline() const;
00202 void evaluateSpline(fpreal pos, fpreal t0, fpreal t1,
00203 int i, float *val) const;
00204
00205 private:
00206 int myNumNodes;
00207 UT_ColorNode *myNodes;
00208 UT_ColorNode *myCurrentNode;
00209
00210 UT_AssocArray<int, UT_ColorNode *> mySelectedNodes;
00211
00212 UT_ColorType myColorType;
00213
00214 mutable UT_Spline mySpline;
00215 mutable bool mySplineDirty;
00216
00217 bool myGlobalEnable;
00218 };
00219
00220 #endif