Parcourir la source

ENH: Added ModuleDescription and a test

Xavi Planes il y a 14 ans
Parent
commit
55d811a680

+ 5 - 4
CMakeLists.txt

@@ -275,6 +275,7 @@ SET(CTK_LIBS
   DICOM/Core:OFF
   DICOM/Widgets:OFF
   Messaging/Core:OFF
+  ModuleDescription:OFF
   Scripting/Python/Core:OFF
   Scripting/Python/Widgets:OFF
   Visualization/VTK/Core:OFF
@@ -463,13 +464,13 @@ ENDIF()
 
 
 # Convert 'CTEST_PROJECT_SUBPROJECTS_OUTPUT' to a list
-STRING(REPLACE " " "\\;" CTEST_PROJECT_SUBPROJECTS ${CTEST_PROJECT_SUBPROJECTS_OUTPUT})
-SET(CTEST_PROJECT_SUBPROJECTS ${CTEST_PROJECT_SUBPROJECTS})
-
-# If the list of subproject is empty, let's at least build CTKCore
 LIST(LENGTH CTEST_PROJECT_SUBPROJECTS subproject_count)
 IF (subproject_count EQUAL 0)
+  # If the list of subproject is empty, let's at least build CTKCore
   SET(CTEST_PROJECT_SUBPROJECTS CTKCore)
+ELSE( )
+  STRING(REPLACE " " "\\;" CTEST_PROJECT_SUBPROJECTS ${CTEST_PROJECT_SUBPROJECTS_OUTPUT})
+  SET(CTEST_PROJECT_SUBPROJECTS ${CTEST_PROJECT_SUBPROJECTS})
 ENDIF()
 
 # Configure CTestConfigSubProject.cmake used that could be used by CTest scripts

+ 56 - 0
Libs/ModuleDescription/CMakeLists.txt

@@ -0,0 +1,56 @@
+PROJECT(CTKModuleDescription)
+
+#
+# 3rd party dependencies
+#
+
+#
+# See CTK/CMake/ctkMacroBuildLib.cmake for details
+#
+
+SET(KIT_export_directive "CTK_MODULDESC_EXPORT")
+
+# Additional directories to include
+  
+# Source files
+SET(KIT_SRCS
+  ctkModuleDescription.h
+  ctkModuleDescription.cpp
+  ctkModuleParameter.h
+  ctkModuleParameter.cpp
+  ctkModuleParameterGroup.h
+  ctkModuleParameterGroup.cpp
+  )
+
+# Headers that should run through moc
+SET(KIT_MOC_SRCS
+)
+
+# UI files
+SET(KIT_UI_FORMS
+)
+
+# Resources
+SET(KIT_resources
+)
+
+# Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake
+# The following macro will read the target libraries from the file 'target_libraries.cmake'
+ctkMacroGetTargetLibraries(KIT_target_libraries)
+
+ctkMacroBuildLib(
+  NAME ${PROJECT_NAME}
+  EXPORT_DIRECTIVE ${KIT_export_directive}
+  INCLUDE_DIRECTORIES ${KIT_include_directories}
+  SRCS ${KIT_SRCS}
+  MOC_SRCS ${KIT_MOC_SRCS}
+  UI_FORMS ${KIT_UI_FORMS}
+  TARGET_LIBRARIES ${KIT_target_libraries}
+  RESOURCES ${KIT_resources}
+  LIBRARY_TYPE ${CTK_LIBRARY_MODE}
+  )
+
+# Testing
+IF(BUILD_TESTING)
+  ADD_SUBDIRECTORY(Testing)
+ENDIF(BUILD_TESTING)

+ 0 - 0
Libs/ModuleDescription/README


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

@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(Cpp)

+ 27 - 0
Libs/ModuleDescription/Testing/Cpp/CMakeLists.txt

@@ -0,0 +1,27 @@
+SET(KIT ${PROJECT_NAME})
+
+CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cpp
+  ctkModuleDescriptionTest.cpp
+  )
+
+SET (TestsToRun ${Tests})
+REMOVE (TestsToRun ${KIT}CppTests.cpp)
+
+SET(LIBRARY_NAME ${PROJECT_NAME})
+
+ADD_EXECUTABLE(${KIT}CppTests ${Tests})
+TARGET_LINK_LIBRARIES(${KIT}CppTests ${LIBRARY_NAME} ${CTK_BASE_LIBRARIES})
+
+SET( KIT_TESTS ${CPP_TEST_PATH}/${KIT}CppTests)
+
+MACRO( SIMPLE_TEST  TESTNAME )
+  ADD_TEST( ${TESTNAME} ${KIT_TESTS} ${TESTNAME} )
+  SET_PROPERTY(TEST ${TESTNAME} PROPERTY LABELS ${PROJECT_NAME})
+ENDMACRO( SIMPLE_TEST  )
+
+#
+# Add Tests
+#
+
+SIMPLE_TEST( ctkModuleDescriptionTest.cpp )
+

