Skip to content

Commit

Permalink
Merge pull request #61 from aghayoor/landmarksTransformation
Browse files Browse the repository at this point in the history
ENH: A new program called "BRAINSConstellationLandmarksTransform" is added
  • Loading branch information
hjmjohnson committed Sep 18, 2013
2 parents caac031 + 943ef21 commit 21c295e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Author: Ali Ghayoor
* at Psychiatry Imaging Lab,
* University of Iowa Health Care 2013
*/

/*
This program program uses the input transform to propagate
reference landmarks to the target landmark file.
*/

#include "itkPoint.h"
#include "itkTransformFileReader.h"
#include "itkCompositeTransform.h"
#include "Slicer3LandmarkIO.h"

#include "BRAINSConstellationLandmarksTransformCLP.h"


int main( int argc, char *argv[] )
{
PARSE_ARGS;

if( inputLandmarksFile == ""
|| inputTransformFile == ""
|| outputLandmarksFile == "")
{
std::cerr << "Input and output file names should be given by commandline. " << std::endl;
std::cerr << "Usage:\n"
<< "~/BRAINSConstellationLandmarksTransform\n"
<< "--inputLandmarksFile (-i)\n"
<< "--inputTransformFile (-t)\n"
<< "--outputLandmarksFile (-o)"
<< std::endl;
return EXIT_FAILURE;
}

const unsigned int Dimension = 3;

typedef itk::Point<double,Dimension> PointType;
typedef std::map< std::string, PointType > LandmarksMapType;

LandmarksMapType origLandmarks = ReadSlicer3toITKLmk( inputLandmarksFile );
LandmarksMapType transformedLandmarks;

typedef itk::TransformFileReader ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputTransformFile );
reader->Update();

ReaderType::TransformListType *transformList = reader->GetTransformList();

typedef itk::CompositeTransform<double, Dimension> CompositeTransformType;

CompositeTransformType::Pointer inputCompTrans =
dynamic_cast<CompositeTransformType *>( transformList->front().GetPointer() );
if( inputCompTrans.IsNull() )
{
std::cerr << "The input transform should be a composite transform." << std::endl;
return EXIT_FAILURE;
}

LandmarksMapType::const_iterator it = origLandmarks.begin();
for(; it!=origLandmarks.end(); it++)
{
transformedLandmarks[it->first] = inputCompTrans->TransformPoint( it->second );
}

WriteITKtoSlicer3Lmk( outputLandmarksFile, transformedLandmarks );
std::cout << "The transformed landmarks file is written." << std::endl;

return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>Utilities.BRAINS</category>
<title>Landmarks Transformation</title>
<description>
This program converts the original landmark file to the target landmark file using the input transform.
</description>
<version>1.0</version>
<documentation-url> </documentation-url>
<license> </license>
<contributor>Ali Ghayoor</contributor>
<acknowledgements>
</acknowledgements>

<parameters>
<label>IO</label>
<description>Input/output parameters</description>

<file fileExtensions=".fcsv">
<name>inputLandmarksFile</name>
<flag>i</flag>
<longflag>inputLandmarksFile</longflag>
<label>Input landmarks file</label>
<channel>input</channel>
<description>Input landmarks file (.fcsv)</description>
</file>

<transform fileExtensions=".h5,.hdf5">
<name>inputTransformFile</name>
<flag>t</flag>
<longflag>inputTransformFile</longflag>
<label>Input transform file</label>
<channel>input</channel>
<description>input composite transform file (.h5,.hdf5)</description>
</transform>

<file fileExtensions=".fcsv">
<name>outputLandmarksFile</name>
<flag>o</flag>
<longflag>outputLandmarksFile</longflag>
<label>Output landmarks file</label>
<channel>output</channel>
<description>Output landmarks file (.fcsv)</description>
</file>

</parameters>

</executable>
1 change: 1 addition & 0 deletions BRAINSConstellationDetector/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(ALL_PROGS_LIST
landmarksConstellationAligner
landmarksConstellationWeights
BinaryMaskEditorBasedOnLandmarks
BRAINSConstellationLandmarksTransform
)
foreach(prog ${ALL_PROGS_LIST})
StandardBRAINSBuildMacro(NAME ${prog} TARGET_LIBRARIES landmarksConstellationCOMMONLIB )
Expand Down

0 comments on commit 21c295e

Please sign in to comment.