Skip to content

[New Component] Addition of new methods based on jira issue number 105 - #2

Open
bouamarakamelia wants to merge 8 commits into
masterfrom
dev_kamelia_new_methods_to_comp
Open

[New Component] Addition of new methods based on jira issue number 105#2
bouamarakamelia wants to merge 8 commits into
masterfrom
dev_kamelia_new_methods_to_comp

Conversation

@bouamarakamelia

Copy link
Copy Markdown

1. Description

Extends SkeletonGraph/SkeletonReader with node-level query methods (parents, children, path from root, subtree) and a new human-readable CSV export, so the skeleton tree can be inspected per-node without needing ParaView or writing custom code.

2. Newest features

node(nodeId) : safe lookup by id

  • Bounds-checked accessor into m_nodes.
  • Returns nullptr for an invalid id instead of crashing.
  • Is the foundation every other new method builds on.

parentsOf(nodeId) / childrenOf(nodeId)

  • Direct accessors returning a node's parent/children id lists.
  • Invalid id → empty vector, not a crash.
  • Thin wrappers around node().

pathFromRoot(nodeId)

  • Walks each node's primary parent (parentIds().front()) back to the root, then reverses the result to get root → ... → nodeId, inclusive.
  • Guards against a cyclic parent chain with a visited-set check, bailing out to an empty path rather than looping forever.

subtree(nodeId)

  • Breadth-first traversal outward through childrenIds, collecting every node reachable from nodeId (itself included).
  • Correctly reflects loop edges: a node that gained an extra child from a loop is not treated as a dead end.

exportReportCSV(filename)

  • Writes one row per node: id, x, y, z, parentId, childrenIds, pathFromRoot, loopParentIds. parentId is the single primary (tree) parent for the common case; any extra parent from a loop-closing node is kept in a separate loopParentIds column so nothing is silently dropped.
  • Wired into SkeletonReader as a new output Data field, outputReport.

3. Results

  • exportReportCSV compiled and run for real against what we have;
  • output matches expected values exactly, e.g.:
    id,x,y,z,parentId,childrenIds,pathFromRoot,loopParentIds
    2,0.0,0.0,2.0,1,"3;5","0;1;2",""
    6,-2.0,0.0,4.0,5,"","0;1;2;5;6","4"
    
  • Wired into the scene via outputReport="report.csv" on <SkeletonReader/>, no other component or file affected.
image

4. Example of the componenet in the scene (use case)

        <SkeletonReader name="reader"
            filename="outputfilefromtheMeshSkeletonizationOutput.txt"
            inputVertices="@loader.position"
            outputVTK="output.vtk"
            outputReport="output.csv" />

@epernod epernod added pr: clean pr: enhancement pr: status to review To notify reviewers to review this pull-request labels Aug 10, 2026
@epernod
epernod force-pushed the dev_kamelia_new_methods_to_comp branch from f8c4580 to fa0a675 Compare August 13, 2026 10:04
Comment thread src/MeshSkeletonizationPlugin/SkeletonGraph/SkeletonGraph.cpp Outdated
Comment thread src/MeshSkeletonizationPlugin/SkeletonGraph/SkeletonGraph.cpp Outdated
path.push_back(cur);
if (cur == m_rootId) break;
const auto& parents = parentsOf(cur);
if (parents.empty()) return {};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure to get this return, if you loop several time and suddently there si no more parents, it means you reach the root node no? For me you should exit the while loop and return path no?

Suggested change
if (parents.empty()) return {};
if (parents.empty()) { std::reverse(path.begin(), path.end()); return path;}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think this one should stay as-is, though the code didn't make the reason clear enoug
my fault, I've added a comment.

The root case is already handled by the check immediately above: ligne

if (cur == m_rootId) break;      // root exits here
if (!parentsOf(cur, parents))    // so reaching this means: parentless AND not the root

So this branch only fires for a node whose parent chain never reaches the root . For esample, a vertex in a component disconnected from it.
If we reversed and returned the path there, the caller would get back a sequence that doesn't start at the root, with no way to tell it apart from a valid one. That would show up directly in the pathFromRoot column of the CSV export as plausible-looking but wrong paths for orphaned nodes.

Returning empty keeps the contract simple: a non-empty result always starts at the root and ends at the requested node.

const std::vector<int>& childrenOf(int nodeId) const;
std::vector<int> pathFromRoot(int nodeId) const;
std::vector<int> subtree(int nodeId) const;
void exportReportCSV(const std::string& filename) const;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what does this report do? just add a comment: ///< export CSV report using @sa d_outReportFilename that will...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added

sofa::core::objectmodel::DataFileName d_inSkeletonFilename; ///< Path to the skeleton polyline file to read (e.g. skeleton.txt)
sofa::core::objectmodel::Data<VecCoord> d_inVertices; ///< Optional input mesh vertices, to link skeleton nodes to the mesh
sofa::core::objectmodel::Data<Vec3> d_inEntryPoint; ///< Approx. entry point; closest node becomes the tree root
sofa::core::objectmodel::DataFileName d_outReportFilename; /// CSV report that guves out the ide, 3D coordinates, parent vertice and child vertice

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
sofa::core::objectmodel::DataFileName d_outReportFilename; /// CSV report that guves out the ide, 3D coordinates, parent vertice and child vertice
sofa::core::objectmodel::DataFileName d_outReportFilename; /// CSV report that gives out the ids, 3D coordinates, parent vertex and child vertex

vertex or vertices

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

@bouamarakamelia

Copy link
Copy Markdown
Author

@epernod it's done and ready for correction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: clean pr: enhancement pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants