Hi, On 21 Oct 2010, at 13:25, JuanPi wrote:
> Hi c. > > Thanks a lot for the pointer. Indeed I am working with triangular > meshes. > > In my experience dealing with cells is very slow, so I try to avoid > them. > > I need this function to speed up queries to a mesh (maybe there is a > better solution), with a cost on memory and preprocessing. I use the > point2triag matrix to slice(or clip) the mesh to the region of > interest, and then do the usual call to inpolygon (or tsearch, though > I found it slow) in the clipped mesh. > This use of the matrix requires fast slicing, and I wonder if a cell > would be slower... > example > Given a extremely dense mesh "T" of the square [0 1] and Nx2 nodes > coordinates "coord". > Given points "xi" in a circle of radius 0.1 and center c=[0.5,0.5] > To get the triangles they belong to I would do > > p2T = point2triag(T); > idx = find( sumsq( coord-repmat(c,N,1),2) <= (0.1)^2) > triangles = p2T(idx,:); If I understand correctly, what you need to do is find all triangles whos vertices are all within a distance d = 0.1 from a point c = [xc, yc]. I'm not sure whether my approach is faster than yours but what I usually do when I need something like that is: triangles = find (all (ismember (t (1:3, :), (p(1,:) - xc).^2 + (p(2,:) - yc).^2 <= d^2))); this is untested but should work in Ocatve 3.3+, while in 3.2.4 I seem to recall you would need a reshape to work around a bug in ismember: triangles = find (all (reshape (ismember (t (1:3, :), (p(1,:) - xc).^2 + (p(2,:) - yc).^2 <= d^2), size(t(1:3,:))))); note that I have vertex coordinates in a 2 x nvertex matrix p and triangle veritces in the first 3 rows of a 4 x ntriangles matrix t, so I think p = coord' and T' = t (1:3, :). > While with a cell, I think, it wont be so easy. Please correct me if I > am wrong, I love the functionalities of cells, but at the moment I > need speed! Maybe a sparse matrix would be another option, but I have > no clue how sparse are the matrix created this way. > > Also, note that point2triag internally calculates the maximum degree > of your mesh and erases the extra columns (filled with NaNs) at the > end. > > I will be happy to contribute with the functionality, provided my code > is somehow efficient. even though I wouldn't use it in the case above, I believe point2triag would be a nice addition to msh, why do you say a cell-array is slower in this case, do you have an example benchmark? > Thanks, > > JPi c. ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev