<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt">Hi David,<br><br>Thanks so much for your clarification!<br>I did see issues in the resulting image but was attributing them to noise in the original images. Now I see my code just had a huge bug in it.<br><br>I guess I would need a row counter in order to initialize voxelid correctly.<br><br>Wouldn't it be nice if the image iterator had a function like getVoxel(int ijk[3])...? I believe ITK has such an iterator.<br><br>Maarten<br><div><span><br></span></div><div style="display: block;" class="yahoo_quoted"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> On
Wednesday, May 7, 2014 5:26:23 PM, David Gobbi <david.gobbi@gmail.com> wrote:<br> </font> </div> <div class="y_msg_container">I should add: you actually have to re-initialize the voxelid at the<br>beginning of each row (i.e. at the beginning of each span of the<br>iterator).<br><br>On Wed, May 7, 2014 at 3:22 PM, David Gobbi <<a ymailto="mailto:david.gobbi@gmail.com" href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br>> Hi Maarten,<br>><br>> Since you know it's a vtkUnsignedCharArray, you shouldn't be using<br>> the SetTuple/GetTuple methods. Use the SetTupleValue and<br>> GetTupleValue methods, they're much faster because 1) they aren't<br>> virtual methods and 2) they don't have to convert to/from double.<br>> Or even better, if you know that your array only has one component,<br>> you can use SetValue/GetValue.<br>><br>> Your math for voxelid is too simplistic. Depending on
how the update<br>> extent is divided amongst the threads, it might give you a location<br>> that is totally wrong. To see why, draw a square on a piece of paper.<br>> That square represents the total extent of the output. Then divide<br>> that square into quadrants, and imagine that each quadrant goes<br>> to a different Execute method. Then think about how each thread<br>> is going to march through the data.<br>><br>> David<br>><br>><br>> On Wed, May 7, 2014 at 2:20 PM, Maarten Beek <<a ymailto="mailto:beekmaarten@yahoo.com" href="mailto:beekmaarten@yahoo.com">beekmaarten@yahoo.com</a>> wrote:<br>>> Hi all,<br>>><br>>> I experienced a crash in my algorithm derived from<br>>> vtkThreadedImageAlgorithm, that (I think) I solved, but that I don't<br>>> understand. Is there some one who can shed some light on the following?<br>>><br>>> What I am trying
to do is adding a flag identifying the input(s) that<br>>> contribute to the value of each pixel in the output image<br>>><br>>> //----------------------------------------------------------------------------<br>>> // This templated function executes the filter for any type of data.<br>>> template <class OT><br>>> void cmvtkTemplatedExecute(cmvtkDRRGenerator2* self,<br>>> vtkDataSetCollection* inputs, vtkImageData*<br>>> output,<br>>> int extent[6], int threadId, OT*)<br>>> {<br>>> vtkUnsignedCharArray* uchararray =<br>>> vtkUnsignedCharArray::SafeDownCast(output->GetPointData()->GetScalars("input_flag"));<br>>><br>>>
int numinputs = inputs->GetNumberOfItems();<br>>> for( int input_i = 0; input_i < numinputs; ++input_i )<br>>> {<br>>> vtkImageData* input =<br>>> vtkImageData::SafeDownCast(inputs->GetItem(input_i));<br>>> if( 0 == input )<br>>> {<br>>> // should not happen<br>>> continue;<br>>> }<br>>> const int* dims= output->GetDimensions();<br>>><br>>> vtkImageProgressIterator<OT> outIt(output, extent, self, threadId);<br>>> vtkIdType voxelid = extent[0] + size[0]*extent[2] +<br>>> size[0]*size[1]*extent[4];<br>>><br>>>
// Loop through output pixels<br>>> while( !outIt.IsAtEnd() )<br>>> {<br>>> OT* outSI = outIt.BeginSpan();<br>>> OT* outSIEnd = outIt.EndSpan();<br>>><br>>> while( outSI != outSIEnd )<br>>> {<br>>> // start with setting pixel to 0.0<br>>> if( input_i == 0 )<br>>> {<br>>> *outSI = 0.0;<br>>> }<br>>><br>>>
OT result = 0.0;<br>>><br>>> //.... some math resulting in a value for result....<br>>><br>>> *outSI += result;<br>>><br>>> // this input image participates in voxel values; adjust bit<br>>> if( 0.0 < result && 0 != uchararray )<br>>> {<br>>> // The commented code crashes...<br>>><br>>> //unsigned char oldvalue =<br>>> uchararray->GetTuple1(voxelid);<br>>> //unsigned char
newvalue = oldvalue | (1<<input_i);<br>>> //uchararray->SetTuple1(voxelid, newvalue);<br>>><br>>> double dOldValue;<br>>> uchararray->GetTuple(voxelid, &dOldValue);<br>>> unsigned char chOldValue = static_cast<unsigned<br>>> char>(dOldValue);<br>>> unsigned char chNewValue = chOldValue | (1<<input_i);<br>>> double dNewValue = static_cast<double>(chNewValue);<br>>>
uchararray->SetTuple(voxelid, &dNewValue);<br>>> }<br>>><br>>> ++outSI;<br>>> ++voxelid;<br>>> }<br>>> outIt.NextSpan();<br>>> }<br>>> } // input_i < numinputs<br>>> }<br><br><br></div> </div> </div> </div> </div></body></html>