[IGSTK-Users] Reading STL files

Andrew Wiles awiles at ndigital.com
Tue Aug 10 14:01:10 EDT 2010


Thanks Sebastian.  Much appreciated.

I was wondering if I would have to go through the VTK reader, but I figured I should inquire with the community in case there was something I was missing.  I couldn't find anything on Google, but at least your solution will now be found by Google.

Thanks again for your help.

Cheers.
Andrew

--------------------
Andrew D. Wiles, PhD, PEng
Research Scientist, Medical Division
NDI
103 Randall Drive
Waterloo, ON, Canada, N2V 1C5
Telephone: +1 (519) 884-5142 ext. 314
Toll Free: +1 (877) 634-6340
Global: ++ (800) 634-634-00
Facsimile: +1 (519) 884-5184
Website: www.ndigital.com
--------------------

>>> Sebastian Bodenstedt <sbodenstedt at ehmo.org> 8/10/2010 1:55 PM >>>
Hello Andrew,
I accomplish this by first reading the STL file with the vtkSTLReader class from 
the vtk:

vtkSTLReader * reader = vtkSTLReader::New();
reader->SetFileName(fname);
reader->Update();
vtkPolyData* polyData = reader->GetOutput();

I then convert it into a Mesh Spatial Object

igstk::MeshObject::Pointer meshObject = igstk::MeshObject::New(); 

int numPts = polyData->GetNumberOfPoints();
	
vtkCellArray * verts = polyData->GetPolys();
	
int numVerts = verts->GetNumberOfCells();
		
for (int i = 0;i < numPts;i++)
{
	double* pt = polyData->GetPoint(i);
	meshObject->AddPoint(i,pt[0],pt[1],pt[2]);
}
		
verts->InitTraversal();
	
for (int i = 0;i < numVerts;i++)
{
	vtkIdType* pts;
	vtkIdType count;
		
	verts->GetNextCell(count,pts);
		
	meshObject->AddTriangleCell(i,pts[0],pts[1],pts[2]);
}

This definitely works, though there might exist a more elegant solution, I am 
not aware of. 

Greetings,
Sebastian
On Tuesday, August 10, 2010 05:14:45 pm Andrew Wiles wrote:
> Hello,
> 
> Does anyone have an example on how to import an STL file into an IGSTK Mesh
> Spatial Object?
> 
> Thanks,
> 
> Andrew
> 
> --------------------
> Andrew D. Wiles, PhD, PEng
> Research Scientist, Medical Division
> NDI
> 103 Randall Drive
> Waterloo, ON, Canada, N2V 1C5
> Telephone: +1 (519) 884-5142 ext. 314
> Toll Free: +1 (877) 634-6340
> Global: ++ (800) 634-634-00
> Facsimile: +1 (519) 884-5184
> Website: www.ndigital.com 
> --------------------
> 
> _______________________________________________
> Powered by www.kitware.com 
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html 
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/cgi-bin/mailman/listinfo/igstk-users




More information about the IGSTK-Users mailing list