+ 110 - 0
Libs/ModuleDescription/Testing/Cpp/TestData/ParserTest1.xml

@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="utf-8"?>
+<executable>
+  <category>registration</category>
+  <title>NAMIC sample registration</title>
+  <description>Registers two images together using a rigid transform and MI</description>
+  <version>1.0</version>
+  <documentation-url></documentation-url>
+  <license></license>
+  <contributor>Daniel Blezek</contributor>
+
+  <parameters>
+    <label>Registration Parameters</label>
+    <description>Parameters used for registration</description>
+    <integer>
+      <name>HistogramBins</name>
+      <flag>-b</flag>
+      <longflag>--histogrambins</longflag>
+      <description>Number of histogram bins to use for Mattes Mutual Information</description>
+      <label>Histogram Bins</label>
+      <default>30</default>
+      <constraints>
+        <minimum>1</minimum>
+        <maximum>500</maximum>
+        <step>5</step>
+      </constraints>
+    </integer>
+
+    <integer>
+      <name>SpatialSamples</name>
+      <flag>-s</flag>
+      <longflag>--spatialsamples</longflag>
+      <description>Number of spatial samples to use in estimating Mattes Mutual Information</description>
+      <label>Spatial Samples</label>
+      <default>10000</default>
+      <constraints>
+        <minimum>1000</minimum>
+        <maximum>50000</maximum>
+        <step>1000</step>
+      </constraints>
+    </integer>
+
+    <boolean>
+      <name>InitializeTransform</name>
+      <flag>-u</flag>
+      <longflag>--noinitializetransform</longflag>
+      <description>Calculate initial transform</description>
+      <label>Initialize TransformSpatial Samples</label>
+      <default>false</default>
+    </boolean>
+
+    <integer-vector>
+      <name>Iterations</name>
+      <flag>-i</flag>
+      <longflag>--iterations</longflag>
+      <description>Comma separated list of iterations. Must have the same number of elements as learning rate</description>
+      <label>Iterations</label>
+      <default>100,100,100,200</default>
+    </integer-vector>
+
+    <float-vector>
+      <name>LearningRate</name>
+      <flag>-l</flag>
+      <longflag>--learningrate</longflag>
+      <description>Comma separated list of learning rates must have the same number of elements as iterations</description>
+      <label>Learning Rates</label>
+      <default>0.005,0.001,0.0005,0.0002</default>
+    </float-vector>
+    
+    <double>
+      <name>TranslationScale</name>
+      <longflag>--translationscale</longflag>
+      <flag>-t</flag>
+      <description>Relative scale of translations to rotations, i.e. a value of 100 means 10mm = 1 degree</description>
+      <label>Translation scaling</label>
+      <default>100.0</default>
+      <constraints>
+        <minimum>10.0</minimum>
+        <maximum>500.0</maximum>
+        <step>50.0</step>
+      </constraints>
+    </double>
+  </parameters>
+
+  <parameters>
+    <label>IO</label>
+    <description>Input/output parameters</description>
+    <file>
+      <name>FixedImage</name>
+      <label>Fixed Image</label>
+      <channel>input</channel>
+      <index>0</index>
+      <description>Fixed image to register to</description>
+    </file>
+    <file>
+      <name>MovingImage</name>
+      <label>Moving Image</label>
+      <channel>input</channel>
+      <index>1</index>
+      <description>Moving image</description>
+    </file>
+    <file>
+      <name>OutputImage</name>
+      <label>Output Volume</label>
+      <channel>output</channel>
+      <index>2</index>
+      <description>Resampled Moving Image</description>
+    </file>
+  </parameters>
+
+</executable>

+ 110 - 0
Libs/ModuleDescription/Testing/Cpp/TestData/ParserTest2.xml

