From d337654ea9058a427baa6cf158d56fedfb163c7b Mon Sep 17 00:00:00 2001 From: "DESKTOP-5EVOSD4\\olive" Date: Mon, 14 Jan 2019 22:23:06 +0000 Subject: [PATCH 1/5] Update PointCloudManager to visualise points by height and intensity gradient --- Scripts/PointCloudManager.cs | 144 ++++++++++++++++++++++++----------- 1 file changed, 99 insertions(+), 45 deletions(-) diff --git a/Scripts/PointCloudManager.cs b/Scripts/PointCloudManager.cs index 6731650..fd1a312 100644 --- a/Scripts/PointCloudManager.cs +++ b/Scripts/PointCloudManager.cs @@ -1,24 +1,34 @@ -using UnityEngine; +// Original project by Gerard Llorach (2014) +// Updated by Oliver Dawkins and Dominic Zisch (2017) to visualise points using height and intensity gradients + +using UnityEngine; using System.Collections; using System.IO; -public class PointCloudManager : MonoBehaviour { +public class PointCloudHeightAndIntensity : MonoBehaviour { - // File + // File location public string dataPath; private string filename; public Material matVertex; - // GUI - private float progress = 0; + // Methods to colour points + public enum cpb {Default, RGB, Height, Intensity}; + public cpb colourPointsBy = cpb.RGB; + public Color defaultPointColour; + public Gradient colourGradient; + + // Processing GUI + private float progress = 0; private string guiText; private bool loaded = false; - // PointCloud + // Point cloud properties private GameObject pointCloud; public float scale = 1; - public bool invertYZ = false; + public bool relocateToOrigin = false; + public bool invertYZ = false; public bool forceReload = false; public int numPoints; @@ -29,19 +39,35 @@ public class PointCloudManager : MonoBehaviour { private Color[] colors; private Vector3 minValue; - - void Start () { - // Create Resources folder - createFolders (); + // Point height properties + public float minHeight; + public float maxHeight; + private float heightDiff; + private float localDiff; + + // Point intensity properties + public float minIntensity; + public float maxIntensity; + private float intensityDiff; + private float relativeDiff; + + void Start () { + + //Calculate height difference for the visualising height gradient + heightDiff = maxHeight - minHeight; + + //Calculate intensity difference for visualising intensity gradient + intensityDiff = maxIntensity - minIntensity; + + // Create Resources folder + createFolders(); // Get Filename filename = Path.GetFileName(dataPath); - loadScene (); + loadScene(); } - - void loadScene(){ // Check if the PointCloud was loaded previously if(!Directory.Exists (Application.dataPath + "/Resources/PointCloudMeshes/" + filename)){ @@ -55,14 +81,13 @@ void loadScene(){ } else // Load stored PointCloud loadStoredMeshes(); - } - - + } + void loadPointCloud(){ // Check what file exists - if (File.Exists (Application.dataPath + dataPath + ".off")) - // load off - StartCoroutine ("loadOFF", dataPath + ".off"); + if (File.Exists (Application.dataPath + dataPath + ".xyz")) + // Load XYZ + StartCoroutine ("loadXYZ", dataPath + ".xyz"); else Debug.Log ("File '" + dataPath + "' could not be found"); @@ -78,44 +103,76 @@ void loadStoredMeshes(){ loaded = true; } - // Start Coroutine of reading the points from the OFF file and creating the meshes - IEnumerator loadOFF(string dPath){ + // Start Coroutine of reading the points from the XYZ file and creating the meshes + IEnumerator loadXYZ(string dPath){ // Read file + numPoints = File.ReadAllLines (Application.dataPath + dPath).Length; + StreamReader sr = new StreamReader (Application.dataPath + dPath); - sr.ReadLine (); // OFF - string[] buffer = sr.ReadLine ().Split(); // nPoints, nFaces - - numPoints = int.Parse (buffer[0]); + points = new Vector3[numPoints]; colors = new Color[numPoints]; minValue = new Vector3(); for (int i = 0; i< numPoints; i++){ - buffer = sr.ReadLine ().Split (); + string[] buffer = sr.ReadLine ().Split (); if (!invertYZ) - points[i] = new Vector3 (float.Parse (buffer[0])*scale, float.Parse (buffer[1])*scale,float.Parse (buffer[2])*scale) ; - else - points[i] = new Vector3 (float.Parse (buffer[0])*scale, float.Parse (buffer[2])*scale,float.Parse (buffer[1])*scale) ; - - if (buffer.Length >= 5) - colors[i] = new Color (int.Parse (buffer[3])/255.0f,int.Parse (buffer[4])/255.0f,int.Parse (buffer[5])/255.0f); + points[i] = new Vector3 (float.Parse (buffer[0])*scale, float.Parse (buffer[1])*scale,float.Parse (buffer[2])*scale); else - colors[i] = Color.cyan; - - // Relocate Points near the origin - //calculateMin(points[i]); - - // GUI - progress = i *1.0f/(numPoints-1)*1.0f; - if (i%Mathf.FloorToInt(numPoints/20) == 0){ + points[i] = new Vector3 (float.Parse (buffer[0])*scale, float.Parse (buffer[2])*scale,float.Parse (buffer[1])*scale); + + // Test enum for technique to colour points + // Apply default point colour + if (colourPointsBy == cpb.Default) + { + colors[i] = defaultPointColour; + } + + // Colour points by RGB values + if (colourPointsBy == cpb.RGB) + { + if (buffer.Length >= 5) + colors[i] = new Color(int.Parse(buffer[3]) / 255.0f, int.Parse(buffer[4]) / 255.0f, int.Parse(buffer[5]) / 255.0f); + else + colors[i] = defaultPointColour; + } + + // TO DO - Automate calculation of minHeight and maxHeight + // Colour points by Height + else if (colourPointsBy == cpb.Height) + { + if (!invertYZ) + localDiff = float.Parse(buffer[1]) - minHeight; + else + localDiff = float.Parse(buffer[2]) - minHeight; + colors[i] = colourGradient.Evaluate(localDiff / heightDiff); + } + + //TO DO - Automate calculation of minIntensity and maxIntensity + // Colour points by intensity + else if (colourPointsBy == cpb.Intensity) + { + relativeDiff = float.Parse(buffer[6]) - minIntensity; + colors[i] = colourGradient.Evaluate(relativeDiff / intensityDiff); + } + + // Relocate points near the origin + if (relocateToOrigin == true) + { + calculateMin(points[i]); + } + + // Processing GUI + progress = i *1.0f/(numPoints-1)*1.0f; + if (i%Mathf.FloorToInt(numPoints/20) == 0) + { guiText=i.ToString() + " out of " + numPoints.ToString() + " loaded"; yield return null; } } - // Instantiate Point Groups numPointGroups = Mathf.CeilToInt (numPoints*1.0f / limitPoints*1.0f); @@ -135,7 +192,6 @@ IEnumerator loadOFF(string dPath){ loaded = true; } - void InstantiateMesh(int meshInd, int nPoints){ // Create Mesh @@ -147,7 +203,6 @@ void InstantiateMesh(int meshInd, int nPoints){ pointGroup.GetComponent ().mesh = CreateMesh (meshInd, nPoints, limitPoints); pointGroup.transform.parent = pointCloud.transform; - // Store Mesh UnityEditor.AssetDatabase.CreateAsset(pointGroup.GetComponent ().mesh, "Assets/Resources/PointCloudMeshes/" + filename + @"/" + filename + meshInd + ".asset"); UnityEditor.AssetDatabase.SaveAssets (); @@ -200,7 +255,6 @@ void createFolders(){ UnityEditor.AssetDatabase.CreateFolder ("Assets/Resources", "PointCloudMeshes"); } - void OnGUI(){ From 69836f45be4675668670476348167d58084bb1c0 Mon Sep 17 00:00:00 2001 From: virtualarchitectures Date: Mon, 8 Jun 2020 19:18:14 +0100 Subject: [PATCH 2/5] Create .gitignore --- .gitignore | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8af868e --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# This .gitignore file should be placed at the root of your Unity project directory +# +# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore +# +/[Ll]ibrary/ +/[Tt]emp/ +/[Oo]bj/ +/[Bb]uild/ +/[Bb]uilds/ +/[Ll]ogs/ +/[Mm]emoryCaptures/ + +# Asset meta data should only be ignored when the corresponding asset is also ignored +!/[Aa]ssets/**/*.meta + +# Uncomment this line if you wish to ignore the asset store tools plugin +# /[Aa]ssets/AssetStoreTools* + +# Autogenerated Jetbrains Rider plugin +[Aa]ssets/Plugins/Editor/JetBrains* + +# Visual Studio cache directory +.vs/ + +# Gradle cache directory +.gradle/ + +# Autogenerated VS/MD/Consulo solution and project files +ExportedObj/ +.consulo/ +*.csproj +*.unityproj +*.sln +*.suo +*.tmp +*.user +*.userprefs +*.pidb +*.booproj +*.svd +*.pdb +*.mdb +*.opendb +*.VC.db + +# Unity3D generated meta files +*.pidb.meta +*.pdb.meta +*.mdb.meta + +# Unity3D generated file on crash reports +sysinfo.txt + +# Builds +*.apk +*.unitypackage + +# Crashlytics generated file +crashlytics-build.properties + From 61e263953f84e80a44a3d4aedd53e2b1551a7650 Mon Sep 17 00:00:00 2001 From: virtualarchitectures Date: Mon, 8 Jun 2020 20:55:28 +0100 Subject: [PATCH 3/5] Removed example scene --- Example.unity | Bin 13632 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Example.unity diff --git a/Example.unity b/Example.unity deleted file mode 100644 index 18c9911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NC6HRuihcB7zACmHyq3gA`Bv!9}r zJjDlNM=cmXFlek;_|JFf!>x>kA-$w71<|W8?-`Q@4}~N$N4(h+!=ykaDb~rPhGN3n zo3naUOCc3a-NY^WOG6>saXJt?@E!Vyt0`bJj`~6cdcW+;rf-6K;bN8!lziXC>t_3A z_wiwW(CB1oo_p5fJA0|ac3?W4VMd>Ev|_TeK0choP5-PiAP&jBB7bMl_I#1V@y+GSY zjz2===Xb+_gl)-b*Wkqyz$c`um5%L z<+aOae{}q=Ki%+vEUf2$eMj`<+fOyW^XI<=M=sy>3_}6mH(jX*!Dv1RURh9(V{~t? z(J{1q%kPdnD&@~NUwd_R-d$7|IG5-i&-J>?xZYn3!8k38E^e&2&C#*9?>m3&8+RmD z##k=uzDY`wPLH7tXHu`d`YJsGH^y2Slo!;=5EckSefLuR^y%+6Xj18#onTH-5eZX_ zsYZecz#NcZA}|#sm=H_}2_}YLtkX3UB{lo83RXFu?IR#w^2f<5;s==XEX=!A4jI3> zx;X#Ri!aXq?X9=we{$uDwGXHvWB%d`FVNUtS`31LwXG|4D*Gi&8wp5GGZcotw}1Ux z^YuG_|BL2Je}C+ayPrPx?4=(z{_uFx_}S~{e&uAzuWPXS_Xf&#^Mz%F<%NW0hu_=i z;;5w=r^Bw>gv$=@bW)gJk50oT(hSuZiDm9E`2FMF&&w9>rn?8m0w37jyOi}dF7!<@ g%=!P3P&st2-CCo+-uk5H*$Hxe#N--q>%!0fCrX2_HUIzs From a7ceeadfb90e70f5bcb281c5a44944130d13500f Mon Sep 17 00:00:00 2001 From: virtualarchitectures Date: Mon, 8 Jun 2020 20:57:11 +0100 Subject: [PATCH 4/5] Updated package for Unity 2019.2.12f1 --- Materials/VertexColor.mat | Bin 4308 -> 908 bytes Scripts/PointCloudManager.cs | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Materials/VertexColor.mat b/Materials/VertexColor.mat index 98087963c0c3a30be53df241159e86015d6d0b00..6baf1eaf40089548227a3f6752453f55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c3!~g$l-bTM^Vvtiir2Ro+;y)$pFzaW6RCUJpP%!xN{=8xhcT-dM{+lt*8W z42OI(04mkw-7*|y+Nnc6JKn0<(G>fX?QciyL7=O{VNL~!W9*$85|axfy<4-R8Af_9 zVwdvWM7~nJ?}wm5*1BE;X9)x1m^{LGma79|fs7E(F7(;zT|^g2=;995`+=Y zm{#+26RN^nBA!;b(69dfrE%%6KfYhTb>q)li)U|M!Pz#KIRkSB<_ydk_`foM55ep7 zAz=>rNhL>pdyA)o*LEEJc$w>6)=5gQu593+f}T>iM1aF*Cw(?1X_A^eM}M(`rvyHa zd*WXG{Og&E7k Date: Mon, 8 Jun 2020 21:00:19 +0100 Subject: [PATCH 5/5] Updated to exclude meta files --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8af868e..b901558 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ /[Mm]emoryCaptures/ # Asset meta data should only be ignored when the corresponding asset is also ignored -!/[Aa]ssets/**/*.meta +# !/[Aa]ssets/**/*.meta # Uncomment this line if you wish to ignore the asset store tools plugin # /[Aa]ssets/AssetStoreTools*