示例#1
0
        /// <summary>
        /// Check if the data point is of extreme values. For example if the data point is furthest away in a direction.
        /// </summary>
        /// <param name="filename">Data point</param>
        void CheckIfEdgeStar(LabeledPlanet planet)
        {
            if (firstStar)
            {
                farAwayNegX = planet.Position.x;
                farAwayPosX = planet.Position.x;
                farAwayNegY = planet.Position.y;
                farAwayPosY = planet.Position.y;
                farAwayNegZ = planet.Position.z;
                farAwayPosZ = planet.Position.z;
                firstStar   = false;
            }
            if (planet.age > oldestPlanet)
            {
                oldestPlanet = planet.age;
            }
            else if (planet.age < youngestPlanet)
            {
                youngestPlanet = planet.age;
            }


            if (planet.Position.x < farAwayNegX)
            {
                farAwayNegX = planet.Position.x;
            }
            if (planet.Position.x > farAwayPosX)
            {
                farAwayPosX = planet.Position.x;
            }
            if (planet.Position.y < farAwayNegY)
            {
                farAwayNegY = planet.Position.y;
            }
            if (planet.Position.y > farAwayPosY)
            {
                farAwayPosY = planet.Position.y;
            }
            if (planet.Position.z < farAwayNegZ)
            {
                farAwayNegZ = planet.Position.z;
            }
            if (planet.Position.z > farAwayPosZ)
            {
                farAwayPosZ = planet.Position.z;
            }
        }
