[vtkusers] vtkTriangleStrip and empty vtkSTLWriter output

Cory Quammen cory.quammen at kitware.com
Wed Oct 14 13:10:05 EDT 2015


Maybe try inserting a vtkTriangleFilter in front of your STL writer?

- Cory

On Mon, Oct 12, 2015 at 6:12 PM, <piers.barber at logicmonkey.co.uk> wrote:

> Hello VTKers
>
> I was getting empty STL file output from a program I wrote using the ruled
> surface filter. So I thought I would take a different approach and create
> triangle strips.
>
> The code does what I would expect, but I still get an empty STL file
> (which I think would be because there are no polys in the polydata).
>
> The ruled surface I can believe would have this problem, but a triangle
> strip should be OK?
>
> My full test example code follows. It creates a triangle strip 2 triangles
> at a time by starting with 2 points and then successively adding more in
> pairs.
>
> If there is a step that I have missed that is required to convert this to
> individual triangles for vtxSTLWriter, what would happen to vertex winding
> order?
>
> All comments and observations welcome!
>
> Thanks.
>
> -=:LogicMonkey:=-
>
> #include <vtkVersion.h>
> #include <vtkSmartPointer.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkCellArray.h>
> #include <vtkTransform.h>
> #include <vtkTransformPolyDataFilter.h>
> #include <vtkAppendPolyData.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkProperty.h>
> #include <vtkCamera.h>
> #include <vtkTriangleStrip.h>
> #include <vtkSTLWriter.h>
>
> #define VERTICES 100
>
> int main(int, char *[]) {
>
> vtkSmartPointer<vtkPoints>
> points = vtkSmartPointer<vtkPoints>::New();
> points->InsertPoint(0, 0, 0, 0);
> points->InsertPoint(1, 0, 1, 0);
>
> vtkSmartPointer<vtkTriangleStrip>
> strip = vtkSmartPointer<vtkTriangleStrip>::New();
> strip->GetPointIds()->SetNumberOfIds(VERTICES);
> strip->GetPointIds()->SetId(0,0);
> strip->GetPointIds()->SetId(1,1);
>
> for( int i=1; i<VERTICES/2; i++ ) {
>
> points->InsertPoint(2*i, (double) i, 0, 0);
> points->InsertPoint(2*i+1, (double) i, 1, 0);
>
> strip->GetPointIds()->SetId(2*i,2*i);
> strip->GetPointIds()->SetId(2*i+1,2*i+1);
> }
>
> vtkSmartPointer<vtkPolyData>
> polydata = vtkSmartPointer<vtkPolyData>::New();
>
> polydata->SetPoints(points);
>
> vtkSmartPointer<vtkCellArray>
> cells = vtkSmartPointer<vtkCellArray>::New();
> cells->InsertNextCell(strip);
>
> polydata->SetStrips(cells);
>
> // STL file output
>
> vtkSmartPointer<vtkSTLWriter>
> stlWriter = vtkSmartPointer<vtkSTLWriter>::New();
> stlWriter->SetFileName("StripEx.stl");
> stlWriter->SetInputData(polydata);
> stlWriter->Write();
>
> // now the usual VTK render and displey pipeline
>
> vtkSmartPointer<vtkPolyDataMapper>
> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInputData(polydata); // data to mapper
>
> vtkSmartPointer<vtkActor>
> actor = vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper); // mapper to actor
>
> actor->GetProperty()->SetColor(0.89, 0.81, 0.34);
> actor->GetProperty()->SetRepresentationToWireframe();
>
> // Add the actors to the renderer, set the background and size
> vtkSmartPointer<vtkRenderer>
> renderer = vtkSmartPointer<vtkRenderer>::New();
>
> vtkSmartPointer<vtkRenderWindow>
> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->AddRenderer(renderer);
>
> vtkSmartPointer<vtkRenderWindowInteractor>
> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
> interactor->SetRenderWindow(renderWindow);
>
> renderer->AddActor(actor);
> renderer->SetBackground(.3, .4, .5);
>
> renderer->ResetCamera();
> renderer->GetActiveCamera()->Azimuth(60);
> renderer->GetActiveCamera()->Elevation(60);
> renderer->GetActiveCamera()->Dolly(1.2);
> renderer->ResetCameraClippingRange();
>
> renderWindow->Render();
> interactor->Start();
>
> return EXIT_SUCCESS;
>
> }
>
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151014/e0505279/attachment.html>


More information about the vtkusers mailing list