Skip to content

Commit ac840b9

Browse files
authored
Add netcdf support (#2335)
- Integrated `vtkNetCDFReader` into the HDF plugin for `.nc`, `.cdf`, `.ncdf` - Updated `f3d-hdf-formats.xml` with the mime-types - Added tests - Updated `SUPPORTED_FORMATS.md` to list NetCDF and include a usage example and other docs
1 parent 5c8eff0 commit ac840b9

File tree

14 files changed

+59
-6
lines changed

14 files changed

+59
-6
lines changed

.github/actions/vtk-install-dep/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ runs:
2929
uses: actions/cache/restore@v4
3030
with:
3131
path: dependencies/vtk_install
32-
key: vtk-${{ inputs.vtk_version }}${{ inputs.openvdb_version != '' && format('-openvdb-{0}', inputs.openvdb_version) || '' }}-${{runner.os}}-${{inputs.raytracing_label}}-${{inputs.cpu}}-0
32+
key: vtk-${{ inputs.vtk_version }}${{ inputs.openvdb_version != '' && format('-openvdb-{0}', inputs.openvdb_version) || '' }}-${{runner.os}}-${{inputs.raytracing_label}}-${{inputs.cpu}}-1
3333

3434
- name: Setup VTK
3535
if: steps.cache-vtk.outputs.cache-hit != 'true'
@@ -93,6 +93,7 @@ runs:
9393
-DVTK_MODULE_ENABLE_VTK_IOHDF=YES
9494
-DVTK_MODULE_ENABLE_VTK_IOImage=YES
9595
-DVTK_MODULE_ENABLE_VTK_IOImport=YES
96+
-DVTK_MODULE_ENABLE_VTK_IONetCDF=YES
9697
-DVTK_MODULE_ENABLE_VTK_IOOpenVDB=${{ inputs.openvdb_version != '' && 'YES' || 'DEFAULT' }}
9798
-DVTK_MODULE_ENABLE_VTK_IOPLY=YES
9899
-DVTK_MODULE_ENABLE_VTK_IOParallel=YES

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ find_package(VTK 9.2.6 REQUIRED
109109
opengl
110110
IOExodus
111111
IOHDF
112+
IONetCDF
112113
IOOpenVDB
113114
RenderingRayTracing)
114115
message(STATUS "VTK ${VTK_VERSION} found")

application/testing/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,14 @@ if(F3D_PLUGIN_BUILD_HDF)
833833
f3d_test(NAME TestPluginFullPath DATA disk_out_ref.ex2 ARGS --verbose --load-plugins "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_SHARED_MODULE_PREFIX}f3d-plugin-hdf${CMAKE_SHARED_MODULE_SUFFIX}" NO_BASELINE REGEXP "Loaded plugin hdf from")
834834
endif()
835835

836+
# NetCDF tests
837+
# Basic rendering test with scalar coloring
838+
f3d_test(NAME TestNetCDF DATA temperature_grid.nc ARGS --load-plugins=hdf -s)
839+
840+
if(NOT F3D_MACOS_BUNDLE)
841+
f3d_test(NAME TestDefaultConfigFileNetCDF DATA temperature_grid.nc CONFIG config_build LONG_TIMEOUT TONE_MAPPING UI)
842+
f3d_test(NAME TestThumbnailConfigFileNetCDF DATA temperature_grid.nc CONFIG thumbnail_build LONG_TIMEOUT TONE_MAPPING)
843+
endif()
836844
endif()
837845

838846
if(F3D_PLUGIN_BUILD_OCCT)

doc/dev/BUILD.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ F3D is tested continuously against versions recommended by the [VFX reference pl
2424

2525
## VTK compatibility
2626

27-
As stated in the dependencies, F3D is compatible with VTK >= 9.2.6, however, some features may not be available. We suggest using VTK 9.5.0 with RenderingRayTracing, IOExodus, IOHDF and IOOpenVDB modules enabled in order to get as many features as possible in F3D.
27+
As stated in the dependencies, F3D is compatible with VTK >= 9.2.6, however, some features may not be available. We suggest using VTK 9.5.0 with RenderingRayTracing, IOExodus, IOHDF, IONetCDF and IOOpenVDB modules enabled in order to get as many features as possible in F3D.
2828

2929
## Configuration and building
3030

@@ -46,7 +46,7 @@ Some modules, plugins and language bindings depending on external libraries can
4646
- `F3D_MODULE_RAYTRACING`: Support for raytracing rendering. Requires that VTK has been built with `OSPRay` and `VTK_MODULE_ENABLE_VTK_RenderingRayTracing` turned on. Disabled by default.
4747
- `F3D_MODULE_EXR`: Support for OpenEXR images. Requires `OpenEXR`. Disabled by default.
4848
- `F3D_MODULE_UI`: Support for ImGui widgets. Uses provided ImGui. Enabled by default.
49-
- `F3D_PLUGIN_BUILD_HDF`: Support for VTKHDF (.vtkhdf) and ExodusII (.ex2) file formats. Requires that VTK has been built with `IOHDF` and `IOExodus` modules (and `hdf5`). Enabled by default.
49+
- `F3D_PLUGIN_BUILD_HDF`: Support for VTKHDF (.vtkhdf), ExodusII (.ex2), and NetCDF (.nc) file formats. Requires that VTK has been built with `IOHDF`, `IOExodus`, and `IONetCDF` modules (and `hdf5`). Enabled by default.
5050
- `F3D_PLUGIN_BUILD_OCCT`: Support for STEP, IGES, BREP, and XBF file formats. Requires `OpenCASCADE`. Disabled by default.
5151
- `F3D_PLUGIN_BUILD_ASSIMP`: Support for FBX, DAE, OFF, DXF, X and 3MF file formats. Requires `Assimp`. Disabled by default.
5252
- `F3D_PLUGIN_BUILD_ALEMBIC`: Support for ABC file format. Requires `Alembic`. Disabled by default.

doc/user/SUPPORTED_FORMATS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ F3D supports the following file formats:
88
| VTK XML | `.vtp`, `.vtu`, `.vtr`, `.vti`, `.vts`, `.vtm` | No | No | `native` | `VTKXMLVT<P,U,R,I,S,M>` |
99
| VTKHDF | `.vtkhdf` | No | Yes | `hdf` | `VTKHDF` |
1010
| EXODUS II | `.e`, `.ex2`, `.exo`, `.g` | No | Yes | `hdf` | `ExodusII` |
11+
| NetCDF | `.nc`, `.cdf`, `.ncdf` | No | No | `hdf` | `NetCDF` |
1112
| Polygon File Format | `.ply` | No | No | `native` | `PLYReader` |
1213
| Standard Triangle Language | `.stl` | No | No | `native` | `STL` |
1314
| DICOM | `.dcm` | No | No | `native` | `DICOM` |

plugins/hdf/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,20 @@ f3d_plugin_declare_reader(
3131
CUSTOM_CODE "${CMAKE_CURRENT_SOURCE_DIR}/exodus.inl"
3232
)
3333

34+
f3d_plugin_declare_reader(
35+
NAME NetCDF
36+
EXTENSIONS nc cdf ncdf
37+
MIMETYPES application/netcdf application/x-netcdf
38+
VTK_READER vtkNetCDFReader
39+
FORMAT_DESCRIPTION "NetCDF"
40+
CUSTOM_CODE "${CMAKE_CURRENT_SOURCE_DIR}/netcdf.inl"
41+
)
42+
3443
f3d_plugin_build(
3544
NAME hdf
3645
VERSION 1.0
3746
DESCRIPTION "VTK HDF formats support"
38-
VTK_MODULES IOHDF IOExodus
47+
VTK_MODULES IOHDF IOExodus IONetCDF
3948
MIMETYPE_XML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/f3d-hdf-formats.xml"
4049
CONFIGURATION_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/configs/config.d" "${CMAKE_CURRENT_SOURCE_DIR}/configs/thumbnail.d"
4150
FREEDESKTOP

plugins/hdf/configs/config.d/10_hdf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"match-type": "glob",
4-
"match": "*.{exo,ex2,e,g,vtkhdf}",
4+
"match": "*.{exo,ex2,e,g,vtkhdf,nc,cdf,ncdf}",
55
"options": {
66
"scalar-coloring": true,
77
"load-plugins": "hdf",

plugins/hdf/configs/thumbnail.d/10_hdf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"match-type": "glob",
4-
"match": "*.{exo,ex2,e,g,vtkhdf}",
4+
"match": "*.{exo,ex2,e,g,vtkhdf,nc,cdf,ncdf}",
55
"options": {
66
"scalar-coloring": true,
77
"load-plugins": "hdf"

plugins/hdf/f3d-hdf-formats.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
<comment>VTKHDF file</comment>
1212
<glob pattern="*.vtkhdf"/>
1313
</mime-type>
14+
<mime-type type="application/netcdf">
15+
<comment>NetCDF file</comment>
16+
<glob pattern="*.nc"/>
17+
<glob pattern="*.cdf"/>
18+
<glob pattern="*.ncdf"/>
19+
</mime-type>
1420
</mime-info>

plugins/hdf/netcdf.inl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
void applyCustomReader(vtkAlgorithm* algo, const std::string&) const override
2+
{
3+
vtkNetCDFReader* ncReader = vtkNetCDFReader::SafeDownCast(algo);
4+
ncReader->UpdateInformation();
5+
6+
int numArrays = ncReader->GetNumberOfVariableArrays();
7+
for (int i = 0; i < numArrays; i++)
8+
{
9+
const char* arrayName = ncReader->GetVariableArrayName(i);
10+
if (arrayName)
11+
{
12+
ncReader->SetVariableArrayStatus(arrayName, 1);
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)