18using namespace helios;
23 contextUUIDs_build.clear();
24 colorPrimitives_UUIDs.clear();
25 colorPrimitives_objIDs.clear();
26 depth_buffer_data.clear();
32 context = context_ptr;
36 build_all_context_geometry =
true;
39 if (navigation_gizmo_was_enabled_before_image_display) {
41 navigation_gizmo_was_enabled_before_image_display =
false;
47 std::cerr <<
"WARNING (Visualizer::buildContextGeometry): There is no Context geometry to build...exiting." << std::endl;
51 context = context_ptr;
55 build_all_context_geometry =
false;
56 contextUUIDs_build = UUIDs;
59 if (navigation_gizmo_was_enabled_before_image_display) {
61 navigation_gizmo_was_enabled_before_image_display =
false;
65void Visualizer::buildContextGeometry_private() {
67 if (context ==
nullptr) {
72 if (build_all_context_geometry) {
73 bool include_deleted_UUIDs =
true;
74 if (contextUUIDs_build.empty()) {
75 include_deleted_UUIDs =
false;
77 contextUUIDs_build = context->
getDirtyUUIDs(include_deleted_UUIDs);
81 std::vector<uint> contextUUIDs_needupdate;
82 contextUUIDs_needupdate.reserve(contextUUIDs_build.size());
84 for (
uint UUID: contextUUIDs_build) {
88 auto it = std::find(contextUUIDs_build.begin(), contextUUIDs_build.end(), UUID);
89 if (it != contextUUIDs_build.end()) {
91 *it = contextUUIDs_build.back();
92 contextUUIDs_build.pop_back();
94 if (geometry_handler.doesGeometryExist(UUID)) {
101 contextUUIDs_needupdate.push_back(UUID);
105 if (contextUUIDs_needupdate.empty() && !primitiveColorsNeedUpdate) {
109 if (!colorPrimitivesByData.empty()) {
110 if (colorPrimitives_UUIDs.empty()) {
111 std::vector<uint> all_UUIDs = context->
getAllUUIDs();
112 for (
uint UUID: all_UUIDs) {
114 colorPrimitives_UUIDs[UUID] = UUID;
118 std::vector<uint> all_UUIDs = context->
getAllUUIDs();
119 for (
uint UUID: all_UUIDs) {
121 auto it = colorPrimitives_UUIDs.find(UUID);
122 colorPrimitives_UUIDs.erase(it);
126 }
else if (!colorPrimitivesByObjectData.empty()) {
127 if (colorPrimitives_objIDs.empty()) {
129 for (
uint objID: ObjIDs) {
132 for (
uint UUID: UUIDs) {
134 colorPrimitives_UUIDs[UUID] = UUID;
140 for (
const auto &objID: colorPrimitives_objIDs) {
143 for (
uint UUID: UUIDs) {
145 colorPrimitives_UUIDs[UUID] = UUID;
153 if (!colorPrimitives_UUIDs.empty() && colorbar_flag == 0) {
159 uint psize = contextUUIDs_needupdate.size();
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;
167 std::cout <<
"updating " << psize <<
" Context primitives to visualizer...." << std::flush;
170 std::cerr <<
"WARNING (Visualizer::buildContextGeometry): No primitives were found in the Context..." << std::endl;
177 colormap_current.setRange(colorbar_min, colorbar_max);
178 if ((!colorPrimitivesByData.empty() || !colorPrimitivesByObjectData.empty()) && colorbar_min == 0 && colorbar_max == 0) {
180 colorbar_min = (std::numeric_limits<float>::max)();
181 colorbar_max = (std::numeric_limits<float>::lowest)();
184 colorbar_integer_data =
false;
185 bool data_type_detected =
false;
187 for (
uint UUID: contextUUIDs_build) {
188 float colorValue = -9999;
189 if (!colorPrimitivesByData.empty()) {
190 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
195 if (!data_type_detected) {
197 data_type_detected =
true;
200 if (type == HELIOS_TYPE_FLOAT) {
202 }
else if (type == HELIOS_TYPE_INT) {
205 colorValue = float(cv);
206 }
else if (type == HELIOS_TYPE_UINT) {
209 colorValue = float(cv);
210 }
else if (type == HELIOS_TYPE_DOUBLE) {
213 colorValue = float(cv);
221 }
else if (!colorPrimitivesByObjectData.empty()) {
222 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
224 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
228 if (!data_type_detected) {
230 data_type_detected =
true;
233 if (type == HELIOS_TYPE_FLOAT) {
234 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
235 }
else if (type == HELIOS_TYPE_INT) {
237 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
238 colorValue = float(cv);
239 }
else if (type == HELIOS_TYPE_UINT) {
241 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
242 colorValue = float(cv);
243 }
else if (type == HELIOS_TYPE_DOUBLE) {
245 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
246 colorValue = float(cv);
256 if (std::isnan(colorValue) || std::isinf(colorValue)) {
260 if (colorValue != -9999) {
261 if (colorValue < colorbar_min) {
262 colorbar_min = colorValue;
265 if (colorValue > colorbar_max) {
266 colorbar_max = colorValue;
272 if (!std::isinf(colorbar_min) && !std::isinf(colorbar_max)) {
273 colormap_current.setRange(colorbar_min, colorbar_max);
277 if (!colorPrimitivesByData.empty()) {
278 assert(colorbar_min <= colorbar_max);
286 geometry_handler.
allocateBufferSize(patch_count, GeometryHandler::GEOMETRY_TYPE_RECTANGLE);
288 geometry_handler.
allocateBufferSize(triangle_count, GeometryHandler::GEOMETRY_TYPE_TRIANGLE);
290 for (
unsigned int UUID: contextUUIDs_needupdate) {
293 std::cerr <<
"WARNING (Visualizer::buildContextGeometry): UUID vector contains ID(s) that do not exist in the Context...they will be ignored." << std::endl;
304 if (!colorPrimitivesByData.empty()) {
305 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
308 if (type == HELIOS_TYPE_FLOAT) {
310 }
else if (type == HELIOS_TYPE_INT) {
313 colorValue = float(cv);
314 }
else if (type == HELIOS_TYPE_UINT) {
317 colorValue = float(cv);
318 }
else if (type == HELIOS_TYPE_DOUBLE) {
321 colorValue = float(cv);
329 if (std::isnan(colorValue) || std::isinf(colorValue)) {
337 }
else if (!colorPrimitivesByObjectData.empty()) {
338 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
340 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
342 if (type == HELIOS_TYPE_FLOAT) {
343 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
344 }
else if (type == HELIOS_TYPE_INT) {
346 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
347 colorValue = float(cv);
348 }
else if (type == HELIOS_TYPE_UINT) {
350 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
351 colorValue = float(cv);
352 }
else if (type == HELIOS_TYPE_DOUBLE) {
354 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
355 colorValue = float(cv);
363 if (std::isnan(colorValue) || std::isinf(colorValue)) {
376 if (!texture_file.empty()) {
377 textureID = registerTextureImage(texture_file);
381 if (ptype == helios::PRIMITIVE_TYPE_PATCH) {
383 if (texture_file.empty()) {
384 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
392 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
396 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
401 else if (ptype == helios::PRIMITIVE_TYPE_TRIANGLE) {
403 if (texture_file.empty()) {
404 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
412 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
416 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
421 else if (ptype == helios::PRIMITIVE_TYPE_VOXEL) {
425 const std::vector<vec3> bottom_vertices{v_vertices.at(0), v_vertices.at(1), v_vertices.at(2), v_vertices.at(3)};
428 const std::vector<vec3> top_vertices{v_vertices.at(4), v_vertices.at(5), v_vertices.at(6), v_vertices.at(7)};
431 const std::vector<vec3> mx_vertices{v_vertices.at(0), v_vertices.at(3), v_vertices.at(7), v_vertices.at(4)};
434 const std::vector<vec3> px_vertices{v_vertices.at(1), v_vertices.at(2), v_vertices.at(6), v_vertices.at(5)};
437 const std::vector<vec3> my_vertices{v_vertices.at(0), v_vertices.at(1), v_vertices.at(5), v_vertices.at(4)};
440 const std::vector<vec3> py_vertices{v_vertices.at(2), v_vertices.at(3), v_vertices.at(7), v_vertices.at(6)};
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);
453 const std::vector<helios::vec2> voxel_uvs = {{0.f, 0.f}, {1.f, 0.f}, {1.f, 1.f}, {0.f, 1.f}};
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);
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);
477 if (primitiveColorsNeedUpdate) {
484 std::vector<size_t> geometry_UUIDs = geometry_handler.getAllGeometryIDs();
486 if (geometry_UUIDs.empty()) {
487 primitiveColorsNeedUpdate =
false;
491 colormap_current.setRange(colorbar_min, colorbar_max);
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)();
498 colorbar_integer_data =
false;
499 bool data_type_detected =
false;
501 for (
auto UUID: geometry_UUIDs) {
506 float colorValue = -9999.f;
507 if (!colorPrimitivesByData.empty()) {
508 if (colorPrimitives_UUIDs.find(
static_cast<uint>(UUID)) != colorPrimitives_UUIDs.end()) {
513 if (!data_type_detected) {
515 data_type_detected =
true;
523 colorValue = float(cv);
527 colorValue = float(cv);
531 colorValue = float(cv);
539 }
else if (!colorPrimitivesByObjectData.empty()) {
540 if (colorPrimitives_UUIDs.find(
static_cast<uint>(UUID)) != colorPrimitives_UUIDs.end()) {
542 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
546 if (!data_type_detected) {
548 data_type_detected =
true;
552 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
555 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
556 colorValue = float(cv);
559 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
560 colorValue = float(cv);
563 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
564 colorValue = float(cv);
574 if (std::isnan(colorValue) || std::isinf(colorValue)) {
578 if (colorValue != -9999.f) {
579 if (colorValue < colorbar_min) {
580 colorbar_min = colorValue;
582 if (colorValue > colorbar_max) {
583 colorbar_max = colorValue;
588 if (!std::isinf(colorbar_min) && !std::isinf(colorbar_max)) {
589 colormap_current.setRange(colorbar_min, colorbar_max);
593 for (
auto UUID: geometry_UUIDs) {
603 if (!colorPrimitivesByData.empty()) {
604 if (colorPrimitives_UUIDs.find(uid) != colorPrimitives_UUIDs.end()) {
605 float colorValue = 0.f;
613 colorValue = float(cv);
617 colorValue = float(cv);
621 colorValue = float(cv);
627 if (std::isnan(colorValue) || std::isinf(colorValue)) {
633 if (!texture_file.empty()) {
636 }
else if (!texture_file.empty()) {
639 }
else if (!colorPrimitivesByObjectData.empty()) {
640 if (colorPrimitives_UUIDs.find(uid) != colorPrimitives_UUIDs.end()) {
641 float colorValue = 0.f;
643 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
646 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
649 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
650 colorValue = float(cv);
653 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
654 colorValue = float(cv);
657 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
658 colorValue = float(cv);
664 if (std::isnan(colorValue) || std::isinf(colorValue)) {
670 if (!texture_file.empty()) {
673 }
else if (!texture_file.empty()) {
677 if (!texture_file.empty()) {
682 geometry_handler.
setColor(UUID, color);
685 primitiveColorsNeedUpdate =
false;
689 colorPrimitivesByData = data_name;
690 colorPrimitivesByObjectData =
"";
691 if (!colorPrimitives_UUIDs.empty()) {
692 colorPrimitives_UUIDs.clear();
694 if (!colorPrimitives_objIDs.empty()) {
695 colorPrimitives_objIDs.clear();
697 primitiveColorsNeedUpdate =
true;
701 colorPrimitivesByData = data_name;
702 colorPrimitivesByObjectData =
"";
703 for (
uint UUID: UUIDs) {
704 colorPrimitives_UUIDs[UUID] = UUID;
706 if (!colorPrimitives_objIDs.empty()) {
707 colorPrimitives_objIDs.clear();
709 primitiveColorsNeedUpdate =
true;
713 colorPrimitivesByObjectData = data_name;
714 colorPrimitivesByData =
"";
715 if (!colorPrimitives_UUIDs.empty()) {
716 colorPrimitives_UUIDs.clear();
718 if (!colorPrimitives_objIDs.empty()) {
719 colorPrimitives_objIDs.clear();
721 primitiveColorsNeedUpdate =
true;
725 colorPrimitivesByObjectData = data_name;
726 colorPrimitivesByData =
"";
727 for (
uint objID: ObjIDs) {
728 colorPrimitives_objIDs[objID] = objID;
730 if (!colorPrimitives_UUIDs.empty()) {
731 colorPrimitives_UUIDs.clear();
733 primitiveColorsNeedUpdate =
true;
738 if (!colorPrimitives_UUIDs.empty()) {
739 colorPrimitives_UUIDs.clear();
741 for (
uint UUID: UUIDs) {
746 colorPrimitivesByData =
"random_color";
747 colorPrimitivesByObjectData =
"";
748 for (
uint UUID: UUIDs) {
749 colorPrimitives_UUIDs[UUID] = UUID;
751 if (!colorPrimitives_objIDs.empty()) {
752 colorPrimitives_objIDs.clear();
759 std::vector<uint> all_UUIDs = context->
getAllUUIDs();
760 for (
uint UUID: all_UUIDs) {
765 colorPrimitivesByData =
"random_color";
766 colorPrimitivesByObjectData =
"";
767 if (!colorPrimitives_UUIDs.empty()) {
768 colorPrimitives_UUIDs.clear();
770 if (!colorPrimitives_objIDs.empty()) {
771 colorPrimitives_objIDs.clear();
778 if (!colorPrimitives_UUIDs.empty()) {
779 colorPrimitives_UUIDs.clear();
781 for (
uint ObjID: ObjIDs) {
786 colorPrimitivesByData =
"";
787 colorPrimitivesByObjectData =
"random_color";
793 if (!colorPrimitives_UUIDs.empty()) {
794 colorPrimitives_UUIDs.clear();
796 for (
uint ObjID: all_ObjIDs) {
801 colorPrimitivesByData =
"";
802 colorPrimitivesByObjectData =
"random_color";
806 colorPrimitivesByData =
"";
807 colorPrimitivesByObjectData =
"";
808 colorbar_integer_data =
false;
809 if (!colorPrimitives_UUIDs.empty()) {
810 colorPrimitives_UUIDs.clear();
812 if (!colorPrimitives_objIDs.empty()) {
813 colorPrimitives_objIDs.clear();
819 primitiveColorsNeedUpdate =
true;