4

I am using scipy.spatial.Delaunay to triangulate a cloud of 3D points.

Each point is imported in an array with the structure R, G, B, X, Y, Z, only the values X, Y, Z are used to triangulate.

I calculate the barycentric coordinates of a list of "target" points.

For each target, I'd like to get:

  • the R, G, B of each point of the simplex in which target is located.

  • the barycentric coordinates of target

I cannot figure out how to get these data with my code.

print bcoords works fine (it generates a series of 4 values for each target):

[[  2.89657287e-01   3.98169955e-01   1.24220635e-01   1.87952122e-01]
 [  3.24695465e-01   3.99228351e-01   8.91849061e-02   1.86891278e-01]
 [  2.89657287e-01   3.98169955e-01   1.24220635e-01   1.87952122e-01]
 ..., 
 [ -1.13763739e+03   1.32600196e+03   2.61787735e+02  -4.49152304e+02]
 [ -1.13764457e+03   1.32600118e+03   2.61796224e+02  -4.49152837e+02]
 [ -1.13765132e+03   1.32600045e+03   2.61804205e+02  -4.49153338e+02]]

However, print tetrahedra generates a list of numbers:

[915 915 915 ...,  -1  -1  -1]

And this list is a list of indices

How can I replace it with a list of vertices?

code:

import csv
import numpy as np
import scipy.spatial

points = np.array([(int(R), int(G), int(B), float(X), float(Y), float(Z))
              for R, G, B, X, Y, Z in csv.reader(open('XYZcolorlist_D65.csv'))])
    # load X,Y,Z coordinates of 'points' in a np.array 
    # alternative points = pd.read_csv('XYZcolorlist_D65.csv')  

tri = scipy.spatial.Delaunay(points[:,[3,4,5]])
# do the triangulation

indices = tri.simplices
# indices of vertices

vertices = points[indices]
# the vertices for each tetrahedron

targets = np.array([(float(X), float(Y), float(Z))
           for name, X, Y, Z, crap in csv.reader(open('targets.csv'))])
    # load the XYZ target values in a np.array

tetrahedra = tri.find_simplex(targets)
# find which tetrahedron each point belong to

X = tri.transform[tetrahedra,:3]
Y = targets - tri.transform[tetrahedra,3]
b = np.einsum('ijk,ik->ij', X, Y)
bcoords = np.c_[b, 1 - b.sum(axis=1)]
# find the barycentric coordinates of each point

#np.savetxt('coords.out', bcoords, fmt="%f")

print points.shape
print indices.shape
print vertices.shape
print tetrahedra.shape
print bcoords.shape

print bcoords
print tetrahedra
print indices
print vertices
adrienlucca.net
  • 677
  • 2
  • 10
  • 26
  • 1
    possible duplicate of [Python numpy, understanding and ordering data structures](http://stackoverflow.com/questions/21649696/python-numpy-understanding-and-ordering-data-structures) – jonrsharpe Feb 08 '14 at 19:46
  • [This answer](http://stackoverflow.com/questions/20915502/speedup-scipy-griddata-for-multiple-interpolations-between-two-irregular-grids/20930910#20930910) may shed some light on some of the inner workings of `Delaunay`. – Jaime Feb 09 '14 at 02:59
  • @Jaime thank you for the link, but I don't see how it helps here. My problem is that I don't know how to get the results of Delaunay: my function `tetrahedra = tri.find_simplex(targets)` gives me a list of numbers that are the "labels" of my `simplices`, instead of getting those "labels", i'd like to get 4 vertices... – adrienlucca.net Feb 09 '14 at 19:58
  • 2
    tetrahedra are just indexes into tri.points – joshua Apr 25 '14 at 22:00

0 Answers0