[vtkusers] Re: 2d image extrude into 3d object
Goodwin Lawlor
goodwin.lawlor at ucd.ie
Wed Jul 28 12:32:55 EDT 2004
Hi Chris,
Your images are already binary (black and white) so you dont need
vtkImageThreshold. In segemented.tcl you should use vtkPNGReader. Try to get
your data into either one 3D image or multiple 2D (single) cross-sections.
hth
Goodwin
"Chris Kennedy" <vtk072404 at thinkpeak.com> wrote in message
news:4107C8F4.8010404 at thinkpeak.com...
> hi,
> I'd like to take several 2d images that represent cross-sections at
> different elevations through an object. I have PNG files that are black
> and white, with black being the "metal" content in the object. I only
> want to take the black pixels and extrude them some distance. I have
> several different X-sections and I will take them into GoFly for some
> assembly/collision work.
>
> Each x-section is standalone, in that it doesn't have to be averaged
> into the x-section above or below it.
>
> I've been trying to follow the seg12 example
> http://www.crd.ge.com/~lorensen/seg12/ using python instead. I have vtk
> recompiled with the required patented methods also. I get an error
>
> ERROR: In C:\apps\VTK42\Patented\vtkMarchingCubes.cxx, line 420
> vtkMarchingCubes (0x01E03640): Cannot contour data of dimension != 3
>
> thus I'm not applying a proper filter to the image.
> I suspect in I need to specify additional operations to get the image
> into a proper 3d format. I don't understand what input the
> SetVectorInput option needs, for instance or if it is applicable here.
>
> At http://www.thinkpeak.com/cust/vtk/ I have sample png files and 2 tcl
> files. The tcl files are similiar to what Goodwin posted to help Vidya,
> but I haven't been able to get that configured properly either...
>
> here is the python code:
>
> #!/usr/bin/env python
>
>
> fname='m10'
> slice_order='is'
> #file_pattern=%s.png
> #study=.
> pixel_size=1.0
> spacing=100.0
> start_slice=10
> end_slice=19
> zmax=end_slice-start_slice
> #voi="0=255=0=255=0=$zmax"
> sample_rate="1 1 1"
> decimate_reduction=.95
> decimate_iterations=5
> decimate_error=.0002
> decimate_error_increment=.0002
> decimate_angle=60
> smooth_iterations=0
> smooth_expand=-.34
> smooth_shrink=.33
> smooth_factor=.1
> smooth_angle=60
> feature_angle=60
> gaussian_standard_deviation=2
>
> import vtk
> from vtk.util.misc import vtkGetDataRoot
> VTK_DATA_ROOT = vtkGetDataRoot()
>
> # Create the image
> reader = vtk.vtkPNGReader()
> reader.SetFilePrefix("./png")
> reader.SetFilePattern('%s.%d')
> reader.SetDataSpacing(0.8, 0.8, 1.5)
> #reader.SetFileName(VTK_DATA_ROOT + "/Data/fran_cut.png")
> reader.SetDataByteOrderToLittleEndian()
> reader.SetDataExtent(0,255,0,255,1,9,)
> reader.SetDataScalarTypeToShort()
> reader.SetDataSpacing(1, 1, 100)
> #reader.SetDataMask(0x7fff)
>
> #
> # select the metal, two rgb values in png file:
> # 255 - white
> # 0 - black
> selectMetal=vtk.vtkImageThreshold()
> selectMetal.ReleaseDataFlagOff()
> selectMetal.ReplaceInOn()
> selectMetal.ReplaceOutOn()
> selectMetal.ThresholdBetween(0,0)
> selectMetal.SetInValue(0)
> selectMetal.SetOutValue(0)
> selectMetal.SetInput(reader.GetOutput())
> #selectMetal.Print() # what's proper syntax?
>
>
> # I don't think I need this action...
> gaussian=vtk.vtkImageGaussianSmooth()
> gaussian.SetDimensionality(3)
> gaussian.SetStandardDeviation(gaussian_standard_deviation)
> gaussian.SetInput(selectMetal.GetOutput())
> #gaussian.Print() # what's the syntax?
>
> toStructuredPoints=vtk.vtkImageToStructuredPoints()
> toStructuredPoints.SetInput(gaussian.GetOutput())
> #toStructuredPoints.SetVectorInput(10)
> # need more processing here... ie, how to specify thickness?
>
> mcubes=vtk.vtkMarchingCubes()
> mcubes.SetInput(toStructuredPoints.GetOutput())
> mcubes.ComputeScalarsOff()
> mcubes.ComputeGradientsOff()
> mcubes.ComputeNormalsOff()
> mcubes.SetValue(0,0)
> #mcubes.GetOutput()
>
> decimator=vtk.vtkDecimate()
> decimator.SetInput(mcubes.GetOutput())
> decimator.SetInitialFeatureAngle(decimate_angle)
> decimator.SetMaximumIterations(decimate_iterations)
> decimator.SetMaximumSubIterations(0)
> decimator.PreserveEdgesOn()
> decimator.SetMaximumError(1)
> decimator.SetTargetReduction(decimate_reduction)
> decimator.SetInitialError(decimate_error)
> decimator.SetErrorIncrement(decimate_error_increment)
>
> smoother=vtk.vtkSmoothPolyDataFilter()
> smoother.SetInput(decimator.GetOutput())
> smoother.SetNumberOfIterations(smooth_iterations)
> smoother.SetRelaxationFactor(smooth_factor)
> smoother.SetFeatureAngle(smooth_angle)
> smoother.FeatureEdgeSmoothingOff()
> smoother.BoundarySmoothingOff()
> smoother.SetConvergence(0)
>
> normals=vtk.vtkPolyDataNormals()
> normals.SetInput(smoother.GetOutput())
> normals.SetFeatureAngle(feature_angle)
>
> stripper=vtk.vtkStripper()
> stripper.SetInput(normals.GetOutput())
>
> writer=vtk.vtkPolyDataWriter()
> writer.SetInput(stripper.GetOutput())
> writer.SetFileName(fname+'.vtk')
> writer.SetFileType(2)
>
> mapOutline = vtk.vtkPolyDataMapper()
> mapOutline.SetInput(stripper.GetOutput())
> outline = vtk.vtkActor()
> outline.SetMapper(mapOutline)
> outline.GetProperty().SetColor(0, 0, 0)
>
>
> reader.Update()
> #shiftScale.Update()
> selectMetal.Update()
> #wpng.Update()
> gaussian.Update()
> toStructuredPoints.Update()
> #mcubes.Update()
> #decimator.Update()
> #smoother.Update()
> #normals.Update()
> #stripper.Update()
>
>
> aCamera = vtk.vtkCamera()
> aCamera.SetViewUp(0, 0, -1)
> aCamera.SetPosition(1, 1, 1)
> aCamera.SetFocalPoint(0, 0, 0)
> aCamera.ComputeViewPlaneNormal()
>
>
>
> ia = vtk.vtkImageActor()
> #ia.SetInput(shiftScale.GetOutput())
> ia.SetInput(selectMetal.GetOutput())
>
> # Create the RenderWindow, Renderer and both Actors
> ren = vtk.vtkRenderer()
> renWin = vtk.vtkRenderWindow()
> renWin.AddRenderer(ren)
> iren = vtk.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
> iren.Initialize()
>
> # Actors are added to the renderer. An initial camera view is created.
> # The Dolly() method moves the camera towards the FocalPoint,
> # thereby enlarging the image.
> ren.AddActor(outline)
> ren.SetActiveCamera(aCamera)
> ren.ResetCamera()
> aCamera.Dolly(1.5)
>
> # Add the actors to the renderer, set the background and size
> ren.AddActor(ia)
> ren.SetBackground(0.14, 0.2, 0.4)
> renWin.SetSize(300, 300)
>
> renWin.Render()
>
> cam1 = ren.GetActiveCamera()
>
> ren.ResetCameraClippingRange()
>
> renWin.Render()
> iren.Start()
>
>
> =======================================================
>
> How do I select pixels of a certain value from the image?
> What processing needs to be done so that the data can be operated on by
> MarchingCubes?
>
> I would like to get an assembly of these stacked images (converted into
> 3d objects), and then do additional geometry definitions and then take
> it into GoFly.
> Extensions I'd like to make to this:
> - each image x-section may have a unique thickness
> - the x-section in image png.9 actually represent spheres, not
> cylinders.
> - I want to define additional rectangular volumes, and spline tubes
> and have this in the assembly file that is generated also
> - names (metadata) assigned here and carried forward into GoFly
>
> Thanks for any assistance.
>
> Chris Kennedy
> Think Peak, Inc.
>
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list