Page 1 of 1

IntensityMeshSeries with different amount of columns per row

Posted: Tue Sep 25, 2018 12:28 pm
by Igor
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 6835 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 6835 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++)
                {

Re: IntensityMeshSeries with different amount of columns per

Posted: Wed Sep 26, 2018 1:42 pm
by ArctionKestutis
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 6829 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.