Skip to content

Commit

Permalink
update features
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Wilson committed Aug 12, 2019
1 parent b77ba22 commit 2786ff1
Show file tree
Hide file tree
Showing 47 changed files with 972 additions and 56 deletions.
77 changes: 77 additions & 0 deletions AlignMesh/AlignMesh.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "AlignMeshCLP.h"


// VTK Includes
#include "vtkDecimatePro.h"
#include "vtkXMLPolyDataWriter.h"
#include "vtkXMLPolyDataReader.h"
#include "vtkSmartPointer.h"
#include "vtkPolyData.h"
#include "vtkTriangleFilter.h"
#include "vtkNew.h"
#include "vtkCellLocator.h"

//ITK Includes
#include "itkMesh.h"
#include "itkMeshFileReader.h"
#include "itkMeshFileWriter.h"
#include "itkLineCell.h"
#include "itkTriangleCell.h"
#include "itkImageFileWriter.h"
#include "itkResampleImageFilter.h"
#include "itkConstrainedValueAdditionImageFilter.h"
#include "itkBSplineInterpolateImageFunction.h"
#include "itkPluginUtilities.h"
#include <itkDefaultDynamicMeshTraits.h>
#include <itkMetaMeshConverter.h>


int main (int argc, char * argv[])
{
PARSE_ARGS;
try{
typedef itk::DefaultDynamicMeshTraits<float, 3, 3, float, float> MeshTraitsType;


typedef MeshTraitsType::PointType PointType;

constexpr unsigned int Dimension = 3;
using InputPixelType = float;


using MeshType = itk::Mesh<InputPixelType, Dimension>;
using MeshReaderType = itk::MeshFileReader<MeshType>;

using MeshWriterType = itk::MeshFileWriter<MeshType>;

MeshReaderType::Pointer meshReader = MeshReaderType::New();
meshReader->SetFileName(inputVolume.c_str());
// meshReader->Update();
MeshType::Pointer mesh = meshReader->GetOutput();
MeshType::PointsContainerPointer Points = mesh->GetPoints();
int numberOfPoints = Points->Size();

MeshReaderType::Pointer meshReader2 = MeshReaderType::New();
meshReader2->SetFileName(inputVolumeTwo.c_str());
// meshReader->Update();
MeshType::Pointer mesh2 = meshReader2->GetOutput();





MeshWriterType::Pointer writer = MeshWriterType::New();
writer->SetInput(mesh);
writer->SetFileName(outputVolume.c_str());
//writer->Update();


}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e << '\n';
return EXIT_FAILURE;
}
return EXIT_SUCCESS;

}
36 changes: 36 additions & 0 deletions AlignMesh/AlignMesh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>Surface Models.Advanced</category>
<title>AlignMesh</title>
<description><![CDATA[This is a CLI module that can be bundled in an extension]]></description>
<version>0.0.1</version>
<documentation-url>http://www.example.com/Slicer/Modules/AlignMesh</documentation-url>
<license>Slicer</license>
<contributor>FirstName LastName (Institution), FirstName LastName (Institution)</contributor>
<acknowledgements>This work was partially funded by NIH grant NXNNXXNNNNNN-NNXN</acknowledgements>
<parameters>
<label>IO</label>
<description><![CDATA[Input/output parameters]]></description>
<geometry>
<name>inputVolume</name>
<label>Input Volume</label>
<channel>input</channel>
<index>0</index>
<description><![CDATA[Input volume]]></description>
</geometry>
<geometry>
<name>inputVolumeTwo</name>
<label>Input Volume Two </label>
<channel>input</channel>
<index>1</index>
<description><![CDATA[Input volume two]]></description>
</geometry>
<geometry>
<name>outputVolume</name>
<label>Output Volume</label>
<channel>output</channel>
<index>2</index>
<description><![CDATA[Output Volume]]></description>
</geometry>
</parameters>
</executable>
53 changes: 53 additions & 0 deletions AlignMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

#-----------------------------------------------------------------------------
set(MODULE_NAME AlignMesh)

#-----------------------------------------------------------------------------

#
# SlicerExecutionModel
#
find_package(SlicerExecutionModel REQUIRED)
include(${SlicerExecutionModel_USE_FILE})


