[vtkusers] Read data from a vtkCutter

Darshan Pai darshanpai at gmail.com
Fri Feb 26 18:11:45 EST 2010


Yes the renderer code has a mistake . Fixed code is attached here

//////////////////// Code
#include <vtkSmartPointer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkStripper.h>
#include <vtkCutter.h>
#include <vtkPlane.h>
#include <vtkSphereSource.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>

int main (int, char *[])
{

  vtkSmartPointer<vtkSphereSource> modelSource =
    vtkSmartPointer<vtkSphereSource>::New();

  vtkSmartPointer<vtkPlane> plane =
    vtkSmartPointer<vtkPlane>::New();

  vtkSmartPointer<vtkCutter> cutter =
    vtkSmartPointer<vtkCutter>::New();
  cutter->SetInputConnection(modelSource->GetOutputPort());
  cutter->SetCutFunction(plane);
  cutter->GenerateValues(10, -.5, .5);

  vtkSmartPointer<vtkPolyDataMapper> modelMapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  modelMapper->SetInputConnection(modelSource->GetOutputPort());

  vtkSmartPointer<vtkActor> model =
    vtkSmartPointer<vtkActor>::New();
  model->SetMapper(modelMapper);

  vtkSmartPointer<vtkStripper> stripper =
    vtkSmartPointer<vtkStripper>::New();
  stripper->SetInputConnection(cutter->GetOutputPort());

  vtkSmartPointer<vtkPolyDataMapper> linesMapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  linesMapper->SetInputConnection(stripper->GetOutputPort());

  vtkSmartPointer<vtkActor> lines =
    vtkSmartPointer<vtkActor>::New();
  lines->SetMapper(linesMapper);
  lines->GetProperty()->SetDiffuseColor(.2, .2, .2);

  vtkSmartPointer<vtkRenderer> renderer =
      vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
      vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  //Add the actor to the scene
  renderer->AddActor(model);
  renderer->AddActor(lines);
  renderer->SetBackground(0.1, 0.2, 0.4); // Background color white

  //Render and interact
  renderWindow->Render();
  renderWindowInteractor->Start();


  // Extract the lines from the polydata
  vtkIdType numberOfLines = cutter->GetOutput()->GetNumberOfLines();


  std::cout << "-----------Lines without using vtkStripper" << std::endl;
  std::cout << "There are "
            << numberOfLines
            << " lines in the polydata" << std::endl;

  numberOfLines = stripper->GetOutput()->GetNumberOfLines();
  vtkPoints *points = stripper->GetOutput()->GetPoints();
  vtkCellArray *cells = stripper->GetOutput()->GetLines();

  std::cout << "-----------Lines using vtkStripper" << std::endl;
  std::cout << "There are "
            << numberOfLines
            << " lines in the polydata" << std::endl;

  vtkIdType *indices;
  vtkIdType numberOfPoints;
  unsigned int lineCount = 0;
  for (cells->InitTraversal();
       cells->GetNextCell(numberOfPoints, indices);
       lineCount++)
    {
    std::cout << "Line " << lineCount << ": " << std::endl;
    for (vtkIdType i = 0; i < numberOfPoints; i++)
      {
      double point[3];
      points->GetPoint(indices[i], point);
      std::cout << "\t("
                << point[0] << ", "
                << point[1] << ", "
                << point[2] << ")" << std::endl;
      }
    }
  return EXIT_SUCCESS;
}

On Thu, Feb 25, 2010 at 11:16 PM, Hsiang-Chi Kuo <hskuo at montefiore.org>wrote:

> Hi Bill,
>
> I have tested the example. It turned out:
> -----------Lines without using vtkStripper
> There are 0 lines in the polydata
> -----------Lines using vtkStripper
> There are 0 lines in the polydata
>
> No line and no polydata output from the program. Can you advise what's
> wrong?
>
> Thanks,
>
> Howard
>
> >>> Bill Lorensen <bill.lorensen at gmail.com> 02/25/10 8:15 AM >>>
> This example accesses the lines after cutting and stripping:
>
> http://vtk.org/Wiki/VTK/Examples/ExtractPolyLinesFromPolyData
>
> On Thu, Feb 25, 2010 at 1:15 AM, Hsiang-Chi Kuo <hskuo at montefiore.org>
> wrote:
> > Hi dear friends,
> >
> > I want to cut a volume data (.vtp) at different angle and read the
> data
> > out. I applied vtkPlan and vtkCutter on the vtp data, what should I do
> > next to be able to read the data out? Bellow is part of my code.
> >
> > vtkSmartPointer<vtkXMLUnstructuredGridReader> reader =
> > vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
> >  reader->SetFileName(filename.c_str());
> >  reader->Update();
> > vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
> >  plane->SetOrigin(-50.3,-84.5,-18.8);
> >  plane->SetNormal(1,0,0);
> > vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New();
> >  cutter->SetCutFunction(plane);
> >  cutter->SetInput(reader->GetOutput());
> >  cutter->Update();
> >
> > Thanks,
> >
> > Howard
> > _______________________________________________
> > 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
> >
>
> _______________________________________________
> 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/20100226/7a9ec878/attachment.htm>


More information about the vtkusers mailing list