@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="utf-8"?>
+<executable>
+  <category>registration</category>
+  <title>NAMIC sample registration</title>
+  <description>Registers two images together using a rigid transform and MI</description>
+  <version>1.0</version>
+  <documentation-url></documentation-url>
+  <license></license>
+  <contributor>Daniel Blezek</contributor>
+
+  <parameters>
+    <label>Registration Parameters</label>
+    <description>Parameters used for registration</description>
+    <integer>
+      <name>HistogramBins</name>
+      <flag>-b</flag>
+      <longflag>--histogrambins</longflag>
+      <description>Number of histogram bins to use for Mattes Mutual Information</description>
+      <label>Histogram Bins</label>
+      <default>30</default>
+      <constraints>
+        <minimum>1</minimum>
+        <maximum>500</maximum>
+        <step>5</step>
+      </constraints>
+    </integer>
+
+    <integer>
+      <name>SpatialSamples</name>
+      <flag>-s</flag>
+      <longflag>--spatialsamples</longflag>
+      <description>Number of spatial samples to use in estimating Mattes Mutual Information</description>
+      <label>Spatial Samples</label>
+      <default>10000</default>
+      <constraints>
+        <minimum>1000</minimum>
+        <maximum>50000</maximum>
+        <step>1000</step>
+      </constraints>
+    </integer>
+
+    <boolean>
+      <name>InitializeTransform</name>
+      <flag>-u</flag>
+      <longflag>--noinitializetransform</longflag>
+      <description>Calculate initial transform</description>
+      <label>Initialize TransformSpatial Samples</label>
+      <default>false</default>
+    </boolean>
+
+    <integer-vector>
+      <name>Iterations</name>
+      <flag>-i</flag>
+      <longflag>--iterations</longflag>
+      <description>Comma separated list of iterations. Must have the same number of elements as learning rate</description>
+      <label>Iterations</label>
+      <default>100,100,100,200</default>
+    </integer-vector>
+
+    <float-vector>
+      <name>LearningRate</name>
+      <flag>-l</flag>
+      <longflag>--learningrate</longflag>
+      <description>Comma separated list of learning rates must have the same number of elements as iterations</description>
+      <label>Learning Rates</label>
+      <default>0.005,0.001,0.0005,0.0002</default>
+    </float-vector>
+    
+    <double>
+      <name>TranslationScale</name>
+      <longflag>--translationscale</longflag>
+      <flag>-t</flag>
+      <description>Relative scale of translations to rotations, i.e. a value of 100 means 10mm = 1 degree</description>
+      <label>Translation scaling</label>
+      <default>100.0</default>
+      <constraints>
+        <minimum>10.0</minimum>
+        <maximum>500.0</maximum>
+        <step>50.0</step>
+      </constraints>
+    </double>
+  </parameters>
+
+  <parameters>
+    <label>IO</label>
+    <description>Input/output parameters</description>
+    <image fileExtensions=".png,.nrrd">
+      <name>FixedImage</name>
+      <label>Fixed Image</label>
+      <channel>input</channel>
+      <index>0</index>
+      <description>Fixed image to register to</description>
+    </image>
+    <file fileExtensions=".txt,*.csv,*.html">
+      <name>MovingImage</name>
+      <label>Moving Image</label>
+      <channel>input</channel>
+      <index>1</index>
+      <description>Moving image</description>
+    </file>
+    <file fileExtensions="">
+      <name>OutputImage</name>
+      <label>Output Volume</label>
+      <channel>output</channel>
+      <index>2</index>
+      <description>Resampled Moving Image</description>
+    </file>
+  </parameters>
+
+</executable>

+ 90 - 0
Libs/ModuleDescription/Testing/Cpp/ctkModuleDescriptionTest.cpp

