Ver código fonte

Added skeleton for two CLI modules.

Sascha Zelzer 13 anos atrás
pai
commit
2c082fc64e

+ 2 - 0
Libs/ModuleDescription/Testing/CLIModules/Blur2dImage/CMakeLists.txt

@@ -0,0 +1,2 @@
+
+ctkFunctionCreateCLIModule(Blur2dImage)

+ 71 - 0
Libs/ModuleDescription/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.cpp

@@ -0,0 +1,71 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#include <ctkCommandLineParser.h>
+
+#include <QCoreApplication>
+#include <QTextStream>
+#include <QFile>
+
+int main(int argc, char* argv[])
+{
+  QCoreApplication app(argc, argv);
+  // This is used by QSettings
+  QCoreApplication::setOrganizationName("CommonTK");
+  QCoreApplication::setApplicationName("CLIModuleBlur2dImage");
+
+  ctkCommandLineParser parser;
+  // Use Unix-style argument names
+  parser.setArgumentPrefix("--", "-");
+
+  // Add command line argument names
+  parser.addArgument("help", "h", QVariant::Bool, "Show this help text");
+  parser.addArgument("xml", "", QVariant::Bool, "Print a XML description of this modules command line interface");
+
+  // Parse the command line arguments
+  bool ok = false;
+  QHash<QString, QVariant> parsedArgs = parser.parseArguments(QCoreApplication::arguments(), &ok);
+  if (!ok)
+  {
+    QTextStream(stderr, QIODevice::WriteOnly) << "Error parsing arguments: "
+                                              << parser.errorString() << "\n";
+    return EXIT_FAILURE;
+  }
+
+  // Show a help message
+  if (parsedArgs.contains("help") || parsedArgs.contains("h"))
+  {
+    QTextStream(stdout, QIODevice::WriteOnly) << parser.helpText();
+    return EXIT_SUCCESS;
+  }
+
+  if (parsedArgs.contains("xml"))
+  {
+    QFile xmlDescription(":/ctkCLIModuleBlur2dImage.xml");
+    xmlDescription.open(QIODevice::ReadOnly);
+    QTextStream(stdout, QIODevice::WriteOnly) << xmlDescription.readAll();
+    return EXIT_SUCCESS;
+  }
+
+  // Do something
+
+  return EXIT_SUCCESS;
+}

+ 5 - 0
Libs/ModuleDescription/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.qrc

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>ctkCLIModuleBlur2dImage.xml</file>
+    </qresource>
+</RCC>

+ 93 - 0
Libs/ModuleDescription/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.xml

@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<executable>
+  <category>Image Filter</category>
+  <title>2D Blurring</title>
+  <description>
+Blur a 2d image.
+  </description>
+  <version>1.0</version>
+  <documentation-url></documentation-url>
+  <license></license>
+  <contributor>Sascha Zelzer</contributor>
+
+  <parameters>
+    <label>Scalar Parameters</label>
+    <description>
+    Variations on scalar parameters
+    </description>
+    <integer>
+      <name>integerVariable</name>
+      <flag>i</flag>
+      <longflag>integer</longflag>
+      <description>
+      An integer without constraints
+      </description>
+      <label>Integer Parameter</label>
+      <default>30</default>
+    </integer>
+    <boolean>
+      <name>booleanParam</name>
+      <flag>b</flag>
+      <description>
+      A boolean without constraints
+      </description>
+      <label>Boolean Parameter</label>
+    </boolean>
+    <file>
+    <name>fileVar</name>
+    <index>3</index>
+    <description>Some file</description>
+    <label>Some file</label>
+    <default>bla</default>
+    <channel>input</channel>
+    </file>
+    <directory>
+    <name>dirVar</name>
+    <index>6</index>
+    <description>Some dir</description>
+        <label>Some dir</label>
+    <default>/home</default>
+    <channel>output</channel>
+    </directory>
+    <geometry fileExtensions="*.jpg, *.txt">
+    <name>geomVar</name>
+    <index>3</index>
+    <description>Some geom</description>
+    <label>Some geom</label>
+    </geometry>
+    <double>
+      <name>doubleVariable</name>
+      <flag>d</flag>
+      <longflag>double</longflag>
+      <description>An double with constraints</description>
+      <label>Double Parameter</label>
+      <default>30</default>
+      <constraints>
+        <minimum>0</minimum>
+        <maximum>1.e3</maximum>
+        <step>0</step>
+      </constraints>
+    </double>
+  </parameters>
+
+  <parameters advanced="true">
+    <label>Vector Parameters</label>
+    <description>Variations on vector parameters</description>
+    <float-vector>
+      <name>floatVector</name>
+      <flag>f</flag>
+      <description>A vector of floats</description>
+      <label>Float Vector Parameter</label>
+      <default>1.3,2,-14</default>
+    </float-vector>
+    <string-vector>
+      <name>stringVector</name>
+      <longflag>string_vector</longflag>
+      <description>A vector of strings</description>
+      <label>String Vector Parameter</label>
+      <default>"foo",bar,"foobar"</default>
+    </string-vector>
+  </parameters>
+
+</executable>
+

