This is exactly what I was looking for! Wow, thank you guys so much for your help. I will be able to try it out when I get home from work tonight, because I'm on a Windows machine right now, and I am hesistant to try and build VTK from source again, as it took a few hours last night on my Mac. <div>
<br></div><div>I will let you know if I need any other help with this, and I'll try and update the wiki if I come up with any other useful examples.</div><div><br></div><div>Thanks,</div><div><br></div><div>Dave<br><br>
<div class="gmail_quote">On Thu, Jan 14, 2010 at 7:53 AM, David Doria <span dir="ltr"><<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Thu, Jan 14, 2010 at 2:31 AM, David Morris <<a href="mailto:dvmorris@gmail.com">dvmorris@gmail.com</a>> wrote:<br>
</div><div><div></div><div class="h5">> I have some basic code that creates a 3D text, applies a linear extrusion<br>
> filter, and then displays it in a viewport. This works well, but now I would<br>
> like to output the result of the extrusion to an STL file using<br>
> vtkStlWriter. I am extremely new to VTK (just got it to compile two hours<br>
> ago), so I believe I'm just missing something really basic. Here is the<br>
> relevant code:<br>
><br>
> ...<br>
><br>
> // Create vector text<br>
> vtkVectorText* vecText = vtkVectorText::New();<br>
> vecText->SetText("Text!");<br>
><br>
> // Apply linear extrusion<br>
> vtkLinearExtrusionFilter* extrude = vtkLinearExtrusionFilter::New();<br>
> extrude->SetInputConnection( vecText->GetOutputPort());<br>
> extrude->SetExtrusionTypeToNormalExtrusion();<br>
> extrude->SetVector(0, 0, 1 );<br>
> extrude->SetScaleFactor (0.5);<br>
><br>
> // output the mesh to a PolyDataMapper and then to an Actor<br>
> vtkPolyDataMapper* txtMapper = vtkPolyDataMapper::New();<br>
> txtMapper->SetInputConnection( extrude->GetOutputPort());<br>
> vtkActor* txtActor = vtkActor::New();<br>
> txtActor->SetMapper(txtMapper);<br>
><br>
> // add it to the renderer<br>
> ren->AddActor(txtActor);<br>
><br>
> // attempt to write an STL file<br>
> std::string outputFilename = "test.stl";<br>
> vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New();<br>
><br>
><br>
> // data = extrude->getOutput(); // this line causes an error: 'class<br>
> vtkLinearExtrusionFilter' has no member named 'getOutput'<br>
> vtkSmartPointer<vtkSTLWriter> stlWriter =<br>
> vtkSmartPointer<vtkSTLWriter>::New();<br>
> stlWriter->SetFileName(outputFilename.c_str());<br>
><br>
> stlWriter->SetInput(data); // passing extrude->getOutput() here seems to<br>
> work, but doesn't send the walls of the extrusion<br>
> stlWriter->Write();<br>
><br>
> ...<br>
><br>
> When I try to run:<br>
><br>
> stlWriter->setInput(extrude->getOutput());<br>
><br>
> it just outputs the text twice, separated by the thickness of the extrusion<br>
> but without the walls. Does that make sense. Let me know if I'm missing<br>
> something or if it is not possible. Thanks for the help, and I can certainly<br>
> send the whole code if someone wants to run it, but I think my problem is<br>
> simple enough that someone can just glance at the code and see what's wrong.<br>
> Thanks for the help in advance,<br>
><br>
> Dave<br>
<br>
</div></div>Dave,<br>
<br>
Welcome to VTK!<br>
<br>
I have multiple comments/suggestions for you:<br>
<br>
1) You will find it really helpful to use smart pointers rather than<br>
normal pointers (I see that you have done that in some places):<br>
<br>
vtkSmartPointer<vtkLinearExtrusionFilter> extrude =<br>
vtkSmartPointer<vtkLinearExtrusionFilter>::New();<br>
rather than:<br>
vtkLinearExtrusionFilter* extrude = vtkLinearExtrusionFilter::New();<br>
<br>
with the old style pointers, you are *supposed* to call<br>
extrude->Delete() when you are done using it, but with a smart pointer<br>
that is not necessary. Smart pointers will also help you do things<br>
like return pointers from functions and other tasks with much less<br>
headache.<br>
<br>
2) There is no need to create a mapper and an actor if your goal is to<br>
write the result to a file. Mappers/actor are for use with<br>
renderers/renderwindows.<br>
<br>
3) You should ALWAYS update filters before you use their output:<br>
extrude->Update();<br>
<br>
(until you know exactly what is going on and when the pipeline is updating :) )<br>
<br>
4) The preferred method is SetInputConnection(xxx->GetOutputPort())<br>
rather than SetInput(xxx->GetOutput())<br>
<br>
5) To verify that your file is "correct", you should use Paraview<br>
(<a href="http://www.paraview.org" target="_blank">www.paraview.org</a>) to view it.<br>
<br>
6) I fixed your code here: <a href="http://www.vtk.org/Wiki/VTK/Examples/LinearExtrusion" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/LinearExtrusion</a><br>
<br>
7) We have been working hard to compile a giant list of examples of<br>
how to do many common things in VTK:<br>
<br>
<a href="http://www.vtk.org/Wiki/VTK/Examples" target="_blank">http://www.vtk.org/Wiki/VTK/Examples</a><br>
<br>
Please check that out and let us know if it helps!<br>
<br>
Enjoy!<br>
<font color="#888888"><br>
David<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Dave Morris<br><a href="http://dave.showviz.net/">http://dave.showviz.net/</a><br><a href="http://3dcamphouston.com/">http://3dcamphouston.com/</a><br>
</div>