Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
rasterizing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dwastberg committed Oct 2, 2024
1 parent 5670930 commit ff860d2
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion tests/python/test_meshing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from dtcc_builder.meshing import mesh_multisurface, mesh_surface, mesh_multisurfaces
from dtcc_builder.meshing import (
mesh_multisurface,
mesh_surface,
mesh_multisurfaces,
rasterize_mesh,
)
import dtcc_io as io
from dtcc_model import Mesh, Building, Surface, MultiSurface
import numpy as np
Expand Down Expand Up @@ -201,3 +206,62 @@ def test_mesh_multisurfaces(self):
self.assertEqual(len(meshes[1].faces), 6)
self.assertAlmostEqual(meshes[1].vertices[:, 2].min(), 0)
self.assertAlmostEqual(meshes[1].vertices[:, 2].max(), 7)


class TestMeshConvertion(unittest.TestCase):
def test_get_vertices(self):
vertice = np.array(
[
[0, 0, 5],
[0, 10, 5],
[10, 10, 8],
[10, 0, 8],
[0, 0, 0],
]
)
faces = np.array([[0, 1, 2], [0, 2, 3]])
mesh = Mesh(vertices=vertice, faces=faces)
unique_verices = mesh.unique_vertices()

self.assertEqual(len(unique_verices), 4)
self.assertEqual(unique_verices[:, 2].min(), 5)

def test_face_centroids(self):
vertice = np.array(
[
[0, 0, 5],
[0, 10, 5],
[10, 10, 8],
[10, 0, 8],
[0, 0, 0],
]
)
faces = np.array([[0, 1, 2], [0, 2, 3]])
mesh = Mesh(vertices=vertice, faces=faces)
centroids = mesh.face_centroids()
self.assertEqual(len(centroids), 2)
self.assertAlmostEqual(centroids[0][0], 10 / 3.0)
self.assertAlmostEqual(centroids[0][1], 20 / 3.0)
self.assertAlmostEqual(centroids[0][2], 6)

def test_rasterize(self):
vertice = np.array(
[
[0, 0, 5],
[0, 10, 5],
[10, 10, 8],
[10, 0, 8],
]
)
faces = np.array([[0, 1, 2], [0, 2, 3]])
mesh = Mesh(vertices=vertice, faces=faces)
raster = rasterize_mesh(mesh, 1, include_centroids=True)
bounds = raster.bounds
self.assertAlmostEqual(bounds.xmin, 0)
self.assertAlmostEqual(bounds.ymin, 0)
self.assertAlmostEqual(bounds.xmax, 10)
self.assertAlmostEqual(bounds.ymax, 10)
self.assertAlmostEqual(
raster.min, 5, places=1
) # roughly equal to 5.03 due to interpolation
self.assertAlmostEqual(raster.max, 8, places=1)

0 comments on commit ff860d2

Please sign in to comment.