[vtkusers] set two Actor in boxWidget with vtkInteractorStyleTrackballCamera
sam
sandoure at yahoo.fr
Fri Apr 8 04:43:42 EDT 2005
Dear all;
I want to set two Actor in boxWidget using
boxWidget->SetProp3D(Actor(i=1,2));
but when I used the vtkInteractorStyleTrackballCamera
I can only zoom or change the shape of the last Actor
in my box (code is below).
It is possible to add and zoom the two actor in same
time in my box.
Any help it is welcome
Sam
my code :
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyDataReader.h"
#include "vtkUnstructuredGridReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyData.h"
#include "vtkActor.h"
#include "vtkProperty.h"
#include "vtkLight.h"
#include "vtkUnstructuredGrid.h"
#include "vtkDelaunay2D.h"
#include "vtkLookupTable.h"
#include "vtkElevationFilter.h"
#include "vtkScalarBarActor.h"
#include "vtkCommand.h"
#include "vtkBoxWidget.h"
#include "vtkTransform.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkCamera.h"
//*****************************
using namespace std;
//********************************************
//******************************************
class vtkMyCallback : public vtkCommand
{
public:
static vtkMyCallback *New()
{ return new vtkMyCallback; }
void Delete()
{ delete this; }
virtual void Execute(vtkObject *caller, unsigned
long, void*)
{
vtkTransform *t = vtkTransform::New();
vtkBoxWidget *widget =
reinterpret_cast<vtkBoxWidget*>(caller);
widget->GetTransform(t);
widget->GetProp3D()->SetUserTransform(t);
}
};
int main(int argc, char *argv[])
{
vtkRenderer *aRen = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aRen);
vtkRenderWindowInteractor *iren =
vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
//---------------------------------------------------------------
vtkUnstructuredGridReader *reader[2];
for(int i = 0; i < 2; i++)
{
reader[i]= vtkUnstructuredGridReader::New();
}
reader[0]->SetFileName("XYGL.vtk");
reader[0]-> Modified();
reader[0]-> Update();
reader[1]->SetFileName("lignefeu.vtk");
reader[1]-> Modified();
reader[1]-> Update();
//---------------------------------------------------------
vtkDelaunay2D *delaunay[2];
for(int i = 0; i < 2; i++)
{
delaunay[i] = vtkDelaunay2D::New();
}
delaunay[0]->SetInput((vtkPointSet *)
reader[0]->GetOutput());
delaunay[0] -> SetOffset (0.18);
delaunay[0] -> SetTolerance(0.00001);
delaunay[0] -> BoundingTriangulationOff();
delaunay[0] -> Modified();
delaunay[0] -> Update();
delaunay[1]->SetInput((vtkPointSet *)
reader[1]->GetOutput());
delaunay[1] -> SetOffset (0.18);
delaunay[1] -> SetTolerance(0.01);
delaunay[1] -> BoundingTriangulationOff();
delaunay[1] -> Modified();
delaunay[1] -> Update();
//---------------------------------------------------------
vtkElevationFilter *elevation[2];
for(int i = 0; i < 2; i++)
{
elevation[i] = vtkElevationFilter::New();
}
elevation[0]->SetInput(delaunay[0]->GetOutput());
elevation[0]->SetLowPoint(125987.0, 19987.0, 0.0);
elevation[0]->SetHighPoint(192990.0, 78940.0,
3020.0);
elevation[0]->SetScalarRange(0, 3200.0);
elevation[0]->Modified();
elevation[0]->Update();
elevation[1]->SetInput(delaunay[1]->GetOutput());
elevation[1]->SetLowPoint(159490.0, 49500.0,
33470.0);
elevation[1]->SetHighPoint(159740.0,49500.0,
33720.0);
elevation[1]->SetScalarRange(0, 3372.0);
elevation[1]->Modified();
elevation[1]->Update();
//----------------------------------------------------------
vtkLookupTable *litcolor[2];
for(int i = 0; i < 2; i++)
{
litcolor[i] = vtkLookupTable::New();
}
vtkLookupTable *coloreverse[2];
for(int i = 0; i < 2; i++)
{
coloreverse[i] = vtkLookupTable::New();
}
int nbcol = 1024;
litcolor[0]->SetNumberOfColors(nbcol);
litcolor[0]->SetHueRange(0.3, 0.20);
litcolor[0]->SetSaturationRange(1.0,1.0);
litcolor[0]->SetValueRange (0.0, 1);
litcolor[0]->SetTableRange(0.0, 0.90);
litcolor[0]->SetAlphaRange(1.0,1.0);
litcolor[0]->Build();
coloreverse[0]->SetNumberOfColors(nbcol);
litcolor[1]->SetNumberOfColors(nbcol);
litcolor[1]->SetHueRange(0.9, 0.05);
litcolor[1]->SetSaturationRange(1.0,1.0);
litcolor[1]->SetValueRange (0.0, 1);
litcolor[1]->SetTableRange(0.0, 0.90);
litcolor[1]->SetAlphaRange(1.0,1.0);
litcolor[1]->Build();
coloreverse[1]->SetNumberOfColors(nbcol);
for(int idx=0; idx<nbcol; idx++)
{
coloreverse[0]->SetTableValue(idx,litcolor[0]->GetTableValue(nbcol-idx));
}
for(int idx=0; idx<nbcol; idx++)
{
coloreverse[1]->SetTableValue(idx,litcolor[1]->GetTableValue(nbcol-idx));
}
//-------------------------------------------------------------
vtkPolyDataMapper *mapMesh[2];
for (int i =0; i <2; i++)
{
mapMesh[i] = vtkPolyDataMapper::New();
}
mapMesh[0]->SetInput((vtkPolyData
*)elevation[0]->GetOutput());
mapMesh[0]->SetScalarRange(0, 3200.0);
mapMesh[0] -> Modified();
mapMesh[0]-> Update();
mapMesh[1]->SetInput((vtkPolyData
*)elevation[1]->GetOutput());
mapMesh[1]->SetScalarRange(0, 3372.0);
mapMesh[1] -> Modified();
mapMesh[1]-> Update();
//----------------------------------------------------------
vtkPolyDataMapper *colmapper[2];
for (int i =0; i <2; i++)
{
colmapper[i]= vtkPolyDataMapper::New();
}
colmapper[0]->SetLookupTable(litcolor[0]) ;
colmapper[0]->SetInput((vtkPolyData *)
delaunay[0]->GetOutput());
colmapper[0]->ScalarVisibilityOn();
colmapper[0]->SetScalarRange(0, 3200.0);
colmapper[0]->SetColorModeToMapScalars();
colmapper[0]->Modified();
colmapper[0]->Update();
colmapper[1]->SetLookupTable(litcolor[1]) ;
colmapper[1]->SetInput((vtkPolyData *)
delaunay[1]->GetOutput());
colmapper[1]->ScalarVisibilityOn();
colmapper[1]->SetScalarRange(0, 3372.0);
colmapper[1]->SetColorModeToMapScalars();
colmapper[1]->Modified();
colmapper[1]->Update();
//------------------------------------------------------------------
vtkActor *meshActor[2];
for (int i =0; i <2; i++)
{
meshActor[i]= vtkActor::New();
}
meshActor[0]->SetMapper(mapMesh[0]);
meshActor[0]->SetMapper(colmapper[0]);
meshActor[0]->GetProperty()->SetInterpolationToFlat();
meshActor[0]->GetProperty()->SetInterpolationToGouraud();
meshActor[0]->GetProperty()->SetInterpolationToPhong();
meshActor[1]->SetMapper(mapMesh[1]);
meshActor[1]->SetMapper(colmapper[1]);
meshActor[1]->GetProperty()->SetInterpolationToFlat();
meshActor[1]->GetProperty()->SetInterpolationToGouraud();
meshActor[1]->GetProperty()->SetInterpolationToPhong();
//--------------------------------------------------------------
vtkScalarBarActor *scalarBar =
vtkScalarBarActor::New();
// --------- On
scalarBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
scalarBar->GetPositionCoordinate()->SetValue(0.1,
0.1);
scalarBar->SetOrientationToHorizontal();
scalarBar->SetNumberOfLabels(11);
scalarBar->SetWidth(0.80);
scalarBar->SetHeight(0.125);
scalarBar->SetMaximumNumberOfColors(nbcol);
scalarBar->SetLookupTable(colmapper[1]->GetLookupTable());
scalarBar->Modified();
//------------------------------------------------------------
aRen->AddActor(meshActor[0]);
aRen->AddActor(meshActor[1]);
aRen->AddActor2D(scalarBar);
//-----------------------------------------------------------------
vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
vtkBoxWidget *boxWidget = vtkBoxWidget::New();
boxWidget->SetInteractor(iren);
boxWidget->SetPlaceFactor(1.25);
for (int i = 0; i < 2; i++)
{
boxWidget->SetProp3D(meshActor[i]);
}
boxWidget->PlaceWidget();
vtkMyCallback *callback = vtkMyCallback::New();
boxWidget->AddObserver(vtkCommand::InteractionEvent,
callback);
boxWidget->On();
vtkLight *light1 = vtkLight::New();
aRen->AddLight(light1);
aRen->SetBackground(.8, .8, .8);
renWin->SetSize(750, 400);
iren->Initialize();
renWin->Render();
iren->Start();
return 0;
}
Send instant messages to your online friends http://uk.messenger.yahoo.com
More information about the vtkusers
mailing list