Skip to content

Commit

Permalink
feat(Pipeline): Add interface_json()
Browse files Browse the repository at this point in the history
This requires the addition of a initial "name" positional parameter for
the pipeline, which will be used for binding function name generation.
  • Loading branch information
thewtex committed Aug 31, 2022
1 parent c76fd25 commit 24bbeb7
Show file tree
Hide file tree
Showing 45 changed files with 202 additions and 76 deletions.
23 changes: 20 additions & 3 deletions doc/content/docs/interface_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ The following [`itk::wasm::Pipeline`](https://github.com/InsightSoftwareConsorti

int main(argc, char * argv[])
{
itk::wasm::Pipeline pipeline("A test ITK WASM Pipeline", argc, argv);
itk::wasm::Pipeline pipeline("TestPipeline", "A test ITK WASM Pipeline", argc, argv);

itk::wasm::InputTextStream inputTextStream;
pipeline.add_option("InputText", inputTextStream, "The input text")->required();
pipeline.add_option("InputText", inputTextStream, "The input text")->required()->type_name("INPUT_TEXT");

itk::wasm::OutputTextStream outputTextStream;
pipeline.add_option("OutputText", outputTextStream, "The output text")->required();
Expand All @@ -45,4 +45,21 @@ int main(argc, char * argv[])
<dl>
<dt><b>InputTextStream</b><dt><dd>A string. To reader this data type in C++, using the resulting <a href="https://www.cplusplus.com/reference/istream/istream/">std::istream</a>.</dd>
</dl>
</dl>
For binding generation, set the `type_name` an the options accordingly. The type names are:
- `INPUT_TEXT_FILE`
- `OUTPUT_TEXT_FILE`
- `INPUT_BINARY_FILE`
- `OUTPUT_BINARY_FILE`
- `INPUT_TEXT_STREAM`
- `OUTPUT_TEXT_STREAM`
- `INPUT_BINARY_STREAM`
- `OUTPUT_BINARY_STREAM`
- `INPUT_IMAGE`
- `OUTPUT_IMAGE`
- `INPUT_MESH`
- `OUTPUT_MESH`
- `INPUT_POLYDATA`
- `OUTPUT_POLYDATA`
2 changes: 1 addition & 1 deletion include/itkInputImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool lexical_cast(const std::string &input, InputImage<TImage> &inputImage)
return false;
}

if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
using WASMImageToImageFilterType = WASMImageToImageFilter<TImage>;
Expand Down
2 changes: 1 addition & 1 deletion include/itkInputImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool lexical_cast(const std::string &input, InputImageIO &inputImageIO)
return false;
}

if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
const unsigned int index = std::stoi(input);
Expand Down
2 changes: 1 addition & 1 deletion include/itkInputMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool lexical_cast(const std::string &input, InputMesh<TMesh> &inputMesh)
return false;
}

if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
using WASMMeshToMeshFilterType = WASMMeshToMeshFilter<TMesh>;
Expand Down
2 changes: 1 addition & 1 deletion include/itkInputMeshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool lexical_cast(const std::string &input, InputMeshIO &inputMeshIO)
return false;
}

if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
const unsigned int index = std::stoi(input);
Expand Down
2 changes: 1 addition & 1 deletion include/itkInputPolyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool lexical_cast(const std::string &input, InputPolyData<TPolyData> &inputPolyD
return false;
}

if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
using WASMPolyDataToPolyDataFilterType = WASMPolyDataToPolyDataFilter<TPolyData>;
Expand Down
2 changes: 1 addition & 1 deletion include/itkOutputImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ITK_TEMPLATE_EXPORT OutputImage

