Difference between revisions of "VTK/Examples/Cxx/PolyData/ColoredPoints"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(VTK API Change)
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColoredPoints ColoredPoints] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples websit...")
 
Line 1: Line 1:
<div class="floatright">[[File:VTK_Examples_Baseline_PolyData_TestColoredPoints.png]]</div>
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColoredPoints ColoredPoints] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
==ColoredPoints.cxx==
 
<source lang="cpp">
 
#include <vtkVersion.h>
 
#include <vtkSmartPointer.h>
 
#include <vtkPoints.h>
 
#include <vtkPolyData.h>
 
#include <vtkPointData.h>
 
#include <vtkCellArray.h>
 
#include <vtkUnsignedCharArray.h>
 
#include <vtkPolyDataMapper.h>
 
#include <vtkActor.h>
 
#include <vtkRenderWindow.h>
 
#include <vtkRenderer.h>
 
#include <vtkRenderWindowInteractor.h>
 
#include <vtkVertexGlyphFilter.h>
 
#include <vtkProperty.h>
 
 
 
// For compatibility with new VTK generic data arrays
 
#ifdef vtkGenericDataArray_h
 
#define InsertNextTupleValue InsertNextTypedTuple
 
#endif
 
 
 
int main(int, char *[])
 
{
 
  vtkSmartPointer<vtkPoints> points =
 
    vtkSmartPointer<vtkPoints>::New();
 
  points->InsertNextPoint (0.0, 0.0, 0.0);
 
  points->InsertNextPoint (1.0, 0.0, 0.0);
 
  points->InsertNextPoint (0.0, 1.0, 0.0);
 
 
 
  vtkSmartPointer<vtkPolyData> pointsPolydata =
 
    vtkSmartPointer<vtkPolyData>::New();
 
 
 
  pointsPolydata->SetPoints(points);
 
 
 
  vtkSmartPointer<vtkVertexGlyphFilter> vertexFilter =
 
    vtkSmartPointer<vtkVertexGlyphFilter>::New();
 
#if VTK_MAJOR_VERSION <= 5
 
  vertexFilter->SetInputConnection(pointsPolydata->GetProducerPort());
 
#else
 
  vertexFilter->SetInputData(pointsPolydata);
 
#endif
 
  vertexFilter->Update();
 
 
 
  vtkSmartPointer<vtkPolyData> polydata =
 
    vtkSmartPointer<vtkPolyData>::New();
 
  polydata->ShallowCopy(vertexFilter->GetOutput());
 
 
 
  // Setup colors
 
  unsigned char red[3] = {255, 0, 0};
 
  unsigned char green[3] = {0, 255, 0};
 
  unsigned char blue[3] = {0, 0, 255};
 
 
 
  vtkSmartPointer<vtkUnsignedCharArray> colors =
 
    vtkSmartPointer<vtkUnsignedCharArray>::New();
 
  colors->SetNumberOfComponents(3);
 
  colors->SetName ("Colors");
 
  colors->InsertNextTupleValue(red);
 
  colors->InsertNextTupleValue(green);
 
  colors->InsertNextTupleValue(blue);
 
 
 
  polydata->GetPointData()->SetScalars(colors);
 
 
 
  // Visualization
 
  vtkSmartPointer<vtkPolyDataMapper> mapper =
 
    vtkSmartPointer<vtkPolyDataMapper>::New();
 
#if VTK_MAJOR_VERSION <= 5
 
  mapper->SetInputConnection(polydata->GetProducerPort());
 
#else
 
  mapper->SetInputData(polydata);
 
#endif
 
 
 
  vtkSmartPointer<vtkActor> actor =
 
    vtkSmartPointer<vtkActor>::New();
 
  actor->SetMapper(mapper);
 
  actor->GetProperty()->SetPointSize(5);
 
 
 
  vtkSmartPointer<vtkRenderer> renderer =
 
    vtkSmartPointer<vtkRenderer>::New();
 
  vtkSmartPointer<vtkRenderWindow> renderWindow =
 
    vtkSmartPointer<vtkRenderWindow>::New();
 
  renderWindow->AddRenderer(renderer);
 
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
 
  renderWindowInteractor->SetRenderWindow(renderWindow);
 
 
 
  renderer->AddActor(actor);
 
 
 
  renderWindow->Render();
 
  renderWindowInteractor->Start();
 
 
 
  return EXIT_SUCCESS;
 
}
 
 
 
</source>
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 

Latest revision as of 16:33, 9 September 2019

See ColoredPoints on the new VTKExamples website.