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