Thread Subject: tristripping of vertices matrix

Subject: tristripping of vertices matrix

From: Felix Morsdorf

Date: 23 Aug, 2007 13:15:11

Message: 1 of 3

Hello all,

I am trying to write a function that outputs the content of a matlab opengl
rendered axis to an OpenSceneGraph (.osg) file for faster 3d visualization.

I have so far succeeded for simple objects like point, lines and patches.

For objects of type 'surf' I am now facing the problem of converting the
matlab generated vertices and vertex normals matrices into triangle strips.

Matlab vertices (three times for x,y,z) Tristrip(s):
1 2 3 1 4 2 5 3 6
4 5 6 4 7 5 8 6 9
7 8 9


I have now implemeted a very clumsy (using loops and slow!) way of doing it,
which generates some triangles that are not in the original data. Does
anybody know a way of doing it using e.g. clever indexing ?

cheers,

Felix

Subject: tristripping of vertices matrix

From: Titus

Date: 23 Aug, 2007 13:23:37

Message: 2 of 3


"Felix Morsdorf" <felix.morsdorf@geo.uzh.ch> schrieb im Newsbeitrag
news:fak18v$j47$1@fred.mathworks.com...
> Hello all,
>
> I am trying to write a function that outputs the content of a matlab
> opengl
> rendered axis to an OpenSceneGraph (.osg) file for faster 3d
> visualization.
>
> I have so far succeeded for simple objects like point, lines and patches.
>
> For objects of type 'surf' I am now facing the problem of converting the
> matlab generated vertices and vertex normals matrices into triangle
> strips.
>
> Matlab vertices (three times for x,y,z) Tristrip(s):
> 1 2 3 1 4 2
> 5 3 6
> 4 5 6 4 7 5
> 8 6 9
> 7 8 9
>
>
> I have now implemeted a very clumsy (using loops and slow!) way of doing
> it,
> which generates some triangles that are not in the original data. Does
> anybody know a way of doing it using e.g. clever indexing ?
>
> cheers,
>
> Felix

Hi Felix,
at least for this example the following works:
A = reshape(1:9,3,3)'
ATri = reshape(A([1 2 2 3],:), 2, 6)

Hope, this helps,
Titus

Subject: tristripping of vertices matrix

From: Felix Morsdorf

Date: 23 Aug, 2007 14:44:58

Message: 3 of 3

Many thanks Titus for your help!

It works very well, the generalised form will look like this:

A = reshape(1:20,4,5)';
[m,n] = size(A);
 jj = [1:m-1,2:m];
 ATri = reshape(A(jj,:),m-1,n*2);

these lines replace about four time the code with loops :-)

cheers,

Felix


"Titus" <titus.edelhofer@mathworks.de> wrote in message <fak1oq$pig
$1@fred.mathworks.com>...
>
> "Felix Morsdorf" <felix.morsdorf@geo.uzh.ch> schrieb im Newsbeitrag
> news:fak18v$j47$1@fred.mathworks.com...
> > Hello all,
> >
> > I am trying to write a function that outputs the content of a matlab
> > opengl
> > rendered axis to an OpenSceneGraph (.osg) file for faster 3d
> > visualization.
> >
> > I have so far succeeded for simple objects like point, lines and patches.
> >
> > For objects of type 'surf' I am now facing the problem of converting the
> > matlab generated vertices and vertex normals matrices into triangle
> > strips.
> >
> > Matlab vertices (three times for x,y,z) Tristrip(s):
> > 1 2 3 1 4 2
> > 5 3 6
> > 4 5 6 4 7 5
> > 8 6 9
> > 7 8 9
> >
> >
> > I have now implemeted a very clumsy (using loops and slow!) way of
doing
> > it,
> > which generates some triangles that are not in the original data. Does
> > anybody know a way of doing it using e.g. clever indexing ?
> >
> > cheers,
> >
> > Felix
>
> Hi Felix,
> at least for this example the following works:
> A = reshape(1:9,3,3)'
> ATri = reshape(A([1 2 2 3],:), 2, 6)
>
> Hope, this helps,
> Titus
>
>
>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
matrix indexing Felix Morsdorf 23 Aug, 2007 09:20:21
3d graphics Felix Morsdorf 23 Aug, 2007 09:20:20
rssFeed for this Thread

Contact us at files@mathworks.com