Skip to content

Instantly share code, notes, and snippets.

@arnaudgelas
Created April 19, 2011 19:36
Show Gist options
  • Save arnaudgelas/929409 to your computer and use it in GitHub Desktop.
Save arnaudgelas/929409 to your computer and use it in GitHub Desktop.
project( itkMetaImageMesh.cxx )
cmake_minimum_required( VERSION 2.6 )
find_package( ITK )
include( ${ITK_USE_FILE} )
add_executable( itkMetaImageMesh itkMetaImageMesh.cxx )
target_link_libraries( itkMetaImageMesh ${ITK_LIBRARIES} )
#include "itkImage.h"
#include "itkQuadEdgeMesh.h"
namespace itk
{
template< class TInput, class TNode, class TPixel >
class MyClassBase
{
public:
typedef TInput InputType;
typedef typename InputType::Pointer InputPointer;
typedef TNode NodeType;
virtual TPixel GetData( InputPointer input, NodeType iNode ) = 0;
void Print()
{
std::cout << "Print" << std::endl;
}
void MyMethod( InputPointer input )
{
this->GetData( input, NodeType() );
}
};
template< class TInput >
class MyClass
{
};
template< class TPixel, unsigned int VDimension >
class MyClass< Image< TPixel, VDimension > > :
public MyClassBase< Image< TPixel, VDimension >,
typename Image< TPixel, VDimension >::IndexType,
TPixel >
{
public:
typedef Image< TPixel, VDimension > InputType;
typedef typename InputType::Pointer InputPointer;
typedef typename InputType::IndexType NodeType;
TPixel GetData( InputPointer input, NodeType iNode )
{
return input->GetPixel( iNode );
}
};
template< class TPixel, unsigned int VDimension, class TTraits >
class MyClass< QuadEdgeMesh< TPixel, VDimension, TTraits > > :
public MyClassBase< QuadEdgeMesh< TPixel, VDimension, TTraits >,
typename QuadEdgeMesh< TPixel, VDimension, TTraits >::PointIdentifier,
TPixel >
{
public:
typedef QuadEdgeMesh< TPixel, VDimension, TTraits > InputType;
typedef typename InputType::Pointer InputPointer;
typedef typename InputType::PointIdentifier NodeType;
TPixel GetData( InputPointer input, NodeType iNode )
{
TPixel data;
input->GetPointData( iNode, &data );
return data;
}
};
}
int main( int argc, char* argv[] )
{
typedef itk::Image< unsigned char, 3 > ImageType;
typedef itk::MyClass< ImageType > ImageClassType;
ImageType::Pointer temp_image = ImageType::New();
ImageType::IndexType idx;
idx.Fill( 0 );
ImageClassType a;
a.Print();
a.MyMethod( temp_image );
a.GetData( temp_image.GetPointer(), idx );
typedef itk::QuadEdgeMesh< unsigned char, 3 > MeshType;
typedef itk::MyClass< MeshType > MeshClassType;
MeshType::Pointer temp_mesh = MeshType::New();
MeshType::PointIdentifier id = 0;
MeshClassType b;
b.Print();
b.MyMethod( temp_mesh );
b.GetData( temp_mesh.GetPointer(), id );
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment