Commit 78776fb4 authored by Kasper Marstal's avatar Kasper Marstal
Browse files

COMP: Put command line program in examples folder and build examples with SuperBuild

parent 2cd45f97
......@@ -41,6 +41,7 @@ macro( _selxmodule_enable MODULE_NAME )
if( ${MODULE_NAME}_INCLUDE_DIRS )
include_directories( ${${MODULE_NAME}_INCLUDE_DIRS} )
list( APPEND SUPERELASTIX_INCLUDE_DIRS ${${MODULE_NAME}_INCLUDE_DIRS} )
endif()
if( ${MODULE_NAME}_LIBRARIES )
......@@ -63,6 +64,7 @@ endmacro()
macro( _selxmodules_initialize )
set( SUPERELASTIX_MODULES )
set( SUPERELASTIX_INCLUDE_DIRS )
set( SUPERELASTIX_LIBRARIES )
set( SUPERELASTIX_TESTS )
......
......@@ -111,7 +111,7 @@ if( ${SUPERELASTIX_BUILD_TESTING} )
add_subdirectory( Testing )
endif()
# -----------------------------------------------------------brkdwn----------
# ---------------------------------------------------------------------
# Build Documentation
mark_as_advanced( SUPERELASTIX_BUILD_DOXYGEN )
......@@ -120,6 +120,14 @@ option( SUPERELASTIX_BUILD_DOXYGEN "Enable building Doxygen documentation." OFF
mark_as_advanced( SUPERELASTIX_BUILD_READTHEDOCS )
option( SUPERELASTIX_BUILD_READTHEDOCS "Enable building readthedocs.org documentation." OFF )
# ---------------------------------------------------------------------
# Enable other projects to use SuperElastix via CMake's find_packge() and a use-file
set( SUPERELASTIX_CONFIG_DIR ${CMAKE_CURRENT_BINARY_DIR} )
set( SUPERELASTIX_BINARY_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} )
configure_file( SuperElastixConfig.cmake.in SuperElastixConfig.cmake @ONLY IMMEDIATE )
configure_file( UseSuperElastix.cmake.in UseSuperElastix.cmake COPYONLY IMMEDIATE )
# ---------------------------------------------------------------------
# Install
......
#=========================================================================
#
# Copyright Leiden University Medical Center, Erasmus University Medical
# Center and contributors
#
# 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.txt
#
# 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.
#
#=========================================================================
cmake_minimum_required( VERSION 3.0.2 )
project(SuperElastixExamples)
if( NOT CMAKE_PROJECT_NAME STREQUAL "SuperElastix" )
# Examples are build as an external project, need to import dependencies
find_package( SuperElastix )
include( ${SUPERELASTIX_USE_FILE} )
find_package( ITK )
include( ${ITK_USE_FILE} )
message( STATUS "ELASTIX_USE_FILE: ${ELASTIX_USE_FILE}")
include( ${ELASTIX_USE_FILE} )
endif()
add_subdirectory( CommandlineProgram )
\ No newline at end of file
#=========================================================================
#
# Copyright Leiden University Medical Center, Erasmus University Medical
# Center and contributors
#
# 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.txt
#
# 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.
#
#=========================================================================
# Collect header files for Visual Studio Project
# http://stackoverflow.com/questions/8316104/specify-how-cmake-creates-visual-studio-project
file(GLOB COMMANDLINE_HEADER_FILES "${COMMANDLINE_SOURCE_DIR}/*/include/*.*")
set( COMMANDLINE_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/selxSuperElastix.cxx
)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib)
find_package(Boost COMPONENTS program_options system filesystem REQUIRED)
# Compile executable
add_executable( SuperElastixCommandlineProgram ${COMMANDLINE_SOURCE_FILES} ${COMMANDLINE_HEADER_FILES} )
target_link_libraries( SuperElastixCommandlineProgram ${SUPERELASTIX_LIBRARIES} ${Boost_LIBRARIES})
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* 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.txt
*
* 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 "selxSuperElastixFilter.h"
#include "selxBlueprint.h"
#include "selxConfigurationReader.h"
#include "selxAnyFileReader.h"
#include "selxAnyFileWriter.h"
#include "selxDefaultComponents.h"
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <stdexcept>
template< class T >
std::ostream &
operator<<( std::ostream & os, const std::vector< T > & v )
{
std::copy( v.begin(), v.end(), std::ostream_iterator< T >( os, " " ) );
return os;
}
int
main( int ac, char * av[] )
{
try
{
typedef std::vector< std::string > VectorOfStringsType;
selx::SuperElastixFilter< selx::DefaultComponents >::Pointer superElastixFilter = selx::SuperElastixFilter< selx::DefaultComponents >::New();
fs::path configurationPath;
VectorOfStringsType inputPairs;
VectorOfStringsType outputPairs;
// Store the reader so that they will not be destroyed before the pipeline is executed.
std::vector< selx::AnyFileReader::Pointer > fileReaders;
// Store the writers for the update call
//vector<ImageWriter2DType::Pointer> fileWriters;
std::vector< selx::AnyFileWriter::Pointer > fileWriters;
po::options_description desc( "Allowed options" );
desc.add_options()
( "help", "produce help message" )
( "conf", po::value< fs::path >( &configurationPath )->required(), "Configuration file" )
( "in", po::value< VectorOfStringsType >( &inputPairs )->multitoken(), "Input data: images, labels, meshes, etc. Usage <name>=<path>" )
( "out", po::value< VectorOfStringsType >( &outputPairs )->multitoken(), "Output data: images, labels, meshes, etc. Usage <name>=<path>" )
( "graphout", po::value< fs::path >(), "Output Graphviz dot file" )
;
po::variables_map vm;
po::store( po::parse_command_line( ac, av, desc ), vm );
po::notify( vm );
if( vm.count( "help" ) )
{
std::cout << desc << "\n";
return 0;
}
selx::Blueprint::Pointer blueprint;
if( configurationPath.extension() == ".xml" )
{
// TODO: open file here and pass a stream to the ConfigurationReader
blueprint = selx::ConfigurationReader::FromXML( configurationPath.string() );
}
else if( configurationPath.extension() == ".json" )
{
// TODO: open file here and pass a stream to the ConfigurationReader
blueprint = selx::ConfigurationReader::FromJson( configurationPath.string() );
}
else
{
throw std::invalid_argument( "Configuration file requires extension .xml or .json" );
}
if( vm.count( "graphout" ) )
{
blueprint->WriteBlueprint( vm[ "graphout" ].as< fs::path >().string() );
}
superElastixFilter->SetBlueprint( blueprint );
if( vm.count( "in" ) )
{
std::cout << "Number of input data: " << inputPairs.size() << "\n";
int index = 0;
for( const auto & inputPair : inputPairs )
{
VectorOfStringsType nameAndPath;
boost::split( nameAndPath, inputPair, boost::is_any_of( "=" ) ); // NameAndPath == { "name","path" }
const std::string & name = nameAndPath[ 0 ];
const std::string & path = nameAndPath[ 1 ];
std::cout << " " << index << " " << name << " : " << path << "\n";
++index;
// since we do not know which reader type we should instantiate for input "name",
// we ask SuperElastix for a reader that matches the type of the source component "name"
selx::AnyFileReader::Pointer reader = superElastixFilter->GetInputFileReader( name );
reader->SetFileName( path );
superElastixFilter->SetInput( name, reader->GetOutput() );
fileReaders.push_back( reader );
}
}
if( vm.count( "out" ) )
{
std::cout << "Number of output data: " << outputPairs.size() << "\n";
int index = 0;
for( const auto & outputPair : outputPairs )
{
VectorOfStringsType nameAndPath;
boost::split( nameAndPath, outputPair, boost::is_any_of( "=" ) ); // NameAndPath == { "name","path" }
const std::string & name = nameAndPath[ 0 ];
const std::string & path = nameAndPath[ 1 ];
std::cout << " " << index << " " << name << " : " << path << "\n";
++index;
// since we do not know which writer type we should instantiate for output "name",
// we ask SuperElastix for a writer that matches the type of the sink component "name"
selx::AnyFileWriter::Pointer writer = superElastixFilter->GetOutputFileWriter( name );
//ImageWriter2DType::Pointer writer = ImageWriter2DType::New();
writer->SetFileName( path );
//writer->SetInput(superElastixFilter->GetOutput<Image2DType>(name));
writer->SetInput( superElastixFilter->GetOutput( name ) );
fileWriters.push_back( writer );
}
}
/* Execute SuperElastix by updating the writers */
for( auto & writer : fileWriters )
{
writer->Update();
}
}
catch( std::exception & e )
{
std::cerr << "error: " << e.what() << "\n";
return 1;
}
catch( ... )
{
std::cerr << "Exception of unknown type!\n";
}
return 0;
}
......@@ -63,7 +63,7 @@ public:
ItkImageSourceComponent< 3, double >,
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, double >,
ItkMeshSinkComponent< 2, float >,
ItkMeshSourceComponent< 2, float >> RegisterComponents;
ItkMeshSourceComponent< 2, float > > RegisterComponents;
typedef SuperElastixFilter< RegisterComponents > SuperElastixFilterType;
......
......@@ -125,5 +125,10 @@ endif()
include( SuperElastix )
# ---------------------------------------------------------------------
# Build Examples as an external project
include( ExternalExamples )
......@@ -17,3 +17,17 @@
#
#=========================================================================
set( proj SuperElastixExamples )
ExternalProject_Add( ${proj}
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../Examples
BINARY_DIR ${proj}-build
CMAKE_ARGS
--no-warn-unused-cli
-DSuperElastix_DIR:PATH=${SuperElastix_DIR}
-DITK_DIR:PATH=${ITK_DIR}
-DELASTIX_USE_FILE:PATH=${ELASTIX_USE_FILE}
DEPENDS ${SUPERELASTIX_DEPENDENCIES}
INSTALL_COMMAND ""
)
......@@ -37,3 +37,8 @@ ExternalProject_Add( ${proj}
DEPENDS ${SUPERELASTIX_DEPENDENCIES}
INSTALL_COMMAND ""
)
ExternalProject_Get_Property( SuperElastix binary_dir )
set( SuperElastix_DIR "${binary_dir}" )
list( APPEND SUPERELASTIX_DEPENDENCIES ${proj} )
set( SUPERELASTIX_USE_FILE ${CMAKE_BINARY_DIR}/UseSuperElastix.cmake )
# Add include directories needed to use SuperElastix
set( SUPERELASTIX_INCLUDE_DIRS @SUPERELASTIX_INCLUDE_DIRS@ )
# Add link directories needed to use SuperElastix
set( SUPERELASTIX_LIBRARY_DIRS @SUPERELASTIX_BINARY_DIR@ )
# Add list of SuperElastix libraries
set( SUPERELASTIX_LIBRARIES @SUPERELASTIX_LIBRARIES@ )
# The location of the SuperElastix use-file
set( SUPERELASTIX_USE_FILE "@SUPERELASTIX_CONFIG_DIR@/UseSuperElastix.cmake")
#
# This file sets up include directories and link directories
# for a project to use SuperElastix. It should not be
# included directly, but rather through the SUPERELASTIX_USE_FILE setting
# obtained from SimpleITKConfig.cmake.
#
# Add include directories needed to use SuperElastix
include_directories( ${SUPERELASTIX_INCLUDE_DIRS} )
# Add link directories needed to use SuperElastix
link_directories( ${SUPERELASTIX_LIBRARY_DIRS} )
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