Exemple #1
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
Exemple #2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FindNeighbors::execute()
{
    setErrorCondition(0);
    dataCheck();
    if(getErrorCondition() < 0) {
        return;
    }

    DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName());
    size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples();
    size_t totalFeatures = m_NumNeighborsPtr.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]),
    };

    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];

    DimType column = 0, row = 0, plane = 0;
    int32_t feature = 0;
    int32_t nnum = 0;
    int8_t onsurf = 0;
    bool good = false;
    DimType neighbor = 0;

    std::vector<std::vector<int32_t> > neighborlist;
    std::vector<std::vector<float> > neighborsurfacearealist;

    int32_t nListSize = 100;
    neighborlist.resize(totalFeatures);
    neighborsurfacearealist.resize(totalFeatures);

    uint64_t millis = QDateTime::currentMSecsSinceEpoch();
    uint64_t currentMillis = millis;

    for (size_t i = 1; i < totalFeatures; i++)
    {
        currentMillis = QDateTime::currentMSecsSinceEpoch();
        if (currentMillis - millis > 1000)
        {
            QString ss = QObject::tr("Finding Neighbors || Initializing Neighbor Lists || %1% Complete").arg((static_cast<float>(i) / totalFeatures) * 100);
            notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
            millis = QDateTime::currentMSecsSinceEpoch();
        }

        if (getCancel() == true) {
            return;
        }

        m_NumNeighbors[i] = 0;
        neighborlist[i].resize(nListSize);
        neighborsurfacearealist[i].assign(nListSize, -1.0f);
        if (m_StoreSurfaceFeatures == true) {
            m_SurfaceFeatures[i] = false;
        }

    }

    for (size_t j = 0; j < totalPoints; j++)
    {
        currentMillis = QDateTime::currentMSecsSinceEpoch();
        if (currentMillis - millis > 1000)
        {
            QString ss = QObject::tr("Finding Neighbors || Determining Neighbor Lists || %1% Complete").arg((static_cast<float>(j) / totalPoints) * 100);
            notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
            millis = QDateTime::currentMSecsSinceEpoch();
        }

        if (getCancel() == true) {
            return;
        }

        onsurf = 0;
        feature = m_FeatureIds[j];
        if (feature > 0)
        {
            column = static_cast<DimType>( j % m->getGeometryAs<ImageGeom>()->getXPoints() );
            row = static_cast<DimType>( (j / m->getGeometryAs<ImageGeom>()->getXPoints()) % m->getGeometryAs<ImageGeom>()->getYPoints() );
            plane = static_cast<DimType>( j / (m->getGeometryAs<ImageGeom>()->getXPoints() * m->getGeometryAs<ImageGeom>()->getYPoints()) );
            if (m_StoreSurfaceFeatures == true)
            {
                if ((column == 0 || column == DimType((m->getGeometryAs<ImageGeom>()->getXPoints() - 1))
                        || row == 0 || row == DimType((m->getGeometryAs<ImageGeom>()->getYPoints()) - 1)
                        || plane == 0 || plane == DimType((m->getGeometryAs<ImageGeom>()->getZPoints() - 1)))
                        && m->getGeometryAs<ImageGeom>()->getZPoints() != 1)
                {
                    m_SurfaceFeatures[feature] = true;
                }
                if ((column == 0 || column == DimType((m->getGeometryAs<ImageGeom>()->getXPoints() - 1)) || row == 0 || row == DimType((m->getGeometryAs<ImageGeom>()->getYPoints() - 1))) && m->getGeometryAs<ImageGeom>()->getZPoints() == 1)
                {
                    m_SurfaceFeatures[feature] = true;
                }
            }
            for (int32_t k = 0; k < 6; k++)
            {
                good = true;
                neighbor = static_cast<DimType>( j + neighpoints[k] );
                if (k == 0 && plane == 0) {
                    good = false;
                }
                if (k == 5 && plane == (m->getGeometryAs<ImageGeom>()->getZPoints() - 1)) {
                    good = false;
                }
                if (k == 1 && row == 0) {
                    good = false;
                }
                if (k == 4 && row == (m->getGeometryAs<ImageGeom>()->getYPoints() - 1)) {
                    good = false;
                }
                if (k == 2 && column == 0) {
                    good = false;
                }
                if (k == 3 && column == (m->getGeometryAs<ImageGeom>()->getXPoints() - 1)) {
                    good = false;
                }
                if (good == true && m_FeatureIds[neighbor] != feature && m_FeatureIds[neighbor] > 0)
                {
                    onsurf++;
                    nnum = m_NumNeighbors[feature];
                    neighborlist[feature].push_back(m_FeatureIds[neighbor]);
                    nnum++;
                    m_NumNeighbors[feature] = nnum;
                }
            }
        }
        if (m_StoreBoundaryCells == true) {
            m_BoundaryCells[j] = onsurf;
        }
    }

    // We do this to create new set of NeighborList objects
    for (size_t i = 1; i < totalFeatures; i++)
    {
        currentMillis = QDateTime::currentMSecsSinceEpoch();
        if (currentMillis - millis > 1000)
        {
            QString ss = QObject::tr("Finding Neighbors || Calculating Surface Areas || %1% Complete").arg(((float)i / totalFeatures) * 100);
            notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
            millis = QDateTime::currentMSecsSinceEpoch();
        }

        if(getCancel() == true) {
            return;
        }


        QMap<int32_t, int32_t> neighToCount;
        int32_t numneighs = static_cast<int32_t>( neighborlist[i].size() );

        // this increments the voxel counts for each feature
        for (int32_t j = 0; j < numneighs; j++)
        {
            neighToCount[neighborlist[i][j]]++;
        }

        QMap<int32_t, int32_t>::Iterator neighiter = neighToCount.find(0);
        neighToCount.erase(neighiter);
        neighiter = neighToCount.find(-1);
        neighToCount.erase(neighiter);
        // Resize the features neighbor list to zero
        neighborlist[i].resize(0);
        neighborsurfacearealist[i].resize(0);

        for (QMap<int32_t, int32_t>::iterator iter = neighToCount.begin(); iter != neighToCount.end(); ++iter)
        {
            int32_t neigh = iter.key(); // get the neighbor feature
            int32_t number = iter.value(); // get the number of voxels
            float area = float(number) * m->getGeometryAs<ImageGeom>()->getXRes() * m->getGeometryAs<ImageGeom>()->getYRes();

            // Push the neighbor feature 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<int32_t>::SharedVectorType sharedNeiLst(new std::vector<int32_t>);
        sharedNeiLst->assign(neighborlist[i].begin(), neighborlist[i].end());
        m_NeighborList.lock()->setList(static_cast<int32_t>(i), sharedNeiLst);

        NeighborList<float>::SharedVectorType sharedSAL(new std::vector<float>);
        sharedSAL->assign(neighborsurfacearealist[i].begin(), neighborsurfacearealist[i].end());
        m_SharedSurfaceAreaList.lock()->setList(static_cast<int32_t>(i), sharedSAL);
    }

    notifyStatusMessage(getHumanLabel(), "Complete");
}