Hi Greg,<div>Sure, the code that I wrote is at the end of this email - I&#39;m always happy to have someone else to look for bugs! Â It creates a temp grid to store the original version of the unstructured grid, and then modifies the values in the original grid in place, with new values being calculated from the unmodified temp grid.</div>

<div><br></div><div>I&#39;m using itk and vtk to measure strains in solids, where I use image registration to find the displacements of the nodes in an FE mesh and then use FE techniques to calculate the strains. Â The registration is carried out between an image of the solid unloaded, and another image of the solid loaded (deformed). Â Basically I&#39;m doing digital image correlation in 3D, and using an FE mesh to decide where to perform my registration.</div>

<div><br></div><div>The unstructured grid is read in from a gmsh mesh file.</div><div><br></div><div>Cheers,<br clear="all">Seth</div><div><br></div><div><div>/** A function to smooth the image using a weighted moving average using</div>

<div> * a Gaussian kernel for weight calculation. The function is given R, </div><div> * the radius of points to consider; sigma, the standard deviation of the</div><div> * of the Gaussian kernel; and mean, the mean of the Gaussian kernel in</div>

<div> * terms of distance from the point being averaged (this will in 99.99%</div><div> * of cases need to be set to 0).*/</div><div>void WeightedMovingAverageFilter( double R , double sigma, double mean )</div><div>{</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>// create a duplicate of the data image</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>DataImagePointer tempImage = DataImagePointer::New();</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>tempImage-&gt;DeepCopy(this-&gt;m_DataImage);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// loop through the points of both the images</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>unsigned int nPoints = tempImage-&gt;GetNumberOfPoints();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>for( unsigned int i = 0; i &lt; nPoints; ++i ){</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>// find the points withing the specified radius of the current point position<span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>double *cPoint = tempImage-&gt;GetPoint( i ); // current point position</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>vtkIdList *pointList = vtkIdList::New(); // id list to hold ids of the closest points</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>this-&gt;m_KDTree-&gt;FindPointsWithinRadius( R, cPoint, pointList );</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>// move through the points in the list and use them to calculate the new point value</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>unsigned int N = pointList-&gt;GetNumberOfIds();</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>double totalNumerator[3] = { 0, 0, 0 };</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>double totalDenominator = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for( unsigned int j = 0; j &lt; N; ++j){</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>vtkIdType cId = pointList-&gt;GetId( j );</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>// calcualate the weight based on the distance and the gaussian parameters</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>double *tempLocation = tempImage-&gt;GetPoint( cId );</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>double cDistance = sqrt( pow((*tempLocation-*cPoint),2) + pow((*(tempLocation+1)-(*cPoint+1)),2) + pow((*(tempLocation+2)-(*cPoint+2)),2) );</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>double weight = 1/(2.50662827*sqrt(sigma))*pow(2.718281828,-pow((cDistance-mean),2)/(2*sigma*sigma)); // 1/sqrt(2*pi*sigma)*e^(-(X-mean)^2/(s*sigma^2)) (the Gaussian distribution)</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>// add the weight to the total denominator</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>totalDenominator = totalDenominator + weight;</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>// add to the numerators</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>double *tempPixel = tempImage-&gt;GetPointData()-&gt;GetArray(&quot;Displacement&quot;)-&gt;GetTuple( cId ); // the original data in the current point</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>totalNumerator[0] = totalNumerator[0] + weight * *tempPixel;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>totalNumerator[1] = totalNumerator[1] + weight * *(tempPixel+1);</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>totalNumerator[2] = totalNumerator[2] + weight * *(tempPixel+2);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>// use the total numerators and denominator to calculate the new pixel</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>double *newPixel = new double[3];</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>*newPixel = totalNumerator[0] / totalDenominator;</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>*(newPixel+1) = totalNumerator[1] / totalDenominator;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>*(newPixel+2) = totalNumerator[2] / totalDenominator;</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>// set the data image pixel to the value of the new pixel</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>this-&gt;m_DataImage-&gt;GetPointData()-&gt;GetArray(&quot;Displacement&quot;)-&gt;SetTuple( i, newPixel );</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>}</div></div><div><br></div><div><br>
<br><br><div class="gmail_quote">On Thu, Oct 20, 2011 at 11:19 AM, greg aiken <span dir="ltr">&lt;<a href="mailto:gregaiken@hotmail.com">gregaiken@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">





<div><div dir="ltr">
I dont suppose you have any sample code to share with someone who is interested to learn how you did this?<br><br>Greg<br><br>ps - what is your application?  where did your unstructured grid data originate from?  thanks.<br>

<br><div><hr>From: <a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a><br>Date: Thu, 20 Oct 2011 11:00:21 -0700<br>To: <a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a><br>Subject: Re: [vtkusers] Smooth Data Unstructured Grid<div>

<div></div><div class="h5"><br><br>Hello all,<div>There were no suggestions on how to do this, so in the end I implemented a weighted moving average filter, with a Gaussian kernel, based on the distance from the current point to the neighbouring points.</div>



<div><br></div><div>Cheers,<br clear="all">Seth<br><br>
<br><br><div>On Tue, Oct 18, 2011 at 11:15 AM, Seth Gilchrist <span dir="ltr">&lt;<a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a>&gt;</span> wrote:<br><blockquote style="border-left:1px solid rgb(204, 204, 204);padding-left:1ex">



Hello,<div>I have an unstructured grid that contains point data. Â The point data has a certain amount of noise associated with it and I would like to smooth the data. Â The classes vtkImageGaussianSmooth and vtkImageMedian3D require variables in pixel units, so I assume that they won&#39;t work on unstructured grid data.</div>




<div><br></div><div>Is there a class/way to smooth/filter the data in an unstructured grid?</div><div><br></div><div>Thanks,</div><div>Seth</div>
</blockquote></div><br></div>
<br></div></div>_______________________________________________
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a>

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>

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>

Follow this link to subscribe/unsubscribe:
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a></div>                                               </div></div>

</blockquote></div><br></div>