[vtkusers] Exporting 3D Extruded text to a file
David Morris
dvmorris at gmail.com
Thu Jan 14 02:31:16 EST 2010
I have some basic code that creates a 3D text, applies a linear extrusion
filter, and then displays it in a viewport. This works well, but now I would
like to output the result of the extrusion to an STL file using
vtkStlWriter. I am extremely new to VTK (just got it to compile two hours
ago), so I believe I'm just missing something really basic. Here is the
relevant code:
...
// Create vector text
vtkVectorText* vecText = vtkVectorText::New();
vecText->SetText("Text!");
// Apply linear extrusion
vtkLinearExtrusionFilter* extrude = vtkLinearExtrusionFilter::New();
extrude->SetInputConnection( vecText->GetOutputPort());
extrude->SetExtrusionTypeToNormalExtrusion();
extrude->SetVector(0, 0, 1 );
extrude->SetScaleFactor (0.5);
// output the mesh to a PolyDataMapper and then to an Actor
vtkPolyDataMapper* txtMapper = vtkPolyDataMapper::New();
txtMapper->SetInputConnection( extrude->GetOutputPort());
vtkActor* txtActor = vtkActor::New();
txtActor->SetMapper(txtMapper);
// add it to the renderer
ren->AddActor(txtActor);
// attempt to write an STL file
std::string outputFilename = "test.stl";
vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New();
*// data = extrude->getOutput();* // this line causes an error: *'class
vtkLinearExtrusionFilter' has no member named 'getOutput'*
vtkSmartPointer<vtkSTLWriter> stlWriter =
vtkSmartPointer<vtkSTLWriter>::New();
stlWriter->SetFileName(outputFilename.c_str());
*stlWriter->SetInput(data);* // passing *extrude->getOutput()* here
seems to work, but doesn't send the walls of the extrusion
stlWriter->Write();
...
When I try to run:
stlWriter->setInput(extrude->getOutput());
it just outputs the text twice, separated by the thickness of the extrusion
but without the walls. Does that make sense. Let me know if I'm missing
something or if it is not possible. Thanks for the help, and I can certainly
send the whole code if someone wants to run it, but I think my problem is
simple enough that someone can just glance at the code and see what's wrong.
Thanks for the help in advance,
Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100114/03351412/attachment.htm>
More information about the vtkusers
mailing list