Moving and rotating a point cloud in e57 format

Feel free to ask any question here
raitisx
Posts: 6
Joined: Sun Feb 19, 2023 9:54 pm

Re: Moving and rotating a point cloud in e57 format

Post by raitisx »

Latest stable - 2.12.4
The latest alpha has the same problem.

here are a couple of scans:
https://files.fm/u/qg5ke7f7p

should apply a scale of 0.9996


is it possible to automate this operation via CLI?
I saw only APPLY_TRANS, but even after extraction of each scan center point, I couldn't manage it to work.

Code: Select all

@echo off
setlocal enableDelayedExpansion

set input_dir=Z:\new_transformed\

REM Scaling factor
set scale=0.9996

REM Read pose center coordinates from text file
set pose_file=pose_centers.txt

for /f "usebackq tokens=2,3,4 delims=," %%a in ("%pose_file%") do (
    REM Calculate the translation vector to shift the point cloud to the coordinate center
    set tx=%%a
    set ty=%%b
    set tz=%%c
    set /a tx=-1*!tx!
    set /a ty=-1*!ty!
    set /a tz=-1*!tz!

    REM Generate the transformation matrix for each file
    set trans_file=trans_matrix.txt
    echo !scale! 0.0000 0.0000 0.0000 > !trans_file!
    echo 0.0000 !scale! 0.0000 0.0000 >> !trans_file!
    echo 0.0000 0.0000 !scale! 0.0000 >> !trans_file!
    echo !tx! !ty! !tz! 1.0000 >> !trans_file!

    REM Apply the transformation to each file
    for %%i in ("%input_dir%\*.e57") do (
        REM Extract the filename and extension
        set input_file=%%i
        for %%j in ("!input_file!") do set input_name=%%~nj
        for %%j in ("!input_file!") do set input_ext=%%~xj

        REM Generate the output filename
        set output_file=\!input_name!!input_ext!

        REM Apply the transformation and save the output cloud
        cloudcompare.exe -SILENT -NO_TIMESTAMP -C_EXPORT_FMT E57 -O "%%i" -APPLY_TRANS trans_matrix.txt -SAVE_CLOUDS FILE "%output_file%"
    )

    REM Remove the transformation matrix file
    del %trans_file%

    REM Exit the loop 
    exit
)

endlocal
pause
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Moving and rotating a point cloud in e57 format

Post by daniel »

I believe you need to add '-GLOBAL_SHIFT AUTO' after -O? (or a particular shift at least)

(and I am still confused about the fact that you said that the clouds were 'all rotated' while you were not applying any transformation in your described workflow...)
Daniel, CloudCompare admin
raitisx
Posts: 6
Joined: Sun Feb 19, 2023 9:54 pm

Re: Moving and rotating a point cloud in e57 format

Post by raitisx »

Try to scale 0.9996 via GUI both files, after setting Global shift exactly to each file scan center.

Export to e57.

Load transformed files again in CC - you'll see, that wires in the middle from each scan do not align.


CLI script is separate problem, let's fix it later.
raitisx
Posts: 6
Joined: Sun Feb 19, 2023 9:54 pm

Re: Moving and rotating a point cloud in e57 format

Post by raitisx »

Could you tell if this is CC behaviour, (will it be fixed?) or there is something I missed?
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Moving and rotating a point cloud in e57 format

Post by daniel »

<< Try to scale 0.9996 via GUI both files, after setting Global shift exactly to each file scan center. >>

How are you 'scaling' the coordinates? With the 'Edit > Multiply/Scale' method or with the 'Edit > Apply transformation' tool? If it's the latter, how are you managing the Z dimension? Should it also be scaled from the center or from 0?

EDIT: the matrix you use should be fine (I had some doubts, but it's due to a glitch in the second panel of the tool).
Daniel, CloudCompare admin
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Moving and rotating a point cloud in e57 format

Post by daniel »

And I'm not sure to understand why the scaling point would be the center of each clouds?
Daniel, CloudCompare admin
raitisx
Posts: 6
Joined: Sun Feb 19, 2023 9:54 pm

Re: Moving and rotating a point cloud in e57 format

Post by raitisx »

Probably I did not express problem correctly before, but rereading now, can't see why. 'Edit > Multiply/Scale' method doesn't work as somehow rotations are always changed. Anyway, solved this yesterday, and here are all steps.

Scanned city.
Registration in original coordinate system (which has scale 0.9996 there), didn't work well with original Leica files, as those were in 1.0
Scaled all GCP's to 1.0 around one particular point, then registered all scans and exported to e57.
Shifted all scans back to their original locations.
Internal scan scale is still 1.0, so objects further away from scan origin are not aligned well with nearby scans (4cm at 100m)

Used transformation matrix file

Code: Select all

0.9996 0.0000 0.0000 0.0000
0.0000 0.9996 0.0000 0.0000
0.0000 0.0000 1.0000 0.0000
0.0000 0.0000 0.0000 1.0000
Generated scan centers, little bit of excel fun, then this worked correctly:

CloudCompare.exe -SILENT -O -GLOBAL_SHIFT -501111.07 -312345.18 -5.53 D:\182.e57 -APPLY_TRANS D:\trans_matrix.txt -AUTO_SAVE OFF -C_EXPORT_FMT E57 -SAVE_CLOUDS
Post Reply