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()) {
128 std::vector<uint> all_UUIDs = context->
getAllUUIDs();
129 for (
uint UUID: all_UUIDs) {
131 colorPrimitives_UUIDs[UUID] = UUID;
135 for (
const auto &objID: colorPrimitives_objIDs) {
138 for (
uint UUID: UUIDs) {
140 colorPrimitives_UUIDs[UUID] = UUID;
148 if (!colorPrimitives_UUIDs.empty() && colorbar_flag == 0) {
154 uint psize = contextUUIDs_needupdate.size();
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;
162 std::cout <<
"updating " << psize <<
" Context primitives to visualizer...." << std::flush;
165 std::cerr <<
"WARNING (Visualizer::buildContextGeometry): No primitives were found in the Context..." << std::endl;
172 colormap_current.setRange(colorbar_min, colorbar_max);
173 if ((!colorPrimitivesByData.empty() || !colorPrimitivesByObjectData.empty()) && colorbar_min == 0 && colorbar_max == 0) {
175 colorbar_min = (std::numeric_limits<float>::max)();
176 colorbar_max = (std::numeric_limits<float>::lowest)();
179 colorbar_integer_data =
false;
180 bool data_type_detected =
false;
182 for (
uint UUID: contextUUIDs_build) {
183 float colorValue = -9999;
184 if (!colorPrimitivesByData.empty()) {
185 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
190 if (!data_type_detected) {
192 data_type_detected =
true;
195 if (type == HELIOS_TYPE_FLOAT) {
197 }
else if (type == HELIOS_TYPE_INT) {
200 colorValue = float(cv);
201 }
else if (type == HELIOS_TYPE_UINT) {
204 colorValue = float(cv);
205 }
else if (type == HELIOS_TYPE_DOUBLE) {
208 colorValue = float(cv);
216 }
else if (!colorPrimitivesByObjectData.empty()) {
217 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
219 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
223 if (!data_type_detected) {
225 data_type_detected =
true;
228 if (type == HELIOS_TYPE_FLOAT) {
229 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
230 }
else if (type == HELIOS_TYPE_INT) {
232 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
233 colorValue = float(cv);
234 }
else if (type == HELIOS_TYPE_UINT) {
236 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
237 colorValue = float(cv);
238 }
else if (type == HELIOS_TYPE_DOUBLE) {
240 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
241 colorValue = float(cv);
251 if (std::isnan(colorValue) || std::isinf(colorValue)) {
255 if (colorValue != -9999) {
256 if (colorValue < colorbar_min) {
257 colorbar_min = colorValue;
260 if (colorValue > colorbar_max) {
261 colorbar_max = colorValue;
267 if (!std::isinf(colorbar_min) && !std::isinf(colorbar_max)) {
268 colormap_current.setRange(colorbar_min, colorbar_max);
272 if (!colorPrimitivesByData.empty()) {
273 assert(colorbar_min <= colorbar_max);
281 geometry_handler.
allocateBufferSize(patch_count, GeometryHandler::GEOMETRY_TYPE_RECTANGLE);
283 geometry_handler.
allocateBufferSize(triangle_count, GeometryHandler::GEOMETRY_TYPE_TRIANGLE);
285 for (
unsigned int UUID: contextUUIDs_needupdate) {
288 std::cerr <<
"WARNING (Visualizer::buildContextGeometry): UUID vector contains ID(s) that do not exist in the Context...they will be ignored." << std::endl;
299 if (!colorPrimitivesByData.empty()) {
300 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
303 if (type == HELIOS_TYPE_FLOAT) {
305 }
else if (type == HELIOS_TYPE_INT) {
308 colorValue = float(cv);
309 }
else if (type == HELIOS_TYPE_UINT) {
312 colorValue = float(cv);
313 }
else if (type == HELIOS_TYPE_DOUBLE) {
316 colorValue = float(cv);
324 if (std::isnan(colorValue) || std::isinf(colorValue)) {
332 }
else if (!colorPrimitivesByObjectData.empty()) {
333 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
335 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
337 if (type == HELIOS_TYPE_FLOAT) {
338 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
339 }
else if (type == HELIOS_TYPE_INT) {
341 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
342 colorValue = float(cv);
343 }
else if (type == HELIOS_TYPE_UINT) {
345 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
346 colorValue = float(cv);
347 }
else if (type == HELIOS_TYPE_DOUBLE) {
349 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
350 colorValue = float(cv);
358 if (std::isnan(colorValue) || std::isinf(colorValue)) {
371 if (!texture_file.empty()) {
372 textureID = registerTextureImage(texture_file);
376 if (ptype == helios::PRIMITIVE_TYPE_PATCH) {
378 if (texture_file.empty()) {
379 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
387 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
391 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
396 else if (ptype == helios::PRIMITIVE_TYPE_TRIANGLE) {
398 if (texture_file.empty()) {
399 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
407 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
411 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
416 else if (ptype == helios::PRIMITIVE_TYPE_VOXEL) {
420 const std::vector<vec3> bottom_vertices{v_vertices.at(0), v_vertices.at(1), v_vertices.at(2), v_vertices.at(3)};
423 const std::vector<vec3> top_vertices{v_vertices.at(4), v_vertices.at(5), v_vertices.at(6), v_vertices.at(7)};
426 const std::vector<vec3> mx_vertices{v_vertices.at(0), v_vertices.at(3), v_vertices.at(7), v_vertices.at(4)};
429 const std::vector<vec3> px_vertices{v_vertices.at(1), v_vertices.at(2), v_vertices.at(6), v_vertices.at(5)};
432 const std::vector<vec3> my_vertices{v_vertices.at(0), v_vertices.at(1), v_vertices.at(5), v_vertices.at(4)};
435 const std::vector<vec3> py_vertices{v_vertices.at(2), v_vertices.at(3), v_vertices.at(7), v_vertices.at(6)};
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);
448 const std::vector<helios::vec2> voxel_uvs = {{0.f, 0.f}, {1.f, 0.f}, {1.f, 1.f}, {0.f, 1.f}};
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);
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);
472 if (primitiveColorsNeedUpdate) {
479 std::vector<size_t> geometry_UUIDs = geometry_handler.getAllGeometryIDs();
481 if (geometry_UUIDs.empty()) {
482 primitiveColorsNeedUpdate =
false;
486 colormap_current.setRange(colorbar_min, colorbar_max);
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)();
493 colorbar_integer_data =
false;
494 bool data_type_detected =
false;
496 for (
auto UUID: geometry_UUIDs) {
501 float colorValue = -9999.f;
502 if (!colorPrimitivesByData.empty()) {
503 if (colorPrimitives_UUIDs.find(
static_cast<uint>(UUID)) != colorPrimitives_UUIDs.end()) {
508 if (!data_type_detected) {
510 data_type_detected =
true;
518 colorValue = float(cv);
522 colorValue = float(cv);
526 colorValue = float(cv);
534 }
else if (!colorPrimitivesByObjectData.empty()) {
535 if (colorPrimitives_UUIDs.find(
static_cast<uint>(UUID)) != colorPrimitives_UUIDs.end()) {
537 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
541 if (!data_type_detected) {
543 data_type_detected =
true;
547 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
550 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
551 colorValue = float(cv);
554 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
555 colorValue = float(cv);
558 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
559 colorValue = float(cv);
569 if (std::isnan(colorValue) || std::isinf(colorValue)) {
573 if (colorValue != -9999.f) {
574 if (colorValue < colorbar_min) {
575 colorbar_min = colorValue;
577 if (colorValue > colorbar_max) {
578 colorbar_max = colorValue;
583 if (!std::isinf(colorbar_min) && !std::isinf(colorbar_max)) {
584 colormap_current.setRange(colorbar_min, colorbar_max);
588 for (
auto UUID: geometry_UUIDs) {
598 if (!colorPrimitivesByData.empty()) {
599 if (colorPrimitives_UUIDs.find(uid) != colorPrimitives_UUIDs.end()) {
600 float colorValue = 0.f;
608 colorValue = float(cv);
612 colorValue = float(cv);
616 colorValue = float(cv);
622 if (std::isnan(colorValue) || std::isinf(colorValue)) {
628 if (!texture_file.empty()) {
631 }
else if (!texture_file.empty()) {
634 }
else if (!colorPrimitivesByObjectData.empty()) {
635 if (colorPrimitives_UUIDs.find(uid) != colorPrimitives_UUIDs.end()) {
636 float colorValue = 0.f;
638 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
641 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
644 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
645 colorValue = float(cv);
648 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
649 colorValue = float(cv);
652 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
653 colorValue = float(cv);
659 if (std::isnan(colorValue) || std::isinf(colorValue)) {
665 if (!texture_file.empty()) {
668 }
else if (!texture_file.empty()) {
672 if (!texture_file.empty()) {
677 geometry_handler.
setColor(UUID, color);
680 primitiveColorsNeedUpdate =
false;
684 colorPrimitivesByData = data_name;
685 colorPrimitivesByObjectData =
"";
686 if (!colorPrimitives_UUIDs.empty()) {
687 colorPrimitives_UUIDs.clear();
689 if (!colorPrimitives_objIDs.empty()) {
690 colorPrimitives_objIDs.clear();
692 primitiveColorsNeedUpdate =
true;
696 colorPrimitivesByData = data_name;
697 colorPrimitivesByObjectData =
"";
698 for (
uint UUID: UUIDs) {
699 colorPrimitives_UUIDs[UUID] = UUID;
701 if (!colorPrimitives_objIDs.empty()) {
702 colorPrimitives_objIDs.clear();
704 primitiveColorsNeedUpdate =
true;
708 colorPrimitivesByObjectData = data_name;
709 colorPrimitivesByData =
"";
710 if (!colorPrimitives_UUIDs.empty()) {
711 colorPrimitives_UUIDs.clear();
713 if (!colorPrimitives_objIDs.empty()) {
714 colorPrimitives_objIDs.clear();
716 primitiveColorsNeedUpdate =
true;
720 colorPrimitivesByObjectData = data_name;
721 colorPrimitivesByData =
"";
722 for (
uint objID: ObjIDs) {
723 colorPrimitives_objIDs[objID] = objID;
725 if (!colorPrimitives_UUIDs.empty()) {
726 colorPrimitives_UUIDs.clear();
728 primitiveColorsNeedUpdate =
true;
733 if (!colorPrimitives_UUIDs.empty()) {
734 colorPrimitives_UUIDs.clear();
736 for (
uint UUID: UUIDs) {
741 colorPrimitivesByData =
"random_color";
742 colorPrimitivesByObjectData =
"";
743 for (
uint UUID: UUIDs) {
744 colorPrimitives_UUIDs[UUID] = UUID;
746 if (!colorPrimitives_objIDs.empty()) {
747 colorPrimitives_objIDs.clear();
754 std::vector<uint> all_UUIDs = context->
getAllUUIDs();
755 for (
uint UUID: all_UUIDs) {
760 colorPrimitivesByData =
"random_color";
761 colorPrimitivesByObjectData =
"";
762 if (!colorPrimitives_UUIDs.empty()) {
763 colorPrimitives_UUIDs.clear();
765 if (!colorPrimitives_objIDs.empty()) {
766 colorPrimitives_objIDs.clear();
773 if (!colorPrimitives_UUIDs.empty()) {
774 colorPrimitives_UUIDs.clear();
776 for (
uint ObjID: ObjIDs) {
781 colorPrimitivesByData =
"";
782 colorPrimitivesByObjectData =
"random_color";
788 if (!colorPrimitives_UUIDs.empty()) {
789 colorPrimitives_UUIDs.clear();
791 for (
uint ObjID: all_ObjIDs) {
796 colorPrimitivesByData =
"";
797 colorPrimitivesByObjectData =
"random_color";
801 colorPrimitivesByData =
"";
802 colorPrimitivesByObjectData =
"";
803 colorbar_integer_data =
false;
804 if (!colorPrimitives_UUIDs.empty()) {
805 colorPrimitives_UUIDs.clear();
807 if (!colorPrimitives_objIDs.empty()) {
808 colorPrimitives_objIDs.clear();
814 primitiveColorsNeedUpdate =
true;