示例#2
0
        //HG

        // Start Coroutine of reading the points and parameters from text file and creating meshes
        IEnumerator loadData_Galaxy(string dPath)
        {
            // Load data from text file (no headers, line 1 is data with whitespaces)
            StreamReader sr = new StreamReader(Application.dataPath + "/" + dPath);

            string[] buffer;
            string   line;
            int      numLines;

            line   = sr.ReadLine();
            buffer = line.Split(null);

            //HG: An unaccurate line counter (is bigger):
            numLines = (int)((sr.BaseStream.Length) / sr.ReadLine().Length);

            //HG: An unaccurate but slower counter:
            if (countLines)
            {
                numLines = 0;
                while (!sr.EndOfStream)
                {
                    line      = sr.ReadLine();
                    numLines += 1;
                }
                numPoints = numLines;
                // ALTERNATIVE II:
                // Reload data
                //sr = new StreamReader(Application.dataPath + "/" + dPath);
                //string[] allLines = sr.ReadToEnd().Split();
                //numLines = allLines.Length;

                //TESTING:
                // Reload data
                //sr = new StreamReader(Application.dataPath + "/" + dPath);
                //Regex regex = new Regex(@"\s");  //HG doesnt work as expected
                //buffer = regex.Split(sr.ReadLine().Trim()); //using regular expression

                // Reload data
                sr = new StreamReader(Application.dataPath + "/" + dPath);
            }
            // HG: 'off' files contains file length in line2 buffer[0]
            //sr.ReadLine(); // 1st line contains 'off'
            //buffer = sr.ReadLine().Split(); //null, nPoints, nFaces
            //numPoints = int.Parse(buffer[0]);

            points   = new Vector3[numLines];
            colors   = new Color[numLines];
            ages     = new float[numLines];
            minValue = new Vector3();

            float age_light;
            float age_col;
            int   i = 0;

            accumulatedPlanetAge = 0;
            averageAge           = 0;
            youngestPlanet       = float.MaxValue;
            oldestPlanet         = 0;

            //for (int i = 0; i < numLines; i++)
            bool   readingDone;
            string flag = "";

            while (!sr.EndOfStream && i < numLines)
            {
                try {
                    flag = "point";
                    if (!invertYZ)
                    {
                        points[i] = new Vector3(float.Parse(buffer[2]) * scale - offSet, float.Parse(buffer[4]) * scale - offSet, float.Parse(buffer[6]) * scale - offSet);
                    }
                    else
                    {
                        points[i] = new Vector3(float.Parse(buffer[2]) * scale - offSet, float.Parse(buffer[6]) * scale - offSet, float.Parse(buffer[4]) * scale - offSet);
                    }

                    colors[i] = new Color(55.0f, 0f, 0f);
                    if (buffer.Length >= 6 && i < 681536) //HG: Chrashing after !
                    {
                        flag = "age";
                        // ages[i] = 1.1f; // > 100k
                        ages[i]   = float.Parse(buffer[8]);
                        age_light = ages[i] / 50000000000.0f;  // Red if > 50 mio year of age
                        if (age_light < 1.0f)
                        {
                            age_light = age_light * 255.0f;
                        }
                        else
                        {
                            age_light = 255.0f;
                        }
                        colors[i] = new Color(255.0f, age_light, age_light);
                    }
                } catch (IOException) {
                    readingDone = false;
                    Debug.Log("Reading data interrupted at line " + i.ToString() + " at " + flag);
                }
                numPoints = numLines;


                // Relocate Points near the origin
                //calculateMin(points[i]);

                // GUI progress:
                progress = i * 1.0f / (numLines - 1) * 1.0f;
                if (i % Mathf.FloorToInt(numLines / 20) == 0)
                {
                    guiText = i.ToString() + " out of " + numLines.ToString() + " loaded!!";
                    yield return(null);
                }


                //HG always all! if (i < 50000)
                {
                    //HG02.. build planetData list here
                    //RTClient.cs:             List<Q3D> markerData = packet.Get3DMarkerData();
                    LabeledPlanet p = new LabeledPlanet();
                    p.Label = i.ToString();

                    pointRGB   = new Color(r, g, b);
                    pointRGB.a = 0.3f;
                    p.Color    = pointRGB; // transred; //dataColor;

                    p.Color = transblue;   //HG colors[i];
                    //p.Color.a = planetTransparency;
                    p.Position = points[i];
                    p.age      = ages[i];
                    //LabeledPlanet p = new LabeledPlanet();
                    //p.Id = 0;
                    //p.Residual = -1;
                    //p.Position = BitConvert.GetPoint(mData, ref position);

                    //body..planetData.Add(p);
                    planetData.Add(p);
                    //..HG02
                    CheckIfEdgeStar(p);

                    checkIfYoungestOldest(p.age);
                    accumulatedPlanetAge += p.age;
                }

                buffer = sr.ReadLine().Split(null);
                i     += 1;
            }

            //Vector3 pos = Vector3.Lerp(new Vector3(farAwayPosX, farAwayPosY, farAwayPosZ), new Vector3(farAwayNegX, farAwayNegY, farAwayNegZ), 0.5f);
            //GetComponent<BoxCollider>().center = pos; //TODO Test for now
            //GetComponent<BoxCollider>().size = new Vector3(sizeX, sizeY, sizeZ); //TODO Test for now

            readingDone = true;
            numLines    = i; //HG: to be sure numlines is right for the following

            // Instantiate Point Groups
            numPointGroups = Mathf.CeilToInt(numLines * 1.0f / limitPoints * 1.0f);

            if (currentGalaxy)
            {
                currentDatasets.Remove(currentGalaxy);
                Destroy(currentGalaxy);
            }


            averageAge = accumulatedPlanetAge / planetData.Count;
            pointCloud = CreateGalaxyGameObject(filename);
            spaceManager.GetComponent <PlayerParts>().dataPoints = pointCloud;
            currentGalaxy = pointCloud;
            currentDatasets.Add(currentGalaxy);


            PlayerPrefs.SetFloat("farAwayPosX", farAwayPosX);
            PlayerPrefs.SetFloat("farAwayNegX", farAwayNegX);
            PlayerPrefs.SetFloat("farAwayPosY", farAwayPosY);
            PlayerPrefs.SetFloat("farAwayNegY", farAwayNegY);
            PlayerPrefs.SetFloat("farAwayPosZ", farAwayPosZ);
            PlayerPrefs.SetFloat("farAwayNegZ", farAwayNegZ);
            PlayerPrefs.SetFloat("minAge", youngestPlanet);
            PlayerPrefs.SetFloat("maxAge", oldestPlanet);
            PlayerPrefs.SetFloat("avgAge", averageAge);

            for (i = 0; i < numPointGroups - 1; i++)
            {
                InstantiateMesh(i, limitPoints);
                if (i % 10 == 0)
                {
                    guiText = i.ToString() + " out of " + numPointGroups.ToString() + " PointGroups loaded";
                    yield return(null);
                }
            }
            InstantiateMesh(numPointGroups - 1, numLines - (numPointGroups - 1) * limitPoints);

            pointCloud.transform.rotation = Quaternion.Euler(90f, 0f, 0f);
            //Store PointCloud
#if UNITY_EDITOR
            UnityEditor.PrefabUtility.CreatePrefab("Assets/Resources/PointCloudMeshes/" + filename + ".prefab", pointCloud);
#endif
            UpdateScreenData();

            loaded          = true;
            selectedPlanets = planetData;
        }
