IntensityMeshSeries with different amount of columns per row

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
Igor
Posts: 67
Joined: Mon Sep 28, 2015 1:14 pm

IntensityMeshSeries with different amount of columns per row

Post by Igor » Tue Sep 25, 2018 12:28 pm

In my application, I use the IntensityMeshSeries.
As data source for the mesh, the series needs an array,
So it's exactly specified how many columns and rows must be included, otherwise
this leads to a faulty presentation.
fail.png
fail.png (86.1 KiB) Viewed 6824 times
I now face the problem that in my application under
circumstances may sometimes be less columns per row.

How could I build the mesh with a different amount of columns?

(everything ok with always the same number of columns per line)
ok.png
ok.png (77.92 KiB) Viewed 6824 times
You can simulate the behavior by changing the method "CreateMeshGeometry()" in the attached sample project.
Please comment/uncomment the for-header in lines 146/147.

Code: Select all

    for (int col = 0; col < rnd.Next(6, columns); col++)
                //for (int col = 0; col < columns; col++)
                {
Attachments
IntensityMeshTest.zip
(106.26 KiB) Downloaded 633 times

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: IntensityMeshSeries with different amount of columns per

Post by ArctionKestutis » Wed Sep 26, 2018 1:42 pm

Intensity series (Grid or Mesh) is array of M x N nodes and you should fill all the nodes. For IntensityMeshSeries X & Y values initialized as 0. Therefore, you are getting broken image as you described, if you are not setting values for remaining nodes.
In your case, either yo need to arrange points differently or use Stencil areas to clip points you don't want to see.

For example, following modification could be done in your code, where polygon is created around mesh and used as stencil:

Code: Select all

            PointDouble2D[] polygonPoints = new PointDouble2D[2 * columns + 2 * rows];
            int iPoly = 0;
            int iColCount = 0;

            for (int row = 0; row < rows; row++)
            {
                double x = minX;
                iColCount = rnd.Next(6, columns);

                //for (int col = 0; col < iColCount; col++)
                for (int col = 0; col < columns; col++)
                {
                    data[col, row].X = x + bendAmplitude * Math.Sin((double)row / 16.0);
                    data[col, row].Y = y + bendAmplitude * Math.Cos((double)col / 16.0);

                    if (row == 0 && col < iColCount - 1)
                    {
                        // add all 1st row point to polygon before Column to be ignored
                        polygonPoints[iPoly].X = data[col, row].X;
                        polygonPoints[iPoly].Y = data[col, row].Y;
                        iPoly++;
                    }
                    x += stepX;
                }
                y += stepY;

                polygonPoints[iPoly].X = data[iColCount - 1, row].X;
                polygonPoints[iPoly].Y = data[iColCount - 1, row].Y;
                iPoly++;
            }

            _intensityMesh.Data = data;

            // add last row points of IntensityMesh to polygon (starting from column one before ignored)
            for (int col = iColCount - 2; col >= 0; col--)
            {
                polygonPoints[iPoly].X = data[col, rows - 1].X;
                polygonPoints[iPoly].Y = data[col, rows - 1].Y;
                iPoly++;
            }

            // add 1st column points of IntensityMesh to polygon
            for (int row = rows - 2; row >= 0; row--)
            {
                polygonPoints[iPoly].X = data[0, row].X;
                polygonPoints[iPoly].Y = data[0, row].Y;
                iPoly++;
            }

            PointDouble2D[] newPolygonPoints = new PointDouble2D[iPoly];
            Array.Copy(polygonPoints, newPolygonPoints, iPoly);

             // Apply circle stencil for Intensity Mesh
            StencilArea stencilArea = new StencilArea(_intensityMesh.Stencil);
            stencilArea.IgnoreHoles = true;
            stencilArea.AddPolygon(newPolygonPoints);
            _intensityMesh.Stencil.AdditiveAreas.Add(stencilArea);
Here is the image
ClippedMesh.png
ClippedMesh.png (57.71 KiB) Viewed 6818 times

Please note, that enabling stencilArea.IgnoreHoles will allow to avoid polygon drawing direction issues (clockwise and anticlockwise may be interpreted differently). In addition, try to avoid adding duplicate points.

Hope this helps.

Post Reply