// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AlignSectionsFeature::execute()
{
  setErrorCondition(0);
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    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;
  }

  AlignSections::execute();

  // If there is an error set this to something negative and also set a message
 notifyStatusMessage("Aligning Sections Complete");
}
示例#2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void  AddOrientationNoise::add_orientation_noise()
{
 notifyStatusMessage("Adding Orientation Noise");
  DREAM3D_RANDOMNG_NEW()

  VoxelDataContainer* m = getVoxelDataContainer();

  //float ea1, ea2, ea3;
  float g[3][3];
  float newg[3][3];
  float rot[3][3];
  float w, n1, n2, n3;
  int64_t totalPoints = m->getTotalPoints();
  for (size_t i = 0; i < static_cast<size_t>(totalPoints); ++i)
  {
    float ea1 = m_CellEulerAngles[3*i+0];
    float ea2 = m_CellEulerAngles[3*i+1];
    float ea3 = m_CellEulerAngles[3*i+2];
    OrientationMath::EulertoMat(ea1, ea2, ea3, g);
    n1 = static_cast<float>( rg.genrand_res53() );
    n2 = static_cast<float>( rg.genrand_res53() );
    n3 = static_cast<float>( rg.genrand_res53() );
    w = static_cast<float>( rg.genrand_res53() );
    w = 2.0*(w-0.5);
    w = (m_Magnitude*w);
    OrientationMath::AxisAngletoMat(w, n1, n2, n3, rot);
    MatrixMath::Multiply3x3with3x3(g, rot, newg);
    OrientationMath::MattoEuler(newg, ea1, ea2, ea3);
    m_CellEulerAngles[3*i+0] = ea1;
    m_CellEulerAngles[3*i+1] = ea2;
    m_CellEulerAngles[3*i+2] = ea3;
  }
}
示例#3
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AddOrientationNoise::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;
  }

  int64_t totalPoints = m->getTotalPoints();
  size_t totalFields = m->getNumFieldTuples();

  dataCheck(false, totalPoints, totalFields, m->getNumEnsembleTuples());
  if (getErrorCondition() < 0)
  {
    return;
  }

  m_Magnitude = m_Magnitude*m_pi/180.0;

  add_orientation_noise();

  // If there is an error set this to something negative and also set a message
 notifyStatusMessage("AddOrientationNoises Completed");
}
示例#4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FlattenImage::execute()
{
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);
  int64_t totalPoints = m->getTotalPoints();
  size_t numgrains = m->getNumFieldTuples();
  size_t numensembles = m->getNumEnsembleTuples();
  dataCheck(false, totalPoints, numgrains, numensembles);
  if (getErrorCondition() < 0)
  {
    return;
  }

  float Rfactor = 1.0;
  float Gfactor = 1.0;
  float Bfactor = 1.0;
  if (m_FlattenMethod == DREAM3D::FlattenImageMethod::Average)
  {
    Rfactor = 1.0/3.0;
    Gfactor = 1.0/3.0;
    Bfactor = 1.0/3.0;
  }
  else if (m_FlattenMethod == DREAM3D::FlattenImageMethod::Luminosity)
  {
    Rfactor = 0.21;
    Gfactor = 0.72;
    Bfactor = 0.07;
  }

#ifdef DREAM3D_USE_PARALLEL_ALGORITHMS
  tbb::task_scheduler_init init;
  bool doParallel = true;
#endif

  size_t comp = m->getCellData(m_ImageDataArrayName)->GetNumberOfComponents();

  //  std::cout << "FlattenImage: " << m_ConversionFactor << std::endl;
#ifdef DREAM3D_USE_PARALLEL_ALGORITHMS
  if (doParallel == true)
  {
    tbb::parallel_for(tbb::blocked_range<size_t>(0, totalPoints),
                      FlattenImageImpl(m_ImageData, m_FlatImageData, Rfactor, Gfactor, Bfactor, comp), tbb::auto_partitioner());

  }
  else
