InsightSoftwareConsortium / InsightSoftwareConsortium/ITK

`IO` `Mesh` modules reading methods missing reading ability check

Open
#3,412 0 comments 0 reactions 0 assignees View on GitHub
type:Design
Dominant language
C++
Stars
1.7k
Forks
748
Avg merge
1d 1h
Merged PRs (30d)
64

Description

### Description

The `IO` modules `itk::FreeSurferAsciiMeshIO`, `itk::FreeSurferBinaryMeshIO`, `itk::OBJMeshIO`, and `itk::OFFMeshIO` classes' `ReadMeshInformation` methods do not take into account the information provided by the `CanReadFile` method, i.e. whether the file can be correctly interpreted by the class.

### Impact analysis

Despite `CanReadFile` signaling a given file format as not readable for a given class in the above list (e.g an ASCII FreeSurfer `*.fsa` file, or an ASCII VTK file `*.vtk` for the `itk::FreeSurferBinaryMeshIO` class), when the same filename is set to the class instance (i.e. `fsMeshIO->SetFileName(inputFileName)`), the `ReadMeshInformation` method tries to read the data, and the `IO` instance data might get populated with unexpected values.

Calling `CanReadFile` at the beginning of the `Read*` methods would prevent this inconsistency. A boolean should probably be returned to tell the user whether reading has been successful.

### Expected behavior

`ReadMeshInformation` methods do not attempt to read a file format that does not match the expected format.

In order to make sure that the `Read*` methods do first check whether the file format is readable, it would suffice to add, e.g. for the `itk::FreeSurferMeshIO*` test:
```
fsMeshIO->SetFileName(notAFsInputFileName);
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->ReadMeshInformation());
```

### Actual behavior

`ReadMeshInformation` methods attempt to read a file format that `CanReadFile` tells they cannot read.

### Versions

ITK `master`.

### Additional Information

Related to PR #3403.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.