OutputImage() = default;
~OutputImage() {
if(wasm::Pipeline::GetUseMemoryIO())
if(wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
if (!this->m_Image.IsNull() && !this->m_Identifier.empty())
Expand Down
2 changes: 1 addition & 1 deletion include/itkOutputImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class OutputImageIO

OutputImageIO() = default;
~OutputImageIO() {
if(wasm::Pipeline::GetUseMemoryIO())
if(wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
if (!this->m_ImageIO.IsNull() && !this->m_Identifier.empty())
Expand Down
2 changes: 1 addition & 1 deletion include/itkOutputMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ITK_TEMPLATE_EXPORT OutputMesh

OutputMesh() = default;
~OutputMesh() {
if(wasm::Pipeline::GetUseMemoryIO())
if(wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty())
Expand Down
2 changes: 1 addition & 1 deletion include/itkOutputMeshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class OutputMeshIO

OutputMeshIO() = default;
~OutputMeshIO() {
if(wasm::Pipeline::GetUseMemoryIO())
if(wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
if (!this->m_MeshIO.IsNull() && !this->m_Identifier.empty())
Expand Down
2 changes: 1 addition & 1 deletion include/itkOutputPolyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ITK_TEMPLATE_EXPORT OutputPolyData

OutputPolyData() = default;
~OutputPolyData() {
if(wasm::Pipeline::GetUseMemoryIO())
if(wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
if (!this->m_PolyData.IsNull() && !this->m_Identifier.empty())
Expand Down
26 changes: 15 additions & 11 deletions include/itkPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
#include <CLI/App.hpp>
#include <CLI/Config.hpp>
#include <CLI/Error.hpp>

#include "itkMacro.h"

// Short circuit help output without raising an exception (currently not
// available in WASI)
#define ITK_WASM_PARSE(pipeline) \
try { \
const auto iwpArgc = (pipeline).GetArgc(); \
const auto iwpArgv = (pipeline).GetArgv(); \
const auto iwpArgc = (pipeline).get_argc(); \
const auto iwpArgv = (pipeline).get_argv(); \
for (int ii = 0; ii < iwpArgc; ++ii) \
{ \
const std::string arg(iwpArgv[ii]); \
Expand All @@ -37,6 +38,11 @@
(pipeline).exit(CLI::CallForAllHelp()); \
std::exit(0); \
} \
if (arg == "--interface-json") \
{ \
(pipeline).interface_json(); \
std::exit(0); \
} \
} \
(pipeline).parse(); \
} catch(const CLI::ParseError &e) { \
Expand Down Expand Up @@ -101,12 +107,8 @@ using CLI::Config;
class Pipeline: public CLI::App
{
public:
/** Make a new Pipeline application. */
Pipeline(std::string description, int argc, char **argv);

/** Shortcut for the lazy. */
Pipeline(int argc, char **argv)
: Pipeline("", argc, argv) {}
/** Make a new Pipeline application. `name` should be CamelCase by convention. */
Pipeline(std::string name, std::string description, int argc, char **argv);

/** Exit. */
auto exit(const CLI::Error &e) -> int;
Expand All @@ -115,21 +117,23 @@ class Pipeline: public CLI::App
CLI::App::parse(m_argc, m_argv);
}

static auto GetUseMemoryIO()
static auto get_use_memory_io()
{
return m_UseMemoryIO;
}

int GetArgc() const
int get_argc() const
{
return m_argc;
}

char ** GetArgv() const
char ** get_argv() const
{
return m_argv;
}

void interface_json();

~Pipeline() override;
private:
static bool m_UseMemoryIO;
Expand Down
4 changes: 2 additions & 2 deletions include/itkSupportInputImageTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ SupportInputImageTypes
{
InterfaceImageType imageType;

const auto iwpArgc = pipeline.GetArgc();
const auto iwpArgv = pipeline.GetArgv();
const auto iwpArgc = pipeline.get_argc();
const auto iwpArgv = pipeline.get_argv();
bool passThrough = false;
for (int ii = 0; ii < iwpArgc; ++ii)
{
Expand Down
4 changes: 2 additions & 2 deletions include/itkSupportInputImageTypesNoVectorImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ SupportInputImageTypesNoVectorImage
Dimensions(const std::string & inputImageOptionName, Pipeline & pipeline)
{
InterfaceImageTypeNoVectorImage imageType;
const auto iwpArgc = pipeline.GetArgc();
const auto iwpArgv = pipeline.GetArgv();
const auto iwpArgc = pipeline.get_argc();
const auto iwpArgv = pipeline.get_argv();
bool passThrough = false;
for (int ii = 0; ii < iwpArgc; ++ii)
{
Expand Down
4 changes: 2 additions & 2 deletions include/itkSupportInputMeshTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ SupportInputMeshTypes
{
InterfaceMeshType meshType;

const auto iwpArgc = pipeline.GetArgc();
const auto iwpArgv = pipeline.GetArgv();
const auto iwpArgc = pipeline.get_argc();
const auto iwpArgv = pipeline.get_argv();
bool passThrough = false;
for (int ii = 0; ii < iwpArgc; ++ii)
{
Expand Down
6 changes: 3 additions & 3 deletions include/itkSupportInputPolyDataTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PipelineFunctor
int
main(int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Test supporting multiple input polydata types", argc, argv);
itk::wasm::Pipeline pipeline("TestPipeline", "Test supporting multiple input polydata types", argc, argv);
// Supports the pixels types uint8_t, float
return itk::wasm::SupportInputPolyDataTypes<PipelineFunctor>
Expand All @@ -96,8 +96,8 @@ SupportInputPolyDataTypes
PixelTypes(const std::string & inputPolyDataOptionName, Pipeline & pipeline)
{
InterfacePolyDataType polyDataType;
const auto iwpArgc = pipeline.GetArgc();
const auto iwpArgv = pipeline.GetArgv();
const auto iwpArgc = pipeline.get_argc();
const auto iwpArgv = pipeline.get_argv();
bool passThrough = false;
for (int ii = 0; ii < iwpArgc; ++ii)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int compressStringify(itk::wasm::Pipeline & pipeline, itk::wasm::InputBinaryStre

int main(int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Given a binary, compress optionally base64 encode", argc, argv);
itk::wasm::Pipeline pipeline("CompressStringify", "Given a binary, compress optionally base64 encode", argc, argv);

itk::wasm::InputBinaryStream inputBinaryStream;
pipeline.add_option("InputBinary", inputBinaryStream, "Input binary");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int decodeDecompress(itk::wasm::Pipeline & pipeline)

int main(int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Given a binary or string produced with CompressedStringify, decompress optionally base64 deencode", argc, argv);
itk::wasm::Pipeline pipeline("ParseStringDecompress", "Given a binary or string produced with CompressedStringify, decompress optionally base64 deencode", argc, argv);

bool parseString = false;
pipeline.add_flag("-s,--parse-string", parseString, "Parse the input string before decompression");
Expand Down
2 changes: 1 addition & 1 deletion src/io/internal/pipelines/image/ConvertImage/ReadImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int readImage(const std::string & inputFileName, itk::wasm::OutputImageIO & outp

int main (int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Read an image file format and convert it to the itk-wasm file format", argc, argv);
itk::wasm::Pipeline pipeline("ReadImage", "Read an image file format and convert it to the itk-wasm file format", argc, argv);

std::string inputFileName;
pipeline.add_option("InputImage", inputFileName, "Input image")->required()->check(CLI::ExistingFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int writeImage(itk::wasm::InputImageIO & inputImageIO, const std::string & outpu

int main (int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Read an image file format and convert it to the itk-wasm file format", argc, argv);
itk::wasm::Pipeline pipeline("WriteImage", "Write an itk-wasm file format converted to an image file format", argc, argv);

itk::wasm::InputImageIO inputImageIO;
pipeline.add_option("InputImage", inputImageIO, "Input image")->required();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ class DICOMTagReader

int main( int argc, char * argv[] )
{
itk::wasm::Pipeline pipeline("Read the tags from a DICOM file", argc, argv);
itk::wasm::Pipeline pipeline("ReadDICOMTags", "Read the tags from a DICOM file", argc, argv);

std::string dicomFile;
pipeline.add_option("DICOMFile", dicomFile, "Input DICOM file.")->required()->check(CLI::ExistingFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ int runPipeline(itk::wasm::Pipeline & pipeline, std::vector<std::string> & input

int main (int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Read a DICOM image series and return the associated image volume", argc, argv);
itk::wasm::Pipeline pipeline("ReadImageDICOMFileSeries", "Read a DICOM image series and return the associated image volume", argc, argv);

std::vector<std::string> inputFileNames;
pipeline.add_option("-i,--input-images", inputFileNames, "File names in the series")->required()->check(CLI::ExistingFile)->expected(1,-1);
Expand Down
2 changes: 1 addition & 1 deletion src/io/internal/pipelines/mesh/ConvertMesh/ReadMesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int readMesh(const std::string & inputFileName, itk::wasm::OutputMeshIO & output

int main (int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Read an mesh file format and convert it to the itk-wasm file format", argc, argv);
itk::wasm::Pipeline pipeline("ReadMesh", "Read an mesh file format and convert it to the itk-wasm file format", argc, argv);

std::string inputFileName;
pipeline.add_option("InputMesh", inputFileName, "Input mesh")->required()->check(CLI::ExistingFile);
Expand Down
2 changes: 1 addition & 1 deletion src/io/internal/pipelines/mesh/ConvertMesh/WriteMesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int writeMesh(itk::wasm::InputMeshIO & inputMeshIO, const std::string & outputFi

int main (int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Read an mesh file format and convert it to the itk-wasm file format", argc, argv);
itk::wasm::Pipeline pipeline("WriteMesh", "Write an mesh in the itk-wasm file format to another file format", argc, argv);

itk::wasm::InputMeshIO inputMeshIO;
pipeline.add_option("InputMesh", inputMeshIO, "Input mesh")->required();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PipelineFunctor

int main (int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Convert an itk::Mesh to an itk::PolyData", argc, argv);
itk::wasm::Pipeline pipeline("MeshToPolyData", "Convert an itk::Mesh to an itk::PolyData", argc, argv);

itk::WASMMeshIOFactory::RegisterOneFactory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PipelineFunctor

int main (int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("Convert an itk::PolyData to an itk::Mesh", argc, argv);
itk::wasm::Pipeline pipeline("PolyDataToMesh", "Convert an itk::PolyData to an itk::Mesh", argc, argv);

itk::WASMMeshIOFactory::RegisterOneFactory();

Expand Down
2 changes: 1 addition & 1 deletion src/itkInputBinaryStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool lexical_cast(const std::string &input, InputBinaryStream &inputStream)
{
return false;
}
if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
const unsigned int index = std::stoi(input);
Expand Down
2 changes: 1 addition & 1 deletion src/itkInputTextStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool lexical_cast(const std::string &input, InputTextStream &inputStream)
{
return false;
}
if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
const unsigned int index = std::stoi(input);
Expand Down
4 changes: 2 additions & 2 deletions src/itkOutputBinaryStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace wasm
OutputBinaryStream
::~OutputBinaryStream()
{
if(wasm::Pipeline::GetUseMemoryIO())
if(wasm::Pipeline::get_use_memory_io())
{
if (this->m_Identifier.empty())
{
Expand Down Expand Up @@ -67,7 +67,7 @@ OutputBinaryStream

bool lexical_cast(const std::string &output, OutputBinaryStream &outputStream)
{
if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
outputStream.SetIdentifier(output);
Expand Down
4 changes: 2 additions & 2 deletions src/itkOutputTextStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace wasm
OutputTextStream
::~OutputTextStream()
{
if(wasm::Pipeline::GetUseMemoryIO())
if(wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
if (this->m_Identifier.empty())
Expand Down Expand Up @@ -67,7 +67,7 @@ OutputTextStream

bool lexical_cast(const std::string &output, OutputTextStream &outputStream)
{
if (wasm::Pipeline::GetUseMemoryIO())
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
outputStream.SetIdentifier(output);
Expand Down
Loading

0 comments on commit 24bbeb7

Please sign in to comment.