#endif
  {
    FlattenImageImpl serial(m_ImageData, m_FlatImageData, Rfactor, Gfactor, Bfactor, comp);
    serial.convert(0, totalPoints);
  }

  notifyStatusMessage("Complete");
}
示例#5
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
示例#6
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ReadH5Ebsd::copyHEDMArrays(H5EbsdVolumeReader* ebsdReader)
{
  float* f1 = NULL;
  float* f2 = NULL;
  float* f3 = NULL;
  int* phasePtr = NULL;

  FloatArrayType::Pointer fArray = FloatArrayType::NullPointer();
  Int32ArrayType::Pointer iArray = Int32ArrayType::NullPointer();
  VoxelDataContainer* m = getVoxelDataContainer();
  int64_t totalPoints = m->getTotalPoints();


  if (m_SelectedVoxelCellArrays.find(m_CellEulerAnglesArrayName) != m_SelectedVoxelCellArrays.end() )
  {
    //  radianconversion = M_PI / 180.0;
    f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Mic::Euler1));
    f2 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Mic::Euler2));
    f3 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Mic::Euler3));
    fArray = FloatArrayType::CreateArray(totalPoints * 3, DREAM3D::CellData::EulerAngles);
    fArray->SetNumberOfComponents(3);
    float* cellEulerAngles = fArray->GetPointer(0);
    for (int64_t i = 0; i < totalPoints; i++)
    {
      cellEulerAngles[3 * i] = f1[i];
      cellEulerAngles[3 * i + 1] = f2[i];
      cellEulerAngles[3 * i + 2] = f3[i];
    }
    m->addCellData(DREAM3D::CellData::EulerAngles, fArray);
  }

  if (m_SelectedVoxelCellArrays.find(m_CellPhasesArrayName) != m_SelectedVoxelCellArrays.end() )
  {
    phasePtr = reinterpret_cast<int*>(ebsdReader->getPointerByName(Ebsd::Mic::Phase));
    iArray = Int32ArrayType::CreateArray(totalPoints, DREAM3D::CellData::Phases);
    iArray->SetNumberOfComponents(1);
    ::memcpy(iArray->GetPointer(0), phasePtr, sizeof(int32_t) * totalPoints);
    m->addCellData(DREAM3D::CellData::Phases, iArray);
  }

  if (m_SelectedVoxelCellArrays.find(Ebsd::Mic::Confidence) != m_SelectedVoxelCellArrays.end() )
  {
    f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Mic::Confidence));
    fArray = FloatArrayType::CreateArray(totalPoints, Ebsd::Mic::Confidence);
    fArray->SetNumberOfComponents(1);
    ::memcpy(fArray->GetPointer(0), f1, sizeof(float) * totalPoints);
    m->addCellData(Ebsd::Mic::Confidence, fArray);
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AvizoRectilinearCoordinateWriter::execute()
{
  int err = 0;
  setErrorCondition(err);
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);

  // Make sure any directory path is also available as the user may have just typed
  // in a path without actually creating the full path
  std::string parentPath = MXAFileInfo::parentPath(m_OutputFile);
  if(!MXADir::mkdir(parentPath, true))
  {
    std::stringstream ss;
    ss << "Error creating parent path '" << parentPath << "'";
    notifyErrorMessage(ss.str(), -1);
    setErrorCondition(-1);
    return;
  }

  int64_t totalPoints = m->getTotalPoints();
  size_t totalFields = m->getNumFieldTuples();
  size_t totalEnsembleTuples = m->getNumEnsembleTuples();

  dataCheck(false, totalPoints, totalFields, totalEnsembleTuples);

  MXAFileWriter64 writer(m_OutputFile);
  if(false == writer.initWriter())
  {
    std::stringstream ss;
    ss << "Error opening file '" << parentPath << "'";
    notifyErrorMessage(ss.str(), -1);
    setErrorCondition(-1);
    return;
  }

  std::string header = generateHeader();
  writer.writeString(header);

  err = writeData(writer);

  /* Let the GUI know we are done with this filter */
  notifyStatusMessage("Complete");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void LinkFieldMapToCellArray::execute()
{
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);
  int64_t voxels = m->getTotalPoints();
  int64_t fields = m->getNumFieldTuples();
  dataCheck(false, voxels, fields, m->getNumEnsembleTuples());
  if (getErrorCondition() < 0)
  {
    return;
  }
  //int err = 0;
  std::stringstream ss;

  m->clearFieldData();

  int maxIndex = 0;
  std::vector<bool> active;
  for(int64_t i=0;i<voxels;i++)
  {
    int index = m_SelectedCellData[i];
    if((index+1) > maxIndex)
    {
      active.resize(index+1);
      active[index] = true;
      maxIndex = index+1;
    }
  }

  BoolArrayType::Pointer m_Active = BoolArrayType::CreateArray(maxIndex, 1, DREAM3D::FieldData::Active);
  bool* mActive = m_Active->GetPointer(0);
  for(int i=0;i<maxIndex;i++)
  {
    mActive[i] = active[i];
  }
  m->addFieldData(DREAM3D::FieldData::Active, m_Active);

  notifyStatusMessage("Complete");
}
示例#9
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void UpdateCellQuats::execute()
{
  setErrorCondition(0);
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);
  std::stringstream ss;

  int64_t totalPoints = m->getTotalPoints();

  //getting the 5 component quaternions from the data container and down-casting them
  IDataArray::Pointer Quats5 = m->getCellData(DREAM3D::CellData::Quats);
  if(Quats5->GetNumberOfComponents() != 5)
  {
    notifyErrorMessage("The Quats array did not contain 5 components", -999);
    return;
  }
  DataArray<float>* quats5 = DataArray<float>::SafePointerDownCast(Quats5.get());
  float* quats5ptr = quats5->GetPointer(0);
  //creating the 4 component quaternions in the data container
  CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, Quats, ss, float, FloatArrayType, 0, totalPoints, 4)

  if (getErrorCondition() < 0)
  {
    return;
  }

  //copying the 5 component quaternions into the new 4 component quaternions
  // This is a special case for dealing with this conversion. If you are dealing with
  // quaternions then DO NOT USE THIS CODE as an example. Use another filter instead.
  for (int i = 0; i < totalPoints; i++)
  {
    for(int j=0;j<4;j++)
    {
      m_Quats[4*i+j] = quats5ptr[5*i+(j+1)];
    }
  }

  notifyStatusMessage("Complete");
}
示例#10
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RotateEulerRefFrame::execute()
{
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);
  int64_t totalPoints = m->getTotalPoints();
  size_t numgrains = m->getNumFieldTuples();
  size_t numensembles = m->getNumEnsembleTuples();
  dataCheck(false, totalPoints, numgrains, numensembles);
  if (getErrorCondition() < 0)
  {
    return;
  }


