[Insight-users] DeformableMesh3DFilter,GradientRecursiveGaussianImageFilter,vtk2i tkDouble.cxx

Waltraud Henrich henrich@ira.uka.de
Mon, 16 Dec 2002 13:11:26 +0100


Hallo,


1) I work with itkDeformableMesh3DFilter and now I get the OutputWindow. 

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkpointset.txx,
line 74
Mesh (088D9178): returning Points container of VectorContainer (013B4AA8)
  Reference Count: 2
  Modified Time: 9838
  Debug: Off
  Observers: 
    none



Debug: In
D:\Programme\Development\InsightToolkit-1.0.0\Code\Common\itkDataObject.cxx,
line 239
Mesh (088D9178): disconnecting source  088D7D98, source output index 0

Debug: In
D:\Programme\Development\InsightToolkit-1.0.0\Code\Common\itkObject.cxx,
line 288
Mesh (088D9178): UnRegistered, ReferenceCount = 0

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1061
Mesh (088D9178): Mesh Destructor 

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1078
Mesh (088D9178): Mesh  ReleaseCellsMemory method 

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1104
Mesh (088D9178): m_CellsContainer->GetReferenceCount()= 1

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1149
Mesh (088D9178): CellsAllocatedDynamicallyCellByCell

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1168
Mesh (088D9178): Mesh  ReleaseBoundariesMemory method 

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1195
Mesh (088D9178): Mesh  ReleaseBoundariesMemory(unsigned int) method 

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1286
Mesh (088D9178): Boundaries already deleted.

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1195
Mesh (088D9178): Mesh  ReleaseBoundariesMemory(unsigned int) method 

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1286
Mesh (088D9178): Boundaries already deleted.

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1195
Mesh (088D9178): Mesh  ReleaseBoundariesMemory(unsigned int) method 

Debug: In
d:\programme\development\insighttoolkit-1.0.0\code\common\itkmesh.txx, line
1286
Mesh (088D9178): Boundaries already deleted.

Debug: In
D:\Programme\Development\InsightToolkit-1.0.0\Code\Common\itkObject.cxx,
line 447
Object (088D9178): Destructing!


2) When I save vtkUnstructuredGrid in a file and when I look this file I get
following:

# vtk DataFile Version 3.0
vtk output
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 402 float
-1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#INF 
-1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#INF 
-1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#INF 
-1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#INF 
-1.#INF -1.#INF 1.#INF -1.#INF -1.#INF 1.#IN.......etc

My problem is that in vtk2itkDouble.cxx this coordinates are #INF..

pcoordinates[0] = pp[0];
pcoordinates[1] = pp[1];
pcoordinates[2] = pp[2];

Can you tell me where the problem is?

3) I can disply my SphereSource with vtk2itkDouble. The coordinates are OK
here.

4) How can display GradientRecursiveGaussianImageFilter in vtk?  How can it
write into a file?
I tried with itktovtk pipline 	
	typedef itk::VTKImageExport<myImageType> ImageExportType;

	// Create the itk::VTKImageExport instance and connect it to the
	// itk::CurvatureFlowImageFilter.
	ImageExportType::Pointer itkExporter = ImageExportType::New();
	itkExporter->SetInput(gradient);

	// Create the vtkImageImport and connect it to the
	// itk::VTKImageExport instance.
	vtkImageImport* vtkImporter = vtkImageImport::New();  
	ConnectPipelines(itkExporter, vtkImporter);
	vtkImporter->Update();

and I get the following mistake:

D:\user\henrich\mediframedezember\Mediframe\SOURCE\COMPONENTS\Segmentation\S
nakeModel.cpp(310) : error C2664: 'SetInput' : Konvertierung des Parameters
1 von 'class itk::SmartPointer<class
itk::GradientRecursiveGaussianImageFilter<class itk::Image<d
ouble,3>,class itk::Image<class itk::CovariantVector<double,3>,3> > >' in
'const class itk::Image<double,3> *' nicht moeglich
        Kein benutzerdefinierter Konvertierungsoperator verfuegbar, der
diese Konvertierung durchfuehren kann, oder der Operator kann nicht
aufgerufen werden
Fehler beim Ausführen von cl.exe.

MediFrame.exe - 1 Fehler, 0 Warnung(en)


My code is the following:

Thanks a lot.

Waltraut Henrich


	vtkImageData* pImage = GetImageData() ;
	
	pImage->GetDimensions(m_ImageDim );
	
	int SEEDX = m_nSeedX;
	int SEEDY = m_nSeedY;
	int SEEDZ = m_nSeedZ;
	
	WIDTH = m_ImageDim[0];
	HEIGHT = m_ImageDim[1];
	DEPTH = m_ImageDim[2];
	
	//VTK->ITK
	vtkImageCast *floatImage = vtkImageCast::New();
    	floatImage->SetInput(pImage);
   	 floatImage->SetOutputScalarTypeToDouble();  //Bild in auf
short-Daten konvertieren 
	floatImage->Update();
	
	vtkImageExport* vtkExporter = vtkImageExport::New();
	vtkExporter->SetInput(floatImage->GetOutput());
	
	
	
	
