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;
41 std::cerr <<
"WARNING (Visualizer::buildContextGeometry): There is no Context geometry to build...exiting." << std::endl;
45 context = context_ptr;
49 build_all_context_geometry =
false;
50 contextUUIDs_build = UUIDs;
53void Visualizer::buildContextGeometry_private() {
55 if (context ==
nullptr) {
60 if (build_all_context_geometry) {
61 bool include_deleted_UUIDs =
true;
62 if (contextUUIDs_build.empty()) {
63 include_deleted_UUIDs =
false;
65 contextUUIDs_build = context->
getDirtyUUIDs(include_deleted_UUIDs);
69 std::vector<uint> contextUUIDs_needupdate;
70 contextUUIDs_needupdate.reserve(contextUUIDs_build.size());
72 for (
uint UUID: contextUUIDs_build) {
76 auto it = std::find(contextUUIDs_build.begin(), contextUUIDs_build.end(), UUID);
77 if (it != contextUUIDs_build.end()) {
79 *it = contextUUIDs_build.back();
80 contextUUIDs_build.pop_back();
82 if (geometry_handler.doesGeometryExist(UUID)) {
89 contextUUIDs_needupdate.push_back(UUID);
93 if (contextUUIDs_needupdate.empty() && !primitiveColorsNeedUpdate) {
97 if (!colorPrimitivesByData.empty()) {
98 if (colorPrimitives_UUIDs.empty()) {
99 std::vector<uint> all_UUIDs = context->
getAllUUIDs();
100 for (
uint UUID: all_UUIDs) {
102 colorPrimitives_UUIDs[UUID] = UUID;
106 std::vector<uint> all_UUIDs = context->
getAllUUIDs();
107 for (
uint UUID: all_UUIDs) {
109 auto it = colorPrimitives_UUIDs.find(UUID);
110 colorPrimitives_UUIDs.erase(it);
114 }
else if (!colorPrimitivesByObjectData.empty()) {
115 if (colorPrimitives_objIDs.empty()) {
117 for (
uint objID: ObjIDs) {
120 for (
uint UUID: UUIDs) {
122 colorPrimitives_UUIDs[UUID] = UUID;
128 for (
const auto &objID: colorPrimitives_objIDs) {
131 for (
uint UUID: UUIDs) {
133 colorPrimitives_UUIDs[UUID] = UUID;
141 if (!colorPrimitives_UUIDs.empty() && colorbar_flag == 0) {
147 uint psize = contextUUIDs_needupdate.size();
150 if (psize >= 1e3 && psize < 1e6) {
151 std::cout <<
"updating " << psize / 1e3 <<
"K Context primitives to visualizer...." << std::flush;
152 }
else if (psize >= 1e6) {
153 std::cout <<
"updating " << psize / 1e6 <<
"M Context primitives to visualizer...." << std::flush;
155 std::cout <<
"updating " << psize <<
" Context primitives to visualizer...." << std::flush;
158 std::cerr <<
"WARNING (Visualizer::buildContextGeometry): No primitives were found in the Context..." << std::endl;
165 colormap_current.setRange(colorbar_min, colorbar_max);
166 if ((!colorPrimitivesByData.empty() || !colorPrimitivesByObjectData.empty()) && colorbar_min == 0 && colorbar_max == 0) {
168 colorbar_min = (std::numeric_limits<float>::max)();
169 colorbar_max = (std::numeric_limits<float>::lowest)();
171 for (
uint UUID: contextUUIDs_build) {
172 float colorValue = -9999;
173 if (!colorPrimitivesByData.empty()) {
174 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
177 if (type == HELIOS_TYPE_FLOAT) {
179 }
else if (type == HELIOS_TYPE_INT) {
182 colorValue = float(cv);
183 }
else if (type == HELIOS_TYPE_UINT) {
186 colorValue = float(cv);
187 }
else if (type == HELIOS_TYPE_DOUBLE) {
190 colorValue = float(cv);
198 }
else if (!colorPrimitivesByObjectData.empty()) {
199 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
201 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
203 if (type == HELIOS_TYPE_FLOAT) {
204 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
205 }
else if (type == HELIOS_TYPE_INT) {
207 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
208 colorValue = float(cv);
209 }
else if (type == HELIOS_TYPE_UINT) {
211 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
212 colorValue = float(cv);
213 }
else if (type == HELIOS_TYPE_DOUBLE) {
215 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
216 colorValue = float(cv);
226 if (std::isnan(colorValue) || std::isinf(colorValue)) {
230 if (colorValue != -9999) {
231 if (colorValue < colorbar_min) {
232 colorbar_min = colorValue;
235 if (colorValue > colorbar_max) {
236 colorbar_max = colorValue;
242 if (!std::isinf(colorbar_min) && !std::isinf(colorbar_max)) {
243 colormap_current.setRange(colorbar_min, colorbar_max);
247 if (!colorPrimitivesByData.empty()) {
248 assert(colorbar_min <= colorbar_max);
256 geometry_handler.
allocateBufferSize(patch_count, GeometryHandler::GEOMETRY_TYPE_RECTANGLE);
258 geometry_handler.
allocateBufferSize(triangle_count, GeometryHandler::GEOMETRY_TYPE_TRIANGLE);
260 for (
unsigned int UUID: contextUUIDs_needupdate) {
263 std::cerr <<
"WARNING (Visualizer::buildContextGeometry): UUID vector contains ID(s) that do not exist in the Context...they will be ignored." << std::endl;
274 if (!colorPrimitivesByData.empty()) {
275 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
278 if (type == HELIOS_TYPE_FLOAT) {
280 }
else if (type == HELIOS_TYPE_INT) {
283 colorValue = float(cv);
284 }
else if (type == HELIOS_TYPE_UINT) {
287 colorValue = float(cv);
288 }
else if (type == HELIOS_TYPE_DOUBLE) {
291 colorValue = float(cv);
299 if (std::isnan(colorValue) || std::isinf(colorValue)) {
307 }
else if (!colorPrimitivesByObjectData.empty()) {
308 if (colorPrimitives_UUIDs.find(UUID) != colorPrimitives_UUIDs.end()) {
310 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
312 if (type == HELIOS_TYPE_FLOAT) {
313 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
314 }
else if (type == HELIOS_TYPE_INT) {
316 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
317 colorValue = float(cv);
318 }
else if (type == HELIOS_TYPE_UINT) {
320 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
321 colorValue = float(cv);
322 }
else if (type == HELIOS_TYPE_DOUBLE) {
324 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
325 colorValue = float(cv);
333 if (std::isnan(colorValue) || std::isinf(colorValue)) {
346 if (!texture_file.empty()) {
347 textureID = registerTextureImage(texture_file);
351 if (ptype == helios::PRIMITIVE_TYPE_PATCH) {
353 if (texture_file.empty()) {
354 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
362 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
366 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, verts, color, uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
371 else if (ptype == helios::PRIMITIVE_TYPE_TRIANGLE) {
373 if (texture_file.empty()) {
374 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
382 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
386 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_TRIANGLE, verts, color, uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
391 else if (ptype == helios::PRIMITIVE_TYPE_VOXEL) {
395 const std::vector<vec3> bottom_vertices{v_vertices.at(0), v_vertices.at(1), v_vertices.at(2), v_vertices.at(3)};
398 const std::vector<vec3> top_vertices{v_vertices.at(4), v_vertices.at(5), v_vertices.at(6), v_vertices.at(7)};
401 const std::vector<vec3> mx_vertices{v_vertices.at(0), v_vertices.at(3), v_vertices.at(7), v_vertices.at(4)};
404 const std::vector<vec3> px_vertices{v_vertices.at(1), v_vertices.at(2), v_vertices.at(6), v_vertices.at(5)};
407 const std::vector<vec3> my_vertices{v_vertices.at(0), v_vertices.at(1), v_vertices.at(5), v_vertices.at(4)};
410 const std::vector<vec3> py_vertices{v_vertices.at(2), v_vertices.at(3), v_vertices.at(7), v_vertices.at(6)};
413 if (texture_file.empty()) {
414 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, bottom_vertices, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
415 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, top_vertices, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
416 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, mx_vertices, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
417 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, px_vertices, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
418 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, my_vertices, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
419 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, py_vertices, color, {}, -1,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
423 const std::vector<helios::vec2> voxel_uvs = {{0.f, 0.f}, {1.f, 0.f}, {1.f, 1.f}, {0.f, 1.f}};
427 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, bottom_vertices, color, voxel_uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
428 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, top_vertices, color, voxel_uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
429 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, mx_vertices, color, voxel_uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
430 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, px_vertices, color, voxel_uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
431 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, my_vertices, color, voxel_uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
432 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, py_vertices, color, voxel_uvs, textureID,
false,
false,
COORDINATES_CARTESIAN,
true,
true);
436 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, bottom_vertices, color, voxel_uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
437 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, top_vertices, color, voxel_uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
438 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, mx_vertices, color, voxel_uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
439 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, px_vertices, color, voxel_uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
440 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, my_vertices, color, voxel_uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
441 geometry_handler.
addGeometry(UUID, GeometryHandler::GEOMETRY_TYPE_RECTANGLE, py_vertices, color, voxel_uvs, textureID,
true,
false,
COORDINATES_CARTESIAN,
true,
true);
447 if (primitiveColorsNeedUpdate) {
454 std::vector<size_t> geometry_UUIDs = geometry_handler.getAllGeometryIDs();
456 if (geometry_UUIDs.empty()) {
457 primitiveColorsNeedUpdate =
false;
461 colormap_current.setRange(colorbar_min, colorbar_max);
463 if ((!colorPrimitivesByData.empty() || !colorPrimitivesByObjectData.empty()) && colorbar_min == 0 && colorbar_max == 0) {
464 colorbar_min = (std::numeric_limits<float>::max)();
465 colorbar_max = (std::numeric_limits<float>::lowest)();
467 for (
auto UUID: geometry_UUIDs) {
472 float colorValue = -9999.f;
473 if (!colorPrimitivesByData.empty()) {
474 if (colorPrimitives_UUIDs.find(
static_cast<uint>(UUID)) != colorPrimitives_UUIDs.end()) {
482 colorValue = float(cv);
486 colorValue = float(cv);
490 colorValue = float(cv);
498 }
else if (!colorPrimitivesByObjectData.empty()) {
499 if (colorPrimitives_UUIDs.find(
static_cast<uint>(UUID)) != colorPrimitives_UUIDs.end()) {
501 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
504 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
507 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
508 colorValue = float(cv);
511 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
512 colorValue = float(cv);
515 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
516 colorValue = float(cv);
526 if (std::isnan(colorValue) || std::isinf(colorValue)) {
530 if (colorValue != -9999.f) {
531 if (colorValue < colorbar_min) {
532 colorbar_min = colorValue;
534 if (colorValue > colorbar_max) {
535 colorbar_max = colorValue;
540 if (!std::isinf(colorbar_min) && !std::isinf(colorbar_max)) {
541 colormap_current.setRange(colorbar_min, colorbar_max);
545 for (
auto UUID: geometry_UUIDs) {
555 if (!colorPrimitivesByData.empty()) {
556 if (colorPrimitives_UUIDs.find(uid) != colorPrimitives_UUIDs.end()) {
557 float colorValue = 0.f;
565 colorValue = float(cv);
569 colorValue = float(cv);
573 colorValue = float(cv);
579 if (std::isnan(colorValue) || std::isinf(colorValue)) {
585 if (!texture_file.empty()) {
588 }
else if (!texture_file.empty()) {
591 }
else if (!colorPrimitivesByObjectData.empty()) {
592 if (colorPrimitives_UUIDs.find(uid) != colorPrimitives_UUIDs.end()) {
593 float colorValue = 0.f;
595 if (ObjID != 0 && context->
doesObjectDataExist(ObjID, colorPrimitivesByObjectData.c_str())) {
598 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), colorValue);
601 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
602 colorValue = float(cv);
605 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
606 colorValue = float(cv);
609 context->
getObjectData(ObjID, colorPrimitivesByObjectData.c_str(), cv);
610 colorValue = float(cv);
616 if (std::isnan(colorValue) || std::isinf(colorValue)) {
622 if (!texture_file.empty()) {
625 }
else if (!texture_file.empty()) {
629 if (!texture_file.empty()) {
634 geometry_handler.
setColor(UUID, color);
637 primitiveColorsNeedUpdate =
false;
641 colorPrimitivesByData = data_name;
642 colorPrimitivesByObjectData =
"";
643 if (!colorPrimitives_UUIDs.empty()) {
644 colorPrimitives_UUIDs.clear();
646 if (!colorPrimitives_objIDs.empty()) {
647 colorPrimitives_objIDs.clear();
649 primitiveColorsNeedUpdate =
true;
653 colorPrimitivesByData = data_name;
654 colorPrimitivesByObjectData =
"";
655 for (
uint UUID: UUIDs) {
656 colorPrimitives_UUIDs[UUID] = UUID;
658 if (!colorPrimitives_objIDs.empty()) {
659 colorPrimitives_objIDs.clear();
661 primitiveColorsNeedUpdate =
true;
665 colorPrimitivesByObjectData = data_name;
666 colorPrimitivesByData =
"";
667 if (!colorPrimitives_UUIDs.empty()) {
668 colorPrimitives_UUIDs.clear();
670 if (!colorPrimitives_objIDs.empty()) {
671 colorPrimitives_objIDs.clear();
673 primitiveColorsNeedUpdate =
true;
677 colorPrimitivesByObjectData = data_name;
678 colorPrimitivesByData =
"";
679 for (
uint objID: ObjIDs) {
680 colorPrimitives_objIDs[objID] = objID;
682 if (!colorPrimitives_UUIDs.empty()) {
683 colorPrimitives_UUIDs.clear();
685 primitiveColorsNeedUpdate =
true;
690 if (!colorPrimitives_UUIDs.empty()) {
691 colorPrimitives_UUIDs.clear();
693 for (
uint UUID: UUIDs) {
698 colorPrimitivesByData =
"random_color";
699 colorPrimitivesByObjectData =
"";
700 for (
uint UUID: UUIDs) {
701 colorPrimitives_UUIDs[UUID] = UUID;
703 if (!colorPrimitives_objIDs.empty()) {
704 colorPrimitives_objIDs.clear();
711 std::vector<uint> all_UUIDs = context->
getAllUUIDs();
712 for (
uint UUID: all_UUIDs) {
717 colorPrimitivesByData =
"random_color";
718 colorPrimitivesByObjectData =
"";
719 if (!colorPrimitives_UUIDs.empty()) {
720 colorPrimitives_UUIDs.clear();
722 if (!colorPrimitives_objIDs.empty()) {
723 colorPrimitives_objIDs.clear();
730 if (!colorPrimitives_UUIDs.empty()) {
731 colorPrimitives_UUIDs.clear();
733 for (
uint ObjID: ObjIDs) {
738 colorPrimitivesByData =
"";
739 colorPrimitivesByObjectData =
"random_color";
745 if (!colorPrimitives_UUIDs.empty()) {
746 colorPrimitives_UUIDs.clear();
748 for (
uint ObjID: all_ObjIDs) {
753 colorPrimitivesByData =
"";
754 colorPrimitivesByObjectData =
"random_color";
758 colorPrimitivesByData =
"";
759 colorPrimitivesByObjectData =
"";
760 if (!colorPrimitives_UUIDs.empty()) {
761 colorPrimitives_UUIDs.clear();
763 if (!colorPrimitives_objIDs.empty()) {
764 colorPrimitives_objIDs.clear();
770 primitiveColorsNeedUpdate =
true;