Esempio n. 1
0
        public new CPeak Clone()
        {
            CPeak clonePeak = new CPeak(Center, treePointExtent);

            clonePeak.Points = Points;
            foreach (Vector3 p in Points)
            {
                OnAddPoint(p);
            }
            return(clonePeak);
        }
Esempio n. 2
0
        public new static CPeak Deserialize(string pLine, float pTreePointExtent)
        {
            string[] split = pLine.Split(null);

            Vector3 _minBB = new Vector3(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]));

            Vector3 _maxBB = new Vector3(float.Parse(split[3]), float.Parse(split[4]), float.Parse(split[5]));

            CPeak peak = new CPeak((_minBB + _maxBB) / 2, pTreePointExtent);

            peak.OnAddPoint(_minBB);
            peak.OnAddPoint(_maxBB);
            return(peak);
        }
Esempio n. 3
0
        public CRefTree(string pFileName, string[] pSerializedLines)
        {
            DeserialiseMode currentMode = DeserialiseMode.None;

            fileName = pFileName;
            isValid  = true;

            branches = new List <CBranch>();
            List <CTreePoint> _treepointsOnBranch = new List <CTreePoint>();

            //if first line is not version then it is the old version and
            //the file needs to be regenerated
            if (pSerializedLines.Length == 0 || pSerializedLines[0] != KEY_VERSION)
            {
                return;
            }

            foreach (string line in pSerializedLines)
            {
                switch (line)
                {
                case KEY_VERSION:
                    currentMode = DeserialiseMode.Version;
                    continue;

                case KEY_TREE_INDEX:
                    currentMode = DeserialiseMode.TreeIndex;
                    continue;

                case KEY_TREE_POINT_EXTENT:
                    currentMode = DeserialiseMode.TreePointExtent;
                    continue;

                case KEY_PEAK:
                    currentMode = DeserialiseMode.Peak;
                    continue;

                case KEY_BRANCHES:
                    currentMode = DeserialiseMode.Branches;
                    continue;

                case KEY_STEM:
                    currentMode = DeserialiseMode.Stem;
                    branches.Last().SetTreePoints(_treepointsOnBranch);
                    _treepointsOnBranch = new List <CTreePoint>();
                    continue;

                case KEY_BOUNDING_BOX:
                    currentMode = DeserialiseMode.BoundingBox;
                    continue;
                }

                switch (currentMode)
                {
                case DeserialiseMode.Version:
                    version = line;
                    if (!IsCurrentVersion())
                    {
                        CDebug.Warning($"reftree version {version} is not up to date {CURRENT_REFTREE_VERSION}. Generating new file.");
                        return;
                    }
                    break;

                case DeserialiseMode.TreeIndex:
                    treeIndex = int.Parse(line);
                    break;

                case DeserialiseMode.TreePointExtent:
                    treePointExtent = float.Parse(line);
                    break;

                case DeserialiseMode.Peak:
                    peak = CPeak.Deserialize(line, treePointExtent);
                    stem = new CBranch(this, 0, 0);
                    break;

                case DeserialiseMode.Branches:
                    if (line.Contains(KEY_BRANCH))
                    {
                        int branchIndex = branches.Count;
                        if (branchIndex > 0)
                        {
                            branches.Last().SetTreePoints(_treepointsOnBranch);
                        }

                        branches.Add(new CBranch(
                                         this,
                                         branchIndex * BRANCH_ANGLE_STEP,
                                         branchIndex * BRANCH_ANGLE_STEP + BRANCH_ANGLE_STEP));
                        _treepointsOnBranch = new List <CTreePoint>();
                    }
                    else
                    {
                        CTreePoint treePointOnBranch = CTreePoint.Deserialize(line, treePointExtent);
                        _treepointsOnBranch.Add(treePointOnBranch);
                        Points.Add(treePointOnBranch.Center);
                    }
                    break;

                case DeserialiseMode.Stem:
                    _treepointsOnBranch.Add(CTreePoint.Deserialize(line, treePointExtent));
                    break;

                case DeserialiseMode.BoundingBox:
                    string[] split = line.Split(null);
                    minBB = new Vector3(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]));
                    maxBB = new Vector3(float.Parse(split[3]), float.Parse(split[4]), float.Parse(split[5]));
                    break;
                }
            }
            stem.SetTreePoints(_treepointsOnBranch);
            LoadObj(pFileName);
        }