Skip to content

Commit a3b11b8

Browse files
committed
fix int packed bounds for batch #BUILD
1 parent 4dcfe9d commit a3b11b8

File tree

2 files changed

+66
-19
lines changed

2 files changed

+66
-19
lines changed

MainWindow.xaml.cs

+58-19
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ private static void ProcessAllFiles(System.Object importSettingsObject)
139139
Stopwatch stopwatch = new Stopwatch();
140140
stopwatch.Start();
141141

142-
143142
// if user has set maxFiles param, loop only that many files
144143
importSettings.maxFiles = importSettings.maxFiles > 0 ? importSettings.maxFiles : importSettings.inputFiles.Count;
145144
importSettings.maxFiles = Math.Min(importSettings.maxFiles, importSettings.inputFiles.Count);
@@ -150,14 +149,50 @@ private static void ProcessAllFiles(System.Object importSettingsObject)
150149
progressFile = 0;
151150
progressTotalFiles = importSettings.maxFiles - 1;
152151
if (progressTotalFiles < 0) progressTotalFiles = 0;
152+
153+
List<Float3> boundsListTemp = new List<Float3>();
154+
155+
// get all file bounds, if in batch mode and RGB+INT+PACK
156+
// TODO: check what happens if its too high? over 128/256?
157+
if (importSettings.useAutoOffset == true && importSettings.importIntensity == true && importSettings.importRGB == true && importSettings.packColors == true)
158+
{
159+
for (int i = 0, len = importSettings.maxFiles; i < len; i++)
160+
{
161+
progressFile = i;
162+
Log.WriteLine("\nReading bounds from file (" + (i + 1) + "/" + len + ") : " + importSettings.inputFiles[i] + " (" + Tools.HumanReadableFileSize(new FileInfo(importSettings.inputFiles[i]).Length) + ")");
163+
var res = GetBounds(importSettings, i);
164+
165+
if (res.Item1 == true)
166+
{
167+
boundsListTemp.Add(new Float3(res.Item2, res.Item3, res.Item4));
168+
}
169+
}
170+
171+
// print lowest bounds from boundsListTemp
172+
float lowestX = float.MaxValue;
173+
float lowestY = float.MaxValue;
174+
float lowestZ = float.MaxValue;
175+
for (int iii = 0; iii < boundsListTemp.Count; iii++)
176+
{
177+
if (boundsListTemp[iii].x < lowestX) lowestX = (float)boundsListTemp[iii].x;
178+
if (boundsListTemp[iii].y < lowestY) lowestY = (float)boundsListTemp[iii].y;
179+
if (boundsListTemp[iii].z < lowestZ) lowestZ = (float)boundsListTemp[iii].z;
180+
}
181+
182+
//Console.WriteLine("Lowest bounds: " + lowestX + " " + lowestY + " " + lowestZ);
183+
// TODO could take center for XZ, and lowest for Y
184+
importSettings.offsetX = lowestX + 0.1f;
185+
importSettings.offsetY = lowestY + 0.1f;
186+
importSettings.offsetZ = lowestZ + 0.1f;
187+
}
188+
189+
progressFile = 0;
153190
for (int i = 0, len = importSettings.maxFiles; i < len; i++)
154191
{
155192
progressFile = i;
156193
Log.WriteLine("\nReading file (" + (i + 1) + "/" + len + ") : " + importSettings.inputFiles[i] + " (" + Tools.HumanReadableFileSize(new FileInfo(importSettings.inputFiles[i]).Length) + ")");
157194
//Debug.WriteLine("\nReading file (" + (i + 1) + "/" + len + ") : " + importSettings.inputFiles[i] + " (" + Tools.HumanReadableFileSize(new FileInfo(importSettings.inputFiles[i]).Length) + ")");
158-
159195
//if (abort==true)
160-
161196
// do actual point cloud parsing for this file
162197
ParseFile(importSettings, i);
163198
}
@@ -222,6 +257,22 @@ static void ProgressTick(object sender, EventArgs e)
222257
}
223258
}
224259

260+
static (bool, float, float, float) GetBounds(ImportSettings importSettings, int fileIndex)
261+
{
262+
var res = importSettings.reader.InitReader(importSettings, fileIndex);
263+
if (res == false)
264+
{
265+
Log.WriteLine("Unknown error while initializing reader: " + importSettings.inputFiles[fileIndex]);
266+
return (false, 0, 0, 0);
267+
}
268+
var bounds = importSettings.reader.GetBounds();
269+
//Console.WriteLine(bounds.minX + " " + bounds.minY + " " + bounds.minZ);
270+
271+
importSettings.reader.Close();
272+
273+
return (true, bounds.minX, bounds.minY, bounds.minZ);
274+
}
275+
225276
// process single file
226277
static void ParseFile(ImportSettings importSettings, int fileIndex)
227278
{
@@ -260,24 +311,12 @@ static void ParseFile(ImportSettings importSettings, int fileIndex)
260311
Log.WriteLine("Points: " + pointCount);
261312
}
262313

263-
// NOTE only works with formats that have bounds defined in header, otherwise need to loop whole file to get bounds
264-
var bounds = importSettings.reader.GetBounds();
314+
// NOTE only works with formats that have bounds defined in header, otherwise need to loop whole file to get bounds?
265315

266-
if (importSettings.useAutoOffset == true)
316+
// dont use these bounds, in this case
317+
if (importSettings.useAutoOffset == true && importSettings.importIntensity == true && importSettings.importRGB == true && importSettings.packColors == true)
267318
{
268-
// get offset only from the first file, other files use same offset
269-
if (fileIndex == 0)
270-
{
271-
// offset cloud to be near 0,0,0
272-
importSettings.offsetX = bounds.minX;
273-
importSettings.offsetY = bounds.minY;
274-
//importSettings.offsetZ = bounds.minZ;
275-
}
276-
// NOW smallest Y offset and largest X,Z is used (to fix INT packing negative value issue) TODO this can create more tile than old, so need to check if this is ok
277-
if (bounds.minZ < importSettings.offsetZ)
278-
{
279-
importSettings.offsetZ = bounds.minZ;
280-
}
319+
// we use global bounds or Y offset to fix negative Y
281320
}
282321
else if (importSettings.useManualOffset == true)
283322
{

Structs/Float3.cs

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ public struct Float3
88

99
public bool hasError;
1010

11+
public Float3(float x, float y, float z)
12+
{
13+
this.x = x;
14+
this.y = y;
15+
this.z = z;
16+
hasError = false;
17+
}
18+
1119
public override string ToString()
1220
{
1321
return $"{x}, {y}, {z} " + (hasError ? " (Error = True)" : "");

0 commit comments

Comments
 (0)