[vtkusers] Set camera view along XY, XZ and YZ axis
madz
madaramh at gmail.com
Mon Jan 27 23:27:59 EST 2014
The problem is that if I rotate the 3d object and use function setPosition(),
the position changes according to the rotation. I don't want it to change
position according to the rotation.
Here is an example code,
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkObjectFactory.h>
#include <vtkLabelPlacementMapper.h>
#include <vtkPointSetToLabelHierarchy.h>
#include <vtkStringArray.h>
#include <vtkLabeledDataMapper.h>
#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkCubeSource.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
vtkSmartPointer<vtkRenderer> renderer;
class MouseInteractorStyle4 : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorStyle4* New();
vtkTypeMacro(MouseInteractorStyle4, vtkInteractorStyleTrackballCamera);
double p[3], f[3];
virtual void OnLeftButtonDown()
{
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
virtual void OnMiddleButtonDown()
{
std::cout << "Pressed middle mouse button." << std::endl;
// Forward events
renderer->GetActiveCamera()->SetPosition(p[1],p[2],p[3]);
vtkInteractorStyleTrackballCamera::OnMiddleButtonDown();
}
virtual void OnRightButtonDown()
{
renderer->GetActiveCamera()->GetPosition(p);
renderer->GetActiveCamera()->GetFocalPoint(f);
std::cout << "Position" <<p[0]<<" ,
"<<p[1]<<" , "<<p[2] << std::endl;
std::cout << "focal" <<f[0]<<" ,
"<<f[1]<<" , "<<f[2] << std::endl;
vtkInteractorStyleTrackballCamera::OnRightButtonDown();
}
};
vtkStandardNewMacro(MouseInteractorStyle4);
int main(int, char *[])
{
// Create a cube.
vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
cubeSource->SetXLength(7);
cubeSource->SetYLength(10);
cubeSource->SetZLength(15);
// Create a mapper and actor.
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cubeSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Create a renderer, render window, and interactor
renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actors to the scene
renderer->AddActor(actor);
renderer->SetBackground(.3, .2, .1);
vtkSmartPointer<MouseInteractorStyle4> style2 =
vtkSmartPointer<MouseInteractorStyle4>::New();
renderWindowInteractor->SetInteractorStyle( style2 );
// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
First I press left button to store the position coordinates, then I rotate
the cube randomly and click the middle button to set position (the stored
position co-ordinates). The new position is different from the one I stored
the position from.
How do I solve this problem? Any help would be highly appreciated.
--
View this message in context: http://vtk.1045678.n5.nabble.com/Set-camera-view-along-XY-XZ-and-YZ-axis-tp5725516p5725658.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list