Repository navigation
Expand file tree
/
Copy pathSIM_PBVisualizeAdvect.cpp
More file actions
260 lines (183 loc) · 6.24 KB
/
Copy pathSIM_PBVisualizeAdvect.cpp
File metadata and controls
260 lines (183 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
////////////////////////////////////////////////////
// VISUALIZER - ADVECTION PATHS
#include "include.h"
#include "SIM_Pebble.h"
#include "SIM_PBVisualizeAdvect.h"
const SIM_DopDescription * SIM_PBVisualizeAdvect::getDopDescription()
{
static PRM_Template theTemplates[] = {
PRM_Template()
};
static PRM_Template theGuideTemplates[] = {
PRM_Template(PRM_TOGGLE, 1, &SIMshowguideName, PRMzeroDefaults),
PRM_Template(PRM_FLT_J, 1, &theTimestepName, &theTimestepDef),
PRM_Template(PRM_FLT_J, 1, &theMinMagnitudeName, &theMinMagnitudeDef),
PRM_Template(PRM_FLT_J, 1, &theAmountName, PRMoneDefaults, 0, &PRMunitRange),
PRM_Template(PRM_INT, 1, &theSeedName, PRMzeroDefaults),
PRM_Template(PRM_INT, 1, &theMarkName, &theMarkDef, 0, &theMarkRng),
PRM_Template(PRM_FLT_J, 1, &theUpperName, PRMzeroDefaults),
PRM_Template(PRM_TOGGLE, 1, &theShowVGuideName, PRMoneDefaults),
//PRM_Template(PRM_RGB, 3, &SIMcolorName, PRMoneDefaults, 0, &PRMunitRange),
PRM_Template()
};
static SIM_DopDescription theDopDescription(true, "sim_pb_visualize_advect", "Pebble Visualize Advection", "VisualizationAdv", classname(), theTemplates);
theDopDescription.setGuideTemplates(theGuideTemplates);
return &theDopDescription;
}
void SIM_PBVisualizeAdvect::buildGuideGeometrySubclass(const SIM_RootData & root, const SIM_Options & options, const GU_DetailHandle & gdh, UT_DMatrix4 * xform, const SIM_Time & t) const
{
// Build our template geometry, if we are so asked.
initAlternateRepresentation();
if (!m_pebble) return;
for (const Patch* _pb : m_pebble->m_P) if (_pb == NULL) return;
if (gdh.isNull()) return;
GU_DetailHandleAutoWriteLock gdl(gdh);
m_gdp = gdl.getGdp();
//UT_Vector3 color = getColor(options);
m_cdh.bind(m_gdp->findPointAttribute("Cd"));
if (!m_cdh.isValid())
{
m_cdh = GA_RWHandleV3(m_gdp->addFloatTuple(GA_ATTRIB_POINT, "Cd", 3, GA_Defaults(1.0)));
m_cdh->setTypeInfo(GA_TYPE_COLOR);
};
uint seed = getSeed(options);
m_S = seed;
m_amount = getAmount(options);
m_timestep = getTimestep(options);
m_upper = getUpper(options);
m_minmagnitude = getMinMagnitude(options);
m_sg = getShowVGuide(options);
int psz = m_pebble->m_P.size();
m_Ps.resize(psz);
m_Vs.resize(psz);
m_dPdUs.resize(psz);
m_dPdVs.resize(psz);
m_Ns.resize(psz);
m_Rels.resize(psz);
m_Gs.resize(psz);
for (int i = 0; i < psz; i++)
{
m_Ps[i] = NULL; m_Vs[i] = NULL;
m_dPdUs[i] = NULL; m_dPdVs[i] = NULL; m_Ns[i] = NULL;
m_Rels[i] = NULL;
m_Gs[i] = NULL;
};
int mark = getMark(options);
bool oneWay = (mark != -1);
int path_index = 0;
//UT_StringArray pages;
//pages.append("rel");
for (const Patch* _pb : m_pebble->m_P)
{
if (_pb->chs.find("v") == -1) return;
if (_pb->chs.find("rel") == -1) return;
//_pb->declarePages(pages);
};
build();
for (int i = 0; i < psz; i++)
{
if (m_Ps[i] != NULL) delete m_Ps[i];
if (m_Vs[i] != NULL) delete m_Vs[i];
if (m_dPdUs[i] != NULL) delete m_dPdUs[i];
if (m_dPdVs[i] != NULL) delete m_dPdVs[i];
if (m_Ns[i] != NULL) delete m_Ns[i];
if (m_Rels[i] != NULL) delete m_Rels[i];
if (m_Gs[i] != NULL) delete m_Gs[i];
};
};
void SIM_PBVisualizeAdvect::buildPartial(const UT_JobInfo & info) const
{
int start, end;
info.divideWork(m_pebble->m_P.size(), start, end);
for (int id = start; id < end; id++)
{
UT_FastRandom RA;
RA.setSeed(m_S+id);
const Patch& pb = *m_pebble->m_P[id];
const Page& P = pb.getPrimVar("P");
const Page& V = pb.getPrimVar("v");
//const Page& DPDU = pb.getPrimVar("dPdu");
//const Page& DPDV = pb.getPrimVar("dPdv");
const Page& CD = pb.getPrimVar("Cd");
const Page& N = pb.getPrimVar("N");
const Page& UV = pb.getPrimVar("uvw");
const Page& REL = pb.getPrimVar("rel");
for (int ii = 0; ii < pb.dim[0]; ii++)
{
for (int jj = 0; jj < pb.dim[1]; jj++)
{
if (RA.frandom() >= m_amount) continue;
UT_Vector3 uv = UV.get(ii, jj);
UT_Vector3 rel = REL.get(uv);
if (rel[1] > 0) continue;
UT_Vector3 _v = V.get(uv);
//_v[2] = 0;
float length = _v.length() * m_timestep;
if (length < m_minmagnitude) continue;
float L = length;
if (isnan(L)) continue;
if (!isfinite(L)) continue;
//if (m_oneWay)
//{
// if (mark != path_index) continue;
// path_index++;
//};
// CALCULATE
UT_Vector3Array path;
UT_Vector3Array colors;
path.append(uv);
colors.append(UT_Vector3(1, 1, 0));
traceStat stat;
stat.id = id;
//continue;
bool res = trace(m_pebble->m_P, uv, length, path, colors, m_Ps, m_Vs, m_dPdUs, m_dPdVs, m_Ns, m_Rels, m_Gs, m_lock, stat);
int sz = path.size();
if (sz < 2)
{
continue;
};
UT_AutoJobInfoLock a(info);
// ...MIND ABOUT PROJ : BUILD V GUIDE
if (m_sg)
{
GEO_PrimPoly* PV = GEO_PrimPoly::build(m_gdp, 2, true, false);
UT_Vector3 vn = pb.composite(V.get(uv),uv);
UT_Vector3 n = N.get(uv); n.normalize();
vn -= n*vn.dot(n);
vn.normalize();
UT_Vector3 pp = P.get(uv) + m_upper*n;
GA_Offset poff0 = m_gdp->appendPoint();
m_gdp->setPos3(poff0, pp);
m_cdh.set(poff0, UT_Vector3(0, 1, 0));
PV->setPointOffset(0, poff0);
GA_Offset poff1 = m_gdp->appendPoint();
m_gdp->setPos3(poff1, pp - vn*L);
m_cdh.set(poff1, UT_Vector3(0, 1, 0));
PV->setPointOffset(1, poff1);
}
// BUILD PATH
GEO_PrimPoly* PP = GEO_PrimPoly::build(m_gdp, path.size(), true, false);
for (int k = 0; k < path.size(); k++)
{
GA_Offset poff0 = m_gdp->appendPoint();
UT_Vector3 C = path[k];
const Page& pp = *m_Ps[C[2]];
// .getPrimVar("P");
//const Page& pp = m_pb->m_P[C[2]].getPrimVar("P");
const Page& np = (*m_pebble->m_P[C[2]]).getPrimVar("N");
UT_Vector3 nn = np.get(C);
nn.normalize();
UT_Vector3 __P = pp.get(C);
m_gdp->setPos3(poff0, __P + nn*m_upper);
UT_Vector3 CLR = colors[k]; // *(1 - (float(k)) / float(path.size() + 1));
// CD.get(ii, jj) * float(k) / float(k - 1); // UT_Vector3(1, 0.85, 0.15)* float(k) / float(k - 1);
//UV.get(ii, jj); // UT_Vector3(1, 0, 1); // CD.get(i,j) * float(k)/float(k-1)
//CLR[2] = (ii + jj) % 2;
//if (!res && k == path.size() - 1) CLR = UT_Vector3(1, 0, 0);
m_cdh.set(poff0, CLR);
PP->setPointOffset(k, poff0);
};
};
};
};
};