Skip to content

Commit ea5c40c

Browse files
committed
add srgb to linear conversion argument "-srgb" (use if your model colors seem too bright), e57: check for null pose data
1 parent 85afb4c commit ea5c40c

File tree

9 files changed

+86
-10
lines changed

9 files changed

+86
-10
lines changed

App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@
166166
<setting name="detectIntensityRange" serializeAs="String">
167167
<value>False</value>
168168
</setting>
169+
<setting name="useSRGB" serializeAs="String">
170+
<value>False</value>
171+
</setting>
169172
</PointCloudConverter.Properties.Settings>
170173
</userSettings>
171174
<runtime>

MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
</StackPanel>
108108
<StackPanel Grid.Column="1" Margin="0,4,0,0">
109109
<CheckBox x:Name="chkUseJSONLog" Content="Use JSON log *Used in commandline only" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" IsChecked="False" ToolTip="Log messages are written in JSON format. Experimental, V3 format is better supported."/>
110+
<CheckBox x:Name="chkConvertSRGB" Content="Convert sRGB to Linear RGB" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" IsChecked="False" ToolTip="Convert sRGB colors to Linear RGB"/>
110111
</StackPanel>
111112

112113
<StackPanel Grid.Column="1" Margin="0,4,0,0" Orientation="Horizontal">

MainWindow.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,14 @@ static bool ParseFile(ImportSettings importSettings, int fileIndex, int? taskId,
904904
if (importSettings.importRGB == true)
905905
{
906906
rgb = taskReader.GetRGB();
907+
908+
// convert from srg to linear (if your model seems too bright)
909+
if (importSettings.sRGB)
910+
{
911+
rgb.r = Tools.SRGBToLinear(rgb.r);
912+
rgb.g = Tools.SRGBToLinear(rgb.g);
913+
rgb.b = Tools.SRGBToLinear(rgb.b);
914+
}
907915
}
908916

909917
// skip points
@@ -1208,6 +1216,8 @@ void StartProcess(bool doProcess = true)
12081216
args.Add("-maxthreads=" + txtMaxThreads.Text);
12091217

12101218
if ((bool)chkUseFilter.IsChecked) args.Add("-filter=" + txtFilterDistance.Text);
1219+
if ((bool)chkConvertSRGB.IsChecked) args.Add("-srgb=true");
1220+
12111221

12121222
if (isGLTF == true) args.Add(("-usegrid=" + (bool)chkUseGrid.IsChecked).ToLower());
12131223

@@ -1627,6 +1637,7 @@ private void LoadSettings()
16271637
txtOffsetMode.Text = Properties.Settings.Default.offsetMode;
16281638
chkUseFilter.IsChecked = Properties.Settings.Default.useFilter;
16291639
txtFilterDistance.Text = Properties.Settings.Default.filterDistance.ToString();
1640+
chkConvertSRGB.IsChecked = Properties.Settings.Default.useSRGB;
16301641
isInitialiazing = false;
16311642
}
16321643

@@ -1681,6 +1692,7 @@ void SaveSettings()
16811692
Properties.Settings.Default.offsetMode = txtOffsetMode.Text;
16821693
Properties.Settings.Default.useFilter = (bool)chkUseFilter.IsChecked;
16831694
Properties.Settings.Default.filterDistance = Tools.ParseFloat(txtFilterDistance.Text);
1695+
Properties.Settings.Default.useSRGB = (bool)chkConvertSRGB.IsChecked;
16841696
Properties.Settings.Default.Save();
16851697
}
16861698

Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,8 @@
158158
<Setting Name="detectIntensityRange" Type="System.Boolean" Scope="User">
159159
<Value Profile="(Default)">False</Value>
160160
</Setting>
161+
<Setting Name="useSRGB" Type="System.Boolean" Scope="User">
162+
<Value Profile="(Default)">False</Value>
163+
</Setting>
161164
</Settings>
162165
</SettingsFile>

Readers/E57.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,36 @@ public bool InitReader(ImportSettings importSettings, int fileIndex)
4545
header = ASTM_E57.E57FileHeader.Parse(stream, new FileInfo(filePath).Length, false);
4646
stream.Close();
4747

48-
var pose = header.E57Root.Data3D[0].Pose;
48+
var data3D = header.E57Root.Data3D[0];
49+
var pose = data3D.Pose;
4950

5051
metaData = new E57MetaData
5152
{
52-
Name = header.E57Root.Data3D[0].Name,
53-
X = pose.Translation.X,
54-
Y = importSettings.swapYZ ? pose.Translation.Z : pose.Translation.Y,
55-
Z = importSettings.swapYZ ? pose.Translation.Y : pose.Translation.Z,
56-
RX = pose.Rotation.X,
57-
RY = importSettings.swapYZ ? pose.Rotation.Z : pose.Rotation.Y,
58-
RZ = importSettings.swapYZ ? pose.Rotation.Y : pose.Rotation.Z,
59-
RW = pose.Rotation.W
53+
Name = data3D.Name
6054
};
6155

