Skip to content

Instantly share code, notes, and snippets.

@celiacintas
Last active July 19, 2016 20:26
Show Gist options
  • Save celiacintas/191527da400cacae4a36ede5f60cfe7e to your computer and use it in GitHub Desktop.
Save celiacintas/191527da400cacae4a36ede5f60cfe7e to your computer and use it in GitHub Desktop.
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
cols = 63*3 + 1 # 63 is the larger polyline in the file
df = pd.read_csv('skel.cgal', header=None, sep=" ", names=range(cols), engine='python')
out = []
for index, row in df.iterrows():
n = row[0]
tmp_array = row[1:].values[~np.isnan(row[1:].values)]
tmp_array = tmp_array.reshape((int(n), 3))
a = np.amax(tmp_array, axis=0)
b = np.amin(tmp_array, axis=0)
if np.linalg.norm(a - b) > 0.5 :
ax.plot(tmp_array[:,0], tmp_array[:, 1], tmp_array[:, 2], label=str(index))
out.append([tmp_array[0, 0], tmp_array[0, 1], tmp_array[0, 2]]) # comienzo
out.append([tmp_array[-1, 0], tmp_array[-1, 1], tmp_array[-1, 2]]) # fin
ax.plot([tmp_array[0, 0]], [tmp_array[0, 1]], [tmp_array[0, 2]], 'ro')
ax.plot([tmp_array[-1, 0]], [tmp_array[-1, 1]], [tmp_array[-1, 2]], 'bo')
plt.legend()
plt.show()
my_out = np.array(out).reshape((-1, 3))
print my_out
np.savetxt("/tmp/max_points_skel.txt", my_out, fmt='%.6f')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment