[vtkusers] using vtkSmoothPolyDataFilter with...errr... polydata?

Alex Malyushytskyy alexmalvtk at gmail.com
Fri Aug 30 21:23:53 EDT 2013


vtk algorithms either require connection or data.

to make a connection you call :

SetInputConnection


to provide data as input you call  :

SetInput


in vtk 6.0+ you if not mistaken it is:

SetInputData



Alex


On Fri, Aug 30, 2013 at 5:48 PM, Paul McIntosh <paul.mcintosh at monash.edu>wrote:

> Hi All,
>
> I have a dumb question - how do I used vtkSmoothPolyDataFilter
> with...errr... polydata?
>
> I am trying to do the equivalent of :
> http://www.paraview.org/Wiki/VTK/Examples/Cxx/PolyData/ConvexHullShrinkWrap
>
> But instead of using a point source I want to load an STL and get points
> from that. Seems that vtkSmoothPolyDataFilter only likes vtkAlgorithmOutput
> and not actual concrete data. Is there an easy way to make this work?
>
> Here is my code as reference.
>
> Cheers,
>
> Paul
>
>
> #include <vtkSmartPointer.h>
>
> #include <vtkPolyData.h>
>
> #include <vtkSphereSource.h>
>
> #include <vtkPointSource.h>
>
> #include <vtkSmoothPolyDataFilter.h>
>
> #include <vtkXMLPolyDataWriter.h>
>
> #include <vtkSTLReader.h>
>
> #include <vtkActor.h>
>
> #include <vtkRenderWindow.h>
>
> #include <vtkRenderer.h>
>
> #include <vtkRenderWindowInteractor.h>
>
> #include <vtkPolyDataMapper.h>
>
> #include <vtkCamera.h>
>
> #include <vtkWeightedTransformFilter.h>
>
> #include <vtkXMLUnstructuredGridReader.h>
>
> #include <vtkUnstructuredGrid.h>
>
> #include <vtkXMLPolyDataReader.h>
>
> #include <vtkDataSetMapper.h>
>
> #include <vtkDataSetSurfaceFilter.h>
>
> // C/C++
>
> #include <iostream>
>
> #include <sstream>
>
> #include <stdio.h>
>
> using namespace std;
>
> // just to make things nicer later and save some documentation reading ;)
>
> struct boundingBox {
>
>     double xmin;
>
>     double xmax;
>
>     double ymin;
>
>     double ymax;
>
>     double zmin;
>
>     double zmax;
>
> };
>
> int main(int argc, char *argv[])
>
> {
>
>     // check and get options provided
>
>     if ( argc != 2 )
>
>     {
>
>         cout << "Required parameters:" << endl;
>
>         cout << "  Filename (Full path to stl file e.g. something.stl)" << endl;
>
> //        cout << "  Magnification (Image resolution size multipler e.g. 2)" << endl;
>
> //        cout << "  x (x camera offset position from centre)" << endl;
>
> //        cout << "  y (y camera offset position from centre)" << endl;
>
> //        cout << "  z (z camera offset position from centre)" << endl;
>
>         return EXIT_FAILURE;
>
>     }
>
>     std::string inputfile = argv[1];
>
>     // Read STL
>
>     std::cout << "Reading: " << inputfile << std::endl;
>
>     vtkSmartPointer<vtkSTLReader> stlReader = vtkSmartPointer<vtkSTLReader>::New();
>
>     stlReader->SetFileName(inputfile.c_str());
>
>     vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
>
>     polydata = stlReader->GetOutput();
>
>     stlReader->Update();
>
>     vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
>
>     mapper->SetInputConnection(stlReader->GetOutputPort());
>
>     // the bounding box will tell us where the object is and how big it is...
>
>     double centre[3];
>
>     double bounds[6];
>
>     double results[3];
>
>     boundingBox boxBounds;
>
>     mapper->GetBounds(bounds);
>
>     mapper->GetCenter(centre);
>
>     boxBounds.xmin = bounds[0];
>
>     boxBounds.xmax = bounds[1];
>
>     boxBounds.ymin = bounds[2];
>
>     boxBounds.ymax = bounds[3];
>
>     boxBounds.zmin = bounds[4];
>
>     boxBounds.zmax = bounds[5];
>
>   // possibly remesh with finer detail with subdivide filter?
>
>   // convert to pointset
>
>   // create sphere around bounds (possibly transformed to a better shape?)
>
>   // shrinkwrap
>
>   // spit out the result as an stl
>
>   std::cout << "vtkSphereSource: " << std::endl;
>
>   vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
>
>   sphereSource->SetRadius(1000); // will calculate this later from bounding box
>
>   sphereSource->SetPhiResolution(50);
>
>   sphereSource->SetThetaResolution(50);
>
>   sphereSource->SetCenter(centre);
>
>   sphereSource->Update();
>
>  //  vtkSmartPointer<vtkPointSource> pointSource = vtkSmartPointer<vtkPointSource>::New();
>
> //  pointSource->SetNumberOfPoints(40);
>
> //  pointSource->SetRadius(2);
>
> //  pointSource->Update();
>
>    {
>
>   vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
>
>   writer->SetFileName("input.vtp");
>
>   writer->SetInputConnection(sphereSource->GetOutputPort());
>
>   writer->Write();
>
>   }
>
>    {
>
>   vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
>
>   writer->SetFileName("points.vtp");
>
>   writer->SetInputConnection(pointSource->GetOutputPort());
>
>   writer->Write();
>
>   }
>
>   std::cout << "ShrinkWrapping: " << inputfile << std::endl;
>
>   vtkSmartPointer<vtkSmoothPolyDataFilter> smoothFilter = vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
>
>   smoothFilter->SetInputConnection(0, sphereSource->GetOutputPort());
>
>   //smoothFilter->SetInputConnection(1, pointSource->GetOutputPort());
>
>   smoothFilter->SetInputConnection(1, polydata);
>
>   smoothFilter->Update();
>
>    vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
>
>   writer->SetFileName("output.vtp");
>
>   writer->SetInputConnection(smoothFilter->GetOutputPort());
>
>   writer->Write();
>
>    return EXIT_SUCCESS;
>
> }
>
>
>
>
>
> --
> Dr Paul McIntosh
>   Senior HPC Consultant, Technical Lead,
>     Multi-modal Australian ScienceS Imaging and Visualisation Environment (
> www.massive.org.au)
>        Monash University, Ph: 9902 0439 Mob: 0434 524935
>
> _______________________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130830/b34469f2/attachment.htm>


More information about the vtkusers mailing list