示例#3
0
        IEnumerator ReadDataFromFile(string dPath)
        {
            StreamReader sr = new StreamReader(Application.dataPath + "/" + dPath);

            string[] buffer;
            string   line;
            int      numLines;

            line   = sr.ReadLine();
            buffer = line.Split(null);

            //HG: An unaccurate line counter (is bigger):
            numLines = (int)((sr.BaseStream.Length) / sr.ReadLine().Length);

            //HG: An unaccurate but slower counter:
            if (countLines)
            {
                numLines = 0;
                while (!sr.EndOfStream)
                {
                    line      = sr.ReadLine();
                    numLines += 1;
                }
                numPoints = numLines;
                // ALTERNATIVE II:
                // Reload data
                //sr = new StreamReader(Application.dataPath + "/" + dPath);
                //string[] allLines = sr.ReadToEnd().Split();
                //numLines = allLines.Length;

                //TESTING:
                // Reload data
                //sr = new StreamReader(Application.dataPath + "/" + dPath);
                //Regex regex = new Regex(@"\s");  //HG doesnt work as expected
                //buffer = regex.Split(sr.ReadLine().Trim()); //using regular expression

                // Reload data
                sr = new StreamReader(Application.dataPath + "/" + dPath);
            }
            // HG: 'off' files contains file length in line2 buffer[0]
            //sr.ReadLine(); // 1st line contains 'off'
            //buffer = sr.ReadLine().Split(); //null, nPoints, nFaces
            //numPoints = int.Parse(buffer[0]);

            points   = new Vector3[numLines];
            colors   = new Color[numLines];
            ages     = new float[numLines];
            minValue = new Vector3();

            float age_light;
            float age_col;
            int   i = 0;

            accumulatedPlanetAge = 0;
            averageAge           = 0;
            youngestPlanet       = float.MaxValue;
            oldestPlanet         = 0;

            //for (int i = 0; i < numLines; i++)
            bool   readingDone;
            string flag = "";

            while (!sr.EndOfStream && i < numLines)
            {
                try {
                    flag = "point";
                    if (!invertYZ)
                    {
                        points[i] = new Vector3(float.Parse(buffer[2]) * scale - offSet, float.Parse(buffer[4]) * scale - offSet, float.Parse(buffer[6]) * scale - offSet);
                    }
                    else
                    {
                        points[i] = new Vector3(float.Parse(buffer[2]) * scale - offSet, float.Parse(buffer[6]) * scale - offSet, float.Parse(buffer[4]) * scale - offSet);
                    }

                    colors[i] = new Color(55.0f, 0f, 0f);
                    if (buffer.Length >= 6 && i < 681536) //HG: Chrashing after !
                    {
                        flag = "age";
                        // ages[i] = 1.1f; // > 100k
                        ages[i]   = float.Parse(buffer[8]);
                        age_light = ages[i] / 50000000000.0f;  // Red if > 50 mio year of age
                        if (age_light < 1.0f)
                        {
                            age_light = age_light * 255.0f;
                        }
                        else
                        {
                            age_light = 255.0f;
                        }
                        colors[i] = new Color(255.0f, age_light, age_light);
                    }
                } catch (IOException) {
                    readingDone = false;
                    Debug.Log("Reading data interrupted at line " + i.ToString() + " at " + flag);
                }
                numPoints = numLines;


                // Relocate Points near the origin
                //calculateMin(points[i]);

                // GUI progress:
                progress = i * 1.0f / (numLines - 1) * 1.0f;
                if (i % Mathf.FloorToInt(numLines / 20) == 0)
                {
                    guiText = i.ToString() + " out of " + numLines.ToString() + " loaded!!";
                    yield return(null);
                }


                //HG always all! if (i < 50000)
                {
                    //HG02.. build planetData list here
                    //RTClient.cs:             List<Q3D> markerData = packet.Get3DMarkerData();
                    LabeledPlanet p = new LabeledPlanet();
                    p.Label = i.ToString();

                    pointRGB   = new Color(r, g, b);
                    pointRGB.a = 0.3f;
                    p.Color    = pointRGB; // transred; //dataColor;

                    p.Color = transblue;   //HG colors[i];
                    //p.Color.a = planetTransparency;
                    p.Position = points[i];
                    p.age      = ages[i];
                    //LabeledPlanet p = new LabeledPlanet();
                    //p.Id = 0;
                    //p.Residual = -1;
                    //p.Position = BitConvert.GetPoint(mData, ref position);

                    //body..planetData.Add(p);
                    planetData.Add(p);
                    //..HG02
                    CheckIfEdgeStar(p);

                    checkIfYoungestOldest(p.age);
                    accumulatedPlanetAge += p.age;
                }

                buffer = sr.ReadLine().Split(null);
                i     += 1;
            }
            selectedPlanets = planetData;
            Debug.Log("selectedPlanetsCount: " + selectedPlanets.Count);
        }