1#include "ColorMapping.h"
2#include "Math/SimpleMath.h"
6 IMPLEMENT_TCLASS(ColorMapping, TDataType)
8 template <typename Real>
9 __global__ void CM_MapJetColor(
15 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
16 if (tId >= color.size()) return;
18 Real x = clamp((v[tId] - vmin) / (vmax - vmin), Real(0), Real(1));
19 Real r = clamp(Real(-4 * abs(x - 0.75) + 1.5), Real(0), Real(1));
20 Real g = clamp(Real(-4 * abs(x - 0.50) + 1.5), Real(0), Real(1));
21 Real b = clamp(Real(-4 * abs(x - 0.25) + 1.5), Real(0), Real(1));
22 color[tId] = Vec3f(r, g, b);
25 template <typename Real>
26 __global__ void CM_MapHeatColor(
32 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
33 if (tId >= color.size()) return;
35 Real x = clamp((v[tId] - vmin) / (vmax - vmin), Real(0), Real(1));
36 Real r = clamp(Real(-4 * abs(x - 0.75) + 2), Real(0), Real(1));
37 Real g = clamp(Real(-4 * abs(x - 0.50) + 2), Real(0), Real(1));
38 Real b = clamp(Real(-4 * abs(x) + 2), Real(0), Real(1));
39 color[tId] = Vec3f(r, g, b);
42 template<typename TDataType>
43 void ColorMapping<TDataType>::compute()
45 auto& inData = this->inScalar()->getData();
47 int num = inData.size();
49 if (this->outColor()->isEmpty())
51 this->outColor()->allocate();
54 auto& outData = this->outColor()->getData();
55 if (outData.size() != num)
60 if(this->varType()->getData() == ColorTable::Jet)
66 this->varMin()->getData(),
67 this->varMax()->getData());
69 else if(this->varType()->getData() == ColorTable::Heat)
75 this->varMin()->getData(),
76 this->varMax()->getData());
80 DEFINE_CLASS(ColorMapping);