Difference between revisions of "VTK/Examples/Cxx/GeometricObjects/TriangleStrip"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(Warnings)
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/GeometricObjects/TriangleStrip TriangleStrip] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExample...")
 
Line 1: Line 1:
<div class="floatright">[[File:VTK_Examples_Baseline_GeometricObjects_TestTriangleStrip.png]]</div>
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/GeometricObjects/TriangleStrip TriangleStrip] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
A triangle strip is a compact representation of a series of triangles. See [http://en.wikipedia.org/wiki/Triangle_strip this wikipedia article] for an explanation.
 
==TriangleStrip.cxx==
 
<source lang="cpp">
 
#include <vtkVersion.h>
 
#include <vtkActor.h>
 
#include <vtkCellArray.h>
 
#include <vtkDataSetMapper.h>
 
#include <vtkPoints.h>
 
#include <vtkPolyData.h>
 
#include <vtkProperty.h>
 
#include <vtkRenderer.h>
 
#include <vtkRenderWindow.h>
 
#include <vtkRenderWindowInteractor.h>
 
#include <vtkSmartPointer.h>
 
#include <vtkTriangleStrip.h>
 
 
int main(int, char *[])
 
{
 
  vtkSmartPointer<vtkPoints> points =
 
    vtkSmartPointer<vtkPoints>::New();
 
  points->InsertNextPoint(0,0,0);
 
  points->InsertNextPoint(0,1,0);
 
  points->InsertNextPoint(1,0,0);
 
  points->InsertNextPoint(1.5,1,0);
 
 
  vtkSmartPointer<vtkTriangleStrip> triangleStrip =
 
    vtkSmartPointer<vtkTriangleStrip>::New();
 
  triangleStrip->GetPointIds()->SetNumberOfIds(4);
 
  triangleStrip->GetPointIds()->SetId(0,0);
 
  triangleStrip->GetPointIds()->SetId(1,1);
 
  triangleStrip->GetPointIds()->SetId(2,2);
 
  triangleStrip->GetPointIds()->SetId(3,3);
 
 
  vtkSmartPointer<vtkCellArray> cells =
 
    vtkSmartPointer<vtkCellArray>::New();
 
  cells->InsertNextCell(triangleStrip);
 
 
  vtkSmartPointer<vtkPolyData> polydata =
 
    vtkSmartPointer<vtkPolyData>::New();
 
  polydata->SetPoints(points);
 
  polydata->SetStrips(cells);
 
 
  // Create an actor and mapper
 
  vtkSmartPointer<vtkDataSetMapper> mapper =
 
    vtkSmartPointer<vtkDataSetMapper>::New();
 
#if VTK_MAJOR_VERSION <= 5
 
  mapper->SetInput(polydata);
 
#else
 
  mapper->SetInputData(polydata);
 
#endif
 
 
  vtkSmartPointer<vtkActor> actor =
 
    vtkSmartPointer<vtkActor>::New();
 
  actor->SetMapper(mapper);
 
  actor->GetProperty()->SetRepresentationToWireframe();
 
 
  // 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);
 
 
  renderer->AddActor(actor);
 
  renderWindow->Render();
 
  renderWindowInteractor->Start();
 
 
  return EXIT_SUCCESS;
 
}
 
</source>
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 

Latest revision as of 15:38, 16 August 2019

See TriangleStrip on the new VTKExamples website.