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

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to navigationJump to search
(New page: This example is currently broken. This example creates a stack of 10 circles and creates a contour on them. ==ContoursToSurface.cxx== <source lang="cpp"> #include <vtkSmartPointer.h> #in...)
 
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ContoursToSurface ContoursToSurface] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExample...")
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This example is currently broken.
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ContoursToSurface ContoursToSurface] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
 
 
This example creates a stack of 10 circles and creates a contour on them.
 
 
 
==ContoursToSurface.cxx==
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkSphereSource.h>
 
#include <vtkPlane.h>
 
#include <vtkCutter.h>
 
#include <vtkPolyData.h>
 
#include <vtkRenderer.h>
 
#include <vtkRenderWindow.h>
 
#include <vtkRenderWindowInteractor.h>
 
#include <vtkPolyDataMapper.h>
 
#include <vtkActor.h>
 
#include <vtkVoxelContoursToSurfaceFilter.h>
 
#include <vtkAppendPolyData.h>
 
 
 
void CreateCircle(double h, vtkPolyData* pd);
 
 
 
int main()
 
{
 
  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
 
  vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
 
 
 
  renderWindow->AddRenderer(renderer);
 
  vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
 
  interactor->SetRenderWindow(renderWindow);
 
 
 
  //Create the data
 
  vtkstd::vector<vtkSmartPointer<vtkPolyData> > circles;
 
  for(int i = 0; i < 10; i++)
 
    {
 
    vtkSmartPointer<vtkPolyData> circle = vtkSmartPointer<vtkPolyData>::New();
 
    double h = i*.1;
 
    cout << "h(" << i << "): " << h << endl;
 
    CreateCircle(h, circle);
 
    circles.push_back(circle);
 
    }
 
   
 
 
 
  vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
 
  for(unsigned int i = 0; i < circles.size(); i++)
 
    {
 
    appendFilter->AddInput(circles[i]);
 
    }
 
 
 
  appendFilter->Update();
 
  vtkPolyData* contours = appendFilter->GetOutput();
 
 
 
  vtkSmartPointer<vtkPolyDataMapper> contoursMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
 
  contoursMapper->SetInput(contours);
 
 
 
  vtkSmartPointer<vtkActor> contoursActor = vtkSmartPointer<vtkActor>::New();
 
  contoursActor->SetMapper(contoursMapper);
 
 
 
  //Create the contour to surface filter
 
  vtkSmartPointer<vtkVoxelContoursToSurfaceFilter> f = vtkSmartPointer<vtkVoxelContoursToSurfaceFilter>::New();
 
  f->SetInput(contours);
 
  //f->SetMemoryLimitInBytes(100000);
 
 
 
  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
 
  mapper->SetInputConnection(f->GetOutputPort());
 
  mapper->ScalarVisibilityOff();
 
  mapper->ImmediateModeRenderingOn();
 
 
 
  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
 
  actor->SetMapper(mapper);
 
 
 
  renderer->AddViewProp(actor);
 
  renderer->AddViewProp(contoursActor);
 
  renderWindow->Render();
 
 
 
  interactor->Start();
 
 
 
  return EXIT_SUCCESS;
 
}
 
 
 
void CreateCircle(double h, vtkPolyData* pd)
 
{
 
  vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
 
   
 
  vtkSmartPointer<vtkPolyDataMapper> sphereMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
 
  sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
 
 
 
  //create a plane to cut,here it cuts in the XZ direction (xz normal=(1,0,0);XY =(0,0,1),YZ =(0,1,0)
 
  vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
 
  plane->SetOrigin(0,0,h);
 
  plane->SetNormal(1,0,0);
 
 
 
    //create cutter
 
  vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New();
 
  cutter->SetCutFunction(plane);
 
  cutter->SetInput(sphereMapper->GetInput());
 
  cutter->Update();
 
  pd->ShallowCopy(cutter->GetOutput());
 
}
 
</source>
 
 
 
==CMakeLists.txt==
 
<source lang="text">
 
cmake_minimum_required(VERSION 2.6)
 
 
PROJECT(ContoursToSurface)
 
 
FIND_PACKAGE(VTK REQUIRED)
 
INCLUDE(${VTK_USE_FILE})
 
 
ADD_EXECUTABLE(ContoursToSurface ContoursToSurface.cxx)
 
 
TARGET_LINK_LIBRARIES(ContoursToSurface vtkHybrid)
 
 
 
</source>
 

Latest revision as of 16:33, 9 September 2019