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