@@ -0,0 +1,90 @@
+/*=========================================================================
+
+  Library:   CTK
+ 
+  Copyright (c) 2010  Kitware Inc.
+
+  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.commontk.org/LICENSE
+
+  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.
+ 
+=========================================================================*/
+
+// CTK includes
+#include "ctkModuleDescription.h"
+#include <iostream>
+
+
+//-----------------------------------------------------------------------------
+int ctkModuleDescriptionTest(int argc, char * argv [] )
+{
+  Q_UNUSED(argc);
+  Q_UNUSED(argv);  
+
+
+  ctkModuleParameter param;
+  param[ "Tag" ] = "MyTag";
+  param[ "Name" ] = "MyName";
+  param[ "Description" ] = "MyDescription";
+  param[ "Label" ] = "MyLabel";
+  param[ "CPPType" ] = "MyCPPType";
+  param[ "Type" ] = "MyType";
+  param[ "Reference" ] = "MyReference";
+  param[ "Hidden" ] = "false";
+  param[ "ArgType" ] = "MyArgType";
+  param[ "StringToType" ] = "MyStringToType";
+  param[ "Default" ] = "MyDefault";
+  param[ "Flag" ] = "MyFlag";
+  param[ "LongFlag" ] = "MyLongFlag";
+  param[ "Constraints" ] = "MyConstraints";
+  param[ "Minimum" ] = "MyMinimum";
+  param[ "Maximum" ] = "MyMaximum";
+  param[ "Channel" ] = "MyChannel";
+  param[ "Index" ] = "MyIndex";
+  param[ "Multiple" ] = "false";
+  param[ "Aggregate" ] = "false";
+  param[ "FileExtensions" ] = ".vtk,.jpg";
+  param[ "FlagAliases" ] = "MyFlagAliases";
+  param[ "DeprecatedFlagAliases" ] = "MyDeprecatedFlagAliases";
+  param[ "LongFlagAliases" ] = "MyLongFlagAliases";
+  param[ "DeprecatedLongFlagAliases" ] = "MyDeprecatedLongFlagAliases";
+  param[ "CoordinateSystem" ] = "MyCoordinateSystem";
+
+
+  ctkModuleParameterGroup group;
+  group[ "Label" ] = "MyLabel";
+  group[ "Description" ] = "MyDescription";
+  group[ "Advanced" ] = "MyAdvanced";
+
+
+  ctkModuleDescription module;
+  module[ "Category" ] = "MyCategory";
+  module[ "Index" ] = "MyIndex";
+  module[ "Title" ] = "MyTitle";
+  module[ "Description" ] = "MyDescription";
+  module[ "DocumentationURL" ] = "MyDocumentationURL";
+  module[ "License" ] = "MyLicense";
+  module[ "Acknowledgements" ] = "MyAcknowledgements";
+  module[ "Contributor" ] = "MyContributor";
+  module[ "Type" ] = "MyType";
+  module[ "AlternativeType" ] = "MyAlternativeType";
+  module[ "Target" ] = "MyTarget";
+  module[ "AlternativeTarget" ] = "MyAlternativeTarget";
+  module[ "Location" ] = "MyLocation";
+
+
+  group.addParameter( param );
+  module.addParameterGroup( group );
+
+  QTextStream(stdout)<< module;
+
+  return EXIT_SUCCESS;
+}

+ 270 - 0
Libs/ModuleDescription/ctkModuleDescription.cpp

