[vtkusers] Why can't I warp vtkCubeSource ?|

alican alican1812 at hotmail.com
Fri Oct 27 19:55:32 EDT 2017


I need  to apply kind of  "pinch" to vtkCubeSource, to make it look like half
cylinder. I have thought to use warpScalar for that, however, no matter what
I try I just can't get it working. The cube remains exactly as it was.

Can anybody  spot a problem in my code? Thanks,
AC

void warpTest()
{
	vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
	cubeSource->SetXLength(50);
	cubeSource->SetYLength(10);
	cubeSource->SetZLength(1);
	cubeSource->SetCenter(0,0,0);
	cubeSource->Update();
	vtkPolyData* polydata = cubeSource->GetOutput();

	vtkSmartPointer<vtkDoubleArray> scalars =
vtkSmartPointer<vtkDoubleArray>::New();
	polydata->GetPointData()->SetScalars(scalars);
	int numOfPoints = polydata->GetNumberOfPoints();
	scalars->SetNumberOfTuples(numOfPoints);
	for (vtkIdType i = 0; i < numOfPoints ; ++i)
	{
		scalars->SetTuple1(i, 200);
	}

	vtkSmartPointer<vtkPolyDataNormals> normalGenerator =
vtkSmartPointer<vtkPolyDataNormals>::New();
	normalGenerator->SetInputData(polydata);
	normalGenerator->ComputePointNormalsOn();
	normalGenerator->ComputeCellNormalsOff();
	normalGenerator->Update();

	vtkSmartPointer<vtkWarpScalar> warpScalar =
vtkSmartPointer<vtkWarpScalar>::New();
	warpScalar->SetInputData(normalGenerator->GetOutput());
	warpScalar->SetScaleFactor(1); // use the scalars themselves 
	warpScalar->Update();

	vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputConnection(warpScalar->GetOutputPort());

	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->GetProperty()->SetColor(1.0, 1.0, 0.0);
	actor->SetMapper(mapper);

	vtkSmartPointer<vtkPolyDataMapper> smapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
	smapper->SetInputData(polydata);

	vtkSmartPointer<vtkActor> sactor = vtkSmartPointer<vtkActor>::New();
	sactor->GetProperty()->SetColor(1.0, 0.0, 1.0);
	sactor->SetMapper(smapper);

	// Visualize
	getRenderer()->AddActor(actor);
	getRenderer()->AddActor(sactor);



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list