Skip to content

Commit 817c506

Browse files
committed
Add unit tests for Python codes.
1 parent 675f3b3 commit 817c506

File tree

17 files changed

+171
-45
lines changed

17 files changed

+171
-45
lines changed

.gitignore

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1+
# IDE
12
.idea/*
3+
.vscode/*
4+
build/*
25
cmake-build-debug/*
36
cmake-build-release/*
47
Testing/*
58

6-
build/*
7-
89
*.TMP
910
.DS_Store
1011

1112
test_config.h
1213

14+
# C/C++ libraries
1315
*.a
1416
*.so
1517
*.lib
1618
*.dll
17-
*.pyd
1819
*.dylib
1920

21+
# Python cache files
22+
*.pyc
23+
*.pyd
24+
__pycache__/*
25+
26+
27+
# Mesh file format
2028
*.ply
2129
*.obj
30+
*.off
31+
*.stl

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ option(BUILD_TESTS "Build unit tests." OFF)
1616
set(CMAKE_CXX_STANDARD 17)
1717
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1818
if (UNIX)
19-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
19+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -Wall")
2020
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O2")
2121
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
2222
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
@@ -31,7 +31,7 @@ endif()
3131
# ----------
3232
set(TINYMESH_LIBRARY "tinymesh")
3333
set(TINYMESH_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/src")
34-
set(TINYMESH_PYTHON_MODULE "pytinymesh")
34+
set(TINYMESH_PYTHON_MODULE "tinymesh-python")
3535

3636
# ----------
3737
# Required packages

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Here is the list of modules and reference papers for that.
2929

3030
* [Eigen 3.x](http://eigen.tuxfamily.org/index.php)
3131

32-
### Build
32+
### C++ Library and Examples
3333

3434
You can build a shared library and all the examples by `CMake` with the following commands.
3535

@@ -40,13 +40,38 @@ $ mkdir build && cd build
4040
$ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON ..
4141
$ cmake --build . --config Release --parallel 2
4242
```
43+
#### Run examples
4344

44-
### Examples
45+
```shell
46+
$ ./build/bin/example_simplify data/models/bunny.ply
47+
```
48+
49+
### Python module
50+
51+
By the following shell command, you can build the module, which will be placed on the root of this repo.
4552

4653
```shell
47-
$ ./build/bin/example data/models/bunny.ply
54+
$ python setup.py build_ext -i
4855
```
4956

57+
Otherwise, you can build the module also using `CMake`.
58+
59+
```shell
60+
$ mkdir build && cd build
61+
$ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON_MODULE=ON ..
62+
$ cmake --build . --config Release --parallel 2
63+
```
64+
65+
#### Run examples
66+
67+
```shell
68+
$ python examples/python/fill_and_fair.py data/models/bunny.ply
69+
```
70+
71+
## Screen shots
72+
73+
74+
5075
## License
5176

52-
Mozilla Public License v2 (c) Tatsuya Yatagawa 2019
77+
Mozilla Public License v2 (c) Tatsuya Yatagawa 2020

data/.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
!models/*.ply
2-
!models/*.obj
1+
!models/bunny.ply
2+
!models/box.obj
3+
!models/plane.obj
4+
!models/sphere.obj
5+
!models/torus.obj
36

environment.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: tinymesh
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- numpy
6+
- nose
7+
- matplotlib
8+
- conda-forge::plyfile

examples/python/construct.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,36 @@
22
import sys
33
from plyfile import PlyData, PlyElement
44
import numpy as np
5-
from pytinymesh import Mesh
5+
from tinymesh import Mesh
66

7-
def main(filename):
8-
# Construct a simple tetrahedron
9-
a = np.asarray([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='double')
10-
b = np.asarray([0, 1, 2, 0, 2, 3, 0, 3, 1, 3, 2, 1], dtype='uint32')
11-
mesh = Mesh(a, b)
12-
mesh.save('tetra.ply')
137

14-
# Load .PLY with "plyfile" and construct a mesh by "tinymesh"
8+
def main(filename):
9+
# Load .PLY with "plyfile"
1510
plydata = PlyData.read(filename)
1611
vx = plydata['vertex']['x']
1712
vy = plydata['vertex']['y']
1813
vz = plydata['vertex']['z']
1914
verts = np.stack([vx, vy, vz], axis=1).astype('double')
20-
elems = np.concatenate(plydata['face']['vertex_indices']).astype('uint32')
21-
mesh = Mesh(verts, elems)
22-
mesh.save('output.ply')
15+
faces = np.concatenate(plydata['face']['vertex_indices']).astype('uint32')
16+
17+
# Construct halfedge structure by "tinymesh"
18+
mesh = Mesh(verts, faces)
19+
20+
# Get vertices and indices back to Python
21+
verts = mesh.get_vertices()
22+
faces = mesh.get_vertex_indices()
23+
24+
verts = np.asarray(verts, dtype='float32')
25+
faces = np.asarray(faces, dtype='int32').reshape((-1, 3))
26+
27+
vert_el = np.array([tuple(v) for v in verts], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
28+
face_el = np.array([(tuple(f),) for f in faces], dtype=[('vertex_indices', 'i4', (3,))])
29+
plydata = PlyData([PlyElement.describe(vert_el, 'vertex'),
30+
PlyElement.describe(face_el, 'face')], text=False)
31+
32+
base, ext = os.path.splitext(filename)
33+
outfile = base + "_copy" + ext
34+
plydata.write(outfile)
2335

2436

2537
if __name__ == '__main__':

examples/python/fill_and_fair.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import sys
3-
from pytinymesh import Mesh, hole_fill, remesh_incremental
3+
from tinymesh import Mesh, hole_fill, remesh_incremental
44

55

66
def main(filename):

examples/simplify/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ int main(int argc, char **argv) {
1818

1919
// Simplify
2020
const int target = (int)(ratio * mesh.num_vertices());
21-
tinymesh::simplifyIncremental(mesh, target);
2221
tinymesh::hole_fill(mesh);
22+
tinymesh::simplifyIncremental(mesh, target);
2323
tinymesh::remeshIncremental(mesh);
2424

2525
// Save

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ def build_extension(self, ext):
6464
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
6565
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
6666

67+
6768
setup(
68-
name='pytinymesh',
69+
name='tinymesh',
6970
version='0.1.0',
7071
author='Tatsuya Yatagawa',
7172
author_email='[email protected]',
7273
description='TinyMesh is a light-weight mesh processing library',
7374
long_description='',
74-
ext_modules=[CMakeExtension('pytinymesh')],
75+
ext_modules=[CMakeExtension('tinymesh')],
7576
cmdclass=dict(build_ext=CMakeBuild)
7677
)

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ if (BUILD_PYTHON_MODULE)
99
include_directories(${CMAKE_CURRENT_LIST_DIR}/tinymesh/ext/pybind11)
1010
add_subdirectory(tinymesh/ext/pybind11)
1111
pybind11_add_module(${TINYMESH_PYTHON_MODULE} pybind11.cpp)
12+
set_target_properties(${TINYMESH_PYTHON_MODULE} PROPERTIES OUTPUT_NAME "tinymesh")
1213
target_link_libraries(${TINYMESH_PYTHON_MODULE} PRIVATE ${TINYMESH_LIBRARY})
1314
endif()

0 commit comments

Comments
 (0)