Skip to content

Commit

Permalink
Be more tolerant when loading files with a missing spot.
Browse files Browse the repository at this point in the history
Normally this would cause the reading of the edges and tracks to
stop immediatelly.
Now a warning is printed, but the other edges are imported.
  • Loading branch information
tinevez committed Jul 7, 2024
1 parent 70b0f57 commit bb10ad3
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/main/java/fiji/plugin/trackmate/io/TmXmlReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
Expand Down Expand Up @@ -936,7 +936,7 @@ private SpotCollection getSpots( final Element modelElement )
*/
protected boolean readTracks( final Element modelElement, final Model model )
{

boolean ok = true;
final Element allTracksElement = modelElement.getChild( TRACK_COLLECTION_ELEMENT_KEY );
final List< Element > trackElements = allTracksElement.getChildren( TRACK_ELEMENT_KEY );

Expand Down Expand Up @@ -984,19 +984,22 @@ protected boolean readTracks( final Element modelElement, final Model model )
// Error check
if ( null == sourceSpot )
{
logger.error( "Unknown spot ID: " + sourceID + "\n" );
return false;
logger.error( "Unknown spot ID: " + sourceID + " - skipping edge " + sourceID + " → " + targetID + ".\n" );
ok = false;
continue;
}
if ( null == targetSpot )
{
logger.error( "Unknown spot ID: " + targetID + "\n" );
return false;
logger.error( "Unknown spot ID: " + targetID + " - skipping edge " + sourceID + " → " + targetID + ".\n" );
ok = false;
continue;
}

if ( sourceSpot.equals( targetSpot ) )
{
logger.error( "Bad link for track " + trackID + ". Source = Target with ID: " + sourceID + "\n" );
return false;
ok = false;
continue;
}

/*
Expand All @@ -1015,7 +1018,8 @@ protected boolean readTracks( final Element modelElement, final Model model )
if ( edge == null )
{
logger.error( "Bad edge found for track " + trackID + "\n" );
return false;
ok = false;
continue;
}

graph.setEdgeWeight( edge, weight );
Expand Down Expand Up @@ -1064,7 +1068,7 @@ protected boolean readTracks( final Element modelElement, final Model model )
*/
model.getTrackModel().from( graph, connectedVertexSet, connectedEdgeSet, visibility, savedTrackNames );

return true;
return ok;
}

/**
Expand Down

0 comments on commit bb10ad3

Please sign in to comment.