[vtkusers] How can I modify an vtkImageData manually?
Tao Kai
caesartaoyz at gmail.com
Sun Aug 20 21:53:58 EDT 2006
Hi all~
The program I'm writing requires some self-defined operation on
vtkImageData. I hope to operate on the internal data structure of
vtkImageData as on an ordinary array in c++. I write the code like this:
vtkDICOMImageReader *p=vtkDICOMImageReader::New();
p->SetDirectoryName("f:\\dcm\\organ1");
vtkImageData *t=p->GetOutput();
float *f=(float*)t->GetScalarPointer();
vtkContourFilter *skinExtractor = vtkContourFilter::New();
skinExtractor->SetInput(t);
skinExtractor->SetValue(0, 300);
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
skinMapper->SetInput(skinExtractor->GetOutput());
skinMapper->ScalarVisibilityOff();
//vtkActor *skin = vtkActor::New();
vtkLODActor *skin = vtkLODActor::New();
skin->SetMapper(skinMapper);
vtkRenderer *ren1=vtkRenderer::New();
vtkRenderWindow *renWin=vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
ren1->AddActor(skin);
for(int k=0;k<360;k++){
t->Update();
p->Update();
renWin->Render();
ren1->GetActiveCamera()->Azimuth( 1 );
for(int j=0;j<dims[0]*dims[1]*dims[2];j++){
f[j]+=10;
}
}
The intention of the code above is to modify the intensity value of the
vtkImageData and immediately display it in the rendering window. However,
the effect of the modification(as illustrated in the for loop block, which
uses a float type pointer which is initialized by
vtkImageData::GetScalraPointer() previously) is not reflected in the
rendering Window. Since I have set an contour filter which allows the
display of only voxel which has the intensity of 300, clearly the scene in
the rendering window should be changed due to the modification. But it
doesn't, why?
I suppose that may be it is due to the implicti execute mechanism. I modify
the content of array pointed by "f", but there lacks a method to inform
"t"(vtkImageData) of the change, thus the time stamp of "t" will not change.
Is it right? Is there anyway to solve the problem?
Taokai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060821/f00e4288/attachment-0001.htm>
More information about the vtkusers
mailing list