Skip to content

Commit 2a6e0f2

Browse files
committed
fix nullref in metadata only for pcroot, gltf. Add Job metadata in json (converter version, import settings and other data), adding minmax intensity and classification data to reader
1 parent 2958b78 commit 2a6e0f2

File tree

6 files changed

+89
-34
lines changed

6 files changed

+89
-34
lines changed

MainWindow.xaml.cs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
using System.Reflection;
2525
using System.Globalization;
2626
using System.Windows.Media;
27+
using PointCloudConverter.Structs.Metadata;
2728

2829
namespace PointCloudConverter
2930
{
3031
public partial class MainWindow : Window
3132
{
32-
static readonly string version = "03.04.2025";
33+
static readonly string version = "04.04.2025";
3334
static readonly string appname = "PointCloud Converter - " + version;
3435
static readonly string rootFolder = AppDomain.CurrentDomain.BaseDirectory;
3536

@@ -54,7 +55,7 @@ public partial class MainWindow : Window
5455
public static MainWindow mainWindowStatic;
5556
bool isInitialiazing = true;
5657

57-
static List<LasHeader> lasHeaders = new List<LasHeader>();
58+
static JobMetadata jobMetadata = new JobMetadata();
5859

5960
// progress bar data
6061
static int progressPoint = 0;
@@ -70,10 +71,6 @@ public partial class MainWindow : Window
7071
private readonly float cellSize = 0.5f;
7172
private static ConcurrentDictionary<(int, int, int), byte> occupiedCells = new();
7273

73-
// classification stats
74-
static byte minClass = 255;
75-
static byte maxClass = 0;
76-
7774
// plugins
7875
string externalFileFormats = "";
7976

@@ -202,10 +199,6 @@ private async void Main()
202199
// get elapsed time using time
203200
var startTime = DateTime.Now;
204201

205-
// classification minmax
206-
minClass = 255;
207-
maxClass = 0;
208-
209202
// if have files, process them
210203
if (importSettings.errors.Count == 0)
211204
{
@@ -343,7 +336,15 @@ private static async Task ProcessAllFiles(object workerParamsObject)
343336
importSettings.offsetZ = lowestZ;
344337
} // if useAutoOffset
345338

346-
lasHeaders.Clear();
339+
340+
//lasHeaders.Clear();
341+
jobMetadata.Job = new Job
342+
{
343+
ConverterVersion = version,
344+
ImportSettings = importSettings,
345+
StartTime = DateTime.Now
346+
};
347+
jobMetadata.lasHeaders.Clear();
347348
progressFile = 0;
348349

349350
//for (int i = 0, len = importSettings.maxFiles; i < len; i++)
@@ -505,7 +506,11 @@ private static async Task ProcessAllFiles(object workerParamsObject)
505506
StringEscapeHandling = StringEscapeHandling.Default // This prevents escaping of characters and write the WKT string properly
506507
};
507508

508-
string jsonMeta = JsonConvert.SerializeObject(lasHeaders, settings);
509+
// add job date
510+
jobMetadata.Job.EndTime = DateTime.Now;
511+
jobMetadata.Job.Elapsed = jobMetadata.Job.EndTime - jobMetadata.Job.StartTime;
512+
513+
string jsonMeta = JsonConvert.SerializeObject(jobMetadata, settings);
509514

510515
// var jsonMeta = JsonSerializer.Serialize(lasHeaders, new JsonSerializerOptions() { WriteIndented = true });
511516
//Log.Write("MetaData: " + jsonMeta);
@@ -666,8 +671,8 @@ static void ProgressTick(object sender, EventArgs e)
666671
progressBar.Maximum = maxValue;
667672
progressBar.Value = currentValue;
668673
progressBar.Foreground = ((currentValue + 1 >= maxValue) ? Brushes.Lime : Brushes.Red); //+1 hack fix
669-
//progressBar.ToolTip = $"Thread {index} - {currentValue} / {maxValue}"; // not visible, because modal dialog
670-
//Log.Write("ProgressTick: " + index + " " + currentValue + " / " + maxValue);
674+
//progressBar.ToolTip = $"Thread {index} - {currentValue} / {maxValue}"; // not visible, because modal dialog
675+
//Log.Write("ProgressTick: " + index + " " + currentValue + " / " + maxValue);
671676

672677
// print json progress
673678
if (progressInfo.UseJsonLog) // TODO now same bool value is for each progressinfo..
@@ -686,12 +691,12 @@ static void ProgressTick(object sender, EventArgs e)
686691
}
687692
} // foreach progressinfo
688693
} // lock
689-
//}
690-
//else // finished ?
691-
//{
692-
// Log.Write("*************** ProgressTick: progressTotalPoints is 0, finishing..");
693-
// mainWindowStatic.progressBarFiles.Value = 0;
694-
// mainWindowStatic.lblStatus.Content = "";
694+
//}
695+
//else // finished ?
696+
//{
697+
// Log.Write("*************** ProgressTick: progressTotalPoints is 0, finishing..");
698+
// mainWindowStatic.progressBarFiles.Value = 0;
699+
// mainWindowStatic.lblStatus.Content = "";
695700

