[vtkusers] Exporting 3D Extruded text to a file
David Morris
dvmorris at gmail.com
Thu Jan 14 10:11:27 EST 2010
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.
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.
Thanks,
Dave
On Thu, Jan 14, 2010 at 7:53 AM, David Doria
<daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>
> wrote:
> 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
>
> Dave,
>
> Welcome to VTK!
>
> I have multiple comments/suggestions for you:
>
> 1) You will find it really helpful to use smart pointers rather than
> normal pointers (I see that you have done that in some places):
>
> vtkSmartPointer<vtkLinearExtrusionFilter> extrude =
> vtkSmartPointer<vtkLinearExtrusionFilter>::New();
> rather than:
> vtkLinearExtrusionFilter* extrude = vtkLinearExtrusionFilter::New();
>
> with the old style pointers, you are *supposed* to call
> extrude->Delete() when you are done using it, but with a smart pointer
> that is not necessary. Smart pointers will also help you do things
> like return pointers from functions and other tasks with much less
> headache.
>
> 2) There is no need to create a mapper and an actor if your goal is to
> write the result to a file. Mappers/actor are for use with
> renderers/renderwindows.
>
> 3) You should ALWAYS update filters before you use their output:
> extrude->Update();
>
> (until you know exactly what is going on and when the pipeline is updating
> :) )
>
> 4) The preferred method is SetInputConnection(xxx->GetOutputPort())
> rather than SetInput(xxx->GetOutput())
>
> 5) To verify that your file is "correct", you should use Paraview
> (www.paraview.org) to view it.
>
> 6) I fixed your code here:
> http://www.vtk.org/Wiki/VTK/Examples/LinearExtrusion
>
> 7) We have been working hard to compile a giant list of examples of
> how to do many common things in VTK:
>
> http://www.vtk.org/Wiki/VTK/Examples
>
> Please check that out and let us know if it helps!
>
> Enjoy!
>
> David
> _______________________________________________
> 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
>
--
Dave Morris
http://dave.showviz.net/
http://3dcamphouston.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100114/33f13947/attachment.htm>
More information about the vtkusers
mailing list