#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
ITKIOImageBase
ITKIOMeshBase
ITKSmoothing
ITKLabelMap
)
find_package(ITK 5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
include(${ITK_USE_FILE})

#-----------------------------------------------------------------------------
set(MODULE_INCLUDE_DIRECTORIES
${MRMLCore_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}

)

set(MODULE_SRCS
)

set(MODULE_TARGET_LIBRARIES
${ITK_LIBRARIES}
${VTK_LIBRARIES}
)

#-----------------------------------------------------------------------------
SEMMacroBuildCLI(
NAME ${MODULE_NAME}
TARGET_LIBRARIES ${MODULE_TARGET_LIBRARIES}
INCLUDE_DIRECTORIES ${MODULE_INCLUDE_DIRECTORIES}
ADDITIONAL_SRCS ${MODULE_SRCS}
)

#-----------------------------------------------------------------------------
if(BUILD_TESTING)
add_subdirectory(Testing)
endif()
1 change: 1 addition & 0 deletions AlignMesh/Data/Baseline/AlignMeshTest.nhdr.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fc6170ceeff3d8217a9dd6a1add2ec8c
1 change: 1 addition & 0 deletions AlignMesh/Data/Baseline/AlignMeshTest.raw.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0749d4d3f07a217030f9ae33d94c4559
1 change: 1 addition & 0 deletions AlignMesh/Data/Input/CTHeadAxial.nhdr.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6e5c289c73e14ba7a1b0f8aaf6ed249a
1 change: 1 addition & 0 deletions AlignMesh/Data/Input/CTHeadAxial.raw.gz.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3ebd710c9cf9d75750f4569b8caf6d07
1 change: 1 addition & 0 deletions AlignMesh/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Cxx)
25 changes: 25 additions & 0 deletions AlignMesh/Testing/Cxx/AlignMeshTest.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif

#include "itkTestMain.h"

// STD includes
#include <iostream>

#ifdef WIN32
# define MODULE_IMPORT __declspec(dllimport)
#else
# define MODULE_IMPORT
#endif

extern "C" MODULE_IMPORT int ModuleEntryPoint(int, char* []);

void RegisterTests()
{
StringToTestFunctionMap["ModuleEntryPoint"] = ModuleEntryPoint;
}
25 changes: 25 additions & 0 deletions AlignMesh/Testing/Cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#-----------------------------------------------------------------------------
set(BASELINE ${CMAKE_CURRENT_SOURCE_DIR}/../../Data/Baseline)
set(INPUT ${CMAKE_CURRENT_SOURCE_DIR}/../../Data/Input)
set(TEMP "${CMAKE_BINARY_DIR}/Testing/Temporary")

set(CLP ${MODULE_NAME})

#-----------------------------------------------------------------------------
add_executable(${CLP}Test ${CLP}Test.cxx)
target_link_libraries(${CLP}Test ${CLP}Lib ${SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES})
set_target_properties(${CLP}Test PROPERTIES LABELS ${CLP})

#-----------------------------------------------------------------------------
set(testname ${CLP}Test)
ExternalData_add_test(${CLP}Data NAME ${testname} COMMAND ${SEM_LAUNCH_COMMAND} $<TARGET_FILE:${CLP}Test>
--compare DATA{${BASELINE}/${CLP}Test.nhdr,${CLP}Test.raw}
${TEMP}/${CLP}Test.nhdr
ModuleEntryPoint
--sigma 2.5 DATA{${INPUT}/CTHeadAxial.nhdr,CTHeadAxial.raw.gz} ${TEMP}/${CLP}Test.nhdr
)
set_property(TEST ${testname} PROPERTY LABELS ${CLP})

#-----------------------------------------------------------------------------
ExternalData_add_target(${CLP}Data)
66 changes: 66 additions & 0 deletions AlignMeshICP/AlignMeshICP.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "AlignMeshICPCLP.h"

// VTK Includes
#include "vtkXMLPolyDataWriter.h"
#include "vtkXMLPolyDataReader.h"
#include "vtkSmartPointer.h"
#include "vtkPolyData.h"
#include "vtkTriangleFilter.h"
#include "vtkNew.h"
#include "vtkIterativeClosestPointTransform.h"
#include "vtkLandmarkTransform.h"
#include "vtkTransformPolyDataFilter.h"
#include "vtkAppendPolyData.h"


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

