1.3.49
 
Loading...
Searching...
No Matches
VisualizerContext.cpp
Go to the documentation of this file.
1
16#include "Visualizer.h"
17
18using namespace helios;
19
21 geometry_handler.clearContextGeometry();
22
23 contextUUIDs_build.clear();
24 colorPrimitives_UUIDs.clear();
25 colorPrimitives_objIDs.clear();
26 depth_buffer_data.clear();
27 colorbar_min = 0;
28 colorbar_max = 0;
29}
30
32 context = context_ptr;
33
34 // Asset directory registration removed - now using HELIOS_BUILD resolution
35
36 build_all_context_geometry = true;
37}
38
39void Visualizer::buildContextGeometry(helios::Context *context_ptr, const std::vector<uint> &UUIDs) {
40 if (UUIDs.empty()) {
41 std::cerr << "WARNING (Visualizer::buildContextGeometry): There is no Context geometry to build...exiting." << std::endl;
42 return;
43 }
44
45 context = context_ptr;
46
47 // Asset directory registration removed - now using HELIOS_BUILD resolution
48
49 build_all_context_geometry = false;
50 contextUUIDs_build = UUIDs;
51}
52
53void Visualizer::buildContextGeometry_private() {
54
55 if (context == nullptr) { // If Visualizer::buildContextGeometry() was never called, nothing to do
56 return;
57 }
58
59 // If building all context geometry, get all dirty UUIDs from the Context
60 if (build_all_context_geometry) {
61 bool include_deleted_UUIDs = true;
62 if (contextUUIDs_build.empty()) {
63 include_deleted_UUIDs = false;
64 }
65 contextUUIDs_build = context->getDirtyUUIDs(include_deleted_UUIDs);
66 }
67
68 // Populate contextUUIDs_needupdate based on dirty primitives in the Context
69 std::vector<uint> contextUUIDs_needupdate;
70 contextUUIDs_needupdate.reserve(contextUUIDs_build.size());
71
72 for (uint UUID: contextUUIDs_build) {
73
74 // Check if primitives in contextUUIDs_build have since been deleted from the Context. If so, remove them from contextUUIDs_build and from the geometry handler
75 if (!context->doesPrimitiveExist(UUID)) {
76 auto it = std::find(contextUUIDs_build.begin(), contextUUIDs_build.end(), UUID);
77 if (it != contextUUIDs_build.end()) {
78 // swap-and-pop delete from contextUUIDs_build
79 *it = contextUUIDs_build.back();
80 contextUUIDs_build.pop_back();
81 // delete from the geometry handler
82 if (geometry_handler.doesGeometryExist(UUID)) {
83 geometry_handler.deleteGeometry(UUID);
84 }
85 }
86 }
87 // check if the primitive is dirty, if so, add it to contextUUIDs_needupdate
88 else {
89 contextUUIDs_needupdate.push_back(UUID);
90 }
91 }
92
93 if (contextUUIDs_needupdate.empty() && !primitiveColorsNeedUpdate) {
94 return;
95 }
96
97 if (!colorPrimitivesByData.empty()) {
98 if (colorPrimitives_UUIDs.empty()) { // load all primitives
99 std::vector<uint> all_UUIDs = context->getAllUUIDs();
100 for (uint UUID: all_UUIDs) {
101 if (context->doesPrimitiveExist(UUID)) {
102 colorPrimitives_UUIDs[UUID] = UUID;
103 }
104 }
105 } else { // double check that primitives exist
106 std::vector<uint> all_UUIDs = context->getAllUUIDs();
107 for (uint UUID: all_UUIDs) {
108 if (!context->doesPrimitiveExist(UUID)) {
109 auto it = colorPrimitives_UUIDs.find(UUID);
110 colorPrimitives_UUIDs.erase(it);
111 }
112 }
113 }
114 } else if (!colorPrimitivesByObjectData.empty()) {
115 if (colorPrimitives_objIDs.empty()) { // load all primitives
116 std::vector<uint> ObjIDs = context->getAllObjectIDs();
117 for (uint objID: ObjIDs) {
118 if (context->doesObjectExist(objID)) {
119 std::vector<uint> UUIDs = context->getObjectPointer(objID)->getPrimitiveUUIDs();
120 for (uint UUID: UUIDs) {
121 if (context->doesPrimitiveExist(UUID)) {
122 colorPrimitives_UUIDs[UUID] = UUID;
123 }
124 }
125 }
126 }
127 } else { // load primitives specified by user
128 for (const auto &objID: colorPrimitives_objIDs) {
129 if (context->doesObjectExist(objID.first)) {
130 std::vector<uint> UUIDs = context->getObjectPointer(objID.first)->getPrimitiveUUIDs();
131 for (uint UUID: UUIDs) {
132 if (context->doesPrimitiveExist(UUID)) {
133 colorPrimitives_UUIDs[UUID] = UUID;
134 }
135 }
136 }
137 }
138 }
139 }
140
141 if (!colorPrimitives_UUIDs.empty() && colorbar_flag == 0) {
143 }
144
145 //------ Colormap ------//
146
147 uint psize = contextUUIDs_needupdate.size();
148 if (message_flag) {
149 if (psize > 0) {
150 if (psize >= 1e3 && psize < 1e6) {
151 std::cout << "updating " << psize / 1e3 << "K Context primitives to visualizer...." << std::flush;
152 } else if (psize >= 1e6) {
153 std::cout << "updating " << psize / 1e6 << "M Context primitives to visualizer...." << std::flush;
154 } else {
155 std::cout << "updating " << psize << " Context primitives to visualizer...." << std::flush;
156 }
157 } else {
158 std::cerr << "WARNING (Visualizer::buildContextGeometry): No primitives were found in the Context..." << std::endl;
159 }
160 }
161
162 // figure out colorbar range
163 // \todo Figure out how to avoid doing this when not necessary
164
165 colormap_current.setRange(colorbar_min, colorbar_max);
166 if ((!colorPrimitivesByData.empty() || !colorPrimitivesByObjectData.empty()) && colorbar_min == 0 && colorbar_max == 0) { // range was not set by user, use full range of values
167
168 colorbar_min = (std::numeric_limits<float>::max)();
169 colorbar_max = (std::numeric_limits<float>::lowest)();
170
171 for (uint UUID: contextUUIDs_build) {
172 float colorValue = -9999;
173 if (!colorPrimitivesByData.empty()) {
174 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
175 if (context->doesPrimitiveDataExist(UUID, colorPrimitivesByData.c_str())) {
176 HeliosDataType type = context->getPrimitiveDataType(colorPrimitivesByData.c_str());
177 if (type == HELIOS_TYPE_FLOAT) {
178 context->getPrimitiveData(UUID, colorPrimitivesByData.c_str(), colorValue);
179 } else if (type == HELIOS_TYPE_INT) {
180 int cv;
181 context->getPrimitiveData(UUID, colorPrimitivesByData.c_str(), cv);
182 colorValue = float(cv);
183 } else if (type == HELIOS_TYPE_UINT) {
184 uint cv;
185 context->getPrimitiveData(UUID, colorPrimitivesByData.c_str(), cv);
186 colorValue = float(cv);
187 } else if (type == HELIOS_TYPE_DOUBLE) {
188 double cv;
189 context->getPrimitiveData(UUID, colorPrimitivesByData.c_str(), cv);
190 colorValue = float(cv);
191 } else {
192 colorValue = 0;
193 }
194 } else {
195 colorValue = 0;
196 }
197 }
198 } else if (!colorPrimitivesByObjectData.empty()) {
199 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
200 uint ObjID = context->getPrimitiveParentObjectID(UUID);
201 if (ObjID != 0 && context->doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
202 HeliosDataType type = context->getObjectDataType(colorPrimitivesByObjectData.c_str());
203 if (type == HELIOS_TYPE_FLOAT) {
204 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
205 } else if (type == HELIOS_TYPE_INT) {
206 int cv;
207 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
208 colorValue = float(cv);
209 } else if (type == HELIOS_TYPE_UINT) {
210 uint cv;
211 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
212 colorValue = float(cv);
213 } else if (type == HELIOS_TYPE_DOUBLE) {
214 double cv;
215 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
216 colorValue = float(cv);
217 } else {
218 colorValue = 0;
219 }
220 } else {
221 colorValue = 0;
222 }
223 }
224 }
225
226 if (std::isnan(colorValue) || std::isinf(colorValue)) { // check for NaN or infinity
227 colorValue = 0;
228 }
229
230 if (colorValue != -9999) {
231 if (colorValue < colorbar_min) {
232 colorbar_min = colorValue;
233 ;
234 }
235 if (colorValue > colorbar_max) {
236 colorbar_max = colorValue;
237 ;
238 }
239 }
240 }
241
242 if (!std::isinf(colorbar_min) && !std::isinf(colorbar_max)) {
243 colormap_current.setRange(colorbar_min, colorbar_max);
244 }
245 }
246
247 if (!colorPrimitivesByData.empty()) {
248 assert(colorbar_min <= colorbar_max);
249 }
250
251 //------- Simulation Geometry -------//
252
253 // add primitives
254
255 size_t patch_count = context->getPatchCount();
256 geometry_handler.allocateBufferSize(patch_count, GeometryHandler::GEOMETRY_TYPE_RECTANGLE);
257 size_t triangle_count = context->getTriangleCount();
258 geometry_handler.allocateBufferSize(triangle_count, GeometryHandler::GEOMETRY_TYPE_TRIANGLE);
259
260 for (unsigned int UUID: contextUUIDs_needupdate) {
261
262 if (!context->doesPrimitiveExist(UUID)) {
263 std::cerr << "WARNING (Visualizer::buildContextGeometry): UUID vector contains ID(s) that do not exist in the Context...they will be ignored." << std::endl;
264 continue;
265 }
266
267 helios::PrimitiveType ptype = context->getPrimitiveType(UUID);
268
269 const std::vector<vec3> verts = context->getPrimitiveVertices(UUID);
270 const std::string texture_file = context->getPrimitiveTextureFile(UUID);
271
272 RGBAcolor color;
273 float colorValue;
274 if (!colorPrimitivesByData.empty()) {
275 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
276 if (context->doesPrimitiveDataExist(UUID, colorPrimitivesByData.c_str())) {
277 HeliosDataType type = context->getPrimitiveDataType(colorPrimitivesByData.c_str());
278 if (type == HELIOS_TYPE_FLOAT) {
279 context->getPrimitiveData(UUID, colorPrimitivesByData.c_str(), colorValue);
280 } else if (type == HELIOS_TYPE_INT) {
281 int cv;
282 context->getPrimitiveData(UUID, colorPrimitivesByData.c_str(), cv);
283 colorValue = float(cv);
284 } else if (type == HELIOS_TYPE_UINT) {
285 uint cv;
286 context->getPrimitiveData(UUID, colorPrimitivesByData.c_str(), cv);
287 colorValue = float(cv);
288 } else if (type == HELIOS_TYPE_DOUBLE) {
289 double cv;
290 context->getPrimitiveData(UUID, colorPrimitivesByData.c_str(), cv);
291 colorValue = float(cv);
292 } else {
293 colorValue = 0;
294 }
295 } else {
296 colorValue = 0;
297 }
298
299 if (std::isnan(colorValue) || std::isinf(colorValue)) { // check for NaN or infinity
300 colorValue = 0;
301 }
302
303 color = make_RGBAcolor(colormap_current.query(colorValue), 1);
304 } else {
305 color = context->getPrimitiveColorRGBA(UUID);
306 }
307 } else if (!colorPrimitivesByObjectData.empty()) {
308 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
309 uint ObjID = context->getPrimitiveParentObjectID(UUID);
310 if (ObjID != 0 && context->doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
311 HeliosDataType type = context->getObjectDataType(colorPrimitivesByObjectData.c_str());
312 if (type == HELIOS_TYPE_FLOAT) {
313 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
314 } else if (type == HELIOS_TYPE_INT) {
315 int cv;
316 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
317 colorValue = float(cv);
318 } else if (type == HELIOS_TYPE_UINT) {
319 uint cv;
320 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
321 colorValue = float(cv);
322 } else if (type == HELIOS_TYPE_DOUBLE) {
323 double cv;
324 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
325 colorValue = float(cv);
326 } else {
327 colorValue = 0;
328 }
329 } else {
330 colorValue = 0;
331 }
332
333 if (std::isnan(colorValue) || std::isinf(colorValue)) { // check for NaN or infinity
334 colorValue = 0;
335 }
336
337 color = make_RGBAcolor(colormap_current.query(colorValue), 1);
338 } else {
339 color = context->getPrimitiveColorRGBA(UUID);
340 }
341 } else {
342 color = context->getPrimitiveColorRGBA(UUID);
343 }
344
345 int textureID = -1;
346 if (!texture_file.empty()) {
347 textureID = registerTextureImage(texture_file);
348 }
349
350 // ---- PATCHES ---- //
351 if (ptype == helios::PRIMITIVE_TYPE_PATCH) {
352 // - Patch does not have an associated texture or we are ignoring texture
353 if (texture_file.empty()) {
354 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, {}, -1, false, false, COORDINATES_CARTESIAN, true, true);
355 }
356 // - Patch has a texture
357 else {
358 std::vector<vec2> uvs = context->getPrimitiveTextureUV(UUID);
359
360 // - coloring primitive based on texture
361 if ((colorPrimitives_UUIDs.find(UUID) == colorPrimitives_UUIDs.end() || colorPrimitives_UUIDs.empty()) && !context->isPrimitiveTextureColorOverridden(UUID)) {
362 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, uvs, textureID, false, false, COORDINATES_CARTESIAN, true, true);
363 }
364 // - coloring primitive based on primitive data
365 else {
366 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, uvs, textureID, true, false, COORDINATES_CARTESIAN, true, true);
367 }
368 }
369 }
370 // ---- TRIANGLES ---- //
371 else if (ptype == helios::PRIMITIVE_TYPE_TRIANGLE) {
372 // - Triangle does not have an associated texture or we are ignoring texture
373 if (texture_file.empty()) {
374 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, {}, -1, false, false, COORDINATES_CARTESIAN, true, true);
375 }
376 // - Triangle has a texture
377 else {
378 std::vector<vec2> uvs = context->getPrimitiveTextureUV(UUID);
379
380 // - coloring primitive based on texture
381 if ((colorPrimitives_UUIDs.find(UUID) == colorPrimitives_UUIDs.end() || colorPrimitives_UUIDs.empty()) && !context->isPrimitiveTextureColorOverridden(UUID)) {
382 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, uvs, textureID, false, false, COORDINATES_CARTESIAN, true, true);
383 }
384 // - coloring primitive based on RGB color but mask using texture
385 else {
386 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, uvs, textureID, true, false, COORDINATES_CARTESIAN, true, true);
387 }
388 }
389 }
390 // ---- VOXELS ---- //
391 else if (ptype == helios::PRIMITIVE_TYPE_VOXEL) {
392 std::vector<vec3> v_vertices = context->getPrimitiveVertices(UUID);
393
394 // bottom
395 const std::vector<vec3> bottom_vertices{v_vertices.at(0), v_vertices.at(1), v_vertices.at(2), v_vertices.at(3)};
396
397 // top
398 const std::vector<vec3> top_vertices{v_vertices.at(4), v_vertices.at(5), v_vertices.at(6), v_vertices.at(7)};
399
400 //-x
401 const std::vector<vec3> mx_vertices{v_vertices.at(0), v_vertices.at(3), v_vertices.at(7), v_vertices.at(4)};
402
403 //+x
404 const std::vector<vec3> px_vertices{v_vertices.at(1), v_vertices.at(2), v_vertices.at(6), v_vertices.at(5)};
405
406 //-y
407 const std::vector<vec3> my_vertices{v_vertices.at(0), v_vertices.at(1), v_vertices.at(5), v_vertices.at(4)};
408
409 //+y
410 const std::vector<vec3> py_vertices{v_vertices.at(2), v_vertices.at(3), v_vertices.at(7), v_vertices.at(6)};
411
412 // Voxel does not have an associated texture or we are ignoring texture
413 if (texture_file.empty()) {
414 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, bottom_vertices, color, {}, -1, false, false, COORDINATES_CARTESIAN, true, true);
415 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, top_vertices, color, {}, -1, false, false, COORDINATES_CARTESIAN, true, true);
416 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, mx_vertices, color, {}, -1, false, false, COORDINATES_CARTESIAN, true, true);
417 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, px_vertices, color, {}, -1, false, false, COORDINATES_CARTESIAN, true, true);
418 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, my_vertices, color, {}, -1, false, false, COORDINATES_CARTESIAN, true, true);
419 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, py_vertices, color, {}, -1, false, false, COORDINATES_CARTESIAN, true, true);
420 }
421 // Voxel has a texture
422 else {
423 const std::vector<helios::vec2> voxel_uvs = {{0.f, 0.f}, {1.f, 0.f}, {1.f, 1.f}, {0.f, 1.f}};
424
425 // coloring primitive based on texture
426 if ((colorPrimitives_UUIDs.find(UUID) == colorPrimitives_UUIDs.end() || colorPrimitives_UUIDs.empty()) && context->isPrimitiveTextureColorOverridden(UUID)) {
427 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, bottom_vertices, color, voxel_uvs, textureID, false, false, COORDINATES_CARTESIAN, true, true);
428 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, top_vertices, color, voxel_uvs, textureID, false, false, COORDINATES_CARTESIAN, true, true);
429 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, mx_vertices, color, voxel_uvs, textureID, false, false, COORDINATES_CARTESIAN, true, true);
430 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, px_vertices, color, voxel_uvs, textureID, false, false, COORDINATES_CARTESIAN, true, true);
431 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, my_vertices, color, voxel_uvs, textureID, false, false, COORDINATES_CARTESIAN, true, true);
432 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, py_vertices, color, voxel_uvs, textureID, false, false, COORDINATES_CARTESIAN, true, true);
433 }
434 // coloring primitive based on primitive data
435 else {
436 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, bottom_vertices, color, voxel_uvs, textureID, true, false, COORDINATES_CARTESIAN, true, true);
437 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, top_vertices, color, voxel_uvs, textureID, true, false, COORDINATES_CARTESIAN, true, true);
438 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, mx_vertices, color, voxel_uvs, textureID, true, false, COORDINATES_CARTESIAN, true, true);
439 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, px_vertices, color, voxel_uvs, textureID, true, false, COORDINATES_CARTESIAN, true, true);
440 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, my_vertices, color, voxel_uvs, textureID, true, false, COORDINATES_CARTESIAN, true, true);
441 geometry_handler.addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, py_vertices, color, voxel_uvs, textureID, true, false, COORDINATES_CARTESIAN, true, true);
442 }
443 }
444 }
445 }
446
447 if (primitiveColorsNeedUpdate) {
449 }
450}
451
453
454 std::vector<size_t> geometry_UUIDs = geometry_handler.getAllGeometryIDs();
455
456 if (geometry_UUIDs.empty()) {
457 primitiveColorsNeedUpdate = false;
458 return;
459 }
460
461 colormap_current.setRange(colorbar_min, colorbar_max);
462
463 if ((!colorPrimitivesByData.empty() || !colorPrimitivesByObjectData.empty()) && colorbar_min == 0 && colorbar_max == 0) {
464 colorbar_min = (std::numeric_limits<float>::max)();
465 colorbar_max = (std::numeric_limits<float>::lowest)();
466
467 for (auto UUID: geometry_UUIDs) {
468 if (!context->doesPrimitiveExist(static_cast<uint>(UUID))) {
469 continue;
470 }
471
472 float colorValue = -9999.f;
473 if (!colorPrimitivesByData.empty()) {
474 if (colorPrimitives_UUIDs.find(static_cast<uint>(UUID)) != colorPrimitives_UUIDs.end()) {
475 if (context->doesPrimitiveDataExist(static_cast<uint>(UUID), colorPrimitivesByData.c_str())) {
476 HeliosDataType type = context->getPrimitiveDataType(colorPrimitivesByData.c_str());
477 if (type == HELIOS_TYPE_FLOAT) {
478 context->getPrimitiveData(static_cast<uint>(UUID), colorPrimitivesByData.c_str(), colorValue);
479 } else if (type == HELIOS_TYPE_INT) {
480 int cv;
481 context->getPrimitiveData(static_cast<uint>(UUID), colorPrimitivesByData.c_str(), cv);
482 colorValue = float(cv);
483 } else if (type == HELIOS_TYPE_UINT) {
484 uint cv;
485 context->getPrimitiveData(static_cast<uint>(UUID), colorPrimitivesByData.c_str(), cv);
486 colorValue = float(cv);
487 } else if (type == HELIOS_TYPE_DOUBLE) {
488 double cv;
489 context->getPrimitiveData(static_cast<uint>(UUID), colorPrimitivesByData.c_str(), cv);
490 colorValue = float(cv);
491 } else {
492 colorValue = 0.f;
493 }
494 } else {
495 colorValue = 0.f;
496 }
497 }
498 } else if (!colorPrimitivesByObjectData.empty()) {
499 if (colorPrimitives_UUIDs.find(static_cast<uint>(UUID)) != colorPrimitives_UUIDs.end()) {
500 uint ObjID = context->getPrimitiveParentObjectID(static_cast<uint>(UUID));
501 if (ObjID != 0 && context->doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
502 HeliosDataType type = context->getObjectDataType(colorPrimitivesByObjectData.c_str());
503 if (type == HELIOS_TYPE_FLOAT) {
504 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
505 } else if (type == HELIOS_TYPE_INT) {
506 int cv;
507 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
508 colorValue = float(cv);
509 } else if (type == HELIOS_TYPE_UINT) {
510 uint cv;
511 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
512 colorValue = float(cv);
513 } else if (type == HELIOS_TYPE_DOUBLE) {
514 double cv;
515 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
516 colorValue = float(cv);
517 } else {
518 colorValue = 0.f;
519 }
520 } else {
521 colorValue = 0.f;
522 }
523 }
524 }
525
526 if (std::isnan(colorValue) || std::isinf(colorValue)) {
527 colorValue = 0.f;
528 }
529
530 if (colorValue != -9999.f) {
531 if (colorValue < colorbar_min) {
532 colorbar_min = colorValue;
533 }
534 if (colorValue > colorbar_max) {
535 colorbar_max = colorValue;
536 }
537 }
538 }
539
540 if (!std::isinf(colorbar_min) && !std::isinf(colorbar_max)) {
541 colormap_current.setRange(colorbar_min, colorbar_max);
542 }
543 }
544
545 for (auto UUID: geometry_UUIDs) {
546 uint uid = static_cast<uint>(UUID);
547 if (!context->doesPrimitiveExist(uid) || !geometry_handler.doesGeometryExist(UUID)) {
548 continue;
549 }
550
551 RGBAcolor color = context->getPrimitiveColorRGBA(uid);
552
553 const std::string texture_file = context->getPrimitiveTextureFile(uid);
554
555 if (!colorPrimitivesByData.empty()) {
556 if (colorPrimitives_UUIDs.find(uid) != colorPrimitives_UUIDs.end()) {
557 float colorValue = 0.f;
558 if (context->doesPrimitiveDataExist(uid, colorPrimitivesByData.c_str())) {
559 HeliosDataType type = context->getPrimitiveDataType(colorPrimitivesByData.c_str());
560 if (type == HELIOS_TYPE_FLOAT) {
561 context->getPrimitiveData(uid, colorPrimitivesByData.c_str(), colorValue);
562 } else if (type == HELIOS_TYPE_INT) {
563 int cv;
564 context->getPrimitiveData(uid, colorPrimitivesByData.c_str(), cv);
565 colorValue = float(cv);
566 } else if (type == HELIOS_TYPE_UINT) {
567 uint cv;
568 context->getPrimitiveData(uid, colorPrimitivesByData.c_str(), cv);
569 colorValue = float(cv);
570 } else if (type == HELIOS_TYPE_DOUBLE) {
571 double cv;
572 context->getPrimitiveData(uid, colorPrimitivesByData.c_str(), cv);
573 colorValue = float(cv);
574 } else {
575 colorValue = 0.f;
576 }
577 }
578
579 if (std::isnan(colorValue) || std::isinf(colorValue)) {
580 colorValue = 0.f;
581 }
582
583 color = make_RGBAcolor(colormap_current.query(colorValue), 1.f);
584
585 if (!texture_file.empty()) {
586 geometry_handler.overrideTextureColor(UUID);
587 }
588 } else if (!texture_file.empty()) {
589 geometry_handler.useTextureColor(UUID);
590 }
591 } else if (!colorPrimitivesByObjectData.empty()) {
592 if (colorPrimitives_UUIDs.find(uid) != colorPrimitives_UUIDs.end()) {
593 float colorValue = 0.f;
594 uint ObjID = context->getPrimitiveParentObjectID(uid);
595 if (ObjID != 0 && context->doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
596 HeliosDataType type = context->getObjectDataType(colorPrimitivesByObjectData.c_str());
597 if (type == HELIOS_TYPE_FLOAT) {
598 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
599 } else if (type == HELIOS_TYPE_INT) {
600 int cv;
601 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
602 colorValue = float(cv);
603 } else if (type == HELIOS_TYPE_UINT) {
604 uint cv;
605 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
606 colorValue = float(cv);
607 } else if (type == HELIOS_TYPE_DOUBLE) {
608 double cv;
609 context->getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
610 colorValue = float(cv);
611 } else {
612 colorValue = 0.f;
613 }
614 }
615
616 if (std::isnan(colorValue) || std::isinf(colorValue)) {
617 colorValue = 0.f;
618 }
619
620 color = make_RGBAcolor(colormap_current.query(colorValue), 1.f);
621
622 if (!texture_file.empty()) {
623 geometry_handler.overrideTextureColor(UUID);
624 }
625 } else if (!texture_file.empty()) {
626 geometry_handler.useTextureColor(UUID);
627 }
628 } else {
629 if (!texture_file.empty()) {
630 geometry_handler.useTextureColor(UUID);
631 }
632 }
633
634 geometry_handler.setColor(UUID, color);
635 }
636
637 primitiveColorsNeedUpdate = false;
638}
639
640void Visualizer::colorContextPrimitivesByData(const char *data_name) {
641 colorPrimitivesByData = data_name;
642 colorPrimitivesByObjectData = "";
643 if (!colorPrimitives_UUIDs.empty()) {
644 colorPrimitives_UUIDs.clear();
645 }
646 if (!colorPrimitives_objIDs.empty()) {
647 colorPrimitives_objIDs.clear();
648 }
649 primitiveColorsNeedUpdate = true;
650}
651
652void Visualizer::colorContextPrimitivesByData(const char *data_name, const std::vector<uint> &UUIDs) {
653 colorPrimitivesByData = data_name;
654 colorPrimitivesByObjectData = "";
655 for (uint UUID: UUIDs) {
656 colorPrimitives_UUIDs[UUID] = UUID;
657 }
658 if (!colorPrimitives_objIDs.empty()) {
659 colorPrimitives_objIDs.clear();
660 }
661 primitiveColorsNeedUpdate = true;
662}
663
665 colorPrimitivesByObjectData = data_name;
666 colorPrimitivesByData = "";
667 if (!colorPrimitives_UUIDs.empty()) {
668 colorPrimitives_UUIDs.clear();
669 }
670 if (!colorPrimitives_objIDs.empty()) {
671 colorPrimitives_objIDs.clear();
672 }
673 primitiveColorsNeedUpdate = true;
674}
675
676void Visualizer::colorContextPrimitivesByObjectData(const char *data_name, const std::vector<uint> &ObjIDs) {
677 colorPrimitivesByObjectData = data_name;
678 colorPrimitivesByData = "";
679 for (uint objID: ObjIDs) {
680 colorPrimitives_objIDs[objID] = objID;
681 }
682 if (!colorPrimitives_UUIDs.empty()) {
683 colorPrimitives_UUIDs.clear();
684 }
685 primitiveColorsNeedUpdate = true;
686}
687
688void Visualizer::colorContextPrimitivesRandomly(const std::vector<uint> &UUIDs) {
690 if (!colorPrimitives_UUIDs.empty()) {
691 colorPrimitives_UUIDs.clear();
692 }
693 for (uint UUID: UUIDs) {
694 float rc = randu();
695 context->setPrimitiveData(UUID, "random_color", rc);
696 }
697
698 colorPrimitivesByData = "random_color";
699 colorPrimitivesByObjectData = "";
700 for (uint UUID: UUIDs) {
701 colorPrimitives_UUIDs[UUID] = UUID;
702 }
703 if (!colorPrimitives_objIDs.empty()) {
704 colorPrimitives_objIDs.clear();
705 }
706}
707
710
711 std::vector<uint> all_UUIDs = context->getAllUUIDs();
712 for (uint UUID: all_UUIDs) {
713 float rc = randu();
714 context->setPrimitiveData(UUID, "random_color", rc);
715 }
716
717 colorPrimitivesByData = "random_color";
718 colorPrimitivesByObjectData = "";
719 if (!colorPrimitives_UUIDs.empty()) {
720 colorPrimitives_UUIDs.clear();
721 }
722 if (!colorPrimitives_objIDs.empty()) {
723 colorPrimitives_objIDs.clear();
724 }
725}
726
727
728void Visualizer::colorContextObjectsRandomly(const std::vector<uint> &ObjIDs) {
730 if (!colorPrimitives_UUIDs.empty()) {
731 colorPrimitives_UUIDs.clear();
732 }
733 for (uint ObjID: ObjIDs) {
734 float rc = randu();
735 context->setObjectData(ObjID, "random_color", rc);
736 }
737
738 colorPrimitivesByData = "";
739 colorPrimitivesByObjectData = "random_color";
740}
741
743 std::vector<uint> all_ObjIDs = context->getAllObjectIDs();
745 if (!colorPrimitives_UUIDs.empty()) {
746 colorPrimitives_UUIDs.clear();
747 }
748 for (uint ObjID: all_ObjIDs) {
749 float rc = randu();
750 context->setObjectData(ObjID, "random_color", rc);
751 }
752
753 colorPrimitivesByData = "";
754 colorPrimitivesByObjectData = "random_color";
755}
756
758 colorPrimitivesByData = "";
759 colorPrimitivesByObjectData = "";
760 if (!colorPrimitives_UUIDs.empty()) {
761 colorPrimitives_UUIDs.clear();
762 }
763 if (!colorPrimitives_objIDs.empty()) {
764 colorPrimitives_objIDs.clear();
765 }
767 colorbar_min = 0;
768 colorbar_max = 0;
769 colorbar_flag = 0;
770 primitiveColorsNeedUpdate = true;
771}