Skip to content

Commit 52b3e82

Browse files
committed
add experimental PLY importer support (ascii and tested with simple files only)
1 parent 2e31a04 commit 52b3e82

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

MainWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ private static async Task ProcessAllFiles(object workerParamsObject)
448448
}
449449
else
450450
{
451+
Log.Write("files"+importSettings.inputFiles.Count+" i:"+i);
451452
Log.Write("Error> Failed to parse file: " + importSettings.inputFiles[i], LogEvent.Error);
452453
}
453454
}
@@ -1386,7 +1387,7 @@ private void btnBrowseInput_Click(object sender, RoutedEventArgs e)
13861387
// select single file
13871388
var dialog = new OpenFileDialog();
13881389
dialog.Title = "Select file to import";
1389-
dialog.Filter = "LAS|*.las;*.laz";
1390+
dialog.Filter = "Point Cloud Files|*.las;*.laz;*.ply|LAS Files|*.las;*.laz|PLY Files|*.ply|All Files|*.*";
13901391

13911392
// take folder from field
13921393
if (string.IsNullOrEmpty(txtInputFile.Text) == false)

PointCloudConverter.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<ItemGroup>
3737
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
3838
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
39+
<PackageReference Include="Ply.Net" Version="5.5.5" />
3940
<PackageReference Include="System.Buffers" Version="4.5.1" />
4041
<PackageReference Include="System.Memory" Version="4.5.5" />
4142
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />

Structs/ImportFormat.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public enum ImportFormat
44
{
55
Unknown,
6-
LAS // and LAZ
6+
LAS, // and LAZ
7+
PLY
78
}
89
}

Structs/ImportSettings.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ImportSettings
2121
[JsonConverter(typeof(JsonStringEnumConverter))]
2222
public Logger.LogEvent @event { get; set; }
2323

24-
public IReader reader = new LAZ(null); // single threaded reader
24+
public IReader reader; // single threaded reader
2525
//public Dictionary<int?, IReader> Readers { get; set; } = new Dictionary<int?, IReader>();
2626
public ConcurrentDictionary<int?, IReader> Readers { get; set; } = new ConcurrentDictionary<int?, IReader>();
2727
public IWriter writer = new UCPC();
@@ -48,9 +48,26 @@ public void InitWriterPool(int maxThreads, ExportFormat export)
4848
// Method to get or create a reader for a specific task ID
4949
public IReader GetOrCreateReader(int? taskId)
5050
{
51+
//Log.Write(">>>>> Getting or creating reader for task ID: " + taskId+" format: "+importFormat);
52+
5153
if (!Readers.ContainsKey(taskId))
5254
{
53-
Readers[taskId] = new LAZ(taskId);
55+
IReader readerInstance;
56+
57+
switch (importFormat)
58+
{
59+
case ImportFormat.LAS:
60+
readerInstance = new LAZ(taskId);
61+
break;
62+
case ImportFormat.PLY:
63+
readerInstance = new PLY(); // no taskId needed here
64+
break;
65+
default:
66+
Log.Write($"Unsupported import format: {importFormat}", LogEvent.Error);
67+
throw new NotSupportedException($"Unsupported import format: {importFormat}");
68+
}
69+
70+
Readers[taskId] = readerInstance;
5471
}
5572

5673
//Log.Write(">>>>> Total Readers in dictionary: " + Readers.Count);

Tools/ArgParser.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,29 @@ public static ImportSettings Parse(string[] args, string rootFolder, ILogger log
152152

153153
string importFormatParsed = param.ToUpper();
154154

155-
// TODO check what reader interfaces are available
156-
if (string.IsNullOrEmpty(importFormatParsed) == true || (importFormatParsed != "LAS" && importFormatParsed != "LAZ"))
155+
if (string.IsNullOrEmpty(importFormatParsed) ||
156+
(importFormatParsed != "LAS" && importFormatParsed != "LAZ" && importFormatParsed != "PLY"))
157157
{
158158
importSettings.errors.Add("Unsupported import format: " + param);
159159
importSettings.importFormat = ImportFormat.Unknown;
160160
}
161161
else
162162
{
163-
importSettings.importFormat = ImportFormat.LAS;
164-
importSettings.reader = new LAZ(null);
163+
switch (importFormatParsed)
164+
{
165+
case "LAS":
166+
case "LAZ":
167+
importSettings.importFormat = ImportFormat.LAS;
168+
importSettings.reader = new LAZ(null);
169+
break;
170+
case "PLY":
171+
importSettings.importFormat = ImportFormat.PLY;
172+
importSettings.reader = new PLY();
173+
break;
174+
}
165175
}
166176
break;
177+
167178
case "-exportformat":
168179
Log.Write("exportformat = " + param);
169180

@@ -234,7 +245,7 @@ public static ImportSettings Parse(string[] args, string rootFolder, ILogger log
234245

235246
// TODO get file extension from commandline param? but then need to set -format before input.. for now only LAS/LAZ
236247
// TODO parse/sort args in required order, not in given order
237-
var filePaths = Directory.GetFiles(param).Where(file => Regex.IsMatch(file, @"^.+\.(las|laz)$", RegexOptions.IgnoreCase)).ToArray();
248+
var filePaths = Directory.GetFiles(param).Where(file => Regex.IsMatch(file, @"^.+\.(las|laz|ply)$", RegexOptions.IgnoreCase)).ToArray();
238249

239250

240251
for (int j = 0; j < filePaths.Length; j++)
@@ -854,9 +865,9 @@ public static ImportSettings Parse(string[] args, string rootFolder, ILogger log
854865
{
855866
importSettings.errors.Add("(E) PCROOT Requires some output filename (example: output.pcroot)");
856867
}
857-
if (importSettings.exportFormat == ExportFormat.External)
868+
if (importSettings.exportFormat == ExportFormat.External && importSettings.batch == false)
858869
{
859-
importSettings.errors.Add("(E2) External formats require some output filename (example: basefilename)");
870+
importSettings.errors.Add("(E2) External formats require some output filename for non-batch operations (example: basefilename)");
860871
}
861872
}
862873
}
@@ -938,6 +949,12 @@ public static ImportSettings Parse(string[] args, string rootFolder, ILogger log
938949
Log.Write("No import format defined, using Default: " + importSettings.importFormat.ToString());
939950
}
940951

952+
if (importSettings.importFormat == ImportFormat.PLY)
953+
{
954+
if (importSettings.importIntensity || importSettings.importClassification) Log.Write("PLY doesnt support intensity or classification importing.");
955+
if (importSettings.packColors) Log.Write("PLY doesnt support color packing.");
956+
}
957+
941958
if (importSettings.exportFormat == ExportFormat.PCROOT && importSettings.useGrid == false)
942959
{
943960
//importSettings.errors.Add("V3 pcroot export format requires -usegrid=true to use grid");

0 commit comments

Comments
 (0)