Skip to content

mm2txt, mm2ply: don't emit columns of zeros for missing user-given fields#36

Merged
jlblancoc merged 1 commit intodevelopfrom
feat/mm2txt-missing-fields-dont-emit
Feb 1, 2026
Merged

mm2txt, mm2ply: don't emit columns of zeros for missing user-given fields#36
jlblancoc merged 1 commit intodevelopfrom
feat/mm2txt-missing-fields-dont-emit

Conversation

@jlblancoc
Copy link
Copy Markdown
Member

@jlblancoc jlblancoc commented Feb 1, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Per-layer field validation for exports to ensure only existing fields are written.
    • If a layer has no valid fields, that layer is skipped and a warning is emitted.
    • Improved missing-field warnings now list available fields and note when a field is skipped.
  • Documentation

    • Updated PLY/TXT export docs: missing fields produce warnings (no zero-padding) and errors are suppressed when the ignore-missing option is used.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 1, 2026

📝 Walkthrough

Walkthrough

Point cloud export workflows in mm2ply and mm2txt now validate requested export fields against actual fields in each layer, building filtered field lists before export. Missing fields trigger warnings and are skipped; errors only occur when the --ignore-missing-fields flag is absent. Documentation updated accordingly.

Changes

Cohort / File(s) Summary
Export Field Validation
apps/mm2ply/main.cpp, apps/mm2txt/main.cpp
Introduce per-layer validation that builds a validFields list by filtering requested fields against the layer's actual fields. Missing fields emit warnings (listing available fields) and are skipped; an error is thrown only if --ignore-missing-fields is not set. Export calls now pass validFields.
Documentation Updates
docs/source/app_mm2ply.rst, docs/source/app_mm2txt.rst
Update --ignore-missing-fields descriptions: remove zero-padding behavior, clarify missing-field warnings, and note that errors are conditional on the absence of the ignore flag.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰
Fields hop in rows and columns bright,
I sniff and sort each layer's light,
Skip the gaps that are not there,
Warn a little, then beware —
Hooray! The PLY/TXT hops out right.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: preventing zero-filled columns from being emitted for missing user-specified fields in both mm2txt and mm2ply tools.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/mm2txt-missing-fields-dont-emit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
apps/mm2ply/main.cpp (3)

421-530: ⚠️ Potential issue | 🔴 Critical

Default export path is skipped when --export-fields isn’t provided.

saveToPly() is only called inside if (!selectedFields.empty()), so the common case (no field selection) produces no output. Please add an else branch to preserve the default export behavior.

💡 Proposed fix
         for (const auto& [name, layer] : mm.layers)
         {
             auto* pts = mp2p_icp::MapToPointsMap(*layer);
             if (!pts)
             {
                 continue;
             }

             // Validate selected fields exist in this point cloud
             if (!selectedFields.empty())
             {
                 ...
                 saveToPly(*pts, out, arg_binary.getValue(), validFields);
             }
+            else
+            {
+                std::string out = prefix + "_" + name + ".ply";
+                std::cout << "Exporting '" << name << "' to " << out << "..." << std::endl;
+                saveToPly(*pts, out, arg_binary.getValue());
+            }
         }

439-529: ⚠️ Potential issue | 🟠 Major

When all requested fields are missing, you end up exporting all fields.

If every requested field is missing and --ignore-missing-fields is set, validFields stays empty and saveToPly() interprets that as “export all fields.” That contradicts the user’s selection intent. Consider skipping the layer (or emitting an empty-header file) when validFields is empty but selectedFields was explicit.

💡 Suggested guard
                 for (const auto& field : selectedFields)
                 {
                     ...
                     else
                     {
                         validFields.push_back(field);
                     }
                 }
+                if (validFields.empty())
+                {
+                    std::cerr << "Warning: None of the requested fields exist in layer '" << name
+                              << "'. Skipping export for this layer." << std::endl;
+                    continue;
+                }
                 std::string out = prefix + "_" + name + ".ply";
                 std::cout << "Exporting '" << name << "' to " << out << "..." << std::endl;
                 saveToPly(*pts, out, arg_binary.getValue(), validFields);

