Skip to content

Matlab API: various bug fixes#47

Merged
CarawaySeed42 merged 9 commits into
masterfrom
matlab-api-various-fixes
Mar 11, 2026
Merged

Matlab API: various bug fixes#47
CarawaySeed42 merged 9 commits into
masterfrom
matlab-api-various-fixes

Conversation

@CarawaySeed42

Copy link
Copy Markdown
Contributor

Fix bugs where OpenCRG Matlab API functions would not handle arguments correctly,
remove necessary components of the CRG header, introduce unwanted coordinate shifts,
or rely on optional header entries.

Resolves: #9

Signed-off-by: Patrick Kuemmerle patrick.kuemmerle@3d-mapping.de


Remaining issues:

The crg rerender function did not handle the increment arguments correctly
which let to issues which are hard to understand for the caller.

Signed-off-by: Patrick Kuemmerle <patrick.kuemmerle@3d-mapping.de>
Fix bugs where OpenCRG Matlab API would not handle arguments correctly,
remove necessary components of the CRG header, introudce unwanted coordinate shifts,
or rely on optional header entries.

Resolves: #9

Signed-off-by: Patrick Kuemmerle <patrick.kuemmerle@3d-mapping.de>
@CarawaySeed42 CarawaySeed42 added this to the v1.2.2 milestone Dec 15, 2025
@CarawaySeed42 CarawaySeed42 added the isState:ReadyforCCBreview CCB will review it and change the status to ReadyForMerge if everything is ok label Dec 15, 2025
@yash-shah-asam

Copy link
Copy Markdown
Contributor

ASAM OpenCRG CCB 2025 12 15: Approved and can be merged for the next release.

@asadekasam asadekasam added isState:ReadyforMerge An issue that has been reviewed by CCB and can be merged and removed isState:ReadyforCCBreview CCB will review it and change the status to ReadyForMerge if everything is ok labels Jan 12, 2026

@jorauh jorauh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like fault tolerance, so I suggest to

  • improve documentation
  • implement argument checking with useful error messages.
    Fault tolerance hides users's mis-understanding and increases further fault risks.

If you are ok with that, may I give some proposal?
e.g.
% V vector of v values (single)
% length(v) == 1: defines half width of road (postive value)
% length(v) == 2: defines right/left edge of road [vmin vmax]
% length(v) == nv: defines length cut positions [vmin ... vmax]

case 1
if v < 0 error ...
case 2
if v(1) >= v(2) error ...
case 3
... (check for increasing values)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the crg struct is successfully checked, poff is always defined (see crg_check_data.m)
The idea behind is to avoid this kind of individual checks in all routines by providing a complete check of all structure elements at single check routines.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an older "bug fix" used in our company and I can not tell you why this was changed but I agree that it should be unnecessary

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was introduced as easy workaround, otherwise crg_cut_iuiv using an CRG which has an mpro field does not work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was the crg_cut_iuiv function, where poff was erroneously omitted. This issue is addressed in the latest commit

@jorauh jorauh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose these are mostley errors due to missing checks, which should guarantee a complete crg struct. Please let us look for the real reasons behind the problems and not fix them later in individual routines - we will never find all of them.

@CarawaySeed42 CarawaySeed42 added isState:InProgress An issue that is assigned a responsible, has a due date and clear requirements and removed isState:ReadyforMerge An issue that has been reviewed by CCB and can be merged labels Jan 25, 2026
@CarawaySeed42

CarawaySeed42 commented Jan 25, 2026

Copy link
Copy Markdown
Contributor Author

#47 (review)
I agree on removing fault tolerance and replacing it with useful error messages.

#47 (review)
I agree that the proposed bug fixes are higher level band aid fixes.
The underlying problem is that some api functions break a valid input crg struct, call crg check and then report an error because they themself or the crg check broke it. I assume the solution to that, years ago, was to delete header entries until the error was gone without proper testing.

Fixing the underlying problem is obviously preferrable but someone has to spend the time to get to the root of the problems, test every possible combination of valid crg header parameters with all api functions because the crg check surely has to be changed and preferrably write unit tests.