56+
if (pose != null)
57+
{
58+
metaData.X = pose.Translation.X;
59+
metaData.Y = importSettings.swapYZ ? pose.Translation.Z : pose.Translation.Y;
60+
metaData.Z = importSettings.swapYZ ? pose.Translation.Y : pose.Translation.Z;
61+
62+
metaData.RX = pose.Rotation.X;
63+
metaData.RY = importSettings.swapYZ ? pose.Rotation.Z : pose.Rotation.Y;
64+
metaData.RZ = importSettings.swapYZ ? pose.Rotation.Y : pose.Rotation.Z;
65+
metaData.RW = pose.Rotation.W;
66+
}
67+
else
68+
{
69+
// Optional: assign default values or log warning
70+
metaData.X = metaData.Y = metaData.Z = 0;
71+
metaData.RX = metaData.RY = metaData.RZ = 0;
72+
metaData.RW = 1;
73+
74+
Console.WriteLine("Warning: E57 scan pose is null.");
75+
}
76+
77+
6278
var chunks = ChunksFull(filePath, ParseConfig.Default);
6379
chunkEnumerator = chunks.GetEnumerator();
6480

@@ -140,6 +156,7 @@ public Color GetRGB()
140156
}
141157

142158
int i = currentPointIndex - 1;
159+
143160
if (cachedColors != null && i >= 0 && i < cachedColors.Length)
144161
{
145162
var c = cachedColors[i];

Structs/ImportSettings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public void ReleaseReader(int? taskId)
240240
public string offsetMode { get; set; } = "min"; // TODO use enum: "min" or "legacy" now (legacy is first bounds min only)
241241
public bool useFilter { get; set; } = false; // filter by distance
242242
public float filterDistance { get; set; } = 0.5f;
243+
public bool sRGB { get; set; } = false; // use sRGB color space for RGB values
243244

244245
public override string ToString()
245246
{
@@ -285,6 +286,12 @@ public override string ToString()
285286
t += "\n checkoverlap=" + checkoverlap;
286287
t += "\n useGrid=" + useGrid;
287288
t += "\n offsetMode=" + offsetMode;
289+
t += "\n useFilter=" + useFilter;
290+
t += "\n filterDistance=" + filterDistance;
291+
t += "\n sRGB=" + sRGB;
292+
t += "\n importFormat=" + importFormat;
293+
t += "\n exportFormat=" + exportFormat;
294+
t += "\n maxThreads=" + maxThreads;
288295
return t;
289296
}
290297

Tools/ArgParser.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,14 @@ public static ImportSettings Parse(string[] args, string rootFolder, ILogger log
258258

259259
if (importSettings.importFormat == ImportFormat.Unknown)
260260
{
261-
importSettings.errors.Add("Import format not defined before -input folder for batch (use -importformat" + argValueSeparator + "LAS or PLY)");
261+
importSettings.errors.Add("Import format not defined before -input folder for batch (use -importformat" + argValueSeparator + "LAS or PLY or E57)");
262262
}
263263
else
264264
{
265265
string importExtensions = "";
266266
if (importSettings.importFormat == ImportFormat.LAS) importExtensions = "las|laz";
267267
if (importSettings.importFormat == ImportFormat.PLY) importExtensions = "ply";
268+
if (importSettings.importFormat == ImportFormat.E57) importExtensions = "e57";
268269
var filePaths = Directory.GetFiles(param).Where(file => Regex.IsMatch(file, @"^.+\.(" + importExtensions + ")$", RegexOptions.IgnoreCase)).ToArray();
269270

270271
for (int j = 0; j < filePaths.Length; j++)
@@ -797,6 +798,19 @@ public static ImportSettings Parse(string[] args, string rootFolder, ILogger log
797798
}
798799
break;
799800

801+
case "-srgb":
802+
Log.Write("srgb = " + param);
803+
804+
if (param != "false" && param != "true")
805+
{
806+
importSettings.errors.Add("Invalid srgb parameter: " + param);
807+
}
808+
else
809+
{
810+
importSettings.sRGB = (param == "true");
811+
}
812+
break;
813+
800814
case "-offsetmode":
801815
Log.Write("offsetmode = " + param);
802816

Tools/Tools.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ public static float ParseFloat(string s)
361361
return f;
362362
}
363363

364+
public static float SRGBToLinear(float c)
365+
{
366+
return c <= 0.04045f ? c / 12.92f : MathF.Pow((c + 0.055f) / 1.055f, 2.4f);
367+
}
368+
364369
public static void PrintHelpAndExit(char argSeparator, bool waitEnter = false)
365370
{
366371
Console.ForegroundColor = ConsoleColor.Gray;
@@ -407,6 +412,8 @@ public static void PrintHelpAndExit(char argSeparator, bool waitEnter = false)
407412
Console.WriteLine("-config" + argSeparator + "filename\t\tLoad arguments from text file (easier to handle separate settings for different projects)");
408413
Console.WriteLine("-usegrid" + argSeparator + "true\t\tSplits point cloud to grid (multiple files). Required for V3 format (automatically enabled if its off). \tDefault is true for v3");
409414
Console.WriteLine("-offsetmode" + argSeparator + "min\t\tGet auto-offset bounds, min=min from all bounds, legacy= first cloud min bounds\tDefault is min");
415+
Console.WriteLine("-srgb" + argSeparator + "false\t\tConvert raw sRGB values to Linear RGB\tDefault is false, enable this is your model seems too bright");
416+
410417

411418
Console.WriteLine("");
412419
Console.WriteLine("? /? -? help -help /help");

0 commit comments

Comments
 (0)