As a parallel to @berk.geveci’s post on more pythonic wrappers (and particularly @jaswantp’s example, I’d like input on how we might use modern C++ and the nlohmann::json to achieve something similar in native C++.
Here’s @jaswantp’s example ported to an imaginary C++ example:
auto pipeline =
vtk::Pipeline<vtkElevationFilter>()
.connect<vtkStrinkFilter>({{"ShrinkFactor", 0.3}})
.connect<vtkGeometryFilter>()
.connect<vtkPolyDataConnectivityFilter>({
{"ColorRegions", true},
{"ExtractionMode", VTK_EXTRACT_ALL_REGIONS}})
.connect<vtkPolyDataNormals>()
;
auto cone =
vtk::Pipeline<vtkConeSource>({
{"Radius", 5}, {"Resolution", 8}, {"Height", 2}
}).execute();
vtk::Show(pipeline.execute(cone));
auto cylinder =
vtk::Pipeline<vtkCylinderSource>({
{"Radius", 6}, {"Resolution", 9}, {"Height", 3}
}).execute();
vtk::Show(pipeline.execute(cylinder));
Unlike python, the vtk::Pipeline<Filter>(filterParams)
template could return a new object with additional templated methods such as “connect<Filter>(filterParams)
”, “execute(vtkDataObject* data)
”, “tee(pipeline1, pipeline2)
”, etc.
The filterParams
argument would be an initializer-list used to construct nlohmann::json
and some wrapper-like code could turn the JSON data into calls on the constructed filter.