Commit ecfa80d4 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: run registration from commandline

parent bd05ec49
......@@ -33,7 +33,7 @@ set(Boost_USE_MULTITHREADED ON)
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib)
message(STATUS "BOOST_LIBRARYDIR: ${BOOST_LIBRARYDIR}")
find_package(Boost COMPONENTS program_options REQUIRED)
find_package(Boost COMPONENTS program_options system filesystem REQUIRED)
#find_package(Boost REQUIRED)
# Compile library
......
// Copyright Vladimir Prus 2002-2004.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "Overlord.h"
#include "selxBlueprint.h"
#include "selxConfigurationReader.h"
/* The simplest usage of the library.
*/
#include "selxItkSmoothingRecursiveGaussianImageFilterComponent.h"
#include "selxItkImageFilterSink.h"
#include "selxDisplacementFieldItkImageFilterSink.h"
#include "selxItkImageSource.h"
#include "selxElastixComponent.h"
#include "selxItkImageFilterSink.h"
#include "selxItkImageSink.h"
#include "selxItkImageRegistrationMethodv4Component.h"
#include "selxItkANTSNeighborhoodCorrelationImageToImageMetricv4.h"
#include "selxItkMeanSquaresImageToImageMetricv4.h"
#include "selxItkImageSourceFixed.h"
#include "selxItkImageSourceMoving.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
#include <boost/program_options.hpp>
namespace po = boost::program_options;
......@@ -12,8 +29,10 @@ namespace po = boost::program_options;
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
#include <string>
using namespace std;
using namespace selx;
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
......@@ -21,15 +40,26 @@ ostream& operator<<(ostream& os, const vector<T>& v)
return os;
}
int main(int ac, char* av[])
{
try {
path configurationPath;
vector<path> inputFilePaths;
vector<path> outputFilePaths;
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("levels", po::value<int>(), "number of resolution levels")
("iterations", po::value<vector<int>>()->multitoken(), "number of iterations per level")
("conf", po::value<path>(&configurationPath)->required(), "Configuration file")
("in", po::value<vector<path>>(&inputFilePaths)->multitoken(), "Input data: images, labels, meshes, etc.")
("out", po::value<vector<path>>(&outputFilePaths)->multitoken(), "Output data: images, labels, meshes, etc.")
("graphout", po::value<path>(), "Output Graphviz dot file")
//("levels", po::value<int>(), "number of resolution levels")
//("iterations", po::value<vector<int>>(), "number of iterations per level")
;
po::variables_map vm;
......@@ -41,22 +71,101 @@ int main(int ac, char* av[])
return 0;
}
if (vm.count("in")) {
cout << "Number of input data: " << inputFilePaths.size() << "\n";
int index = 0;
for (const auto & inname : inputFilePaths)
{
cout << " [" << index << "]: " << inname << "\n";
++index;
}
}
if (vm.count("out")) {
cout << "Number of output data: " << outputFilePaths.size() << "\n";
int index = 0;
for (const auto & outname : outputFilePaths)
{
cout << " [" << index << "]: " << outname << "\n";
++index;
}
}
/*
if (vm.count("levels")) {
cout << "number of resolution levels was set to "
<< vm["levels"].as<int>() << ".\n";
cout << "number of resolution levels was set to "
<< vm["levels"].as<int>() << ".\n";
}
else {
cout << "number of resolution levels was not set.\n";
cout << "number of resolution levels was not set.\n";
}
if (vm.count("iterations")) {
cout << "number of iterations per level was set to "
<< vm["iterations"].as< vector<int> >() << "\n";
cout << "number of iterations per level was set to "
<< vm["iterations"].as< vector<int> >() << "\n";
}
else {
cout << "number of iterations per level was not set.\n";
}
*/
Blueprint::Pointer blueprint;
if (configurationPath.extension() == ".xml")
{
// TODO: open file here and pass a stream to the ConfigurationReader
blueprint = ConfigurationReader::FromXML(configurationPath.string());
}
else if (configurationPath.extension() == ".json")
{
// TODO: open file here and pass a stream to the ConfigurationReader
blueprint = ConfigurationReader::FromJson(configurationPath.string());
}
else {
cout << "number of iterations per level was not set.\n";
throw exception("Configuration file requires extension .xml or .json");
}
if (vm.count("graphout"))
{
blueprint->WriteBlueprint(vm["graphout"].as<path>().string());
}
ComponentFactory<ItkImageFilterSinkComponent<2, float>>::RegisterOneFactory();
ComponentFactory<DisplacementFieldItkImageFilterSinkComponent<2, float>>::RegisterOneFactory();
ComponentFactory<ItkImageSourceFixedComponent<2, float>>::RegisterOneFactory();
ComponentFactory<ItkImageSourceMovingComponent<2, float>>::RegisterOneFactory();
ComponentFactory<ItkSmoothingRecursiveGaussianImageFilterComponent<2, float>>::RegisterOneFactory();
ComponentFactory<ItkImageRegistrationMethodv4Component<2, float>>::RegisterOneFactory();
ComponentFactory<ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component<2, float>>::RegisterOneFactory();
ComponentFactory<ItkMeanSquaresImageToImageMetricv4Component<2, float>>::RegisterOneFactory();
ComponentFactory<ElastixComponent<2, float>>::RegisterOneFactory();
ComponentFactory<ItkImageSinkComponent<2, float>>::RegisterOneFactory();
Overlord::Pointer overlord = Overlord::New();
vector<string> inputFileStings;
std::transform(std::begin(inputFilePaths),
std::end(inputFilePaths),
std::back_inserter(inputFileStings),
[](path p) { return p.string(); }
);
vector<string> outputFileStings;
std::transform(std::begin(outputFilePaths),
std::end(outputFilePaths),
std::back_inserter(outputFileStings),
[](path p) { return p.string(); }
);
//The Overlord is not yet an itkfilter with inputs and outputs, therefore it reads and writes the files temporarily.
overlord->inputFileNames = inputFileStings;
overlord->outputFileNames = outputFileStings;
overlord->SetBlueprint(blueprint);
bool allUniqueComponents;
allUniqueComponents = overlord->Configure();
overlord->Execute();
}
catch (exception& e) {
cerr << "error: " << e.what() << "\n";
......@@ -66,5 +175,6 @@ int main(int ac, char* av[])
cerr << "Exception of unknown type!\n";
}
return 0;
}
}
\ No newline at end of file
......@@ -12,20 +12,18 @@ public:
TEST_F( ConfigurationReaderTest, ReadXML )
{
ConfigurationReader reader;
ConfigurationReader::BlueprintPointerType blueprint;
EXPECT_NO_THROW(blueprint = reader.FromXML("configurationReaderTest.xml"));
EXPECT_NO_THROW(blueprint = ConfigurationReader::FromXML("configurationReaderTest.xml"));
blueprint->WriteBlueprint("configurationReaderTest.xml.dot");
}
TEST_F(ConfigurationReaderTest, ReadJson)
{
ConfigurationReader reader;
ConfigurationReader::BlueprintPointerType blueprint;
EXPECT_NO_THROW(blueprint = reader.FromJson("configurationReaderTest.json"));
EXPECT_NO_THROW(blueprint = ConfigurationReader::FromJson("configurationReaderTest.json"));
blueprint->WriteBlueprint("configurationReaderTest.json.dot");
}
......@@ -80,7 +80,7 @@ endif()
mark_as_advanced( USE_SYSTEM_BOOST )
option( USE_SYSTEM_BOOST "Use an installed version of BOOST" OFF )
if( USE_SYSTEM_BOOST )
find_package( BOOST REQUIRED graph )
find_package( BOOST REQUIRED graph program_options filesystem)
else()
include( ExternalBoost )
endif()
......
......@@ -9,13 +9,13 @@ if( UNIX )
set( BOOST_URL "http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz")
set( BOOST_MD5 51528a0e3b33d9e10aaa311d9eb451e3 )
set( BOOST_CONFIGURE_COMMAND ./bootstrap.sh )
set( BOOST_BUILD_COMMAND ./b2 --with-program_options address-model=64)
set( BOOST_BUILD_COMMAND ./b2 --with-program_options --with-filesystem address-model=64)
else()
if( WIN32 )
set( BOOST_URL "http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.zip")
set( BOOST_MD5 08d29a2d85db3ebc8c6fdfa3a1f2b83c )
set( BOOST_CONFIGURE_COMMAND cmd /C bootstrap.bat msvc )
set( BOOST_BUILD_COMMAND b2.exe --with-program_options address-model=64)
set( BOOST_BUILD_COMMAND b2.exe --with-program_options --with-filesystem address-model=64)
endif()
endif()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment