comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » problem with TRIANGULATION option in CONTOUR
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
problem with TRIANGULATION option in CONTOUR [message #73053] Sat, 23 October 2010 05:35 Go to next message
Ardhuin is currently offline  Ardhuin
Messages: 5
Registered: October 2010
Junior Member
Dear all,
I have been having problems with plotting output of a numerical model
that uses unstructured grids using IDL: this model computes wave
heights in the ocean. If I use the set of triangles from the model, I
get really funny errors:
Out of range subscript encountered: <LONG Array[66453]>.
although I only have 9626 points and about 16000 triangles.

The command I use is
CONTOUR,tablep,x,y,$
xstyle=5,ystyle=5,/FOLLOW,/CELL_FILL, TRIANGULATION=tri,
$
C_COLOR=colorind(0:c_numlev-2+addmini+addmaxi), $
LEVELS=lev,/
NOERASE,TITLE=title,CLIP=[rangex(0),rangey(0),rangex(1),rang ey(1)], $
XRANGE=rangex,YRANGE=rangey,MAX_VALUE=maxval, $
POSITION=[blx*winx/mwinx,bly*winy/mwiny,trx*winx/
mwinx,try*winy/mwiny]

Where tablep , x and y
If I first do TRIANGULATE,X,Y,tri then the contours comes out OK...
but they cut out through land boundaries and islands.

So I was thinking: my triangles must be wrong ...
but if I do a TRIGRID with my triangles then I can plot nicely with
TV ...
array=trigrid(X,Y,tablep,tri,[dx,dy],
[rangex(0),rangey(0),rangex(1),rangey(1)], $
MAX_VALUE=maxval)

So my triangles are OK for TRIGRID but not for CONTOUR... How is that
possible ??
Re: problem with TRIANGULATION option in CONTOUR [message #73125 is a reply to message #73053] Tue, 26 October 2010 06:52 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ardhuin writes:

> OK David, your stuff makes a contour ... but you go through trigrid,
> so you loose the initial resolution (a bit like going from vector to
> raster graphics ...).

I don't know what you mean by "initial resolution". I thought
you meant you liked a smoother contour gradient. That's why the
first example showed the contours on top of the image.

What do you mean by it?

> so MY REAL QUESTION is: what is so special about the triangle fed into
> CONTOUR ??? Why can't I just provide my own??
> I guess I now must turn to ITTVIS.

I showed you an example where you supplied the triangles.
I'm not understanding your question at all. Sorry.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: problem with TRIANGULATION option in CONTOUR [message #73126 is a reply to message #73053] Tue, 26 October 2010 06:34 Go to previous message
Ardhuin is currently offline  Ardhuin
Messages: 5
Registered: October 2010
Junior Member
Hi to all,
OK David, your stuff makes a contour ... but you go through trigrid,
so you loose the initial resolution (a bit like going from vector to
raster graphics ...).

so MY REAL QUESTION is: what is so special about the triangle fed into
CONTOUR ??? Why can't I just provide my own??
I guess I now must turn to ITTVIS.


> Actually, in defense of my own (blissful) ignorance, it is not obvious
> that the triangulation is anything other than what might be produced by
> TRIANGULATE.
Why not?

> probably saying, "What is it with these dopes!  I have been saying that
> all along!"  Well, free help probably isn't worth some much nowadays.
you're dead on. But at least some other folks like me now know it by
reading it.
>
> How did you clip the triangulation to begin with?
No, I use this wonderful tool:
http://www.cs.cmu.edu/~quake/triangle.html

Which is widely used for Computational Fluid Dynamics ... and it would
be nice that IDL could use this native triangle grid ...
Thanks for your patience,

Fabrice
Re: problem with TRIANGULATION option in CONTOUR [message #73128 is a reply to message #73053] Tue, 26 October 2010 05:18 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ardhuin writes:

> Hi, yes, obviously: the TRIANGULATE command will make more triangles
> because it will also fill the land, which I do not want. So, why is my
> set of triangles not working in contour ?? That looks like a bug to
> me.

Your triangles work in Contour. Here is a filled contour
version of the program I made available yesterday,
along with a picture.

http://www.dfanning.com/misc/filled_contour.zip

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: problem with TRIANGULATION option in CONTOUR [message #73130 is a reply to message #73053] Tue, 26 October 2010 04:31 Go to previous message
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
On 10/26/10 2:04 AM, Ardhuin wrote:
> On 26 oct, 02:54, David Fanning<n...@dfanning.com> wrote:
>> Ben Tupper writes:
>>> When I load the data you have posted and generate the triangulation I
>>> get a different number of triangles than you. You can see this in the
>>> output of help - note that tri2 has 19160 vertices. Also, you clip the
>>> maximum Z value when you use TRIGRID but you don't specify it for
>>> CONTOUR. I don't know if these are important issues, but perhaps you
>>> are unwittingly comparing apples to oranges?
>
> Hi, yes, obviously: the TRIANGULATE command will make more triangles
> because it will also fill the land, which I do not want. So, why is my
> set of triangles not working in contour ?? That looks like a bug to
> me.
>
> And if I try
> CONTOUR,Z,X,Y,xstyle=5,ystyle=5, TRIANGULATION=TRI,/CELL_FILL,
> MAX_VALUE=10000.
>
> I still get the same error:
> % Out of range subscript encountered:<LONG Array[66453]>.
> % Execution halted at: $MAIN$
>

Hi,

Actually, in defense of my own (blissful) ignorance, it is not obvious
that the triangulation is anything other than what might be produced by
TRIANGULATE.


OK, your TRI triangles have been screened already - those edges that
cross the land have been pulled out of TRI but they still reside in the
triangulation that TRI2 contains. I can see that if I do this...

PRO OPLOT_TRI, x,y,triangles, _EXTRA = extra

COMPILE_OPT IDL2

FOR i = 0, N_ELEMENTS(triangles)/3 - 1 DO BEGIN

t = [triangles[*,i], triangles[0,i]]
PLOTS, x[t], y[t], _EXTRA = extra

ENDFOR

END

.compile oplot_tri
plot, x,y, xrange = rangex, yrange =rangey, psym = 6
oplot_tri, x,y,tri, psym=-3 ; <---- your triangles

window,/free
plot, x,y, xrange = rangex, yrange =rangey, psym = 6
oplot_tri, x,y,tri2, psym=-3 ; <---- TRIANGULATES triangles


When you contour using the triangulation, the CONTOUR routine is
expecting TRIANGULATE's triangulation, not a modified one. At least
that is what the documents state:

"TRIANGULATION

Set this keyword to a variable that contains an array of triangles
returned from the TRIANGULATE procedure. Providing triangulation data
allows you to contour irregularly gridded data directly, without gridding."


TRIGRID on the other hand, looks like it only needs the triangulation in
the same form as that provided by TRIANGULATION, but it doesn't need to
be from TRIANGULATE. Here's what it's docs state:

"Triangles

A longword array of the form output by TRIANGULATE. That is, Triangles
has the dimensions (3, number of triangles) and, for each i,
Triangles[0,i], Triangles[1,i], and Triangles[2,i] are the indices of
the vertices of the i-th triangle."


So, it looks like TRIGRID is loose enough to work with what you give it,
but CONTOUR is much more rigid in its expectations. At this point, your
probably saying, "What is it with these dopes! I have been saying that
all along!" Well, free help probably isn't worth some much nowadays.

How did you clip the triangulation to begin with? Did you even use
TRIANGULATE to compute the triangles?

Ben
Re: problem with TRIANGULATION option in CONTOUR [message #73133 is a reply to message #73053] Mon, 25 October 2010 23:04 Go to previous message
Ardhuin is currently offline  Ardhuin
Messages: 5
Registered: October 2010
Junior Member
On 26 oct, 02:54, David Fanning <n...@dfanning.com> wrote:
> Ben Tupper writes:
>> When I load the data you have posted and generate the triangulation I
>> get a different number of triangles than you.  You can see this in the
>> output of help - note that tri2 has 19160 vertices.  Also, you clip the
>> maximum Z value when you use TRIGRID but you don't specify it for
>> CONTOUR.  I don't know if these are important issues, but perhaps you
>> are unwittingly comparing apples to oranges?

Hi, yes, obviously: the TRIANGULATE command will make more triangles
because it will also fill the land, which I do not want. So, why is my
set of triangles not working in contour ?? That looks like a bug to
me.

And if I try
CONTOUR,Z,X,Y,xstyle=5,ystyle=5, TRIANGULATION=TRI,/CELL_FILL,
MAX_VALUE=10000.

I still get the same error:
% Out of range subscript encountered: <LONG Array[66453]>.
% Execution halted at: $MAIN$

Fabrice
Re: problem with TRIANGULATION option in CONTOUR [message #73136 is a reply to message #73053] Mon, 25 October 2010 17:54 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ben Tupper writes:

> When I load the data you have posted and generate the triangulation I
> get a different number of triangles than you. You can see this in the
> output of help - note that tri2 has 19160 vertices. Also, you clip the
> maximum Z value when you use TRIGRID but you don't specify it for
> CONTOUR. I don't know if these are important issues, but perhaps you
> are unwittingly comparing apples to oranges?

Yes, now that I look at my code again, I didn't recompute
the triangles, just used the ones provided. When I did
the triangulation independently, I got the same number
of triangles Ben got.

I noticed right away the discrepancy between the two
images provided. And I wonder if the first figure (the
one that used the TV command) and for which the triangles were
presumably provided was actually created with a different data set
than the second figure, which was created with the contour command.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: problem with TRIANGULATION option in CONTOUR [message #73139 is a reply to message #73053] Mon, 25 October 2010 17:29 Go to previous message
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
On 10/25/10 3:06 PM, Ardhuin wrote:
> Well, this is exactly what I do not want to do: I want to use my
> triangulation because it contains the information on the grid
> connectivity (islands are "holes" in the grid where the contouring
> should not do any filling).
>
> I have put the basic dataset at this ftp address:
> ftp://ftp.ifremer.fr/ifremer/cersat/products/gridded/wavewat ch3/TOOLS/IDL/BUG/
> with some illustrative plots. The standard contour fills everything,
> including land. If I do a TRIGRID before a TV then I get want I want:
> land and Islands are blank... but I'd like to do this with contour to
> use the native data resolution...
>

Hi,

When I load the data you have posted and generate the triangulation I
get a different number of triangles than you. You can see this in the
output of help - note that tri2 has 19160 vertices. Also, you clip the
maximum Z value when you use TRIGRID but you don't specify it for
CONTOUR. I don't know if these are important issues, but perhaps you
are unwittingly comparing apples to oranges?

Cheers,
Ben

IDL> .full_reset
IDL> restore, filename =
"/Users/Shared/data/tri/TRIANGULATION_MARSEILLE.sav"
IDL> TRIANGULATE, x, y, tri2

IDL> help

% At $MAIN$
DX FLOAT = 0.273573
DY FLOAT = 0.223977
RANGEX FLOAT = Array[2]
RANGEY FLOAT = Array[2]
TRI LONG = Array[3, 18326]
TRI2 LONG = Array[3, 19160]
X FLOAT = Array[9626]
Y FLOAT = Array[9626]
Z FLOAT = Array[9626]
Re: problem with TRIANGULATION option in CONTOUR [message #73147 is a reply to message #73053] Mon, 25 October 2010 15:17 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ardhuin writes:

> Well, this is exactly what I do not want to do: I want to use my
> triangulation because it contains the information on the grid
> connectivity (islands are "holes" in the grid where the contouring
> should not do any filling).
>
> I have put the basic dataset at this ftp address:
> ftp://ftp.ifremer.fr/ifremer/cersat/products/gridded/wavewat ch3/TOOLS/IDL/BUG/
> with some illustrative plots. The standard contour fills everything,
> including land. If I do a TRIGRID before a TV then I get want I want:
> land and Islands are blank... but I'd like to do this with contour to
> use the native data resolution...

It seemed to me you wanted to put a contour plot on top
of an image, so that's what I've shown you how to do.
You will need Coyote Library programs to run the code.

http://www.dfanning.com/programs/coyoteprograms.zip

You can find the program I wrote, and a PNG file of what
the output looks like here:

http://www.dfanning.com/misc/contour_on_image.zip

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Help! (where is all the Help that used to be in 7?)
Next Topic: Spell checking code

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:43:46 PDT 2025

Total time taken to generate the page: 0.00494 seconds