Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions opendm/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def dem_to_mesh_gridded(inGeotiff, outMesh, maxVertexCount, maxConcurrency=1):
def screened_poisson_reconstruction(inPointCloud, outMesh, depth = 8, samples = 1, maxVertexCount=100000, pointWeight=4, threads=context.num_cores):

mesh_path, mesh_filename = os.path.split(outMesh)
# PoissonRecon otherwise writes out-of-core PR_* files to the caller's
# working directory, which may be read-only even when mesh_path is writable.
tempdir = os.path.abspath(mesh_path or '.')
# mesh_path = path/to
# mesh_filename = odm_mesh.ply

Expand All @@ -157,6 +160,7 @@ def screened_poisson_reconstruction(inPointCloud, outMesh, depth = 8, samples =
'bin': context.poisson_recon_path,
'outfile': outMeshDirty,
'infile': inPointCloud,
'tempdir': tempdir,
'depth': depth,
'samples': samples,
'pointWeight': pointWeight,
Expand All @@ -167,6 +171,7 @@ def screened_poisson_reconstruction(inPointCloud, outMesh, depth = 8, samples =
try:
system.run('"{bin}" --in "{infile}" '
'--out "{outfile}" '
'--tempDir "{tempdir}" '
'--depth {depth} '
'--pointWeight {pointWeight} '
'--samplesPerNode {samples} '
Expand Down
47 changes: 47 additions & 0 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import tempfile
import unittest
from unittest.mock import patch

from opendm import mesh


class TestMesh(unittest.TestCase):
def test_poisson_uses_output_directory_for_temporary_files(self):
with tempfile.TemporaryDirectory() as root:
mesh_dir = os.path.join(root, "mesh output")
os.mkdir(mesh_dir)
point_cloud = os.path.join(root, "cloud.ply")
output = os.path.join(mesh_dir, "odm_mesh.ply")
dirty = os.path.join(mesh_dir, "odm_mesh.dirty.ply")
commands = []

def run(command):
commands.append(command)
if "--linearFit" in command:
with open(dirty, "wb"):
pass

with patch.object(mesh.system, "run", side_effect=run):
with patch.object(
mesh.context, "poisson_recon_path", "PoissonRecon"
):
with patch.object(
mesh.context,
"omvs_reconstructmesh_path",
"ReconstructMesh",
):
result = mesh.screened_poisson_reconstruction(
point_cloud, output, threads=3
)

self.assertEqual(result, output)
self.assertEqual(len(commands), 2)
self.assertIn(
'--tempDir "{}"'.format(os.path.abspath(mesh_dir)),
commands[0],
)


if __name__ == "__main__":
unittest.main()
Loading