<div>Hi Dongqing,</div>
<div> </div>
<div>I know I'm getting bck to you with a bit of delay but I'm writting my thesis now a days and I'm pretty busy with that. I still don't know what is causing the problem since I haven't seen your code but here is a sample code for modifying a polydata. Note that this code is not very effecient and I've pasted it here only as an example:
</div>
<div> </div>
<div><font color="#0000ff" size="2">#include</font><font size="2"> </font><font color="#a31515" size="2">"vtkPolyDataMapper.h"<br></font><font color="#0000ff" size="2">#include</font><font size="2"> </font><font color="#a31515" size="2">
"vtkRenderWindow.h"<br></font><font color="#0000ff" size="2">#include</font><font size="2"> </font><font color="#a31515" size="2">"vtkActor.h"<br></font><font color="#0000ff" size="2">#include</font><font size="2">
</font><font color="#a31515" size="2">"vtkRenderer.h"<br></font><font color="#0000ff" size="2">#include</font><font size="2"> </font><font color="#a31515" size="2">"vtkRenderWindowInteractor.h"<br></font>
<font color="#0000ff" size="2">#include</font><font size="2"> </font><font color="#a31515" size="2">"vtkInteractorStyleTrackballCamera.h"<br></font><font color="#0000ff" size="2">#include</font><font size="2"> </font>
<font color="#a31515" size="2">"vtkProperty.h"<br></font><font color="#0000ff" size="2">#include</font><font size="2"> </font><font color="#a31515" size="2">"vtkPolyData.h"<br></font><font color="#0000ff" size="2">
#include</font><font size="2"> </font><font color="#a31515" size="2">"vtkCellArray.h"<br></font><font color="#0000ff" size="2">#include</font><font size="2"> </font><font color="#a31515" size="2">"vtkPointData.h
"<br></font><font color="#0000ff" size="2">#include</font><font size="2"> </font><font color="#a31515" size="2">"vtkPolyDataNormals.h"<br></font><font color="#0000ff" size="2">#include</font><font size="2">
</font><font color="#a31515" size="2">"vtkCamera.h"</font></div>
<div><font size="2">
<p>vtkPolyData *MakeUnitCube()<br>{<br> vtkPolyData *cube = vtkPolyData::New();<br> vtkPoints *pnts = vtkPoints::New(); </p></font><font color="#008000" size="2">// vertices of the cube<br> </font><font size="2">
vtkCellArray *faces = vtkCellArray::New(); </font><font color="#008000" size="2">// faces of the cube<br><br> </font><font color="#0000ff" size="2">double</font><font size="2"> points[8][3] = { {-0.5,-0.5,0.5}, {-0.5
,0.5,0.5}, {0.5,0.5,0.5}, {0.5,-0.5,0.5},<br> {-0.5,-0.5,-0.5}, {-0.5,0.5,-0.5}, {0.5,0.5,-0.5}, {0.5,-0.5,-0.5} };<br> </font><font color="#0000ff" size="2">int</font><font size="2">
faceIds[6][4] = { {3,2,1,0}, {0,1,5,4}, {6,5,1,2}, {3,7,6,2}, {4,7,3,0}, {4,5,6,7} };<br> </font><font color="#0000ff" size="2">int</font><font size="2"> i;<br><br> </font><font color="#0000ff" size="2">for
</font><font size="2">(i=0; i<8; i++)<br> {<br> pnts->InsertNextPoint( points[i] );<br> </font><font color="#0000ff" size="2">if</font><font size="2"> (i < 6)<br> {
<br> faces->InsertNextCell(4, faceIds[i]);<br> }<br> }<br><br> cube->SetPoints( pnts );<br> cube->SetPolys( faces );<br> </font><font color="#0000ff" size="2">
return</font><font size="2"> cube;<br>}</font><font color="#0000ff" size="2">
<p>void</p></font><font size="2"> BuildPolyDataNormals(vtkPolyData *pd)<br>{<br> vtkPolyDataNormals *normals = vtkPolyDataNormals::New();<br> normals->SetInput( pd );<br> </font><font size="2">normals->ComputePointNormalsOn();
<br> normals->ComputeCellNormalsOff();<br> normals->SplittingOff();<br> normals->Update();<br> pd->GetPointData()->SetNormals( normals->GetOutput()->GetPointData()->GetNormals() );
<br> normals->Delete();<br>}</font><font color="#0000ff" size="2">
<p>void</p></font><font size="2"> DeformPoly(vtkPolyData *poly, vtkPolyData *polyNew)<br>{<br> </font><font color="#0000ff" size="2">int</font><font size="2"> numPoints = poly->GetNumberOfPoints();<br> </font>
<font color="#0000ff" size="2">int</font><font size="2"> i;<br> </font><font color="#0000ff" size="2">double</font><font size="2"> pnt[3];<br><br> polyNew->CopyStructure(poly);<br> </font><font color="#0000ff" size="2">
for</font><font size="2">(i=0; i<numPoints; i++)<br> {<br> poly->GetPoint(i, pnt);<br> polyNew->GetPoints()->SetPoint(i, pnt[0]*1.02, pnt[1]*1.04, pnt[2]*1.06);<br> }
<br>}</font><font color="#0000ff" size="2">
<p>void</p></font><font size="2"> main()<br>{<br></font><font color="#008000" size="2"> </font><font size="2">vtkRenderer *ren = vtkRenderer::New();<br> vtkRenderWindow *renWin = vtkRenderWindow::New();<br>
renWin->SetSize(600,400);<br> renWin->AddRenderer(ren);<br><br> </font><font size="2">vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br> iren->SetInteractorStyle( vtkInteractorStyleTrackballCamera::New() );
<br> iren->SetRenderWindow(renWin);<br><br> vtkPolyData *poly = MakeUnitCube(); </font><font color="#008000" size="2">// create a cube<br> </font><font size="2">BuildPolyDataNormals(poly); </font><font color="#008000" size="2">
// create it's point normals<br><br> </font><font size="2">vtkPolyData *newPoly = vtkPolyData::New();<br></font><font color="#0000ff" size="2"> int</font><font size="2"> i=0;<br> </font><font color="#0000ff" size="2">
for</font><font size="2">(i=0; i<10; i++)<br> {<br> DeformPoly( poly, newPoly ); </font><font color="#008000" size="2">// call the function to deform model based on curvature etc.<br>
</font><font size="2">BuildPolyDataNormals( newPoly ); </font><font color="#008000" size="2">// build normals of the new shape<br> </font><font size="2">poly->DeepCopy( newPoly ); </font><font color="#008000" size="2">
// assign it back to poly to be used in the next iteration<br> </font><font size="2">}<br> newPoly->Delete();<br> </font><font color="#008000" size="2">/* I commented the following line because I'm going to render poly onto screen. If you
<br> don't need to rendere it, then in your program you can delete poly here ant it should work */<br> </font><font color="#008000" size="2">// poly->Delete();<br><br> </font><font size="2">vtkProperty *prop = vtkProperty::New();
<br> prop->SetAmbientColor(0.488566, 0.394212, 0.147212);<br> prop->SetAmbient(1);<br> prop->SetDiffuseColor(0.488566, 0.394212, 0.147212);<br> prop->SetDiffuse(1);<br> prop->SetSpecularColor(
0.488566, 0.394212, 0.147212);<br> prop->SetSpecular(1);<br> prop->SetSpecularPower(51.2);<br><br> vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();<br> mapper->SetInput( poly );<br>
mapper->GlobalImmediateModeRenderingOn();<br><br> vtkActor *actor = vtkActor::New();<br> actor->SetMapper( mapper );<br> actor->SetProperty( prop );<br><br> ren->AddActor(actor);
<br> ren->GetActiveCamera()->SetFocalPoint(0,0,0);<br> ren->GetActiveCamera()->SetPosition(3,3,3);<br> ren->GetActiveCamera()->OrthogonalizeViewUp();<br><br> iren->Initialize();
<br> iren->Start();<br><br> prop->Delete();<br> mapper->Delete();<br> actor->Delete();<br> poly->Delete();<br> ren->Delete();<br> renWin->Delete();<br>
iren->Delete();<br>}</font><br><br> </div>
<div><span class="gmail_quote">On 8/13/07, <b class="gmail_sendername">Dongqing Chen</b> <<a href="mailto:dqchen@cvip.louisville.edu">dqchen@cvip.louisville.edu</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div bgcolor="#ffffff">
<div><font face="Arial" size="2">Hi, Meisam: </font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2"> Thanks for your replying. </font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2"> Actually, since I need to update all the new vertex positions based on their previous ones and some curvature flow criteria, during each iteration, I keep the previous polydate dataset structure, (say vtkPolypData *poly=vtkPolyData::New()), and assign the new vertex position to a newly generated polydata dataset polyNew. Finally during each iteration, I regenerate all the normals of polyNew, then I delete the poly and polyNew. Starting from a new interation, I transfer the normals to the poly which is generated again.
</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2"> </font><font face="Arial" size="2">To be simple, let me summarize what I did:</font></div>
<div><font face="Arial" size="2"> 1) create poly and polyNew; poly takes the input dataset, while polyNew is designed to take the updated vertex positions during each iteration. </font></div>
<div><font face="Arial" size="2"> I am also thinking a question: how to keep the exact structures of poly and polyNew?</font></div>
<div><font face="Arial" size="2">2). Based on its old position and curature flow criteria, I iteratively change the vertice position. </font></div>
<div><font face="Arial" size="2">3). At the end of each iteration, I generate all the new normals of polyNew, which will be transfered to the poly generated in next iteration.</font></div>
<div><font face="Arial" size="2">4). keep doing until all iterations are finished.</font></div>
<div><font face="Arial" size="2">5). delete poly or polyNew during each iteration or after all the iterations, which really depends on where I create them, during each iteration or before all the iterations?</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2"> Hope it is more clear this time. Otherwise, I will post some patches of my code.</font></div>
<div><font face="Arial" size="2"> </font></div>
<div><font face="Arial" size="2"> </font></div>
<div>Best Wishes,<br>-----------------------------------------------------------------<br>Dongqing Chen<br>Ph.D Candidate<br>Rm. 07, Paul C. Lutz Hall<br>Computer Vision & Image Processing (CVIP) Lab<br>Department of Electrical & Computer Engineering
<br>Speed School of Engineering<br>University of Louisville<br>Louisville, KY. 40292<br>U.S.A<br>Email: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:dqchen@cvip.louisville.edu" target="_blank">dqchen@cvip.louisville.edu
</a><br>Phone:+1-502-852-2789 (Lab)<br> +1-502-852-6130 (Office)<br>-----------------------------------------------------------------</div>
<blockquote style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<div style="FONT: 10pt arial">----- Original Message ----- </div>
<div style="BACKGROUND: #e4e4e4; FONT: 10pt arial"><b>From:</b> <a title="meisam.aliroteh@gmail.com" onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:meisam.aliroteh@gmail.com" target="_blank">Meisam Aliroteh
</a> </div>
<div style="FONT: 10pt arial"><b>To:</b> <a title="dqchen@cairo.spd.louisville.edu" onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:dqchen@cairo.spd.louisville.edu" target="_blank">Dongqing Chen</a> </div>
<div style="FONT: 10pt arial"><b>Cc:</b> <a title="vtkusers@vtk.org" onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a> </div>
<div style="FONT: 10pt arial"><b>Sent:</b> Sunday, August 12, 2007 8:07 PM</div>
<div style="FONT: 10pt arial"><b>Subject:</b> Re: [vtkusers] iteratively update the vertices positions.</div>
<div><br> </div>
<div>Hi Dongqing,</div>
<div> </div>
<div>I have implemented programs where I update position of vertices in a for-loop and it never crashed. Basically the Delete() method will not crash just because you iteratively change vertex positions. If your program crashes, it is because of something else. From your explanation it is not clear what is the cause of the problem. Maybe you can give more details!? Also including parts of your code that is causing the problem can be very helpful.
</div></blockquote></div></blockquote></div><br>