PeriDyno 1.0.0
Loading...
Searching...
No Matches
ColorMapping.cu
Go to the documentation of this file.
1#include "ColorMapping.h"
2#include "Math/SimpleMath.h"
3
4namespace dyno
5{
6 IMPLEMENT_TCLASS(ColorMapping, TDataType)
7
8 template <typename Real>
9 __global__ void CM_MapJetColor(
10 DArray<Vec3f> color,
11 DArray<Real> v,
12 Real vmin,
13 Real vmax)
14 {
15 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
16 if (tId >= color.size()) return;
17
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);
23 }
24
25 template <typename Real>
26 __global__ void CM_MapHeatColor(
27 DArray<Vec3f> color,
28 DArray<Real> v,
29 Real vmin,
30 Real vmax)
31 {
32 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
33 if (tId >= color.size()) return;
34
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);
40 }
41
42 template<typename TDataType>
43 void ColorMapping<TDataType>::compute()
44 {
45 auto& inData = this->inScalar()->getData();
46
47 int num = inData.size();
48
49 if (this->outColor()->isEmpty())
50 {
51 this->outColor()->allocate();
52 }
53
54 auto& outData = this->outColor()->getData();
55 if (outData.size() != num)
56 {
57 outData.resize(num);
58 }
59
60 if(this->varType()->getData() == ColorTable::Jet)
61 {
62 cuExecute(num,
63 CM_MapJetColor,
64 outData,
65 inData,
66 this->varMin()->getData(),
67 this->varMax()->getData());
68 }
69 else if(this->varType()->getData() == ColorTable::Heat)
70 {
71 cuExecute(num,
72 CM_MapHeatColor,
73 outData,
74 inData,
75 this->varMin()->getData(),
76 this->varMax()->getData());
77 }
78 }
79
80 DEFINE_CLASS(ColorMapping);
81}