[vtkusers] how control in a only one render two actor independent

Miguel Angel Chavez Alfonso machavez at estudiantes.uci.cu
Thu Oct 22 01:00:26 EDT 2009


I wold like to know how I can control independent two groups of actors for example one grup has tree actor(sphere1, outline_actor, axes) and an other with only a sphere1. If I select a style vtkInteractorStyleJoystickActor I only can control there actors independent but no a group.
I use an instance of vtkAssembly to group these component but I can´t join there the axes(vtkCubeAxesActor2D).
I use vtkPropAssembly but there group don´t interact with the style vtkInteractorStyleJoystickActor.
what I can do to group an instance of  vtkCubeAxesActor2D and 3D actors to control it with the mouse like a group and don´t control others actors in the same render?.
If there are another class to group actors 3D and the vtkCubeAxesActor2D like one to interact please say me
Code example


#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkActor2D.h"
#include "vtkProperty2D.h"
#include "vtkCommand.h"
#include "vtkPropPicker.h"
#include "vtkSmartPointer.h"
#include "vtkSphereSource.h"

#include "vtkPolyDataMapper.h"
#include "vtkSphereSource.h"
#include "vtkProperty.h"

//estilos iterators
#include <vtkInteractorStyleFlight.h>
#include <vtkInteractorStyleJoystickActor.h>
#include <vtkInteractorStyleJoystickCamera.h>
#include <vtkInteractorStyleRubberBandZoom.h>
#include <vtkInteractorStyleTrackball.h>
#include <vtkInteractorStyleTerrain.h>
#include <vtkInteractorStyleTrackballActor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkInteractorStyleUnicam.h>
#include <vtkInteractorStyleUser.h>
#include <vtkAssembly.h>
#include <vtkOutlineSource.h>
#include <vtkCubeAxesActor2D.h>
#include <vtkTextProperty.h>
#include <vtkPropAssembly.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkAxesActor.h>
#include <vtkBoxWidget.h>
#include <vtkCamera.h>
int main(int argc, char *argv[])
{
    vtkSphereSource *sphere = vtkSphereSource::New();
    sphere->SetThetaResolution(10);
    //sphere->SetPhiResolution(5);
    vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
    sphereMapper->SetInputConnection(sphere->GetOutputPort());
    vtkActor *sphere1 = vtkActor::New();
    sphere1->SetMapper(sphereMapper);
    sphere1->GetProperty()->SetColor(1,0,0);
    vtkActor *sphere2 = vtkActor::New();
    sphere2->SetMapper(sphereMapper);
    sphere2->GetProperty()->SetColor(0,0,1);
    sphere2->AddPosition(1.25,0,0);
    vtkRenderer *ren1 = vtkRenderer::New();
    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren1);
   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);    
    renWin->SetSize(600, 400);
    vtkOutlineSource * outline;
    vtkPolyDataMapper *outline_mapper;
    vtkActor * outline_actor;    
    vtkOutlineSource * outline2;
    vtkPolyDataMapper *outline_mapper2;
    vtkActor * outline_actor2;
    vtkCubeAxesActor2D * axes;
    vtkCubeAxesActor2D * axes2;
    //vtkTextProperty * tprop;
    outline =  vtkOutlineSource::New();
    outline_mapper =  vtkPolyDataMapper::New();
    outline_actor = vtkActor::New();
    outline2 =  vtkOutlineSource::New();
    outline_mapper2 =  vtkPolyDataMapper::New();
    outline_actor2 = vtkActor::New();
    axes = vtkCubeAxesActor2D::New();
    axes2 = vtkCubeAxesActor2D::New();

    outline->SetBounds(sphere1->GetBounds ());
     outline_mapper->SetInput( outline-> GetOutput() );
     outline_actor->SetMapper(outline_mapper);
    /*desaparece una parte del box y quedan solo las ejes en tres dimenciosnes*/
    outline_actor->VisibilityOn();
    outline_actor->GetProperty ()->SetColor (0,0,0);

    outline2->SetBounds(sphere1->GetBounds ());
     outline_mapper2->SetInput( outline2-> GetOutput() );
     outline_actor2->SetMapper(outline_mapper2);
    /*desaparece una parte del box y quedan solo las ejes en tres dimenciosnes*/
    outline_actor->VisibilityOn();
    outline_actor->GetProperty ()->SetColor (0,0,0);
    outline_actor2->VisibilityOn();
    outline_actor2->GetProperty ()->SetColor (0,0,0);
    /*sombreado de los textos del box*/

    axes->SetBounds(sphere1->GetBounds ());
    axes->SetCamera(ren1->GetActiveCamera());    
    /*separacion de los textos del box*/
    axes->SetLabelFormat("%2.4g");
    axes->SetFlyModeToOuterEdges();

    axes2->SetBounds(sphere2->GetBounds ());
    axes2->SetCamera(ren1->GetActiveCamera());
    /*separacion de los textos del box*/
    axes2->SetLabelFormat("%2.4g");
    axes2->SetFlyModeToOuterEdges();

    /*Cantidad de elementos de la escala del box */
    axes->SetNumberOfLabels(3);
    axes2->SetNumberOfLabels(3);

    axes->SetViewProp( outline_actor );
    axes->SetInertia(20);
    axes->ScalingOn();
    axes->GetProperty ()->SetColor (0,0,0);
    /*tamnno de las letras de los label*/
    axes->SetFontFactor(2.6);    

    axes2->SetViewProp( outline_actor2 );
    axes2->SetInertia(20);
    axes2->ScalingOn();
    axes2->GetProperty ()->SetColor (0,0,0);
    /*tamnno de las letras de los label*/
    axes->SetFontFactor(2.6);

    ren1->AddActor(axes);
    ren1->AddActor(outline_actor);
    ren1->AddActor(sphere1);
    outline->SetBounds(ren1->ComputeVisiblePropBounds());
    
    /*desaparece los label del box*/

    axes->VisibilityOn();
    axes2->VisibilityOn();
    vtkAssembly *assembly = vtkAssembly::New();
    assembly->AddPart(outline_actor2);
    assembly->AddPart(sphere2);

    assembly->SetPickable (1);
    assembly->SetDragable(1);
    ren1->AddActor(assembly);/*

    vtkPropAssembly *assembly2 = vtkPropAssembly::New();
    assembly2->AddPart(axes2);
    assembly2->AddPart(outline_actor2);
    assembly2->AddPart(sphere2);
    ren1->AddActor(assembly2);*/
    ren1->ResetCamera();

    //estilo de iterator para un solo actor
   vtkInteractorStyleTrackballActor *istyle = vtkInteractorStyleTrackballActor::New();
    iren->SetInteractorStyle(istyle);

    ren1->SetBackground(1, 1, 1);
    iren->Initialize();
    iren->Start();
      sphere->Delete();
      sphereMapper->Delete();
      sphere1->Delete();
      sphere2->Delete();
      ren1->Delete();
      renWin->Delete();
      iren->Delete();
}



More information about the vtkusers mailing list