[vtkusers] Up: Segmentation Fault error when trying to animate a vector of actors
Alex Malyushytskyy
alexmalvtk at gmail.com
Mon Jan 28 19:14:00 EST 2013
Try to create array of ActorAnimator instead of animatePart indide the scopes.
I did not look into ActorAnimator code, but I expect the fact that it
does not survive the scope matters.
And at the minimum the below may be simply removed having exactly the
same results.
Alex
> for(unsigned int k = 0; k < actors.size(); k++)
> {
> ActorAnimator animatePart;
> animatePart.SetActor(actors[k]);
> endPart[0] = 1.0;
> endPart[1] = 2.5;
> endPart[2] = 0;
> animatePart.SetEndPosition(endPart);
>
> animatePart.AddObserversToCue(cues[k]);
> }
On Thu, Jan 17, 2013 at 6:10 AM, Lucia Pavan <lpavan.pd at gmail.com> wrote:
> Hi vtkusers,
>
> I re-post my message, as I think something went wrong with it yesterday.
> I want to use VTK to trace the linear movement of a number of particles.
> (my final aim is to visualize the evolution of a stream of particles, each
> of which is following a different path).
> For this I am trying to merge the two C++ examples AnimateActors and
> VectorOfActors that are on the vtk website.
> The code compiles smoothly, but I end up with a Segmentation Fault error
> when trying to animate the vector of actors.
> The code I'm using is here below.
> I isolated the problem in this part of the code:
>
> std::vector<double> endPart(3);
> for(unsigned int k = 0; k < actors.size(); k++)
> {
> ActorAnimator animatePart;
> animatePart.SetActor(actors[k]);
> endPart[0] = 1.0;
> endPart[1] = 2.5;
> endPart[2] = 0;
> animatePart.SetEndPosition(endPart);
>
> animatePart.AddObserversToCue(cues[k]);
> }
>
>
> Could somebody help me in understanding where is my error?
> Even suggestions on a simpler method /different approach to the problem are
> welcome!
>
> many thanks,
> Lucia
>
>
>
> -------------------------------------------------------------------
> Lucia Pavan
>
> ISDC - Science data center for Astrophysics
> Ch. d'Ecogia 16,
> CH-1290 Versoix
> Switzerland
>
>
> --------- my code --------
> #include "AnimateActors.h"
> #include <vtkSmartPointer.h>
> #include <vtkAnimationCue.h>
> #include <vtkRenderer.h>
> #include <vtkSphereSource.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkCommand.h>
> #include <vtkAnimationScene.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkCamera.h>
> #include "vtkProperty.h"
> #include <stdio.h>
> #include <math.h>
>
> #include <vector>
>
>
> int main(int argc, char *argv[])
> {
> // Create the graphics structure. The renderer renders into the
> // render window.
> vtkSmartPointer<vtkRenderWindowInteractor> iren =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
> vtkSmartPointer<vtkRenderWindow> renWin =
> vtkSmartPointer<vtkRenderWindow>::New();
> renWin->SetSize(600,600); //(width, height)
> renWin->SetMultiSamples(0);
> iren->SetRenderWindow(renWin);
> renWin->AddRenderer(ren1);
>
> // Generate a sphere
> vtkSmartPointer<vtkSphereSource> sphereSource =
> vtkSmartPointer<vtkSphereSource>::New();
> sphereSource->SetRadius(0.25);
> sphereSource->SetCenter(0.0,2.5,0.0);
>
> vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> sphereMapper->SetInputConnection( sphereSource->GetOutputPort());
> vtkSmartPointer<vtkActor> sphere = vtkSmartPointer<vtkActor>::New();
> sphere->SetMapper(sphereMapper);
> ren1->AddActor(sphere);
>
>
> // Generate a vector of actors (particles)
> std::vector<vtkSmartPointer<vtkActor> > actors;
> for(unsigned int i = 0; i < 3; i++)
> {
> vtkSmartPointer<vtkSphereSource> sphereSource =
> vtkSmartPointer<vtkSphereSource>::New();
> sphereSource->SetCenter(0.0,2.5,0.0);
> sphereSource->SetRadius(0.2);
>
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInputConnection(sphereSource->GetOutputPort());
>
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
> actor->GetProperty()->SetColor(1.0,1.0,1.0);
> actors.push_back(actor);
>
> ren1->AddActor(actors[i]);
> }
>
> // Create an Animation Scene
> vtkSmartPointer<vtkAnimationScene> scene =
> vtkSmartPointer<vtkAnimationScene>::New();
> if(argc>=2 && strcmp(argv[1],"-real")==0)
> {
> cout << "real-time mode" << endl;
> scene->SetModeToRealTime();
> }
> else
> {
> cout << "sequence mode" << endl;
> scene->SetModeToSequence();
> }
> scene->SetLoop(0);
> scene->SetFrameRate(5);
> scene->SetStartTime(0);
> scene->SetEndTime(10);
>
> vtkSmartPointer<AnimationSceneObserver> sceneObserver =
> vtkSmartPointer<AnimationSceneObserver>::New();
> sceneObserver->SetRenderWindow(renWin);
> scene->AddObserver(vtkCommand::AnimationCueTickEvent,sceneObserver);
>
> // Create an Animation Cue for each actor
>
> vtkSmartPointer<vtkAnimationCue> cue1 =
> vtkSmartPointer<vtkAnimationCue>::New();
> cue1->SetStartTime(5);
> cue1->SetEndTime(10);
> scene->AddCue(cue1);
>
> std::vector<vtkSmartPointer<vtkAnimationCue> > cues;
> for(unsigned int j = 0; j < actors.size(); j++)
> {
> vtkSmartPointer<vtkAnimationCue> cue =
> vtkSmartPointer<vtkAnimationCue>::New();
> cue->SetStartTime(5);
> cue->SetEndTime(10);
> cues.push_back(cue);
>
> scene->AddCue(cues[j]);
> }
>
> // Create an ActorAnimator for each actor;
> ActorAnimator animateSphere;
> animateSphere.SetActor(sphere);
> std::vector<double> endSphere(3);
> endSphere[0] = 0;
> endSphere[1] = -2.5;
> endSphere[2] = 0;
> animateSphere.SetEndPosition(endSphere);
>
> animateSphere.AddObserversToCue(cue1);
>
>
>
> std::vector<double> endPart(3);
> for(unsigned int k = 0; k < actors.size(); k++)
> {
> ActorAnimator animatePart;
> animatePart.SetActor(actors[k]);
> endPart[0] = 1.0;
> endPart[1] = 2.5;
> endPart[2] = 0;
> animatePart.SetEndPosition(endPart);
>
> animatePart.AddObserversToCue(cues[k]);
> }
>
> renWin->Render();
> ren1->ResetCamera();
> ren1->GetActiveCamera()->Dolly(0.5);
> ren1->ResetCameraClippingRange();
>
> // Create Cue observer.
> scene->Play();
> scene->Stop();
>
> iren->Start();
> return EXIT_SUCCESS;
> }
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list