Hi Jana,<br /><br />
much better!<br />
Here we go:<br />
<pre>#<span style=' color: Blue;'>include</span> <vtkVersion.h>
#<span style=' color: Blue;'>include</span> <vtkPolyDataMapper.h>
#<span style=' color: Blue;'>include</span> <vtkActor.h>
#<span style=' color: Blue;'>include</span> <vtkRenderWindow.h>
#<span style=' color: Blue;'>include</span> <vtkRenderer.h>
#<span style=' color: Blue;'>include</span> <vtkRenderWindowInteractor.h>
#<span style=' color: Blue;'>include</span> <vtkPolyData.h>
#<span style=' color: Blue;'>include</span> <vtkSphereSource.h>
#<span style=' color: Blue;'>include</span> <vtkOrientationMarkerWidget.h>
#<span style=' color: Blue;'>include</span> <vtkAxesActor.h>
#<span style=' color: Blue;'>include</span> <vtkPropAssembly.h>
#<span style=' color: Blue;'>include</span> <vtkSmartPointer.h>
#<span style=' color: Blue;'>include</span> <vtkInteractorStyleTrackballCamera.h>
#<span style=' color: Blue;'>include</span> <vtkCommand.h>
#<span style=' color: Blue;'>include</span> <vtkCamera.h>
#<span style=' color: Blue;'>include</span> <vtkCallbackCommand.h>
#<span style=' color: Blue;'>include</span> <vtkObjectFactory.h>
#<span style=' color: Blue;'>include</span> <vtkMatrix4x4.h>
<span style=' color: Blue;'>class</span> MySphereSource : <span style=' color: Blue;'>public</span> vtkSphereSource {
<span style=' color: Blue;'>public</span>:
vtkTypeMacro(MySphereSource, vtkSphereSource);
<span style=' color: Blue;'>static</span> MySphereSource* New();
<span style=' color: Blue;'>void</span> MySphereSource::printDirectionOfProjection(<span style=' color: Blue;'>double</span>* dirOfProj)
{
<span style=' color: Blue;'>cout</span> << <span style=' color: Maroon;'>"direction of view: "</span> << dirOfProj[<span style=' color: Maroon;'>0</span>] << <span style=' color: Maroon;'>" "</span> << dirOfProj[<span style=' color: Maroon;'>1</span>] << <span style=' color: Maroon;'>" "</span> << dirOfProj[<span style=' color: Maroon;'>2</span>] << <span style=' color: Blue;'>endl</span>;
}
<span style=' color: Blue;'>protected</span>:
MySphereSource(){};
~MySphereSource(){};
};
vtkStandardNewMacro(MySphereSource);
<span style=' color: Green;'>// Command</span>
<span style=' color: Blue;'>class</span> vtkCameraObserver : <span style=' color: Blue;'>public</span> vtkCommand
{
<span style=' color: Blue;'>public</span>:
<span style=' color: Blue;'>static</span> vtkCameraObserver *New()
{<span style=' color: Blue;'>return</span> <span style=' color: Blue;'>new</span> vtkCameraObserver();};
<span style=' color: Blue;'>void</span> SetPolyDataAlgorithm(MySphereSource* mySphereSource) {
<span style=' color: Blue;'>this</span>->mySphereSource = mySphereSource;
}
<span style=' color: Blue;'>protected</span>:
vtkCameraObserver() {};
~vtkCameraObserver(){}
<span style=' color: Blue;'>virtual</span> <span style=' color: Blue;'>void</span> Execute(vtkObject* caller, <span style=' color: Blue;'>unsigned</span> <span style=' color: Blue;'>long</span> event, <span style=' color: Blue;'>void</span> *calldata)
{
<span style=' color: Blue;'>cout</span> << <span style=' color: Maroon;'>"Camera modified event"</span> << <span style=' color: Blue;'>endl</span>;
vtkCamera* cam = <span style=' color: Blue;'>reinterpret_cast</span><vtkCamera*> (caller);
<span style=' color: Blue;'>double</span>* direction = cam->GetDirectionOfProjection();
mySphereSource->printDirectionOfProjection(direction);
<span style=' color: Green;'>// In case you would need this too:</span>
<span style=' color: Green;'>//vtkMatrix4x4* mat = cam->GetViewTransformMatrix();</span>
<span style=' color: Green;'>//cout << "View matrix: " << endl; </span>
<span style=' color: Green;'>//cout << "================================================================================= " << endl; </span>
<span style=' color: Green;'>//cout << mat->GetElement(0, 0) << "\t" << mat->GetElement(0, 1) << "\t" << mat->GetElement(0, 2) << "\t" << mat->GetElement(0, 3) << "\t" << endl;</span>
<span style=' color: Green;'>//cout << mat->GetElement(1, 0) << "\t" << mat->GetElement(1, 1) << "\t" << mat->GetElement(1, 2) << "\t" << mat->GetElement(1, 3) << "\t" << endl;</span>
<span style=' color: Green;'>//cout << mat->GetElement(2, 0) << "\t" << mat->GetElement(2, 1) << "\t" << mat->GetElement(2, 2) << "\t" << mat->GetElement(2, 3) << "\t" << endl;</span>
<span style=' color: Green;'>//cout << mat->GetElement(3, 0) << "\t" << mat->GetElement(3, 1) << "\t" << mat->GetElement(3, 2) << "\t" << mat->GetElement(3, 3) << "\t" << endl;</span>
<span style=' color: Green;'>//cout << "================================================================================= " << endl; </span>
<span style=' color: Green;'>//double* x = cam->GetOrientation();</span>
<span style=' color: Green;'>//cout << "Orientation : " << x[0] << " " << x[1] << " " << x[2] << endl;</span>
}
<span style=' color: Blue;'>private</span> :
MySphereSource* mySphereSource;
};
<span style=' color: Blue;'>int</span> main (<span style=' color: Blue;'>int</span>, <span style=' color: Blue;'>char</span> *[])
{
vtkSmartPointer<MySphereSource> sphereSource =
vtkSmartPointer<MySphereSource>::New();
sphereSource->SetCenter(<span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.0</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.0</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.0</span>);
sphereSource->SetRadius(<span style=' color: Maroon;'>1</span><span style=' color: Maroon;'>.23</span>);
sphereSource->Update();
vtkPolyData* polydata = sphereSource->GetOutput();
<span style=' color: Green;'>// Create a mapper</span>
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
<span style=' color: Blue;'>#if</span> VTK_MAJOR_VERSION <= <span style=' color: Maroon;'>5</span>
mapper->SetInput(polydata);
<span style=' color: Blue;'>#else</span>
mapper->SetInputData(polydata);
<span style=' color: Blue;'>#endif</span>
<span style=' color: Green;'>// Create an actor</span>
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
<span style=' color: Green;'>// A renderer and render window</span>
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
<span style=' color: Green;'>// An interactor</span>
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New();
renderWindowInteractor->SetInteractorStyle(style);
<span style=' color: Green;'>// Add the actors to the scene</span>
renderer->AddActor(actor);
renderer->SetBackground(<span style=' color: Maroon;'>.2</span>, <span style=' color: Maroon;'>.3</span>, <span style=' color: Maroon;'>.4</span>);
<span style=' color: Green;'>//*************************************************************************************</span>
<span style=' color: Green;'>// Create observer</span>
vtkSmartPointer<vtkCameraObserver> observer = vtkSmartPointer<vtkCameraObserver>::New();
<span style=' color: Green;'>// tell observer on which object to operate on</span>
observer->SetPolyDataAlgorithm(sphereSource);
<span style=' color: Green;'>// hook observer into camera's modified event</span>
vtkCamera* cam = renderer->GetActiveCamera();
cam->AddObserver(vtkCommand::ModifiedEvent, observer);
<span style=' color: Green;'>//*************************************************************************************</span>
<span style=' color: Green;'>// Add widget</span>
vtkSmartPointer<vtkAxesActor> axes =
vtkSmartPointer<vtkAxesActor>::New();
vtkSmartPointer<vtkOrientationMarkerWidget> widget =
vtkSmartPointer<vtkOrientationMarkerWidget>::New();
widget->SetOutlineColor( <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.9300</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.5700</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.1300</span> );
widget->SetOrientationMarker( axes );
widget->SetInteractor( renderWindowInteractor );
widget->SetViewport( <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.0</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.0</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.4</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.4</span> );
widget->SetEnabled( <span style=' color: Maroon;'>1</span> );
widget->InteractiveOn();
renderer->ResetCamera();
renderWindow->Render();
<span style=' color: Green;'>// Begin mouse interaction</span>
renderWindowInteractor->Start();
<span style=' color: Blue;'>return</span> EXIT_SUCCESS;
}</pre><br/>
best regards<br/>
Jochen
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/How-to-forward-mouse-move-event-to-polydata-algorithm-and-get-there-direction-of-projection-tp5714021p5714029.html">Re: How to forward mouse move event to polydata algorithm and get there direction of projection</a><br/>
Sent from the <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html">VTK - Users mailing list archive</a> at Nabble.com.<br/>