[vtkusers] how to write a x-z slice data file?

shun hyc8410 at 163.com
Tue Jan 16 07:03:37 EST 2007


Now I read a serial file then translate to get the x-z slice(input x-y
slice) data and write to a file,

But my problem is "write" ,only can write 2 or 3 file when use step to step
run "for{}" ,

    the next file is null,only have the vtk filehead;

who can help me?

This is my code:(vc.net2003 winxp)

 

int main (int argc, char **argv)

{

         vtkRenderer *aRenderer = vtkRenderer::New();

         vtkRenderWindow *renWin = vtkRenderWindow::New();

         renWin->AddRenderer(aRenderer);

         vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

         iren->SetRenderWindow(renWin);

         vtkVolume16Reader *v16 = vtkVolume16Reader::New();

         vtkTransform *pTransform = vtkTransform::New();

         vtkImageReslice *pImageReslice = vtkImageReslice::New();

         vtkPolyDataWriter * writer = vtkPolyDataWriter::New();

         vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();

         vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();

         vtkActor *skin = vtkActor::New();

         vtkContourFilter *skinExtractor = vtkContourFilter::New();

         v16->SetDataDimensions (64,64);

         v16->SetImageRange (1,93);

         v16->SetDataByteOrderToLittleEndian();

         v16->SetFilePrefix ("C:/Program Files/VTK
5.0/VTKData/Data/headsq/quarter");

         v16->SetDataSpacing (3.2,3.2,1.5);

         v16->ReleaseDataFlagOff();

         v16->SetDataMask(0x7fff);

         v16->Update(); 

 

         for(double i = 3.2;i<= 114.0; i+=3.2)

      {

         pTransform->Translate(0,-39.8,0); 

         pTransform->Update();

         pImageReslice->SetInputConnection(v16->GetOutputPort());

 
pImageReslice->SetResliceAxesDirectionCosines(0,0,-1,-1,0,0,0,-1,0); //xz
slice

         //pImageReslice->SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1);
//xy slice

         pImageReslice->SetResliceTransform(pTransform);       

         pImageReslice->SetOutputSpacing(3.2,3.2,3.2);

         pImageReslice->InterpolateOn();

         pImageReslice->SetOutputDimensionality(3);

         pImageReslice->SetResliceAxesOrigin(0,0,0);

         pImageReslice->SetOutputExtent(0,74,0,74,0,0);

         pImageReslice->Update();

         skinExtractor->SetInputConnection(pImageReslice->GetOutputPort());

         skinExtractor->SetValue(0, 500);

         skinExtractor->Update();

         writer->SetInputConnection(skinExtractor->GetOutputPort());

         writer->SetFileName("test.txt");

         writer->SetFileTypeToASCII();

         writer->Write();

      }

         skinNormals->SetInputConnection(skinExtractor->GetOutputPort());

         skinNormals->SetFeatureAngle(60.0);

         skinMapper->SetInputConnection(skinExtractor->GetOutputPort());

         skinMapper->ScalarVisibilityOff();

         skin->SetMapper(skinMapper);

         aRenderer->AddActor(skin);

         iren->Initialize();

         iren->Start(); 

         v16->Delete();

         skinExtractor->Delete();

         skinNormals->Delete();

         skinMapper->Delete();

         skin->Delete();

         iren->Delete();

         renWin->Delete();

         aRenderer->Delete();

         return 0;

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070116/ce7bef06/attachment.htm>


More information about the vtkusers mailing list