Hi all,<br><br>I&#39;m looking to speed up the vtkDijkstraImageGeodesicPath::BuildAdjacency method.  Right now, on a 512x512 image, that takes many seconds to compute.<br><br>It looks like the biggest cost (apart from a sqrt and a division at each pixel) is the line<br>
<br><br>  double cost = this-&gt;ImageWeight*(<br>    image-&gt;GetScalarComponentAsDouble( ijk1[0], ijk1[1], ijk1[2], 0 ) +<br>    image-&gt;GetScalarComponentAsDouble( ijk1[0], ijk1[1], ijk1[2], 0 ) );<br><br>Because GetScalarComponentAsDouble is a huge time sink when done over all pixels at once.  I&#39;m hoping to unroll the loop there.<br>
<br>I know that all of the pixels I&#39;m going to access are safe.  I want to get a double or floating point value, but I don&#39;t know the type of the array in the image (or do I?).<br><br>So far, I have:<br><br>  vtkDataArray* theImageData = image-&gt;GetPointData()-&gt;GetScalars();<br>
  vtkIdType increments[3];<br>  image-&gt;GetArrayIncrements(theImageData, increments);<br>  void* imageArrayPointer = image-&gt;GetArrayPointer(theImageData, theOrigin);<br><br>  double result1, result2;<br>  const int theSize = static_cast&lt;int&gt;(this-&gt;Internals-&gt;Adjacency.size());<br>
  for( int u = 0; u &lt; theSize; ++u ) {<br><br>      int v = (*it).first;<br>      double p1[3];<br>      image-&gt;GetPoint( u, p1 );<br>      double p2[3];<br>      image-&gt;GetPoint( v, p2 );<br><br>      int ijk1[3];<br>
      int ijk2[3];<br><br>      for (i=0; i&lt;3; i++)<br>        {<br>          d = p1[i] - origin[i];<br>          doubleLoc = d / spacing[i];<br>          // Floor for negative indexes.<br>          ijk1[i] = static_cast&lt;int&gt;(floor(doubleLoc));<br>
          d = p2[i] - origin[i];<br>          doubleLoc = d / spacing[i];<br>          // Floor for negative indexes.<br>          ijk2[i] = static_cast&lt;int&gt;(floor(doubleLoc));<br>        }<br>      switch (image-&gt;GetScalarType())<br>
        {<br>        vtkTemplateMacro(vtkImageDataConvertScalar(imageArrayPointer[ijk1[0] + ijk1[1]*increments[0] + ijk1[2]*increments[1]],&amp;result1));<br>        vtkTemplateMacro(vtkImageDataConvertScalar(imageArrayPointer[ijk2[0] + ijk2[1]*increments[0] + ijk2[2]*increments[1]],&amp;result1));<br>
        default:<br>        {<br>          vtkErrorMacro(&quot;Unknown Scalar type &quot; &lt;&lt; this-&gt;GetScalarType());<br>        }<br>      }<br><br>which is cobbled together from the various methods that are used in the computation of static edge costs in that file.<br>
<br>Of course, that&#39;s not right.  What are the magic words to make this go?  Do I need to template this function to the possible types of vtkImageData types? I&#39;m thinking something like:<br><br>template &lt;type&gt;<br>
type GetValueAtPoint(int loc){   <br>  return ArrayOfType[loc];<br>}<br><br>I mean, even better if I could get an iterator or something that I could just increment to the appropriate location.<br><br>Thanks,<br>Mark<br>