[vtkusers] fix position of vtkAxesActor
Benoist Laurent
benoist at ibpc.fr
Fri Sep 17 11:07:51 EDT 2010
Basically I thought than the vtkSmartPointers were supposed to managed
this kind of situations...
=====================
axes.cpp
=====================
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSphereSource.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkAxesActor.h>
#include <vtkPropAssembly.h>
#include <vtkSmartPointer.h>
/* Do not use ! */
void displayAxes(vtkRenderWindowInteractor *renderWindowInteractor)
{
vtkSmartPointer<vtkAxesActor> axes =
vtkSmartPointer<vtkAxesActor>::New();
vtkSmartPointer<vtkOrientationMarkerWidget> widget =
vtkSmartPointer<vtkOrientationMarkerWidget>::New();
widget->SetOutlineColor( 0.9300, 0.5700, 0.1300 );
widget->SetOrientationMarker( axes );
widget->SetInteractor( renderWindowInteractor );
widget->SetViewport( 0.0, 0.0, 0.4, 0.4 );
widget->SetEnabled( 1 );
widget->InteractiveOn();
}
int main (int, char *[])
{
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(1.0);
sphereSource->Update();
vtkPolyData* polydata = sphereSource->GetOutput();
// Create a mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(polydata);
// Create an actor
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// A renderer and render window
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
// An interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actors to the scene
renderer->AddActor(actor);
renderer->SetBackground(.2, .3, .4);
// Add the axes
vtkSmartPointer<vtkAxesActor> axes =
vtkSmartPointer<vtkAxesActor>::New();
vtkSmartPointer<vtkOrientationMarkerWidget> widget =
vtkSmartPointer<vtkOrientationMarkerWidget>::New();
widget->SetOutlineColor( 0.9300, 0.5700, 0.1300 );
widget->SetOrientationMarker( axes );
widget->SetInteractor( renderWindowInteractor );
widget->SetViewport( 0.0, 0.0, 0.4, 0.4 );
widget->SetEnabled( 1 );
widget->InteractiveOn();
// Render the scene
renderer->ResetCamera();
renderWindow->Render();
// Begin mouse interaction
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
=====================
CMakeLists.txt
=====================
cmake_minimum_required(VERSION 2.6)
PROJECT(AxesIndicator)
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
ADD_EXECUTABLE(axes axes.cpp)
TARGET_LINK_LIBRARIES(axes vtkHybrid vtkWidgets)
Le 17 sept. 10 à 16:54, David Doria a écrit :
> On Fri, Sep 17, 2010 at 10:57 AM, Benoist Laurent <benoist at ibpc.fr>
> wrote:
> Hi all,
>
> The example works very well.
> However, when I try to put the code relative to the axes in a
> different fonction the application crashes.
>
> void displayAxes(vtkRenderWindowInteractor *renderWindowInteractor)
> {
> vtkSmartPointer<vtkAxesActor> axes =
> vtkSmartPointer<vtkAxesActor>::New();
>
> vtkSmartPointer<vtkOrientationMarkerWidget> widget =
> vtkSmartPointer<vtkOrientationMarkerWidget>::New();
> widget->SetOutlineColor( 0.9300, 0.5700, 0.1300 );
> widget->SetOrientationMarker( axes );
> widget->SetInteractor( renderWindowInteractor );
> widget->SetViewport( 0.0, 0.0, 0.4, 0.4 );
> widget->SetEnabled( 1 );
> widget->InteractiveOn();
> }
>
> So I guess there's something I did not understand with the
> vtkSmartPointer and/or the vtkWidget.
>
> An idea ?
> Thanks,
>
> Benoist
>
> Benoist,
>
> Can you share a compilable piece of code? I'm definitely not a
> smart pointer expert, but I think the pointers defined in your
> displayAxes will go out of scope when you leave the function.
>
> David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100917/1b437f36/attachment.htm>
More information about the vtkusers
mailing list