<div dir="ltr">Dear Jim<div><br></div><div>it didn't affect , do u have any suggestion or a way to reach my goal </div><div><br></div><div>Best regards <br><br><div class="gmail_quote">On Sat, Aug 21, 2010 at 4:44 PM, Jim Peterson <span dir="ltr"><<a href="mailto:jimcp@cox.net">jimcp@cox.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Ali,<br>
I think you need to invoke apd.Modified() before apd.Update() to get the changes incorporated in the pipeline.<br>
<br>
Hope that helps,<br>
Jim.<br>
<br>
Ali Habib wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">
I select part of vtkpolydata using vtkboxwidget and vtkclippolydata , then I want to change (do displacement) to the points be selected so I search for the points in the source polydata and change its position<br>
<br>
my goal is to for example deform vtkpolydata by stretch certain part , the problem is that the shape doesn't change <br>
below is the code any suggestion please <br>
static vtkLODActor selectActor;<br>
static vtkLODActor maceActor;<br>
static vtkPlanes planes;<br>
static vtkClipPolyData clipper;<br>
static vtkAppendPolyData apd;<br>
<br>
static double[] center_Before =new double[3];<br>
static double[] center_After = new double[3];<br>
static void Main(string[] args)<br>
{<br>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
//////////////////////////////////////////////////////// the core of cutting tool /////////////////////////////////////////////////////////////<br>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
// Create a mace out of filters.<br>
vtkSphereSource sphere = new vtkSphereSource();<br>
vtkConeSource cone = new vtkConeSource();<br>
vtkGlyph3D glyph = new vtkGlyph3D();<br>
glyph.SetInput(sphere.GetOutput());<br>
glyph.SetSource(cone.GetOutput());<br>
glyph.SetVectorModeToUseNormal();<br>
glyph.SetScaleModeToScaleByVector();<br>
glyph.SetScaleFactor(0.25);<br>
<br>
// The sphere and spikes are appended into a single polydata. This just<br>
// makes things simpler to manage.<br>
apd = new vtkAppendPolyData();<br>
apd.AddInput(glyph.GetOutput());<br>
apd.AddInput(sphere.GetOutput());<br>
<br>
vtkPolyDataMapper maceMapper = new vtkPolyDataMapper();<br>
maceMapper.SetInput(apd.GetOutput());<br>
maceActor = new vtkLODActor();<br>
maceActor.SetMapper(maceMapper);<br>
maceActor.GetProperty().SetColor(1, 0, 0);<br>
maceActor.VisibilityOn();<br>
<br>
// This portion of the code clips the mace with the vtkPlanes implicit<br>
// function. The clipped region is colored green.<br>
planes = new vtkPlanes();<br>
clipper = new vtkClipPolyData();<br>
clipper.SetInput(apd.GetOutput());<br>
clipper.SetClipFunction(planes);<br>
clipper.InsideOutOff();<br>
<br>
vtkPolyDataMapper selectMapper = new vtkPolyDataMapper();<br>
selectMapper.SetInput(clipper.GetOutput());<br>
selectActor = new vtkLODActor();<br>
selectActor.SetMapper(selectMapper);<br>
selectActor.GetProperty().SetColor(0, 1, 0);<br>
selectActor.VisibilityOff();<br>
selectActor.SetScale(1.01, 1.01, 1.01);<br>
<br>
// Create the RenderWindow, Renderer and both Actors<br>
vtkRenderer ren = new vtkRenderer();<br>
vtkRenderWindow renWin = new vtkRenderWindow();<br>
renWin.AddRenderer(ren);<br>
<br>
vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();<br>
iren.SetRenderWindow(renWin);<br>
<br>
//The SetInteractor method is how 3D widgets are associated with the<br>
//render window interactor. Internally, SetInteractor sets up a bunch<br>
//of callbacks using the Command/Observer mechanism (AddObserver()).<br>
vtkBoxWidget boxWidget = new vtkBoxWidget();<br>
boxWidget.SetInteractor(iren);<br>
boxWidget.SetPlaceFactor(1.25);<br>
boxWidget.TranslationEnabledOn();<br>
ren.AddActor(maceActor);<br>
ren.AddActor(selectActor);<br>
<br>
//Add the actors to the renderer, set the background and size<br>
ren.SetBackground(0.1, 0.2, 0.4);<br>
// renWin.SetSize(300, 300);<br>
<br>
// Place the interactor initially. The input to a 3D widget is used to<br>
// initially position and scale the widget. The "EndInteractionEvent" is<br>
// observed which invokes the SelectPolygons callback.<br>
boxWidget.SetInput(glyph.GetOutput());<br>
boxWidget.PlaceWidget();<br>
boxWidget.AddObserver((uint)vtk.EventIds.InteractionEvent, new vtk.vtkDotNetCallback(InteractionEvent));<br>
boxWidget.AddObserver((uint)vtk.EventIds.EndInteractionEvent, new vtk.vtkDotNetCallback(EndInteractionEvent));<br>
<br>
boxWidget.On();<br>
iren.Initialize();<br>
renWin.Render();<br>
iren.Start();<br>
}<br>
public static void InteractionEvent(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)<br>
{<br>
vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);<br>
widget.GetPlanes(planes);<br>
selectActor.VisibilityOn();<br>
<br>
<br>
vtkPolyData before = new vtkPolyData();<br>
widget.GetPolyData(before);<br>
center_Before = GetBoundsCenter(before.GetBounds());<br>
<br>
//maceActor.VisibilityOff();<br>
///////////// Test writting /////////////////////////////////////////////<br>
//Write the file<br>
<br>
/*vtkXMLPolyDataWriter writer = new vtkXMLPolyDataWriter ();<br>
writer.SetInputConnection(clipper.GetOutputPort());<br>
writer.SetFileName("disk.vtp");<br>
writer.Write();*/<br>
<br>
<br>
}<br>
public static void EndInteractionEvent(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)<br>
{<br>
vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);<br>
vtkPolyData after = new vtkPolyData();<br>
widget.GetPolyData(after);<br>
center_After = GetBoundsCenter(after.GetBounds());<br>
<br>
ModifyData();<br>
<br>
<br>
}<br>
<br>
private static double[] GetBoundsCenter(double[] bounds)<br>
{<br>
double[] center = new double[3];<br>
<br>
center[0] = (bounds[0] + bounds[1]) / 2.0;<br>
center[1] = (bounds[2] + bounds[3]) / 2.0;<br>
center[2] = (bounds[4] + bounds[5]) / 2.0;<br>
<br>
return center;<br>
}<br>
<br>
private static void ModifyData()<br>
{<br>
double[] Displacement = { center_After[0] - center_Before[0], center_After[1] - center_Before[1], center_After[2] - center_Before[2] };<br>
<br>
int NoOfPoints = clipper.GetOutput().GetNumberOfPoints();<br>
<br>
for (int i = 0; i < NoOfPoints;i++ )<br>
{ <br>
/////////////////////////////////////////////////////////////////////////////////////<br>
apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[0] =<br>
apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[0] + Displacement[0];<br>
<br>
apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[1] =<br>
apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[1] + Displacement[1];<br>
<br>
apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[2] =<br>
apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[2] + Displacement[2];<br>
<br>
apd.Update();<br>
<br>
}<br>
}<br></div></div>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br>
</blockquote>
<br>
</blockquote></div><br></div></div>