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,:);

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.

Thanks,

JPi

On Thu, Oct 21, 2010 at 12:51 PM, c. <carlo.defa...@gmail.com> wrote:
>
> On 21 Oct 2010, at 10:05, JuanPi wrote:
>
>> Dear all,
>>
>> I have been trying to documet my functions with some examples. I am
>> using the format described in
>>>
>>> help demo
>>
>> I have a function point2triag that works perfectly when I call it form
>> Octave's terminal, but when I use
>>>
>>> demo(point2triag)
>>
>> I am getting an error of undefined elements in the body of the function.
>>
>> The header is
>> %% p2T = point2triag(T)
>> % p2T = point2triag(T,degMax)
>> %
>> % Given a triangulation T produces the matrix that indicates for each
>> point to
>> % which triangles it belongs to.
>> % The tinagulation T is matrix fo size Ntx3 where each element is an
>> integer
>> % indicating the position of a node in a list of vertices.
>> % Since different points can belong to a differnt number of triangles, the
>> % output has NaNs as unused elements.
>> %
>> % The optional argument degMax indicates the maximum number of trinagles a
>> point
>> % can belong to. If your mesh has a point belonging to more than 10
>> trinagles
>> % you should use degMax > 10 (default value).
>> %
>> %!demo
>> %! coord=rand(10,2);
>> %! Tri=delaunay(coord(:,1),coord(:,2));
>> %! p2T = point2triag(Tri)
>>
>> The last 3 lines defines the demo. They work perfectly in the terminal
>> I am using Octave 3.2.4 compiled in Ubuntu 10.04
>>
>> Thanks
>> --
>> JuanPi Carbajal
>
> JuanPi,
> If you are working a lot with triangular meshes you might want to take a
> look at the package msh in octave forge:
>
> http://octave.sourceforge.net/msh/index.html
>
> For example, it would be nice to add the functionality of your function
> 'point2triag' to the function:
>
> http://octave.sourceforge.net/msh/function/msh2m_topological_properties.html
>
> just one question, why are you using a matrix full of NaNs and not a
> cell-array to store p2T?
> I think using p2T would make it very easy to write a vectorised version of
> 'point2triag'...
>
> c.
>
>
>
>
>
>



-- 
JuanPi Carbajal
-----
A neutron walks into a bar and orders a drink. It asks the bartender,
"How much?", the bartender answers, "For you, sir, no charge."
-----
www.ailab.ch/carbajal

------------------------------------------------------------------------------
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

Reply via email to