#include "DefOrgViewerAdapterBaseTemplated.h" namespace mial{ //explicit instantiations template class DefOrgViewerAdapterBaseTemplated; template void DefOrgViewerAdapterBaseTemplated::PopulateVtkImageHelper(ImageTypePointer itkImage, vtkImageImport* vtkImporter){ itkImageExportTypePointer itkExporter = itkImageExportType::New(); m_itkImageExportPointerHolder.push_back(itkExporter); itkExporter->SetInput( itkImage ); itkExporter->Update(); ConnectPipelines( itkExporter, vtkImporter ); vtkImporter->Update(); } template void DefOrgViewerAdapterBaseTemplated::ConnectPipelines( typename itkImageExportType::Pointer exporter, vtkImageImport* importer) { importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback()); importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback()); importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback()); importer->SetSpacingCallback(exporter->GetSpacingCallback()); importer->SetOriginCallback(exporter->GetOriginCallback()); importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback()); importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback()); importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback()); importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback()); importer->SetDataExtentCallback(exporter->GetDataExtentCallback()); importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback()); importer->SetCallbackUserData(exporter->GetCallbackUserData()); } template void DefOrgViewerAdapterBaseTemplated::MeshToUnstructuredGrid( MeshTypePointer mesh, vtkUnstructuredGrid* vgrid ) { // Get the number of points in the mesh int numPoints = mesh->GetNumberOfPoints(); if(numPoints == 0) { mesh->Print(std::cerr); std::cerr << "no points in Grid " << std::endl; } // Create the vtkPoints object and set the number of points vtkPoints* vpoints = vtkPoints::New(); vpoints->SetNumberOfPoints(numPoints); // iterate over all the points in the itk mesh filling in // the vtkPoints object as we go MeshType::PointsContainer::Pointer points = mesh->GetPoints(); for(MeshType::PointsContainer::Iterator i = points->Begin(); i != points->End(); ++i) { // Get the point index from the point container iterator int idx = i->Index(); // Set the vtk point at the index with the the coord array from itk // itk returns a const pointer, but vtk is not const correct, so // we have to use a const cast to get rid of the const vpoints->SetPoint(idx, const_cast(i->Value().GetDataPointer())); } // Set the points on the vtk grid vgrid->SetPoints(vpoints); // Now create the cells using the MulitVisitor // 1. Create a MultiVisitor MeshType::CellType::MultiVisitor::Pointer mv = MeshType::CellType::MultiVisitor::New(); // 2. Create a triangle and quadrilateral visitor TriangleVisitor::Pointer tv = TriangleVisitor::New(); QuadrilateralVisitor::Pointer qv = QuadrilateralVisitor::New(); // 3. Set up the visitors int vtkCellCount = 0; // running counter for current cell being inserted into vtk int numCells = mesh->GetNumberOfCells(); int *types = new int[numCells]; // type array for vtk // create vtk cells and estimate the size vtkCellArray* cells = vtkCellArray::New(); cells->EstimateSize(numCells, 4); // Set the TypeArray CellCount and CellArray for both visitors tv->SetTypeArray(types); tv->SetCellCounter(&vtkCellCount); tv->SetCellArray(cells); qv->SetTypeArray(types); qv->SetCellCounter(&vtkCellCount); qv->SetCellArray(cells); // add the visitors to the multivisitor mv->AddVisitor(tv); mv->AddVisitor(qv); // Now ask the mesh to accept the multivisitor which // will Call Visit for each cell in the mesh that matches the // cell types of the visitors added to the MultiVisitor mesh->Accept(mv); // Now set the cells on the vtk grid with the type array and cell array vgrid->SetCells(types, cells); // Clean up vtk objects (no vtkSmartPointer ... ) cells->Delete(); vpoints->Delete(); } }