[vtkusers] How to compute area of counter made by vtkContourWidget?

Yihui Cao yihui.cao at qq.com
Wed Dec 30 03:25:36 EST 2015


Hi all,


I used vtkContourWidget to label a contour on an image. And it also need to compute the area of contour. I tired by an example that first converted the contour by vtkTriangleFilter, and then use the vtkMassProperties to compute the area. The detailed code in a Callback function as follows:
////////////////
	void SetObject(vtkContourWidget * contour){
		m_contour = contour;
	}



	virtual void Execute(vtkObject *caller, unsigned long eventId, void *callData){


		int Num = m_contour->GetContourRepresentation()->GetNumberOfNodes();
		std::cout<<"NumOfNodes:"<<Num<<" "<<m_contour->GetContourRepresentation()->GetClosedLoop()<<endl;


		if (m_contour->GetContourRepresentation()->GetClosedLoop())
		{
			
			vtkSmartPointer<vtkTriangleFilter> triangleFileter = 
				vtkSmartPointer<vtkTriangleFilter>::New();


			triangleFileter->SetInput(m_contour->GetContourRepresentation()->GetContourRepresentationAsPolyData());
			
			vtkSmartPointer<vtkMassProperties> massProp = 
				vtkSmartPointer<vtkMassProperties>::New();


			//massProp->SetInput(triangleFileter->GetOutput());
			massProp->SetInputConnection(triangleFileter->GetOutputPort());


			double area = massProp->GetSurfaceArea();
			//double area = 12;
			std::cout<<"Counter Area:"<<area<<" um2"<<endl;
		}
	}

//////////////////////
When run the project, it will output some warring information in a vtkOutputWindow tha t"Warning: In ..\..\VTK5.10.1\Graphics\vtkMassProperties.cxx, line 120 vtkMassProperties (03636DC8): Input data type must be VTK_TRIANGLE not 3"


When is the problem? Or is there some other way to compute the area of contour made be vtkContourWidget?


Thanks
Yihui Cao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151230/c93ad247/attachment.html>


More information about the vtkusers mailing list