11 #ifndef vtk_m_worklet_StreamLineUniformGrid_h
12 #define vtk_m_worklet_StreamLineUniformGrid_h
45 template <
typename FieldType,
typename PortalType>
50 const PortalType& vecdata)
57 if (pos[d] >
static_cast<FieldType
>(vdims[d] - 1))
58 pos[d] =
static_cast<FieldType
>(vdims[d] - 1);
62 vtkm::Id3 idx000, idx001, idx010, idx011, idx100, idx101, idx110, idx111;
63 idx000[0] =
static_cast<vtkm::Id>(floor(pos[0]));
64 idx000[1] =
static_cast<vtkm::Id>(floor(pos[1]));
65 idx000[2] =
static_cast<vtkm::Id>(floor(pos[2]));
68 idx001[0] = (idx001[0] + 1) <= vdims[0] - 1 ? idx001[0] + 1 : vdims[0] - 1;
70 idx010[1] = (idx010[1] + 1) <= vdims[1] - 1 ? idx010[1] + 1 : vdims[1] - 1;
72 idx011[0] = (idx011[0] + 1) <= vdims[0] - 1 ? idx011[0] + 1 : vdims[0] - 1;
74 idx100[2] = (idx100[2] + 1) <= vdims[2] - 1 ? idx100[2] + 1 : vdims[2] - 1;
76 idx101[0] = (idx101[0] + 1) <= vdims[0] - 1 ? idx101[0] + 1 : vdims[0] - 1;
78 idx110[1] = (idx110[1] + 1) <= vdims[1] - 1 ? idx110[1] + 1 : vdims[1] - 1;
80 idx111[0] = (idx111[0] + 1) <= vdims[0] - 1 ? idx111[0] + 1 : vdims[0] - 1;
84 v000 = vecdata.Get(idx000[2] * planesize + idx000[1] * rowsize + idx000[0]);
85 v001 = vecdata.Get(idx001[2] * planesize + idx001[1] * rowsize + idx001[0]);
86 v010 = vecdata.Get(idx010[2] * planesize + idx010[1] * rowsize + idx010[0]);
87 v011 = vecdata.Get(idx011[2] * planesize + idx011[1] * rowsize + idx011[0]);
88 v100 = vecdata.Get(idx100[2] * planesize + idx100[1] * rowsize + idx100[0]);
89 v101 = vecdata.Get(idx101[2] * planesize + idx101[1] * rowsize + idx101[0]);
90 v110 = vecdata.Get(idx110[2] * planesize + idx110[1] * rowsize + idx110[0]);
91 v111 = vecdata.Get(idx111[2] * planesize + idx111[1] * rowsize + idx111[0]);
95 FieldType a = pos[0] -
static_cast<FieldType
>(floor(pos[0]));
96 v00[0] = (1.0f - a) * v000[0] + a * v001[0];
97 v00[1] = (1.0f - a) * v000[1] + a * v001[1];
98 v00[2] = (1.0f - a) * v000[2] + a * v001[2];
100 v01[0] = (1.0f - a) * v010[0] + a * v011[0];
101 v01[1] = (1.0f - a) * v010[1] + a * v011[1];
102 v01[2] = (1.0f - a) * v010[2] + a * v011[2];
104 v10[0] = (1.0f - a) * v100[0] + a * v101[0];
105 v10[1] = (1.0f - a) * v100[1] + a * v101[1];
106 v10[2] = (1.0f - a) * v100[2] + a * v101[2];
108 v11[0] = (1.0f - a) * v110[0] + a * v111[0];
109 v11[1] = (1.0f - a) * v110[1] + a * v111[1];
110 v11[2] = (1.0f - a) * v110[2] + a * v111[2];
114 a = pos[1] -
static_cast<FieldType
>(floor(pos[1]));
115 v0[0] = (1.0f - a) * v00[0] + a * v01[0];
116 v0[1] = (1.0f - a) * v00[1] + a * v01[1];
117 v0[2] = (1.0f - a) * v00[2] + a * v01[2];
119 v1[0] = (1.0f - a) * v10[0] + a * v11[0];
120 v1[1] = (1.0f - a) * v10[1] + a * v11[1];
121 v1[2] = (1.0f - a) * v10[2] + a * v11[2];
125 a = pos[2] -
static_cast<FieldType
>(floor(pos[2]));
126 v[0] = (1.0f - a) * v0[0] + v1[0];
127 v[1] = (1.0f - a) * v0[1] + v1[1];
128 v[2] = (1.0f - a) * v0[2] + v1[2];
134 template <
typename T>
141 template <
typename FieldType>
148 WholeArrayOut numIndices,
149 WholeArrayOut validPoint,
150 WholeArrayOut streamLines);
152 using InputDomain = _2;
180 template <
typename FieldPortalType,
typename IdComponentPortalType,
typename FieldVec3PortalType>
184 IdComponentPortalType& numIndices,
185 IdComponentPortalType& validPoint,
186 FieldVec3PortalType& slLists,
199 validPoint.Set(index, 1);
200 slLists.Set(index++, pos);
202 while (done !=
true && step <
maxsteps)
209 pos[d] += adata[d] / 2.0f;
216 pos[d] += bdata[d] / 2.0f;
223 pos[d] += cdata[d] / 2.0f;
230 pos[d] += (adata[d] + (2.0f * bdata[d]) + (2.0f * cdata[d]) + ddata[d]) / 6.0f;
233 if (pos[0] < 0.0f || pos[0] >
static_cast<FieldType
>(
vdims[0]) || pos[1] < 0.0f ||
234 pos[1] >
static_cast<FieldType
>(
vdims[1]) || pos[2] < 0.0f ||
235 pos[2] >
static_cast<FieldType
>(
vdims[2]))
242 validPoint.Set(index, 1);
243 slLists.Set(index++, pos);
257 validPoint.Set(index, 1);
258 slLists.Set(index++, pos);
260 while (done !=
true && step <
maxsteps)
266 adata[d] =
timestep * (0.0f - vdata[d]);
267 pos[d] += adata[d] / 2.0f;
273 bdata[d] =
timestep * (0.0f - vdata[d]);
274 pos[d] += bdata[d] / 2.0f;
280 cdata[d] =
timestep * (0.0f - vdata[d]);
281 pos[d] += cdata[d] / 2.0f;
287 ddata[d] =
timestep * (0.0f - vdata[d]);
288 pos[d] += (adata[d] + (2.0f * bdata[d]) + (2.0f * cdata[d]) + ddata[d]) / 6.0f;
291 if (pos[0] < 0.0f || pos[0] >
static_cast<FieldType
>(
vdims[0]) || pos[1] < 0.0f ||
292 pos[1] >
static_cast<FieldType
>(
vdims[1]) || pos[2] < 0.0f ||
293 pos[2] >
static_cast<FieldType
>(
vdims[2]))
300 validPoint.Set(index, 1);
301 slLists.Set(index++, pos);
315 template <
typename FieldType>
342 for (
vtkm::Id i = 0; i < numSeeds; i++)
345 seed[0] =
static_cast<FieldType
>(rand() % vdims[0]);
346 seed[1] =
static_cast<FieldType
>(rand() % vdims[1]);
347 seed[2] =
static_cast<FieldType
>(rand() % vdims[2]);
348 seedPosPortal.Set(i, seed);
355 vtkm::Id maxConnectivityLen = numCells * maxSteps;
359 streamArray.
Allocate(maxConnectivityLen);
370 Algorithm::Copy(polyLineShape, cellTypes);
375 validPoint.
Allocate(maxConnectivityLen);
376 Algorithm::Copy(zeros, validPoint);
382 makeStreamLines, fieldArray, seedIdArray, seedPosArray, numIndices, validPoint, streamArray);
391 Algorithm::Copy(connCount, connectivity);
411 #endif // vtk_m_worklet_StreamLineUniformGrid_h