[vtkusers] Hot to .mhd file for 3d reconstruction images
kenichiro yoshimi
rccm.kyoshimi at gmail.com
Sun Jun 24 00:24:58 EDT 2018
Hello,
You have only to specify a file name in executing the program:
> python program.py file-name
Best,
2018-06-24 9:13 GMT+09:00 blue <ustungozde at gmail.com>:
> Hello;
> I have a dataset for 3d reconstructions and I have this code:
> *
> import vtk
>
>
> def main():
> colors = vtk.vtkNamedColors()
>
> fileName = get_program_parameters()
>
> colors.SetColor("BkgColor", [51, 77, 102, 255])
>
> ren = vtk.vtkRenderer()
> renWin = vtk.vtkRenderWindow()
> renWin.AddRenderer(ren)
> iren = vtk.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
>
> reader = vtk.vtkMetaImageReader()
> reader.SetFileName(fileName)
>
> volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()
> volumeMapper.SetInputConnection(reader.GetOutputPort())
>
> volumeColor = vtk.vtkColorTransferFunction()
> volumeColor.AddRGBPoint(0, 0.0, 0.0, 0.0)
> volumeColor.AddRGBPoint(500, 1.0, 0.5, 0.3)
> volumeColor.AddRGBPoint(1000, 1.0, 0.5, 0.3)
> volumeColor.AddRGBPoint(1150, 1.0, 1.0, 0.9)
>
>
> volumeScalarOpacity = vtk.vtkPiecewiseFunction()
> volumeScalarOpacity.AddPoint(0, 0.00)
> volumeScalarOpacity.AddPoint(500, 0.15)
> volumeScalarOpacity.AddPoint(1000, 0.15)
> volumeScalarOpacity.AddPoint(1150, 0.85)
>
>
> volumeGradientOpacity = vtk.vtkPiecewiseFunction()
> volumeGradientOpacity.AddPoint(0, 0.0)
> volumeGradientOpacity.AddPoint(90, 0.5)
> volumeGradientOpacity.AddPoint(100, 1.0)
>
>
> volumeProperty = vtk.vtkVolumeProperty()
> volumeProperty.SetColor(volumeColor)
> volumeProperty.SetScalarOpacity(volumeScalarOpacity)
> volumeProperty.SetGradientOpacity(volumeGradientOpacity)
> volumeProperty.SetInterpolationTypeToLinear()
> volumeProperty.ShadeOn()
> volumeProperty.SetAmbient(0.4)
> volumeProperty.SetDiffuse(0.6)
> volumeProperty.SetSpecular(0.2)
>
>
> volume = vtk.vtkVolume()
> volume.SetMapper(volumeMapper)
> volume.SetProperty(volumeProperty)
>
> ren.AddViewProp(volume)
>
> camera = ren.GetActiveCamera()
> c = volume.GetCenter()
> camera.SetViewUp(0, 0, -1)
> camera.SetPosition(c[0], c[1] - 400, c[2])
> camera.SetFocalPoint(c[0], c[1], c[2])
> camera.Azimuth(30.0)
> camera.Elevation(30.0)
>
> ren.SetBackground(colors.GetColor3d("BkgColor"))
>
> renWin.SetSize(640, 480)
>
> iren.Start()
>
>
> def get_program_parameters():
> import argparse
> description = 'Read a volume dataset and displays it via volume
> rendering.'
> epilogue = '''
> Derived from VTK/Examples/Cxx/Medical4.cxx
> '''
> parser = argparse.ArgumentParser(description=description,
> epilog=epilogue,
>
> formatter_class=argparse.RawDescriptionHelpFormatter)
> parser.add_argument('filename', help='FullHead.mhd.')
> args = parser.parse_args()
> return args.filename
>
>
> if __name__ == '__main__':
> main()
> *
>
> This code including .mhd file How to convert my dataset .mhd file with vtk
> for this code
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list