Grade control

Hi
I tried to make a painted elevation map but I am stuck right now
opengrade3D

So, when I open a field it look min and max easting and northing. After, it make a new list with a point a each meter and for this point it should give the altitude for the nearest survey point. But right now it always take the last, I cannot find the bug.
OpenGL.Designer Line 676 CalculateMinMaxEastNort

 private void CalculateMinMaxEastNort()
        {


            eastingMin = 9999999;
            eastingMax = -9999999;
            northingMin = 9999999;
            northingMax = -9999999;

            int cnt = ct.ptList.Count;

            if (cnt > 0)
            {
                for (int i = 0; i < cnt; i++)
                {
                    //double x = i;
                    double y = ct.ptList[i].easting;
                    double z = ct.ptList[i].northing;

                    //find min max coordonates
                    if (eastingMin > y) eastingMin = y;
                    if (eastingMax < y) eastingMax = y;
                    if (northingMin > z) northingMin = z;
                    if (northingMax < z) northingMax = z;
                }
            }

            if (eastingMax == -9999999 | eastingMin == 9999999 | northingMax == -9999999 | northingMin == 9999999)
            {
                eastingMin = 0; eastingMax = 0; northingMax = 0; northingMin = 0;
            }
            else
            {
                eastingMin -= 2; eastingMax += 2; northingMax += 2; northingMin -= 2;
            }

            for (double h = (double)eastingMin; h < (double)eastingMax; h++)
            {
                for (double i = (double)northingMin; i < (double)northingMax; i++)
                {

                    int ptCnt = ct.ptList.Count;

                    if (ptCnt > 0)
                    {
                        int closestPointMap = 0;
                        int ptCount = ct.ptList.Count - 1;

                        //find the closest point to current fix
                        for (int t = 0; t < ptCount; t++)
                        {
                            minDistMap = 100000000;
                            double distMap = ((h - ct.ptList[t].easting) * (h - ct.ptList[t].easting))
                                            + ((i - ct.ptList[t].northing) * (i - ct.ptList[t].northing));
                            if (distMap < minDistMap)
                            {
                                minDistMap = distMap;
                                closestPointMap = t;
                            }
                        }

                        if (minDistMap < 25)
                        {

                            mapListPt point = new mapListPt(h, i, ct.ptList[closestPointMap].altitude, ct.ptList[closestPointMap].cutAltitude, ct.ptList[closestPointMap].lastPassAltitude);
                            ct.mapList.Add(point);

                        }

                        int closestPointMap2 = 0;
                        int ptCount2 = ct.ptList.Count - 1;

                        //find the closest point to current fix
                        for (int t = 0; t < ptCount2; t++)
                        {
                            minDistMap2 = 100000000;
                            double distMap2 = (((h + 1) - ct.ptList[t].easting) * ((h + 1) - ct.ptList[t].easting))
                                            + ((i - ct.ptList[t].northing) * (i - ct.ptList[t].northing));
                            if (distMap2 < minDistMap2) { minDistMap2 = distMap2; closestPointMap2 = t; }
                        }

                        if (minDistMap2 < 25)
                        {

                            mapListPt point2 = new mapListPt((h + 1), i, ct.ptList[closestPointMap2].altitude, ct.ptList[closestPointMap2].cutAltitude, ct.ptList[closestPointMap2].lastPassAltitude);
                            ct.mapList.Add(point2);

                        }
                    }
                }
            }
            FileSaveMapPt();

        }

then in CContour I modified DrawContourLine line 401
It draw with OpenGL.GL_QUAD_STRIP


 //dot test by Pat
            lastMapValue = -9999999;
            sndLastMapValue = -9999999;

            for (int h = 0; h < ptCount; h++)
            {

                if (mapList[h].altitudeMap < 100) gl.Color(0.5f, 0.900f, 0.90f);
                else gl.Color(0.98f, 0.2f, 0.0f);  
                
                if (mapList[h].northingMap < lastMapValue )
                {
                    gl.End();
                    gl.Begin(OpenGL.GL_QUAD_STRIP);
                    gl.Vertex(mapList[h].eastingMap, mapList[h].northingMap, 0);
                }
                else gl.Vertex(mapList[h].eastingMap, mapList[h].northingMap, 0);

                sndLastMapValue = lastMapValue;
                lastMapValue = mapList[h].northingMap;
            }
            gl.End();

If someone can take a look and make it work for the closestPoint thing it would be appreciated.

Code here:https://github.com/Pat-I/OpenGrade3D

Edit: I have modified the code, now with GL_QUADS and much less points. I still must find out why that closestpoint don’t work , after we will be able to colour it according the cut fill value.
Edit2: Bug Found, see post below.

1 Like