[Insight-users] itk::fem

Vincent A. Magnotta vincent-magnotta at uiowa.edu
Tue Nov 20 09:26:07 EST 2007


Markus,

We have implemented something similar using the itk::fem framework. We
have always treated the deforming mesh as a solid meaning that it
contains hex or tet elements that compose the structure. In this case we
will load a vtkUnstructured grid convert it to an ITK mesh and then to a
itk::fem mesh. We then deform the mesh by applying loads to the surface
nodes of the mesh while applying a boundary condition to the center node
to hold it fixed. 

I have attached code for the conversion from vtk into an itk::fem mesh. 


Vince
 


On Tue, 2007-11-20 at 10:12 +0100, Markus Mehrwald wrote:
> Sorry...the whole Mail again!
> 
> Hello everyone,
> 
> I am looking for an example for the itk:fem package. Following a short 
> description of of my problem.
> I have a sphere as VTK Polydata. This sphere should be transfered into a 
> image which I can use with itk:fem (actually I do not understand why I 
> cannot use a mesh). To the center of the sphere should a force be 
> applied in the outward direction that the sphere is growing. The bigger 
> sphere should be transformed back into a VTK Polydata.
> Has anyone an example for this or even for parts of the whole problem.
> 
> Thank you very much in advance,
> Markus
> 
-- 
Assistant Professor
Department of Radiology
0453-D JCP
200 Hawkins Drive
Iowa City, IA 52242
E-mail: vincent-magnotta at uiowa.edu
Phone: 319-356-8255
Fax: 319-353-6275
Website: http://www.radiology.uiowa.edu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ItkMeshToFEMMesh.h
Type: text/x-chdr
Size: 2516 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20071120/0e5973e9/ItkMeshToFEMMesh.h
-------------- next part --------------
#ifndef __ItkMeshToFEMMesh_cxx
#define __ItkMeshToFEMMesh_cxx

#include <iostream>
#include "ItkMeshToFEMMesh.h"

namespace itk
{

template <class TInputMesh>
ItkMeshToFEMMesh<TInputMesh>
::ItkMeshToFEMMesh()
  {
    m_FileName = "";
    m_Solver = new SolverType;
  }

template <class TInputMesh>
ItkMeshToFEMMesh<TInputMesh>
::~ItkMeshToFEMMesh()
  {
  delete m_Solver;
  }

template <class TInputMesh>
typename ItkMeshToFEMMesh<TInputMesh>::SolverPointerType
ItkMeshToFEMMesh<TInputMesh>
::GetOutput( )
  {
  return m_Solver;
  }


template <class TInputMesh>
void
ItkMeshToFEMMesh<TInputMesh>
::Update( )
{
  // Create dummy material
  MaterialType::Pointer mat = MaterialType::New();
  mat->GN = 0;
  mat->E = 200E6;
  mat->A = 1.0;
  mat->h = 1.0;
  mat->I = 1.0;
  mat->nu = 0.2;
  mat->RhoC = 1.0;

  // Create element type
  HexElementType::Pointer hexElement = HexElementType::New( );
  HexElementType::Pointer hexElement2;
  hexElement->m_mat = dynamic_cast<MaterialType*>( mat );

  TriangElementType::Pointer triangElement = TriangElementType::New( );
  TriangElementType::Pointer triangElement2;
  triangElement->m_mat = dynamic_cast<MaterialType*>( mat );

  // Convert mesh points into nodes
  PointType* ptr;
  PointType pt;
  ptr = &pt;

  int numofpoints = m_Input->GetNumberOfPoints();
  //std::cerr << "# points: " << numofpoints << std::endl;


  // Convert cells into elements
  CellsContainerPointer cellList = m_Input->GetCells();
  CellIterator cells = cellList->Begin();


  //std::cerr << m_Input << std::endl;
  int numberOfCells = m_Input->GetNumberOfCells( );
  //std::cerr << "# cells: " << numberOfCells << std::endl;

  bool Flag = true;

  for (int k=0; k < numberOfCells; k++) 
    {
      CellType* cellPtr = cells.Value();
      //std::cout << "CELL TYPE  = " << cellPtr->GetType() << " Hex Element Type " <<
      //CellType::HEXAHEDRON_CELL << std::endl;

      switch( cellPtr->GetType( ) )
        {
        case CellType::HEXAHEDRON_CELL:
          {
          //std::cout << "Add Hex Element" << std::endl;
          if ( Flag ) // To make sure that the nodes are created just once
            {
              for (int j=0; j < numofpoints; j++) 
                {
                  m_Input->GetPoint(j, ptr);

                  HexNodeType::Pointer hexNode;
                  hexNode = new HexNodeType(pt[0], pt[1], pt[2]);
                  hexNode->GN = j;
                  m_Solver->node.push_back(itk::fem::FEMP<HexNodeType>(hexNode));
                }
              Flag = false;
            }
            PointIdIterator pointIt = cellPtr->PointIdsBegin() ;
            int i=0;
            hexElement2 = dynamic_cast<HexElementType*> (hexElement->Clone());
            while (pointIt != cellPtr->PointIdsEnd() ) 
              {
              hexElement2->SetNode(i, m_Solver->node.Find( *pointIt ));  
              pointIt++;  
              i++;
              }
            cells++;
              
            hexElement2->GN = k;
            m_Solver->el.push_back(itk::fem::FEMP<itk::fem::Element>(hexElement2)); 

            break;
          }

        case CellType::TRIANGLE_CELL:
          {
            if ( Flag ) // To make sure that the nodes are created just once
              {
                for (int j=0; j < numofpoints; j++) 
                  {
                    m_Input->GetPoint(k, ptr);

                    TriangNodeType::Pointer triangNode;
                    triangNode = new TriangNodeType(pt[0], pt[1], pt[2]);
                    triangNode->GN = j;
                    m_Solver->node.push_back(itk::fem::FEMP<TriangNodeType>(triangNode));
                  }
                Flag = false;
              }
            PointIdIterator pointIt = cellPtr->PointIdsBegin() ;
            int i=0;
            triangElement2 = dynamic_cast<TriangElementType*> (triangElement->Clone());
            while (pointIt != cellPtr->PointIdsEnd() ) 
              {
              triangElement2->SetNode(i, m_Solver->node.Find( *pointIt ));  
              pointIt++;  i++;
              }
            cells++;

            triangElement2->GN = k;
            m_Solver->el.push_back(itk::fem::FEMP<itk::fem::Element>(triangElement2)); 
            break;
          }
        }
    }

  //std::cerr << "Converted Cells " << std::endl;

 /* #ifdef __sgi
  // Create the file. This is required on some older sgi's
  std::ofstream tFile(m_FileName.c_str( ),std::ios::out);
  tFile.close( );           
  #endif*/
  /*std::ofstream out;
  out.open( m_FileName.c_str( ), std::ios::out );
  m_Solver->Write( out );
  out.close( );
  m_Solver->Write(std::cout);*/
  
 }
}

#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkUnstructuredGridToitkMesh.cxx
Type: text/x-c++src
Size: 3287 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20071120/0e5973e9/vtkUnstructuredGridToitkMesh.cxx
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkUnstructuredGridToitkMesh.h
Type: text/x-chdr
Size: 1294 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20071120/0e5973e9/vtkUnstructuredGridToitkMesh.h


More information about the Insight-users mailing list