// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AbaqusSurfaceMeshWriter::execute()
{
  int err = 0;
  std::stringstream ss;

  SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer();
  dataCheck(false, 1, 1, 1);
  if(getErrorCondition() < 0)
  {
    return;
  }

  // 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(getOutputFile());
  if(!MXADir::mkdir(parentPath, true))
  {
    std::stringstream ss;
    ss << "Error creating parent path '" << parentPath << "'";
    notifyErrorMessage(ss.str(), -1);
    setErrorCondition(-1);
    return;
  }

  DREAM3D::SurfaceMesh::VertListPointer_t nodesPtr = sm->getVertices();
  DREAM3D::SurfaceMesh::FaceListPointer_t trianglePtr = sm->getFaces();

  // Get the Labels(GrainIds or Region Ids) for the triangles
  Int32ArrayType::Pointer faceLabelsPtr = boost::dynamic_pointer_cast<Int32ArrayType>(sm->getFaceData(DREAM3D::FaceData::SurfaceMeshFaceLabels));
  int32_t* faceLabels = faceLabelsPtr->GetPointer(0);

  // Store all the unique Spins
  std::set<int> uniqueSpins;
  for (int i = 0; i < trianglePtr->GetNumberOfTuples(); i++)
  {
    uniqueSpins.insert(faceLabels[i*2]);
    uniqueSpins.insert(faceLabels[i*2+1]);
  }

  FILE* f = fopen(m_OutputFile.c_str(), "wb");
  ScopedFileMonitor fileMonitor(f);

  err = writeHeader(f, nodesPtr->GetNumberOfTuples(), trianglePtr->GetNumberOfTuples(), uniqueSpins.size()-1);
  err = writeNodes(f);
  err = writeTriangles(f);
  err = writeGrains(f);

  setErrorCondition(0);
  notifyStatusMessage("Complete");

  return;
}
Exemplo n.º 2
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);
  }
}
Exemplo n.º 3
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");
}
Exemplo n.º 4
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);
  }
}
Exemplo n.º 5
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ImportR3DStack::execute()
{
  int err = 0;
  setErrorCondition(err);
  dataCheck(false,1,1,1);
  if (getErrorCondition() < 0) { notifyErrorMessage("There is a problem with the data check", getErrorCondition()); }
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);
  std::stringstream ss;

  m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z);
  m->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z);
  int x = 0;
  int y = 0;
  readXYSize(x, y);

  if (x < 1 || y < 1)
  {  
	setErrorCondition(-1000);
	notifyErrorMessage("At least one dimension is less than 1", getErrorCondition());
  }
  size_t numSlices = m_ZEndIndex - m_ZStartIndex + 1;
  size_t totalVoxels = numSlices * x * y;
  // Create a new array, eventually substituting this into the DataContainer later on.
  Int32ArrayType::Pointer grainIdsPtr = Int32ArrayType::CreateArray(totalVoxels, 1, DREAM3D::CellData::GrainIds);
  grainIdsPtr->initializeWithZeros();
  m_GrainIds = grainIdsPtr->GetPointer(0); // Get the pointer to the front of the array
  int32_t* currentPositionPtr = m_GrainIds;

  bool ok = false;

  int pixelBytes = 0;
  int totalPixels = 0;
  int height = 0;
  int width = 0;

  size_t index = 0;

  int64_t z = m_ZStartIndex;

  m->setDimensions(x,y,numSlices);

  for (std::vector<std::string>::iterator filepath = m_R3DFileList.begin(); filepath != m_R3DFileList.end(); ++filepath)
  {
    QString R3DFName = QString::fromStdString(*filepath);

    ss.str("");
    ss << "Importing file " << R3DFName.toStdString();
    notifyStatusMessage(ss.str());

    QByteArray buf;
    QFile in(R3DFName);

    if (!in.open(QIODevice::ReadOnly | QIODevice::Text))
    {
      QString msg = QString("R3D file could not be opened: ") + R3DFName;
      setErrorCondition(-14000);
      notifyErrorMessage(msg.toStdString(), getErrorCondition());
    }

    buf = in.readLine(); // Read first line which is the x and y sizes

    QList<QByteArray> tokens = buf.split(',');

    width = tokens.at(0).toInt();
    height = tokens.at(1).toInt();

    int32_t value = 0;

    for(qint32 i = 0; i < height; ++i)
    {
      buf = in.readLine();
      tokens = buf.split(',');
      if (tokens.size() != width+2)
      {
		notifyStatusMessage("A file did not have the correct width partilcuar line");
		break;
      }
      for(int j = 1; j < width+1; j++)
      {
        currentPositionPtr[index] = tokens[j].toInt(&ok, 10);
        ++index;
		if (!ok) 
		{
		  setErrorCondition(-2004);
		  notifyErrorMessage("Width dimension entry was not an integer", getErrorCondition());
		  break;
		}
      }

      if (in.atEnd() == true && i < height - 2)
      {
		notifyStatusMessage("A file did not have the correct height");
        break;
      }
    }

    ++z;
    if(getCancel() == true)
    {
      notifyStatusMessage("Conversion was Canceled");
      return;
    }
  }

  // OVer write any GrainIds array that is already in the DataContainer
  getVoxelDataContainer()->addCellData(DREAM3D::CellData::GrainIds, grainIdsPtr);

  /* Let the GUI know we are done with this filter */
  notifyStatusMessage("Complete");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int AbaqusSurfaceMeshWriter::writeGrains(FILE* f)
{

  //*Elset, elset=Grain1
  //1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16

  int err = 0;

  std::stringstream ss;
  SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer();
  DREAM3D::SurfaceMesh::VertListPointer_t nodesPtr = sm->getVertices();
  DREAM3D::SurfaceMesh::FaceListPointer_t trianglePtr = sm->getFaces();

  // Get the Labels(GrainIds or Region Ids) for the triangles
  Int32ArrayType::Pointer faceLabelsPtr = boost::dynamic_pointer_cast<Int32ArrayType>(sm->getFaceData(DREAM3D::FaceData::SurfaceMeshFaceLabels));
  int32_t* faceLabels = faceLabelsPtr->GetPointer(0);

  int nTriangles = trianglePtr->GetNumberOfTuples();

  // Store all the unique Spins
  std::set<int> uniqueSpins;
  for (int i = 0; i < nTriangles; i++)
  {
    uniqueSpins.insert(faceLabels[i*2]);
    uniqueSpins.insert(faceLabels[i*2+1]);
  }

  int spin = 0;

  //Loop over the unique Spins
  for (std::set<int>::iterator spinIter = uniqueSpins.begin(); spinIter != uniqueSpins.end(); ++spinIter )
  {
    spin = *spinIter;
    if(spin < 0) { continue; }

    fprintf(f, "*ELSET, ELSET=Grain%d\n", spin);

    ss.str("");
    ss << "Writing ELSET for Grain Id " << spin;
    notifyStatusMessage(ss.str());


    // Loop over all the triangles for this spin
    int lineCount = 0;
    for(int t = 0; t < nTriangles; ++t)
    {
      if (faceLabels[t*2] != spin && faceLabels[t*2+1] != spin)
      {
        continue; // We do not match either spin so move to the next triangle
      }

      // Only print 15 Triangles per line
      if (lineCount == 15)
      {
        fprintf(f, ", %d\n", t);
        lineCount = 0;
      }
      else if(lineCount == 0) // First value on the line
      {
        fprintf(f,"%d", t);
        lineCount++;
      }
      else
      {
        fprintf(f,", %d", t);
        lineCount++;
      }

    }
    // Make sure we have a new line at the end of the section
    if (lineCount != 0)
    {
      fprintf(f, "\n");
    }
  }
  return err;
}