From SimBio - A generic environment for bio-numerical simulations
Implementation example of user interface I:
Class definition
// UIF1.h: interface for the UIF1 class.
//
……..
//
// A great variety of further options can be chosen, by setting parameters,
// when calling a method (see definition of enumarators).
//////////////////////////////////////////////////////////////////////////
#include <utilities/include/utvector_t.h>
#include <utilities/include/utmatrix_t.h>
#include <utilities/include/utblock_t.h>
///// enumerators are used for switches to determine details of the methods
enum forwardtype_e {forwardtype_Sphere, forwardtype_BEM,forwardtype_FEM};
enum linearinversetype_e {linearinversetype_L2, linearinversetype_Loreta};
enum invertertype_e {invertertype_Tikhonow, invertertype_TruncatedSVD};
enum sensortype_e {sensortype_EEG, sensortype_MEG};
enum optimizertype_e {optimizertype_SimplexOptimizer, optimizertype_MarquardtOptimizer,
optimizertype_SimulatedAnnealing};
enum criteriatype_e {criteriatype_MinimumSquareError, criteriatype_MaximumEntropie,
criteriatype_MaximumProbability};
enum searchvolumetype_e {searchvolumetype_InEntireBrain};
enum intialguesstype_e {intialguesstype_Standard}
class UIF1
{
public:
UIF1();
virtual ~UIF1();
// Discrete Parameter Space: UserFunctions for Linear Estimation
bool uif1_linear_estimation_oncortex
(const utMatrix_t<double>& inReferenceData, // Matrix containing reference (measured) data
MRItype inMRI, // Description of the segmented MRI
SensorConfiguration inSensorConfiguration, // Configurstion of the sensors (electrodes,
// MEG-gradiometer)
sensortype_e inSensorType, // Switch for the selecetion of the sensortype
utMatrix_t<double> outResult, // Resultmatrix
forwardtype_e inForwardType = forwardtype_BEM, // Switch for the selecetion of forward model
linearinversetype_e inInverseType = linearinversetype_L2, // Type of linear estimation,
// Default: L2-Norm
invertertype_e inInverterType = invertertype_TruncatedSVD); // Type of regularization,
// Default: Truncated Singular
// Value Decomposition
……}
Class implementation
// Implementation of uif1 for linear estimation methods
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool UIF1::uif1_linear_estimation_oncortex
(const utMatrix_t<double>& inReferenceData, // Matrix containing reference (measured) data
MRItype inMRI, // Description of the segmented MRI
SensorConfiguration inSensorConfiguration, // Configurstion of the sensors (electrodes,
// MEG-gradiometer)
sensortype_e inSensorType, // Switch for the selecetion of the sensortype
const utMatrix_t<double> outResult, // Resultmatrix of Linear Estimation
forwardtype_e inForwardType, // Switch for the selecetion of forward model
linearinversetype_e inInverseType, // Type of linear estimation, Default: L2-Norm
invertertype_e inInverterType) // Type of regularization, Default: Truncated
// Singular Value Decomposition
{
// Intialization of Grid on Cortex and for Head Model
if (!searchspacegrid_is_generated) anCorticalSurfaceGridGenerator_c cortex_grid(inMRI);
if (!headgrid_is_generated) anHeadModelGridGenerator_c head_grid(inMRI);
// Selection of Type of forward model
anAbstractSimulatorEEGMEG_c *sim=NULL;
switch(inSensorType)
{
case sensortype_EEG:
switch (inForwardType)
{
case forwardtype_Sphere:
return false;
case forwardtype_BEM:
sim= new
anForwardSimulatorBEMEEG_c(inSensorConfiguration,head_grid);
break;
case forwardtype_FEM:
sim= new
anForwardSimulatorCauchyFEMEEG_c(inSensorConfiguration,head_grid);
break;
default:
return false;
}
break;
case sensortype_MEG:
switch (inForwardType)
{
case forwardtype_Sphere:
return false ;
case forwardtype_BEM:
sim= neanForwardSimulatorBEMMEG_c(inSensorConfiguration, head_grid);
break;
case forwardtype_FEM:
sim= new anForwardSimulatorCauchyFEMMEG_c(inSensorConfiguration,
head_grid);
break;
default:
return false;
}
break;
}
// Selection of Linear Inverse Type
anAbstractWeighter_c *weigth=NULL;
switch (inInverseType)
{
case linearinversetype_L2:
weigth = new anL2weighter_c(sim);
break;
case linearinversetype_Loreta:
weight = new anLoretaweighter_c(sim);
break;
default:
delete sim;
return false;
}
// Selection of Regularization
anAbstractRegularizer_c *reg=NULL;
switch (inInverterType)
{
case invertertype_Tikhonow:
reg = new anRegularizerTikhonow_c;
break;
case invertertype_TruncatedSVD:
reg = new anRegularizerTruncatedSVD_c;
break;
default:
delete sim;
delete weigth;
return false;
}
//AnalyzerInverseLinear
anAnalyzerInversLinear_c linest(inReferenceData, sim, cortex_grid, weight, reg);
linest.run();
linest.getResult(outResult);
delete cortex_grid;
delete head_grid;
delete sim;
delete weight;
delete reg;
return true;
}
Implementation example of user interface II:
Class definition
// UIF2.h: interface for the UIF2 class. Access to results probably generated on different computers via files
//
// UIF2 for the access of methodes from the inverse toolbx
……
//
// A great variety of further options can be chosen, by setting parameters,
// when calling a method (see definition of enumarators).
//////////////////////////////////////////////////////////////////////////
#include <utilities/include/utvector_t.h>
#include <utilities/include/utmatrix_t.h>
#include <utilities/include/utblock_t.h>
#include <uif1_c.h>
#include <MRItype.h>
#include <SensorConfiguration.h>
///// enumerators are used for switches to determine details of the methods
enum forwardtype_e {forwardtype_Sphere, forwardtype_BEM,forwardtype_FEM};
enum linearinversetype_e {linearinversetype_L2, linearinversetype_Loreta};
enum invertertype_e {invertertype_Tikhonow, invertertype_TruncatedSVD};
enum sensortype_e {sensortype_EEG, sensortype_MEG};
enum optimizertype_e {optimizertype_SimplexOptimizer, optimizertype_MarquardtOptimizer,
optimizertype_SimulatedAnnealing};
enum criteriatype_e {criteriatype_MinimumSquareError, criteriatype_MaximumEntropie,
criteriatype_MaximumProbability};
enum searchvolumetype_e {searchvolumetype_InEntireBrain};
enum intialguesstype_e {intialguesstype_Standard}
class UIF2
{
public:
UIF2();
virtual ~UIF2();
// Discrete Parameter Space: UserFunctions for Linear Estimation
bool uif2_linear_estimation_oncortex
(string inReferenceDataFileName, // Inputfilename: File containing reference (measured) data
string inCortexGridFileName, // Inputfilename: File with description of cortex grid
string inHeadGridFileName, // Inputfilename: File with description of the head grid
string inSensorConfigurationFileName, // InputFile:Configurstion of the sensors (electrodes, MEG–
// gradiometer)
string outResultFilename, // OutputFilenam: File with Resultmatrix
forwardtype_e inForwardType = forwardtype_BEM, // Switch for the selecetion of
// forward model
linearinversetype_e inInverseType = linearinversetype_L2, // Type of linear estimation,
// Default: L2-Norm
invertertype_e inInverterType = invertertype_TruncatedSVD); // Type of regularization, Default:
// Truncated Singular Value Decomposition
…}
Class implementation
// Implementation of uif2 for linear estimation methods
/////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////
bool UIF2::uif2_linear_estimation_oncorte x
(string inReferenceDataFileName, // Inputfilename: File containing reference (measured) data
string inCortexGridFileName, // Inputfilename: File with description of cortex grid
string inHeadGridFileName, // Inputfilename: File with description of the head grid
string inSensorConfigurationFileName, // InputFile:Configurstion of the sensors (electrodes,
//MEG-gradiometer)
string outResultFilename, // OutputFilenam: File with Resultmatrix
forwardtype_e inForwardType, // Switch for the selecetion of forward model
linearinversetype_e inInverseType, // Type of linear estimation, Default: L2-Norm
invertertype_e inInverterType); // Type of regularization, Default:
//Truncated Singular Value Decomposition
{
MRItype inMRI = NULL; // MRI is not needed since grids are already available in files
// Intialization of Grid on Cortex and for Head Model
anCorticalSurfaceGridGeneratorfromFile_c cortex_grid(inCortexGridFileName);
searchspacegrid_is_generated = true;
anHeadModelGridGeneratorfromFile_c head_grid (inHeadGridFileName);
headgrid_is_generated = true;
// Read SensorConfiguration from File
uif2_read_SensorConfiguration(inSensorConfigurationFileName, inSensorConfiguration, inSensorType)
// Read Referencedata
uif2_read_ReferenceData(inReferenceDataFileName, inReferenceData);
UIF1::uif1_linear_estimation_oncortex(inReferenceData, // Matrix containing reference (measured) data
inMRI, // Description of the segmented MRI
inSensorConfiguration, // Configurstion of the sensors (electrodes,
// MEG-gradiometer)
inSensorType, // Switch for the selecetion of the sensortype
outResult, // Resultmatrix of Linear Estimation
inForwardType, // Switch for the selecetion of forward model
inInverseType, // Type of linear estimation, Default: L2-Norm
inInverterType) // Type of regularization, Default:
//Truncated Singular Value Decomposition
uif2_write_ResultData(outResultFilename, outResult);
}
Implementation example of user interface III:
int main(int argc,char* argv[])
{
forwardtype_e inForwardType ;
linearinversetype_e inInverseType ;
invertertype_e inInverterType;
bool correctparameter;
if (argc > 3)
{
if ((argv[1]== "uif3_linear_estimation_oncortex") && (argc > 6))
{
// Start with default values, which are replaced if correct arguments are present
inForwardType = forwardtype_BEM;
inInverseType = linearinversetype_L2;
inInverterType = invertertype_TruncatedSVD;
if (argc > 7)
{correctparameter = false;
if (argv[7] == "Sphere") ;
if (argv[7] == "BEM") {inForwardType = forwardtype_BEM; correctparameter = true;}
if (argv[7] == "FEM") {inForwardType = forwardtype_BEM; correctparameter = true;}
if (!correctparameter) std::cout << "wrong forward type, instead default is used"<<'\n';
if (argc >8)
{correctparameter = false;
if (argv[8] == "L2") {inInverseType = linearinversetype_L2; correctparameter = true;}
if (argv[8] == "Loreta") {inInverseType = linearinversetype_Loreta; correctparameter =
true;}
if (!correctparameter) std::cout << "wrong inversetype, instead default is used"<<'\n';
}
correctparameter = false;
if (argv[9] == "Tikhonow") {inInverterType = invertertype_Tikhonow; correctparameter = true;}
if (argv[9] == "TruncatedSVD") {inInverterType = invertertype_TruncatedSVD; correctparameter = true;}
if (!correctparameter) std::cout << "wrong inverter type, instead default is used"<<'\n';
UIF2::uif2_linear_estimation_oncortex(argv[2], // Inputfilename: File containing reference (measured) data
argv[3], // Inputfilename: File with description of cortex grid
argv[4], // Inputfilename: File with description of the head grid
argv[5], // InputFile:Configurstion of the sensors (electrodes,
// MEG-gradiometer)
argv[6], // OutputFilenam: File with Resultmatrix
inForwardType, // Switch for the selecetion of forward model
inInverseType, // Type of linear estimation, Default: L2-Norm
inInverterType);
}
….
}