try{
vtkSmartPointer<vtkPolyData> source;
vtkSmartPointer<vtkPolyData> target;

// Read the file
vtkNew<vtkXMLPolyDataReader> targetReader;
targetReader->SetFileName(inputVolume.c_str());
targetReader->Update();
target = targetReader->GetOutput();

vtkNew<vtkXMLPolyDataReader> sourceReader;
sourceReader->SetFileName(inputVolumeTwo.c_str());
sourceReader->Update();
source = sourceReader->GetOutput();


vtkNew<vtkIterativeClosestPointTransform> icp;
icp->SetSource(source);
icp->SetTarget(target);
vtkSmartPointer<vtkLandmarkTransform> transform =
icp->GetLandmarkTransform();
transform->SetModeToRigidBody();
icp->SetMaximumNumberOfIterations(20);
icp->StartByMatchingCentroidsOn();
icp->Modified();
icp->Update();

vtkNew<vtkTransformPolyDataFilter> icpTransformFilter;
icpTransformFilter->SetInputData(source);
icpTransformFilter->SetTransform(icp);
icpTransformFilter->Update();

//Write to file
vtkNew<vtkXMLPolyDataWriter> writer;
writer->SetFileName(outputVolume.c_str());
writer->SetInputData(icpTransformFilter->GetOutput());
writer->Update();
}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e << '\n';
return EXIT_FAILURE;
}

return EXIT_SUCCESS;

}
36 changes: 36 additions & 0 deletions AlignMeshICP/AlignMeshICP.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>Surface Models.Advanced</category>
<title>AlignMeshICP</title>
<description><![CDATA[This is a CLI module that can be bundled in an extension]]></description>
<version>0.0.1</version>
<documentation-url>http://www.example.com/Slicer/Modules/avgMesh</documentation-url>
<license>Slicer</license>
<contributor>Ben Wilson (Kitware)</contributor>
<acknowledgements></acknowledgements>
<parameters>
<label>IO</label>
<description><![CDATA[Input/output parameters]]></description>
<geometry>
<name>inputVolume</name>
<label>Input Volume</label>
<channel>input</channel>
<index>0</index>
<description><![CDATA[Input volume]]></description>
</geometry>
<geometry>
<name>inputVolumeTwo</name>
<label>Input Volume Two </label>
<channel>input</channel>
<index>1</index>
<description><![CDATA[Input volume two]]></description>
</geometry>
<geometry>
<name>outputVolume</name>
<label>Output Volume</label>
<channel>output</channel>
<index>2</index>
<description><![CDATA[Output Volume]]></description>
</geometry>
</parameters>
</executable>
47 changes: 47 additions & 0 deletions AlignMeshICP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#-----------------------------------------------------------------------------
set(MODULE_NAME AlignMeshICP)

#-----------------------------------------------------------------------------

#
# SlicerExecutionModel
#
find_package(SlicerExecutionModel REQUIRED)
include(${SlicerExecutionModel_USE_FILE})

#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
ITKIOImageBase
ITKSmoothing
)
find_package(ITK 5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
include(${ITK_USE_FILE})

#-----------------------------------------------------------------------------
set(MODULE_INCLUDE_DIRECTORIES
)

set(MODULE_SRCS
)

set(MODULE_TARGET_LIBRARIES
${ITK_LIBRARIES}
${VTK_LIBRARIES}
)

#-----------------------------------------------------------------------------
SEMMacroBuildCLI(
NAME ${MODULE_NAME}
TARGET_LIBRARIES ${MODULE_TARGET_LIBRARIES}
INCLUDE_DIRECTORIES ${MODULE_INCLUDE_DIRECTORIES}
ADDITIONAL_SRCS ${MODULE_SRCS}
)

#-----------------------------------------------------------------------------
if(BUILD_TESTING)
add_subdirectory(Testing)
endif()
1 change: 1 addition & 0 deletions AlignMeshICP/Data/Baseline/AlignMeshICPTest.nhdr.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fc6170ceeff3d8217a9dd6a1add2ec8c
1 change: 1 addition & 0 deletions AlignMeshICP/Data/Baseline/AlignMeshICPTest.raw.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0749d4d3f07a217030f9ae33d94c4559
1 change: 1 addition & 0 deletions AlignMeshICP/Data/Input/CTHeadAxial.nhdr.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6e5c289c73e14ba7a1b0f8aaf6ed249a
1 change: 1 addition & 0 deletions AlignMeshICP/Data/Input/CTHeadAxial.raw.gz.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3ebd710c9cf9d75750f4569b8caf6d07
1 change: 1 addition & 0 deletions AlignMeshICP/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Cxx)
Loading

0 comments on commit 2786ff1

Please sign in to comment.