<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div style="" class="">Hi all,</div><div style="" class=""><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">I experienced a crash in my algorithm derived from vtkThreadedImageAlgorithm, that (I think) I solved, but that I don't understand. Is there some one who can shed some light on the following?</div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">What I am trying to do is adding a flag identifying the input(s) that contribute to the value of each pixel in the output image<br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">//----------------------------------------------------------------------------<br style="" class="">// This templated function executes the filter for any type of data.<br style="" class="">template <class OT><br style="" class="">void cmvtkTemplatedExecute(cmvtkDRRGenerator2* self,<br
style="" class=""> vtkDataSetCollection* inputs, vtkImageData* output,<br style="" class=""> int extent[6], int threadId, OT*)<br style="" class="">{<br style="" class="">
vtkUnsignedCharArray* uchararray =
vtkUnsignedCharArray::SafeDownCast(output->GetPointData()->GetScalars("input_flag"));<br style="" class=""><br style="" class=""> int numinputs = inputs->GetNumberOfItems();<br style="" class=""> for( int input_i = 0; input_i < numinputs; ++input_i )<br style="" class=""> {<br style="" class=""> vtkImageData* input = vtkImageData::SafeDownCast(inputs->GetItem(input_i));<br style="" class=""> if( 0 == input )<br style="" class=""> {<br style="" class=""> // should not happen<br style="" class=""> continue;<br style="" class=""> }<br style="" class=""> const int* dims=
output->GetDimensions();<br style="" class=""><br style="" class=""> vtkImageProgressIterator<OT> outIt(output, extent, self, threadId);<br style="" class=""> vtkIdType voxelid = extent[0] + size[0]*extent[2] + size[0]*size[1]*extent[4];<br style="" class=""> <br style="" class=""> // Loop through output pixels<br style="" class=""> while( !outIt.IsAtEnd() )<br style="" class=""> {<br style="" class=""> OT* outSI = outIt.BeginSpan();<br style="" class=""> OT* outSIEnd = outIt.EndSpan();<br style="" class=""><br style="" class=""> while( outSI != outSIEnd )<br style=""
class=""> {<br style="" class=""> // start with setting pixel to 0.0<br style="" class=""> if( input_i == 0 )<br style="" class=""> {<br style="" class=""> *outSI = 0.0;<br style="" class=""> }<br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family:
HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"> OT result = 0.0;</div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"> //.... some math resulting in a value for result....</div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br
style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"> *outSI += result;<br style="" class=""><br style="" class=""> // this input image participates in voxel values; adjust bit<br style="" class=""> if( 0.0 < result && 0 != uchararray )<br style="" class=""> {<br style="" class=""> // The commented code crashes...<br style="" class=""><br style="" class="">
//unsigned char oldvalue = uchararray->GetTuple1(voxelid);<br style="" class=""> //unsigned char newvalue = oldvalue | (1<<input_i);<br style="" class=""> //uchararray->SetTuple1(voxelid, newvalue);<br style="" class=""><br style="" class=""> double dOldValue;<br style="" class=""> uchararray->GetTuple(voxelid, &dOldValue);<br style="" class=""> unsigned char chOldValue
= static_cast<unsigned char>(dOldValue);<br style="" class=""> unsigned char chNewValue = chOldValue | (1<<input_i);<br style="" class=""> double dNewValue = static_cast<double>(chNewValue);<br style="" class=""> uchararray->SetTuple(voxelid, &dNewValue);<br style="" class=""> }<br style="" class=""><br style="" class=""> ++outSI;<br style="" class=""> ++voxelid;<br style="" class="">
}<br style="" class=""> outIt.NextSpan();<br style="" class=""> }<br style="" class=""> } // input_i < numinputs<br style="" class="">}</div></div></body></html>