Recent

Author Topic: Need help with ColorMapSeries  (Read 3325 times)

Darkhoru

  • Newbie
  • Posts: 2
Need help with ColorMapSeries
« on: December 21, 2015, 08:22:35 pm »
Hello!

I really need help of knowledgeable people. I can not add data into the component ColorMapSeries. I have a matrix of data that the user enters data about body temperature (for example 3x3). I need to draw a graphical temperature distribution (color map). I can't figure out how to add data to the component and to obtain such interpolation.

Please, tell me. All hope only on you  :'(

wp

  • Hero Member
  • *****
  • Posts: 13210
Re: Need help with ColorMapSeries
« Reply #1 on: December 21, 2015, 09:00:42 pm »
First of all, TColorMapSeries is a function series. This means it does not use data values, but a function for plotting. You specify the function in the OnCalculate event.

Nothing is lost for your case of temperature data. You have to interpolate the function values between your gridded data, and plug this interpolation function into the OnCalculate event.

Some time ago, I published some demos here on how to do this. Please see http://forum.lazarus.freepascal.org/index.php/topic,18702.msg112702.htmt - the top-most post draws a colormap for data a a regular (rectangular) grid, while further down you find a version for arbitrary locations.

You should also have a look at the TColorMap tutorial in order to understand how it works: http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_ColorMapSeries,_Zooming

Please come back here if you need further assistance.

Darkhoru

  • Newbie
  • Posts: 2
Re: Need help with ColorMapSeries
« Reply #2 on: December 23, 2015, 08:00:57 pm »
Thank you so much for your work. I have read your code. I understand you made a feature-rich application. But to be honest, for me it is very difficult. I am a newbie. Maybe you will be able to share pieces of code that are only needed for my task?

After reviewing your posts, I came to the conclusion that I need a bilinear interpolation (as shown here - https://en.wikipedia.org/wiki/Bilinear_interpolation).

What data do I have? The matrix temperature. For example, 7x7. 49 points. So, I need to draw 49 points? But then what will be the coordinates of x and y, if I have only the sequence of values of temperatures?

If you have time, please could you share pieces of code that could implement this? So I was able to figure it out. I understand that in your program already implemented, but there are so many components that I as a beginner can not understand...

Thank you so much!!

wp

  • Hero Member
  • *****
  • Posts: 13210
Re: Need help with ColorMapSeries
« Reply #3 on: December 23, 2015, 09:00:24 pm »
Did you look at the header of unit "mapinterpolation" of the "Interpolation.zip" attachment of the first post in http://forum.lazarus.freepascal.org/index.php/topic,18702.msg112702.htmt? It contains step-by-step instructions how to use the interpolator.

The basic idea is that the code in this unit does the main interpolation and prepares a function which you can plug into the TColorMap series' OnCalculate event. The only problem is how you pass your data to the interpolator. For this purpose the interpolator has three events OnNeedX, OnNeedY, and OnNeedZ - x,y indicate the location of the temperature sensor, and Z refers to the temperature.

I don't know how your data are stored. If the 7x7 temperature sensors are equally spaced with a constant distance, and you define the origin in the left-bottom corner of this square, the x index (ix) increases horizontally and the y index (iy) increases vertically then OnNeedX and OnNeedY event handlers simple return the index multiplied by the sensor distance:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.InterpolationNeedX(AIndex: Integer; out AValue:Double);
  2. begin
  3.   AValue := AIndex * Your_Constant_Sensor_Distance;
  4. end;
  5. // the same for OnNeedY

I suppose from your post that your 49 temperature values are stored in a single, 1-dimensional array (a 2d-matrix would be easier). I also suppose the first value is for the origin in the 7x7 grid we had defined above, and the first 7 values are for the first 7 sensors in the horizontal row, and the next 7 sensors are for those in the second row, etc. Then you can convert the row and column index of the sensor to the array index (i)  of the temperatur:

Code: Pascal  [Select][+][-]
  1.   i := iy*7 + ix;

For this to work, indexes must start at 0.

And with this knowledge you can write the event handler OnNeedZ which passes the temperature to the interpolator:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.InterpolationNeedZ(AIndexX, AIndexZ: Integer; out AValue:Double);
  2. var
  3.   i : Integer;
  4. begin
  5.   i := AIndexY * 7 + AIndexX;   // better: use a variable (nx) here instead of "7"
  6.   AValue := Your_Temperature_Array[i];
  7. end;

I think this is all which relates to your data setup. The rest is described in the unit header mentioned above.

 

TinyPortal © 2005-2018