Skip to content

Commit 0b3ddc6

Browse files
committed
save last used config folder, improve skipping (in main loop) fixes #38, fix GUI auto-offset+manual duplicated argument, fix import settings format type (was object, needs to be string),
1 parent 69cb222 commit 0b3ddc6

File tree

8 files changed

+73
-33
lines changed

8 files changed

+73
-33
lines changed

App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@
148148
<setting name="useGrid" serializeAs="String">
149149
<value>True</value>
150150
</setting>
151+
<setting name="lastUsedConfigFolder" serializeAs="String">
152+
<value />
153+
</setting>
151154
</PointCloudConverter.Properties.Settings>
152155
</userSettings>
153156
<runtime>

MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<CheckBox x:Name="chkUseMaxFileCount" Content="Maximum file count:" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" ToolTip="For batch processing, parse only this many files (good for testing with few files first)"/>
8282
<TextBox x:Name="txtMaxFileCount" HorizontalAlignment="Left" Margin="0" TextWrapping="Wrap" VerticalAlignment="Top" Width="92"/>
8383
</StackPanel>
84-
<CheckBox x:Name="chkRandomize" Content="Randomize" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" IsChecked="True" ToolTip="Randomize point indexes, to use Dynamic resolution\tDefault is true (Always enabled for v3)"/>
84+
<CheckBox x:Name="chkRandomize" Content="Randomize" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" IsChecked="True" ToolTip="Randomize point indexes, to use Dynamic resolution. Default is true (Always enabled for v3)"/>
8585
<CheckBox x:Name="chkOpenOutputFolder" Content="Open output folder" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" IsChecked="False" ToolTip="Open Explorer to Output folder after finished processing"/>
8686
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal">
8787
<CheckBox x:Name="chkReadMetaData" Content="Import metadata" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" IsChecked="True" ToolTip="Reads LAs/LAZ metadata and saves into file"/>

