[vtkusers] Re: 2d image extrude into 3d object

Chris Kennedy vtk072404 at thinkpeak.com
Wed Jul 28 13:48:26 EDT 2004


hi Goodwin,
Thanks for the reply, although you've confused me with what I should do 
with my data. 

I reduced all the images down to 10% of their original size. Now I'm 
using this tcl script, basically going from reader directly into 
marching cubes. I get some geometry in my Viz window, cool!.

What are the commands to cap the geometry? ie, for each x-section that 
is extruded into 3d I want the not only the surfaces representing the Z 
direction walls, but also the surfaces in the x-section plane.

# A script to reconstruct surfaces from segmented images
# Adapted from Bill Lorensen's segmented16.tcl, 
http://www.crd.ge.com/~lorensen/seg12/
# Goodwin Lawlor, 2004

package require vtk
wm withdraw .
wm protocol . WM_DELETE_WINDOW {vtkCommand DeleteAllObjects; exit}


vtkPNGReader reader
    reader SetFilePrefix "./png"
    reader SetFilePattern %s.%d
    reader SetDataExtent 0 255 0 255 1 9
    reader SetDataScalarTypeToShort
    # data is in acsii, space delimited format
    # this data mask is just a trick to cut out the space.
    #reader SetDataMask 0x00FF
    reader SetDataByteOrderToLittleEndian
    reader SetDataSpacing 1.0 1.0 10.0
    # decimator complains so...
    #reader GlobalWarningDisplayOff


vtkImageThreshold selectTissue
    selectTissue SetInput [reader GetOutput]
    selectTissue SetInValue 255
    selectTissue SetOutValue 0
    selectTissue ReplaceInOn
    selectTissue ReplaceOutOn

vtkImageShrink3D shrinker
     #shrinker SetInput [selectTissue GetOutput]
     shrinker SetInput [reader GetOutput]
     shrinker SetShrinkFactors 1 1 1
     shrinker AveragingOn

vtkImageGaussianSmooth gaussian
    gaussian SetInput [shrinker GetOutput]
    gaussian SetDimensionality 3
    gaussian SetStandardDeviation  0 0 0


vtkMarchingCubes mcubes;
    #mcubes SetInput [gaussian GetOutput]
    #mcubes SetInput [shrinker GetOutput]
    mcubes SetInput [reader GetOutput]
    mcubes ComputeScalarsOff
    mcubes ComputeGradientsOff
    mcubes ComputeNormalsOff
    mcubes SetValue 0 127.5

vtkDecimate decimator
    decimator SetInput [mcubes GetOutput]
    decimator SetInitialFeatureAngle 60
    decimator SetMaximumIterations 5
    decimator SetMaximumSubIterations 0
    decimator PreserveEdgesOn
    decimator SetMaximumError 1.0
    decimator SetTargetReduction 0.95
    decimator SetInitialError 0.0002
    decimator SetErrorIncrement 0.0002

vtkWindowedSincPolyDataFilter smoother
    smoother SetInput [decimator GetOutput]
    smoother SetNumberOfIterations 20
    smoother SetPassBand 0.1
    smoother SetFeatureAngle 60
    smoother FeatureEdgeSmoothingOff
    smoother NonManifoldSmoothingOff;

vtkPolyDataNormals normals
    #normals SetInput [smoother GetOutput]
    normals SetInput [decimator GetOutput]
    normals SetFeatureAngle 60

vtkStripper stripper
    stripper SetInput [normals GetOutput]

vtkXMLPolyDataWriter writer
    writer SetInput [stripper GetOutput]

# Write and render the models

vtkRenderer ren
vtkMath math
set tissue 0
#foreach tissue {0 } {
# write the models to file
    #selectTissue ThresholdBetween $tissue $tissue
    #reader.Update()
    writer SetFileName model$tissue.vtp
    writer Write

#create readers, mappers, and actors
vtkXMLPolyDataReader reader$tissue
    reader$tissue SetFileName model$tissue.vtp

vtkPolyDataMapper mapper$tissue
    mapper$tissue SetInput [reader$tissue GetOutput]

vtkProperty prop$tissue
    prop$tissue SetDiffuseColor [math Random] [math Random] [math Random]
    prop$tissue SetSpecularPower 50
    prop$tissue SetSpecular .5
    prop$tissue SetDiffuse .8

vtkActor actor$tissue
    actor$tissue SetMapper mapper$tissue
    actor$tissue SetProperty prop$tissue

ren AddActor actor$tissue
#}

vtkRenderWindow renWin
    renWin AddRenderer ren
    renWin SetSize 600 600
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin
    iren Initialize
       
   


thanks

Goodwin Lawlor wrote:

>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
>>
>>    
>>
>
>
>
>_______________________________________________
>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
>
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040728/0493a2bb/attachment.htm>


More information about the vtkusers mailing list