I use a scipy.spatial.Delaunaycloud of three-dimensional points to triangulate.
Each point is imported into an array with a structure R, G, B, X, Y, Z; only values are used for triangulation X, Y, Z.
I calculate the barycentric coordinates of the list of "target" points.
For each goal, I would like to get:
R, G, B of each point of the simplex at which the target is located.
barycentric target coordinates
I cannot figure out how to get this data with my code.
print bcoordsworks 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, it print tetrahedracreates a list of numbers:
[915 915 915 ..., -1 -1 -1]
And this list is a list indices
How can I replace it with a list vertices?
the 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'))])
tri = scipy.spatial.Delaunay(points[:,[3,4,5]])
indices = tri.simplices
vertices = points[indices]
targets = np.array([(float(X), float(Y), float(Z))
for name, X, Y, Z, crap in csv.reader(open('targets.csv'))])
tetrahedra = tri.find_simplex(targets)
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)]
print points.shape
print indices.shape
print vertices.shape
print tetrahedra.shape
print bcoords.shape
print bcoords
print tetrahedra
print indices
print vertices