#ifdef DREAM3D_USE_PARALLEL_ALGORITHMS
  tbb::task_scheduler_init init;
  bool doParallel = true;
#endif

#ifdef DREAM3D_USE_PARALLEL_ALGORITHMS
  if (doParallel == true)
  {
    tbb::parallel_for(tbb::blocked_range<size_t>(0, totalPoints),
                      RotateEulerRefFrameImpl(m_CellEulerAngles, m_RotationAngle, m_RotationAxis), tbb::auto_partitioner());

  }
  else
#endif
  {
    RotateEulerRefFrameImpl serial(m_CellEulerAngles, m_RotationAngle, m_RotationAxis);
    serial.convert(0, totalPoints);
  }

  notifyStatusMessage("Complete");
}
示例#11
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void PerPhaseMinSize::remove_smallgrains()
{
  VoxelDataContainer* m = getVoxelDataContainer();
  int64_t totalPoints = m->getTotalPoints();

  bool good = false;

  int gnum;

  int numgrains = m->getNumFieldTuples();

  std::vector<int> voxcounts;
  voxcounts.resize(numgrains,0);
  for (int64_t i = 0; i < totalPoints; i++)
  {
    gnum = m_GrainIds[i];
    if(gnum >= 0) voxcounts[gnum]++;
  }
  for (size_t i = 1; i <  static_cast<size_t>(numgrains); i++)
  {
    m_Active[i] = true;
    if(voxcounts[i] >= getMinAllowedGrainSize() || m_FieldPhases[i] != m_PhaseNumber) good = true;
  }
  if(good == false)
  {
    setErrorCondition(-1);
    notifyErrorMessage("The minimum size is larger than the largest Field.  All Fields would be removed.  The filter has quit.", -1);
    return;
  }
  for (int64_t i = 0; i < totalPoints; i++)
  {
    gnum = m_GrainIds[i];
    if(voxcounts[gnum] < getMinAllowedGrainSize() && m_CellPhases[i] == m_PhaseNumber && gnum > 0)
    {
      m_GrainIds[i] = -1;
      m_Active[gnum] = false;
    }
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FindCellQuats::execute()
{
  setErrorCondition(0);
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);
  std::stringstream ss;

  int64_t totalPoints = m->getTotalPoints();
  size_t totalFields = m->getNumFieldTuples();
  size_t totalEnsembles = m->getNumEnsembleTuples();
  dataCheck(false, totalPoints, totalFields, totalEnsembles);
  if (getErrorCondition() < 0)
  {
    return;
  }

  QuatF* quats = reinterpret_cast<QuatF*>(m_Quats);
  QuatF qr;
  int phase = -1;
  for (int i = 0; i < totalPoints; i++)
  {
    phase = m_CellPhases[i];
    OrientationMath::EulertoQuat(qr, m_CellEulerAngles[3 * i], m_CellEulerAngles[3 * i + 1], m_CellEulerAngles[3 * i + 2]);
    QuaternionMathF::UnitQuaternion(qr);
    if (m_CrystalStructures[phase] == Ebsd::CrystalStructure::UnknownCrystalStructure)
    {
      QuaternionMathF::Identity(qr);
    }
    QuaternionMathF::Copy(qr, quats[i]);
  }

  notifyStatusMessage("Complete");
}
示例#13
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
示例#14
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
示例#15
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");
}
示例#16
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ReadH5Ebsd::copyTSLArrays(H5EbsdVolumeReader* ebsdReader)
{
  float* f1 = NULL;
  float* f2 = NULL;
  float* f3 = NULL;
  int* phasePtr = NULL;

  FloatArrayType::Pointer fArray = FloatArrayType::NullPointer();
  Int32ArrayType::Pointer iArray = Int32ArrayType::NullPointer();
  VoxelDataContainer* m = getVoxelDataContainer();
  int64_t totalPoints = m->getTotalPoints();

  if (m_SelectedVoxelCellArrays.find(m_CellPhasesArrayName) != m_SelectedVoxelCellArrays.end() )
  {
    phasePtr = reinterpret_cast<int*>(ebsdReader->getPointerByName(Ebsd::Ang::PhaseData));
    iArray = Int32ArrayType::CreateArray(totalPoints, DREAM3D::CellData::Phases);
    iArray->SetNumberOfComponents(1);
    ::memcpy(iArray->GetPointer(0), phasePtr, sizeof(int32_t) * totalPoints);
    m->addCellData(DREAM3D::CellData::Phases, iArray);
  }

  if (m_SelectedVoxelCellArrays.find(m_CellEulerAnglesArrayName) != m_SelectedVoxelCellArrays.end() )
  {
    f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Ang::Phi1));
    f2 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Ang::Phi));
    f3 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Ang::Phi2));
    fArray = FloatArrayType::CreateArray(totalPoints, 3, DREAM3D::CellData::EulerAngles);
    float* cellEulerAngles = fArray->GetPointer(0);

    for (int64_t i = 0; i < totalPoints; i++)
    {
      cellEulerAngles[3 * i] = f1[i];
      cellEulerAngles[3 * i + 1] = f2[i];
      cellEulerAngles[3 * i + 2] = f3[i];
    }
    m->addCellData(DREAM3D::CellData::EulerAngles, fArray);
  }

  if (m_SelectedVoxelCellArrays.find(Ebsd::Ang::ImageQuality) != m_SelectedVoxelCellArrays.end() )
  {
    f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Ang::ImageQuality));
    fArray = FloatArrayType::CreateArray(totalPoints, Ebsd::Ang::ImageQuality);
    ::memcpy(fArray->GetPointer(0), f1, sizeof(float) * totalPoints);
    m->addCellData(Ebsd::Ang::ImageQuality, fArray);
  }

  if (m_SelectedVoxelCellArrays.find(Ebsd::Ang::ConfidenceIndex) != m_SelectedVoxelCellArrays.end() )
  {
    f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Ang::ConfidenceIndex));
    fArray = FloatArrayType::CreateArray(totalPoints, Ebsd::Ang::ConfidenceIndex);
    ::memcpy(fArray->GetPointer(0), f1, sizeof(float) * totalPoints);
    m->addCellData(Ebsd::Ang::ConfidenceIndex, fArray);
  }

  if (m_SelectedVoxelCellArrays.find(Ebsd::Ang::SEMSignal) != m_SelectedVoxelCellArrays.end() )
  {
    f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Ang::SEMSignal));
    fArray = FloatArrayType::CreateArray(totalPoints, Ebsd::Ang::SEMSignal);
    ::memcpy(fArray->GetPointer(0), f1, sizeof(float) * totalPoints);
    m->addCellData(Ebsd::Ang::SEMSignal, fArray);
  }

  if (m_SelectedVoxelCellArrays.find(Ebsd::Ang::Fit) != m_SelectedVoxelCellArrays.end() )
  {
    f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Ang::Fit));
    fArray = FloatArrayType::CreateArray(totalPoints, Ebsd::Ang::Fit);
    ::memcpy(fArray->GetPointer(0), f1, sizeof(float) * totalPoints);
    m->addCellData(Ebsd::Ang::Fit, fArray);
  }
}
示例#17
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ReadH5Ebsd::execute()
{
  std::stringstream ss;
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-1);
    ss << " DataContainer was NULL";
    addErrorMessage(getHumanLabel(), ss.str(), -1);
    return;
  }
  int err = 0;
  setErrorCondition(err);
  std::string manufacturer;
  // Get the Size and Resolution of the Volume
  {
    H5EbsdVolumeInfo::Pointer volumeInfoReader = H5EbsdVolumeInfo::New();
    volumeInfoReader->setFileName(m_InputFile);
    err = volumeInfoReader->readVolumeInfo();
    setErrorCondition(err);
    int64_t dims[3];
    float res[3];
    volumeInfoReader->getDimsAndResolution(dims[0], dims[1], dims[2], res[0], res[1], res[2]);
    /* Sanity check what we are trying to load to make sure it can fit in our address space.
     * Note that this does not guarantee the user has enough left, just that the
     * size of the volume can fit in the address space of the program
     */
#if   (CMP_SIZEOF_SSIZE_T==4)
    int64_t max = std::numeric_limits<size_t>::max();
#else
    int64_t max = std::numeric_limits<int64_t>::max();
#endif
    if(dims[0] * dims[1] * dims[2] > max)
    {
      err = -1;
      std::stringstream s;
      s << "The total number of elements '" << (dims[0] * dims[1] * dims[2]) << "' is greater than this program can hold. Try the 64 bit version.";
      setErrorCondition(err);
      addErrorMessage(getHumanLabel(), s.str(), -1);
      return;
    }

    if(dims[0] > max || dims[1] > max || dims[2] > max)
    {
      err = -1;
      std::stringstream s;
      s << "One of the dimensions is greater than the max index for this sysem. Try the 64 bit version.";
      s << " dim[0]=" << dims[0] << "  dim[1]=" << dims[1] << "  dim[2]=" << dims[2];
      setErrorCondition(err);
      addErrorMessage(getHumanLabel(), s.str(), -1);
      return;
    }
    /* ************ End Sanity Check *************************** */
    size_t dcDims[3] =
    { dims[0], dims[1], dims[2] };
    m->setDimensions(dcDims);
    m->setResolution(res);
    //Now Calculate our "subvolume" of slices, ie, those start and end values that the user selected from the GUI
    dcDims[2] = m_ZEndIndex - m_ZStartIndex + 1;
    m->setDimensions(dcDims);
    manufacturer = volumeInfoReader->getManufacturer();
    m_RefFrameZDir = volumeInfoReader->getStackingOrder();
    m_SampleTransformationAngle = volumeInfoReader->getSampleTransformationAngle();
    m_SampleTransformationAxis = volumeInfoReader->getSampleTransformationAxis();
    m_EulerTransformationAngle = volumeInfoReader->getEulerTransformationAngle();
    m_EulerTransformationAxis = volumeInfoReader->getEulerTransformationAxis();
    volumeInfoReader = H5EbsdVolumeInfo::NullPointer();
  }
  H5EbsdVolumeReader::Pointer ebsdReader;
  if(manufacturer.compare(Ebsd::Ang::Manufacturer) == 0)
  {
    ebsdReader = initTSLEbsdVolumeReader();
  }
  else if(manufacturer.compare(Ebsd::Ctf::Manufacturer) == 0)
  {
    ebsdReader = initHKLEbsdVolumeReader();
  }
  else if(manufacturer.compare(Ebsd::Mic::Manufacturer) == 0)
  {
    ebsdReader = initHEDMEbsdVolumeReader();
  }
  else
  {
    setErrorCondition(-1);
    std::string msg("Could not determine or match a supported manufacturer from the data file.");
    msg = msg.append("Supported manufacturer codes are: ").append(Ebsd::Ctf::Manufacturer);
    msg = msg.append(", ").append(Ebsd::Ang::Manufacturer).append(" and ").append(Ebsd::Mic::Manufacturer);
    addErrorMessage(getHumanLabel(), msg, -1);
    return;
  }

  // Sanity Check the Error Condition or the state of the EBSD Reader Object.
  if(getErrorCondition() < 0 || NULL == ebsdReader.get())
  {
    return;
  }

  // Initialize all the arrays with some default values
  int64_t totalPoints = m->getTotalPoints();
  ss.str("");
  ss << " - Initializing " << totalPoints << " voxels";
  notifyStatusMessage(ss.str());

  ss.str("");
  ss << " - Reading Ebsd Data from file";
  notifyStatusMessage(ss.str());
  ebsdReader->setSliceStart(m_ZStartIndex);
  ebsdReader->setSliceEnd(m_ZEndIndex);
  ebsdReader->readAllArrays(false);
  ebsdReader->setArraysToRead(m_SelectedVoxelCellArrays);
  err = ebsdReader->loadData(m->getXPoints(), m->getYPoints(), m->getZPoints(), m_RefFrameZDir);
  if(err < 0)
  {
    setErrorCondition(err);
    PipelineMessage em (getHumanLabel(), "Error Loading Data from Ebsd Data file.", -1);
    addErrorMessage(em);
    return;
  }


  typedef DataArray<unsigned int> XTalStructArrayType;
  GET_PREREQ_DATA(m, DREAM3D, EnsembleData, CrystalStructures, ss, -304, unsigned int, XTalStructArrayType, m->getNumEnsembleTuples(), 1)
  GET_PREREQ_DATA(m, DREAM3D, EnsembleData, LatticeConstants, ss, -305, float, FloatArrayType, m->getNumEnsembleTuples(), 6)

  // Copy the data from the pointers embedded in the reader object into our data container (Cell array).
  if(manufacturer.compare(Ebsd::Ang::Manufacturer) == 0)
  {
    copyTSLArrays(ebsdReader.get());
  }
  else if(manufacturer.compare(Ebsd::Ctf::Manufacturer) == 0)
  {
    copyHKLArrays(ebsdReader.get());
  }
  else if(manufacturer.compare(Ebsd::Mic::Manufacturer) == 0)
  {
    copyHEDMArrays(ebsdReader.get());
  }
  else
  {
    std::string msg("Could not determine or match a supported manufacturer from the data file.");
    msg = msg.append("Supported manufacturer codes are: ").append(Ebsd::Ctf::Manufacturer);
    msg = msg.append(" and ").append(Ebsd::Ang::Manufacturer);
    addErrorMessage(getHumanLabel(), msg, -10001);
    return;
  }

  if(m_UseTransformations == true)
  {
    if(m_EulerTransformationAngle > 0)
    {
      FloatVec3Widget_t eulerAxis;
      eulerAxis.x = m_EulerTransformationAxis[0];
      eulerAxis.y = m_EulerTransformationAxis[1];
      eulerAxis.z = m_EulerTransformationAxis[2];

      RotateEulerRefFrame::Pointer rot_Euler = RotateEulerRefFrame::New();
      rot_Euler->setObservers(this->getObservers());
      rot_Euler->setVoxelDataContainer(getVoxelDataContainer());
      rot_Euler->setRotationAngle(m_EulerTransformationAngle);
      rot_Euler->setRotationAxis(eulerAxis);
      rot_Euler->execute();
    }

    if(m_SampleTransformationAngle > 0)
    {
      FloatVec3Widget_t sampleAxis;
      sampleAxis.x = m_SampleTransformationAxis[0];
      sampleAxis.y = m_SampleTransformationAxis[1];
      sampleAxis.z = m_SampleTransformationAxis[2];

      RotateSampleRefFrame::Pointer rot_Sample = RotateSampleRefFrame::New();
      rot_Sample->setObservers(this->getObservers());
      rot_Sample->setVoxelDataContainer(getVoxelDataContainer());
      rot_Sample->setRotationAngle(m_SampleTransformationAngle);
      rot_Sample->setRotationAxis(sampleAxis);
      rot_Sample->setsliceBySlice(true);
      rot_Sample->execute();
    }
  }

  // If there is an error set this to something negative and also set a message
  ss.str("");
  ss << getHumanLabel() << " Completed";
  notifyStatusMessage(ss.str());
}
示例#18
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
示例#19
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
示例#20
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FindAxisODF::execute()
{
  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;
  }

  StatsDataArray& statsDataArray = *m_StatsDataArray;

  typedef DataArray<unsigned int> XTalType;
  XTalType* crystruct = XTalType::SafeObjectDownCast<IDataArray*, XTalType*>(m->getEnsembleData(DREAM3D::EnsembleData::CrystalStructures).get());

  float r1, r2, r3;
  int bin;
  std::vector<FloatArrayType::Pointer> axisodf;
  std::vector<float> totalaxes;
  size_t numXTals = crystruct->GetNumberOfTuples();
  axisodf.resize(numXTals);
  totalaxes.resize(numXTals);
  for (size_t i = 1; i < numXTals; i++)
  {
    totalaxes[i] = 0.0;
    axisodf[i] = FloatArrayType::CreateArray((36 * 36 * 36), DREAM3D::HDF5::AxisOrientation);
    for (int j = 0; j < (36 * 36 * 36); j++)
    {
      axisodf[i]->SetValue(j, 0.0);
    }
  }
  size_t numgrains = m->getNumFieldTuples();
  for (size_t i = 0; i < numgrains; i++)
  {
    if(m_SurfaceFields[i] == false)
    {
      totalaxes[m_FieldPhases[i]]++;
    }
  }
  for (size_t i = 1; i < numgrains; i++)
  {
    float ea1 = m_AxisEulerAngles[3 * i];
    float ea2 = m_AxisEulerAngles[3 * i + 1];
    float ea3 = m_AxisEulerAngles[3 * i + 2];
    if(m_SurfaceFields[i] == 0)
    {
      OrientationMath::EulerToRod( ea1,  ea2,  ea3, r1,  r2,  r3);
      m_OrientationOps[Ebsd::CrystalStructure::OrthoRhombic]->getODFFZRod(r1, r2, r3);
      bin = m_OrientationOps[Ebsd::CrystalStructure::OrthoRhombic]->getOdfBin(r1, r2, r3);
      axisodf[m_FieldPhases[i]]->SetValue(bin, (axisodf[m_FieldPhases[i]]->GetValue(bin) + static_cast<float>((1.0 / totalaxes[m_FieldPhases[i]]))));
    }
  }
  // int err;
  for (size_t i = 1; i < numXTals; i++)
  {
    if(m_PhaseTypes[i] == DREAM3D::PhaseType::PrimaryPhase)
    {
      PrimaryStatsData* pp = PrimaryStatsData::SafePointerDownCast(statsDataArray[i].get());
      pp->setAxisOrientation(axisodf[i]);
    }
    if(m_PhaseTypes[i] == DREAM3D::PhaseType::PrecipitatePhase)
    {
      PrecipitateStatsData* pp = PrecipitateStatsData::SafePointerDownCast(statsDataArray[i].get());
      pp->setAxisOrientation(axisodf[i]);
    }
    if(m_PhaseTypes[i] == DREAM3D::PhaseType::TransformationPhase)
    {
      TransformationStatsData* tp = TransformationStatsData::SafePointerDownCast(statsDataArray[i].get());
      tp->setAxisOrientation(axisodf[i]);
    }
  }

  notifyStatusMessage("Completed");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