//------------------------------------------------------------------------
	// VTK to ITK pipeline connection.
	
//------------------------------------------------------------------------
	
	
	typedef itk::Image<double, 3> myImageType;
	typedef itk::Index<3> myIndexType;
	
	
	typedef itk::VTKImageImport<myImageType> myImageImportType;
	myImageImportType::Pointer itkImporter = myImageImportType::New();
	ConnectPipelines(vtkExporter, itkImporter);
	
	itkImporter->Update();
	
	typedef itk::DeformableMesh3DFilter<doubleMesh,doubleMesh>
Deformable3DFilterType;
	typedef Deformable3DFilterType::GradientImageType
GradientImageType;
	
	
	typedef itk::GradientRecursiveGaussianImageFilter< myImageType,
GradientImageType > GradientImageFilterType;
	

	typedef itk::SphereSource<doubleMesh> DoubleSphereSource;
	typedef DoubleSphereSource::OPointType  OPointType;
	
	DoubleSphereSource::Pointer m_spheresource =
DoubleSphereSource::New();
	
	OPointType m_spherecenter;
	OPointType m_scale;
	
	m_spherecenter[0] = (double) SEEDX;
	m_spherecenter[1] = (double) SEEDY;
	m_spherecenter[2] = (double) SEEDZ;
	m_scale[0] = 10;
	m_scale[1] = 10;
	m_scale[2] = 10;
	
	
	m_spheresource->SetCenter(m_spherecenter);
	m_spheresource->SetScale(m_scale);
	m_spheresource->SetResolutionX(20);
	m_spheresource->SetResolutionY(20);
	m_spheresource->SetSquareness1(1);
	m_spheresource->SetSquareness2(1);
	m_spheresource->Update();
	
	
	
	GradientImageFilterType::Pointer gradient =
GradientImageFilterType::New();
	gradient->SetInput(itkImporter->GetOutput());
	gradient->SetSigma(2.0);
	
	gradient->Update();
	
	//try
    //{
	// gradient->Update();
    //}
	//catch( itk::ExceptionObject & exp )
    //{
	//GfxPrint("Exception thrown during gradient filter Update() ");
    //}
	
	

		
	Deformable3DFilterType::Pointer m_bfilter =
Deformable3DFilterType::New();

	m_bfilter->SetGradient(gradient->GetOutput());
	m_bfilter->SetInput(m_spheresource->GetOutput()); //ok die
Anfangsnetz setzen
	
	m_bfilter->Update();
	
	
	
	//try
    //{
    //m_bfilter->Update();
    //}
	//catch( itk::ExceptionObject & exp )
    //{
	// GfxPrint("Exception thrown during mesh filter Update() ");
    //}
	
	
	
	
//------------------------------------------------------------------------
	// ITK to VTK connection.
	
//------------------------------------------------------------------------
		  
	
	// Get the number of points in the mesh
	int numPoints = m_bfilter->GetOutput()->GetNumberOfPoints();
	//int numPoints = m_spheresource->GetOutput()->GetNumberOfPoints();
	if(numPoints == 0)
    {
		m_bfilter->GetOutput()->Print(std::cerr);
		
		//m_spheresource->GetOutput()->Print(std::cerr);
		std::cerr << "no points in Grid " << std::endl;
		exit(-1);
    }
	// Create a vtkUnstructuredGrid
	vtkUnstructuredGrid* vgrid = vtkUnstructuredGrid::New();
	
	// 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
	doubleMesh::PointsContainer::Pointer points =
m_bfilter->GetOutput()->GetPoints();
	//doubleMesh::PointsContainer::Pointer points =
m_spheresource->GetOutput()->GetPoints();
	
	
	
	for(doubleMesh::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
		doubleMesh::PointType  & pp = i->Value();
		float pcoordinates[3]; 
		pcoordinates[0] = pp[0];
		pcoordinates[1] = pp[1];
		pcoordinates[2] = pp[2];
		vpoints->SetPoint(idx, pcoordinates);
		// vpoints->SetPoint(idx,
const_cast<double*>(i->Value().GetDataPointer()));
    }
	// Set the points on the vtk grid
	vgrid->SetPoints(vpoints);
	
	// Now create the cells using the MulitVisitor
	// 1. Create a MultiVisitor
	doubleMesh::CellType::MultiVisitor::Pointer mv =
		doubleMesh::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 = m_bfilter->GetOutput()->GetNumberOfCells();
	
	//int numCells = m_spheresource->GetOutput()->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
	 m_bfilter->GetOutput()->Accept(mv);
	
	//m_spheresource->GetOutput()->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();
	// return the vtkUnstructuredGrid
	//return vgrid;
	
	vgrid->Update();
	
	vtkUnstructuredGridWriter * writer = vtkUnstructuredGridWriter
::New();
	writer->SetInput(vgrid);
	writer->SetFileName("./snake.vtk");
	writer->Update();
	
	
	GfxMeshViewer(vgrid,"Snake");