But I am open to discuss how to tackle these bugs. This will also lead to the general problems with the map projection that many api functions cant handle properly (see #10 (comment))

@CarawaySeed42
CarawaySeed42 marked this pull request as draft January 25, 2026 18:21
@jorauh

jorauh commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

If we introduce workarounds, we will worsen the long-term stability of opencrg. Even though analyzing (and fixing) problems may seem difficult, this is the only way to ensure that we will continue to have a stable product in the long term.
We will hardly be able to achieve complete coverage of all possibilities through testing. But if we are prepared to address and resolve reported errors and problems promptly, as we have done in the past, we will soon be back to a stable state. Please help to highlight known problems with the MATLAB toolset; I am ready to contribute to the solution.

If the introduction of map projections in Release 1.2.0 has not yet been fully implemented in a number of MATLAB tools, that is another task.

@CarawaySeed42

CarawaySeed42 commented Jan 26, 2026

Copy link
Copy Markdown
Contributor Author

Agreed, then the only bug fixes we keep from these commits are proper numerical function argument checks but removing fault tolerances and the ones where position information is thrown away for no reason

Undoing workarounds that would prevent errors
due to the underlying crg check issues.

Signed-off-by: Patrick Kuemmerle <patrick.kuemmerle@3d-mapping.de>
Remove fault tolerance, check arguments and throw error
on invalid arguments.

Signed-off-by: Patrick Kuemmerle <patrick.kuemmerle@3d-mapping.de>
Without copying poff the crg check would
fail if mpro is present.

Signed-off-by: Patrick Kuemmerle <patrick.kuemmerle@3d-mapping.de>
@CarawaySeed42
CarawaySeed42 marked this pull request as ready for review February 2, 2026 09:01
@CarawaySeed42
CarawaySeed42 requested a review from jorauh February 2, 2026 09:01
@CarawaySeed42 CarawaySeed42 added isState:ReadyforCCBreview CCB will review it and change the status to ReadyForMerge if everything is ok and removed isState:InProgress An issue that is assigned a responsible, has a due date and clear requirements labels Feb 2, 2026
@CarawaySeed42

Copy link
Copy Markdown
Contributor Author

Workarounds have been removed again.
crg_ext_slope and crg_ext_banking reverted back to removing position information!

@asadekasam asadekasam added isState:InProgress An issue that is assigned a responsible, has a due date and clear requirements and removed isState:ReadyforCCBreview CCB will review it and change the status to ReadyForMerge if everything is ok labels Feb 9, 2026
@asadekasam

Copy link
Copy Markdown
Contributor

OpenCRG 2026.02.09: @CarawaySeed42 & @jorauh are still working on it.

The extract slope and banking functions introduced or
removed offsets from the data.

Signed-off-by: Patrick Kuemmerle <patrick.kuemmerle@3d-mapping.de>
@CarawaySeed42

Copy link
Copy Markdown
Contributor Author

Latest commit introduced a workaround free solution for extract slope and banking functions, when considering the master branch code as not a workaround.

@CarawaySeed42 CarawaySeed42 added isState:ReadyforCCBreview CCB will review it and change the status to ReadyForMerge if everything is ok and removed isState:InProgress An issue that is assigned a responsible, has a due date and clear requirements labels Feb 23, 2026
@jorauh

jorauh commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

@CarawaySeed42 :
I suggest to continue work on this branch/PR until I did some further fixes on crg_append and maybe related functions.
The current status is quite error-prone, so I will even remove some previously available (only somtimes working) functionality and add somee missing (as in crg_cut_iuiv).
These "editing" functions (cut, append, ...) were introduced long time ago, and nobody took care about consequences when using the geo-referencing (previously with lon/lat in header only and currently with the mpro).
Any things I also should have a deeper look into?
OK with that?

@CarawaySeed42

Copy link
Copy Markdown
Contributor Author

@jorauh
That is fine by me.
Yes, there are a lot of issues with lon/lat/mpro. One thing I found, but have not tested extensively yet is, that
crg_check_wgs84 is called twice during the crg_check. Once during crg_check_head and towards the end of crg_check.
A function that modifies the refline usually let's crg_check recalculate said refline, but that doesn't work because the geographic coordinates are often dependent on crg_check_data which runs later.
In short: My guess is, that removing crg_check_wgs84 from crg_check_head might make the proper support of lat/lon/mpro a lot easier, but again, I have not tested it extensively. But crg_check_wgs84 definitely shouldn't run twice.

@CarawaySeed42

Copy link
Copy Markdown
Contributor Author

One more addition to handling lat/lon and mpro in API functions modifying the refline:
If you have a map projection the crg check can always recalculate the geographcial coordinates after modifying the refline.
If you don't have one then it gets a little bit more involved unless you just omit lat/lon altogether.

@jorauh jorauh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting to merge this PR, since my further fixes on the georeferencing topics will take some more time.

fixed error: added missing dim argument to size function

removed  dead code to write unknown header element data.head.rccl

corrected some comments
@jorauh

jorauh commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

One more fix for crg_write which didn't work on current matlab release.

Comment thread matlab/lib/crg_write.m
default = crg_check_opts(default);
f = fieldnames(opts);
for i = 1:size(f)
for i = 1:size(f, 1)

@CarawaySeed42 CarawaySeed42 Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i = 1:numel(f) would be independent of the size/dimension of f, but this is good as well

Otherwise no objections to the commited changes to crg_write

@jorauh

jorauh commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

One more addition to handling lat/lon and mpro in API functions modifying the refline: If you have a map projection the crg check can always recalculate the geographcial coordinates after modifying the refline. If you don't have one then it gets a little bit more involved unless you just omit lat/lon altogether.

This is not always possible: if the modifiers e.g. scale the refline, the map projection becomes invalid. I will handle this and further cases in #77

@CarawaySeed42

Copy link
Copy Markdown
Contributor Author

True, my answer was directed towards cutting or appending CRGs.

@asadekasam

Copy link
Copy Markdown
Contributor

OpenCRG CCB 2026.03.09: Ready for merge

@asadekasam asadekasam added isState:ReadyforMerge An issue that has been reviewed by CCB and can be merged and removed isState:ReadyforCCBreview CCB will review it and change the status to ReadyForMerge if everything is ok labels Mar 9, 2026
@CarawaySeed42
CarawaySeed42 merged commit c00a2a6 into master Mar 11, 2026
@CarawaySeed42
CarawaySeed42 deleted the matlab-api-various-fixes branch March 11, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isState:ReadyforMerge An issue that has been reviewed by CCB and can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Matlab-API: Bug fixes

5 participants