Exemplo n.º 1
0
        /// <summary>
        /// Txt line for 1 point.
        /// byte = unsigned char
        /// </summary>
        private static string GetPointLine(CVector3D pPoint, int pClass, byte pUserData, string pColor)
        {
            //todo: make string method
            string output = $"{pPoint.X.ToString(NUM_FORMAT)} {pPoint.Y.ToString(NUM_FORMAT)} {pPoint.Z.ToString(NUM_FORMAT)} "; //x y z (swap Y Z)

            output += $"{pClass} {pUserData} ";                                                                                  //class, id
            output += pColor;                                                                                                    //R G B
            return(output);
        }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            CVector3D item = obj as CVector3D;

            if (item == null)
            {
                return(false);
            }
            return(item.X == X && item.Y == Y && item.Z == Z);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates point feature representing position of the tree.
        /// Attributes:
        /// id, X, Y, height, DBH, AGB, type
        /// </summary>
        private static Feature GetTreePosition(CTree pTree, ref StringBuilder pString)
        {
            CVector3D globalTreepos = CUtils.GetGlobalPosition(pTree.peak.Center);
            IPoint    myPoint       = factory.CreatePoint(new Coordinate(globalTreepos.X, globalTreepos.Y));

            AttributesTable attributesTable = new AttributesTable();

            attributesTable.Add(ATTR_ID, pTree.treeIndex);
            pString.Append(pTree.treeIndex + SEP);
            shpInfoMain.Append(pTree.treeIndex + SEP);

            attributesTable.Add(ATTR_X, globalTreepos.X.ToString(NUM_FORMAT));
            attributesTable.Add(ATTR_Y, globalTreepos.Y.ToString(NUM_FORMAT));
            pString.Append(globalTreepos.X.ToString(NUM_FORMAT) + SEP);
            shpInfoMain.Append(globalTreepos.X.ToString(NUM_FORMAT) + SEP);
            pString.Append(globalTreepos.Y.ToString(NUM_FORMAT) + SEP);
            shpInfoMain.Append(globalTreepos.Y.ToString(NUM_FORMAT) + SEP);

            float treeHeight = pTree.GetTreeHeight();

            attributesTable.Add(ATTR_HEIGHT, treeHeight.ToString(NUM_FORMAT));
            pString.Append(treeHeight.ToString(NUM_FORMAT) + SEP);
            shpInfoMain.Append(treeHeight.ToString(NUM_FORMAT) + SEP);

            if (CParameterSetter.GetBoolSettings(ESettings.calculateDBH))
            {
                double stemDiameter = CBiomassController.GetTreeStemDiameter(treeHeight);
                attributesTable.Add(ATTR_DBG, stemDiameter.ToString(NUM_FORMAT));
                pString.Append(stemDiameter.ToString(NUM_FORMAT) + SEP);
                shpInfoMain.Append(stemDiameter.ToString(NUM_FORMAT) + SEP);

                if (CParameterSetter.GetBoolSettings(ESettings.calculateAGB))
                {
                    double biomass = CBiomassController.GetTreeBiomass(stemDiameter, treeHeight);
                    attributesTable.Add(ATTR_AGB, biomass.ToString(NUM_FORMAT));
                    pString.Append(biomass.ToString(NUM_FORMAT) + SEP);
                    shpInfoMain.Append(biomass.ToString(NUM_FORMAT) + SEP);
                }
            }

            //251 - Finalizace produktu
            //attributesTable.Add(ATTR_TYPE, pTree.assignedRefTree.RefTreeTypeName);
            //pString.Append(pTree.assignedRefTree.RefTreeTypeName + SEP);

            Feature feature = new Feature(myPoint, attributesTable);

            pString.AppendLine();
            shpInfoMain.AppendLine();

            return(feature);
        }