@@ -0,0 +1,270 @@
+/*=============================================================================
+
+Library: CTK
+
+Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
+
+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 "ctkModuleDescription.h"
+#include <iostream>
+#include "QFile"
+#include "QTextStream"
+
+//----------------------------------------------------------------------------
+ctkModuleDescription::ctkModuleDescription()
+{
+}
+
+//----------------------------------------------------------------------------
+ctkModuleDescription::ctkModuleDescription(const ctkModuleDescription &md)
+  : QHash<QString, QString>( QHash<QString, QString>( md ) )
+{
+  this->ParameterGroups = md.ParameterGroups;
+  this->Logo = md.Logo;
+}
+
+//----------------------------------------------------------------------------
+void ctkModuleDescription::operator=(const ctkModuleDescription &md)
+{
+ QHash<QString, QString>::operator=(md);
+	this->ParameterGroups = md.ParameterGroups;
+	this->Logo = md.Logo;
+}
+
+//----------------------------------------------------------------------------
+QTextStream & operator<<(QTextStream &os, const ctkModuleDescription &module)
+{
+  os << QHash<QString, QString>(module);
+  //os << "Logo: " << module.GetLogo() << endl;
+
+  os << "ParameterGroups: " << endl;
+  QVector<ctkModuleParameterGroup>::const_iterator it = module.parameterGroups().begin();
+  while (it != module.parameterGroups().end())
+    {
+    os << *it;
+    ++it;
+    }
+  return os;
+}
+
+
+//----------------------------------------------------------------------------
+bool ctkModuleDescription::hasReturnParameters() const
+{
+  // iterate over each parameter group
+  QVector<ctkModuleParameterGroup>::const_iterator pgbeginit
+    = this->ParameterGroups.begin();
+  QVector<ctkModuleParameterGroup>::const_iterator pgendit
+    = this->ParameterGroups.end();
+  QVector<ctkModuleParameterGroup>::const_iterator pgit;
+  
+  for (pgit = pgbeginit; pgit != pgendit; ++pgit)
+    {
+    // iterate over each parameter in this group
+    QVector<ctkModuleParameter>::const_iterator pbeginit
+      = (*pgit).parameters().begin();
+    QVector<ctkModuleParameter>::const_iterator pendit
+      = (*pgit).parameters().end();
+    QVector<ctkModuleParameter>::const_iterator pit;
+
+    for (pit = pbeginit; pit != pendit; ++pit)
+      {
+      if ((*pit).isReturnParameter())
+        {
+        return true;
+        }
+      }    
+    }
+
+  return false;
+}
+
+//----------------------------------------------------------------------------
+bool ctkModuleDescription::setParameterDefaultValue(const QString& name, const QString& value)
+{
+  ctkModuleParameter* param = parameter( name );
+  if ( param )
+  {
+    (*param)[ "Default" ] = value;
+    return true;
+  }
+
+  return false;
+}
+
+
+//----------------------------------------------------------------------------
+ctkModuleParameter* ctkModuleDescription::parameter(const QString& name)
+{
+  // iterate over each parameter group
+  QVector<ctkModuleParameterGroup>::iterator pgbeginit
+    = this->ParameterGroups.begin();
+  QVector<ctkModuleParameterGroup>::iterator pgendit
+    = this->ParameterGroups.end();
+  QVector<ctkModuleParameterGroup>::iterator pgit;
+  
+  for (pgit = pgbeginit; pgit != pgendit; ++pgit)
+    {
+    // iterate over each parameter in this group
+    QVector<ctkModuleParameter>::iterator pbeginit
+      = (*pgit).parameters().begin();
+    QVector<ctkModuleParameter>::iterator pendit
+      = (*pgit).parameters().end();
+    QVector<ctkModuleParameter>::iterator pit;
+
+    for (pit = pbeginit; pit != pendit; ++pit)
+      {
+      if ((*pit)["Name"] == name)
+        {
+        return &(*pit);
+        }
+      }    
+    }
+
+  return NULL;
+}
+
+//----------------------------------------------------------------------------
+void ctkModuleDescription ::setLogo(const QIcon& logo)
+{
+  this->Logo = logo;
+}
+
+//----------------------------------------------------------------------------
+const QIcon& ctkModuleDescription::logo() const
+{
+  return this->Logo;
+}
+
+//----------------------------------------------------------------------------
+bool ctkModuleDescription ::readParameterFile(const QString& filename)
+{
+  bool modified = false;
+
+  QFile file(filename);
+  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+    {
+    std::cout << "Parameter file " << filename.toStdString( ) << " could not be opened." << endl;
+    return false;
+    }
+
+  QTextStream in(&file);
+  while (!in.atEnd())
+    {
+    QString line = in.readLine();
+
+    // split the line into key: value
+    QString key, value;
+
+    line = line.trimmed();
+    QStringList list = line.split( "=" );
+    key = list[ 0 ].trimmed();
+    if ( list.size() == 1 )
+    {
+      continue;
+    }
+    value = list[ 1 ].trimmed();
+
+    
+    // std::cout << "key=" << key << ", value=" << value << "!" << endl;
+
+    ctkModuleParameter *param = this->parameter( key );
+    if ( param )
+      {
+      if (value != (*param)["Default"] )
+        {
+        (*param)["Default"] = value;
+        modified = true;
+
+        // multiple="true" may have to be handled differently
+        }
+      }
+    }
+
+  return modified;
+}
+
+//----------------------------------------------------------------------------
+bool ctkModuleDescription::
+writeParameterFile(const QString& filename, bool withHandlesToBulkParameters)
+{
+  QFile rtp(filename);
+
+  if (!rtp.open(QIODevice::WriteOnly | QIODevice::Text))
+    {
+    std::cout << "Parameter file " << filename.toStdString() << " could not be opened for writing." << endl;
+    return false;
+    }
+
+  QTextStream in(&rtp);
+  // iterate over each parameter group
+  QVector<ctkModuleParameterGroup>::const_iterator pgbeginit
+    = this->ParameterGroups.begin();
+  QVector<ctkModuleParameterGroup>::const_iterator pgendit
+    = this->ParameterGroups.end();
+  QVector<ctkModuleParameterGroup>::const_iterator pgit;
+  
+  for (pgit = pgbeginit; pgit != pgendit; ++pgit)
+    {
+    // iterate over each parameter in this group
+    QVector<ctkModuleParameter>::const_iterator pbeginit
+      = (*pgit).parameters().begin();
+    QVector<ctkModuleParameter>::const_iterator pendit
+      = (*pgit).parameters().end();
+    QVector<ctkModuleParameter>::const_iterator pit;
+
+    for (pit = pbeginit; pit != pendit; ++pit)
+      {
+      // write out all parameters or just the ones that are not bulk parameters
+      if (withHandlesToBulkParameters
+          || (!withHandlesToBulkParameters 
+              && ((*pit)[ "Tag" ] != "image"
+                  && (*pit)[ "Tag" ] != "geometry"
+                  && (*pit)[ "Tag" ] != "transform"
+                  && (*pit)[ "Tag" ] != "table"
+                  && (*pit)[ "Tag" ] != "measurement"
+                  && (*pit)[ "Tag" ] != "point"  // point and region are special
+                  && (*pit)[ "Tag" ] != "region")))
+        {
+        in << (*pit)[ "Name" ] << " = " << (*pit)[ "Default" ] << endl;
+
+        // multiple="true" may have to be handled differently
+        }
+      }
+    }
+
+  return true;
+}
+
+void ctkModuleDescription::addParameterGroup( const ctkModuleParameterGroup &group )
+{
+	this->ParameterGroups.push_back(group);
+}
+
+const QVector<ctkModuleParameterGroup>& ctkModuleDescription::parameterGroups() const
+{
+	return this->ParameterGroups;
+}
+
+QVector<ctkModuleParameterGroup>& ctkModuleDescription::parameterGroups()
+{
+	return this->ParameterGroups;
+}
+
+void ctkModuleDescription::setParameterGroups( const QVector<ctkModuleParameterGroup>& groups )
+{
+	this->ParameterGroups = groups;
+}

+ 102 - 0
Libs/ModuleDescription/ctkModuleDescription.h

@@ -0,0 +1,102 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
+
+  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.
+
+=============================================================================*/
+
+#ifndef __ctkModuleDescription_h
+#define __ctkModuleDescription_h
+
+#include "QHash"
+#include "QIcon"
+
+#include "ctkModuleParameterGroup.h"
+
+/**
+* Description of the parameters of a module
+*
+* The parameters can be used for automated GUI generation or execution
+* of the module.
+*
+* For example:
+* - Target: This is the entry point for a shared object module and the full 
+* command (with path) for an executable.
+* - Type: Unknown, SharedObjectModule, CommandLineModule
+* - AlternativeTarget: This is the entry
+* point for a shared object module and the full command (with path)
+* for an executable. The alternative target is used for a second version
+* of a module (whose type differs from the primary target,
+* executable verses shared object).
+* - Location: This is path to the file (shared
+* object or executable) for the module
+* - AlternativeLocation: This is path to the
+* file (shared object or executable) for a second version of the
+* module (usually a different type from the primary).
+*/
+class CTK_MODULDESC_EXPORT ctkModuleDescription : public QHash<QString, QString>
+{
+public:
+  ctkModuleDescription();
+  ctkModuleDescription(const ctkModuleDescription &md);
+
+  void operator=(const ctkModuleDescription &md);
+
+  
+  void setLogo(const QIcon& logo);
+  const QIcon& logo() const;
+  
+  void addParameterGroup(const ctkModuleParameterGroup &group);
+
+  const QVector<ctkModuleParameterGroup>& parameterGroups() const;
+
+  QVector<ctkModuleParameterGroup>& parameterGroups();
+  
+  void setParameterGroups(const QVector<ctkModuleParameterGroup>& groups);
+
+  // Does the module have any simple (primitive) return types?
+  bool hasReturnParameters() const;
+
+  bool setParameterDefaultValue(const QString& name,
+                                const QString& value);
+
+  ctkModuleParameter* parameter(const QString& name);
+
+  ///
+  /// Read a parameter file. Syntax of file is "name: value" for each
+  /// parameter. Returns a bool indicating whether any parameter value
+  /// was modified.
+  bool readParameterFile(const QString& filename);
+
+  ///
+  /// Write a parameter file. By default, the method writes out all
+  /// the parameters.  The "withHandlesToBulkParameters" parameter
+  /// controls whether the handles to the bulk parameters (image,
+  /// geometry, etc.) are written to the file.
+  bool writeParameterFile(const QString& filename, bool withHandlesToBulkParameters = true);
+
+
+private:
+
+  /// Groups of parameters
+  QVector<ctkModuleParameterGroup> ParameterGroups;
+  /// Logo
+  QIcon Logo;
+};
+
+CTK_MODULDESC_EXPORT QTextStream & operator<<(QTextStream &os, const ctkModuleDescription &module);
+
+#endif

