272 setInSliceVoxelType(_parameters.contentImage->getDataType());
274 ImageVector inputImageExtent = _parameters.contentImage->getImageExtent();
279 MLErrorCode errorCode = _clusters->init(inputImageExtent.x, inputImageExtent.y, inputImageExtent.z);
283 if ((_parameters.neighborhoodRelation ==
NBH_2D_4_XY) || (_parameters.neighborhoodRelation ==
NBH_2D_8_XY))
285 _clusters->setUse2DNeighborhood();
288 const bool useMask = _parameters.maskImage !=
nullptr;
290 if (!Host::getDefaultHost().getUseClassicHost())
293 handler.
setParameters(useMask, _currentSlices[0].getDataType());
295 std::vector<PagedImage*> images;
296 images.push_back(_parameters.contentImage);
299 images.push_back(_parameters.maskImage);
302 errorCode = Host::getDefaultHost().processAllPagesWithInputImages(images, handler,
SubImageBox(), _parameters.progressCB, _parameters.progressCBUserData);
311 for (
MLint zi = 0; (
ML_RESULT_OK == errorCode) && (zi < inputImageExtent.z); zi++)
313 errorCode = loadNextSlice(zi, inputImageExtent);
316 errorCode = loadMaskSlice(inMaskSlice, zi, inputImageExtent);
321 errorCode = processSlice(zi, inputImageExtent, inMaskSlice);
333 _clusters->calcClusterSizes(userDataParameters);
349 const MLint xres = inputImageExtent.x;
350 const MLint yres = inputImageExtent.y;
352 const ClusterVoxelType backgroundValue = DerivedAlgorithm::convertBackgroundValue(_parameters.backgroundValue);
355 MLTypeData* previousSliceInternalPtr =
reinterpret_cast<MLTypeData*
>(_currentSlices[0].getData());
356 const MLDataType dataType = _currentSlices[1].getDataType();
357 size_t dataTypeSize =
MLSizeOf(dataType);
361 size_t xoffset = dataTypeSize;
362 size_t yoffset = dataTypeSize * xres;
364 const bool useMask = _parameters.maskImage !=
nullptr;
365 const bool useBackgroundValue = _parameters.useBackgroundValue;
368 for (
MLint yi = 0; yi < yres; yi++)
370 for (
MLint xi = 0; xi < xres; xi++)
373 MLTypeData* previousSlicePtr = previousSliceInternalPtr;
377 sliceInternalPtr += dataTypeSize;
378 previousSliceInternalPtr += dataTypeSize;
381 CLUSTERVOXELTYPE currentValue = DerivedAlgorithm::getVoxel(slicePtr);
386 MLint8 maskValue = *maskPtr++;
394 if (useBackgroundValue && (currentValue == backgroundValue))
400 MLuint currentClusterRef = 0;
405 currentClusterRef = updateClusterRefForNeighbor(slicePtr - xoffset, xi - 1, yi, zi, currentValue, currentClusterRef);
409 currentClusterRef = updateClusterRefForNeighbor(slicePtr - yoffset, xi, yi - 1, zi, currentValue, currentClusterRef);
412 switch (_parameters.neighborhoodRelation)
415 if ((xi > 0) && (yi > 0))
417 currentClusterRef = updateClusterRefForNeighbor(slicePtr - xoffset - yoffset, xi - 1, yi - 1, zi, currentValue, currentClusterRef);
419 if ((xi<xres - 1) && (yi>0))
421 currentClusterRef = updateClusterRefForNeighbor(slicePtr + xoffset - yoffset, xi + 1, yi - 1, zi, currentValue, currentClusterRef);
428 if ((xi > 0) && (yi > 0) && (zi > 0))
430 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr - xoffset - yoffset, xi - 1, yi - 1, zi - 1, currentValue, currentClusterRef);
432 if ((xi<xres - 1) && (yi>0) && (zi > 0))
434 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr + xoffset - yoffset, xi + 1, yi - 1, zi - 1, currentValue, currentClusterRef);
436 if ((xi > 0) && (yi<yres - 1) && (zi>0))
438 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr - xoffset + yoffset, xi - 1, yi + 1, zi - 1, currentValue, currentClusterRef);
440 if ((xi<xres - 1) && (yi<yres - 1) && (zi>0))
442 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr + xoffset + yoffset, xi + 1, yi + 1, zi - 1, currentValue, currentClusterRef);
446 if ((xi>0) && (yi > 0))
448 currentClusterRef = updateClusterRefForNeighbor(slicePtr - xoffset - yoffset, xi - 1, yi - 1, zi, currentValue, currentClusterRef);
450 if ((xi<xres - 1) && (yi>0))
452 currentClusterRef = updateClusterRefForNeighbor(slicePtr + xoffset - yoffset, xi + 1, yi - 1, zi, currentValue, currentClusterRef);
454 if ((zi > 0) && (xi > 0))
456 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr - xoffset, xi - 1, yi, zi - 1, currentValue, currentClusterRef);
458 if ((zi > 0) && (xi<xres - 1))
460 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr + xoffset, xi + 1, yi, zi - 1, currentValue, currentClusterRef);
462 if ((zi>0) && (yi > 0))
464 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr - yoffset, xi, yi - 1, zi - 1, currentValue, currentClusterRef);
466 if ((zi > 0) && (yi<yres - 1))
468 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr + yoffset, xi, yi + 1, zi - 1, currentValue, currentClusterRef);
474 currentClusterRef = updateClusterRefForNeighbor(previousSlicePtr, xi, yi, zi - 1, currentValue, currentClusterRef);
489 if (currentClusterRef == 0)
493 if (_parameters.useImageValueAsUserData)
495 imageValue = DerivedAlgorithm::getVoxelAsDouble(slicePtr);
498 currentClusterRef = _clusters->getNewReference(imageValue);
500 _clusters->setClusterRef(xi, yi, zi, currentClusterRef);