diff --git a/src/mcd_clip/bike_rendering/bikeCad_renderer.py b/src/mcd_clip/bike_rendering/bikeCad_renderer.py index e06a216..9b96231 100644 --- a/src/mcd_clip/bike_rendering/bikeCad_renderer.py +++ b/src/mcd_clip/bike_rendering/bikeCad_renderer.py @@ -7,7 +7,6 @@ import uuid from asyncio import subprocess -from mcd_clip.bike_rendering.cad_builder import BikeCadFileBuilder from mcd_clip.resource_utils import resource_path TEMP_DIR = "bikes" @@ -21,17 +20,12 @@ class RenderingService: - def __init__(self, renderer_pool_size, cad_builder=BikeCadFileBuilder()): + def __init__(self, renderer_pool_size): os.makedirs(os.path.join(os.path.dirname(__file__), TEMP_DIR), exist_ok=True) self._renderer_pool = queue.Queue(maxsize=renderer_pool_size) - self.cad_builder = cad_builder for i in range(renderer_pool_size): self._renderer_pool.put(BikeCad()) - def render_object(self, bike_object, seed_bike_id): - return self.render(self.cad_builder.build_cad_from_object(bike_object, - seed_bike_id)) - def render(self, bike_xml): renderer = self._get_renderer() result = renderer.render(bike_xml) diff --git a/src/mcd_clip/bike_rendering/cad_builder.py b/src/mcd_clip/bike_rendering/cad_builder.py deleted file mode 100644 index 4f3c5be..0000000 --- a/src/mcd_clip/bike_rendering/cad_builder.py +++ /dev/null @@ -1,45 +0,0 @@ -from mcd_clip.bike_rendering.bike_xml_handler import BikeXmlHandler -from mcd_clip.resource_utils import resource_path - -OPTIMIZED_TO_CAD = { - "ST Angle": "Seat angle", - "HT Length": "Head tube length textfield", - "HT Angle": "Head angle", - "HT LX": "Head tube lower extension2", - 'Stack': 'Stack', - "ST Length": "Seat tube length", - "Seatpost LENGTH": "Seatpost LENGTH", - "Saddle height": "Saddle height", - "Stem length": "Stem length", - "Crank length": "Crank length", - "Headset spacers": "Headset spacers", - "Stem angle": "Stem angle", - "Handlebar style": "Handlebar style", -} - - -def _get_valid_seed_bike(seed_image_id): - if str(seed_image_id) not in [str(_) for _ in range(1, 14)]: - raise ValueError(f"Invalid seed bike ID [{seed_image_id}]") - return f"bike{seed_image_id}.bcad" - - -class BikeCadFileBuilder: - def build_cad_from_object(self, bike_object, seed_bike_id) -> str: - xml_handler = BikeXmlHandler() - self._load_seed_xml(xml_handler, seed_bike_id) - for response_key, cad_key in OPTIMIZED_TO_CAD.items(): - self._update_xml(xml_handler, cad_key, bike_object[response_key]) - # self._update_xml(xml_handler, "Display RIDER", "true") - return xml_handler.get_content_string() - - def _load_seed_xml(self, xml_handler, seed_image_id): - with open(resource_path("PlainRoadBikeStandardized.txt"), "r") as file: - xml_handler.set_xml(file.read()) - - def _update_xml(self, xml_handler, cad_key, desired_value): - entry = xml_handler.find_entry_by_key(cad_key) - if entry: - xml_handler.update_entry_value(entry, str(desired_value)) - else: - xml_handler.add_new_entry(cad_key, str(desired_value)) diff --git a/src/mcd_clip/e2e_runner.py b/src/mcd_clip/e2e_runner.py index 4d337af..282a764 100644 --- a/src/mcd_clip/e2e_runner.py +++ b/src/mcd_clip/e2e_runner.py @@ -94,7 +94,7 @@ def run_counterfactual_generation_task(target_bike_description, if __name__ == "__main__": run_counterfactual_generation_task( - "A yellow bicycle with curved handles", - 300, + "A yellow mountain bike", + 450, 3 ) diff --git a/test/test_rendering.py b/test/test_rendering.py index dcddb09..98cad60 100644 --- a/test/test_rendering.py +++ b/test/test_rendering.py @@ -12,3 +12,6 @@ def test_rendering(self): rendering_result = ParametricToImageConvertor().to_image(data.iloc[0]) self.assertTrue(type(rendering_result.bike_xml) is str) self.assertTrue(type(rendering_result.image) is bytes) + + def test_one_hot_encoded(self): + pass