49-53: ⚠️ Potential issue | 🟡 Minor

CLI help text still claims missing fields are padded with zeros.

The --ignore-missing-fields description is now stale; behavior is “warn and skip,” not “pad with zeros.”

✏️ Proposed wording update
 TCLAP::SwitchArg argIgnoreMissingFields(
     "", "ignore-missing-fields",
     "If defined, the lack of any of the --export-fields in the map will be considered a warning "
-    "instead of an error, and that column will be padded with zeros.",
+    "instead of an error; missing fields are skipped.",
     cmd);
apps/mm2txt/main.cpp (2)

299-362: ⚠️ Potential issue | 🟠 Major

All-missing field selection falls back to exporting all fields.

If selectedFields is explicit but none exist (and --ignore-missing-fields is set), validFields becomes empty and saveToTxt() exports all fields by design. That undermines the user’s selection intent. Consider skipping the layer (or outputting an empty-header file) when validFields is empty but a selection was provided.

💡 Suggested guard
             if (!selectedFields.empty())
             {
                 ...
                 for (const auto& field : selectedFields)
                 {
                     ...
                     else
                     {
                         validFields.push_back(field);
                     }
                 }
+                if (validFields.empty())
+                {
+                    std::cerr << "Warning: None of the requested fields exist in layer '" << name
+                              << "'. Skipping export for this layer." << std::endl;
+                    continue;
+                }
             }
             else
             {
                 validFields = selectedFields;
             }

             bool printHeader = true;
             saveToTxt(*genxyz, filName, printHeader, validFields);

57-61: ⚠️ Potential issue | 🟡 Minor

CLI help text still mentions “padded with zeros.”

The current behavior is to skip missing fields; the help text should match.

✏️ Proposed wording update
 TCLAP::SwitchArg argIgnoreMissingFields(
     "", "ignore-missing-fields",
     "If defined, the lack of any of the --export-fields in the map will be considered a warning "
-    "instead of an error, and that column will be padded with zeros.",
+    "instead of an error; missing fields are skipped.",
     cmd);

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.03%. Comparing base (5ed30ea) to head (8700cb7).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop      #36   +/-   ##
========================================
  Coverage    77.03%   77.03%           
========================================
  Files          179      179           
  Lines         9526     9526           
  Branches       917      917           
========================================
  Hits          7338     7338           
  Misses        2188     2188           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jlblancoc jlblancoc force-pushed the feat/mm2txt-missing-fields-dont-emit branch from d47ad05 to 8700cb7 Compare February 1, 2026 22:45
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/mm2txt/main.cpp (1)

319-346: ⚠️ Potential issue | 🟡 Minor

Avoid “skipping” warning when an error is thrown.

When --ignore-missing-fields is not set, the code throws, so “skipping this field” is misleading. Consider branching the message based on the flag.

📝 Suggested message branching
-                        std::cerr << " - skipping this field." << std::endl;
-                        if (!argIgnoreMissingFields.isSet())
-                        {
-                            THROW_EXCEPTION_FMT(
-                                "Field '%s' specified in --export-fields not found in layer '%s'",
-                                field.c_str(), name.c_str());
-                        }
+                        if (argIgnoreMissingFields.isSet())
+                        {
+                            std::cerr << " - skipping this field." << std::endl;
+                        }
+                        else
+                        {
+                            std::cerr << " - aborting export." << std::endl;
+                            THROW_EXCEPTION_FMT(
+                                "Field '%s' specified in --export-fields not found in layer '%s'",
+                                field.c_str(), name.c_str());
+                        }

@jlblancoc
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 1, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jlblancoc jlblancoc enabled auto-merge February 1, 2026 22:51
@jlblancoc jlblancoc merged commit e217dd1 into develop Feb 1, 2026
13 checks passed
@jlblancoc jlblancoc deleted the feat/mm2txt-missing-fields-dont-emit branch February 1, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant