// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ErodeDilateBadData::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getFeatureIdsArrayPath().getDataContainerName()); size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); Int32ArrayType::Pointer neighborsPtr = Int32ArrayType::CreateArray(totalPoints, "_INTERNAL_USE_ONLY_Neighbors"); m_Neighbors = neighborsPtr->getPointer(0); neighborsPtr->initializeWithValue(-1); size_t udims[3] = {0, 0, 0}; m->getGeometryAs<ImageGeom>()->getDimensions(udims); #if (CMP_SIZEOF_SIZE_T == 4) typedef int32_t DimType; #else typedef int64_t DimType; #endif DimType dims[3] = { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), }; int32_t good = 1; int64_t count = 0; int64_t kstride = 0, jstride = 0; int32_t featurename = 0, feature = 0; int32_t current = 0; int32_t most = 0; int64_t neighpoint = 0; size_t numfeatures = 0; for (size_t i = 0; i < totalPoints; i++) { featurename = m_FeatureIds[i]; if (featurename > numfeatures) { numfeatures = featurename; } } DimType neighpoints[6] = { 0, 0, 0, 0, 0, 0 }; neighpoints[0] = -dims[0] * dims[1]; neighpoints[1] = -dims[0]; neighpoints[2] = -1; neighpoints[3] = 1; neighpoints[4] = dims[0]; neighpoints[5] = dims[0] * dims[1]; QVector<int32_t> n(numfeatures + 1, 0); for (int32_t iteration = 0; iteration < m_NumIterations; iteration++) { for (DimType k = 0; k < dims[2]; k++) { kstride = dims[0] * dims[1] * k; for (DimType j = 0; j < dims[1]; j++) { jstride = dims[0] * j; for (DimType i = 0; i < dims[0]; i++) { count = kstride + jstride + i; featurename = m_FeatureIds[count]; if (featurename == 0) { current = 0; most = 0; for (int32_t l = 0; l < 6; l++) { good = 1; neighpoint = count + neighpoints[l]; if (l == 0 && (k == 0 || m_ZDirOn == false)) { good = 0; } else if (l == 5 && (k == (dims[2] - 1) || m_ZDirOn == false)) { good = 0; } else if (l == 1 && (j == 0 || m_YDirOn == false)) { good = 0; } else if (l == 4 && (j == (dims[1] - 1) || m_YDirOn == false)) { good = 0; } else if (l == 2 && (i == 0 || m_XDirOn == false)) { good = 0; } else if (l == 3 && (i == (dims[0] - 1) || m_XDirOn == false)) { good = 0; } if (good == 1) { feature = m_FeatureIds[neighpoint]; if (m_Direction == 0 && feature > 0) { m_Neighbors[neighpoint] = count; } if (feature > 0 && m_Direction == 1) { n[feature]++; current = n[feature]; if (current > most) { most = current; m_Neighbors[count] = neighpoint; } } } } if (m_Direction == 1) { for (int32_t l = 0; l < 6; l++) { good = 1; neighpoint = count + neighpoints[l]; if (l == 0 && k == 0) { good = 0; } if (l == 5 && k == (dims[2] - 1)) { good = 0; } if (l == 1 && j == 0) { good = 0; } if (l == 4 && j == (dims[1] - 1)) { good = 0; } if (l == 2 && i == 0) { good = 0; } if (l == 3 && i == (dims[0] - 1)) { good = 0; } if (good == 1) { feature = m_FeatureIds[neighpoint]; n[feature] = 0; } } } } } } } QString attrMatName = m_FeatureIdsArrayPath.getAttributeMatrixName(); QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames(); for (size_t j = 0; j < totalPoints; j++) { featurename = m_FeatureIds[j]; int32_t neighbor = m_Neighbors[j]; if (neighbor >= 0) { if ( (featurename == 0 && m_FeatureIds[neighbor] > 0 && m_Direction == 1) || (featurename > 0 && m_FeatureIds[neighbor] == 0 && m_Direction == 0)) { for(QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter); p->copyTuple(neighbor, j); } } } } } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void RemoveFlaggedFeatures::assign_badpoints() { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); size_t udims[3] = {0, 0, 0}; m->getGeometryAs<ImageGeom>()->getDimensions(udims); #if (CMP_SIZEOF_SIZE_T == 4) typedef int32_t DimType; #else typedef int64_t DimType; #endif DimType dims[3] = { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), }; Int32ArrayType::Pointer neighborsPtr = Int32ArrayType::CreateArray(totalPoints, "_INTERNAL_USE_ONLY_Neighbors"); m_Neighbors = neighborsPtr->getPointer(0); neighborsPtr->initializeWithValue(-1); int32_t good = 1; int32_t current = 0; int32_t most = 0; int64_t neighpoint = 0; DimType neighpoints[6]; neighpoints[0] = -dims[0] * dims[1]; neighpoints[1] = -dims[0]; neighpoints[2] = -1; neighpoints[3] = 1; neighpoints[4] = dims[0]; neighpoints[5] = dims[0] * dims[1]; size_t counter = 1; int64_t count = 0; int64_t kstride = 0, jstride = 0; int32_t featurename, feature; int32_t neighbor; QVector<int32_t> n(m_FlaggedFeaturesPtr.lock()->getNumberOfTuples(), 0); while (counter != 0) { counter = 0; for (DimType k = 0; k < dims[2]; k++) { kstride = dims[0] * dims[1] * k; for (DimType j = 0; j < dims[1]; j++) { jstride = dims[0] * j; for (DimType i = 0; i < dims[0]; i++) { count = kstride + jstride + i; featurename = m_FeatureIds[count]; if (featurename < 0) { counter++; current = 0; most = 0; for (int32_t l = 0; l < 6; l++) { good = 1; neighpoint = count + neighpoints[l]; if (l == 0 && k == 0) { good = 0; } if (l == 5 && k == (dims[2] - 1)) { good = 0; } if (l == 1 && j == 0) { good = 0; } if (l == 4 && j == (dims[1] - 1)) { good = 0; } if (l == 2 && i == 0) { good = 0; } if (l == 3 && i == (dims[0] - 1)) { good = 0; } if (good == 1) { feature = m_FeatureIds[neighpoint]; if (feature >= 0) { n[feature]++; current = n[feature]; if (current > most) { most = current; m_Neighbors[count] = neighpoint; } } } } for (int32_t l = 0; l < 6; l++) { good = 1; neighpoint = count + neighpoints[l]; if (l == 0 && k == 0) { good = 0; } if (l == 5 && k == (dims[2] - 1)) { good = 0; } if (l == 1 && j == 0) { good = 0; } if (l == 4 && j == (dims[1] - 1)) { good = 0; } if (l == 2 && i == 0) { good = 0; } if (l == 3 && i == (dims[0] - 1)) { good = 0; } if (good == 1) { feature = m_FeatureIds[neighpoint]; if (feature >= 0) { n[feature] = 0; } } } } } } } QString attrMatName = m_FeatureIdsArrayPath.getAttributeMatrixName(); QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames(); for (size_t j = 0; j < totalPoints; j++) { featurename = m_FeatureIds[j]; neighbor = m_Neighbors[j]; if (neighbor >= 0) { if (featurename < 0 && m_FeatureIds[neighbor] >= 0) { for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter); p->copyTuple(neighbor, j); } } } } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ErodeDilateCoordinationNumber::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getFeatureIdsArrayPath().getDataContainerName()); size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); Int32ArrayType::Pointer neighborsPtr = Int32ArrayType::CreateArray(totalPoints, "Neighbors"); m_Neighbors = neighborsPtr->getPointer(0); neighborsPtr->initializeWithValue(-1); size_t udims[3] = {0, 0, 0}; m->getGeometryAs<ImageGeom>()->getDimensions(udims); int64_t dims[3] = { static_cast<int64_t>(udims[0]), static_cast<int64_t>(udims[1]), static_cast<int64_t>(udims[2]), }; int32_t good = 1; int64_t point = 0; int64_t kstride = 0, jstride = 0; int32_t featurename = 0, feature = 0; int32_t coordination = 0; int32_t current = 0; int32_t most = 0; int64_t neighpoint = 0; size_t numfeatures = 0; for(size_t i = 0; i < totalPoints; i++) { featurename = m_FeatureIds[i]; if (featurename > numfeatures) { numfeatures = featurename; } } int64_t neighpoints[6] = { 0, 0, 0, 0, 0, 0 }; neighpoints[0] = -dims[0] * dims[1]; neighpoints[1] = -dims[0]; neighpoints[2] = -1; neighpoints[3] = 1; neighpoints[4] = dims[0]; neighpoints[5] = dims[0] * dims[1]; QString attrMatName = m_FeatureIdsArrayPath.getAttributeMatrixName(); QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames(); QVector<int32_t> n(numfeatures + 1, 0); QVector<int32_t> coordinationNumber(totalPoints, 0); bool keepgoing = true; int32_t counter = 1; while (counter > 0 && keepgoing == true) { counter = 0; if (m_Loop == false) { keepgoing = false; } for (int64_t k = 0; k < dims[2]; k++) { kstride = dims[0] * dims[1] * k; for (int64_t j = 0; j < dims[1]; j++) { jstride = dims[0] * j; for (int64_t i = 0; i < dims[0]; i++) { point = kstride + jstride + i; featurename = m_FeatureIds[point]; coordination = 0; current = 0; most = 0; for (int32_t l = 0; l < 6; l++) { good = 1; neighpoint = point + neighpoints[l]; if (l == 0 && k == 0) { good = 0; } if (l == 5 && k == (dims[2] - 1)) { good = 0; } if (l == 1 && j == 0) { good = 0; } if (l == 4 && j == (dims[1] - 1)) { good = 0; } if (l == 2 && i == 0) { good = 0; } if (l == 3 && i == (dims[0] - 1)) { good = 0; } if (good == 1) { feature = m_FeatureIds[neighpoint]; if ((featurename > 0 && feature == 0) || (featurename == 0 && feature > 0)) { coordination = coordination + 1; n[feature]++; current = n[feature]; if (current > most) { most = current; m_Neighbors[point] = neighpoint; } } } } coordinationNumber[point] = coordination; int32_t neighbor = m_Neighbors[point]; if (coordinationNumber[point] >= m_CoordinationNumber && coordinationNumber[point] > 0) { for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter); p->copyTuple(neighbor, point); } } for (int32_t l = 0; l < 6; l++) { good = 1; neighpoint = point + neighpoints[l]; if (l == 0 && k == 0) { good = 0; } if (l == 5 && k == (dims[2] - 1)) { good = 0; } if (l == 1 && j == 0) { good = 0; } if (l == 4 && j == (dims[1] - 1)) { good = 0; } if (l == 2 && i == 0) { good = 0; } if (l == 3 && i == (dims[0] - 1)) { good = 0; } if (good == 1) { feature = m_FeatureIds[neighpoint]; if (feature > 0) { n[feature] = 0; } } } } } } for (int64_t k = 0; k < dims[2]; k++) { kstride = static_cast<int64_t>(dims[0] * dims[1] * k); for (int64_t j = 0; j < dims[1]; j++) { jstride = static_cast<int64_t>(dims[0] * j); for (int64_t i = 0; i < dims[0]; i++) { point = kstride + jstride + i; if (coordinationNumber[point] >= m_CoordinationNumber) { counter++; } } } } } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }