Commit cc097a34 authored by Cyril Poupon's avatar Cyril Poupon
Browse files

new command to converter BrainVISA diffeomorphic direct & inverse vector...

new command to converter BrainVISA diffeomorphic direct & inverse vector fields to GKG direct/inverse vector field
parent be15c180
#include <gkg-processing-plugin-functors/BrainVISAVectorFieldConverter/BrainVISAVectorFieldConverterCommand.h>
#include <gkg-communication-command/CommandFactory.h>
#include <gkg-communication-getopt/Application.h>
#include <gkg-processing-container/Volume_i.h>
#include <gkg-processing-coordinates/Vector3d.h>
#include <gkg-core-io/Reader_i.h>
#include <gkg-core-io/Writer_i.h>
#include <gkg-core-exception/Exception.h>
#include <iostream>
//
// class BrainVISAVectorFieldConverterCommand
//
gkg::BrainVISAVectorFieldConverterCommand::BrainVISAVectorFieldConverterCommand( int32_t argc,
char* argv[],
bool loadPlugin,
bool removeFirst )
: gkg::Command( argc, argv,
loadPlugin,
removeFirst )
{
try
{
parse();
}
GKG_CATCH( "gkg::BrainVISAVectorFieldConverterCommand::BrainVISAVectorFieldConverterCommand( "
"int32_t argc, char* argv[], bool loadPlugin, "
"bool removeFirst )" );
}
gkg::BrainVISAVectorFieldConverterCommand::BrainVISAVectorFieldConverterCommand(
const std::string& fileNameInputDirectVectorField,
const std::string& fileNameInputInverseVectorField,
const std::string& fileNameOutputVectorField,
bool ascii,
const std::string& format,
bool verbose )
{
try
{
execute( fileNameInputDirectVectorField,
fileNameInputInverseVectorField,
fileNameOutputVectorField,
ascii,
format,
verbose );
}
GKG_CATCH( "gkg::BrainVISAVectorFieldConverterCommand::"
"BrainVISAVectorFieldConverterCommand( "
"const std::string& fileNameInputDirectVectorField, "
"const std::string& fileNameInputInverseVectorField, "
"const std::string& fileNameOutputVectorField, "
"bool ascii, "
"const std::string& format, "
"bool verbose )" );
}
gkg::BrainVISAVectorFieldConverterCommand::BrainVISAVectorFieldConverterCommand(
const gkg::Dictionary& parameters )
: gkg::Command( parameters )
{
try
{
DECLARE_STRING_PARAMETER( parameters, std::string,
fileNameInputDirectVectorField );
DECLARE_STRING_PARAMETER( parameters, std::string,
fileNameInputInverseVectorField );
DECLARE_STRING_PARAMETER( parameters, std::string,
fileNameOutputVectorField );
DECLARE_BOOLEAN_PARAMETER( parameters, bool, ascii );
DECLARE_STRING_PARAMETER( parameters, std::string, format );
DECLARE_BOOLEAN_PARAMETER( parameters, bool, verbose );
execute( fileNameInputDirectVectorField,
fileNameInputInverseVectorField,
fileNameOutputVectorField,
ascii,
format,
verbose );
}
GKG_CATCH( "gkg::BrainVISAVectorFieldConverterCommand::"
"BrainVISAVectorFieldConverterCommand( "
"const gkg::Dictionary& parameters )" );
}
gkg::BrainVISAVectorFieldConverterCommand::
~BrainVISAVectorFieldConverterCommand()
{
}
std::string gkg::BrainVISAVectorFieldConverterCommand::getStaticName()
{
try
{
return "BrainVISAVectorFieldConverter";
}
GKG_CATCH( "std::string gkg::BrainVISAVectorFieldConverterCommand::"
"getStaticName()" );
}
void gkg::BrainVISAVectorFieldConverterCommand::parse()
{
try
{
std::string fileNameInputDirectVectorField;
std::string fileNameInputInverseVectorField;
std::string fileNameOutputVectorField;
bool ascii = false;
std::string format = "";
bool verbose = false;
gkg::Application application( _argc, _argv,
"BrainVISA to GKG vector field converter",
_loadPlugin );
application.addSingleOption( "-d",
"Input BrainVISA direct POINT3DF "
"vector field volume",
fileNameInputDirectVectorField );
application.addSingleOption( "-i",
"Input BrainVISA inverse POINT3DF "
"vector field volume",
fileNameInputInverseVectorField );
application.addSingleOption( "-o",
"Output GKG direct and inverse vector field",
fileNameOutputVectorField );
application.addSingleOption( "-ascii",
"Save ouput volume in ASCII mode",
ascii,
true );
application.addSingleOption( "-format",
"Ouput volume format (default=input)",
format,
true );
application.addSingleOption( "-verbose",
"Show as much information as possible",
verbose,
true );
application.initialize();
execute( fileNameInputDirectVectorField,
fileNameInputInverseVectorField,
fileNameOutputVectorField,
ascii,
format,
verbose );
}
GKG_CATCH_FUNCTOR( "void "
"gkg::BrainVISAVectorFieldConverterCommand::parse()" );
}
void gkg::BrainVISAVectorFieldConverterCommand::execute(
const std::string& fileNameInputDirectVectorField,
const std::string& fileNameInputInverseVectorField,
const std::string& fileNameOutputVectorField,
bool ascii,
const std::string& format,
bool verbose )
{
try
{
////////////////////////////////////////////////////////////////////////////
// reading input BrainVISA direct vector field volume
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameInputDirectVectorField
<< "' : " << std::flush;
}
gkg::Volume< gkg::Vector3d< float > > directVectorFieldVolume;
gkg::Reader::getInstance().read( fileNameInputDirectVectorField,
directVectorFieldVolume );
gkg::Vector3d< int32_t > size;
directVectorFieldVolume.getSize( size );
gkg::Vector3d< double > resolution;
directVectorFieldVolume.getResolution( resolution );
if ( verbose )
{
std::cout << "done" << std::endl;
}
////////////////////////////////////////////////////////////////////////////
// reading input BrainVISA direct vector field volume
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameInputInverseVectorField
<< "' : " << std::flush;
}
gkg::Volume< gkg::Vector3d< float > > inverseVectorFieldVolume;
gkg::Reader::getInstance().read( fileNameInputInverseVectorField,
inverseVectorFieldVolume );
if ( verbose )
{
std::cout << "done" << std::endl;
}
////////////////////////////////////////////////////////////////////////////
// sanity check(s)
////////////////////////////////////////////////////////////////////////////
if ( !inverseVectorFieldVolume.hasSameSize( directVectorFieldVolume,
true ) ||
!inverseVectorFieldVolume.hasSameResolution( directVectorFieldVolume,
true ) )
{
throw std::runtime_error( "direct and inverse vector fields "
"don't have the same size or resolution" );
}
////////////////////////////////////////////////////////////////////////////
// computing output GKG direct/inverse vector field volume
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "computing GKG direct/inverse vector field : "
<< std::flush;
}
gkg::Volume< float >
directAndInverseVectorFieldVolume( size, 6 );
directAndInverseVectorFieldVolume.setResolution( resolution );
gkg::Vector3d< int32_t > voxel;
for ( voxel.z = 0; voxel.z < size.z; voxel.z++ )
{
for ( voxel.y = 0; voxel.y < size.y; voxel.y++ )
{
for ( voxel.x = 0; voxel.x < size.x; voxel.x++ )
{
directAndInverseVectorFieldVolume( voxel, 0 ) =
directVectorFieldVolume( voxel ).x;
directAndInverseVectorFieldVolume( voxel, 1 ) =
directVectorFieldVolume( voxel ).y;
directAndInverseVectorFieldVolume( voxel, 2 ) =
directVectorFieldVolume( voxel ).z;
directAndInverseVectorFieldVolume( voxel, 3 ) =
inverseVectorFieldVolume( voxel ).x;
directAndInverseVectorFieldVolume( voxel, 4 ) =
inverseVectorFieldVolume( voxel ).y;
directAndInverseVectorFieldVolume( voxel, 5 ) =
inverseVectorFieldVolume( voxel ).z;
}
}
}
if ( verbose )
{
std::cout << "done" << std::endl;
}
////////////////////////////////////////////////////////////////////////////
// writing output GKG direct/inverse vector field volume
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "writing '" << fileNameOutputVectorField
<< "' : " << std::flush;
}
gkg::Writer::getInstance().write( fileNameOutputVectorField,
directAndInverseVectorFieldVolume,
ascii,
format );
if ( verbose )
{
std::cout << "done" << std::endl;
}
}
GKG_CATCH( "void gkg::BrainVISAVectorFieldConverterCommand::execute( "
"const std::string& fileNameInputDirectVectorField, "
"const std::string& fileNameInputInverseVectorField, "
"const std::string& fileNameOutputVectorField, "
"bool ascii, "
"const std::string& format, "
"bool verbose )" );
}
RegisterCommandCreator( BrainVISAVectorFieldConverterCommand,
DECLARE_STRING_PARAMETER_HELP(
fileNameInputDirectVectorField ) +
DECLARE_STRING_PARAMETER_HELP(
fileNameInputInverseVectorField ) +
DECLARE_STRING_PARAMETER_HELP(
fileNameOutputVectorField ) +
DECLARE_BOOLEAN_PARAMETER_HELP( ascii ) +
DECLARE_STRING_PARAMETER_HELP( format ) +
DECLARE_BOOLEAN_PARAMETER_HELP( verbose ) );
#ifndef _gkg_processing_plugin_functors_BrainVISAVectorFieldConverter_BrainVISAVectorFieldConverterCommand_h_
#define _gkg_processing_plugin_functors_BrainVISAVectorFieldConverter_BrainVISAVectorFieldConverterCommand_h_
#include <gkg-communication-command/Command.h>
#include <gkg-core-pattern/Creator.h>
#include <string>
namespace gkg
{
class BrainVISAVectorFieldConverterCommand : public Command,
public Creator2Arg< BrainVISAVectorFieldConverterCommand,
Command,
int32_t,
char** >,
public Creator1Arg< BrainVISAVectorFieldConverterCommand,
Command,
const Dictionary& >
{
public:
BrainVISAVectorFieldConverterCommand( int32_t argc,
char* argv[],
bool loadPlugin = false,
bool removeFirst = true );
BrainVISAVectorFieldConverterCommand(
const std::string& fileNameInputDirectVectorField,
const std::string& fileNameInputInverseVectorField,
const std::string& fileNameOutputVectorField,
bool ascii,
const std::string& format,
bool verbose );
BrainVISAVectorFieldConverterCommand( const Dictionary& parameters );
virtual ~BrainVISAVectorFieldConverterCommand();
static std::string getStaticName();
protected:
friend class Creator2Arg< BrainVISAVectorFieldConverterCommand,
Command, int32_t, char** >;
friend class Creator1Arg< BrainVISAVectorFieldConverterCommand,
Command, const Dictionary& >;
void parse();
void execute( const std::string& fileNameInputDirectVectorField,
const std::string& fileNameInputInverseVectorField,
const std::string& fileNameOutputVectorField,
bool ascii,
const std::string& format,
bool verbose );
};
}
#endif
......@@ -9,6 +9,7 @@ AddRoiStatisticsToProbabilisticAtlas/AddRoiStatisticsToProbabilisticAtlasCommand
AffineTransform3d/AffineTransform3dCommand.h
BiasCorrection/BiasCorrectionCommand.h
Binarizer/BinarizerCommand.h
BrainVISAVectorFieldConverter/BrainVISAVectorFieldConverterCommand.h
Brownian/BrownianCommand.h
BrukerPhaseMapConverter/BrukerPhaseMapConverterCommand.h
Cat/CatCommand.h
......@@ -131,6 +132,7 @@ AddRoiStatisticsToProbabilisticAtlas/AddRoiStatisticsToProbabilisticAtlasCommand
AffineTransform3d/AffineTransform3dCommand.cxx
BiasCorrection/BiasCorrectionCommand.cxx
Binarizer/BinarizerCommand.cxx
BrainVISAVectorFieldConverter/BrainVISAVectorFieldConverterCommand.cxx
Brownian/BrownianCommand.cxx
BrukerPhaseMapConverter/BrukerPhaseMapConverterCommand.cxx
Cat/CatCommand.cxx
......
Markdown is supported
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