示例#22
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void MultiThresholdCells::execute()
{
  int err = 0;
  std::stringstream ss;
  setErrorCondition(err);
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The Voxel DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);
  int64_t nPoints = m->getTotalPoints();
  dataCheck(false, m->getTotalPoints(), m->getNumFieldTuples(), m->getNumEnsembleTuples());
  if (getErrorCondition() < 0)
  {
    return;
  }
  /* Place all your code to execute your filter here. */

  IDataArray::Pointer outputArrayPtr = m->getCellData(m_OutputArrayName);
  BoolArrayType* outputArray = BoolArrayType::SafeObjectDownCast<IDataArray*, BoolArrayType*>(outputArrayPtr.get());
  if (NULL == outputArray)
  {
    setErrorCondition(-11002);
    notifyErrorMessage("Could not properly cast the output array to a BoolArrayType", getErrorCondition());
    return;
  }
  m_Output = outputArray->GetPointer(0);

  // Prime our output array with the result of the first comparison
  {
    ComparisonInput_t& comp_0 = m_ComparisonInputs[0];

    ThresholdFilterHelper filter(static_cast<DREAM3D::Comparison::Enumeration>(comp_0.compOperator),
                                 comp_0.compValue,
                                 outputArray);

    err = filter.execute(m->getCellData(comp_0.arrayName).get(), outputArrayPtr.get());

    if (err < 0)
    {
      setErrorCondition(-13001);
      notifyErrorMessage("Error Executing threshold filter on first array", getErrorCondition());
      return;
    }
  }
  for(size_t i = 1; i < m_ComparisonInputs.size(); ++i)
  {

    BoolArrayType::Pointer currentArrayPtr = BoolArrayType::CreateArray(m->getTotalPoints(), "TEMP");
    currentArrayPtr->initializeWithZeros();
    bool* currentArray = currentArrayPtr->GetPointer(0);

    ComparisonInput_t& compRef = m_ComparisonInputs[i];

    ThresholdFilterHelper filter(static_cast<DREAM3D::Comparison::Enumeration>(compRef.compOperator),
                                 compRef.compValue,
                                 currentArrayPtr.get());

    err = filter.execute(m->getCellData(compRef.arrayName).get(), currentArrayPtr.get());
    if (err < 0)
    {
      setErrorCondition(-13002);
      notifyErrorMessage("Error Executing threshold filter on array", getErrorCondition());
      return;
    }
    for (int64_t p = 0; p < nPoints; ++p)
    {
      if(m_Output[p] == false || currentArray[p] == false)
      {
        m_Output[p] = false;
      }
    }

  }



  /* Let the GUI know we are done with this filter */
  notifyStatusMessage("Complete");
}
示例#23
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int DxReader::readFile()
{
  std::stringstream ss;
  VoxelDataContainer* m = getVoxelDataContainer();
  if (NULL == m)
  {
    ss.clear();
    ss << "DataContainer Pointer was NULL and Must be valid." << __FILE__ << "("<<__LINE__<<")";
    addErrorMessage(getHumanLabel(), ss.str(), -5);
    setErrorCondition(-5);
    return -1;
  }

  std::string delimeters(", ;\t"); /* delimeters to split the data */
  std::vector<std::string> tokens; /* vector to store the split data */

  int error, spin; /* dummy variables */

  bool finished_header, finished_data;
  finished_header = true;
  finished_data = false;
  size_t index = 0;

  size_t totalPoints = m->getTotalPoints();

  // Remove the array that we are about to create first as a 'datacheck()' was called from the super class's 'execute'
  // method which is performed before this function. This will cause an error -501 because the array with the name
  // m_GrainIdsArrayName already exists but of size 1, not the size we are going to read. So we get rid of the array
  m->removeCellData(m_GrainIdsArrayName);
  // Rerun the data check in order to allocate the array to store the data from the .dx file.
//  dataCheck(false, totalPoints, m->getNumFieldTuples(), m->getNumEnsembleTuples());
  CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, GrainIds, ss, int32_t, Int32ArrayType, 0, totalPoints, 1)


  if (getErrorCondition() < 0)
  {
    m_InStream.close();
    return -1;
  }

  for (std::string line; std::getline(m_InStream, line);)
  {

    // Get the remaining lines of the header and ignore
    tokens.clear();
    error = 0;
    tokenize(line, tokens, delimeters);

    size_t total = m->getTotalPoints();
    if( index == total || ( finished_header && tokens.size() != 0 && tokens[0] == "attribute") )
    {
      finished_data = true;
    }

    // Allocate the DataArray at this point:
    if(finished_header && !finished_data)
    {
      for (size_t in_spins = 0; in_spins < tokens.size(); in_spins++)
      {
        error += sscanf(tokens[in_spins].c_str(), "%d", &spin);
        m_GrainIds[index] =  spin;
        ++index;
      }
    }
  }

  if(index != static_cast<size_t>(m->getTotalPoints()))
  {
    ss.clear();
    ss << "ERROR: data size does not match header dimensions" << std::endl;
    ss << "\t" << index << "\t" << m->getTotalPoints() << std::endl;
    setErrorCondition(-495);
    addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
    m_InStream.close();
    return getErrorCondition();
  }

  tokens.clear();
  m_InStream.close();


  // Find the unique set of grain ids