696701
// foreach (UIElement element in mainWindowStatic.ProgressBarsContainer.Children)
697702
// {
@@ -960,10 +965,6 @@ static bool ParseFile(ImportSettings importSettings, int fileIndex, int? taskId,
960965
{
961966
classification = taskReader.GetClassification();
962967

963-
// get min and max
964-
if (classification < minClass) minClass = classification;
965-
if (classification > maxClass) maxClass = classification;
966-
967968
//classification = (byte)255;
968969

969970
//if (classification<0 || classification>1) Log.Write("****: " + classification.ToString());
@@ -1034,11 +1035,7 @@ static bool ParseFile(ImportSettings importSettings, int fileIndex, int? taskId,
10341035
if (importSettings.importMetadata == true)
10351036
{
10361037
var metaData = taskReader.GetMetaData(importSettings, fileIndex);
1037-
// NOTE now its added to every file..
1038-
metaData.ConverterVersion = version;
1039-
metaData.MinClassification = minClass;
1040-
metaData.MaxClassification = maxClass;
1041-
lasHeaders.Add(metaData);
1038+
jobMetadata.lasHeaders.Add(metaData);
10421039
}
10431040

10441041
} // if importMetadataOnly == false ^
@@ -1049,7 +1046,7 @@ static bool ParseFile(ImportSettings importSettings, int fileIndex, int? taskId,
10491046
var metaData = taskReader.GetMetaData(importSettings, fileIndex);
10501047
// NOTE now its added to every file..
10511048
metaData.ConverterVersion = version;
1052-
lasHeaders.Add(metaData);
1049+
jobMetadata.lasHeaders.Add(metaData);
10531050
}
10541051
}
10551052

Readers/IReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public interface IReader
1818
// retrieve single point scan time
1919
double GetTime();
2020

21-
// close filestream
2221
void Close();
2322
byte GetIntensity();
2423
byte GetClassification();
2524
LasHeader GetMetaData(ImportSettings importSettings, int fileIndex);
25+
2626
void Dispose();
2727
}
2828
}

Readers/LAZ.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public class LAZ : IReader, IDisposable
3030
//bool importIntensity = false;
3131
bool customIntensityRange = false;
3232

33+
byte minClassification = 255;
34+
byte maxClassification = 0;
35+
byte minIntensity = 255;
36+
byte maxIntensity = 0;
37+
3338
int? taskID;
3439

3540
// add constructor
@@ -50,6 +55,12 @@ bool IReader.InitReader(ImportSettings importSettings, int fileIndex)
5055
//importRGB = importSettings.importRGB;
5156
//importIntensity = importSettings.importIntensity;
5257
customIntensityRange = importSettings.useCustomIntensityRange;
58+
59+
minClassification = 255;
60+
maxClassification = 0;
61+
minIntensity = 255;
62+
maxIntensity = 0;
63+
5364
res = lazReader.open_reader(file, out compressedLAZ); // 0 = ok, 1 = error
5465
//}
5566
//catch (Exception e)
@@ -63,6 +74,7 @@ bool IReader.InitReader(ImportSettings importSettings, int fileIndex)
6374
LasHeader IReader.GetMetaData(ImportSettings importSettings, int fileIndex)
6475
{
6576
var h = new LasHeader();
77+
6678
h.FileName = importSettings.inputFiles[fileIndex];
6779
h.FileSourceID = lazReader.header.file_source_ID;
6880
h.GlobalEncoding = lazReader.header.global_encoding;
@@ -98,6 +110,18 @@ LasHeader IReader.GetMetaData(ImportSettings importSettings, int fileIndex)
98110
h.MinZ = lazReader.header.min_z;
99111
h.MaxZ = lazReader.header.max_z;
100112

113+
if (importSettings.importClassification)
114+
{
115+
h.MinClassification = minClassification;
116+
h.MaxClassification = maxClassification;
117+
}
118+
119+
if (importSettings.importIntensity)
120+
{
121+
h.MinIntensity = minIntensity;
122+
h.MaxIntensity = maxIntensity;
123+
}
124+
101125
if (h.NumberOfVariableLengthRecords > 0)
102126
{
103127
h.VariableLengthRecords = new System.Collections.Generic.List<LasVariableLengthRecord>();
@@ -378,6 +402,12 @@ byte IReader.GetIntensity()
378402
//c.r = i;
379403
//c.g = i;
380404
//c.b = i;
405+
406+
// get min and max
407+
if (i < minIntensity) minIntensity = i;
408+
if (i > maxIntensity) maxIntensity = i;
409+
410+
381411
return i;
382412
}
383413

@@ -389,6 +419,11 @@ byte IReader.GetClassification()
389419
byte extended = p.extended_classification;
390420
// Choose extended if it's valid and not equal to default "unclassified"
391421
byte finalClassification = (extended > 0 && extended != classification) ? extended : classification;
422+
423+
// get min and max
424+
if (finalClassification < minClassification) minClassification = finalClassification;
425+
if (finalClassification > maxClassification) maxClassification = finalClassification;
426+
392427
return finalClassification;
393428
}
394429

