[vtkusers] vtkCutter->Update doesn't update the vtkCutter->GetOutput()
Wes Turner
wes.turner at kitware.com
Wed Nov 3 09:09:02 EDT 2010
I haven't looked at the cutter code, but it is likely that changing the
parameters to the cutting plane doesn't cause a Modified event to be made to
the cutter code. Try calling cutter->Modified to force the cutter to be
stale before calling cutter->Update().
- Wes
On Wed, Nov 3, 2010 at 8:35 AM, Bill Lorensen <bill.lorensen at gmail.com>wrote:
> Inside the loop you must disconnect the input to append from the
> output of cutter. One way to do that is to use DeepCopy as you
> discovered.
>
> Another is to create the cutter inside the loop and Delete it after
> adding its output to append If you use SmartPointer's you need not
> delete). This should be faster than the DeepCopy, depending on the
> size of the models.
>
> If you do not disconnect the input to append, then all of the inputs
> will be the same (should be the last cutter output).
>
>
> On Wed, Nov 3, 2010 at 5:00 AM, nsarrasin <nsarrasin at phenix-systems.com>
> wrote:
> >
> > 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.
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
--
Wesley D. Turner, Ph.D.
Kitware, Inc.
Technical Leader
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4920
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101103/23ef4db1/attachment.htm>
More information about the vtkusers
mailing list