88import flask
99import werkzeug
1010import zipfile
11+ import opengeode as og
1112import opengeode_io as og_io
1213import opengeode_geosciences as og_geosciences
1314import opengeode_geosciencesio as og_geosciencesio
@@ -264,6 +265,30 @@ def texture_coordinates() -> flask.Response:
264265 return flask .make_response ({"texture_coordinates" : texture_coordinates }, 200 )
265266
266267
268+ def attributes_metadata (manager : og .AttributeManager ) -> dict [str , list [float ]]:
269+ metadata : dict [str , list [float ]] = {}
270+ for name in manager .attribute_names ():
271+ attribute = manager .find_generic_attribute (name )
272+ if not attribute .is_genericable ():
273+ metadata [name ] = [- 1.0 , - 1.0 ]
274+ continue
275+ min_value = None
276+ max_value = None
277+ nb_items = attribute .nb_items ()
278+ for i in range (nb_items ):
279+ generic_value = attribute .generic_value (i )
280+ if min_value is None or generic_value < min_value :
281+ min_value = generic_value
282+ if max_value is None or generic_value > max_value :
283+ max_value = generic_value
284+ metadata [name ] = (
285+ [min_value , max_value ]
286+ if min_value is not None and max_value is not None
287+ else [- 1.0 , - 1.0 ]
288+ )
289+ return metadata
290+
291+
267292@routes .route (
268293 schemas_dict ["vertex_attribute_names" ]["route" ],
269294 methods = schemas_dict ["vertex_attribute_names" ]["methods" ],
@@ -276,10 +301,11 @@ def vertex_attribute_names() -> flask.Response:
276301 geode_object = geode_functions .load_geode_object (params .id )
277302 if not isinstance (geode_object , GeodeMesh ):
278303 flask .abort (400 , f"{ params .id } is not a GeodeMesh" )
279- vertex_attribute_names = geode_object .vertex_attribute_manager (). attribute_names ()
304+ attribute_manager = geode_object .vertex_attribute_manager ()
280305 return flask .make_response (
281306 {
282- "vertex_attribute_names" : vertex_attribute_names ,
307+ "vertex_attribute_names" : attribute_manager .attribute_names (),
308+ "vertex_attribute_metadata" : attributes_metadata (attribute_manager ),
283309 },
284310 200 ,
285311 )
@@ -297,10 +323,11 @@ def cell_attribute_names() -> flask.Response:
297323 geode_object = geode_functions .load_geode_object (params .id )
298324 if not isinstance (geode_object , GeodeGrid2D | GeodeGrid3D ):
299325 flask .abort (400 , f"{ params .id } is not a GeodeGrid" )
300- cell_attribute_names = geode_object .cell_attribute_manager (). attribute_names ()
326+ attribute_manager = geode_object .cell_attribute_manager ()
301327 return flask .make_response (
302328 {
303- "cell_attribute_names" : cell_attribute_names ,
329+ "cell_attribute_names" : attribute_manager .attribute_names (),
330+ "cell_attribute_metadata" : attributes_metadata (attribute_manager ),
304331 },
305332 200 ,
306333 )
@@ -318,10 +345,11 @@ def polygon_attribute_names() -> flask.Response:
318345 geode_object = geode_functions .load_geode_object (params .id )
319346 if not isinstance (geode_object , GeodeSurfaceMesh2D | GeodeSurfaceMesh3D ):
320347 flask .abort (400 , f"{ params .id } is not a GeodeSurfaceMesh" )
321- polygon_attribute_names = geode_object .polygon_attribute_manager (). attribute_names ()
348+ attribute_manager = geode_object .polygon_attribute_manager ()
322349 return flask .make_response (
323350 {
324- "polygon_attribute_names" : polygon_attribute_names ,
351+ "polygon_attribute_names" : attribute_manager .attribute_names (),
352+ "polygon_attribute_metadata" : attributes_metadata (attribute_manager ),
325353 },
326354 200 ,
327355 )
@@ -339,12 +367,11 @@ def polyhedron_attribute_names() -> flask.Response:
339367 geode_object = geode_functions .load_geode_object (params .id )
340368 if not isinstance (geode_object , GeodeSolidMesh3D ):
341369 flask .abort (400 , f"{ params .id } is not a GeodeSolidMesh" )
342- polyhedron_attribute_names = (
343- geode_object .polyhedron_attribute_manager ().attribute_names ()
344- )
370+ attribute_manager = geode_object .polyhedron_attribute_manager ()
345371 return flask .make_response (
346372 {
347- "polyhedron_attribute_names" : polyhedron_attribute_names ,
373+ "polyhedron_attribute_names" : attribute_manager .attribute_names (),
374+ "polyhedron_attribute_metadata" : attributes_metadata (attribute_manager ),
348375 },
349376 200 ,
350377 )
@@ -362,10 +389,11 @@ def edge_attribute_names() -> flask.Response:
362389 geode_object = geode_functions .load_geode_object (params .id )
363390 if not isinstance (geode_object , GeodeGraph ):
364391 flask .abort (400 , f"{ params .id } does not have edges" )
365- edge_attribute_names = geode_object .edge_attribute_manager (). attribute_names ()
392+ attribute_manager = geode_object .edge_attribute_manager ()
366393 return flask .make_response (
367394 {
368- "edge_attribute_names" : edge_attribute_names ,
395+ "edge_attribute_names" : attribute_manager .attribute_names (),
396+ "edge_attribute_metadata" : attributes_metadata (attribute_manager ),
369397 },
370398 200 ,
371399 )
0 commit comments