[vtkusers] 3D rendering with Skin & colouring
Gururajan
gururajan.r at raster.in
Wed Aug 12 08:59:10 EDT 2009
Please any one guide me , how i can add skin to my 3d image.
The 3d image comes with bone part, not with the skin.
I have pasted below my code in java
Thanks
Guru
vtkDICOMImageReader dicomreader = new vtkDICOMImageReader();
dicomreader.SetDirectoryName("/home/gururaj/MANIX/43a297f8");
dicomreader.SetFileNameSliceOffset(1);
dicomreader.SetFileNameSliceSpacing(1);
dicomreader.SetDataExtent(0,511,0,511,0,224);
dicomreader.SetDataSpacing(360.0/512,360.0/512,1.0);
dicomreader.SetDataOrigin(0,0,0);
dicomreader.Update();
vtkMarchingCubes surfaceExtractor = new vtkMarchingCubes();
surfaceExtractor.SetInput(dicomreader.GetOutput());
surfaceExtractor.ComputeNormalsOn();
surfaceExtractor.SetValue(0, 1250);
surfaceExtractor.Update();
vtkPolyDataNormals normals = new vtkPolyDataNormals();
normals.SetInput(surfaceExtractor.GetOutput());
normals.FlipNormalsOn();
vtkPolyDataWriter pdw = new vtkPolyDataWriter();
pdw.SetInput(normals.GetOutput());
pdw .SetFileName("/home/gururaj/eclipse
Project/SimpleVTK/SimpleVtk/CardiacCT/Dicom.vtk");
pdw.Write();
// 3d Construction
String strfilename = new String();
strfilename = "/home/gururaj/eclipse
Project/SimpleVTK/SimpleVtk/CardiacCT/Dicom.vtk";
vtkPolyDataReader polyReader = new vtkPolyDataReader();
polyReader.SetFileName(strfilename);
polyReader.Update();
vtkPolyData polyData = new vtkPolyData();
polyData.DeepCopy(polyReader.GetOutput());
vtkPolyDataMapper polyMapper = new vtkPolyDataMapper();
polyMapper.SetInput(polyData);
polyMapper.Update();
polyMapper.ScalarVisibilityOff();
//for skin and bone Diagram
//For setting Bone Colour
vtkGeometryFilter geovolumebone = new vtkGeometryFilter();
geovolumebone.SetInput(polyReader.GetOutput());
vtkPolyDataMapper geobonemapper = new vtkPolyDataMapper();
geobonemapper.SetInput(geovolumebone.GetOutput());
geobonemapper.ScalarVisibilityOff();
vtkLODActor boneActor = new vtkLODActor();
boneActor.SetNumberOfCloudPoints(100000);
boneActor.SetMapper(geobonemapper);
boneActor.GetProperty().SetColor(1,1,1);
boneActor.GetProperty().SetOpacity(3.0);
boneActor.GetProperty().SetDiffuse(0.75);
boneActor.GetProperty().SetSpecular(0.75);
//For setting Bone Colour
//For setting Skin Colour
vtkMarchingCubes skin = new vtkMarchingCubes();
skin.SetInput(dicomreader.GetOutput());
skin.SetValue(0, 760);
skin.ComputeNormalsOn();
vtkGeometryFilter geovolumeSkin = new vtkGeometryFilter();
geovolumeSkin.SetInput(skin.GetOutput());
vtkPolyDataMapper skinmapper = new vtkPolyDataMapper();
skinmapper.SetInput(geovolumeSkin.GetOutput());
skinmapper.ScalarVisibilityOff();
vtkLODActor actorskin = new vtkLODActor();
actorskin.SetNumberOfCloudPoints(100000);
actorskin.SetMapper(skinmapper);
//actorskin.GetProperty().SetColor(1, 0.547237, 0.319073);
actorskin.GetProperty().SetColor(100, 67, 67);
actorskin.GetProperty().SetOpacity( 0.5 );
//For setting Skin Colour
//for skin and bone Diagram
vtkRenderer render = new vtkRenderer();
vtkRenderWindow renwindow = new vtkRenderWindow();
renwindow.AddRenderer(render);
vtkRenderWindowInteractor renintec = new
vtkRenderWindowInteractor();
renintec.SetRenderWindow(renwindow);
render.AddActor(actorskin);
//render.AddActor(boneActor);
render.SetBackground(0, 0, 0);
renwindow.BordersOff();
renwindow.FullScreenOn();
renwindow.SetSize(500, 500);
renwindow.Render();
render.ResetCamera();
renintec.Start();
More information about the vtkusers
mailing list