//  std::set<int32_t> grainIdSet;
//  for (int64_t i = 0; i < totalPoints; ++i)
//  {
//    grainIdSet.insert(m_GrainIds[i]);
//  }
//  for (std::set<int32_t>::iterator iter = grainIdSet.begin(); iter != grainIdSet.end(); ++iter )
//  {
//    std::cout << "Grain ID: " << (*iter) << std::endl;
//  }

  notifyStatusMessage("Complete");
  return 0;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void DecimateSolidMesh::execute()
{
  setErrorCondition(0);
  VoxelDataContainer* m = getVoxelDataContainer();
  SolidMeshDataContainer* sm = getSolidMeshDataContainer();

  int64_t totalPoints = m->getTotalPoints();
  size_t totalFields = m->getNumFieldTuples();
  size_t totalEnsembles = m->getNumEnsembleTuples();
  dataCheck(false, totalPoints, totalFields, totalEnsembles);
  if (getErrorCondition() < 0)
  {
    return;
  }

  StructArray<Node>& nodes = *(sm->getNodes());
  StructArray<Tetrahedron>& tetrahedrons = *(sm->getTetrahedrons());
  int numNodes = nodes.GetNumberOfTuples();
  int numTets = tetrahedrons.GetNumberOfTuples();

  int gnum;
  size_t nodeId1, nodeId2, nodeId3, nodeId4;

  //Locate Boundary Nodes
  nodeGrainIds.resize(numNodes,-1);
  nodeEuclideanDistances.resize(numNodes,-1);
  for(int k = 0; k < numTets; k++)
  {
    gnum = tetrahedrons[k].nSpin;
  //  float x = nodes[k].coord[0];
    nodeId1 = tetrahedrons[k].node_id[0];
    nodeId2 = tetrahedrons[k].node_id[1];
    nodeId3 = tetrahedrons[k].node_id[2];
    nodeId4 = tetrahedrons[k].node_id[3];
    if(nodeGrainIds[nodeId1] == -1 || nodeGrainIds[nodeId1] == gnum) nodeGrainIds[nodeId1] = gnum;
    else
    {
      nodeGrainIds[nodeId1] = -1000;
      nodeEuclideanDistances[nodeId1] = 0;
    }
    if(nodeGrainIds[nodeId2] == -1 || nodeGrainIds[nodeId2] == gnum) nodeGrainIds[nodeId2] = gnum;
    else
    {
      nodeGrainIds[nodeId2] = -1000;
      nodeEuclideanDistances[nodeId2] = 0;
    }
    if(nodeGrainIds[nodeId3] == -1 || nodeGrainIds[nodeId3] == gnum) nodeGrainIds[nodeId3] = gnum;
    else
    {
      nodeGrainIds[nodeId3] = -1000;
      nodeEuclideanDistances[nodeId3] = 0;
    }
    if(nodeGrainIds[nodeId4] == -1 || nodeGrainIds[nodeId4] == gnum) nodeGrainIds[nodeId4] = gnum;
    else
    {
      nodeGrainIds[nodeId4] = -1000;
      nodeEuclideanDistances[nodeId4] = 0;
    }
  }
  nodeGrainIds.clear();

  //Determine Node Euclidean Distance Map
  tetDone.resize(numTets,false);
  int tetsLeft = 1;
  int ED1, ED2, ED3, ED4;
  int currentED = 0;
  int maxGlobalED = 0;
  while(tetsLeft > 0)
  {
    tetsLeft = 0;
    currentED++;
    for(int k = 0; k < numTets; k++)
    {
      if(tetDone[k] == false)
      {
        nodeId1 = tetrahedrons[k].node_id[0];
        nodeId2 = tetrahedrons[k].node_id[1];
        nodeId3 = tetrahedrons[k].node_id[2];
        nodeId4 = tetrahedrons[k].node_id[3];
        ED1 = nodeEuclideanDistances[nodeId1];
        ED2 = nodeEuclideanDistances[nodeId2];
        ED3 = nodeEuclideanDistances[nodeId3];
        ED4 = nodeEuclideanDistances[nodeId4];
        if(ED1 == -1 || ED2 == -1 || ED3 == -1 || ED4 == -1) tetsLeft++;
        if(ED1 == (currentED-1) || ED2 == (currentED-1) || ED3 == (currentED-1) || ED4 == (currentED-1))
        {
          if(ED1 == -1) nodeEuclideanDistances[nodeId1] = currentED;
          if(ED2 == -1) nodeEuclideanDistances[nodeId2] = currentED;
          if(ED3 == -1) nodeEuclideanDistances[nodeId3] = currentED;
          if(ED4 == -1) nodeEuclideanDistances[nodeId4] = currentED;
          tetDone[k] = true;
        }
      }
    }
    maxGlobalED = currentED;
  }
  tetDone.clear();

  //Decimate Mesh
 // ED1, ED2, ED3, ED4;
  int removeED = maxGlobalED;
 // int secondLargestED = 0;
  int point;
  int otherPoint;
  while(numTets > m_GoalElementNumber && removeED > 1)
  {
    for(int k = 0; k < numTets; k++)
    {
      nodeId1 = tetrahedrons[k].node_id[0];
      nodeId2 = tetrahedrons[k].node_id[1];
      nodeId3 = tetrahedrons[k].node_id[2];
      nodeId4 = tetrahedrons[k].node_id[3];
      ED1 = nodeEuclideanDistances[nodeId1];
      ED2 = nodeEuclideanDistances[nodeId2];
      ED3 = nodeEuclideanDistances[nodeId3];
      ED4 = nodeEuclideanDistances[nodeId4];
      if(ED1 >= removeED)
      {
        point = nodeId1;
//				secondLargestED = ED2;
        otherPoint = nodeId2;
//				if(ED3 > secondLargestED) secondLargestED = ED3, otherPoint = nodeId3;
//				if(ED4 > secondLargestED) secondLargestED = ED4, otherPoint = nodeId4;
        k = updateNodesandTets(k, point, otherPoint);
      }
      else if(ED2 >= removeED)
      {
        point = nodeId2;
//				secondLargestED = ED1;
        otherPoint = nodeId3;
//				if(ED3 > secondLargestED) secondLargestED = ED3, otherPoint = nodeId3;
//				if(ED4 > secondLargestED) secondLargestED = ED4, otherPoint = nodeId4;
        k = updateNodesandTets(k, point, otherPoint);
      }
      else if(ED3 >= removeED)
      {
        point = nodeId3;
//				secondLargestED = ED1;
        otherPoint = nodeId4;
//				if(ED2 > secondLargestED) secondLargestED = ED2, otherPoint = nodeId2;
//				if(ED4 > secondLargestED) secondLargestED = ED4, otherPoint = nodeId4;
        k = updateNodesandTets(k, point, otherPoint);
      }
      else if(ED4 >= removeED)
      {
        point = nodeId4;
//				secondLargestED = ED1;
        otherPoint = nodeId1;
//				if(ED2 > secondLargestED) secondLargestED = ED2, otherPoint = nodeId2;
//				if(ED3 > secondLargestED) secondLargestED = ED3, otherPoint = nodeId3;
        k = updateNodesandTets(k, point, otherPoint);
      }
      numTets = tetrahedrons.GetNumberOfTuples();
      StructArray<Node>& nodes = *(sm->getNodes());
      StructArray<Tetrahedron>& tetrahedrons = *(sm->getTetrahedrons());
      numNodes = nodes.GetNumberOfTuples();
      numTets = tetrahedrons.GetNumberOfTuples();
    }
    removeED = removeED-1;
  }

  notifyStatusMessage("Complete");
}