Skip to content

Commit

Permalink
add function read obj lines. update readme and licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
zishun committed Mar 18, 2022
1 parent 1d85869 commit 5c68737
Show file tree
Hide file tree
Showing 11 changed files with 577 additions and 43 deletions.
25 changes: 25 additions & 0 deletions LICENSE.BSD2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BSD 2-Clause License

Copyright (c) 2008, Danil Kirsanov
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
373 changes: 373 additions & 0 deletions LICENSE.MPL2

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions LICENSE.OpenMesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
OpenMesh is licensed under the 3-clause BSD License. See the LICENSE file for the complete license.

/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *\
29 changes: 29 additions & 0 deletions LICENSE.pybind11
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright (c) 2016 Wenzel Jakob <[email protected]>, All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of
external contributions to this project including patches, pull requests, etc.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include LICENSE
include LICENSE.*
include README.md
include CMakeLists.txt
graft src
Expand Down
46 changes: 10 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[![Build](https://github.com/zishun/MeshUtility/actions/workflows/wheels.yml/badge.svg?branch=main)](https://github.com/zishun/MeshUtility/actions/workflows/wheels.yml)
# MeshUtility

A collection of python utilities for mesh processing.

Install with
```
pip install meshutility==0.0.1
```

A simple tutorial is available [here](https://zishun.github.io/projects/MeshUtility/).


Expand All @@ -10,48 +16,16 @@ A simple tutorial is available [here](https://zishun.github.io/projects/MeshUtil
- ```IsoCurve``` module: extract isocurves on a scalar field defined on a manifold triangular mesh.
- ```mesh_cut```: cut a mesh along a vertex chain.
- ```mesh_split```: split a mesh by inserting new vertices defined on mesh edges.
- ```read_obj_lines```: read polyline from a [Wavefront .obj file](https://en.wikipedia.org/wiki/Wavefront_.obj_file#Line_elements).
- ```sphere_cvt```: iteratively approximate centroidal Voronoi tessellation (CVT) on the unit sphere (kind of uniform sampling).
- ```split_connected_components```: split connected components.
- ```write_obj_lines```: write polyline as a [Wavefront .obj file](https://en.wikipedia.org/wiki/Wavefront_.obj_file#Line_elements), which can be open with MeshLab.
- ```write_obj_lines```: write polyline as a Wavefront .obj file that can be open with MeshLab.
- ```pygeodesic``` module (C++): exact geodesic for triangular meshes.
- ```pyisocurve``` module (C++): almost the same as ```IsoCurve``` above.
- ```pyremesh``` module (C++): incremental isotropic remeshing.
- ```pyshapeop``` module (C++): a partial binding of ShapeOp.


## TL;DR
```
pip install numpy scipy networkx matplotlib openmesh
conda install -c conda-forge igl meshplot
git clone --recurse-submodules https://github.com/zishun/MeshUtility.git
python setup.py install
```

## Dependencies

Python:
* numpy
* scipy
* networkx
* matplotlib
* openmesh
* libigl Python bindings
* meshplot: only for jupyter notebook

Install with
```shell
pip install numpy scipy networkx matplotlib openmesh
conda install -c conda-forge igl meshplot
```

C++:
* Eigen
* OpenMesh
* libigl
* geodesic: Danil Kirsanov's implementation of MMP algorithm.

All have been included here directly or as submodules.
## Build from Source

## Build
1. Clone the repo: ```git clone --recurse-submodules https://github.com/zishun/MeshUtility.git```
2. ```python setup.py install```
see [```build.md```](https://github.com/zishun/MeshUtility/blob/main/build.md)
55 changes: 55 additions & 0 deletions build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Setup MeshUtility

## TL;DR
```
pip install numpy scipy networkx matplotlib openmesh
conda install -c conda-forge igl meshplot
git clone --recurse-submodules https://github.com/zishun/MeshUtility.git
python setup.py install
```

## Dependencies

<details>
<summary>
<b>
Python:
</b>
</summary>

* numpy
* scipy
* networkx
* matplotlib
* openmesh
* libigl Python bindings
* meshplot: only for jupyter notebook

</details>



Install with
```shell
pip install numpy scipy networkx matplotlib openmesh
conda install -c conda-forge igl meshplot
```

<details>
<summary>
<b>
C++:
</b>
</summary>
* Eigen
* OpenMesh
* libigl
* geodesic: Danil Kirsanov's implementation of MMP algorithm.
* ShapeOp
</details>

All have been included here directly or as submodules.

## Build
1. Clone the repo: ```git clone --recurse-submodules https://github.com/zishun/MeshUtility.git```
2. ```python setup.py install```
2 changes: 1 addition & 1 deletion meshutility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .mesh2graph import *
from .sphere_cvt import *
from .split_connected_components import *
from .write_obj_lines import *
from .obj_lines_io import *
from .pygeodesic import *
from .pyisocurve import *
from .pyremesh import *
Expand Down
35 changes: 35 additions & 0 deletions meshutility/write_obj_lines.py → meshutility/obj_lines_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Author: Zishun Liu <[email protected]>
Date: Feb 16, 2021
"""
import numpy as np


def write_obj_lines(fn, verts, lines):
Expand Down Expand Up @@ -34,3 +35,37 @@ def write_obj_lines(fn, verts, lines):
for line in lines:
for i in range(len(line)-1):
f.write('l %d %d\n' % (line[i]+1, line[i+1]+1))


def read_obj_lines(fn):
"""
Read polylines from an obj file.
Parameters
----------
fn : str
path to the output obj file
Returns
-------
verts : numpy.array
vertex coordinates (n x 3)
lines : numpy.array (m x 2)
edge segments
"""
verts = []
segs = []
with open(fn, 'r') as f:
lines = f.readlines()
for i in range(len(lines)):
s = lines[i].split()
if (len(s) == 0):
continue
if (s[0] == 'v'):
verts.append([float(s[1]), float(s[2]), float(s[3])])
elif (s[0] == 'l'):
L = list(map(lambda x: int(x), s[1:]))
segs.extend([[L[i], L[i+1]] for i in range(len(L)-1)])

verts_mat = np.array(verts)
segs_mat = np.array(segs)-1 # 1-indexed -> 0-indexed
return verts_mat, segs_mat
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
from pathlib import Path

# Convert distutils Windows platform specifiers to CMake -A arguments
PLAT_TO_CMAKE = {
Expand Down Expand Up @@ -119,13 +120,16 @@ def build_extension(self, ext):

# The information here can also be placed in setup.cfg - better separation of
# logic and declaration, and simpler if you include description/version in a file.
this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()
setup(
name="meshutility",
version="0.0.1",
author="Zishun Liu",
author_email="",
description="A collection of python utilities for mesh processing",
long_description="",
long_description=long_description,
long_description_content_type='text/markdown'
url="https://github.com/zishun/MeshUtility",
project_urls={
"Bug Tracker": "https://github.com/zishun/MeshUtility/issues",
Expand All @@ -134,6 +138,7 @@ def build_extension(self, ext):
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Operating System :: OS Independent",
"Topic :: Multimedia :: Graphics :: 3D Modeling",
],
install_requires=[ 'numpy', 'scipy', 'openmesh', 'networkx', 'matplotlib' ],
ext_modules=[CMakeExtension("meshutility.cpp")],
Expand Down

0 comments on commit 5c68737

Please sign in to comment.