Skip to content

Commit 8b146be

Browse files
committed
fix randomization issue
1 parent c840611 commit 8b146be

File tree

3 files changed

+44
-61
lines changed

3 files changed

+44
-61
lines changed

MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace PointCloudConverter
2929
{
3030
public partial class MainWindow : Window
3131
{
32-
static readonly string version = "29.03.2025";
32+
static readonly string version = "02.04.2025";
3333
static readonly string appname = "PointCloud Converter - " + version;
3434
static readonly string rootFolder = AppDomain.CurrentDomain.BaseDirectory;
3535

Tools/Tools.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using PointCloudConverter.Structs;
22
using SharpNeatLib.Maths;
3+
using System.Collections;
34
using System.Globalization;
45
using System.IO;
56
using System.Numerics;
@@ -139,6 +140,32 @@ public static Vector2 SuperUnpacker(float f, float GridSizeAndPackMagic)
139140
// return (ax * bx + ay * by + az * bz);
140141
//}
141142

143+
public static void ShuffleInPlace(params IList[] arrays)
144+
{
145+
//ResetRandom();
146+
147+
// Assume all lists are the same length
148+
if (arrays.Length == 0 || arrays[0] == null)
149+
return;
150+
151+
int count = arrays[0].Count;
152+
153+
for (int i = count - 1; i > 0; i--)
154+
{
155+
int rand = frnd.Next(0, i + 1);
156+
157+
foreach (var list in arrays)
158+
{
159+
if (list == null || list.Count <= i || list.Count <= rand)
160+
continue;
161+
162+
object temp = list[i];
163+
list[i] = list[rand];
164+
list[rand] = temp;
165+
}
166+
}
167+
}
168+
142169

143170
public static void Shuffle(ref List<float> array)
144171
{
@@ -149,8 +176,8 @@ public static void Shuffle(ref List<float> array)
149176
int rand = frnd.Next(0, index--);
150177
(array[index], array[rand]) = (array[rand], array[index]);
151178
}
152-
}
153-
179+
}
180+
154181
public static void Shuffle(ref List<byte> array)
155182
{
156183
ResetRandom();

Writers/PCROOT.cs

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using PointCloudConverter.Logger;
44
using System;
5+
using System.Collections;
56
using System.Diagnostics;
67
using System.IO;
78
using System.Runtime.CompilerServices;
@@ -537,71 +538,26 @@ void IWriter.Save(int fileIndex)
537538
// randomize points in this node
538539
if (importSettings.randomize)
539540
{
540-
//ShuffleFlags flags = ShuffleFlags.None;
541-
//int rand = Tools.frnd.Next(0, index--);
541+
var listsToShuffle = new List<IList> { nodeTempX, nodeTempY, nodeTempZ };
542542

543-
Tools.Shuffle(ref nodeTempX);
544-
Tools.Shuffle(ref nodeTempY);
545-
Tools.Shuffle(ref nodeTempZ);
546-
547-
// NOTE now we shuffle all arrays, even if not all are used?
548-
if (importSettings.importRGB == true || (importSettings.importIntensity == true || importSettings.importClassification == true))
543+
if (importSettings.importRGB)
549544
{
550-
Tools.Shuffle(ref nodeTempR);
551-
Tools.Shuffle(ref nodeTempG);
552-
Tools.Shuffle(ref nodeTempB);
545+
listsToShuffle.Add(nodeTempR);
546+
listsToShuffle.Add(nodeTempG);
547+
listsToShuffle.Add(nodeTempB);
553548
}
554549

555-
if (importSettings.importIntensity == true) Tools.Shuffle(ref nodeTempIntensity);
556-
if (importSettings.importClassification == true) Tools.Shuffle(ref nodeTempClassification);
550+
if (importSettings.importIntensity)
551+
listsToShuffle.Add(nodeTempIntensity);
557552

558-
//if (importSettings.importRGB == true)
559-
//{
560-
// if (importSettings.packColors == true)
561-
// {
562-
563-
// }
564-
// else // not packed
565-
// {
566-
// //// intensity or classification are saved into rgb field if not packed
567-
// //if (importSettings.importIntensity || importSettings.importClassification)
568-
// //{
569-
// // Tools.Shuffle(ref nodeTempR);
570-
// // Tools.Shuffle(ref nodeTempG);
571-
// // Tools.Shuffle(ref nodeTempB);
572-
// //}
573-
574-
// // if separate intensity
575-
// if (importSettings.importIntensity)
576-
// {
577-
// Tools.Shuffle(ref nodeTempIntensity);
578-
// }
579-
580-
// // if separate classification
581-
// if (importSettings.importClassification)
582-
// {
583-
// Tools.Shuffle(ref nodeTempClassification);
584-
// }
585-
// }
586-
//}
587-
//else // no rgb
588-
//{
589-
// if (importSettings.importIntensity)
590-
// {
591-
// Tools.Shuffle(ref nodeTempIntensity);
592-
// }
593-
594-
// // if separate classification
595-
// if (importSettings.importClassification)
596-
// {
597-
// Tools.Shuffle(ref nodeTempClassification);
598-
// }
599-
//}
553+
if (importSettings.importClassification)
554+
listsToShuffle.Add(nodeTempClassification);
600555

601556
if (importSettings.averageTimestamp)
602-
{
603-
Tools.Shuffle(ref nodeTempTime);
604-
}
557+
listsToShuffle.Add(nodeTempTime);
558+
559+
Tools.ShuffleInPlace(listsToShuffle.ToArray());
560+
605561
}
606562

607563

0 commit comments

Comments
 (0)