// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSectionsList::find_shifts(std::vector<int> &xshifts, std::vector<int> &yshifts) { VoxelDataContainer* m = getVoxelDataContainer(); //int64_t totalPoints = m->totalPoints(); std::ifstream inFile; inFile.open(m_InputFile.c_str()); 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]), }; int slice; int newxshift, newyshift; for (DimType iter = 1; iter < dims[2]; iter++) { inFile >> slice >> newxshift >> newyshift; xshifts[iter] = xshifts[iter-1] + newxshift; yshifts[iter] = yshifts[iter-1] + newyshift; } inFile.close(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ClearData::execute() { int err = 0; setErrorCondition(err); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); dataCheck(false, m->getTotalPoints(), m->getNumFieldTuples(), m->getNumEnsembleTuples()); if(getErrorCondition() < 0) { 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]), }; int index; std::list<std::string> voxelArrayNames = m->getCellArrayNameList(); for (int k = m_ZMin; k < m_ZMax+1; k++) { for (int j = m_YMin; j < m_YMax+1; j++) { for (int i = m_XMin; i < m_XMax+1; i++) { index = (k * dims[0] * dims[1]) + (j * dims[0]) + i; for (std::list<std::string>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { std::string name = *iter; IDataArray::Pointer p = m->getCellData(*iter); p->InitializeTuple(index,0); } } } } notifyStatusMessage("Completed"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeResolution::preflight() { VoxelDataContainer* m = getVoxelDataContainer(); size_t dims[3]; m->getDimensions(dims); float sizex = (dims[0])*m->getXRes(); float sizey = (dims[1])*m->getYRes(); float sizez = (dims[2])*m->getZRes(); int m_XP = int(sizex / m_Resolution.x); int m_YP = int(sizey / m_Resolution.y); int m_ZP = int(sizez / m_Resolution.z); m->setDimensions(m_XP, m_YP, m_ZP); m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void IdentifySample::execute() { setErrorCondition(0); // int err = 0; VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } int64_t totalPoints = m->getTotalPoints(); dataCheck(false, totalPoints, m->getNumFieldTuples(), m->getNumEnsembleTuples()); if (getErrorCondition() < 0 && getErrorCondition() != -305) { return; } setErrorCondition(0); 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]), }; DimType neighpoints[6]; DimType xp = dims[0]; DimType yp = dims[1]; DimType zp = dims[2]; neighpoints[0] = -(xp * yp); neighpoints[1] = -xp; neighpoints[2] = -1; neighpoints[3] = 1; neighpoints[4] = xp; neighpoints[5] = (xp * yp); std::vector<int> currentvlist; std::vector<bool> checked; checked.resize(totalPoints,false); std::vector<bool> Sample; Sample.resize(totalPoints,false); std::vector<bool> notSample; notSample.resize(totalPoints,false); int biggestBlock = 0; size_t count; int good; int neighbor; DimType column, row, plane; int index; for (int i = 0; i < totalPoints; i++) { if(checked[i] == false && m_GoodVoxels[i] == false) { currentvlist.push_back(i); count = 0; while (count < currentvlist.size()) { index = currentvlist[count]; column = index % xp; row = (index / xp) % yp; plane = index / (xp * yp); for (int j = 0; j < 6; j++) { good = 1; neighbor = static_cast<int>( index + neighpoints[j] ); if(j == 0 && plane == 0) good = 0; if(j == 5 && plane == (zp - 1)) good = 0; if(j == 1 && row == 0) good = 0; if(j == 4 && row == (yp - 1)) good = 0; if(j == 2 && column == 0) good = 0; if(j == 3 && column == (xp - 1)) good = 0; if(good == 1 && checked[neighbor] == false && m_GoodVoxels[neighbor] == false) { currentvlist.push_back(neighbor); checked[neighbor] = true; } } count++; } if(static_cast<int>(currentvlist.size()) >= biggestBlock) { biggestBlock = currentvlist.size(); for(int j = 0; j < totalPoints; j++) { notSample[j] = false; } for(size_t j = 0; j < currentvlist.size(); j++) { notSample[currentvlist[j]] = true; } } currentvlist.clear(); } } for (int i = 0; i < totalPoints; i++) { if (notSample[i] == false && m_GoodVoxels[i] == false) m_GoodVoxels[i] = true; else if (notSample[i] == true && m_GoodVoxels[i] == true) m_GoodVoxels[i] = false; } notSample.clear(); checked.clear(); biggestBlock = 0; checked.resize(totalPoints,false); for (int i = 0; i < totalPoints; i++) { if(checked[i] == false && m_GoodVoxels[i] == true) { currentvlist.push_back(i); count = 0; while (count < currentvlist.size()) { index = currentvlist[count]; column = index % xp; row = (index / xp) % yp; plane = index / (xp * yp); for (int j = 0; j < 6; j++) { good = 1; neighbor = static_cast<int>( index + neighpoints[j] ); if(j == 0 && plane == 0) good = 0; if(j == 5 && plane == (zp - 1)) good = 0; if(j == 1 && row == 0) good = 0; if(j == 4 && row == (yp - 1)) good = 0; if(j == 2 && column == 0) good = 0; if(j == 3 && column == (xp - 1)) good = 0; if(good == 1 && checked[neighbor] == false && m_GoodVoxels[neighbor] == true) { currentvlist.push_back(neighbor); checked[neighbor] = true; } } count++; } if(static_cast<int>(currentvlist.size()) >= biggestBlock) { biggestBlock = currentvlist.size(); for(int j = 0; j < totalPoints; j++) { Sample[j] = false; } for(size_t j = 0; j < currentvlist.size(); j++) { Sample[currentvlist[j]] = true; } } currentvlist.clear(); } } for (int i = 0; i < totalPoints; i++) { if (Sample[i] == false && m_GoodVoxels[i] == true) m_GoodVoxels[i] = false; else if (Sample[i] == true && m_GoodVoxels[i] == false) m_GoodVoxels[i] = true; } Sample.clear(); checked.clear(); /* std::vector<bool> change; change.resize(totalPoints,false); for (int i = 0; i < totalPoints; i++) { if(m_GoodVoxels[i] == false) { column = i % xp; row = (i / xp) % yp; plane = i / (xp * yp); for (int j = 0; j < 6; j++) { good = 1; neighbor = static_cast<int>( i + neighpoints[j] ); if(j == 0 && plane == 0) good = 0; if(j == 5 && plane == (zp - 1)) good = 0; if(j == 1 && row == 0) good = 0; if(j == 4 && row == (yp - 1)) good = 0; if(j == 2 && column == 0) good = 0; if(j == 3 && column == (xp - 1)) good = 0; if(good == 1 && m_GoodVoxels[neighbor] == true) { change[i] = true; } } } } for(int j = 0; j < totalPoints; j++) { if(change[j] == true) m_GoodVoxels[j] = true; } change.clear(); */ // If there is an error set this to something negative and also set a message notifyStatusMessage("Identifying Sample Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeResolution::execute() { int err = 0; setErrorCondition(err); DREAM3D_RANDOMNG_NEW() VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); if (getErrorCondition() < 0) { return; } if(m->getXRes() == m_Resolution.x && m->getYRes() == m_Resolution.y && m->getZRes() == m_Resolution.z) { return; } size_t dims[3]; m->getDimensions(dims); float sizex = (dims[0])*m->getXRes(); float sizey = (dims[1])*m->getYRes(); float sizez = (dims[2])*m->getZRes(); int m_XP = int(sizex / m_Resolution.x); int m_YP = int(sizey / m_Resolution.y); int m_ZP = int(sizez / m_Resolution.z); int64_t totalPoints = m_XP*m_YP*m_ZP; float x, y, z; int col, row, plane; int index; int index_old; std::vector<size_t> newindicies; newindicies.resize(totalPoints); for (int i = 0; i < m_ZP; i++) { std::stringstream ss; ss << "Changing Resolution - " << ((float)i/m->getZPoints())*100 << " Percent Complete"; notifyStatusMessage(ss.str()); for (int j = 0; j < m_YP; j++) { for (int k = 0; k < m_XP; k++) { x = (k * m_Resolution.x); y = (j * m_Resolution.y); z = (i * m_Resolution.z); col = int(x / m->getXRes()); row = int(y / m->getYRes()); plane = int(z / m->getZRes()); index_old = (plane * m->getXPoints() * m->getYPoints()) + (row * m->getXPoints()) + col; index = (i * m_XP * m_YP) + (j * m_XP) + k; newindicies[index] = index_old; } } } std::list<std::string> voxelArrayNames = m->getCellArrayNameList(); for (std::list<std::string>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { std::string name = *iter; IDataArray::Pointer p = m->getCellData(*iter); // Make a copy of the 'p' array that has the same name. When placed into // the data container this will over write the current array with // the same name. At least in theory IDataArray::Pointer data = p->createNewArray(p->GetNumberOfTuples(), p->GetNumberOfComponents(), p->GetName()); data->Resize(totalPoints); void* source = NULL; void* destination = NULL; size_t newIndicies_I = 0; int nComp = data->GetNumberOfComponents(); for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++) { newIndicies_I = newindicies[i]; source = p->GetVoidPointer((nComp * newIndicies_I)); destination = data->GetVoidPointer((data->GetNumberOfComponents() * i)); ::memcpy(destination, source, p->GetTypeSize() * data->GetNumberOfComponents()); } m->addCellData(*iter, data); } m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); m->setDimensions(m_XP, m_YP, m_ZP); notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSectionsFeature::find_shifts(std::vector<int> &xshifts, std::vector<int> &yshifts) { VoxelDataContainer* m = getVoxelDataContainer(); //int64_t totalPoints = m->totalPoints(); std::ofstream outFile; if (getWriteAlignmentShifts() == true) { outFile.open(getAlignmentShiftFileName().c_str()); } 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]), }; float disorientation = 0; float mindisorientation = 100000000; int newxshift = 0; int newyshift = 0; int oldxshift = 0; int oldyshift = 0; float count = 0; int slice = 0; // int xspot, yspot; int refposition = 0; int curposition = 0; std::vector<std::vector<float> > misorients; misorients.resize(dims[0]); for (DimType a = 0; a < dims[0]; a++) { misorients[a].resize(dims[1], 0.0); } for (DimType iter = 1; iter < dims[2]; iter++) { std::stringstream ss; ss << "Aligning Sections - Determining Shifts - " << ((float)iter/dims[2])*100 << " Percent Complete"; // notifyStatusMessage(ss.str()); mindisorientation = 100000000; slice = static_cast<int>( (dims[2] - 1) - iter ); oldxshift = -1; oldyshift = -1; newxshift = 0; newyshift = 0; for (DimType a = 0; a < dims[0]; a++) { for (DimType b = 0; b < dims[1]; b++) { misorients[a][b] = 0; } } while (newxshift != oldxshift || newyshift != oldyshift) { oldxshift = newxshift; oldyshift = newyshift; for (int j = -3; j < 4; j++) { for (int k = -3; k < 4; k++) { disorientation = 0; count = 0; if(misorients[k + oldxshift + size_t(dims[0] / 2)][j + oldyshift + (size_t)(dims[1] / 2)] == 0 && abs(k + oldxshift) < (dims[0] / 2) && (j + oldyshift) < (dims[1] / 2)) { for (DimType l = 0; l < dims[1]; l = l + 4) { for (DimType n = 0; n < dims[0]; n = n + 4) { if((l + j + oldyshift) >= 0 && (l + j + oldyshift) < dims[1] && (n + k + oldxshift) >= 0 && (n + k + oldxshift) < dims[0]) { refposition = static_cast<int>( ((slice + 1) * dims[0] * dims[1]) + (l * dims[0]) + n ); curposition = static_cast<int>( (slice * dims[0] * dims[1]) + ((l + j + oldyshift) * dims[0]) + (n + k + oldxshift) ); if(m_GoodVoxels[refposition] != m_GoodVoxels[curposition]) disorientation++; count++; } else { } } } disorientation = disorientation/count; misorients[k + oldxshift + int(dims[0] / 2)][j + oldyshift + int(dims[1] / 2)] = disorientation; if(disorientation < mindisorientation) { newxshift = k + oldxshift; newyshift = j + oldyshift; mindisorientation = disorientation; } } } } } xshifts[iter] = xshifts[iter-1] + newxshift; yshifts[iter] = yshifts[iter-1] + newyshift; if (getWriteAlignmentShifts() == true) { outFile << slice << " " << slice+1 << " " << newxshift << " " << newyshift << " " << xshifts[iter] << " " << yshifts[iter] << std::endl; } } if (getWriteAlignmentShifts() == true) { outFile.close(); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void Threshold::execute() { std::stringstream ss; int err = 0; setErrorCondition(err); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", getErrorCondition()); return; } setErrorCondition(0); int64_t totalPoints = m->getTotalPoints(); size_t totalFields = m->getNumFieldTuples(); size_t totalEnsembles = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, totalFields, totalEnsembles); if(m_OverwriteArray) { CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, ProcessedImageData, ss, ImageProcessing::DefaultPixelType, ImageProcessing::DefaultArrayType, 0, totalPoints, 1) } if (getErrorCondition() < 0) { return; } //get dims 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]), }; //wrap input as itk image ImageProcessing::DefaultImageType::Pointer inputImage=ITKUtilities::Dream3DtoITK(m, m_RawImageData); //define threshold filters typedef itk::BinaryThresholdImageFilter <ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType> BinaryThresholdImageFilterType; typedef itk::BinaryThresholdImageFilter <ImageProcessing::DefaultSliceType, ImageProcessing::DefaultSliceType> BinaryThresholdImageFilterType2D; if(m_Method>=0 && m_Method<=11) { //define hitogram generator (will make the same kind of histogram for 2 and 3d images typedef itk::Statistics::ImageToHistogramFilter<ImageProcessing::DefaultImageType> HistogramGenerator; //find threshold value w/ histogram itk::HistogramThresholdCalculator< HistogramGenerator::HistogramType, uint8_t >::Pointer calculator; typedef itk::HuangThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > HuangCalculatorType; typedef itk::IntermodesThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > IntermodesCalculatorType; typedef itk::IsoDataThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > IsoDataCalculatorType; typedef itk::KittlerIllingworthThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > KittlerIllingowrthCalculatorType; typedef itk::LiThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > LiCalculatorType; typedef itk::MaximumEntropyThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > MaximumEntropyCalculatorType; typedef itk::MomentsThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > MomentsCalculatorType; typedef itk::OtsuThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > OtsuCalculatorType; typedef itk::RenyiEntropyThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > RenyiEntropyCalculatorType; typedef itk::ShanbhagThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > ShanbhagCalculatorType; typedef itk::TriangleThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > TriangleCalculatorType; typedef itk::YenThresholdCalculator< HistogramGenerator::HistogramType, uint8_t > YenCalculatorType; switch(m_Method) { case 0: { calculator = HuangCalculatorType::New(); } break; case 1: { calculator = IntermodesCalculatorType::New(); } break; case 2: { calculator = IsoDataCalculatorType::New(); } break; case 3: { calculator = KittlerIllingowrthCalculatorType::New(); } break; case 4: { calculator = LiCalculatorType::New(); } break; case 5: { calculator = MaximumEntropyCalculatorType::New(); } break; case 6: { calculator = MomentsCalculatorType::New(); } break; case 7: { calculator = OtsuCalculatorType::New(); } break; case 8: { calculator = RenyiEntropyCalculatorType::New(); } break; case 9: { calculator = ShanbhagCalculatorType::New(); } break; case 10: { calculator = TriangleCalculatorType::New(); } break; case 11: { calculator = YenCalculatorType::New(); } break; } if(m_Slice) { //define 2d histogram generator typedef itk::Statistics::ImageToHistogramFilter<ImageProcessing::DefaultSliceType> HistogramGenerator2D; HistogramGenerator2D::Pointer histogramFilter2D = HistogramGenerator2D::New(); //specify number of bins / bounds typedef HistogramGenerator2D::HistogramSizeType SizeType; SizeType size( 1 ); size[0] = 255; histogramFilter2D->SetHistogramSize( size ); histogramFilter2D->SetMarginalScale( 10.0 ); HistogramGenerator2D::HistogramMeasurementVectorType lowerBound( 1 ); HistogramGenerator2D::HistogramMeasurementVectorType upperBound( 1 ); lowerBound[0] = 0; upperBound[0] = 256; histogramFilter2D->SetHistogramBinMinimum( lowerBound ); histogramFilter2D->SetHistogramBinMaximum( upperBound ); //wrap output buffer as image ImageProcessing::DefaultImageType::Pointer outputImage=ITKUtilities::Dream3DtoITK(m, m_ProcessedImageData); //loop over slices for(int i=0; i<dims[2]; i++) { //get slice ImageProcessing::DefaultSliceType::Pointer slice = ITKUtilities::ExtractSlice<ImageProcessing::DefaultPixelType>(inputImage, ImageProcessing::ZSlice, i); //find histogram histogramFilter2D->SetInput( slice ); histogramFilter2D->Update(); const HistogramGenerator::HistogramType * histogram = histogramFilter2D->GetOutput(); //calculate threshold level calculator->SetInput(histogram); calculator->Update(); const uint8_t thresholdValue = calculator->GetThreshold(); //threshold BinaryThresholdImageFilterType2D::Pointer thresholdFilter = BinaryThresholdImageFilterType2D::New(); thresholdFilter->SetInput(slice); thresholdFilter->SetLowerThreshold(thresholdValue); thresholdFilter->SetUpperThreshold(255); thresholdFilter->SetInsideValue(255); thresholdFilter->SetOutsideValue(0); thresholdFilter->Update(); //copy back into volume ITKUtilities::SetSlice<ImageProcessing::DefaultPixelType>(outputImage, thresholdFilter->GetOutput(), ImageProcessing::ZSlice, i); } } else { //specify number of bins / bounds HistogramGenerator::Pointer histogramFilter = HistogramGenerator::New(); typedef HistogramGenerator::HistogramSizeType SizeType; SizeType size( 1 ); size[0] = 255; histogramFilter->SetHistogramSize( size ); histogramFilter->SetMarginalScale( 10.0 ); HistogramGenerator::HistogramMeasurementVectorType lowerBound( 1 ); HistogramGenerator::HistogramMeasurementVectorType upperBound( 1 ); lowerBound[0] = 0; upperBound[0] = 256; histogramFilter->SetHistogramBinMinimum( lowerBound ); histogramFilter->SetHistogramBinMaximum( upperBound ); //find histogram histogramFilter->SetInput( inputImage ); histogramFilter->Update(); const HistogramGenerator::HistogramType * histogram = histogramFilter->GetOutput(); //calculate threshold level calculator->SetInput(histogram); calculator->Update(); const uint8_t thresholdValue = calculator->GetThreshold(); //threshold BinaryThresholdImageFilterType::Pointer thresholdFilter = BinaryThresholdImageFilterType::New(); thresholdFilter->SetInput(inputImage); thresholdFilter->SetLowerThreshold(thresholdValue); thresholdFilter->SetUpperThreshold(255); thresholdFilter->SetInsideValue(255); thresholdFilter->SetOutsideValue(0); thresholdFilter->GetOutput()->GetPixelContainer()->SetImportPointer(m_ProcessedImageData, totalPoints, false); thresholdFilter->Update(); } } else if(m_Method==12)//manual { //threshold BinaryThresholdImageFilterType::Pointer thresholdFilter = BinaryThresholdImageFilterType::New(); thresholdFilter->SetInput(inputImage); thresholdFilter->SetLowerThreshold(m_ManualParameter); thresholdFilter->SetUpperThreshold(255); thresholdFilter->SetInsideValue(255); thresholdFilter->SetOutsideValue(0); thresholdFilter->GetOutput()->GetPixelContainer()->SetImportPointer(m_ProcessedImageData, totalPoints, false); thresholdFilter->Update(); } /* else if(m_Method==13)//robust automatic { typedef itk::GradientMagnitudeImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType> GradientMagnitudeType; typedef itk::GradientMagnitudeImageFilter<ImageProcessing::DefaultSliceType, ImageProcessing::DefaultSliceType> GradientMagnitudeType2D; typedef itk::itkRobustAutomaticThresholdCalculator<ImageProcessing::DefaultImageType,ImageProcessing::DefaultImageType> SelectionType; typedef itk::itkRobustAutomaticThresholdCalculator<ImageProcessing::DefaultSliceType,ImageProcessing::DefaultSliceType> SelectionType2D; if(m_slice) { //wrap output buffer as image ImageProcessing::DefaultImageType::Pointer outputImage=ITKUtilities::Dream3DtoITK(m, m_ProcessedImageData); //loop over slices for(int i=0; i<dims[2]; i++) { //get slice ImageProcessing::DefaultSliceType::Pointer slice = ITKUtilities::ExtractSlice<ImageProcessing::DefaultPixelType>(inputImage, ImageProcessing::ZSlice, i); //find gradient GradientMagnitudeType2D::Pointer gradientFilter = GradientMagnitudeType2D::New(); gradientFilter->setInput(slice); gradientFilter->Update(); //calculate thershold SelectionType2D::Pointer calculatorFilter = SelectionType2D::New(); calculatorFilter->SetInput(slice); calculatorFilter->SetGradientImage(gradientFilter->GetOutput()); calculatorFilter->SetPow(m_ManualParameter); calculatorFilter->Update(); const uint8_t thresholdValue = calculatorFilter->GetOutput(); //threshold BinaryThresholdImageFilterType::Pointer thresholdFilter = BinaryThresholdImageFilterType::New(); thresholdFilter->SetInput(inputImage); thresholdFilter->SetLowerThreshold(thresholdValue); thresholdFilter->SetUpperThreshold(255); thresholdFilter->SetInsideValue(255); thresholdFilter->SetOutsideValue(0); thresholdFilter->Update(); //copy back into volume ITKUtilities::SetSlice<ImageProcessing::DefaultPixelType>(outputImage, thresholdFilter->GetOutput(), ImageProcessing::ZSlice, i); } } else { //find gradient GradientMagnitudeType::Pointer gradientFilter = GradientMagnitudeType::New(); gradientFilter->setInput(inputImage); gradientFilter->Update(); //calculate threshold SelectionType::Pointer calculatorFilter = SelectionType::New(); calculatorFilter->SetInput(inputImage); calculatorFilter->SetGradientImage(gradientFilter->GetOutput()); calculatorFilter->SetPow(m_ManualParameter); calculatorFilter->Update(); const uint8_t thresholdValue = calculatorFilter->GetOutput(); //threshold BinaryThresholdImageFilterType::Pointer thresholdFilter = BinaryThresholdImageFilterType::New(); thresholdFilter->SetInput(inputImage); thresholdFilter->SetLowerThreshold(thresholdValue); thresholdFilter->SetUpperThreshold(255); thresholdFilter->SetInsideValue(255); thresholdFilter->SetOutsideValue(0); thresholdFilter->GetOutput()->GetPixelContainer()->SetImportPointer(m_ProcessedImageData, totalPoints, false); thresholdFilter->Update(); } } */ //array name changing/cleanup if(m_OverwriteArray) { m->removeCellData(m_SelectedCellArrayName); bool check = m->renameCellData(m_ProcessedImageDataArrayName, m_SelectedCellArrayName); } /* Let the GUI know we are done with this filter */ notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSections::execute() { setErrorCondition(0); VoxelDataContainer* m = getVoxelDataContainer(); if (NULL == m) { setErrorCondition(-1); std::stringstream ss; ss << " DataContainer was NULL"; notifyErrorMessage(ss.str(), -1); return; } int64_t totalPoints = m->getTotalPoints(); size_t numgrains = m->getNumFieldTuples(); size_t numensembles = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, numgrains, numensembles); if (getErrorCondition() < 0) { 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]), }; int slice; int xspot, yspot; DimType newPosition; DimType currentPosition; // unsigned int phase2; std::vector<int> xshifts; std::vector<int> yshifts; xshifts.resize(dims[2],0); yshifts.resize(dims[2],0); find_shifts(xshifts, yshifts); std::list<std::string> voxelArrayNames = m->getCellArrayNameList(); DimType progIncrement = dims[2]/100; DimType prog = 1; int progressInt = 0; std::stringstream ss; for (DimType i = 1; i < dims[2]; i++) { if (i > prog) { ss.str(""); progressInt = ((float)i/dims[2])*100.0; ss << "Transferring Cell Data - " << progressInt << "% Complete"; notifyStatusMessage(ss.str()); prog = prog + progIncrement; } if (getCancel() == true) { return; } slice = static_cast<int>( (dims[2] - 1) - i ); for (DimType l = 0; l < dims[1]; l++) { for (DimType n = 0; n < dims[0]; n++) { if(yshifts[i] >= 0) yspot = static_cast<int>(l); else if(yshifts[i] < 0) yspot = static_cast<int>( dims[1] - 1 - l ); if(xshifts[i] >= 0) xspot = static_cast<int>(n); else if(xshifts[i] < 0) xspot = static_cast<int>( dims[0] - 1 - n ); newPosition = (slice * dims[0] * dims[1]) + (yspot * dims[0]) + xspot; currentPosition = (slice * dims[0] * dims[1]) + ((yspot + yshifts[i]) * dims[0]) + (xspot + xshifts[i]); if((yspot + yshifts[i]) >= 0 && (yspot + yshifts[i]) <= dims[1] - 1 && (xspot + xshifts[i]) >= 0 && (xspot + xshifts[i]) <= dims[0] - 1) { for(std::list<std::string>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { std::string name = *iter; IDataArray::Pointer p = m->getCellData(*iter); p->CopyTuple(currentPosition, newPosition); } } if((yspot + yshifts[i]) < 0 || (yspot + yshifts[i]) > dims[1] - 1 || (xspot + xshifts[i]) < 0 || (xspot + xshifts[i]) > dims[0] - 1) { for(std::list<std::string>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { std::string name = *iter; IDataArray::Pointer p = m->getCellData(*iter); p->InitializeTuple(newPosition, 0.0); } } } } } // If there is an error set this to something negative and also set a message notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void OpenCloseBadData::execute() { setErrorCondition(0); // int err = 0; VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } int64_t totalPoints = m->getTotalPoints(); dataCheck(false, totalPoints, m->getNumFieldTuples(), m->getNumEnsembleTuples()); if (getErrorCondition() < 0 && getErrorCondition() != -305) { return; } setErrorCondition(0); Int32ArrayType::Pointer neighborsPtr = Int32ArrayType::CreateArray(totalPoints, "Neighbors"); m_Neighbors = neighborsPtr->GetPointer(0); neighborsPtr->initializeWithValues(-1); 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 count = 1; int good = 1; // int neighbor; // int index = 0; // float x, y, z; // DimType row, plane; int neighpoint; size_t numgrains = m->getNumFieldTuples(); int neighpoints[6]; neighpoints[0] = static_cast<int>(-dims[0] * dims[1]); neighpoints[1] = static_cast<int>(-dims[0]); neighpoints[2] = static_cast<int>(-1); neighpoints[3] = static_cast<int>(1); neighpoints[4] = static_cast<int>(dims[0]); neighpoints[5] = static_cast<int>(dims[0] * dims[1]); std::vector<int> currentvlist; size_t count = 0; int kstride, jstride; int grainname, grain; int current; int most; std::vector<int > n(numgrains + 1,0); for (int iteration = 0; iteration < m_NumIterations; iteration++) { for (int k = 0; k < dims[2]; k++) { kstride = static_cast<int>( dims[0]*dims[1]*k ); for (int j = 0; j < dims[1]; j++) { jstride = static_cast<int>( dims[0]*j ); for (int i = 0; i < dims[0]; i++) { count = kstride+jstride+i; std::stringstream ss; grainname = m_GrainIds[count]; if (grainname == 0) { current = 0; most = 0; for (int l = 0; l < 6; l++) { good = 1; neighpoint = static_cast<int>( 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) { grain = m_GrainIds[neighpoint]; if (m_Direction == 0 && grain > 0) { m_Neighbors[neighpoint] = count; } if ((grain > 0 && m_Direction == 1)) { n[grain]++; current = n[grain]; if (current > most) { most = current; m_Neighbors[count] = neighpoint; } } } } if (m_Direction == 1) { for (int l = 0; l < 6; l++) { good = 1; neighpoint = static_cast<int>( 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) { grain = m_GrainIds[neighpoint]; n[grain] = 0; } } } } } } } std::list<std::string> voxelArrayNames = m->getCellArrayNameList(); for (int j = 0; j < totalPoints; j++) { int grainname = m_GrainIds[j]; int neighbor = m_Neighbors[j]; if (neighbor >= 0) { if ( (grainname == 0 && m_GrainIds[neighbor] > 0 && m_Direction == 1) || (grainname > 0 && m_GrainIds[neighbor] == 0 && m_Direction == 0)) { for(std::list<std::string>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { std::string name = *iter; IDataArray::Pointer p = m->getCellData(*iter); p->CopyTuple(neighbor, j); } } } } } // If there is an error set this to something negative and also set a message notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void QuickSolidMesh::execute() { setErrorCondition(0); VoxelDataContainer* m = getVoxelDataContainer(); SolidMeshDataContainer* sm = getSolidMeshDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); int64_t totalPoints = m->getTotalPoints(); size_t totalFields = m->getNumFieldTuples(); size_t totalEnsembles = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, totalFields, totalEnsembles); if (getErrorCondition() < 0) { 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 xP = dims[0]; size_t yP = dims[1]; size_t zP = dims[2]; float xRes = m->getXRes(); float yRes = m->getYRes(); float zRes = m->getZRes(); int numNodes = (xP+1)*(yP+1)*(zP+1); int numTetrahedrons = 6*(xP*yP*zP); size_t point; size_t nodeId1, nodeId2, nodeId3, nodeId4, nodeId5, nodeId6, nodeId7, nodeId8; StructArray<Node>::Pointer vertices = StructArray<Node>::CreateArray(numNodes, DREAM3D::CellData::SolidMeshNodes); StructArray<Tetrahedron>::Pointer tetrahedrons = StructArray<Tetrahedron>::CreateArray(numTetrahedrons, DREAM3D::CellData::SolidMeshTetrahedrons); Node* vertex = vertices.get()->GetPointer(0); Tetrahedron* tetrahedron = tetrahedrons.get()->GetPointer(0); for(size_t k = 0; k < zP; k++) { for(size_t j = 0; j < yP; j++) { for(size_t i = 0; i < xP; i++) { point = (k*xP*yP)+(j*xP)+i; nodeId1 = (k*(xP+1)*(yP+1)) + (j*(xP+1)) + i; vertex[nodeId1].coord[0] = (i*xRes) - (xRes/2.0); vertex[nodeId1].coord[1] = (j*yRes) - (yRes/2.0); vertex[nodeId1].coord[2] = (k*zRes) - (zRes/2.0); nodeId2 = (k*(xP+1)*(yP+1)) + (j*(xP+1)) + (i+1); vertex[nodeId2].coord[0] = ((i+1)*xRes) - (xRes/2.0); vertex[nodeId2].coord[1] = (j*yRes) - (yRes/2.0); vertex[nodeId2].coord[2] = (k*zRes) - (zRes/2.0); nodeId3 = (k*(xP+1)*(yP+1)) + ((j+1)*(xP+1)) + i; vertex[nodeId3].coord[0] = (i*xRes) - (xRes/2.0); vertex[nodeId3].coord[1] = ((j+1)*yRes) - (yRes/2.0); vertex[nodeId3].coord[2] = (k*zRes) - (zRes/2.0); nodeId4 = (k*(xP+1)*(yP+1)) + ((j+1)*(xP+1)) + (i+1); vertex[nodeId4].coord[0] = ((i+1)*xRes) - (xRes/2.0); vertex[nodeId4].coord[1] = ((j+1)*yRes) - (yRes/2.0); vertex[nodeId4].coord[2] = (k*zRes) - (zRes/2.0); nodeId5 = ((k+1)*(xP+1)*(yP+1)) + (j*(xP+1)) + i; vertex[nodeId5].coord[0] = (i*xRes) - (xRes/2.0); vertex[nodeId5].coord[1] = (j*yRes) - (yRes/2.0); vertex[nodeId5].coord[2] = ((k+1)*zRes) - (zRes/2.0); nodeId6 = ((k+1)*(xP+1)*(yP+1)) + (j*(xP+1)) + (i+1); vertex[nodeId6].coord[0] = ((i+1)*xRes) - (xRes/2.0); vertex[nodeId6].coord[1] = (j*yRes) - (yRes/2.0); vertex[nodeId6].coord[2] = ((k+1)*zRes) - (zRes/2.0); nodeId7 = ((k+1)*(xP+1)*(yP+1)) + ((j+1)*(xP+1)) + i; vertex[nodeId7].coord[0] = (i*xRes) - (xRes/2.0); vertex[nodeId7].coord[1] = ((j+1)*yRes) - (yRes/2.0); vertex[nodeId7].coord[2] = ((k+1)*zRes) - (zRes/2.0); nodeId8 = ((k+1)*(xP+1)*(yP+1)) + ((j+1)*(xP+1)) + (i+1); vertex[nodeId8].coord[0] = ((i+1)*xRes) - (xRes/2.0); vertex[nodeId8].coord[1] = ((j+1)*yRes) - (yRes/2.0); vertex[nodeId8].coord[2] = ((k+1)*zRes) - (zRes/2.0); tetrahedron[6*point].node_id[0] = nodeId1; tetrahedron[6*point].node_id[1] = nodeId2; tetrahedron[6*point].node_id[2] = nodeId3; tetrahedron[6*point].node_id[3] = nodeId7; tetrahedron[6*point].nSpin = m_GrainIds[point]; tetrahedron[6*point+1].node_id[0] = nodeId2; tetrahedron[6*point+1].node_id[1] = nodeId4; tetrahedron[6*point+1].node_id[2] = nodeId3; tetrahedron[6*point+1].node_id[3] = nodeId7; tetrahedron[6*point+1].nSpin = m_GrainIds[point]; tetrahedron[6*point+2].node_id[0] = nodeId1; tetrahedron[6*point+2].node_id[1] = nodeId2; tetrahedron[6*point+2].node_id[2] = nodeId7; tetrahedron[6*point+2].node_id[3] = nodeId5; tetrahedron[6*point+2].nSpin = m_GrainIds[point]; tetrahedron[6*point+3].node_id[0] = nodeId2; tetrahedron[6*point+3].node_id[1] = nodeId4; tetrahedron[6*point+3].node_id[2] = nodeId7; tetrahedron[6*point+3].node_id[3] = nodeId8; tetrahedron[6*point+3].nSpin = m_GrainIds[point]; tetrahedron[6*point+4].node_id[0] = nodeId2; tetrahedron[6*point+4].node_id[1] = nodeId5; tetrahedron[6*point+4].node_id[2] = nodeId6; tetrahedron[6*point+4].node_id[3] = nodeId7; tetrahedron[6*point+4].nSpin = m_GrainIds[point]; tetrahedron[6*point+5].node_id[0] = nodeId6; tetrahedron[6*point+5].node_id[1] = nodeId8; tetrahedron[6*point+5].node_id[2] = nodeId2; tetrahedron[6*point+5].node_id[3] = nodeId7; tetrahedron[6*point+5].nSpin = m_GrainIds[point]; } } } sm->setTetrahedrons(tetrahedrons); sm->setNodes(vertices); notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindNeighbors::execute() { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } int64_t totalPoints = m->getTotalPoints(); int totalFields = int(m->getNumFieldTuples()); dataCheck(false, totalPoints, totalFields, m->getNumEnsembleTuples()); if (getErrorCondition() < 0) { 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]), }; 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]; float column, row, plane; int grain; size_t nnum; int onsurf = 0; int good = 0; int neighbor = 0; //size_t xtalCount = m->getEnsembleData(DREAM3D::EnsembleData::CrystalStructures)->GetNumberOfTuples(); std::vector<std::vector<int> > neighborlist; std::vector<std::vector<float> > neighborsurfacearealist; int nListSize = 100; neighborlist.resize(totalFields); neighborsurfacearealist.resize(totalFields); for (int i = 1; i < totalFields; i++) { std::stringstream ss; ss << "Finding Neighbors - Initializing Neighbor Lists - " << (static_cast<float>(i)/totalFields)*100 << " Percent Complete"; // notifyStatusMessage(ss.str()); m_NumNeighbors[i] = 0; neighborlist[i].resize(nListSize); neighborsurfacearealist[i].resize(nListSize, -1.0); m_SurfaceFields[i] = false; } totalPoints = m->getTotalPoints(); for (int64_t j = 0; j < totalPoints; j++) { std::stringstream ss; ss << "Finding Neighbors - Determining Neighbor Lists - " << (static_cast<float>(j)/totalPoints)*100 << " Percent Complete"; // notifyStatusMessage(ss.str()); onsurf = 0; grain = m_GrainIds[j]; if(grain > 0) { column = static_cast<float>( j % m->getXPoints() ); row = static_cast<float>( (j / m->getXPoints()) % m->getYPoints() ); plane = static_cast<float>( j / (m->getXPoints() * m->getYPoints()) ); if((column == 0 || column == (m->getXPoints() - 1) || row == 0 || row == (m->getYPoints() - 1) || plane == 0 || plane == (m->getZPoints() - 1)) && m->getZPoints() != 1) { m_SurfaceFields[grain] = true; } if((column == 0 || column == (m->getXPoints() - 1) || row == 0 || row == (m->getYPoints() - 1)) && m->getZPoints() == 1) { m_SurfaceFields[grain] = true; } for (int k = 0; k < 6; k++) { good = 1; neighbor = static_cast<int>( j + neighpoints[k] ); if(k == 0 && plane == 0) good = 0; if(k == 5 && plane == (m->getZPoints() - 1)) good = 0; if(k == 1 && row == 0) good = 0; if(k == 4 && row == (m->getYPoints() - 1)) good = 0; if(k == 2 && column == 0) good = 0; if(k == 3 && column == (m->getXPoints() - 1)) good = 0; if(good == 1 && m_GrainIds[neighbor] != grain && m_GrainIds[neighbor] > 0) { onsurf++; nnum = m_NumNeighbors[grain]; neighborlist[grain].push_back(m_GrainIds[neighbor]); nnum++; m_NumNeighbors[grain] = static_cast<int32_t>(nnum); } } } m_SurfaceVoxels[j] = onsurf; } // We do this to create new set of NeighborList objects dataCheck(false, totalPoints, totalFields, m->getNumEnsembleTuples()); for (size_t i = 1; i < m->getNumFieldTuples(); i++) { std::stringstream ss; ss << "Finding Neighbors - Calculating Surface Areas - " << ((float)i/totalFields)*100 << " Percent Complete"; // notifyStatusMessage(ss.str()); std::map<int, int> neighToCount; int numneighs = static_cast<int>( neighborlist[i].size() ); // this increments the voxel counts for each grain for (int j = 0; j < numneighs; j++) { neighToCount[neighborlist[i][j]]++; } neighToCount.erase(0); neighToCount.erase(-1); //Resize the grains neighbor list to zero neighborlist[i].resize(0); neighborsurfacearealist[i].resize(0); for (std::map<int, int>::iterator iter = neighToCount.begin(); iter != neighToCount.end(); ++iter) { int neigh = iter->first; // get the neighbor grain int number = iter->second; // get the number of voxels float area = number * m->getXRes() * m->getYRes(); // Push the neighbor grain id back onto the list so we stay synced up neighborlist[i].push_back(neigh); neighborsurfacearealist[i].push_back(area); } m_NumNeighbors[i] = int32_t( neighborlist[i].size() ); // Set the vector for each list into the NeighborList Object NeighborList<int>::SharedVectorType sharedNeiLst(new std::vector<int>); sharedNeiLst->assign(neighborlist[i].begin(), neighborlist[i].end()); m_NeighborList->setList(static_cast<int>(i), sharedNeiLst); NeighborList<float>::SharedVectorType sharedSAL(new std::vector<float>); sharedSAL->assign(neighborsurfacearealist[i].begin(), neighborsurfacearealist[i].end()); m_SharedSurfaceAreaList->setList(static_cast<int>(i), sharedSAL); } notifyStatusMessage("Finding Neighbors Complete"); }