Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
Restructured files and added new installation instructions.
Created setup files.
  • Loading branch information
mattbv committed Feb 20, 2019
1 parent 634ead4 commit 7aa26f8
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 113 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
v1.0
----
- Generated setup files to install package.
- Bumped version to 1.0 as it's completely operational.
26 changes: 25 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pc2graph
General Information
~~~~~~~~~~~~~~~~~~~

This is a Python script that converts a numpy.ndarray containing a point cloud
This is a Python (2.7x) script that converts a numpy.ndarray containing a point cloud
(x, y, z) into a NetworkX graph.

The code also includes a function to extract shortest path information from a
Expand All @@ -19,3 +19,27 @@ and Scientific Development (10.13039/501100003593) – Brazil (Process number 23

Any questions or suggestions, feel free to contact me using one of the
following e-mails: [email protected] or [email protected]


Installation
~~~~~~~~~~~~

To install this package use the command:

.. code-block:: python
python setup.py install
or:

.. code-block:: python
pip install pc2graph
2 changes: 1 addition & 1 deletion data/batch/files.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
../data/point_cloud_example.txt
../../data/point_cloud_example.txt
Binary file added data/test_gif/test.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
32 changes: 32 additions & 0 deletions pc2graph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2018-2019, Matheus Boni Vicari, pc2graph
# All rights reserved.
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = "Matheus Boni Vicari"
__copyright__ = "Copyright 2018-2019"
__credits__ = ["Matheus Boni Vicari"]
__license__ = "GPL3"
__version__ = "1.0"
__maintainer__ = "Matheus Boni Vicari"
__email__ = "[email protected]"
__status__ = "Development"


__all__ = ['downsampling', 'shortpath']

import downsampling
import shortpath

6 changes: 3 additions & 3 deletions pc2graph/downsampling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017, Matheus Boni Vicari, TLSeparation Project
# Copyright (c) 2018-2019, Matheus Boni Vicari, pc2graph
# All rights reserved.
#
#
Expand All @@ -16,10 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = "Matheus Boni Vicari"
__copyright__ = "Copyright 2017"
__copyright__ = "Copyright 2018-2019"
__credits__ = ["Matheus Boni Vicari"]
__license__ = "GPL3"
__version__ = "0.1"
__version__ = "1.0"
__maintainer__ = "Matheus Boni Vicari"
__email__ = "[email protected]"
__status__ = "Development"
Expand Down
93 changes: 0 additions & 93 deletions pc2graph/example_plot_gif.py

This file was deleted.

14 changes: 7 additions & 7 deletions pc2graph/example_batch.py → pc2graph/examples/example_batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017, Matheus Boni Vicari, TLSeparation Project
# Copyright (c) 2018-2019, Matheus Boni Vicari, pc2graph
# All rights reserved.
#
#
Expand All @@ -16,10 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = "Matheus Boni Vicari"
__copyright__ = "Copyright 2017"
__copyright__ = "Copyright 2018-2019"
__credits__ = ["Matheus Boni Vicari"]
__license__ = "GPL3"
__version__ = "0.1"
__version__ = "1.0"
__maintainer__ = "Matheus Boni Vicari"
__email__ = "[email protected]"
__status__ = "Development"
Expand All @@ -32,9 +32,9 @@

if __name__ == '__main__':

# Declaring list of files to process and output folder.
filelist = '../data/batch/files.txt'
out_folder = '../data/batch/'
# Declaring list of files to process and output directory.
filelist = '../../data/batch/files.txt'
out_dir = '../../data/batch/'

# Declaring downsample size of 10 cm.
downsample_size = 0.1
Expand Down Expand Up @@ -112,4 +112,4 @@
# Stacking all variables and exporting.
out_cloud = np.hstack((upscale_cloud, upscale_distance.reshape(-1, 1),
diff.reshape(-1, 1)))
np.savetxt('%s%s.txt' % (out_folder, fname), out_cloud, fmt='%1.3f')
np.savetxt('%s%s.txt' % (out_dir, fname), out_cloud, fmt='%1.3f')
99 changes: 99 additions & 0 deletions pc2graph/examples/example_plot_gif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Copyright (c) 2018-2019, Matheus Boni Vicari, pc2graph
# All rights reserved.
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = "Matheus Boni Vicari"
__copyright__ = "Copyright 2018-2019"
__credits__ = ["Matheus Boni Vicari"]
__license__ = "GPL3"
__version__ = "1.0"
__maintainer__ = "Matheus Boni Vicari"
__email__ = "[email protected]"
__status__ = "Development"

from downsampling import downsample_cloud
from shortpath import array_to_graph
import numpy as np
import glob
import os




if __name__ == '__main__':

try:
import mayavi.mlab as mlab

# Setting up where to save the data.
out_dir = '../../data/test_gif/'
out_file = 'test'
layer_delay = 2

# Setting up parameters to generate the graph.
point_cloud = np.loadtxt('../../data/point_cloud_example.txt')
downsample_dist = 0.05
kpairs = 3
knn = 100
nbr_dist_threshold = downsample_dist * 1.5
nbr_dist_threshold_step = 0.03
downsample_cloud = downsample_cloud(point_cloud, downsample_dist)

# Obtaining base id (lowest point in the cloud).
base_id = np.argmin(downsample_cloud[:, 2])

# Generating graph with option to return the step_register as True.
G, step_register = array_to_graph(downsample_cloud, base_id, kpairs,
knn, nbr_dist_threshold,
nbr_dist_threshold_step,
return_step=True)


# Starts the iterative plotting. This will require the Mayavi package.
iteration = 0
mlab.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0))
mlab.points3d(downsample_cloud[:, 0], downsample_cloud[:, 1],
downsample_cloud[:, 2], color=(0.3, 0.3, 0.3), mode='point')
for s in np.unique(step_register):
mask = step_register == s
mlab.points3d(downsample_cloud[mask, 0], downsample_cloud[mask, 1],
downsample_cloud[mask, 2], color=(1, 0, 0), mode='point')
mlab.savefig(out_dir + '%s.png' % iteration)
iteration += 1
mlab.close()