+ 24 - 0
Libs/ModuleDescription/Testing/CLIModules/CMakeLists.txt

@@ -0,0 +1,24 @@
+
+# This is very simple and for test purposes
+# only. Relies on naming conventions and has
+# no extensive error checking yet.
+function(ctkFunctionCreateCLIModule name)
+  set(_src_files ${ARGN})
+  list(APPEND _src_files ctkCLIModule${name}.cpp)
+  qt4_add_resources(_src_files ctkCLIModule${name}.qrc)
+
+  add_executable(ctkCLIModule${name} ${_src_files})
+  target_link_libraries(ctkCLIModule${name} CTKCore ${QT_LIBRARIES})
+  add_dependencies(ctkCLITestModules ctkCLIModule${name})
+endfunction()
+
+set(_cli_modules
+  Blur2dImage
+  Tour
+)
+
+add_custom_target(ctkCLITestModules)
+
+foreach(_cli_module ${_cli_modules})
+  add_subdirectory(${_cli_module})
+endforeach()

+ 2 - 0
Libs/ModuleDescription/Testing/CLIModules/Tour/CMakeLists.txt

@@ -0,0 +1,2 @@
+
+ctkFunctionCreateCLIModule(Tour)

+ 70 - 0
Libs/ModuleDescription/Testing/CLIModules/Tour/ctkCLIModuleTour.cpp

@@ -0,0 +1,70 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#include <ctkCommandLineParser.h>
+
+#include <QCoreApplication>
+#include <QTextStream>
+#include <QFile>
+
+int main(int argc, char* argv[])
+{
+  QCoreApplication app(argc, argv);
+  // This is used by QSettings
+  QCoreApplication::setOrganizationName("CommonTK");
+  QCoreApplication::setApplicationName("CLIModuleTour");
+
+  ctkCommandLineParser parser;
+  // Use Unix-style argument names
+  parser.setArgumentPrefix("--", "-");
+
+  // Add command line argument names
+  parser.addArgument("help", "h", QVariant::Bool, "Show this help text");
+  parser.addArgument("xml", "", QVariant::Bool, "Print a XML description of this modules command line interface");
+
+  // Parse the command line arguments
+  bool ok = false;
+  QHash<QString, QVariant> parsedArgs = parser.parseArguments(QCoreApplication::arguments(), &ok);
+  if (!ok)
+  {
+    QTextStream(stderr, QIODevice::WriteOnly) << "Error parsing arguments: "
+                                              << parser.errorString() << "\n";
+    return EXIT_FAILURE;
+  }
+
+  // Show a help message
+  if (parsedArgs.contains("help") || parsedArgs.contains("h"))
+  {
+    QTextStream(stdout, QIODevice::WriteOnly) << parser.helpText();
+    return EXIT_SUCCESS;
+  }
+
+  if (parsedArgs.contains("xml"))
+  {
+    QFile xmlDescription(":/ctkCLIModuleTour.xml");
+    xmlDescription.open(QIODevice::ReadOnly);
+    QTextStream(stdout, QIODevice::WriteOnly) << xmlDescription.readAll();
+  }
+
+  // Do something
+
+  return EXIT_SUCCESS;
+}

