VTK/Examples/Cxx/Broken/InfoVis/AppendPoints

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to navigationJump to search

This example is currently broken. The data sets seem to have been combined (there are 10 points and 10 cells in the output), but nothing is displayed.

AppendPoints.cxx

#include <vtkSmartPointer.h>
#include <vtkPointSource.h>
#include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkAppendPoints.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>

int main(int, char *[])
{
  // Create one set of poitns.
  vtkSmartPointer<vtkPointSource> pointSource1 =
      vtkSmartPointer<vtkPointSource>::New();
  pointSource1->SetNumberOfPoints(5);
  pointSource1->Update();
  cout << "pointSource1 has " << pointSource1->GetOutput()->GetNumberOfPoints() << " points and "
       << pointSource1->GetOutput()->GetNumberOfPoints() << " cells and "
       << pointSource1->GetOutput()->GetNumberOfVerts() <<  " verts." << endl;
      
  // Create another set of poitns.
  vtkSmartPointer<vtkPointSource> pointSource2 =
    vtkSmartPointer<vtkPointSource>::New();
  pointSource2->SetNumberOfPoints(5);
  pointSource2->Update();
  cout << "pointSource2 has "
       << pointSource2->GetOutput()->GetNumberOfPoints() << " points and "
       << pointSource2->GetOutput()->GetNumberOfPoints() << " cells and "
       << pointSource2->GetOutput()->GetNumberOfVerts() <<  " verts." << endl;

  // Combine the two point sets
  vtkSmartPointer<vtkAppendPoints> appendFilter =
      vtkSmartPointer<vtkAppendPoints>::New();
  appendFilter->AddInputConnection(pointSource1->GetOutputPort());
  appendFilter->AddInputConnection(pointSource2->GetOutputPort());
  appendFilter->Update();

  cout << "Combined there are "
       << appendFilter->GetOutput()->GetNumberOfPoints() << " points and "
       << appendFilter->GetOutput()->GetNumberOfPoints() << " cells and "
       << appendFilter->GetOutput()->GetNumberOfVerts() <<  " verts." << endl;

  //Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(appendFilter->GetOutputPort());
  //mapper->SetInputConnection(pointSource1->GetOutputPort());

  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  //Create a renderer, render window, and interactor
  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(actor);
  //renderer->SetBackground(.3, .6, .3); // Background color green

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

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(AppendPoints)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(AppendPoints MACOSX_BUNDLE AppendPoints.cxx)

if(VTK_LIBRARIES)
  target_link_libraries(AppendPoints ${VTK_LIBRARIES})
else()
  target_link_libraries(AppendPoints vtkHybrid vtkWidgets)
endif()

Download and Build AppendPoints

Click here to download AppendPoints. and its CMakeLists.txt file.

Once the tarball AppendPoints.tar has been downloaded and extracted,

cd AppendPoints/build 
  • If VTK is installed:
cmake ..
  • If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

make

and run it:

./AppendPoints

WINDOWS USERS PLEASE NOTE: Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.