Batch Scalar Field operation

Feel free to ask any question here
Post Reply
cragoras
Posts: 6
Joined: Tue Feb 14, 2023 8:58 am

Batch Scalar Field operation

Post by cragoras »

Hey All,

i currently try to simplify some tasks with batches. There is the option to set a scalar field in 2.13 with -SF_OP {SF index or name} {operation} {value} (https://www.cloudcompare.org/doc/wiki/i ... 13.beta.29)

I have a working batch for the CSF Filter.

Code: Select all

::USE CSF in Current Directory
for %%f in (%CD%\*.las) DO "C:\Program Files\CloudCompare\cloudcompare.exe" -SILENT -O -GLOBAL_SHIFT AUTO %%f -AUTO_SAVE OFF -C_EXPORT_FMT LAS -NO_TIMESTAMP -CSF -SCENES RELIEF -PROC_SLOPE -CLOTH_RESOLUTION 2.0 -CLASS_THRESHOLD 0.5 -EXPORT_GROUND -EXPORT_OFFGROUND
as a follow up i now want to classify the ground with the correct class number "2" in LAS, a task i need to perform multiple times. I tried several options but I'm not really a coder, this is what i came up with which doesn't work:

Code: Select all

:: Classify ground as Class 2
for %%f in (%CD%\*_ground_points.las)  DO "C:\Program Files\CloudCompare\cloudcompare.exe" -O -GLOBAL_SHIFT AUTO %%f -C_EXPORT_FMT LAS -SF_OP Classification set 2 -SAVE_CLOUDS
What am i doing wrong?
Thank you!

Best
Marius
HeadLess
Posts: 53
Joined: Mon Mar 25, 2019 9:27 pm

Re: Batch Scalar Field operation

Post by HeadLess »

I think, if your source file deos not contain a scaklar field named as Classifiction, than you should use -SF_ADD_CONST Classification 2 instead of SF_OP.

But just to be sure. this will assign classification = 2 on every single points it won't run any algorithm to check if that is ground or will not run a csf algorithm, you need to distinct the clouds beforehands.

PS: i've seen it later you already have the CSF, maybe you could use -SELECT_ENTITIES to filter out only ground so you won't need to save/reaopen the files.

PS2:

Code: Select all

-AUTO_SAVE OFF
-C_EXPORT_FMT LAS
-NO_TIMESTAMP

#open file
-O -GLOBAL_SHIFT AUTO "C:\Users\KamaeL\Documents\XYZ_teszt_rgb.bin"
-CSF -SCENES RELIEF -PROC_SLOPE -CLOTH_RESOLUTION 2.0 -CLASS_THRESHOLD 0.5
#it will only work with one cloud open, because currently there is no name difference between the two cloud it is just two "*.extract", So we only be able to do this with one cloud or we should be a little bit smarter... like using -RENAME_ENTITIES and some regex to select every odd numbered. cloud
-SELECT_ENTITIES -FIRST 1
#create a constant scalar field on the selected cloud (first)
-SF_ADD_CONST "Classification" 2
-SELECT_ENTITIES -ALL
-MERGE_CLOUDS
-SAVE_CLOUDS
You can use this command file, (or list of commands :) )
cragoras
Posts: 6
Joined: Tue Feb 14, 2023 8:58 am

Re: Batch Scalar Field operation

Post by cragoras »

Thanks for the help! That kind of worked, but i dont want to add a new scalar field and rather change the current one named "Classification"

Adding it worked now with

Code: Select all

-SF_ADD_CONST "Classification1" 2
but i dont understand why

Code: Select all

-SF_OP "Classification" set 2
wouldnt work. I get an Invalid SF index error even though if i use just classification in SF ADD CONST it says the SF Index already exists.

the command set can be used as i try to do here, i hope?

Best
Marius
HeadLess
Posts: 53
Joined: Mon Mar 25, 2019 9:27 pm

Re: Batch Scalar Field operation

Post by HeadLess »

Well if you already have Classification scalar field that should work i think. but you might be able to get around it by removing that first and adding it back?

So

Code: Select all

-REMOVE_SF "Classification" -SF_ADD_CONST "Classification" 2
I'll ty to look at on a dataset later where there is already classification.
HeadLess
Posts: 53
Joined: Mon Mar 25, 2019 9:27 pm

Re: Batch Scalar Field operation

Post by HeadLess »

So what i've found

Code: Select all

-SF_OP Classification set 2
works. Can you check that if it works with 2.13.1 (it was released on febr 14). If not can you send us the log and/or the file you are working with?

However one thing to note you cannot change empty values which is kind of not ok in my opinion.

Daniel is there a reason to this behavior i've noticed it in other scalar field operations as well during one of the pull request.

But deleting and readding the ground class won't hurt in this case i suppose. That should work. As i've showed earlier.
cragoras
Posts: 6
Joined: Tue Feb 14, 2023 8:58 am

Re: Batch Scalar Field operation

Post by cragoras »

Awesome! Thank you so much. Works almost perfectly now.
Applying CSF and assigning class codes to ground and non-ground points in the current directory one .bat.

Maybe someone needs this too

Code: Select all

::Apply CSF to all .las in current directory
::--- assign class 20 to non-ground
::--- assign class 2  to ground
for %%f in (%CD%\*.las) DO "C:\Program Files\CloudCompare\cloudcompare.exe" -SILENT -O -GLOBAL_SHIFT AUTO %%f -AUTO_SAVE OFF -C_EXPORT_FMT LAS -NO_TIMESTAMP -SF_ADD_CONST "Classification" 20 -CSF -SCENES RELIEF -PROC_SLOPE -CLOTH_RESOLUTION 2.0 -CLASS_THRESHOLD 0.5 -SELECT_ENTITIES -FIRST 1 -REMOVE_SF "Classification" -SF_ADD_CONST "Classification" 2 -SELECT_ENTITIES -ALL -MERGE_CLOUDS -SAVE_CLOUDS
The last thing that kind of bothers me is the export name. I would like to use the import name and then add something like " *_after_csf ".
Ive seen the rename functionality but couldnt make it work. Maybe someone has an idea on how to do this?

Best
Marius
HeadLess
Posts: 53
Joined: Mon Mar 25, 2019 9:27 pm

Re: Batch Scalar Field operation

Post by HeadLess »

You can use batch variables to get name and apply your extension to that.

Ithink you maybe need enable delayed expansion. Since it only contains one cloud Rename_entities won't apply postfix.

Code: Select all

::Apply CSF to all .las in current directory
::--- assign class 20 to non-ground
::--- assign class 2  to ground
for %%F in (%CD%\*.las) DO (
set filename=%%~nF
 "C:\Program Files\CloudCompare\cloudcompare.exe" -SILENT -O -GLOBAL_SHIFT AUTO %%F -AUTO_SAVE OFF -C_EXPORT_FMT LAS -NO_TIMESTAMP -SF_ADD_CONST "Classification" 20 -CSF -SCENES RELIEF -PROC_SLOPE -CLOTH_RESOLUTION 2.0 -CLASS_THRESHOLD 0.5 -SELECT_ENTITIES -FIRST 1 -REMOVE_SF "Classification" -SF_ADD_CONST "Classification" 2 -SELECT_ENTITIES -ALL -MERGE_CLOUDS -RENAME_ENTITIES "%filename%_after_csf" -SAVE_CLOUDS
 )
But i would advise you to use command files instead of a long unreadable mess :). You can even check your commands if it is not correct easier to debug.
Post Reply