+ 5 - 0
Libs/ModuleDescription/Testing/CLIModules/Tour/ctkCLIModuleTour.qrc

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>ctkCLIModuleTour.xml</file>
+    </qresource>
+</RCC>

+ 115 - 0
Libs/ModuleDescription/Testing/CLIModules/Tour/ctkCLIModuleTour.xml

@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="utf-8"?>
+<executable>
+  <category>Tours</category>
+  <title>Execution Model Tour</title>
+  <description>
+  Shows one of each type of parameter.
+  </description>
+  <version>1.0</version>
+  <documentation-url></documentation-url>
+  <license></license>
+  <contributor>Daniel Blezek</contributor>
+
+  <parameters>
+    <label>Scalar Parameters</label>
+    <description>
+    Variations on scalar parameters
+    </description>
+    <integer>
+      <name>integerVariable</name>
+      <flag>i</flag>
+      <longflag>integer</longflag>
+      <description>
+      An integer without constraints
+      </description>
+      <label>Integer Parameter</label>
+      <default>30</default>
+    </integer>
+    <boolean>
+      <name>booleanParam</name>
+      <flag>b</flag>
+      <description>
+      A boolean without constraints
+      </description>
+      <label>Boolean Parameter</label>
+    </boolean>
+    <file>
+    <name>fileVar</name>
+    <index>3</index>
+    <description>Some file</description>
+    <label>Some file</label>
+    <default>bla</default>
+    <channel>input</channel>
+    </file>
+    <directory>
+    <name>dirVar</name>
+    <index>6</index>
+    <description>Some dir</description>
+        <label>Some dir</label>
+    <default>/home</default>
+    <channel>output</channel>
+    </directory>
+    <geometry fileExtensions="*.jpg, *.txt">
+    <name>geomVar</name>
+    <index>3</index>
+    <description>Some geom</description>
+    <label>Some geom</label>
+    </geometry>
+    <double>
+      <name>doubleVariable</name>
+      <flag>d</flag>
+      <longflag>double</longflag>
+      <description>An double with constraints</description>
+      <label>Double Parameter</label>
+      <default>30</default>
+      <constraints>
+        <minimum>0</minimum>
+        <maximum>1.e3</maximum>
+        <step>0</step>
+      </constraints>
+    </double>
+  </parameters>
+
+  <parameters advanced="true">
+    <label>Vector Parameters</label>
+    <description>Variations on vector parameters</description>
+    <float-vector>
+      <name>floatVector</name>
+      <flag>f</flag>
+      <description>A vector of floats</description>
+      <label>Float Vector Parameter</label>
+      <default>1.3,2,-14</default>
+    </float-vector>
+    <string-vector>
+      <name>stringVector</name>
+      <longflag>string_vector</longflag>
+      <description>A vector of strings</description>
+      <label>String Vector Parameter</label>
+      <default>"foo",bar,"foobar"</default>
+    </string-vector>
+  </parameters>
+
+  <parameters>
+    <label>Enumeration Parameters</label>
+    <description>Variations on enumeration parameters</description>
+    <string-enumeration>
+      <name>stringChoice</name>
+      <flag>e</flag>
+      <longflag>enumeration</longflag>
+      <description>An enumeration of strings</description>
+      <label>String Enumeration Parameter</label>
+      <default>foo</default>
+      <element>foo</element>
+      <element>"foobar"</element>
+      <element>foofoo</element>
+    </string-enumeration>
+    <point>
+    <name>pointVar</name>
+    <flag>p</flag>
+    <description>asf</description>
+    <label>A point</label>
+    <default>0.5,-34.2,43</default>
+      </point>
+  </parameters>
+</executable>
+

