From 129ce2c70aa8078557770bd91a311b174deb6053 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 15:13:55 +0000 Subject: [PATCH 1/2] Map ROI: kernel command from a click on the monitoring map, cameras look at the point - CMD_KRNL_MAP_ROI (242), PARAM ";;" from Mojo_Web (doApplicationOperation 15): format 0 = WGS84 degrees, 1 = local binding (bitmap map, map units). - mojoKernel::mapROI(): WGS84 -> system coordinates through the site anchor (its UTM zone, the site's ground level); local -> map minus the anchor (the map shows a node at anchor + its local coordinates). A format that does not match the anchor (map type changed after the start) or a wrong parameter is logged and ignored. Starts a session and broadcasts EVT_ROI_ACTIVE (EVT_CLASS_SYSTEM, TARGET_DATA) like a sensor's ROI; dispatchEvent saves it as an event of the report. - Cameras: a map ROI has no preferred camera, so PTZ, preset and static cameras act on it only when the point passes their testFOV (range, pan limits, field of view): PTZ/preset lookAt, static makeSnap. - systemAnchor: new convertToSystem(WGS84) in the anchor's own UTM zone; the existing convertToSystem(SP, WGS84) subtracted the anchor's X from Y (no caller used it). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16 --- lib/App/common/dataBinder_structures.h | 1 + lib/App/common/deviceNodePTZCamControl.cpp | 3 +- lib/App/common/deviceNodePresetCamControl.cpp | 10 ++ lib/App/common/deviceNodeStaticCamControl.cpp | 10 ++ lib/App/mojo/mojoKernel.cpp | 99 +++++++++++++++++++ lib/App/mojo/mojoKernel.h | 2 + lib/components/object/objectSystemAnchor.cpp | 17 +++- lib/components/object/objectSystemAnchor.h | 1 + 8 files changed, 141 insertions(+), 2 deletions(-) diff --git a/lib/App/common/dataBinder_structures.h b/lib/App/common/dataBinder_structures.h index f3719552..31a63f4b 100644 --- a/lib/App/common/dataBinder_structures.h +++ b/lib/App/common/dataBinder_structures.h @@ -405,6 +405,7 @@ typedef struct S_DBC_RESOURCE_DATA #define CMD_KRN_COMPOSE_SESSION_VIDEOS 239 #define CMD_KRNL_DELNODE 240 #define CMD_KRNL_RELOAD_MEDIAMTX_SERVICE 241 +#define CMD_KRNL_MAP_ROI 242 // monitoring map click: ";;" (0 WGS84, 1 local) #define CMD_KRNL_RESET_SITE 245 #define CMD_KRNL_PURGE_SESSION 246 #define CMD_KRNL_SET_SESSION_HZL 247 diff --git a/lib/App/common/deviceNodePTZCamControl.cpp b/lib/App/common/deviceNodePTZCamControl.cpp index 0657a411..7ba23747 100644 --- a/lib/App/common/deviceNodePTZCamControl.cpp +++ b/lib/App/common/deviceNodePTZCamControl.cpp @@ -59,7 +59,8 @@ bool deviceNodePTZCamControl::dispatchEvent(EVENT_CONTAINER * E) case EVT_ROI_ACTIVE:{ if ( !m_bCameraAIControled ) { TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData; - if( tDATA ) lookAt(E->m_db_id, tDATA->system_target); + // a map ROI (kernel, EVT_CLASS_SYSTEM) has no preferred camera: only the cameras that can see it + if( tDATA && ( E->m_eClass != EVT_CLASS_SYSTEM || testFOV( tDATA->system_target ) ) ) lookAt(E->m_db_id, tDATA->system_target); } break; }; diff --git a/lib/App/common/deviceNodePresetCamControl.cpp b/lib/App/common/deviceNodePresetCamControl.cpp index 9543dec6..a12f35dc 100644 --- a/lib/App/common/deviceNodePresetCamControl.cpp +++ b/lib/App/common/deviceNodePresetCamControl.cpp @@ -58,6 +58,16 @@ bool deviceNodePresetCamControl::dispatchEvent(EVENT_CONTAINER * E) }; switch (E->m_eClass) { + case EVT_CLASS_SYSTEM: + { + // Map ROI (kernel): the cameras that can see the point + TARGET_DATA * tDATA = (TARGET_DATA *) E->m_pEvtData; + if (E->m_eType == EVT_ROI_ACTIVE && tDATA != NULL && testFOV(tDATA->system_target)) + { + lookAt(E->m_db_id, tDATA->system_target); + }; + break; + }; case EVT_CLASS_SENSOR_CLD: case EVT_CLASS_SENSOR_LGS: case EVT_CLASS_SENSOR_LFS: diff --git a/lib/App/common/deviceNodeStaticCamControl.cpp b/lib/App/common/deviceNodeStaticCamControl.cpp index 46cbe480..690e2912 100644 --- a/lib/App/common/deviceNodeStaticCamControl.cpp +++ b/lib/App/common/deviceNodeStaticCamControl.cpp @@ -90,6 +90,16 @@ bool deviceNodeStaticCamControl::dispatchEvent(EVENT_CONTAINER * E) }; switch (E->m_eClass) { + case EVT_CLASS_SYSTEM: + { + // Map ROI (kernel): the cameras that can see the point + TARGET_DATA * tDATA = (TARGET_DATA *) E->m_pEvtData; + if (E->m_eType == EVT_ROI_ACTIVE && tDATA != NULL && testFOV(tDATA->system_target)) + { + makeSnap(E->m_db_id); + }; + break; + }; case EVT_CLASS_SENSOR_CLD: case EVT_CLASS_SENSOR_LGS: case EVT_CLASS_SENSOR_LFS: diff --git a/lib/App/mojo/mojoKernel.cpp b/lib/App/mojo/mojoKernel.cpp index 2f022a34..1f038722 100644 --- a/lib/App/mojo/mojoKernel.cpp +++ b/lib/App/mojo/mojoKernel.cpp @@ -13,6 +13,7 @@ //---------------------------------------------------------------------------- // +#include #include "mojoKernel.h" static int getLocalReportPeriod(void); @@ -972,6 +973,10 @@ void mojoKernel::m_fThreadProc(void){ case CMD_KRNL_SYSTEM_TASK:{ break; }; + case CMD_KRNL_MAP_ROI:{ + mapROI(tCMD->PARAM); + break; + }; case NODE_FORCE_FINISH_ALARM:{ stopSession(); break; @@ -1267,6 +1272,79 @@ void mojoKernel::validateFilters() }; } +/* + CMD_KRNL_MAP_ROI: a click on the monitoring map (Mojo_Web doApplicationOperation 15). + PARAM ";;": + - format 0: WGS84, a = lat, b = lon (degrees) -> system coordinates through the site anchor (UTM, meters); + - format 1: local binding (bitmap map), a = y, b = x in map units: the map shows a node at + anchor + its local coordinates, so system = map - anchor. + The point is sent as EVT_ROI_ACTIVE (EVT_CLASS_SYSTEM) like a sensor's ROI: it is an event of the + report (dispatchEvent) and every camera that can see it (testFOV) looks at it. +*/ +bool mojoKernel::mapROI(const char * param) +{ + char tB[256]; + int tFormat = -1; + double tA = 0, tC = 0; + if (param == NULL || sscanf(param, "%d;%lf;%lf", &tFormat, &tA, &tC) != 3 || (tFormat != 0 && tFormat != 1) || ! std::isfinite(tA) || ! std::isfinite(tC)) + { + snprintf(tB, sizeof(tB), "Map ROI: wrong parameter [%.64s]", param ? param : ""); + LOG_ERROR(tB); + return false; + }; + if (m_pSystemAnchor == NULL) + { + LOG_ERROR("Map ROI: no system anchor!"); + return false; + }; + bool tLocal = (tFormat == 1); + if (tLocal != m_pSystemAnchor->beLocal()) + { + // the map type was changed after the start: the anchor still uses the other system + snprintf(tB, sizeof(tB), "Map ROI: the map is %s, the site anchor is %s - ignored (restart needed)", tLocal ? "local" : "WGS84", m_pSystemAnchor->beLocal() ? "local" : "WGS84"); + LOG_ERROR(tB); + return false; + }; + TARGET_DATA * tData = (TARGET_DATA *) malloc(sizeof(TARGET_DATA)); // freed with the event + if (tData == NULL) + { + return false; + }; + memset(tData, 0, sizeof(TARGET_DATA)); + tData->source_position.lat = m_pSystemAnchor->getLat(); + tData->source_position.lon = m_pSystemAnchor->getLon(); + tData->source_position.alt = m_pSystemAnchor->getAlt(); + if (tLocal) + { + tData->system_target.x = (C3D_FLOAT) (tC - m_pSystemAnchor->getX()); + tData->system_target.y = (C3D_FLOAT) (tA - m_pSystemAnchor->getY()); + tData->system_target.z = 0; + // as the sensors do in a local system + tData->global_target.lat = tData->system_target.y; + tData->global_target.lon = tData->system_target.x; + tData->global_target.alt = tData->system_target.z; + } + else + { + tData->global_target.lat = (C3D_FLOAT) tA; + tData->global_target.lon = (C3D_FLOAT) tC; + tData->global_target.alt = m_pSystemAnchor->getZ(); // no height on the map: the site's ground level + m_pSystemAnchor->convertToSystem(tData->global_target, tData->system_target); + }; + snprintf(tB, sizeof(tB), "Map ROI: %s %.7f %.7f -> system x:%.2f y:%.2f z:%.2f", tLocal ? "local" : "WGS84", tA, tC, tData->system_target.x, tData->system_target.y, tData->system_target.z); + LOG(tB); + startSession(); + EVENT_CONTAINER * bEVT = createBasicEvent(m_nServerNodeID, EVT_CLASS_SYSTEM, EVT_ROI_ACTIVE, NULL, NULL, tData); + if (bEVT == NULL) + { + LOG_ERROR("Map ROI: event creation failure!"); + free(tData); + return false; + }; + m_pEventHeap->broadcast(bEVT); + return true; +} + bool mojoKernel::dispatchEvent(EVENT_CONTAINER * Evt) { if (Evt == NULL) @@ -1308,6 +1386,27 @@ bool mojoKernel::dispatchEvent(EVENT_CONTAINER * Evt) case EVT_CLASS_SYSTEM: switch (Evt->m_eType) { + case EVT_ROI_ACTIVE: + { + // Map ROI (mapROI): an event of the report like a sensor's ROI, the cameras look at the point + preserveSession(); + TARGET_DATA * tDATA = (TARGET_DATA *) Evt->m_pEvtData; + if (tDATA != NULL) + { + DBC_EVT_RECORD tRecord; + memset(&tRecord, 0, sizeof(DBC_EVT_RECORD)); + tRecord.node_id = Evt->m_nSourceNodeID; + tRecord.type = Evt->m_eType; + strncpy(tRecord.uuid, Evt->m_UUID, 64); + tRecord.ts_s = Evt->m_UMSTS / 1000; + tRecord.ts_ms = Evt->m_UMSTS % 1000; + tRecord.lat = tDATA->global_target.lat; + tRecord.lon = tDATA->global_target.lon; + tRecord.alt = tDATA->global_target.alt; + Evt->m_db_id = m_pDBC->addEvent(&tRecord); + }; + break; + }; case EVT_LRF_START_SESSION: case EVT_LRF_END_SESSION_TO: case EVT_LRF_END_SESSION_MA: diff --git a/lib/App/mojo/mojoKernel.h b/lib/App/mojo/mojoKernel.h index 222c94cc..a4cbc5f3 100644 --- a/lib/App/mojo/mojoKernel.h +++ b/lib/App/mojo/mojoKernel.h @@ -119,6 +119,8 @@ class mojoKernel : public kernelPrototype void stopSession(bool forced = true); + bool mapROI(const char * param); // CMD_KRNL_MAP_ROI + void preserveSession() { m_bSessionMustPreserve = true; diff --git a/lib/components/object/objectSystemAnchor.cpp b/lib/components/object/objectSystemAnchor.cpp index ceb7cc79..ddd9a8cc 100644 --- a/lib/components/object/objectSystemAnchor.cpp +++ b/lib/components/object/objectSystemAnchor.cpp @@ -350,7 +350,22 @@ bool systemAnchor::convertToSystem(basicPosition * SP, C3D_WGS84_LOC POS, C3D_DE tDec.z = POS.alt; m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y); LOC.x = tDec.x - getX(); - LOC.y = tDec.y - getX(); + LOC.y = tDec.y - getY(); + LOC.z = tDec.z - getZ(); + return true; +} + +bool systemAnchor::convertToSystem(C3D_WGS84_LOC POS, C3D_DECART & LOC) +{ + if (m_bUseJustLocalDiffCoords) + { + return false; // no geographic position in a local system + } + C3D_DECART tDec; + tDec.z = POS.alt; + m_SCC.LatLonToUTMXY(POS.lat, POS.lon, utmZone, tDec.x, tDec.y); + LOC.x = tDec.x - getX(); + LOC.y = tDec.y - getY(); LOC.z = tDec.z - getZ(); return true; } diff --git a/lib/components/object/objectSystemAnchor.h b/lib/components/object/objectSystemAnchor.h index eec395a5..64ba1a50 100644 --- a/lib/components/object/objectSystemAnchor.h +++ b/lib/components/object/objectSystemAnchor.h @@ -39,6 +39,7 @@ class systemAnchor : public position3D bool convertToSystem(basicPosition * SP, C3D_WGS84_LOC POS, C3D_DECART & LOC); bool convertToSystem(basicPosition * SP, C3D_SPH_DEGREES POS, C3D_DECART & LOC); bool convertToSystem(basicPosition * SP, C3D_SPH_RADIANS POS, C3D_DECART & LOC); + bool convertToSystem(C3D_WGS84_LOC POS, C3D_DECART & LOC); // in the anchor's own UTM zone (no source node) bool convertToGlobal(basicPosition * SP, C3D_SPH_DEGREES POS, C3D_WGS84_LOC & LOC); bool convertToGlobal(basicPosition * SP, C3D_SPH_RADIANS POS, C3D_WGS84_LOC & LOC); -- 2.39.5 From d7911074a3bbf11687ec99a7e25e2570f9a2d102 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 15:36:46 +0000 Subject: [PATCH 2/2] Map ROI: placeholder for a camera setting - test the point or always look at it PTZ, preset and static camera controls: a map ROI goes through if (1) { testFOV then act } else { act }; the condition becomes a camera setting later (lookAt alone clamps pan/tilt/zoom to the camera's limits, so every camera would turn to every click). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16 --- lib/App/common/deviceNodePTZCamControl.cpp | 14 ++++++++++++-- lib/App/common/deviceNodePresetCamControl.cpp | 16 +++++++++++++--- lib/App/common/deviceNodeStaticCamControl.cpp | 16 +++++++++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/App/common/deviceNodePTZCamControl.cpp b/lib/App/common/deviceNodePTZCamControl.cpp index 7ba23747..791eefe4 100644 --- a/lib/App/common/deviceNodePTZCamControl.cpp +++ b/lib/App/common/deviceNodePTZCamControl.cpp @@ -59,8 +59,18 @@ bool deviceNodePTZCamControl::dispatchEvent(EVENT_CONTAINER * E) case EVT_ROI_ACTIVE:{ if ( !m_bCameraAIControled ) { TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData; - // a map ROI (kernel, EVT_CLASS_SYSTEM) has no preferred camera: only the cameras that can see it - if( tDATA && ( E->m_eClass != EVT_CLASS_SYSTEM || testFOV( tDATA->system_target ) ) ) lookAt(E->m_db_id, tDATA->system_target); + if( tDATA ){ + if( E->m_eClass == EVT_CLASS_SYSTEM ){ + // Map ROI (kernel): no preferred camera + if( 1 ){ // ToDo: camera setting - only when the point passes the camera's test (range, pan limits, FOV) + if( testFOV( tDATA->system_target ) ) lookAt(E->m_db_id, tDATA->system_target); + } else { // every camera turns to it (lookAt clamps pan/tilt/zoom to the camera's limits) + lookAt(E->m_db_id, tDATA->system_target); + }; + } else { + lookAt(E->m_db_id, tDATA->system_target); + }; + }; } break; }; diff --git a/lib/App/common/deviceNodePresetCamControl.cpp b/lib/App/common/deviceNodePresetCamControl.cpp index a12f35dc..faf213c2 100644 --- a/lib/App/common/deviceNodePresetCamControl.cpp +++ b/lib/App/common/deviceNodePresetCamControl.cpp @@ -60,11 +60,21 @@ bool deviceNodePresetCamControl::dispatchEvent(EVENT_CONTAINER * E) { case EVT_CLASS_SYSTEM: { - // Map ROI (kernel): the cameras that can see the point + // Map ROI (kernel): no preferred camera TARGET_DATA * tDATA = (TARGET_DATA *) E->m_pEvtData; - if (E->m_eType == EVT_ROI_ACTIVE && tDATA != NULL && testFOV(tDATA->system_target)) + if (E->m_eType == EVT_ROI_ACTIVE && tDATA != NULL) { - lookAt(E->m_db_id, tDATA->system_target); + if (1) // ToDo: camera setting - only when the point passes the camera's test (range, pan limits, FOV) + { + if (testFOV(tDATA->system_target)) + { + lookAt(E->m_db_id, tDATA->system_target); + }; + } + else // every camera acts on it + { + lookAt(E->m_db_id, tDATA->system_target); + }; }; break; }; diff --git a/lib/App/common/deviceNodeStaticCamControl.cpp b/lib/App/common/deviceNodeStaticCamControl.cpp index 690e2912..7b880986 100644 --- a/lib/App/common/deviceNodeStaticCamControl.cpp +++ b/lib/App/common/deviceNodeStaticCamControl.cpp @@ -92,11 +92,21 @@ bool deviceNodeStaticCamControl::dispatchEvent(EVENT_CONTAINER * E) { case EVT_CLASS_SYSTEM: { - // Map ROI (kernel): the cameras that can see the point + // Map ROI (kernel): no preferred camera TARGET_DATA * tDATA = (TARGET_DATA *) E->m_pEvtData; - if (E->m_eType == EVT_ROI_ACTIVE && tDATA != NULL && testFOV(tDATA->system_target)) + if (E->m_eType == EVT_ROI_ACTIVE && tDATA != NULL) { - makeSnap(E->m_db_id); + if (1) // ToDo: camera setting - only when the point passes the camera's test (range, pan limits, FOV) + { + if (testFOV(tDATA->system_target)) + { + makeSnap(E->m_db_id); + }; + } + else // every camera acts on it + { + makeSnap(E->m_db_id); + }; }; break; }; -- 2.39.5