# Generating the list of step images to join in a gif later.
file_list = glob.glob('%s*.png' % out_dir)
file_list = [os.path.basename(f) for f in file_list]
list.sort(file_list, key=lambda x: int(os.path.basename(x).split('.png')[0]))
with open('%simage_list.txt' % out_dir, 'w') as file:
for item in file_list:
file.write("%s\n" % item)

# Changing directory and using ImageMagik to join all images into a gif.
# Then, delets all unnecessary files.In the end, returns to initial
# directory.
cwd = os.getcwd()
os.chdir(out_dir)
os.system('convert -loop 0 -delay %s @image_list.txt %s.gif' % (layer_delay, out_file))
os.remove('image_list.txt')
for f in file_list:
os.remove(f)
os.chdir(cwd)

except:
print('Mayavi not installed, this example cannot run!')

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017, Matheus Boni Vicari, TLSeparation Project
# Copyright (c) 2018-2019, Matheus Boni Vicari, pc2graph
# All rights reserved.
#
#
Expand All @@ -16,10 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = "Matheus Boni Vicari"
__copyright__ = "Copyright 2017"
__copyright__ = "Copyright 2018-2019"
__credits__ = ["Matheus Boni Vicari"]
__license__ = "GPL3"
__version__ = "0.1"
__version__ = "1.0"
__maintainer__ = "Matheus Boni Vicari"
__email__ = "[email protected]"
__status__ = "Development"
Expand All @@ -31,7 +31,7 @@
if __name__ == "__main__":

# Loads point cloud into a numpy.ndarray (n_points x dimensions).
point_cloud = np.loadtxt('../data/point_cloud_example.txt')
point_cloud = np.loadtxt('../../data/point_cloud_example.txt')

# Growth factor. Each point adds 3 new points to graph.
kpairs = 3
Expand Down Expand Up @@ -64,4 +64,4 @@
# Preparing output point cloud.
distance = np.asarray(distance).reshape(-1, 1)
out_cloud = np.hstack((nodes, distance))
np.savetxt('../data/output_point_cloud.txt', out_cloud, fmt='%1.3f')
np.savetxt('../../data/output_point_cloud.txt', out_cloud, fmt='%1.3f')
6 changes: 3 additions & 3 deletions pc2graph/shortpath.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017, Matheus Boni Vicari, TLSeparation Project
# Copyright (c) 2018-2019, Matheus Boni Vicari, pc2graph
# All rights reserved.
#
#
Expand All @@ -16,10 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = "Matheus Boni Vicari"
__copyright__ = "Copyright 2017"
__copyright__ = "Copyright 2018-2019"
__credits__ = ["Matheus Boni Vicari"]
__license__ = "GPL3"
__version__ = "0.1"
__version__ = "1.0"
__maintainer__ = "Matheus Boni Vicari"
__email__ = "[email protected]"
__status__ = "Development"
Expand Down
Loading

0 comments on commit 7aa26f8

Please sign in to comment.