[vtkusers] Using vtkFillHolesFilter on meshes

KK karoll.frindel at gmail.com
Thu Apr 21 04:22:16 EDT 2011


Here is the code that uses the filter

bool TriangulationModel::FillHoles()
{

           VTKMesh* filter  = new VTKMesh(this);
	filter->Convert();

	vtkSmartPointer<vtkFillHolesFilter> fillHolesFilter =
           vtkSmartPointer<vtkFillHolesFilter>::New();
	fillHolesFilter->SetInput(filter->GetPolyData());
	fillHolesFilter->Update();

	filter->SetPolyData(fillHolesFilter->GetOutput());
	filter->Update();
	return true;

} //FillHoles

The class VTKMesh allows me to convert my mesh data format to the VTK one.

#include "vtkPoints.h"
#include "vtkCellArray.h"

VTKMesh::VTKMesh(TriangulationModel* myModel)
{
	m_poly = vtkSmartPointer<vtkPolyData>::New();
	m_model = myModel;
}


VTKMesh::~VTKMesh() 
{
}

void VTKMesh::Convert()
{
	try
	{
		// Points
		double tempPoint[3];
		int iNbPoints = m_model->GetPointSet()->GetNbPts();
		vtkSmartPointer<vtkPoints>	pointsVtk = vtkSmartPointer<vtkPoints>::New( );
		pointsVtk->SetDataTypeToDouble( );
		pointsVtk->SetNumberOfPoints(iNbPoints);

		// Add the points
		for (unsigned iNumPoint = 0; iNumPoint < iNbPoints; iNumPoint++)
		{
			fPoint3D tempPoint = m_model->GetPointSet()->GetPoint(iNumPoint);
			pointsVtk->SetPoint(iNumPoint,tempPoint.x,tempPoint.y,tempPoint.z);
		}
		m_poly->SetPoints(pointsVtk); 

		//Surface Elements
		int iNbTri = m_model->GetNbTri();
		vtkSmartPointer<vtkCellArray> cellArray =
vtkSmartPointer<vtkCellArray>::New( );
		vtkIdType pointsId[3];

		// Adds surface elements
		for (unsigned i = 0; i < iNbTri ; i++)
		{
			pointsId[0] =
m_model->GetPointSet()->Adr2Indice(m_model->GetT(i).GetAPtr());
			pointsId[1] =
m_model->GetPointSet()->Adr2Indice(m_model->GetT(i).GetBPtr());
			pointsId[2] =
m_model->GetPointSet()->Adr2Indice(m_model->GetT(i).GetCPtr());
			cellArray->InsertNextCell( 3, pointsId );
		}
		m_poly->SetPolys(cellArray);
	}
	catch (...)
	{
		throw;
	}	

}

void VTKMesh::Update()
{
	try
	{
		// Fill our data with their data
		vtkSmartPointer<vtkCellArray> cellArray = m_poly->GetPolys();
		int iNbT = cellArray->GetNumberOfCells();
		int iNbPts = m_poly->GetPoints()->GetNumberOfPoints();
		fPoint3D* p_Pts = new fPoint3D[iNbPts];
		sInt** p_Triangles = new sInt*[iNbT];
		double point[3];

		for (int i=0; i&lt;iNbT; i++)
		{
			p_Triangles[i] = new sInt[3];
			int iMaxCellSize = cellArray-&gt;GetMaxCellSize();
			vtkIdType npts = iMaxCellSize;
			vtkIdType* pointsId = new vtkIdType[iMaxCellSize];
			cellArray->GetNextCell(npts, pointsId); //get the triangle indices

			/*char msg[256];
			sprintf(msg,"points in the triangle 1-%d: %d, %d, %d
\n",j,pointsId[0],pointsId[1],pointsId[2]);
			MessageBox(NULL,msg,"",NULL);
			*/
			p_Triangles[i][0] = pointsId[0];
			m_poly->GetPoints()->GetPoint(pointsId[0],point);
			p_Pts[pointsId[0]] = fPoint3D(point[0],point[1],point[2]);

			p_Triangles[i][1] = pointsId[1];
			m_poly->GetPoints()->GetPoint(pointsId[1],point);
			p_Pts[pointsId[1]] = fPoint3D(point[0],point[1],point[2]);

			p_Triangles[i][2] = pointsId[2];
			m_poly->GetPoints()->GetPoint(pointsId[2],point);
			p_Pts[pointsId[2]] = fPoint3D(point[0],point[1],point[2]);
		}
		
		m_model->AdaptSTLInfo2Triangulation(iNbPts,p_Pts,iNbT,p_Triangles,0.01);
	}

	catch (...)
	{
		throw;
	}

}

vtkSmartPointer<vtkPolyData> VTKMesh::GetPolyData()
{
	return m_poly;
}

void VTKMesh::SetPolyData(vtkSmartPointer<vtkPolyData> new_poly)
{
	m_poly = new_poly;
}

TriangulationModel* VTKMesh::GetTriangulationModel()
{
	return m_model;
}

The problem occurs in the function UpDate() of this class ; on line
cellArray-> GetNextCell (npts, pointsId) / / Get the triangle indices
Npts is 0 while I supposed it should equal 3 so that the cell of the "filled
mesh" describe a triangle. 



--
View this message in context: http://vtk.1045678.n5.nabble.com/Using-vtkFillHolesFilter-on-meshes-tp4328350p4330278.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list