+ 115 - 0
Libs/ModuleDescription/Testing/CLIModules/ctkCLIModuleBlur2dImage.xml

@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="utf-8"?>
+<executable>
+  <category>Tours</category>
+  <title>Execution Model Tour</title>
+  <description>
+  Shows one of each type of parameter.
+  </description>
+  <version>1.0</version>
+  <documentation-url></documentation-url>
+  <license></license>
+  <contributor>Daniel Blezek</contributor>
+
+  <parameters>
+    <label>Scalar Parameters</label>
+    <description>
+    Variations on scalar parameters
+    </description>
+    <integer>
+      <name>integerVariable</name>
+      <flag>i</flag>
+      <longflag>integer</longflag>
+      <description>
+      An integer without constraints
+      </description>
+      <label>Integer Parameter</label>
+      <default>30</default>
+    </integer>
+    <boolean>
+      <name>booleanParam</name>
+      <flag>b</flag>
+      <description>
+      A boolean without constraints
+      </description>
+      <label>Boolean Parameter</label>
+    </boolean>
+    <file>
+    <name>fileVar</name>
+    <index>3</index>
+    <description>Some file</description>
+    <label>Some file</label>
+    <default>bla</default>
+    <channel>input</channel>
+    </file>
+    <directory>
+    <name>dirVar</name>
+    <index>6</index>
+    <description>Some dir</description>
+        <label>Some dir</label>
+    <default>/home</default>
+    <channel>output</channel>
+    </directory>
+    <geometry fileExtensions="*.jpg, *.txt">
+    <name>geomVar</name>
+    <index>3</index>
+    <description>Some geom</description>
+    <label>Some geom</label>
+    </geometry>
+    <double>
+      <name>doubleVariable</name>
+      <flag>d</flag>
+      <longflag>double</longflag>
+      <description>An double with constraints</description>
+      <label>Double Parameter</label>
+      <default>30</default>
+      <constraints>
+        <minimum>0</minimum>
+        <maximum>1.e3</maximum>
+        <step>0</step>
+      </constraints>
+    </double>
+  </parameters>
+
+  <parameters advanced="true">
+    <label>Vector Parameters</label>
+    <description>Variations on vector parameters</description>
+    <float-vector>
+      <name>floatVector</name>
+      <flag>f</flag>
+      <description>A vector of floats</description>
+      <label>Float Vector Parameter</label>
+      <default>1.3,2,-14</default>
+    </float-vector>
+    <string-vector>
+      <name>stringVector</name>
+      <longflag>string_vector</longflag>
+      <description>A vector of strings</description>
+      <label>String Vector Parameter</label>
+      <default>"foo",bar,"foobar"</default>
+    </string-vector>
+  </parameters>
+
+  <parameters>
+    <label>Enumeration Parameters</label>
+    <description>Variations on enumeration parameters</description>
+    <string-enumeration>
+      <name>stringChoice</name>
+      <flag>e</flag>
+      <longflag>enumeration</longflag>
+      <description>An enumeration of strings</description>
+      <label>String Enumeration Parameter</label>
+      <default>foo</default>
+      <element>foo</element>
+      <element>"foobar"</element>
+      <element>foofoo</element>
+    </string-enumeration>
+    <point>
+    <name>pointVar</name>
+    <flag>p</flag>
+    <description>asf</description>
+    <label>A point</label>
+    <default>0.5,-34.2,43</default>
+      </point>
+  </parameters>
+</executable>
+

+ 1 - 0
Libs/ModuleDescription/Testing/CMakeLists.txt

@@ -1 +1,2 @@
+add_subdirectory(CLIModules)
 add_subdirectory(Cpp)