[vtkusers] double vtkDataArray::GetTuple1(vtkIdType i) vs void vtkDataArray::GetTuple(vtkIdType i, double *tuple)
Maarten Beek
beekmaarten at yahoo.com
Wed May 7 16:20:46 EDT 2014
Hi all,
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?
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
//----------------------------------------------------------------------------
// This templated function executes the filter for any type of data.
template <class OT>
void cmvtkTemplatedExecute(cmvtkDRRGenerator2* self,
vtkDataSetCollection* inputs, vtkImageData* output,
int extent[6], int threadId, OT*)
{
vtkUnsignedCharArray* uchararray =
vtkUnsignedCharArray::SafeDownCast(output->GetPointData()->GetScalars("input_flag"));
int numinputs = inputs->GetNumberOfItems();
for( int input_i = 0; input_i < numinputs; ++input_i )
{
vtkImageData* input = vtkImageData::SafeDownCast(inputs->GetItem(input_i));
if( 0 == input )
{
// should not happen
continue;
}
const int* dims= output->GetDimensions();
vtkImageProgressIterator<OT> outIt(output, extent, self, threadId);
vtkIdType voxelid = extent[0] + size[0]*extent[2] + size[0]*size[1]*extent[4];
// Loop through output pixels
while( !outIt.IsAtEnd() )
{
OT* outSI = outIt.BeginSpan();
OT* outSIEnd = outIt.EndSpan();
while( outSI != outSIEnd )
{
// start with setting pixel to 0.0
if( input_i == 0 )
{
*outSI = 0.0;
}
OT result = 0.0;
//.... some math resulting in a value for result....
*outSI += result;
// this input image participates in voxel values; adjust bit
if( 0.0 < result && 0 != uchararray )
{
// The commented code crashes...
//unsigned char oldvalue = uchararray->GetTuple1(voxelid);
//unsigned char newvalue = oldvalue | (1<<input_i);
//uchararray->SetTuple1(voxelid, newvalue);
double dOldValue;
uchararray->GetTuple(voxelid, &dOldValue);
unsigned char chOldValue = static_cast<unsigned char>(dOldValue);
unsigned char chNewValue = chOldValue | (1<<input_i);
double dNewValue = static_cast<double>(chNewValue);
uchararray->SetTuple(voxelid, &dNewValue);
}
++outSI;
++voxelid;
}
outIt.NextSpan();
}
} // input_i < numinputs
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140507/9102c933/attachment.html>
More information about the vtkusers
mailing list