[vtkusers] mesh animation
agatte
agatakrason at gmail.com
Fri Jun 12 13:47:55 EDT 2015
Hello,
I have a problem with animation. I would like to make an animation display
two meshed :
1 fixed mesh and second "moving mesh".
I created a loop for to read data from mhd files and display. But I can't do
it automaticaly ... ;/
I try to add timer .. But It doesn't work well.
Could You help me please ?
I would be appreciate for any help please.
Here is my code :
class vtkTimerCallback : public vtkCommand
{
public:
static vtkTimerCallback *New()
{
vtkTimerCallback *cb = new vtkTimerCallback;
cb->TimerCount = 0;
return cb;
}
virtual void Execute(vtkObject *vtkNotUsed(caller), unsigned long eventId,
void *vtkNotUsed(callData))
{
if(vtkCommand::TimerEvent == eventId)
{
++this->TimerCount;
}
cout << this->TimerCount << endl;
}
private:
int TimerCount;
};
int main (int argc, char *argv[])
{
if( argc < 3)
{
std::cerr << "Usage: " <<argv[0] <<"refFileName
numberOfFiles"<< std::endl;
return EXIT_FAILURE;
}
//string dirName = "images";
//argv[1]="\images\\image06.mhd";
vtkSmartPointer<vtkMetaImageReader> refReader =
vtkSmartPointer<vtkMetaImageReader>::New();
refReader->SetFileName(argv[1]);
refReader->Update();
vtkSmartPointer<vtkImageData> refVolume =
vtkSmartPointer<vtkImageData>::New();
refVolume = refReader->GetOutput();
vtkSmartPointer<vtkContourFilter> refContour =
vtkSmartPointer<vtkContourFilter>::New();
refContour->SetInput(refVolume);
refContour->Update();
refContour->SetValue(0,1);
vtkSmartPointer<vtkPolyData> refPolydata =
vtkSmartPointer<vtkPolyData>::New();
refPolydata= refContour->GetOutput();
vtkSmartPointer<vtkPoints> refPoints = refPolydata->GetPoints();
vtkSmartPointer<vtkCellArray> refPolys = refPolydata->GetPolys();
refPolydata->SetPoints(refPoints);
vtkSmartPointer<vtkPolyDataMapper> refMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
refMapper->SetInputConnection(refContour->GetOutputPort());
refMapper->ScalarVisibilityOn();
vtkSmartPointer<vtkActor> refActor = vtkSmartPointer<vtkActor>::New();
refActor->SetMapper(refMapper);
// refActor->GetProperty()->SetColor(1.0, 2.0, 3.0);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground(0, 0, 0);
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
renderer->AddActor(refActor);
int numberOfFiles = atoi(argv[2]);
std::cout<<"numberOfFiles : "<< std::endl;
interactor->Start();
interactor->SetRepeatCount(numberOfFiles);
for(int i=1; i< numberOfFiles; i++)
{
// Sign up to receive TimerEvent
vtkSmartPointer<vtkTimerCallback> cb =
vtkSmartPointer<vtkTimerCallback>::New();
interactor->AddObserver(vtkCommand::TimerEvent, cb);
interactor->CreateRepeatingTimer(10);
string end = static_cast<ostringstream*>( &(ostringstream() << i)
)->str();
std::cout <<" "<<end<<std::endl;
string currentFileName;
currentFileName = "image0" + end + ".mhd";
std::cout<<"
"<<currentFileName<<std::endl;
vtkSmartPointer<vtkMetaImageReader> moveReader=
vtkSmartPointer<vtkMetaImageReader>::New();
moveReader->SetFileName(currentFileName.c_str());
moveReader->Update();
vtkSmartPointer<vtkImageData> moveVolume =
vtkSmartPointer<vtkImageData>::New();
moveVolume = moveReader->GetOutput();
vtkSmartPointer<vtkContourFilter> moveContour =
vtkSmartPointer<vtkContourFilter>::New();
moveContour->SetInput(moveVolume);
moveContour->Update();
moveContour->SetValue(0,1);
vtkSmartPointer<vtkPolyData> movePolydata =
vtkSmartPointer<vtkPolyData>::New();
movePolydata = moveContour->GetOutput();
vtkSmartPointer<vtkPoints> movePoints = movePolydata->GetPoints();
vtkSmartPointer<vtkCellArray> movePolys = movePolydata->GetPolys();
movePolydata->SetPoints(movePoints);
vtkSmartPointer<vtkPolyDataMapper> moveMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
moveMapper->SetInputConnection(moveContour->GetOutputPort());
moveMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> moveActor = vtkSmartPointer<vtkActor>::New();
moveActor->SetMapper(moveMapper);
std::cout<< "i = "<<i<<std::endl;
moveActor->GetProperty()->SetColor(1.0, 2.0, 0.0);
renderer->AddActor(moveActor);
renderer->Render();
renderWindow->Render();
interactor->Start();
moveActor->SetVisibility(0);
}
system("Pause");
return EXIT_SUCCESS;
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/mesh-animation-tp5732314.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list