Exemplo n.º 4
0
        /// <summary>
        /// </summary>
        private static string GetTreeLines(CTree pTree)
        {
            string output = "";

            foreach (Vector3 p in pTree.Points)
            {
                string color = pTree.isValid ?
                               pTree.assignedMaterial.ToString255() :
                               CMaterialManager.GetInvalidMaterial().ToString255();

                //int treeIndex = pTree.isValid ? pTree.assignedRefTree.treeIndex : 0;
                int treeIndex = pTree.treeIndex;

                CVector3D globalP = CUtils.GetGlobalPosition(p);
                output += GetPointLine(globalP, 5, (byte)treeIndex, color) + newLine;
            }
            return(output);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        private static Feature GetTreeBorder(CTree pTree)
        {
            List <Vector3>    furthestPoints = pTree.GetFurthestPoints();
            List <Coordinate> pointsCoords   = new List <Coordinate>();

            foreach (Vector3 p in furthestPoints)
            {
                CVector3D globalP = CUtils.GetGlobalPosition(p);
                pointsCoords.Add(new Coordinate(globalP.X, globalP.Y));
            }
            pointsCoords.Add(pointsCoords[0]);             //to close polygon

            IPolygon polygon = factory.CreatePolygon(pointsCoords.ToArray());

            //id
            AttributesTable attributesTable = new AttributesTable();

            attributesTable.Add(ATTR_ID, pTree.treeIndex);

            //position
            CVector3D globalTreepos = CUtils.GetGlobalPosition(pTree.peak.Center);

            attributesTable.Add(ATTR_X, globalTreepos.X.ToString(NUM_FORMAT));
            attributesTable.Add(ATTR_Y, globalTreepos.Y.ToString(NUM_FORMAT));

            //area
            attributesTable.Add(ATTR_AREA, pTree.GetArea());

            //tree height
            float treeHeight = pTree.GetTreeHeight();

            attributesTable.Add(ATTR_HEIGHT, treeHeight.ToString(NUM_FORMAT));

            //reftree type
            //attributesTable.Add(ATTR_TYPE, pTree.assignedRefTree.RefTreeTypeName);

            Feature feature = new Feature(polygon, attributesTable);

            return(feature);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add points from given class to the output and main output
        /// </summary>
        private static void AddPointsTo(ref StringBuilder pOutput, EClass pClass, ref DateTime start)
        {
            List <Vector3> points = CProjectData.Points.GetPoints(pClass);
            string         res;
            DateTime       lastDebug = DateTime.Now;

            for (int i = 0; i < points.Count; i++)
            {
                if (CProjectData.backgroundWorker.CancellationPending)
                {
                    return;
                }

                CDebug.Progress(i, points.Count, DEBUG_FREQUENCY, ref lastDebug, start, "Export las (ground points)");

                Vector3   p       = points[i];
                CVector3D globalP = CUtils.GetGlobalPosition(p);
                res = GetPointLine(globalP, 1, 0, GetClassColor(pClass)) + newLine;
                pOutput.Append(res);
            }
            //mainOutput.Append(pOutput);
        }
Exemplo n.º 7
0
        private void SetValues(Vector3 pScaleFactor, Vector3 pOffset, CVector3D pMin, CVector3D pMax)
        {
            ScaleFactor = pScaleFactor;
            Offset      = pOffset;
            //Offset.Z = 0; //given Z offset will not be used
            Min_orig = pMin;
            CVector3D minDouble = Min_orig - Offset;

            Min      = (Vector3)minDouble;
            Max_orig = pMax;
            CVector3D maxDouble = Max_orig - Offset;

            Max = (Vector3)maxDouble;

            if (Min == Vector3.Zero && Max == Vector3.Zero)
            {
                CDebug.Error("Invalid header. Creating default header.");
                const int defaultArraySize = 15;
                Min    = new Vector3(-defaultArraySize, -defaultArraySize, 0);
                Max    = new Vector3(defaultArraySize, defaultArraySize, 0);
                Offset = Vector3.Zero;
            }
        }
Exemplo n.º 8
0
 public static double Distance(CVector3D v1, CVector3D v2)
 {
     return(Math.Sqrt(Math.Pow(v1.X - v2.X, 2) + Math.Pow(v1.Y - v2.Y, 2) + +Math.Pow(v1.Z - v2.Z, 2)));
 }