@@ -80,55 +80,56 @@ def create_voi() -> flask.Response:
8080 utils_functions .validate_request (flask .request , schemas_dict ["create_voi" ])
8181 params = schemas .CreateVoi .from_dict (flask .request .get_json ())
8282
83- # Define the 4 vertices of the AOI (bottom face in the XY plane)
83+ aoi_data = geode_functions .get_data_info (params .aoi_id )
84+ if not aoi_data :
85+ flask .abort (404 , f"AOI with id { params .aoi_id } not found" )
86+
87+ edged_curve_aoi = geode_functions .load_data (params .aoi_id )
88+ if not isinstance (edged_curve_aoi , opengeode .EdgedCurve3D ):
89+ flask .abort (400 , "Referenced object is not an EdgedCurve3D (AOI)" )
90+
91+ bbox_aoi = edged_curve_aoi .bounding_box ()
92+ min_x = bbox_aoi .min ().value (0 )
93+ min_y = bbox_aoi .min ().value (1 )
94+ max_x = bbox_aoi .max ().value (0 )
95+ max_y = bbox_aoi .max ().value (1 )
96+
8497 aoi_vertices = [
85- (params . min_x , params . min_y ),
86- (params . max_x , params . min_y ),
87- (params . max_x , params . max_y ),
88- (params . min_x , params . max_y ),
98+ (min_x , min_y ),
99+ (max_x , min_y ),
100+ (max_x , max_y ),
101+ (min_x , max_y ),
89102 ]
90103
91- # Create the EdgedCurve object and its builder
92104 edged_curve = geode_functions .geode_object_class ("EdgedCurve3D" ).create ()
93105 builder = geode_functions .create_builder ("EdgedCurve3D" , edged_curve )
94106 builder .set_name (params .name )
95107
96- # Extract Z bounds
97108 z_min = params .z_min
98109 z_max = params .z_max
99110
100- # --- 1. Create the 8 vertices of the bounding box ---
101111
102- # Create the 4 bottom vertices (indices 0 to 3)
103112 for x , y in aoi_vertices :
104113 builder .create_point (opengeode .Point3D ([x , y , z_min ]))
105114
106- # Create the 4 top vertices (indices 4 to 7)
107115 for x , y in aoi_vertices :
108116 builder .create_point (opengeode .Point3D ([x , y , z_max ]))
109117
110- # --- 2. Define and create the 12 edges of the bounding box ---
111118
112- # Edges of the bottom face (connecting vertices 0-1, 1-2, 2-3, 3-0)
113119 bottom_edges = [(i , (i + 1 ) % 4 ) for i in range (4 )]
114120
115- # Edges of the top face (connecting vertices 4-5, 5-6, 6-7, 7-4)
116- # The (i + 4) and ((i + 1) % 4 + 4) ensure we use indices 4, 5, 6, 7
117121 top_edges = [(i + 4 , (i + 1 ) % 4 + 4 ) for i in range (4 )]
118122
119- # Vertical edges (connecting bottom (0-3) to top (4-7) vertices: 0-4, 1-5, 2-6, 3-7)
120123 vertical_edges = [(i , i + 4 ) for i in range (4 )]
121124
122- # Combine all edges
123125 all_edges = bottom_edges + top_edges + vertical_edges
124126
125- # Create the edges in the EdgedCurve
126127 for v1 , v2 in all_edges :
127128 builder .create_edge_with_vertices (v1 , v2 )
128129
129- # Save and get info
130130 result = utils_functions .generate_native_viewable_and_light_viewable_from_object (
131131 geode_object = "EdgedCurve3D" ,
132132 data = edged_curve ,
133133 )
134+ result ["aoi_id" ] = params .aoi_id
134135 return flask .make_response (result , 200 )
0 commit comments