[vtkusers] Exporting 3D Extruded text to a file

Bill Lorensen bill.lorensen at gmail.com
Thu Jan 14 08:45:51 EST 2010


1) The method name is GetOutput(), not getOutput()
2) STL only writes triangles. Place a vtkTriangleFilter between the
extruder and the writer.

Bill

On Thu, Jan 14, 2010 at 2:31 AM, David Morris <dvmorris at gmail.com> wrote:
> 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
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list