<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
hi Goodwin,<br>
Thanks for the reply, although you've confused me with what I should do
with my data.&nbsp; <br>
<br>
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!. <br>
<br>
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. <br>
<br>
# A script to reconstruct surfaces from segmented images<br>
# Adapted from Bill Lorensen's segmented16.tcl,
<a class="moz-txt-link-freetext" href="http://www.crd.ge.com/~lorensen/seg12/">http://www.crd.ge.com/~lorensen/seg12/</a><br>
# Goodwin Lawlor, 2004<br>
<br>
package require vtk<br>
wm withdraw .<br>
wm protocol . WM_DELETE_WINDOW {vtkCommand DeleteAllObjects; exit}<br>
<br>
<br>
vtkPNGReader reader<br>
&nbsp;&nbsp;&nbsp; reader SetFilePrefix "./png"<br>
&nbsp;&nbsp;&nbsp; reader SetFilePattern %s.%d<br>
&nbsp;&nbsp;&nbsp; reader SetDataExtent 0 255 0 255 1 9<br>
&nbsp;&nbsp;&nbsp; reader SetDataScalarTypeToShort<br>
&nbsp;&nbsp;&nbsp; # data is in acsii, space delimited format<br>
&nbsp;&nbsp;&nbsp; # this data mask is just a trick to cut out the space.<br>
&nbsp;&nbsp;&nbsp; #reader SetDataMask 0x00FF<br>
&nbsp;&nbsp;&nbsp; reader SetDataByteOrderToLittleEndian<br>
&nbsp;&nbsp;&nbsp; reader SetDataSpacing 1.0 1.0 10.0<br>
&nbsp;&nbsp;&nbsp; # decimator complains so...<br>
&nbsp;&nbsp;&nbsp; #reader GlobalWarningDisplayOff<br>
<br>
<br>
vtkImageThreshold selectTissue<br>
&nbsp;&nbsp;&nbsp; selectTissue SetInput [reader GetOutput]<br>
&nbsp;&nbsp;&nbsp; selectTissue SetInValue 255<br>
&nbsp;&nbsp;&nbsp; selectTissue SetOutValue 0<br>
&nbsp;&nbsp;&nbsp; selectTissue ReplaceInOn<br>
&nbsp;&nbsp;&nbsp; selectTissue ReplaceOutOn<br>
<br>
vtkImageShrink3D shrinker<br>
&nbsp;&nbsp;&nbsp;&nbsp; #shrinker SetInput [selectTissue GetOutput]<br>
&nbsp;&nbsp;&nbsp;&nbsp; shrinker SetInput [reader GetOutput]<br>
&nbsp;&nbsp;&nbsp;&nbsp; shrinker SetShrinkFactors 1 1 1<br>
&nbsp;&nbsp;&nbsp;&nbsp; shrinker AveragingOn<br>
<br>
vtkImageGaussianSmooth gaussian<br>
&nbsp;&nbsp;&nbsp; gaussian SetInput [shrinker GetOutput]<br>
&nbsp;&nbsp;&nbsp; gaussian SetDimensionality 3<br>
&nbsp;&nbsp;&nbsp; gaussian SetStandardDeviation&nbsp; 0 0 0<br>
<br>
<br>
vtkMarchingCubes mcubes;<br>
&nbsp;&nbsp;&nbsp; #mcubes SetInput [gaussian GetOutput]<br>
&nbsp;&nbsp;&nbsp; #mcubes SetInput [shrinker GetOutput]<br>
&nbsp;&nbsp;&nbsp; mcubes SetInput [reader GetOutput]<br>
&nbsp;&nbsp;&nbsp; mcubes ComputeScalarsOff<br>
&nbsp;&nbsp;&nbsp; mcubes ComputeGradientsOff<br>
&nbsp;&nbsp;&nbsp; mcubes ComputeNormalsOff<br>
&nbsp;&nbsp;&nbsp; mcubes SetValue 0 127.5<br>
<br>
vtkDecimate decimator<br>
&nbsp;&nbsp;&nbsp; decimator SetInput [mcubes GetOutput]<br>
&nbsp;&nbsp;&nbsp; decimator SetInitialFeatureAngle 60<br>
&nbsp;&nbsp;&nbsp; decimator SetMaximumIterations 5<br>
&nbsp;&nbsp;&nbsp; decimator SetMaximumSubIterations 0<br>
&nbsp;&nbsp;&nbsp; decimator PreserveEdgesOn<br>
&nbsp;&nbsp;&nbsp; decimator SetMaximumError 1.0<br>
&nbsp;&nbsp;&nbsp; decimator SetTargetReduction 0.95<br>
&nbsp;&nbsp;&nbsp; decimator SetInitialError 0.0002<br>
&nbsp;&nbsp;&nbsp; decimator SetErrorIncrement 0.0002<br>
<br>
vtkWindowedSincPolyDataFilter smoother<br>
&nbsp;&nbsp;&nbsp; smoother SetInput [decimator GetOutput]<br>
&nbsp;&nbsp;&nbsp; smoother SetNumberOfIterations 20<br>
&nbsp;&nbsp;&nbsp; smoother SetPassBand 0.1<br>
&nbsp;&nbsp;&nbsp; smoother SetFeatureAngle 60<br>
&nbsp;&nbsp;&nbsp; smoother FeatureEdgeSmoothingOff<br>
&nbsp;&nbsp;&nbsp; smoother NonManifoldSmoothingOff;<br>
<br>
vtkPolyDataNormals normals<br>
&nbsp;&nbsp;&nbsp; #normals SetInput [smoother GetOutput]<br>
&nbsp;&nbsp;&nbsp; normals SetInput [decimator GetOutput]<br>
&nbsp;&nbsp;&nbsp; normals SetFeatureAngle 60<br>
<br>
vtkStripper stripper<br>
&nbsp;&nbsp;&nbsp; stripper SetInput [normals GetOutput]<br>
<br>
vtkXMLPolyDataWriter writer<br>
&nbsp;&nbsp;&nbsp; writer SetInput [stripper GetOutput]<br>
<br>
# Write and render the models<br>
<br>
vtkRenderer ren<br>
vtkMath math<br>
set tissue 0<br>
#foreach tissue {0 } {<br>
# write the models to file<br>
&nbsp;&nbsp;&nbsp; #selectTissue ThresholdBetween $tissue $tissue<br>
&nbsp;&nbsp;&nbsp; #reader.Update()<br>
&nbsp;&nbsp;&nbsp; writer SetFileName model$tissue.vtp<br>
&nbsp;&nbsp;&nbsp; writer Write<br>
<br>
#create readers, mappers, and actors<br>
vtkXMLPolyDataReader reader$tissue<br>
&nbsp;&nbsp;&nbsp; reader$tissue SetFileName model$tissue.vtp<br>
<br>
vtkPolyDataMapper mapper$tissue<br>
&nbsp;&nbsp;&nbsp; mapper$tissue SetInput [reader$tissue GetOutput]<br>
<br>
vtkProperty prop$tissue<br>
&nbsp;&nbsp;&nbsp; prop$tissue SetDiffuseColor [math Random] [math Random] [math
Random]<br>
&nbsp;&nbsp;&nbsp; prop$tissue SetSpecularPower 50<br>
&nbsp;&nbsp;&nbsp; prop$tissue SetSpecular .5<br>
&nbsp;&nbsp;&nbsp; prop$tissue SetDiffuse .8<br>
<br>
vtkActor actor$tissue<br>
&nbsp;&nbsp;&nbsp; actor$tissue SetMapper mapper$tissue<br>
&nbsp;&nbsp;&nbsp; actor$tissue SetProperty prop$tissue<br>
<br>
ren AddActor actor$tissue<br>
#}<br>
<br>
vtkRenderWindow renWin<br>
&nbsp;&nbsp;&nbsp; renWin AddRenderer ren<br>
&nbsp;&nbsp;&nbsp; renWin SetSize 600 600<br>
vtkRenderWindowInteractor iren<br>
&nbsp;&nbsp;&nbsp; iren SetRenderWindow renWin<br>
&nbsp;&nbsp;&nbsp; iren Initialize<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; <br>
<br>
<br>
thanks<br>
<br>
Goodwin Lawlor wrote:<br>
<blockquote type="cite" cite="midce8kfb$249$1@sea.gmane.org">
  <pre wrap="">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" <a class="moz-txt-link-rfc2396E" href="mailto:vtk072404@thinkpeak.com">&lt;vtk072404@thinkpeak.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:4107C8F4.8010404@thinkpeak.com">news:4107C8F4.8010404@thinkpeak.com</a>...
  </pre>
  <blockquote type="cite">
    <pre wrap="">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
<a class="moz-txt-link-freetext" href="http://www.crd.ge.com/~lorensen/seg12/">http://www.crd.ge.com/~lorensen/seg12/</a> 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 <a class="moz-txt-link-freetext" href="http://www.thinkpeak.com/cust/vtk/">http://www.thinkpeak.com/cust/vtk/</a> 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:
    </pre>
  </blockquote>
  <pre wrap=""><!----><a class="moz-txt-link-rfc2396E" href="http://public.kitware.com/cgi-bin/vtkfaq">&lt;http://public.kitware.com/cgi-bin/vtkfaq&gt;</a>
  </pre>
  <blockquote type="cite">
    <pre wrap="">Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>

    </pre>
  </blockquote>
  <pre wrap=""><!---->


_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at: <a class="moz-txt-link-rfc2396E" href="http://public.kitware.com/cgi-bin/vtkfaq">&lt;http://public.kitware.com/cgi-bin/vtkfaq&gt;</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>

  </pre>
</blockquote>
</body>
</html>