Пример #1
0
        /// <summary>
        /// Returns field from array (of normal step size) of the given class on the given index
        /// </summary>
        public CField GetField(EClass pClass, int pX, int pY)
        {
            switch (pClass)
            {
            case EClass.Unassigned:
                return(unassignedArray.GetField(pX, pY));

            case EClass.Ground:
                return(groundArray.GetField(pX, pY));

            case EClass.Vege:
                return(vegeArray.GetField(pX, pY));

            case EClass.Building:
                return(buildingArray.GetField(pX, pY));
            }
            CDebug.Error($"array from class {pClass} not defined");
            return(null);
        }
Пример #2
0
        public static Obj ExportToObj(string pArrayName, EExportStrategy pStrategy, bool pUseSmoothHeight,
                                      Tuple <int, int> pStartIndex, Tuple <int, int> pEndIndex)
        {
            CGroundArray pArray    = CProjectData.Points.groundArray;
            Obj          obj       = new Obj(pArrayName);
            float        minHeight = CProjectData.GetMinHeight();

            int missingCoordCount = 0;

            int xStart = pStartIndex.Item1;
            int yStart = pStartIndex.Item2;
            int xEnd   = pEndIndex.Item1 + 1;
            int yEnd   = pEndIndex.Item2 + 1;

            xEnd = Math.Min(xEnd, pArray.arrayXRange);
            yEnd = Math.Min(yEnd, pArray.arrayYRange);

            //prepare vertices
            for (int x = xStart; x < xEnd; x++)
            {
                for (int y = yStart; y < yEnd; y++)
                {
                    Vertex       v      = new Vertex();
                    CGroundField el     = pArray.GetField(x, y);
                    float?       height = el.GetHeight(pUseSmoothHeight ? CField.EHeight.Smooth : CField.EHeight.MaxZ);

                    height = GetHeight(pStrategy, y, el, height);

                    //create vertex only if height is defined
                    if (height != null)
                    {
                        //TODO: ATTENTION! in OBJ the height value = Y, while in LAS format it is Z and X,Y are space coordinates
                        //move heights so the lowest point touches the 0
                        //if (pHeight != EHeight.Tree)
                        {
                            height -= minHeight;
                        }

                        v.LoadFromStringArray(new[] { "v", pArray.GetFieldXCoord(x).ToString(),
                                                      height.ToString(), pArray.GetFieldYCoord(y).ToString() });
                        obj.AddVertex(v);
                        //record the index of vertex associated with this field position
                        el.VertexIndex = obj.VertexList.Count;                         //first index = 1 (not 0)!
                    }
                    else
                    {
                        missingCoordCount++;
                    }
                }
            }
            int faceCount = 0;

            //generate faces
            for (int x = xStart; x < xEnd - 1; x++)
            {
                for (int y = yStart; y < yEnd - 1; y++)
                {
                    //create face only if all necessary vertices has been defined. -1 = not defined
                    //| /|	3:[0,1]	2:[1,1]
                    //|/ |  1:[0,0] 4:[1,0]
                    //we create 2 faces: (1,2,3) and (1,2,4)
                    int ind1 = pArray.GetField(x, y).VertexIndex;
                    if (ind1 != -1)
                    {
                        int ind2 = pArray.GetField(x + 1, y + 1).VertexIndex;
                        if (ind2 != -1)
                        {
                            int ind3 = pArray.GetField(x, y + 1).VertexIndex;
                            if (ind3 != -1)
                            {
                                Face f = new Face();
                                f.LoadFromStringArray(new[]
                                {
                                    "f", ind1.ToString(), ind2.ToString(), ind3.ToString()                                     //ind1+"//"+ind3, ind3+"//"+ind2, ind2+"//"+ind1
                                });

                                obj.FaceList.Add(f);
                                faceCount++;
                            }
                            int ind4 = pArray.GetField(x + 1, y).VertexIndex;
                            if (ind4 != -1)
                            {
                                Face f = new Face();
                                f.LoadFromStringArray(new[]
                                {
                                    "f", ind1.ToString(), ind4.ToString(), ind2.ToString()
                                });

                                obj.FaceList.Add(f);
                            }
                        }
                    }
                }
            }

            return(obj);
        }