// gets called when PointWasSelected event fires in viewer void PointSelected(Vector3 pos) { // editor debug line only PointCloudMath.DebugHighLightPointGreen(pos); // was this the first selection if (isFirstPoint == true) { startPos = pos; if (distanceUIText != null) { distanceUIText.text = "Measure: Select 2nd point"; } haveFirstPoint = true; haveSecondPoint = false; } else { // it was 2nd click endPos = pos; haveSecondPoint = true; var distance = Vector3.Distance(previousPoint, pos); if (distanceUIText != null) { distanceUIText.text = "Distance:" + distance.ToString(); } } Debug.Log("(v3) Picked point at :" + pos); previousPoint = pos; isFirstPoint = !isFirstPoint; // flip boolean }
void IWriter.Randomize() { writerPoints.Flush(); bsPoints.Flush(); writerPoints.Close(); bsPoints.Dispose(); Debug.Log("Randomizing " + pointCount + " points..."); // randomize points and colors byte[] tempBytes = null; using (FileStream fs = File.Open(pointsTempFile, FileMode.Open, FileAccess.Read, FileShare.None)) using (BufferedStream bs = new BufferedStream(fs)) using (BinaryReader binaryReader = new BinaryReader(bs)) { tempBytes = binaryReader.ReadBytes(pointCount * 4 * 3); } float[] tempFloats = new float[pointCount * 3]; // convert to float array GCHandle vectorPointer = GCHandle.Alloc(tempFloats, GCHandleType.Pinned); IntPtr pV = vectorPointer.AddrOfPinnedObject(); Marshal.Copy(tempBytes, 0, pV, pointCount * 4 * 3); vectorPointer.Free(); PointCloudMath.ShuffleXYZ(PointCloudMath.rnd, ref tempFloats); PointCloudMath.ResetRandom(); // create new file on top, NOTE seek didnt work? bsPoints = new BufferedStream(new FileStream(pointsTempFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)); writerPoints = new BinaryWriter(bsPoints); // TODO why not use writeallbytes? for (int i = 0; i < pointCount * 3; i++) { writerPoints.Write(tempFloats[i]); } // new files for colors writerColorsV2.Flush(); bsColorsV2.Flush(); writerColorsV2.Close(); bsColorsV2.Dispose(); Debug.Log("Randomizing " + pointCount + " colors..."); tempBytes = null; using (FileStream fs = File.Open(colorsTempFile, FileMode.Open, FileAccess.Read, FileShare.None)) using (BufferedStream bs = new BufferedStream(fs)) using (BinaryReader binaryReader = new BinaryReader(bs)) { tempBytes = binaryReader.ReadBytes(pointCount * 4 * 3); } tempFloats = new float[pointCount * 3]; // convert to float array, TODO no need if can output writeallbytes vectorPointer = GCHandle.Alloc(tempFloats, GCHandleType.Pinned); pV = vectorPointer.AddrOfPinnedObject(); Marshal.Copy(tempBytes, 0, pV, pointCount * 4 * 3); vectorPointer.Free(); // actual point randomization //Tools.ShuffleXYZ(Tools.rnd, ref tempFloats); PointCloudMath.ShuffleXYZ(PointCloudMath.rnd, ref tempFloats); // create new file on top, seek didnt work? bsColorsV2 = new BufferedStream(new FileStream(colorsTempFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)); writerColorsV2 = new BinaryWriter(bsColorsV2); // TODO why not use writeallbytes? check 2gb file limit then use that for (int i = 0; i < pointCount * 3; i++) { writerColorsV2.Write(tempFloats[i]); } }