Issue 1:
Hi all,

Maybe this is not the right place to ask for hints but is the place that I know ;)

In order to improve the efficiency of a python script, I am trying to convert a script based on a lot of "for loop" operations on a points cloud thanks to Numpy to speed up the process.

In a nutshell, I have a 3d model represented as a set of 3d points (x,y,z coordinates) contained in a np.array (dimension : (188706, 3))

[[168.998 167.681 0.] <-- point 1
[169.72 167.695 0.] <-- point 2
[170.44 167.629 0.] <-- point 3
...
[148.986 163.271 25.8] <-- point 188704
[148.594 163.634 25.8] <-- point 188705
[148.547 163.667 25.8]] <-- point 188706

Each pair of [[row x-1][row x]] represents a segment in 3D

[[168.998 167.681 0.] [169.72 167.695 0.] <-- SEGMENT 1 (points 1 & 2)
[169.72 167.695 0.] [170.44 167.629 0.] <-- SEGMENT 2 (points 2 & 3)
[170.44 167.629 0.] [171.149 167.483 0.] <-- SEGMENT 3 (points 3 & 4)
...
[149.328 162.853 25.8] [148.986 163.271 25.8] <-- SEGMENT 94351 (points 188703 & 188704)
[148.986 163.271 25.8] [148.594 163.634 25.8] <-- SEGMENT 94352 (points 18874 & 188705)
[148.594 163.634 25.8] [148.547 163.667 25.8]] <-- SEGMENT 94353 (points 188705 & 188706)

My goal is to measure the euclidean distance between each ordered points//pair of rows(= the length of each segments) so that I can detect where I need to add more points to represent a bit more the surface of my 3d model. In other words, if the segment length is above a threshold value (=0.5mm), I will have to discretize this particular segment with more points and to add those additional points in my points cloud.

I've found a way to measure the euclidean distance recurcively between each rows thanks to this code:

EuclidianDistance = np.linalg.norm(PtCloud[:-1] - PtCloud[1:],axis=1)

Which gives this result:

[0.72213572 0.72301867 0.72387637 ... 0.54008148 0.5342593 0.05742822]

And I found as well how to descretize a segment according to its vertices (extremities):

def AddEquidistantPoints(p1, p2, parts):
return np.stack((np.linspace(p1[0], p2[0], parts + 1), np.linspace(p1[1], p2[1], parts + 1)), axis=-1)

if EuclidianDistance > 0.5mm:
dist = AddEquidistantPoints(currentRow, previousRow, 10) #10 --> nb subdivisions

But my first issue is those euclidean distances have only to be computed on points where z coordinates are equals. Have I to split my array when z coordinate are not equals ?

With :

PtCloud = np.split(PtCloud, np.where(np.diff(PtCloud[:,2])!=0)[0]+1)

Which gives me a list of arrays so I suppose I will have unfortunately to use a for loop...

Here is the proper behavior represented with Excel:

And my second problem is related to the recurcive check and discretization step since I don't know how to implement it with this particular case. I wonder if there is a way to do it without any for loops.

So I would be very delighted if anyone could help me solve this challenge as I am currently "stuck".

It starts to be very challenging for me.

Thanks in advance,

Hervé

Issue 2:
Original ticket http://projects.scipy.org/numpy/ticket/2171 on 2012-06-19 by trac user edcjones, assigned to unknown.

I use up-to-date Debian testing (wheezy) linux, amd64 architecture. I have installed packages python3.2, version 3.2.3~rc2-1 and python3-numpy, version 1:1.6.2-1.

I got the same answers with packages python2.7, version 2.7.3~rc2-2.1, and python-numpy, version 1:1.6.2-1.

Create a numpy.float128 scalar whose value is 2**64 - 1, and call it "x". int(x) is incorrect.