[vtkusers] Error in method CopyAndCastFrom method in vtkImageData?

Thomas Deschamps tdeschamps at lbl.gov
Tue Sep 24 21:08:37 EDT 2002


Hi

I would like to know if it is an error or no in method CopyAndCastFrom
of vtkImageData class
Here is the code of the sub-routine vtkImageDataCastExecute called by
CopyAndCastFrom

 1619 void vtkImageDataCastExecute(vtkImageData *inData, IT *inPtr,
 1620                              vtkImageData *outData, OT *outPtr,
 1621                              int outExt[6])
 1622 {
 1623   int idxR, idxY, idxZ;
 1624   int maxY, maxZ;
 1625   int inIncX, inIncY, inIncZ;
 1626   int outIncX, outIncY, outIncZ;
 1627   int rowLength;
 1628
 1629   // find the region to loop over
 1630   rowLength = (outExt[1] -
outExt[0]+1)*inData->GetNumberOfScalarComponents();
 1631   maxY = outExt[3] - outExt[2];
 1632   maxZ = outExt[5] - outExt[4];
 1633
 1634   // Get increments to march through data
 1635   inData->GetContinuousIncrements(outExt, inIncX, inIncY, inIncZ);

 1636   outData->GetContinuousIncrements(outExt, outIncX, outIncY,
outIncZ);
 1637
 1638   // Loop through ouput pixels
 1639   for (idxZ = 0; idxZ <= maxZ; idxZ++)
 1640     {
 1641     for (idxY = 0; idxY <= maxY; idxY++)
 1642       {
 1643       for (idxR = 0; idxR < rowLength; idxR++)
<---------------------- possible error
 1644         {
 1645         // Pixel operation
 1646         *outPtr = (OT)(*inPtr);
 1647         outPtr++;
 1648         inPtr++;
 1649         }...

Ok, why does it iterate on rowlength and not just on maxR = (outExt[1] -
outExt[0])?
rowLength is two big and it will make a pointer overflow ... I think.
Because it will iterate for (maxZ * maxY * rowLength) while the vector
size is (maxZ * maxY * maxR).
For me it does not work with two images with the same dimensions but
with different scalar types.

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20020924/9d09244c/attachment.htm>


More information about the vtkusers mailing list