[vtkusers] vtk to stl -> code is working, but with error mesage. why?

Andreas Ruopp aruopp at gmx.de
Sat Jan 10 11:50:59 EST 2015


Hello,

in the framework of my project I need a stl-file out of an vtk-file.
Since I couldn't find something ready to use. I took the vtk-library, looked 
into the vtk-doxygen and yes, it is a great library and the writer works.

It compiles without any problems, the wished stl is written, but the 
programm 
complains, when I use the vtkUnstructuredGridReader class.
Any help would be greatly appreciated!

Best regards,

fr

##############################################

Run with: 
./WriteSTL in.vtk out.stl

###ERROR Message Start ###

ERROR: In 
/home/abuild/rpmbuild/BUILD/VTK5.10.1/Filtering/vtkStreamingDemandDrive
nPipeline.cxx, 
line 934
vtkStreamingDemandDrivenPipeline (0x96cf30): No maximum number of 
pieces has 
been set in the information for output port 0 on algorithm 
vtkUnstructuredGridReader(0x9679c0).

ERROR: In 
/home/abuild/rpmbuild/BUILD/VTK5.10.1/Filtering/vtkStreamingDemandDrive
nPipeline.cxx, 
line 934
vtkStreamingDemandDrivenPipeline (0x96cf30): No maximum number of 
pieces has 
been set in the information for output port 0 on algorithm 
vtkUnstructuredGridReader(0x9679c0).
### ERROR Message End###

Here is my peace of code:

###START CODE###

#include <vtkPolyData.h>
#include <vtkSTLWriter.h>
#include <vtkSTLReader.h>
#include <vtkSphereSource.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkUnstructuredGridReader.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetSurfaceFilter.h>

#define VTK_CREATE(type, name) \
   vtkSmartPointer<type> name = vtkSmartPointer<type>::New()

int main(int argc, char *argv[])
{

        std::cout << "argc" << argc << std::endl;
        std::cout << "*argv[0]" << argv[0] << std::endl;
        std::cout << "*argv[1]" << argv[1] << std::endl;
        std::cout << "*argv[2]" << argv[2] << std::endl;

  if(argc != 3)
    {
    std::cout << "Required parameters: in.vtk and out.stl" << std::endl;
    return EXIT_FAILURE;
    }

  std::string filenamevtk = argv[1];
  std::string filenamestl = argv[2];
 

  // Create the reader for the data and read data
  VTK_CREATE(vtkUnstructuredGridReader, vtkreader);
  vtkreader->SetFileName(argv[1]);
  
  vtkreader->Update();
 
  std::cout << "reading vtk done" << std::endl;

   VTK_CREATE(vtkUnstructuredGrid, unstructuredGrid);
    vtkreader->SetOutput(unstructuredGrid);
    unstructuredGrid->Update();

  vtkSmartPointer<vtkDataSetSurfaceFilter> surfaceFilter =
    vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
  surfaceFilter->SetInput(unstructuredGrid);
        surfaceFilter->Update();

  vtkPolyData* polydata = surfaceFilter->GetOutput();
  polydata->Update();

vtkSmartPointer<vtkSTLWriter> stlWriter =
    vtkSmartPointer<vtkSTLWriter>::New();
  stlWriter->SetFileName(filenamestl.c_str());
  
  //stlWriter->SetInput(polydata);//works, since it needs a vtkPolyData...
  stlWriter->SetInputConnection(surfaceFilter->GetOutputPort());//works 
also 
and stl is identical to the other method

  //stlWriter->SetFileTypeToASCII();

  stlWriter->Write();

return EXIT_SUCCESS;
}

###END CODE###
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150110/bd7b7ae1/attachment-0001.html>


More information about the vtkusers mailing list