// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSectionsMutualInformation::form_features_sections() { DREAM3D_RANDOMNG_NEW() DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); 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]), }; DimType point = 0; DimType seed = 0; bool noseeds = false; int32_t featurecount = 1; DimType neighbor = 0; QuatF q1 = QuaternionMathF::New(); QuatF q2 = QuaternionMathF::New(); QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); float w = 0.0f; float n1 = 0.0f; float n2 = 0.0f; float n3 = 0.0f; DimType randx = 0; DimType randy = 0; bool good = false; DimType x = 0, y = 0, z = 0; DimType col = 0, row = 0; size_t size = 0; size_t initialVoxelsListSize = 1000; m_FeatureCounts->resize(dims[2]); featurecounts = m_FeatureCounts->getPointer(0); std::vector<DimType> voxelslist(initialVoxelsListSize, -1); DimType neighpoints[4] = { 0, 0, 0, 0 }; neighpoints[0] = -dims[0]; neighpoints[1] = -1; neighpoints[2] = 1; neighpoints[3] = dims[0]; uint32_t phase1 = 0, phase2 = 0; for (DimType slice = 0; slice < dims[2]; slice++) { QString ss = QObject::tr("Aligning Sections || Identifying Features on Sections || %1% Complete").arg(((float)slice / dims[2]) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); featurecount = 1; noseeds = false; while (noseeds == false) { seed = -1; randx = DimType(float(rg.genrand_res53()) * float(dims[0])); randy = DimType(float(rg.genrand_res53()) * float(dims[1])); for (DimType j = 0; j < dims[1]; ++j) { for (DimType i = 0; i < dims[0]; ++i) { x = randx + i; y = randy + j; z = slice; if (x > dims[0] - 1) { x = x - dims[0]; } if (y > dims[1] - 1) { y = y - dims[1]; } point = (z * dims[0] * dims[1]) + (y * dims[0]) + x; if ((m_UseGoodVoxels == false || m_GoodVoxels[point] == true) && m_FeatureIds[point] == 0 && m_CellPhases[point] > 0) { seed = point; } if (seed > -1) { break; } } if( seed > -1) { break; } } if (seed == -1) { noseeds = true; } if (seed >= 0) { size = 0; m_FeatureIds[seed] = featurecount; voxelslist[size] = seed; size++; for (size_t j = 0; j < size; ++j) { DimType currentpoint = voxelslist[j]; col = currentpoint % dims[0]; row = (currentpoint / dims[0]) % dims[1]; QuaternionMathF::Copy(quats[currentpoint], q1); phase1 = m_CrystalStructures[m_CellPhases[currentpoint]]; for (int32_t i = 0; i < 4; i++) { good = true; neighbor = currentpoint + neighpoints[i]; if ((i == 0) && row == 0) { good = false; } if ((i == 3) && row == (dims[1] - 1)) { good = false; } if ((i == 1) && col == 0) { good = false; } if ((i == 2) && col == (dims[0] - 1)) { good = false; } if (good == true && m_FeatureIds[neighbor] <= 0 && m_CellPhases[neighbor] > 0) { w = std::numeric_limits<float>::max(); QuaternionMathF::Copy(quats[neighbor], q2); phase2 = m_CrystalStructures[m_CellPhases[neighbor]]; if (phase1 == phase2) { w = m_OrientationOps[phase1]->getMisoQuat(q1, q2, n1, n2, n3); } if (w < m_MisorientationTolerance) { m_FeatureIds[neighbor] = featurecount; voxelslist[size] = neighbor; size++; if (std::vector<DimType>::size_type(size) >= voxelslist.size()) { size = voxelslist.size(); voxelslist.resize(size + initialVoxelsListSize); for (std::vector<DimType>::size_type v = size; v < voxelslist.size(); ++v) { voxelslist[v] = -1; } } } } } } voxelslist.erase(std::remove(voxelslist.begin(), voxelslist.end(), -1), voxelslist.end()); featurecount++; voxelslist.assign(initialVoxelsListSize, -1); } } featurecounts[slice] = featurecount; } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SegmentGrains::execute() { setErrorCondition(0); VoxelDataContainer* m = getVoxelDataContainer(); std::stringstream ss; if(NULL == m) { setErrorCondition(-1); ss << " DataContainer was NULL"; addErrorMessage(getHumanLabel(), ss.str(), -1); return; } size_t udims[3] = { 0, 0, 0 }; m->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]), }; size_t gnum = 1; int seed = 0; int neighbor; bool good = 0; DimType col, row, plane; size_t size = 0; size_t initialVoxelsListSize = 1000; std::vector<int> voxelslist(initialVoxelsListSize, -1); 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]); // Burn volume with tight orientation tolerance to simulate simultaneous growth/aglomeration while (seed >= 0) { seed = getSeed(gnum); if(seed >= 0) { size = 0; voxelslist[size] = seed; size++; for (size_t j = 0; j < size; ++j) { // Get the current Voxel size_t currentpoint = voxelslist[j]; // Figure out the Row, Col & Plane the voxel is located in col = currentpoint % dims[0]; row = (currentpoint / dims[0]) % dims[1]; plane = currentpoint / (dims[0] * dims[1]); // Now loop over its 6 neighbors for (int i = 0; i < 6; i++) { good = true; neighbor = currentpoint + neighpoints[i]; // Make sure we have a valid neighbor taking into account the edges of the volume if(i == 0 && plane == 0) good = false; if(i == 5 && plane == (dims[2] - 1)) good = false; if(i == 1 && row == 0) good = false; if(i == 4 && row == (dims[1] - 1)) good = false; if(i == 2 && col == 0) good = false; if(i == 3 && col == (dims[0] - 1)) good = false; if(good == true) { // We got a good voxel to check so check to see if it can be grouped with this point if(determineGrouping(currentpoint, neighbor, gnum) == true) { // The voxel can be grouped with this voxel so add it to the list of voxels for this grain voxelslist[size] = neighbor; // Increment the size of the list which affects the "j" loop size++; // Sanity check the size of the voxelslist vector. If it is not large enough, double the size of the vector if(size >= voxelslist.size()) { voxelslist.resize(size + size, -1); // The resize is a hit but the doubling mitigates the penalty somewhat } } } } } voxelslist.clear(); voxelslist.resize(initialVoxelsListSize, -1); gnum++; ss.str(""); ss << "Total Grains: " << gnum; if(gnum%100 == 0) notifyStatusMessage(ss.str()); if (getCancel() == true) { setErrorCondition(-1); break; } } } // If there is an error set this to something negative and also set a message notifyStatusMessage("Completed"); }