[vtkusers] VtkCutter
Diego Parada
icebishop at gmail.com
Mon Nov 28 19:55:40 EST 2005
Hi,
I use vtkBoxWidget but this don't clip or cut the volume
The Code is:
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkClipPolyData.h"
#include "vtkDebugLeaks.h"
#include "vtkPlanes.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkBoxWidget.h"
#include "vtkSphereSource.h"
#include "vtkConeSource.h"
#include "vtkGlyph3D.h"
#include "vtkAppendPolyData.h"
#include "vtkLODActor.h"
#include "vtkCommand.h"
class vtkMyCallback : public vtkCommand
{
public:
vtkPlanes *planes;
vtkActor *a;
void SetPlane(vtkPlanes * planes)
{
this->planes=planes;
}
void SetActor(vtkActor * a)
{
this->a=a;
}
static vtkMyCallback *New()
{ return new vtkMyCallback; }
void Delete()
{ delete this; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
//widget->GetTransform(t);
widget->GetPlanes(planes);
this->a->VisibilityOn();
//widget->GetProp3D()->SetUserTransform(t);
}
};
void main()
{
// Create a mace out of filters.
vtkSphereSource *sphere = vtkSphereSource::New();
vtkConeSource *cone = vtkConeSource::New();
vtkGlyph3D *glyph = vtkGlyph3D::New();
glyph->SetInput((vtkDataSet *)sphere->GetOutput());
glyph->SetSource(cone->GetOutput());
glyph->SetVectorModeToUseNormal();
glyph->SetScaleModeToScaleByVector();
glyph->SetScaleFactor(0.25);
// The sphere and spikes are appended into a single polydata. This just
// makes things simpler to manage.
vtkAppendPolyData *apd = vtkAppendPolyData::New();
apd->AddInput(glyph->GetOutput());
apd->AddInput(sphere->GetOutput());
vtkPolyDataMapper *maceMapper = vtkPolyDataMapper::New();
maceMapper->SetInput(apd->GetOutput());
vtkLODActor *maceActor = vtkLODActor::New();
maceActor->SetMapper(maceMapper);
maceActor->VisibilityOn();
// This portion of the code clips the mace with the vtkPlanes implicit
// function. The clipped region is colored green.
vtkPlanes *planes = vtkPlanes::New();
vtkClipPolyData *clipper = vtkClipPolyData::New();
clipper->SetInput(apd->GetOutput());
clipper->SetClipFunction(planes);
clipper->InsideOutOff();
vtkPolyDataMapper *selectMapper = vtkPolyDataMapper::New();
selectMapper->SetInput(clipper->GetOutput());
selectMapper->CroppingOn();
vtkLODActor *selectActor = vtkLODActor::New();
selectActor->SetMapper(selectMapper);
selectActor->GetProperty()->SetColor(0, 1, 0);
selectActor->VisibilityOff();
selectActor->SetScale(1.01, 1.01, 1.01);
// Create the RenderWindow, Renderer and both Actors
vtkRenderer *ren = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// The SetInteractor method is how 3D widgets are associated with the
// render window interactor. Internally, SetInteractor sets up a bunch
// of callbacks using the Command/Observer mechanism (AddObserver()).
vtkBoxWidget *boxWidget = vtkBoxWidget::New();
boxWidget->SetInteractor(iren);
boxWidget->SetPlaceFactor(1.25);
ren->AddActor(maceActor);
ren->AddActor(selectActor);
// Add the actors to the renderer, set the background and size
ren->SetBackground(0.1, 0.2, 0.4);
renWin->SetSize(300, 300);
// This callback funciton does the actual work: updates the vtkPlanes
// implicit function. This in turn causes the pipeline to update.
/*de<f SelectPolygons(object, event):
// object will be the boxWidget
global selectActor, planes
object.GetPlanes(planes)
selectActor.VisibilityOn()*/
// Place the interactor initially. The input to a 3D widget is used to
// initially position and scale the widget. The "EndInteractionEvent" is
// observed which invokes the SelectPolygons callback.
boxWidget->SetInput((vtkDataSet *)glyph->GetOutput());
boxWidget->PlaceWidget();
vtkMyCallback *callback = vtkMyCallback::New();
callback->SetActor(selectActor);
callback->SetPlane(planes);
boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
iren->Initialize();
renWin->Render();
iren->Start();
}
2005/11/28, Darshan Pai <darshanpai at gmail.com>:
>
> Try Using vtkPlaneWidget .. Should Work
>
> On 11/25/05, Diego Parada <icebishop at gmail.com> wrote:
>
> > Hi,
> >
> > How i can do the cutter that appears in the image attach?
> >
> > --
> > Diego Armando Parada Cuervo
> > Estudiante de Ingeniería de Sistemas y Computación
> > Universidad Pedagógica y Tecnológica de Colombia
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
> >
> >
>
--
Diego Armando Parada Cuervo
Estudiante de Ingeniería de Sistemas y Computación
Universidad Pedagógica y Tecnológica de Colombia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051128/1487b2f2/attachment.htm>
More information about the vtkusers
mailing list