[vtkusers] vtkCutter->Update doesn't update the vtkCutter->GetOutput()
nsarrasin
nsarrasin at phenix-systems.com
Wed Nov 3 05:00:41 EDT 2010
Thanks for your reply,
I followed your advice and used GetOutputPort() but the result stays the
same.
I post a (light, simple and commented) code which illustrates the problem,
maybe i'm doing something wrong .
Thanks a lot for helping me.
//slicing of a sphere by a plane. the plane is iteratively rotated all
around the sphere
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkTransform.h>
#include <vtkPlane.h>
#include <vtkCutter.h>
#include <vtkMath.h>
#include <vtkAppendPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSphereSource.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vector>
int main (int argc, char *argv[])
{
//the object to cut
vtkSphereSource* sph = vtkSphereSource::New();
sph->SetRadius(25.);
sph->SetPhiResolution(50.);
sph->SetThetaResolution(50.);
vtkPolyData *polydata = sph->GetOutput();
//init the cutting plane
double bounds[6], center[3];
polydata->GetBounds(bounds);
polydata->GetCenter(center);
vtkPlane* plane = vtkPlane::New();
plane->SetOrigin(center);
plane->SetNormal(bounds[0]-center[0], bounds[2]-center[1], 0.);
int nbsections = 10;
double angle = 360./(double)nbsections;
double normal[3]={0,0,1};
//init the transformation
vtkTransform* transf = vtkTransform::New();
transf->RotateWXYZ(angle, normal[0], normal[1], normal[2]);
vtkMatrix4x4* mat = vtkMatrix4x4::New();
transf->GetMatrix(mat);
vtkAppendPolyData* appdata = vtkAppendPolyData::New();
vtkCutter* cutter = vtkCutter::New();
cutter->SetInput(polydata);
cutter->SetCutFunction(plane);
double new_normal[4];
for(int step=0; step<nbsections; step++)
{
//// Code works but need Update + DeppCopy
cutter->Update();
vtkPolyData* tmp_result=vtkPolyData::New();
tmp_result->DeepCopy( cutter->GetOutput());
appdata->AddInput(tmp_result);
//// Code doesn't update though GetOutputPort()
//appdata->AddInputConnection(cutter->GetOutputPort());
//rotation of the cutting plane around normal
mat->MultiplyPoint(plane->GetNormal(), new_normal);
plane->SetNormal(new_normal);
plane->SetOrigin(center);
}
//visualisation
//1. All slices
vtkSmartPointer<vtkPolyDataMapper> appmapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
appmapper->SetInput(appdata->GetOutput());
vtkSmartPointer<vtkActor> appactor = vtkSmartPointer<vtkActor>::New();
appactor->SetMapper(appmapper);
appactor->GetProperty()->SetColor(1,0,0);
//2. polydata
vtkSmartPointer<vtkPolyDataMapper> teethmapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
teethmapper->SetInput(polydata);
vtkSmartPointer<vtkActor> teethactor = vtkSmartPointer<vtkActor>::New();
teethactor->SetMapper(teethmapper);
teethactor->GetProperty()->SetColor(0.8,0.8,0.8);
// The usual renderer, render window and interactor
vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
ren1->SetBackground(.1, .2, .3);
renWin->AddRenderer(ren1);
iren->SetRenderWindow(renWin);
ren1->AddActor(appactor);
ren1->AddActor(teethactor);
renWin->Render();
iren->Start();
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkCutter-Update-doesn-t-update-the-vtkCutter-GetOutput-tp3246712p3248103.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list