Hi all,<br><br>I'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->ImageWeight*(<br> image->GetScalarComponentAsDouble( ijk1[0], ijk1[1], ijk1[2], 0 ) +<br> image->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'm hoping to unroll the loop there.<br>
<br>I know that all of the pixels I'm going to access are safe. I want to get a double or floating point value, but I don't know the type of the array in the image (or do I?).<br><br>So far, I have:<br><br> vtkDataArray* theImageData = image->GetPointData()->GetScalars();<br>
vtkIdType increments[3];<br> image->GetArrayIncrements(theImageData, increments);<br> void* imageArrayPointer = image->GetArrayPointer(theImageData, theOrigin);<br><br> double result1, result2;<br> const int theSize = static_cast<int>(this->Internals->Adjacency.size());<br>
for( int u = 0; u < theSize; ++u ) {<br><br> int v = (*it).first;<br> double p1[3];<br> image->GetPoint( u, p1 );<br> double p2[3];<br> image->GetPoint( v, p2 );<br><br> int ijk1[3];<br>
int ijk2[3];<br><br> for (i=0; i<3; i++)<br> {<br> d = p1[i] - origin[i];<br> doubleLoc = d / spacing[i];<br> // Floor for negative indexes.<br> ijk1[i] = static_cast<int>(floor(doubleLoc));<br>
d = p2[i] - origin[i];<br> doubleLoc = d / spacing[i];<br> // Floor for negative indexes.<br> ijk2[i] = static_cast<int>(floor(doubleLoc));<br> }<br> switch (image->GetScalarType())<br>
{<br> vtkTemplateMacro(vtkImageDataConvertScalar(imageArrayPointer[ijk1[0] + ijk1[1]*increments[0] + ijk1[2]*increments[1]],&result1));<br> vtkTemplateMacro(vtkImageDataConvertScalar(imageArrayPointer[ijk2[0] + ijk2[1]*increments[0] + ijk2[2]*increments[1]],&result1));<br>
default:<br> {<br> vtkErrorMacro("Unknown Scalar type " << this->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'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'm thinking something like:<br><br>template <type><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>