Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions opengeodeweb_back_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,124 @@
"additionalProperties": false
}
},
"model_physical_properties": {
"$id": "opengeodeweb_back/model_physical_properties",
"route": "/model_physical_properties",
"methods": [
"POST"
],
"type": "object",
"properties": {
"id": {
"title": "DataId",
"type": "string",
"minLength": 32,
"maxLength": 32
}
},
"required": [
"id"
],
"additionalProperties": false,
"response": {
"type": "object",
"properties": {
"physical_properties": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"component_type": {
"type": "string",
"enum": [
"Corner",
"Line",
"Surface",
"Block"
]
},
"attribute_id": {
"type": "string"
},
"attribute_name": {
"type": "string"
},
"element_type": {
"type": "string",
"enum": [
"vertex",
"edge",
"polygon",
"polyhedron"
]
},
"nb_items": {
"type": "integer",
"minimum": 1
},
"components": {
"type": "array",
"items": {
"type": "object",
"properties": {
"geode_id": {
"title": "GeodeId",
"type": "string",
"minLength": 36,
"maxLength": 36
},
"min_values": {
"type": "array",
"items": {
"type": [
"number",
"null"
]
}
},
"max_values": {
"type": "array",
"items": {
"type": [
"number",
"null"
]
}
}
},
"required": [
"geode_id",
"min_values",
"max_values"
],
"additionalProperties": false,
"title": "PhysicalPropertyComponent"
}
}
},
"required": [
"name",
"component_type",
"attribute_id",
"attribute_name",
"element_type",
"nb_items",
"components"
],
"additionalProperties": false,
"title": "PhysicalProperty"
}
}
},
"required": [
"physical_properties"
],
"additionalProperties": false
}
},
"model_component_vertex_attribute_range": {
"$id": "opengeodeweb_back/model_component_vertex_attribute_range",
"route": "/model_component_vertex_attribute_range",
Expand Down
29 changes: 29 additions & 0 deletions opengeodeweb_back_typed_schemas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,34 @@ export interface PingResponse {
message: string;
}

export interface ModelPhysicalPropertiesParams {
id: DataId;
}

export interface ModelPhysicalPropertiesResponse {
physical_properties: PhysicalProperty[];
}

export interface PhysicalProperty {
attribute_id: string;
attribute_name: string;
component_type: ComponentType;
components: PhysicalPropertyComponent[];
element_type: ElementType;
name: string;
nb_items: number;
}

export type ComponentType = "Corner" | "Line" | "Surface" | "Block";

export interface PhysicalPropertyComponent {
geode_id: GeodeId;
max_values: Array<number | null>;
min_values: Array<number | null>;
}

export type ElementType = "vertex" | "edge" | "polygon" | "polyhedron";

export interface ModelComponentVertexAttributeRangeParams {
attribute_name: AttributeName;
component_ids: GeodeId[];
Expand Down Expand Up @@ -641,6 +669,7 @@ export interface Schemas {
readonly polygon_attribute_range: (typeof json)["opengeodeweb_back"]["polygon_attribute_range"] & TypedSchema<PolygonAttributeRangeParams, PolygonAttributeRangeResponse>;
readonly polygon_attribute_names: (typeof json)["opengeodeweb_back"]["polygon_attribute_names"] & TypedSchema<PolygonAttributeNamesParams, PolygonAttributeNamesResponse>;
readonly ping: (typeof json)["opengeodeweb_back"]["ping"] & TypedSchema<PingParams, PingResponse>;
readonly model_physical_properties: (typeof json)["opengeodeweb_back"]["model_physical_properties"] & TypedSchema<ModelPhysicalPropertiesParams, ModelPhysicalPropertiesResponse>;
readonly model_component_vertex_attribute_range: (typeof json)["opengeodeweb_back"]["model_component_vertex_attribute_range"] & TypedSchema<ModelComponentVertexAttributeRangeParams, ModelComponentVertexAttributeRangeResponse>;
readonly model_component_vertex_attribute_names: (typeof json)["opengeodeweb_back"]["model_component_vertex_attribute_names"] & TypedSchema<ModelComponentVertexAttributeNamesParams, ModelComponentVertexAttributeNamesResponse>;
readonly model_component_polyhedron_attribute_range: (typeof json)["opengeodeweb_back"]["model_component_polyhedron_attribute_range"] & TypedSchema<ModelComponentPolyhedronAttributeRangeParams, ModelComponentPolyhedronAttributeRangeResponse>;
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,3 @@ werkzeug==3.1.8
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.5.0rc1
109 changes: 109 additions & 0 deletions src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,115 @@ def model_component_polyhedron_attribute_range(
)


def _element_attribute_managers(
mesh: og.VertexSet,
) -> list[tuple[str, og.AttributeManager]]:
"""Attribute managers of a component mesh, its elements before its vertices."""
managers: list[tuple[str, og.AttributeManager]] = []
for element_type in ("polyhedron", "polygon", "edge"):
method = getattr(mesh, f"{element_type}_attribute_manager", None)
if method is not None:
managers.append((element_type, method()))
managers.append(("vertex", mesh.vertex_attribute_manager()))
return managers


def _physical_property_component(
component_id: og.uuid,
attribute_manager: og.AttributeManager,
attribute_id: og.uuid,
nb_items: int,
) -> schemas.model_physical_properties.PhysicalPropertyComponent:
min_values: list[float | None] = []
max_values: list[float | None] = []
for item_index in range(nb_items):
values, _ = _extract_valid_values_from_attribute(
attribute_manager, attribute_id, item_index
)
# An item without any value (e.g. a free displacement axis) is None: NaN is not JSON
min_values.append(min(values) if values else None)
max_values.append(max(values) if values else None)
return schemas.model_physical_properties.PhysicalPropertyComponent(
geode_id=component_id.string(),
min_values=min_values,
max_values=max_values,
)


def _physical_property(
model: GeodeBRep,
name: og.PhysicalPropertyName,
) -> schemas.model_physical_properties.PhysicalProperty | None:
"""The components carrying a physical property, with their value range per item.

The attribute is searched on the element managers first, then on the vertices: the
physical property only records the component type, not the mesh element. The first
component carrying it sets the element: the others are only read on that element, a
component carrying it on another one is left out.
"""
info = model.brep.physical_property_info(name)
component_type = info.component_type.get()
attribute_id = info.attribute_id
element_type: str | None = None
attribute_name = ""
nb_items = 1
components: list[schemas.model_physical_properties.PhysicalPropertyComponent] = []
for registry_type, component_ids in model.mesh_components().items():
if registry_type.get() != component_type:
continue
for component_id in component_ids:
component = model.component(component_id)
if not isinstance(component, ComponentMesh):
continue
for element, attribute_manager in _element_attribute_managers(component.mesh()):
if element_type is not None and element != element_type:
continue
attribute = attribute_manager.find_generic_attribute(attribute_id)
if attribute is None:
continue
if element_type is None:
element_type = element
attribute_name = attribute.name() or name.name
nb_items = attribute.nb_items()
components.append(
_physical_property_component(
component_id, attribute_manager, attribute_id, nb_items
)
)
break
if element_type is None:
return None
return schemas.model_physical_properties.PhysicalProperty(
name=name.name,
component_type=schemas.model_physical_properties.ComponentType(component_type),
attribute_id=attribute_id.string(),
attribute_name=attribute_name,
element_type=schemas.model_physical_properties.ElementType(element_type),
nb_items=nb_items,
components=components,
)


@typed_route(routes, schemas.model_physical_properties_route)
def model_physical_properties(
params: schemas.ModelPhysicalProperties,
) -> schemas.ModelPhysicalPropertiesResponse:
"""Physical properties of a model and the values of the components carrying them."""
geode_object = geode_functions.load_geode_object(params.id)
if not isinstance(geode_object, GeodeModel):
flask.abort(400, f"{params.id} is not a GeodeModel")
physical_properties: list[schemas.model_physical_properties.PhysicalProperty] = []
# Only BReps (and the models built on them) carry physical properties
if isinstance(geode_object, GeodeBRep):
for name in og.PhysicalPropertyName:
if not geode_object.brep.has_physical_property(name):
continue
physical_property = _physical_property(geode_object, name)
if physical_property is not None:
physical_properties.append(physical_property)
return schemas.ModelPhysicalPropertiesResponse(physical_properties=physical_properties)


@typed_route(routes, schemas.horizon_stack_info_route)
def horizon_stack_info(params: schemas.HorizonStackInfo) -> schemas.HorizonStackInfoResponse:
"""Horizons and stratigraphic units of a horizon stack, top to bottom."""
Expand Down
1 change: 1 addition & 0 deletions src/opengeodeweb_back/routes/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .polygon_attribute_range import *
from .polygon_attribute_names import *
from .ping import *
from .model_physical_properties import *
from .model_component_vertex_attribute_range import *
from .model_component_vertex_attribute_names import *
from .model_component_polyhedron_attribute_range import *
Expand Down
Loading
Loading