From dcc6aa51fa3053ee730bd2c01e679e90a6e23d42 Mon Sep 17 00:00:00 2001 From: mmeijerdfki Date: Wed, 25 Sep 2024 11:00:32 +0200 Subject: [PATCH] move and modify inMapFrame property into crsString --- .../python/gRPC/images/gRPC_fb_queryImages.py | 1 - .../python/gRPC/images/gRPC_pb_queryImage.py | 4 +--- .../gRPC/images/gRPC_pb_queryImageGrid.py | 3 ++- .../python/gRPC/point/gRPC_fb_queryPoints.py | 1 - .../pointcloud/gRPC_fb_queryPointCloud.py | 2 +- .../gRPC_fb_queryPointCloudAndVisualize.py | 2 +- examples/python/gRPC/util/fb_helper.py | 11 ++++++---- seerep_msgs/fbs/query.fbs | 1 - seerep_msgs/protos/query.proto | 3 +-- seerep_srv/seerep_core/src/core_project.cpp | 21 +++++++------------ .../seerep_core_fb/core_fb_conversion.h | 9 -------- .../seerep_core_fb/src/core_fb_conversion.cpp | 11 ---------- .../seerep_core_pb/core_pb_conversion.h | 8 ------- .../seerep_core_pb/src/core_pb_conversion.cpp | 7 ------- .../gRPC/images/test_gRPC_fb_queryImage.py | 2 +- .../instances/test_gRPC_fb_getInstances.py | 2 -- ...test_gRPC_fb_createGeodeticCoordProject.py | 5 +---- tests/python/gRPC/util/msg_abs/msgs.py | 14 +++++-------- 18 files changed, 27 insertions(+), 80 deletions(-) diff --git a/examples/python/gRPC/images/gRPC_fb_queryImages.py b/examples/python/gRPC/images/gRPC_fb_queryImages.py index 79f0aab4f..e5fa41136 100755 --- a/examples/python/gRPC/images/gRPC_fb_queryImages.py +++ b/examples/python/gRPC/images/gRPC_fb_queryImages.py @@ -121,7 +121,6 @@ def query_images( labels=labelsCategory, withoutData=True, fullyEncapsulated=False, - inMapFrame=True, ) if matching_images is None or len(matching_images) == 0: diff --git a/examples/python/gRPC/images/gRPC_pb_queryImage.py b/examples/python/gRPC/images/gRPC_pb_queryImage.py index 68a4c7355..fe334690b 100755 --- a/examples/python/gRPC/images/gRPC_pb_queryImage.py +++ b/examples/python/gRPC/images/gRPC_pb_queryImage.py @@ -47,8 +47,7 @@ def query_images( theQuery.polygon.z = -200 theQuery.polygon.height = 800 - theQuery.inMapFrame = True - theQuery.crsString = "EPSG:4326" + theQuery.crsString = "map" scale = 150 vertices = [ @@ -76,7 +75,6 @@ def query_images( labelsCategory.labels.append(label) theQuery.labelCategory.append(labelsCategory) - # theQuery.inMapFrame = True theQuery.fullyEncapsulated = False # 5. Query the server for images matching the query and return them diff --git a/examples/python/gRPC/images/gRPC_pb_queryImageGrid.py b/examples/python/gRPC/images/gRPC_pb_queryImageGrid.py index d2f2b5ea6..e1940c7e7 100755 --- a/examples/python/gRPC/images/gRPC_pb_queryImageGrid.py +++ b/examples/python/gRPC/images/gRPC_pb_queryImageGrid.py @@ -50,7 +50,8 @@ def query_image_grid( theQuery.polygon.z = -1 theQuery.polygon.height = 7 - theQuery.inMapFrame = True + # also means the query is done in the map + theQuery.crsString = "map" theQuery.fullyEncapsulated = False # labels diff --git a/examples/python/gRPC/point/gRPC_fb_queryPoints.py b/examples/python/gRPC/point/gRPC_fb_queryPoints.py index d30c42120..c35285d97 100755 --- a/examples/python/gRPC/point/gRPC_fb_queryPoints.py +++ b/examples/python/gRPC/point/gRPC_fb_queryPoints.py @@ -79,7 +79,6 @@ def get_points_raw( polygon2d=polygon2d, # withoutData=True, fullyEncapsulated=False, - inMapFrame=True, ) builder.Finish(query) diff --git a/examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloud.py b/examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloud.py index b2fcc637e..07109c556 100644 --- a/examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloud.py +++ b/examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloud.py @@ -118,7 +118,7 @@ def query_pcs_raw( # withoutData=True, # polygon2d=query_polygon, # fullyEncapsulated=True - inMapFrame=False, + # crsString="project", ) fb_builder.Finish(query) diff --git a/examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloudAndVisualize.py b/examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloudAndVisualize.py index c016f0f92..6eddb6944 100644 --- a/examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloudAndVisualize.py +++ b/examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloudAndVisualize.py @@ -156,7 +156,7 @@ def query_pcs( # withoutData=True, # polygon2d=query_polygon, # fullyEncapsulated=True - inMapFrame=False, + # crsString="project", ) fb_builder.Finish(query) diff --git a/examples/python/gRPC/util/fb_helper.py b/examples/python/gRPC/util/fb_helper.py index c8a1233a3..ce38347ae 100644 --- a/examples/python/gRPC/util/fb_helper.py +++ b/examples/python/gRPC/util/fb_helper.py @@ -626,6 +626,7 @@ def addToPointFieldVector(builder: Builder, pointFieldList: List[int]) -> int: return builder.EndVector() +# TODO docs for crsString def createQuery( builder: Builder, timeInterval: Union[int, None] = None, @@ -637,7 +638,7 @@ def createQuery( withoutData: bool = False, polygon2d: Union[int, None] = None, fullyEncapsulated: bool = False, - inMapFrame: bool = True, + crsString: str = "map", sortByTime: bool = False, ) -> int: """ @@ -660,8 +661,8 @@ def createQuery( within the polygon fullyEncapsulated: A boolean indicating if the returned instances should be fully encapsulated by the polygon - inMapFrame: A boolean indicating if the polygon coordinates are in the - map frame or in EPSG world coordinates + crsString: A string containing either a proj transformable code (EPSG, ) + 'map' or a empty string are valid values as well. sortByTime: A boolean indicating if the returned instances should be sorted by time @@ -669,6 +670,8 @@ def createQuery( A pointer to the constructed query object """ + crsString = builder.CreateString(crsString) + if projectUuids: # serialize strings projectUuidsSerialized = [ @@ -723,7 +726,7 @@ def createQuery( # no if; has default value Query.AddWithoutdata(builder, withoutData) Query.AddFullyEncapsulated(builder, fullyEncapsulated) - Query.AddInMapFrame(builder, inMapFrame) + Query.AddCrsString(builder, crsString) Query.AddSortByTime(builder, sortByTime) return Query.End(builder) diff --git a/seerep_msgs/fbs/query.fbs b/seerep_msgs/fbs/query.fbs index c9a112890..8c575c9f0 100644 --- a/seerep_msgs/fbs/query.fbs +++ b/seerep_msgs/fbs/query.fbs @@ -10,7 +10,6 @@ table Query { polygonSensorPosition:Polygon2D; fullyEncapsulated:bool; crsString:string; - inMapFrame:bool; timeinterval:TimeInterval; label:[LabelCategory]; sparqlQuery:SparqlQuery; diff --git a/seerep_msgs/protos/query.proto b/seerep_msgs/protos/query.proto index 91ff2f941..adb007c55 100644 --- a/seerep_msgs/protos/query.proto +++ b/seerep_msgs/protos/query.proto @@ -10,7 +10,7 @@ message Query { Polygon2D polygon = 1; bool fullyEncapsulated = 2; - bool inMapFrame = 3; + string crsString = 3; TimeInterval timeinterval = 4; repeated LabelCategory labelCategory = 5; bool mustHaveAllLabels = 6; @@ -20,5 +20,4 @@ message Query bool withoutdata = 10; uint32 maxNumData = 11; bool sortByTime = 12; - string crsString = 13; } diff --git a/seerep_srv/seerep_core/src/core_project.cpp b/seerep_srv/seerep_core/src/core_project.cpp index a4956418c..870e8f3dd 100644 --- a/seerep_srv/seerep_core/src/core_project.cpp +++ b/seerep_srv/seerep_core/src/core_project.cpp @@ -101,7 +101,7 @@ CoreProject::transformToMapFrame(const seerep_core_msgs::Polygon2D& polygon, transformed_polygon.height = polygon.height; // when the query was made in a seperate coordinate reference system - if (query_crs != "") + if (query_crs != "project") { PJ* to_project_crs_rawptr = proj_create_crs_to_crs( ctx, query_crs.c_str(), g.crsString.c_str(), nullptr); @@ -200,18 +200,8 @@ CoreProject::transformToMapFrame(const seerep_core_msgs::Polygon2D& polygon, std::string ellps = ellps_string.substr(ellps_idx); // https://proj.org/en/6.3/operations/conversions/topocentric.html - // the proj pipeline has two steps, convert geodesic to cartesian + // the proj pipeline has two steps, convert geographic to cartesian // coordinates then project to topocentric coordinates - // TODO: get ellps from proj using - BOOST_LOG_SEV(m_logger, boost::log::trivial::severity_level::info) - << "crs string: " << g.crsString; - - BOOST_LOG_SEV(m_logger, boost::log::trivial::severity_level::info) - << "ellps: " << ellps; - - // perform an affine transform to transpose the query polygon to map frame - // the first argument is the thread context, the second is the pipeline - // string created above std::string to_topographic_projstr = "+proj=pipeline +step +proj=cart +ellps=" + ellps + " +step +proj=topocentric" + " +ellps=" + ellps + @@ -275,8 +265,11 @@ CoreProject::getDataset(seerep_core_msgs::Query& query) seerep_core_msgs::QueryResultProject result; result.projectUuid = m_uuid; - // is the query not in map frame? - if (query.polygon && !query.inMapFrame) + // is the query not in map frame? Then transform the polygon into it + // query.crsString == "project" means the polygon is in the project frame + // if query.crsString == "map" that means the query is done in the map + // frame + if (query.polygon && query.crsString != "map") { query.polygon.value() = transformToMapFrame(query.polygon.value(), query.crsString); diff --git a/seerep_srv/seerep_core_fb/include/seerep_core_fb/core_fb_conversion.h b/seerep_srv/seerep_core_fb/include/seerep_core_fb/core_fb_conversion.h index c16ccea29..309ad972f 100644 --- a/seerep_srv/seerep_core_fb/include/seerep_core_fb/core_fb_conversion.h +++ b/seerep_srv/seerep_core_fb/include/seerep_core_fb/core_fb_conversion.h @@ -295,15 +295,6 @@ class CoreFbConversion */ static bool fromFbQueryMustHaveAllLabels(const seerep::fb::Query* query); - /** - * @brief - * - * @param query extracts the inMapFrame flag of the flatbuffer query message - * @return true the polygon in the query is in map frame - * @return false the polygon in the query is in geodetic coordinates - */ - static bool fromFbQueryInMapFrame(const seerep::fb::Query* query); - /** * @brief get the coordinate reference system string from the flatbuffers * query object diff --git a/seerep_srv/seerep_core_fb/src/core_fb_conversion.cpp b/seerep_srv/seerep_core_fb/src/core_fb_conversion.cpp index 209f076f5..393123ddf 100644 --- a/seerep_srv/seerep_core_fb/src/core_fb_conversion.cpp +++ b/seerep_srv/seerep_core_fb/src/core_fb_conversion.cpp @@ -51,7 +51,6 @@ CoreFbConversion::fromFb(const seerep::fb::Query* query, queryCore.polygonSensorPos = fromFbQueryPolygonSensorPosition(query); queryCore.fullyEncapsulated = fromFbQueryFullyEncapsulated(query); queryCore.crsString = fromFbQueryCrsString(query); - queryCore.inMapFrame = fromFbQueryInMapFrame(query); queryCore.sortByTime = query->sortByTime(); return queryCore; @@ -597,16 +596,6 @@ bool CoreFbConversion::fromFbQueryMustHaveAllLabels( return false; } -bool CoreFbConversion::fromFbQueryInMapFrame(const seerep::fb::Query* query) -{ - if (flatbuffers::IsFieldPresent(query, seerep::fb::Query::VT_INMAPFRAME)) - { - return query->inMapFrame(); - } - - return false; -} - bool CoreFbConversion::fromFbQueryFullyEncapsulated( const seerep::fb::Query* query) { diff --git a/seerep_srv/seerep_core_pb/include/seerep_core_pb/core_pb_conversion.h b/seerep_srv/seerep_core_pb/include/seerep_core_pb/core_pb_conversion.h index 32cecb182..7f4ecda0f 100644 --- a/seerep_srv/seerep_core_pb/include/seerep_core_pb/core_pb_conversion.h +++ b/seerep_srv/seerep_core_pb/include/seerep_core_pb/core_pb_conversion.h @@ -167,14 +167,6 @@ class CorePbConversion */ static void fromPbMustHaveAllLabels(const seerep::pb::Query& query, seerep_core_msgs::Query& queryCore); - /** - * @brief converts the inMapFrame flag of the protobuf query message to seerep - * core specific message - * @param query the protobuf query message - * @param queryCore query message in seerep core format - */ - static void fromPbInMapFrame(const seerep::pb::Query& query, - seerep_core_msgs::Query& queryCore); /** * @brief converts the coordinate reference systen string of the protobuf * query message to seerep core specific message diff --git a/seerep_srv/seerep_core_pb/src/core_pb_conversion.cpp b/seerep_srv/seerep_core_pb/src/core_pb_conversion.cpp index 137a24a30..91b63bd6a 100644 --- a/seerep_srv/seerep_core_pb/src/core_pb_conversion.cpp +++ b/seerep_srv/seerep_core_pb/src/core_pb_conversion.cpp @@ -21,7 +21,6 @@ CorePbConversion::fromPb(const seerep::pb::Query& query, fromFbQueryMaxNumData(query, queryCore); fromPbFullyEncapsulated(query, queryCore); fromPbCrsString(query, queryCore); - fromPbInMapFrame(query, queryCore); queryCore.sortByTime = query.sortbytime(); return queryCore; @@ -373,12 +372,6 @@ void CorePbConversion::fromPbMustHaveAllLabels( queryCore.mustHaveAllLabels = query.musthavealllabels(); } -void CorePbConversion::fromPbInMapFrame(const seerep::pb::Query& query, - seerep_core_msgs::Query& queryCore) -{ - queryCore.inMapFrame = query.inmapframe(); -} - void CorePbConversion::fromPbCrsString(const seerep::pb::Query& query, seerep_core_msgs::Query& queryCore) { diff --git a/tests/python/gRPC/images/test_gRPC_fb_queryImage.py b/tests/python/gRPC/images/test_gRPC_fb_queryImage.py index e962c670a..5e6dce1dc 100644 --- a/tests/python/gRPC/images/test_gRPC_fb_queryImage.py +++ b/tests/python/gRPC/images/test_gRPC_fb_queryImage.py @@ -77,7 +77,7 @@ def test_gRPC_fb_queryImages(grpc_channel, project_setup): labels=labelsCategory, withoutData=True, fullyEncapsulated=False, - inMapFrame=True, + crsString="map", ) queried_image_dicts = [ diff --git a/tests/python/gRPC/instances/test_gRPC_fb_getInstances.py b/tests/python/gRPC/instances/test_gRPC_fb_getInstances.py index de178b4c3..77c51dd25 100644 --- a/tests/python/gRPC/instances/test_gRPC_fb_getInstances.py +++ b/tests/python/gRPC/instances/test_gRPC_fb_getInstances.py @@ -649,7 +649,6 @@ def _test_gRPC_getInstanceQuerySortByTime(grpc_channel, project_setup): assert uuids_by_time == label_instances -# this does not work currently def _test_gRPC_getInstanceQueryInMapFrame(grpc_channel, project_setup): _, proj_uuid = project_setup @@ -673,7 +672,6 @@ def _test_gRPC_getInstanceQueryInMapFrame(grpc_channel, project_setup): grpc_channel, enum_types=set( EnumFbQuery.POLYGON, - EnumFbQuery.IN_MAP_FRAME, EnumFbQuery.FULLY_ENCAPSULATED, ), ) diff --git a/tests/python/gRPC/meta/test_gRPC_fb_createGeodeticCoordProject.py b/tests/python/gRPC/meta/test_gRPC_fb_createGeodeticCoordProject.py index 94cbd2ae1..81f9f78b5 100644 --- a/tests/python/gRPC/meta/test_gRPC_fb_createGeodeticCoordProject.py +++ b/tests/python/gRPC/meta/test_gRPC_fb_createGeodeticCoordProject.py @@ -47,10 +47,7 @@ def test_gRPC_fb_createGeoProjectAndGetProjects(grpc_channel): assert created_project["uuid"] != "" assert created_project["frameid"] == "2" - assert ( - created_project["geodetic_position"]["coordinate_system"] - == "EPSG::4326" - ) + assert created_project["geodetic_position"]["crs_string"] == "EPSG::4326" assert created_project["geodetic_position"]["altitude"] == 4.0 assert created_project["geodetic_position"]["latitude"] == 6.0 assert created_project["geodetic_position"]["longitude"] == 7.0 diff --git a/tests/python/gRPC/util/msg_abs/msgs.py b/tests/python/gRPC/util/msg_abs/msgs.py index 88d93892e..1ced0ab97 100644 --- a/tests/python/gRPC/util/msg_abs/msgs.py +++ b/tests/python/gRPC/util/msg_abs/msgs.py @@ -27,7 +27,7 @@ class EnumFbQuery(FrozenEnum): POLYGON = auto() # def: None FULLY_ENCAPSULATED = auto() # def: False - IN_MAP_FRAME = auto() # def: True + CRS_STRING = auto() # def: True TIMEINTERVAL = auto() # def: None LABEL = auto() # def: None SPARQL_QUERY = auto() # def: None @@ -55,8 +55,8 @@ def _set_enum_func_mapping(self) -> Dict[EnumFbQuery, MsgsFunctions]: EnumFbQuery.FULLY_ENCAPSULATED: MsgsFunctions( lambda: False, lambda: True ), - EnumFbQuery.IN_MAP_FRAME: MsgsFunctions( - lambda: True, lambda: False + EnumFbQuery.CRS_STRING: MsgsFunctions( + lambda: "map", lambda: "project" ), EnumFbQuery.TIMEINTERVAL: MsgsFunctions( lambda: None, lambda: Dtypes.Fb.time_interval(self.builder) @@ -110,7 +110,7 @@ def datauuid(self) -> List[int]: def _assemble_datatype_instance(self): polygon = self.get_component(EnumFbQuery.POLYGON) fully_encapsulated = self.get_component(EnumFbQuery.FULLY_ENCAPSULATED) - in_map_frame = self.get_component(EnumFbQuery.IN_MAP_FRAME) + in_map_frame = self.get_component(EnumFbQuery.CRS_STRING) timeinterval = self.get_component(EnumFbQuery.TIMEINTERVAL) label = self.get_component(EnumFbQuery.LABEL) must_have_all_labels = self.get_component( @@ -152,11 +152,7 @@ def _set_enum_func_mapping(self) -> Dict[FrozenEnum, MsgsFunctions]: } def query(self): - features = { - EnumFbQuery.WITHOUTDATA, - EnumFbQuery.IN_MAP_FRAME, - EnumFbQuery.PROJECTUUID, - } + features = {EnumFbQuery.WITHOUTDATA, EnumFbQuery.PROJECTUUID} return FbQuery(self.channel, self.builder, features).datatype_instance def _assemble_datatype_instance(self):