[vtkusers] How can I write VTKData/Data/headsq/quart er to a *.vtk file and display this *.vt k file?

iii-lin iii-lin at 163.com
Wed Dec 13 01:19:54 EST 2006


hello,
 
In the VTKData/Data/headsq/,there are some sample datas,How can I write this datas to a out.vtk file?and display it.
 
I use
 
  vtkVolume16Reader *v16 = vtkVolume16Reader::New();
    v16->SetDataDimensions(64,64);
    v16->SetDataByteOrderToLittleEndian();
    v16->SetFilePrefix ("headsq/quarter");
    v16->SetImageRange(1, 93);
 v16->SetDataSpacing (3.2, 3.2, 1.5);
 
to read the data,
 
 vtkContourFilter *skinExtractor = vtkContourFilter::New();
  skinExtractor->SetInput((vtkDataSet*) v16->GetOutput());
  skinExtractor->SetValue(0, 500);
  vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
  skinNormals->SetInput(skinExtractor->GetOutput());
  skinNormals->SetFeatureAngle(60.0);
  vtkPolyDataWriter *pdw=vtkPolyDataWriter::New();
  pdw->SetInput(skinNormals->GetOutput());
     pdw->SetFileName("out.vtk");
     pdw->Write();
 
I use these code to write datas to out.vtk,and in the java applet,I use these code to display the out.vtk file,but nothing is displayed.
 
//////////////////////////////////////////////////////////////////////////
   vtkPolyDataReader fran = new vtkPolyDataReader();
    fran.SetFileName("d:/lmhjava/out_tougu.vtk");
//    fran.SetFileName("D:\\lmhjava\\vtksource\\VTKconsole\\out.vtk");
    // We want to preserve topology (not let any cracks form);. This may
    // limit the total reduction possible, which we have specified at 90%.
    vtkSmoothPolyDataFilter smoother = new vtkSmoothPolyDataFilter();
    smoother.SetInput(fran.GetOutput());
    smoother.SetNumberOfIterations(50);
    vtkPolyDataNormals normals = new vtkPolyDataNormals();
    normals.SetInput(smoother.GetOutput());
    normals.FlipNormalsOn();
    vtkPolyDataMapper franMapper = new vtkPolyDataMapper();
    franMapper.SetInput(normals.GetOutput());
    vtkActor franActor = new vtkActor();
    franActor.SetMapper(franMapper);
    franActor.GetProperty().SetColor(1.0, 0.49, 0.25);
    // Add the actors to the renderer, set the background and size
    renWin.GetRenderer().AddActor(franActor);
    renWin.GetRenderer().SetBackground(1, 1, 1);
    VtkPanelUtil.setSize(renWin, 250, 250);
    vtkCamera cam1 = new vtkCamera();
    cam1.SetClippingRange(0.0475572, 2.37786);
    cam1.SetFocalPoint(0.052665, -0.129454, -0.0573973);
    cam1.SetPosition(0.327637, -0.116299, -0.256418);
    cam1.SetViewUp(-0.0225386, 0.999137, 0.034901);
    renWin.GetRenderer().SetActiveCamera(cam1);
    // Place renWin in the center of this panel
    setLayout(new BorderLayout());
    add(renWin, BorderLayout.CENTER);
////////////////////////////////////////////////////////////
 
I didnot know where the error is.
thanks.
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061213/d3ae1807/attachment.htm>


More information about the vtkusers mailing list