[vtkusers] BoxClipper

Diego Parada icebishop at gmail.com
Thu Dec 1 12:27:39 EST 2005


Hi,

I have the floowing code:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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;
  vtkClipPolyData *clipper;
  void SetPlane(vtkPlanes * planes)
  {
    this->planes=planes;
  }

  void SetClipper(vtkClipPolyData *clipper)
  {
    this->clipper=clipper;
  }

  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();
        this->clipper->SetClipFunction(planes);


      //widget->GetProp3D()->SetUserTransform(t);
    }
};

void main()
{
    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->GenerateClipScalarsOn();
  clipper->GenerateClippedOutputOn();
  clipper->InsideOutOff();


vtkPolyDataMapper *selectMapper = vtkPolyDataMapper::New();

   selectMapper->SetInput(clipper->GetClippedOutput());
   selectMapper->ScalarVisibilityOff();

vtkProperty *backProp =vtkProperty::New();
     backProp->SetDiffuseColor(0,0,0.25);

vtkLODActor *selectActor = vtkLODActor::New();
  selectActor->SetMapper(selectMapper);
  selectActor->GetProperty()->SetColor(1,0,1);
  selectActor->VisibilityOff();
  selectActor->SetScale(1.01, 1.01, 1.01);
  selectActor->SetBackfaceProperty(backProp);

// 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);
  callback->SetClipper(clipper);
  boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);

  iren->Initialize();
  renWin->Render();
  iren->Start();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
How I Can do to the  clip region can`t to visualize?

Thanks;

--
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/20051201/cc52c585/attachment.htm>


More information about the vtkusers mailing list