Skip to content

Commit

Permalink
move and modify inMapFrame property into crsString
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeijerdfki committed Sep 25, 2024
1 parent fbe32ac commit dcc6aa5
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 80 deletions.
1 change: 0 additions & 1 deletion examples/python/gRPC/images/gRPC_fb_queryImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions examples/python/gRPC/images/gRPC_pb_queryImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion examples/python/gRPC/images/gRPC_pb_queryImageGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion examples/python/gRPC/point/gRPC_fb_queryPoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def get_points_raw(
polygon2d=polygon2d,
# withoutData=True,
fullyEncapsulated=False,
inMapFrame=True,
)

builder.Finish(query)
Expand Down
2 changes: 1 addition & 1 deletion examples/python/gRPC/pointcloud/gRPC_fb_queryPointCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def query_pcs_raw(
# withoutData=True,
# polygon2d=query_polygon,
# fullyEncapsulated=True
inMapFrame=False,
# crsString="project",
)

fb_builder.Finish(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def query_pcs(
# withoutData=True,
# polygon2d=query_polygon,
# fullyEncapsulated=True
inMapFrame=False,
# crsString="project",
)

fb_builder.Finish(query)
Expand Down
11 changes: 7 additions & 4 deletions examples/python/gRPC/util/fb_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
"""
Expand All @@ -660,15 +661,17 @@ 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
Returns:
A pointer to the constructed query object
"""

crsString = builder.CreateString(crsString)

if projectUuids:
# serialize strings
projectUuidsSerialized = [
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion seerep_msgs/fbs/query.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ table Query {
polygonSensorPosition:Polygon2D;
fullyEncapsulated:bool;
crsString:string;
inMapFrame:bool;
timeinterval:TimeInterval;
label:[LabelCategory];
sparqlQuery:SparqlQuery;
Expand Down
3 changes: 1 addition & 2 deletions seerep_msgs/protos/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,5 +20,4 @@ message Query
bool withoutdata = 10;
uint32 maxNumData = 11;
bool sortByTime = 12;
string crsString = 13;
}
21 changes: 7 additions & 14 deletions seerep_srv/seerep_core/src/core_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 +
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions seerep_srv/seerep_core_fb/src/core_fb_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions seerep_srv/seerep_core_pb/src/core_pb_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/python/gRPC/images/test_gRPC_fb_queryImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 0 additions & 2 deletions tests/python/gRPC/instances/test_gRPC_fb_getInstances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions tests/python/gRPC/util/msg_abs/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit dcc6aa5

Please sign in to comment.