+ 114 - 0
Libs/ModuleDescription/ctkModuleParameter.cpp

@@ -0,0 +1,114 @@
+/*=============================================================================
+
+Library: CTK
+
+Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
+
+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 "ctkModuleParameter.h"
+#include "QStringList"
+
+ctkModuleParameter::ctkModuleParameter()
+{
+}
+
+ctkModuleParameter::ctkModuleParameter(const ctkModuleParameter& parameter)
+  : QHash<QString, QString>( QHash<QString, QString>( parameter ) )
+{
+}
+
+bool ctkModuleParameter::isReturnParameter() const
+{
+  // could check for tag == float, int, float-vector, ...
+  if ( (*this)["Channel"] == "output" 
+    && !this->isFlagParameter() && !this->isIndexParameter())
+  {
+    return true;
+  }
+  return false;
+}
+
+bool ctkModuleParameter::isFlagParameter() const
+{
+  return ((*this)["Flag"] != "" || (*this)[ "LongFlag" ] != "");
+}
+
+bool ctkModuleParameter::isIndexParameter() const
+{
+  return ((*this)[ "Index" ] != "");
+}
+
+//-----------------------------------------------------------------------------
+QTextStream & operator<<(QTextStream &os, const ctkModuleParameter &parameter)
+{ 
+  os << "    Parameter" << endl;
+  os << "      ";
+  os.setFieldWidth(7);
+  os.setFieldAlignment(QTextStream::AlignLeft);
+  os << QHash<QString, QString>( parameter );
+  os.setFieldWidth(0);
+
+  os << "Flag aliases: ";
+  os << parameter["FlagAliases"].split( "," );
+
+  os << "      " << "Deprecated Flag aliases: ";
+  os << parameter["DeprecatedFlagAliases"].split( "," );
+
+  os << "      " << "LongFlag aliases: ";
+  os << parameter["LongFlagAliases"].split( "," );
+
+  os << "      " << "Deprecated LongFlag aliases: ";
+  os << parameter["DeprecatedLongFlagAliases"].split( "," );
+
+  os << "      " << "FileExtensions: ";
+  os << parameter["FileExtensions"].split( "," );
+
+  return os;
+}
+
+
+//----------------------------------------------------------------------------
+QTextStream & operator<<(QTextStream &os, const QStringList &list)
+{ 
+  QStringList::const_iterator fit;  
+
+  for (fit = list.begin();fit != list.end(); ++fit)
+  {
+    if (fit != list.begin())
+    {
+      os << ", ";
+    }
+    os << (*fit);
+  }
+  os << endl;
+
+  return os;
+}
+
+
+//----------------------------------------------------------------------------
+QTextStream & operator<<(QTextStream &os, const QHash<QString, QString> &hash)
+{ 
+  QHash<QString,QString>::const_iterator itProp;
+  for ( itProp = hash.begin( ) ; 
+    itProp != hash.end( ) ; 
+    itProp++ )
+  {
+    os << QString( itProp.key( ) + ": " + itProp.value( ) ) << endl;
+  }
+
+  return os;
+}

+ 65 - 0
Libs/ModuleDescription/ctkModuleParameter.h

@@ -0,0 +1,65 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
+
+  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.
+
+=============================================================================*/
+
+#ifndef __ctkModuleParameter_h
+#define __ctkModuleParameter_h
+
+#include "CTKModuleDescriptionExport.h"
+#include "QHash"
+#include "QTextStream"
+
+/** 
+ *  \brief Single parameter to a module, like a threshold of a filter.
+ *
+ * ctkModuleParameter describes a single parameters to a
+ * module. Information on the parameter type, name, flag, label,
+ * description, channel, index, default, and constraints can be
+ * stored.
+ *
+ */
+class CTK_MODULDESC_EXPORT ctkModuleParameter : public QHash<QString, QString>
+{
+public:
+  ctkModuleParameter();
+  virtual ~ctkModuleParameter() {}
+  ctkModuleParameter(const ctkModuleParameter& parameter);
+
+  /// Simple return types are parameters on output channel with no
+  /// flags and without a specified index 
+  virtual bool isReturnParameter() const;
+  
+  /// Has a flag or a long flag?
+  virtual bool isFlagParameter() const;
+
+  /// Is an index type?
+  virtual bool isIndexParameter() const;
+
+protected:
+
+  
+private:
+
+};
+
+CTK_MODULDESC_EXPORT QTextStream & operator<<(QTextStream &os, const ctkModuleParameter &parameter);
+CTK_MODULDESC_EXPORT QTextStream & operator<<(QTextStream &os, const QStringList &list);
+CTK_MODULDESC_EXPORT QTextStream & operator<<(QTextStream &os, const QHash<QString, QString> &hash);
+
+#endif

