[vtkusers] vtkClipPolyData - I cannot get some output

Fabian fabian-richter at gmx.de
Fri Mar 30 02:36:36 EDT 2012


Hi All VTK-Pros,

I am trying to work with the cClipPolyData-Filter and worked with some
Examples from the web. What I would like to do is: 
- create a rectangle 
- create a second rectangle beeing smaller and inside the first one
- substract the second from the first to recieve a rectangle with a
rectangular hole in it

But I cant get any output. Maybe my Code is stupid. Maybe I didnt understand
when to use GetOutput vs. GetOutputPort, or SetInput vs. SetInputConnection.

Could You please check where I am failing?!

THANKS ALOT,
Fabian



#include <vtkCellArray.h>
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolygon.h>
#include <vtkSmartPointer.h>
#include <vtkDelaunay2D.h>
#include <vtkMath.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkClipPolyData.h>
#include <vtkDoubleArray.h>
#include <vtkPointData.h>
#include <vtkFloatArray.h>

 
int main(int, char *[])
{
	int i;

	//-----------------------------
	//create object 1
	//-----------------------------
	vtkSmartPointer<vtkPoints> points =   vtkSmartPointer<vtkPoints>::New();
		points->InsertNextPoint(0,0,0);
		points->InsertNextPoint(0,10,0);
		points->InsertNextPoint(10,10,0);
		points->InsertNextPoint(10,0,0);

	vtkSmartPointer<vtkDoubleArray> weights =
vtkSmartPointer<vtkDoubleArray>::New();
		weights->SetNumberOfValues(points ->GetNumberOfPoints());
		
		for(i = 0; i < points ->GetNumberOfPoints(); ++i)
		{
			weights->SetValue(i, 1);
		}
	
	vtkSmartPointer<vtkPolyData> aPolyData =   
vtkSmartPointer<vtkPolyData>::New();
		aPolyData->SetPoints(points);
		aPolyData->GetPointData()->SetScalars(weights);

  // Triangulate the grid points
	vtkSmartPointer<vtkDelaunay2D> delaunay =
vtkSmartPointer<vtkDelaunay2D>::New();
		delaunay->SetInput(aPolyData);
		delaunay->Update();


	//-----------------------------
	//create object 1
	//-----------------------------
	vtkSmartPointer<vtkPoints> points2 =   vtkSmartPointer<vtkPoints>::New();
		points2->InsertNextPoint(1,1,0);
		points2->InsertNextPoint(1,5,0);
		points2->InsertNextPoint(3,5,0);
		points2->InsertNextPoint(3,1,0);

	vtkSmartPointer<vtkDoubleArray> weights2 =
vtkSmartPointer<vtkDoubleArray>::New();
		weights2->SetNumberOfValues(points2 ->GetNumberOfPoints());
		
		for(i = 0; i < points2 ->GetNumberOfPoints(); ++i)
		{
			weights2->SetValue(i, 0);
		}
		
	vtkSmartPointer<vtkPolyData> aPolyData2 =   
vtkSmartPointer<vtkPolyData>::New();
		aPolyData2->SetPoints(points2);
		aPolyData2->GetPointData()->SetScalars(weights2);
		
  // Triangulate the grid points
	vtkSmartPointer<vtkDelaunay2D> delaunay2 =   
vtkSmartPointer<vtkDelaunay2D>::New();
		delaunay2->SetInput(aPolyData2);
		delaunay2->Update();


	//-----------------------------
	//clip the polydata (in my case: substract second rectangle from the first
	//-----------------------------
	vtkSmartPointer<vtkClipPolyData> clipper =   
vtkSmartPointer<vtkClipPolyData>::New();;
		clipper ->SetInput (delaunay ->GetOutput());
		clipper ->SetInput (delaunay2 ->GetOutput());
		clipper ->SetValue(0.3);
		clipper ->Update();
		
	// Visualize
	vtkSmartPointer<vtkPolyDataMapper> meshMapper =	
vtkSmartPointer<vtkPolyDataMapper>::New();
		meshMapper->SetInputConnection(clipper->GetOutputPort());
 
	vtkSmartPointer<vtkActor> meshActor =     vtkSmartPointer<vtkActor>::New();
		meshActor->SetMapper(meshMapper);
  		// meshActor->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);
 
	// Add the actor to the scene
		renderer->AddActor(meshActor);

		renderer->SetBackground(.3, .6, .3); // Background color green
 
	// Render and interact
		renderWindow->Render();
		renderWindowInteractor->Start();
 
return EXIT_SUCCESS;
}

--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkClipPolyData-I-cannot-get-some-output-tp5605812p5605812.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list