diff --git a/examples/quick_test.py b/examples/quick_test.py index f9d47a1..4e5c576 100644 --- a/examples/quick_test.py +++ b/examples/quick_test.py @@ -3,17 +3,13 @@ print("--- START") # one triangle as a geometric element -# we write our triangle in a CaribuScene format -organ_id = 1 -triangle_vertices = [(0,0,0), (1,0,0), (1,1,1)] -triangle = {organ_id : [triangle_vertices]} -geometry = { "scenes" : [triangle] } +triangle_vertices = [(0.,0.,0.), (1.,0.,0.), (1.,1.,1.)] # surfacic lighting with CARIBU lighting = LightVegeManager(lightmodel="caribu") # build the scene -lighting.build(geometry) +lighting.build(geometry=triangle_vertices) # compute lighting energy = 500 diff --git a/src/lightvegemanager/tool.py b/src/lightvegemanager/tool.py index 32c81a7..1c7dd01 100644 --- a/src/lightvegemanager/tool.py +++ b/src/lightvegemanager/tool.py @@ -212,6 +212,10 @@ def build(self, geometry={}, global_scene_tesselate_level=0): :type global_scene_tesselate_level: int, optional :raises ValueError: Currently, converting voxels mesh to triangles mesh is not possible """ + # pre-check of scenes input, if it has only one triangle or one list of triangles + if isatriangle(geometry) or all(isatriangle(s) for s in geometry): + geometry = {"scenes" : geometry} + self.__geometry = geometry # First process of the scenes list, it gathers all triangulations diff --git a/tests/test_trianglesmesh.py b/tests/test_trianglesmesh.py index 7703d82..873c567 100644 --- a/tests/test_trianglesmesh.py +++ b/tests/test_trianglesmesh.py @@ -139,6 +139,30 @@ def test_isatriangle(): assert not isatriangle(tr4) assert not isatriangle(tr5) +# single triangle +tr = [(0., 0., 0.), (0., 1., 0.), (1., 1., 1.)] +expected1 = ( + {0 : [tr] }, + {0 : [0, 0]} +) + +# list of triangles +triangles = [ + [(0., 0., 0.), (0., 1., 0.), (1., 1., 1.)], + [(0., 0., 10.), (0., 1., 10.), (1., 1., 11.)], + [(0., 0., 20.), (0., 1., 20.), (1., 1., 21.)], +] +expected2 = ( + {0 : triangles }, + {0 : [0, 0]} +) + +@pytest.mark.parametrize("test_input, expected", [(tr, expected1), (triangles, expected2)]) +def test_chain_triangulations_simple(test_input, expected): + complete_trimesh, matching_ids, legume_grid, id_legume_scene = chain_triangulations(test_input) + assert complete_trimesh == expected[0] + assert matching_ids == expected[1] + def test_chain_triangulations(): # single triangle @@ -218,9 +242,6 @@ def test_chain_triangulations(): for t in itertools.chain(*complete_trimesh.values()): assert isatriangle(t) -test_chain_triangulations() - - transformation_1 = {"scenes unit": {0: "m", 1: "dm"}} expected_1 = { 0: [[(0.0, 0.0, 0.0), (0.0, 100.0, 0.0), (100.0, 100.0, 100.0)]],