16 #include "PlusConfigure.h" 20 #include "igsioMath.h" 22 #include "vtkImageData.h" 23 #include "vtkImageProgressIterator.h" 24 #include "vtkInformation.h" 25 #include "vtkInformationVector.h" 26 #include "vtkObjectFactory.h" 27 #include "vtkStreamingDemandDrivenPipeline.h" 44 this->SetInputData( 0, input );
50 this->SetInputData( 1, input );
56 this->SetInputData( 2, input );
62 this->SetInputData( 3, input );
68 this->SetInputData( 4, input );
74 return this->GetOutput( 0 );
80 return this->GetOutput( 1 );
104 int index =
value + 256;
125 for (
int i = 0;
i < 511;
i++ )
134 for (
int i = 0;
i < 256;
i++ )
143 for (
int i = 0;
i < 256;
i++ )
151 this->SetNumberOfInputPorts( 5 );
152 this->SetNumberOfOutputPorts( 2 );
153 this->SetNumberOfThreads( 1 );
157 vtkInformation* vtkNotUsed( request ),
158 vtkInformationVector** vtkNotUsed( inputVector ),
159 vtkInformationVector* outputVector )
162 vtkInformation* outInfo = outputVector->GetInformationObject( 0 );
163 vtkDataObject::SetPointDataActiveScalarInfo( outInfo, VTK_DOUBLE, 1 );
164 vtkInformation* outInfo2 = outputVector->GetInformationObject( 1 );
165 vtkDataObject::SetPointDataActiveScalarInfo( outInfo2, VTK_DOUBLE, 1 );
172 vtkImageData* inData,
173 vtkImageData* outData,
185 vtkIdType inOffsets[3] = {0};
186 inData->GetIncrements( inOffsets[0], inOffsets[1], inOffsets[2] );
188 vtkIdType outOffsets[3] = {0};
189 outData->GetIncrements( outOffsets[0], outOffsets[1], outOffsets[2] );
191 int xtemp( 0 ), ytemp( 0 ), ztemp( 0 );
192 self->resetTrueHistogram();
193 self->resetAbsoluteHistogramWithHoles();
194 self->resetAbsoluteHistogram();
195 std::vector<double> trueDifferences;
196 std::vector<double> absoluteDifferences;
203 std::vector<double> absoluteDifferencesInAllHoles;
205 int countVisibleVoxels( 0 );
206 int countFilledHoles( 0 );
210 for ( ztemp = 0; ztemp <= outExt[5] - outExt[4]; ztemp++ )
212 for ( ytemp = 0; ytemp <= outExt[3] - outExt[2]; ytemp++ )
214 for ( xtemp = 0; xtemp <= outExt[1] - outExt[0]; xtemp++ )
216 int inIndex = inOffsets[0] * xtemp + inOffsets[1] * ytemp + inOffsets[2] * ztemp;
217 int outIndex = outOffsets[0] * xtemp + outOffsets[1] * ytemp + outOffsets[2] * ztemp;
218 if ( gtAlphaPtr[inIndex] != 0 )
220 countVisibleVoxels++;
221 if ( slicesAlphaPtr[inIndex] == 0 )
224 double difference = ( double )gtPtr[inIndex] - testPtr[inIndex];
225 self->incAbsoluteHistogramWithHolesAtIndex( igsioMath::Round( fabs( difference ) ) );
226 absoluteDifferencesInAllHoles.push_back( fabs( difference ) );
227 if ( testAlphaPtr[inIndex] != 0 )
230 trueDifferences.push_back( difference );
231 self->incTrueHistogramAtIndex( igsioMath::Round( difference ) );
232 outPtrTru[outIndex] = difference;
233 absoluteDifferences.push_back( fabs( difference ) );
234 self->incAbsoluteHistogramAtIndex( igsioMath::Round( fabs( difference ) ) );
235 outPtrAbs[outIndex] = fabs( difference );
241 outPtrTru[outIndex] = 0.0;
242 outPtrAbs[outIndex] = 0.0;
247 outPtrTru[outIndex] = 0.0;
248 outPtrAbs[outIndex] = 0.0;
254 double absoluteMeanWithHoles( 0.0 );
256 for (
unsigned int i = 0;
i < absoluteDifferencesInAllHoles.size();
i++ )
258 absoluteMeanWithHoles += absoluteDifferencesInAllHoles[
i];
262 double trueMean( 0.0 );
263 double absoluteMean( 0.0 );
265 for (
int i = 0;
i < countFilledHoles;
i++ )
267 trueMean += trueDifferences[
i];
268 absoluteMean += absoluteDifferences[
i];
269 rms += trueDifferences[
i] * trueDifferences[
i];
273 if ( countFilledHoles != 0 )
275 trueMean /= countFilledHoles;
276 absoluteMean /= countFilledHoles;
277 rms = sqrt( rms / countFilledHoles );
287 if ( countHoles != 0 )
289 absoluteMeanWithHoles /= countHoles;
293 absoluteMeanWithHoles = 0;
297 double trueStdev = 0.0;
298 double absoluteStdev = 0.0;
299 for (
int i = 0;
i < countFilledHoles;
i++ )
301 trueStdev += pow( ( trueDifferences[
i] - trueMean ), 2 );
302 absoluteStdev += pow( ( absoluteDifferences[
i] - absoluteMean ), 2 );
304 if ( countFilledHoles != 0 )
306 trueStdev = sqrt( trueStdev / countFilledHoles );
307 absoluteStdev = sqrt( absoluteStdev / countFilledHoles );
316 std::list<double> trueDifferencesList;
317 std::list<double> absoluteDifferencesList;
318 for (
int i = 0;
i < countFilledHoles;
i++ )
320 trueDifferencesList.push_front( trueDifferences.back() );
321 trueDifferences.pop_back();
322 absoluteDifferencesList.push_front( absoluteDifferences.back() );
323 absoluteDifferences.pop_back();
325 trueDifferencesList.sort();
326 absoluteDifferencesList.sort();
327 for (
int i = 0;
i < countFilledHoles;
i++ )
329 trueDifferences.push_back( trueDifferencesList.front() );
330 trueDifferencesList.pop_front();
331 absoluteDifferences.push_back( absoluteDifferencesList.front() );
332 absoluteDifferencesList.pop_front();
335 double true5thPercentile( 0.0 );
336 double true95thPercentile( 0.0 );
337 double absolute5thPercentile( 0.0 );
338 double absolute95thPercentile( 0.0 );
339 double absoluteMedian( 0.0 );
340 double trueMedian( 0.0 );
341 double trueMinimum( 0.0 );
342 double trueMaximum( 0.0 );
343 double absoluteMinimum( 0.0 );
344 double absoluteMaximum( 0.0 );
346 if ( countFilledHoles != 0 )
348 trueMinimum = trueDifferences[0];
349 trueMaximum = trueDifferences[countFilledHoles - 1];
350 absoluteMinimum = absoluteDifferences[0];
351 absoluteMaximum = absoluteDifferences[countFilledHoles - 1];
357 double medianRank = ( countFilledHoles - 1 ) * 0.5;
358 double medianFraction = fmod( medianRank, 1.0 );
359 int medianFloor = (
int )floor( medianRank );
360 if ( medianFloor < 0 )
364 int medianCeil = (
int )ceil( medianRank );
365 if ( medianCeil > ( countFilledHoles - 1 ) )
367 medianCeil = ( countFilledHoles - 1 );
369 trueMedian = trueDifferences[medianFloor] * ( 1 - medianFraction ) + trueDifferences[medianCeil] * medianFraction;
370 absoluteMedian = absoluteDifferences[medianFloor] * ( 1 - medianFraction ) + absoluteDifferences[medianCeil] * medianFraction;
372 double percentile5rank = ( countFilledHoles - 1 ) * 0.05;
373 double percentile5fraction = fmod( percentile5rank, 1.0 );
374 int percentile5floor = (
int )floor( percentile5rank );
375 if ( percentile5floor < 0 )
377 percentile5floor = 0;
379 int percentile5ceil = (
int )ceil( percentile5rank );
380 if ( percentile5ceil > ( countFilledHoles - 1 ) )
382 percentile5ceil = ( countFilledHoles - 1 );
384 true5thPercentile = trueDifferences[percentile5floor] * ( 1 - percentile5fraction ) + trueDifferences[percentile5ceil] * percentile5fraction;
385 absolute5thPercentile = absoluteDifferences[percentile5floor] * ( 1 - percentile5fraction ) + absoluteDifferences[percentile5ceil] * percentile5fraction;
387 double percentile95rank = ( countFilledHoles - 1 ) * 0.95;
388 double percentile95fraction = fmod( percentile95rank, 1.0 );
389 int percentile95floor = (
int )floor( percentile95rank );
390 if ( percentile95floor < 0 )
392 percentile95floor = 0;
394 int percentile95ceil = (
int )ceil( percentile95rank );
395 if ( percentile95ceil > ( countFilledHoles - 1 ) )
397 percentile95ceil = ( countFilledHoles - 1 );
399 true95thPercentile = trueDifferences[percentile95floor] * ( 1 - percentile95fraction ) + trueDifferences[percentile95ceil] * percentile95fraction;
400 absolute95thPercentile = absoluteDifferences[percentile95floor] * ( 1 - percentile95fraction ) + absoluteDifferences[percentile95ceil] * percentile95fraction;
403 self->SetNumberOfHoles( countHoles );
404 self->SetNumberVoxelsVisible( countVisibleVoxels );
405 self->SetNumberOfFilledHoles( countFilledHoles );
407 self->SetTrue95thPercentile( true95thPercentile );
408 self->SetTrue5thPercentile( true5thPercentile );
409 self->SetTrueMaximum( trueMaximum );
410 self->SetTrueMinimum( trueMinimum );
411 self->SetTrueMedian( trueMedian );
412 self->SetTrueStdev( trueStdev );
413 self->SetTrueMean( trueMean );
415 self->SetAbsolute95thPercentile( absolute95thPercentile );
416 self->SetAbsolute5thPercentile( absolute5thPercentile );
417 self->SetAbsoluteMaximum( absoluteMaximum );
418 self->SetAbsoluteMinimum( absoluteMinimum );
419 self->SetAbsoluteMedian( absoluteMedian );
420 self->SetAbsoluteStdev( absoluteStdev );
421 self->SetAbsoluteMean( absoluteMean );
423 self->SetAbsoluteMeanWithHoles( absoluteMeanWithHoles );
429 vtkInformation* vtkNotUsed( request ),
430 vtkInformationVector** vtkNotUsed( inputVector ),
431 vtkInformationVector* vtkNotUsed( outputVector ),
432 vtkImageData** *inData,
433 vtkImageData** outData,
434 int outExt[6],
int threadId )
442 vtkErrorMacro( <<
"Input must be specified." );
452 vtkErrorMacro( <<
"Execute: input ScalarTypes must match ScalarType " 458 void* gtPtr = gtVolData->GetScalarPointer();
465 double* outPtrTru = static_cast< double* >( outVolDataTru->GetScalarPointer() );
468 switch ( gtVolData->GetScalarType() )
472 static_cast<VTK_TT*>( gtPtr ), static_cast<VTK_TT*>( gtAlphaPtr ),
473 static_cast<VTK_TT*>( testPtr ), static_cast<VTK_TT*>( testAlphaPtr ),
474 static_cast<VTK_TT*>( slicesAlphaPtr ),
475 outPtrTru, outPtrAbs, outExt, threadId )
478 vtkErrorMacro( <<
"Execute: Unknown ScalarType" );
489 info->Set( vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkImageData" );
int AbsoluteHistogramWithHoles[256]
int * GetAbsoluteHistogramPtr()
vtkImageData * GetOutputAbsoluteDifferenceImage()
int AbsoluteHistogram[256]
virtual void SetInputGT(vtkDataObject *input)
void incAbsoluteHistogramWithHolesAtIndex(int value)
vtkImageData * GetOutputTrueDifferenceImage()
void incAbsoluteHistogramAtIndex(int value)
int * GetAbsoluteHistogramWithHolesPtr()
static const int INPUT_GROUND_TRUTH_VOLUME_ALPHA
virtual void SetInputTestAlpha(vtkDataObject *input)
virtual void SetInputTest(vtkDataObject *input)
virtual int FillInputPortInformation(int port, vtkInformation *info)
int * GetTrueHistogramPtr()
static const int INPUT_SLICES_VOLUME_ALPHA
virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
virtual void SetInputGTAlpha(vtkDataObject *input)
void resetAbsoluteHistogram()
static const int INPUT_GROUND_TRUTH_VOLUME
void ThreadedRequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector, vtkImageData ***inData, vtkImageData **outData, int ext[6], int id)
void vtkPlusCompareVolumesExecute(vtkPlusCompareVolumes *self, vtkImageData *inData, vtkImageData *outData, T *gtPtr, T *gtAlphaPtr, T *testPtr, T *testAlphaPtr, T *slicesAlphaPtr, double *outPtrTru, double *outPtrAbs, int outExt[6], int id)
void resetAbsoluteHistogramWithHoles()
vtkStandardNewMacro(vtkPlusCompareVolumes)
const char const char * value
static const int OUTPUT_ABS_DIFF_VOLUME
static const int INPUT_TEST_VOLUME
static const int INPUT_TEST_VOLUME_ALPHA
void resetTrueHistogram()
void incTrueHistogramAtIndex(int value)
virtual void SetInputSliceAlpha(vtkDataObject *input)