MainWindow.xaml.cs

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace PointCloudConverter
2828
{
2929
public partial class MainWindow : Window
3030
{
31-
static readonly string version = "17.09.2024";
31+
static readonly string version = "23.09.2024";
3232
static readonly string appname = "PointCloud Converter - " + version;
3333
static readonly string rootFolder = AppDomain.CurrentDomain.BaseDirectory;
3434

@@ -816,17 +816,10 @@ static bool ParseFile(ImportSettings importSettings, int fileIndex, int? taskId,
816816
int checkCancelEvery = fullPointCount / 128;
817817

818818
// Loop all points
819-
819+
// FIXME: would be nicer, if use different STEP value for skip, keep and limit..(to collect points all over the file, not just start)
820820
int maxPointIterations = importSettings.useLimit ? pointCount : fullPointCount;
821-
822-
//for (int i = 0; i < fullPointCount; i++)
823821
for (int i = 0; i < maxPointIterations; i++)
824-
//for (int i = 0; i < 1000; i++)
825822
{
826-
827-
// stop at limit count
828-
//if (importSettings.useLimit == true && i > pointCount) break;
829-
830823
// check for cancel every 1% of points
831824
if (i % checkCancelEvery == 0)
832825
{
@@ -837,21 +830,23 @@ static bool ParseFile(ImportSettings importSettings, int fileIndex, int? taskId,
837830
}
838831
}
839832

840-
// FIXME: need to add skip and keep point skipper here, to make skipping faster!
841-
842833
// get point XYZ
843834
Float3 point = taskReader.GetXYZ();
844835
if (point.hasError == true) break; // TODO display errors
845836

837+
// skip points
838+
if (importSettings.skipPoints == true && (i % importSettings.skipEveryN == 0)) continue;
839+
840+
// keep points
841+
if (importSettings.keepPoints == true && (i % importSettings.keepEveryN != 0)) continue;
842+
843+
846844
// add offsets (its 0 if not used)
847845
point.x -= importSettings.offsetX;
848846
point.y -= importSettings.offsetY;
849847
point.z -= importSettings.offsetZ;
850848

851849
// scale if enabled
852-
//point.x = importSettings.useScale ? point.x * importSettings.scale : point.x;
853-
//point.y = importSettings.useScale ? point.y * importSettings.scale : point.y;
854-
//point.z = importSettings.useScale ? point.z * importSettings.scale : point.z;
855850
if (importSettings.useScale == true)
856851
{
857852
point.x *= importSettings.scale;
@@ -917,7 +912,6 @@ static bool ParseFile(ImportSettings importSettings, int fileIndex, int? taskId,
917912
taskWriter.AddPoint(i, (float)point.x, (float)point.y, (float)point.z, rgb.r, rgb.g, rgb.b, importSettings.importIntensity, intensity.r, importSettings.averageTimestamp, time);
918913
//progressPoint = i;
919914
progressInfo.CurrentValue = i;
920-
921915
} // for all points
922916

923917
// hack for missing 100% progress
@@ -1025,7 +1019,15 @@ void StartProcess(bool doProcess = true)
10251019
}
10261020
args.Add("-output=" + txtOutput.Text);
10271021

1028-
args.Add("-offset=" + (bool)chkAutoOffset.IsChecked);
1022+
// check if using autooffset
1023+
if ((bool)chkAutoOffset.IsChecked && !(bool)chkManualOffset.IsChecked)
1024+
{
1025+
args.Add("-offset=" + (bool)chkAutoOffset.IsChecked);
1026+
}
1027+
1028+
// or manual offset, TODO later should allow using both (first autooffset, then add manual)
1029+
if ((bool)chkManualOffset.IsChecked) args.Add("-offset=" + txtOffsetX.Text + "," + txtOffsetY.Text + "," + txtOffsetZ.Text);
1030+
10291031
args.Add("-rgb=" + (bool)chkImportRGB.IsChecked);
10301032
args.Add("-intensity=" + (bool)chkImportIntensity.IsChecked);
10311033

@@ -1046,7 +1048,6 @@ void StartProcess(bool doProcess = true)
10461048
if ((bool)chkUseSkip.IsChecked) args.Add("-skip=" + txtSkipEvery.Text);
10471049
if ((bool)chkUseKeep.IsChecked) args.Add("-keep=" + txtKeepEvery.Text);
10481050
if ((bool)chkUseMaxFileCount.IsChecked) args.Add("-maxfiles=" + txtMaxFileCount.Text);
1049-
if ((bool)chkManualOffset.IsChecked) args.Add("-offset=" + txtOffsetX.Text + "," + txtOffsetY.Text + "," + txtOffsetZ.Text);
10501051
args.Add("-randomize=" + (bool)chkRandomize.IsChecked);
10511052
if ((bool)chkSetRandomSeed.IsChecked) args.Add("-seed=" + txtRandomSeed.Text);
10521053
if ((bool)chkUseJSONLog.IsChecked) args.Add("-json=true");
@@ -1061,7 +1062,7 @@ void StartProcess(bool doProcess = true)
10611062
if (((bool)chkImportIntensity.IsChecked) && ((bool)chkCustomIntensityRange.IsChecked)) args.Add("-customintensityrange=True");
10621063

10631064
// check input files
1064-
Trace.WriteLine("loggeris:" + Log.GetType().ToString());
1065+
//Trace.WriteLine("loggeris:" + Log.GetType().ToString());
10651066

10661067
var importSettings = ArgParser.Parse(args.ToArray(), rootFolder, Log);
10671068

@@ -1140,6 +1141,8 @@ void ImportArgs(string rawArgs)
11401141
string key = parts[0].ToLower().TrimStart('-');
11411142
string value = parts[1];
11421143

1144+
// FIXME, if value is not saved, need to use default value
1145+
11431146
// Apply the key-value pairs to the GUI elements
11441147
switch (key)
11451148
{
@@ -1360,7 +1363,7 @@ private void LoadSettings()
13601363
{
13611364
if ((ExportFormat)item == ExportFormat.Unknown) continue;
13621365
if ((ExportFormat)item == ExportFormat.External) continue;
1363-
cmbExportFormat.Items.Add(item);
1366+
cmbExportFormat.Items.Add(item.ToString());
13641367
}
13651368

13661369
// Add dynamic export formats discovered from plugins
@@ -1646,16 +1649,26 @@ private void btnCopyToClipboard_Click(object sender, RoutedEventArgs e)
16461649
private void btnImportSettings_Click(object sender, RoutedEventArgs e)
16471650
{
16481651
var dialog = new OpenFileDialog();
1649-
dialog.Title = "Select settings file";
1652+
dialog.Title = "Import settings file";
16501653
dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
1651-
//dialog.DefaultDirectory = "configs/";
1654+
1655+
// if have previously used config dir use that, if not, use local config dir if exists, if neither, use default..
1656+
if (string.IsNullOrEmpty(Properties.Settings.Default.lastImportFolder) == false)
1657+
{
1658+
dialog.InitialDirectory = Properties.Settings.Default.lastImportFolder;
1659+
}
1660+
else if (Directory.Exists("configs/"))
1661+
{
1662+
dialog.InitialDirectory = "configs/";
1663+
}
16521664

16531665
if (dialog.ShowDialog() == true)
16541666
{
16551667
if (File.Exists(dialog.FileName))
16561668
{
16571669
var contents = File.ReadAllText(dialog.FileName);
16581670
ImportArgs(contents);
1671+
Properties.Settings.Default.lastImportFolder = Path.GetDirectoryName(dialog.FileName);
16591672
}
16601673
}
16611674
}
@@ -1666,10 +1679,20 @@ private void btnExportSettings_Click(object sender, RoutedEventArgs e)
16661679
dialog.Title = "Save settings file";
16671680
dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
16681681

1682+
if (string.IsNullOrEmpty(Properties.Settings.Default.lastImportFolder) == false)
1683+
{
1684+
dialog.InitialDirectory = Properties.Settings.Default.lastImportFolder;
1685+
}
1686+
else if (Directory.Exists("configs/"))
1687+
{
1688+
dialog.InitialDirectory = "configs/";
1689+
}
1690+
16691691
if (dialog.ShowDialog() == true)
16701692
{
16711693
StartProcess(false);
16721694
File.WriteAllText(dialog.FileName, txtConsole.Text);
1695+
Properties.Settings.Default.lastImportFolder = Path.GetDirectoryName(dialog.FileName);
16731696
}
16741697
}
16751698

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
@@ -140,5 +140,8 @@
140140
<Setting Name="useGrid" Type="System.Boolean" Scope="User">
141141
<Value Profile="(Default)">True</Value>
142142
</Setting>
143+
<Setting Name="lastUsedConfigFolder" Type="System.String" Scope="User">
144+
<Value Profile="(Default)" />
145+
</Setting>
143146
</Settings>
144147
</SettingsFile>

Tools/ArgParser.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,16 +595,15 @@ public static ImportSettings Parse(string[] args, string rootFolder, ILogger log
595595
case "-offset":
596596
Log.Write("offset = " + param);
597597

598-
// check if its true or false
598+
// check if its true or false (for automatic offset)
599599
if (param != "false" && param != "true")
600600
{
601-
// check if its valid integer x,z
601+
// check if have x,y,z values, NOTE should be in this format: -offset=10.5,-123,0
602602
if (param.IndexOf(',') > -1)
603603
{
604604
var temp = param.Split(',');
605605
if (temp.Length == 3)
606606
{
607-
608607
float xOff, yOff, zOff;
609608
if (float.TryParse(temp[0].Trim(), out xOff) && float.TryParse(temp[1].Trim(), out yOff) && float.TryParse(temp[2].Trim(), out zOff))
610609
{

Writers/PCROOT.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,11 @@ void IWriter.Save(int fileIndex)
585585
// loop and output all points within that node/tile
586586
for (int i = 0, len = nodeTempX.Count; i < len; i++)
587587
{
588-
// skip points
589-
if (importSettings.skipPoints == true && (i % importSettings.skipEveryN == 0)) continue;
588+
//// skip points
589+
//if (importSettings.skipPoints == true && (i % importSettings.skipEveryN == 0)) continue;
590590

591-
// keep points
592-
if (importSettings.keepPoints == true && (i % importSettings.keepEveryN != 0)) continue;
591+
//// keep points
592+
//if (importSettings.keepPoints == true && (i % importSettings.keepEveryN != 0)) continue;
593593

594594
// get original world positions
595595
float px = nodeTempX[i];

Writers/UCPC.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ void IWriter.Randomize()
252252

253253
void IWriter.AddPoint(int index, float x, float y, float z, float r, float g, float b, bool hasIntensity, float i, bool hasTime, double time)
254254
{
255-
// skip points
256-
if (importSettings.skipPoints == true && (index % importSettings.skipEveryN == 0)) return;
255+
//// skip points
256+
//if (importSettings.skipPoints == true && (index % importSettings.skipEveryN == 0)) return;
257257

258-
// keep points
259-
if (importSettings.keepPoints == true && (index % importSettings.keepEveryN != 0)) return;
258+
//// keep points
259+
//if (importSettings.keepPoints == true && (index % importSettings.keepEveryN != 0)) return;
260260

261261
// get bounds
262262
if (x < cloudMinX) cloudMinX = x;

0 commit comments

Comments
 (0)