Page 1 of 1

Problem while drawing 3D contour and surface

Posted: Sat Nov 14, 2009 11:28 pm
by 10045871
Hello,
I currently have a problem with drawing 3D contour/surface.
I try to read a file which contains 3 colums: x,y and z. While reading (using readln(textfile,x,y,z), I put the data into a Tcontour as follows:

if OpenDialog1.execute then begin
AssignFile(Datafile,OpenDialog1.filename);
Reset(Datafile);
Series1.clear; // Series1 is a TContour
while not(eof(Datafile)) do begin
Readln(Datafile,x,y,z);
Series1.AddXYZ(x,z,z,'',clTeeColor); // add point to the contour
Memo1.Lines.Add(Num2Str(cnt,0,0)+' '+Num2Str(x,2,2) + ' ' + Num2Str(y,2,2) +' ' +Num2Str(z,2,2)); // add values to a TMemo for visualization
end; // end of eof()
CloseFile(Datafile);
end;

The problem is no contour appears on the chart, although the axes correspond to the x and y extents, and the 20 levels legend corresponds to the z values. (please see the attached GIF image).

Just before reading the file, I have tried to populate the chart with for commands, and the following code works:
inherited;
{ First we add XYZ points to the Contour series... }
With Series1 do
begin
Clear;
{ We add values from 0 to 1000. 21x21 cells = 441 }
for x:= -10 to 10 do
for z:= -10 to 10 do
AddXYZ( x, RandomXYZ(x,z) ,z, '', clTeeColor);
end;

I sup

{ Then we specify how many "contour levels" we want }
Series1.NumLevels:=20;

Re: Problem while drawing 3D contour and surface

Posted: Mon Nov 16, 2009 12:29 pm
by narcis
Hi Sciensoria,

Have you tried setting contour's IrregularGrid=true? Notice that such series need to be populated as described here. If this doesn't help please attach a simple example project we can run "as-is" to reproduce the problem here.

Thanks in advance.

Re: Problem while drawing 3D contour and surface

Posted: Mon Nov 16, 2009 1:27 pm
by 10045871
Hi Narcis,
Many thanks for your help.
I have just tried to add Series1.IrregularGrid:=true command but nothing changes (Series1 is a TContourSeries).
I attached my project here so that you can have a look in it. When you launch the project, there are some contours due to initialization. Then you click on the Plot data from file button and load the contour1 file. You will get the loaded data on the right of the window, and the Tcontour plot on the left, but there is no contour line for the moment.
The zip file was checked with anti virus software.

One again, thank you for your help.


Sciensoria
http://www.sciensoria.fr

Re: Problem while drawing 3D contour and surface

Posted: Tue Nov 17, 2009 10:19 am
by yeray
Hi Sciensoria,

According to the explanation that Narcis pointed to you of how the contour series should be populated, I think that adding your values as you do is not correct:

Code: Select all

Series1.AddXYZ(x,z,z,'',clTeeColor); //incorrect input
On the other hand, both the following lines can be applied successfully in your code, giving different results:

Code: Select all

Series1.AddXYZ(x,z,y,'',clTeeColor); //correct input
or...

Code: Select all

Series1.AddXYZ(y,z,x,'',clTeeColor); //correct input

Re: Problem while drawing 3D contour and surface

Posted: Sat May 31, 2014 12:03 am
by 10045871
Hello,
I come back to you for another question: how to use mouse to rotate a 3D surface.
I have read the Surface_XYZFloat unit and see that you use TRotate to do it. However, I didn't find the TRotateTool component on the Delphi panels. So how to add the TRotateTool to a form even when the component is not present on the components panel ?
(I have tried to create the component dynamically by TRotateTool.create(self) but this does'n work)

Thank you for your help.

Re: Problem while drawing 3D contour and surface

Posted: Mon Jun 02, 2014 8:00 am
by yeray
Hello,

The fastest way to add a TRotateTool would be:

Code: Select all

uses TeeTools;
//...
  Chart1.Tools.Add(TRotateTool);
However, if you want to change other properties from it, you could save if into a variable:

Code: Select all

uses TeeTools;
//...
var rotateTool1: TRotateTool;
//...
  rotateTool1:=Chart1.Tools.Add(TRotateTool) as TRotateTool;
Alternatively, you should be able to call the Create constructor:

Code: Select all

uses TeeTools;
//...
var rotateTool1: TRotateTool;
//...
  rotate1:=TRotateTool.Create(Self);
  Chart1.Tools.Add(rotate1);
Finally, you can also add it at design time. You can double-click on a TChart to open the editor, then you can navigate to the "Tools" tab.
2014-06-02_1003_001.png
2014-06-02_1003_001.png (6.12 KiB) Viewed 9348 times
You can click on the "Add..." button to open the tools gallery, select the "Rotate" tool in the "Other" tab, and click "Add".
2014-06-02_1003.png
2014-06-02_1003.png (52.36 KiB) Viewed 9343 times