Difference between revisions of "VTK/Examples/Cxx/Meshes/Triangulate"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Meshes/Triangulate Triangulate] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =")
 
Line 1: Line 1:
<div class="floatcenter">[[File:VTK_Examples_Baseline_Meshes_TestTriangulate.png|300px]]</div>
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Meshes/Triangulate Triangulate] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
==Triangulate.cxx==
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkProperty.h>
 
#include <vtkPolyData.h>
 
#include <vtkTriangleFilter.h>
 
#include <vtkRegularPolygonSource.h>
 
#include <vtkPolyDataMapper.h>
 
#include <vtkActor.h>
 
#include <vtkRenderWindow.h>
 
#include <vtkRenderer.h>
 
#include <vtkRenderWindowInteractor.h>
 
 
 
int main(int, char *[])
 
{
 
  vtkSmartPointer<vtkRegularPolygonSource> polygonSource =
 
    vtkSmartPointer<vtkRegularPolygonSource>::New();
 
  polygonSource->Update();
 
 
 
  vtkSmartPointer<vtkTriangleFilter> triangleFilter =
 
    vtkSmartPointer<vtkTriangleFilter>::New();
 
  triangleFilter->SetInputConnection(polygonSource->GetOutputPort());
 
  triangleFilter->Update();
 
 
 
  vtkSmartPointer<vtkPolyDataMapper> inputMapper =
 
      vtkSmartPointer<vtkPolyDataMapper>::New();
 
  inputMapper->SetInputConnection(polygonSource->GetOutputPort());
 
  vtkSmartPointer<vtkActor> inputActor =
 
      vtkSmartPointer<vtkActor>::New();
 
  inputActor->SetMapper(inputMapper);
 
  inputActor->GetProperty()->SetRepresentationToWireframe();
 
 
 
  vtkSmartPointer<vtkPolyDataMapper> triangleMapper =
 
    vtkSmartPointer<vtkPolyDataMapper>::New();
 
  triangleMapper->SetInputConnection(triangleFilter->GetOutputPort());
 
  vtkSmartPointer<vtkActor> triangleActor =
 
      vtkSmartPointer<vtkActor>::New();
 
  triangleActor->SetMapper(triangleMapper);
 
  triangleActor->GetProperty()->SetRepresentationToWireframe();
 
 
 
  // There will be one render window
 
  vtkSmartPointer<vtkRenderWindow> renderWindow =
 
    vtkSmartPointer<vtkRenderWindow>::New();
 
  renderWindow->SetSize(600, 300);
 
 
 
  // And one interactor
 
  vtkSmartPointer<vtkRenderWindowInteractor> interactor =
 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
 
  interactor->SetRenderWindow(renderWindow);
 
 
 
  // Define viewport ranges
 
  // (xmin, ymin, xmax, ymax)
 
  double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};
 
  double rightViewport[4] = {0.5, 0.0, 1.0, 1.0};
 
 
 
  // Setup both renderers
 
  vtkSmartPointer<vtkRenderer> leftRenderer =
 
    vtkSmartPointer<vtkRenderer>::New();
 
  renderWindow->AddRenderer(leftRenderer);
 
  leftRenderer->SetViewport(leftViewport);
 
  leftRenderer->SetBackground(.6, .5, .4);
 
 
 
  vtkSmartPointer<vtkRenderer> rightRenderer =
 
    vtkSmartPointer<vtkRenderer>::New();
 
  renderWindow->AddRenderer(rightRenderer);
 
  rightRenderer->SetViewport(rightViewport);
 
  rightRenderer->SetBackground(.4, .5, .6);
 
 
 
  leftRenderer->AddActor(inputActor);
 
  rightRenderer->AddActor(triangleActor);
 
 
 
  leftRenderer->ResetCamera();
 
 
 
  rightRenderer->ResetCamera();
 
 
 
  renderWindow->Render();
 
  interactor->Start();
 
 
 
  return EXIT_SUCCESS;
 
}
 
 
 
 
 
</source>
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 

Latest revision as of 19:09, 27 March 2019

See Triangulate on the new VTKExamples website.