@@ -428,6 +463,16 @@ double IReader.GetTime()
428463
return lazReader.point.gps_time;
429464
}
430465

466+
//(byte, byte) IReader.GetClassificationRange()
467+
//{
468+
// return (minClassification, maxClassification);
469+
//}
470+
471+
//(byte, byte) IReader.GetIntensityRange()
472+
//{
473+
// return (minIntensity, maxIntensity);
474+
//}
475+
431476
void IReader.Close()
432477
{
433478
lazReader.close_reader();

Structs/ImportSettings.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ namespace PointCloudConverter
1515
{
1616
public class ImportSettings
1717
{
18-
// filled in by program (so that json serializer is easier)
19-
public string version { get; set; } = "0.0.0";
18+
// filled in by program (so that json serializer is easier), not used
19+
//public string version { get; set; } = "0.0.0";
2020

2121
[JsonConverter(typeof(JsonStringEnumConverter))]
2222
public Logger.LogEvent @event { get; set; }
23-
23+
24+
[JsonIgnore] // FIXME doesnt ígnore it
2425
public IReader reader; // single threaded reader
2526
//public Dictionary<int?, IReader> Readers { get; set; } = new Dictionary<int?, IReader>();
2627
public ConcurrentDictionary<int?, IReader> Readers { get; set; } = new ConcurrentDictionary<int?, IReader>();
28+
[JsonIgnore]
2729
public IWriter writer = new UCPC();
30+
31+
public string ReaderType => reader?.GetType().Name;
32+
public string WriterType => writer?.GetType().Name;
33+
2834
//public Dictionary<int?, IWriter> Writers { get; set; } = new Dictionary<int?, IWriter>();
2935
//public ConcurrentDictionary<int?, WeakReference<IWriter>> Writers { get; set; } = new ConcurrentDictionary<int?, WeakReference<IWriter>>();
3036
private readonly ConcurrentBag<IWriter> _writerPool = new ConcurrentBag<IWriter>();

Structs/Metadata/LasHeader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ public class LasHeader
4444
public double MinY { get; set; }
4545
public double MaxZ { get; set; }
4646
public double MinZ { get; set; }
47+
4748
public byte MinClassification { get; set; }
4849
public byte MaxClassification { get; set; }
50+
public byte MinIntensity { get; set; }
51+
public byte MaxIntensity { get; set; }
52+
4953
public List<LasVariableLengthRecord> VariableLengthRecords { get; set; }
5054
public ulong StartOfWaveformDataPacketRecord { get; internal set; }
5155
public ulong StartOfFirstExtendedVariableLengthRecord { get; internal set; }

Writers/PCROOT.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ void IWriter.WriteRGB(float r, float g, float b)
184184
// for pcroot, this is saving the rootfile
185185
void IWriter.Close()
186186
{
187+
// this happens if imported metadata only?
188+
if (importSettings == null) return;
189+
187190
// save rootfile
188191
// only save after last file, TODO should save this if process fails or user cancels, so no need to start from 0 again.. but then needs some merge or continue from index n feature
189192
// if (isLastTask == true)

0 commit comments

Comments
 (0)