+ 65 - 0
Libs/ModuleDescription/ctkModuleParameterGroup.cpp

@@ -0,0 +1,65 @@
+/*=============================================================================
+
+Library: CTK
+
+Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
+
+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 "ctkModuleParameterGroup.h"
+
+ctkModuleParameterGroup
+::ctkModuleParameterGroup(const ctkModuleParameterGroup &parameters)
+  : QHash<QString, QString>( QHash<QString, QString>( parameters ) )
+{
+  this->Parameters = parameters.Parameters;
+}
+
+void
+ctkModuleParameterGroup
+::operator=(const ctkModuleParameterGroup &parameters)
+{
+  QHash<QString, QString>::operator=(parameters);
+  this->Parameters = parameters.Parameters;
+}
+
+void ctkModuleParameterGroup::addParameter( const ctkModuleParameter &parameter )
+{
+  this->Parameters.push_back(parameter);
+}
+
+const QVector<ctkModuleParameter>& ctkModuleParameterGroup::parameters() const
+{
+  return this->Parameters;
+}
+
+QVector<ctkModuleParameter>& ctkModuleParameterGroup::parameters()
+{
+  return this->Parameters;
+}
+
+QTextStream & operator<<(QTextStream &os, const ctkModuleParameterGroup &group)
+{ 
+  os << QHash<QString, QString>(group);
+
+  os << "  Parameters: " << endl;
+  QVector<ctkModuleParameter>::const_iterator it = group.parameters().begin();
+  while (it != group.parameters().end())
+    {
+    os << *it;
+    ++it;
+    }
+  return os;
+}

+ 53 - 0
Libs/ModuleDescription/ctkModuleParameterGroup.h

@@ -0,0 +1,53 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
+
+  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.
+
+=============================================================================*/
+
+#ifndef __ctkModuleParameterGroup_h
+#define __ctkModuleParameterGroup_h
+
+#include "ctkModuleParameter.h"
+#include "QHash"
+#include "QVector"
+
+/** 
+*  \brief Group of parameters
+*
+*/
+class CTK_MODULDESC_EXPORT ctkModuleParameterGroup : public QHash<QString, QString>
+{
+public:
+  ctkModuleParameterGroup() {};
+  ctkModuleParameterGroup(const ctkModuleParameterGroup &parameters);
+
+  void operator=(const ctkModuleParameterGroup &parameters);
+
+  void addParameter(const ctkModuleParameter &parameter);
+
+  const QVector<ctkModuleParameter>& parameters() const;
+
+  QVector<ctkModuleParameter>& parameters();
+  
+private:
+  ///
+  QVector<ctkModuleParameter> Parameters;
+};
+
+CTK_MODULDESC_EXPORT QTextStream & operator<<(QTextStream &os, const ctkModuleParameterGroup &group);
+
+#endif

+ 9 - 0
Libs/ModuleDescription/target_libraries.cmake

@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK libraries
+#
+
+SET(target_libraries
+  CTKCore
+  )