I am trying to write code for Voronoi patches. This works fine with Matlab as seen below:
<!-- language: lang-Matlab -->
z = cat(2, x,y);
[V, C] = voronoin(z);
for i = 1:length(C)
if any( C{i} == 1)
continue
else
Cnew = [Cnew, i];
end
end
for i = 1:length(Cnew)
xx = V( C{Cnew(i)} , 1);
yy = V( C{Cnew(i)} , 2);
disp(i), disp(xx), disp(yy)
plot(xx,yy, 'Color', 'blue')
end
which is actually what I want!
However, since Matlab calls qhull, I wanted to use it directly, so that I can create a free version for my friends. So I used qhull directly from the commandline, and used its output to do the plotting. This is the result:
Now this is obviously wrong. So the relevant code for obtaining this is as follows:
The command that I use on the command line (for the same set of data points) is the following:
qvoronoi o QJ Fo < data.txt > output.txt
As can be seen, some the the vertices are not correct, although the majority of the vertices are ok ...
The relaxant part of the code used for this plot is the following:
for pD in pData:
if 0 in pD: continue
pD = pD + [pD[0]]
x, y = np.array([vData[i] for i in pD]).T
pl.plot(x,y, color='blue')
pl.show()
Here, pData are the "patch" information that looks like this:
In [6]: pData[:10]
Out[6]:
[[6, 312, 280, 228, 0, 163, 311],
[4, 0, 228, 230, 229],
[8, 0, 100, 101, 20, 21, 19, 70, 163],
[5, 314, 281, 70, 163, 311],
[4, 0, 18, 160, 229],
[4, 282, 19, 70, 281],
[4, 161, 157, 18, 160],
[5, 103, 99, 101, 100, 102],
[6, 101, 20, 76, 75, 37, 99],
[6, 0, 100, 102, 41, 40, 356]]
While vData are the vertices which look like that:
In [7]: vData[:10]
Out[7]:
[[-10.101, -10.101],
[475.0000000012008, 522.999999964199],
[465.1459330246624, 450.7368421188263],
[537.1737804542415, 426.2004572957462],
[477.2870813371678, 434.0427631710093],
[484.6180167742115, 54.98463685526782],
[433.9793388408901, 439.3090909117672],
[399.2310513506661, 466.2359413331789],
[417.877358491973, 465.8773584984193],
[461.9861308542621, 410.6663110455131]]
This information is obviously not correct. I am guessing that the problem is with the way in which I am calling qhull. Maybe I am not using the right flags? Can someone throw some light on the subject please??
Some specifications about the system I am working on: Windows 7 Matlab version R2010A Python 2.7
I actually use Python's subprocess module to run a DOS shell command to get the values directly from Qhull. That part is as follows:
# Execute qvoronoi to get the vertices and patches
p = subP.Popen('bin\qvoronoi o %s < %s'%(params, fileName), \
shell=True, \
stdout=subP.PIPE, \
stderr=subP.STDOUT)
lines = p.stdout.readlines()
retval = p.wait()
However, this part is working properly. I have already verified this.
Note: I cannot post images. Apparently this is a "reputation" thing. If you want to see the images, please feel free to ask ...