[vtkusers] Animation of vtkUnstructuredGrid Code

Сергеев Ефим efim.sergeev at yandex.ru
Tue Jun 8 15:44:04 EDT 2010


class vtkTimerCallback : public vtkCommand
{
public:
static vtkTimerCallback *New()
{
vtkTimerCallback *cb = new vtkTimerCallback;
cb->TimerCount = 0;
return cb;
}

virtual void Execute(vtkObject *caller, unsigned long eventId,
void * vtkNotUsed(callData))
{
if (vtkCommand::TimerEvent == eventId)
{
++this->TimerCount;
}
else
{
return;
}

vtkSmartPointer displacements;
const char *v_names = reader->GetVectorsNameInFile(TimerCount);
displacements = grid->GetPointData()->GetVectors(v_names);
int Size = displacements->GetSize();
std::cout << v_names << std::endl;
std::cout << Size << std::endl;

double point[3];


for(vtkIdType i = 0; i < grid->GetNumberOfPoints(); i++)
{

grid->GetPoint(i,point);

double *touple;

touple = displacements->GetTuple3(i);


point[0]=point[0]+touple[0];
point[1]=point[1]+touple[1];
point[2]=point[2]+touple[2];

grid->GetPoints()->SetPoint(i,point[0],point[1],point[2]);
cout << this->TimerCount << endl;
}

grid->Update();
actor->Modified();

renderer->Render();

}

private:
int TimerCount;
public:
vtkSmartPointer actor;
vtkSmartPointer grid;
vtkSmartPointer reader;
vtkSmartPointer geometryFilter;
vtkSmartPointer renderer;
vtkSmartPointer renderWindow;
vtkSmartPointer iren;
vtkSmartPointer mapper;
};


int main(int, char *[])
{

vtkstd::string filename = "C://vtk//DATA//blow.vtk";

//read all the data from the file
vtkSmartPointer reader = vtkSmartPointer::New();
reader->SetFileName(filename.c_str());
reader->GetReadAllVectors();
reader->ReadAllVectorsOn();

reader->Update();
vtkUnstructuredGrid* unstructuredGrid = reader->GetOutput();



vtkSmartPointer geometryFilter = vtkSmartPointer::New();
geometryFilter->SetInputConnection(unstructuredGrid->GetProducerPort());

geometryFilter->Update();

//Create a mapper and actor
vtkSmartPointer mapper = vtkSmartPointer::New();
mapper->SetInputConnection(geometryFilter->GetOutputPort());
vtkSmartPointer actor = vtkSmartPointer::New();
actor->SetMapper(mapper);


//Create a renderer, render window, and interactor
vtkSmartPointer renderer = vtkSmartPointer::New();
vtkSmartPointer renderWindow = vtkSmartPointer::New();
renderWindow->AddRenderer(renderer);

vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New();
renderWindowInteractor->SetRenderWindow(renderWindow);

//Add the actor to the scene
renderer->AddActor(actor);
//renderer->SetBackground(1,1,1); // Background color white

//Render and interact

renderWindow->Render();

renderWindowInteractor->Initialize();


// Sign up to receive TimerEvent
vtkSmartPointer cb = vtkSmartPointer::New();
//init cb
cb->actor = actor;
cb->grid = unstructuredGrid;
cb->reader = reader;
cb->renderWindow = renderWindow;
cb->iren = renderWindowInteractor;
cb->renderer = renderer;
cb->mapper = mapper;
cb->geometryFilter = geometryFilter;


renderWindowInteractor->AddObserver(vtkCommand::TimerEvent, cb);

int timerId = renderWindowInteractor->CreateRepeatingTimer(1000);
std::cout << "timerId: " << timerId << std::endl;


renderWindowInteractor->Start();

return EXIT_SUCCESS;
}

08.06.10, 23:37, "Bill Lorensen" <bill.lorensen at gmail.com>:

> Please post your code.
>  
>  2010/6/8 Сергеев Ефим :
>  > 08.06.10, 17:58, "David Doria" :
>  >
>  > On Tue, Jun 8, 2010 at 9:46 AM, Сергеев Ефим  wrote:
>  >>
>  >> I have some sophisticated code on C++, it seems must animate
>  >> vtkUnstrucuredGrid which loaded  from C:\VTK\Data\blow.vtk file.
>  >> But code doesn't work. I not understand where error is located.
>  >>
>  >
>  > What do you mean by "doesn't work"? Can you be more specific? What are you
>  > trying to accomplish?
>  > There are many examples here: http://www.vtk.org/Wiki/VTK/Examples
>  > Including an animation demonstration. Please take a look and let us know if
>  > you still have questions.
>  > Thanks,
>  >
>  > David
>  >
>  >  The file "blow.vtk" contain description of unstructured grid and 10 vectors
>  > "displacement0 ....displacement9" described by VECTOR keyword. Each vector
>  > of value in these vectors specifies the offset of the initial position of
>  > point is described by POINTS keyword.
>  >
>  > Using these data probably can construct animation for 10 frames, just move
>  > points to next position by adding displacement. This is the goal of my
>  > program.
>  >
>  > The basis of my program, this example
>  > http://www.vtk.org/Wiki/VTK/Examples/Utilities/Animation. But this example
>  > just move a sphere.
>  >
>  > My program runnig and displays the first frame, but after that the objects
>  > in the window not movin
>  > _______________________________________________
>  > 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
>  >
>  >
>  
>  

-- 
Здесь спама нет http://mail.yandex.ru/nospam/sign



More information about the vtkusers mailing list