コード例 #1
0
ファイル: ChangeResolution.cpp プロジェクト: tuks188/DREAM3D
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ChangeResolution::preflight()
{
  VoxelDataContainer* m = getVoxelDataContainer();

  size_t dims[3];
  m->getDimensions(dims);

  float sizex = (dims[0])*m->getXRes();
  float sizey = (dims[1])*m->getYRes();
  float sizez = (dims[2])*m->getZRes();
  int m_XP = int(sizex / m_Resolution.x);
  int m_YP = int(sizey / m_Resolution.y);
  int m_ZP = int(sizez / m_Resolution.z);

  m->setDimensions(m_XP, m_YP, m_ZP);
  m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z);
}
コード例 #2
0
ファイル: ChangeResolution.cpp プロジェクト: tuks188/DREAM3D
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ChangeResolution::execute()
{
  int err = 0;
  setErrorCondition(err);
  DREAM3D_RANDOMNG_NEW()
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    return;
  }

  setErrorCondition(0);


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

  if(m->getXRes() == m_Resolution.x
      && m->getYRes() == m_Resolution.y
      && m->getZRes() == m_Resolution.z)
  {
    return;
  }

  size_t dims[3];
  m->getDimensions(dims);


  float sizex = (dims[0])*m->getXRes();
  float sizey = (dims[1])*m->getYRes();
  float sizez = (dims[2])*m->getZRes();
  int m_XP = int(sizex / m_Resolution.x);
  int m_YP = int(sizey / m_Resolution.y);
  int m_ZP = int(sizez / m_Resolution.z);
  int64_t totalPoints = m_XP*m_YP*m_ZP;

  float x, y, z;
  int col, row, plane;
  int index;
  int index_old;
  std::vector<size_t> newindicies;
  newindicies.resize(totalPoints);
  for (int i = 0; i < m_ZP; i++)
  {
    std::stringstream ss;
    ss << "Changing Resolution - " << ((float)i/m->getZPoints())*100 << " Percent Complete";
    notifyStatusMessage(ss.str());
    for (int j = 0; j < m_YP; j++)
    {
      for (int k = 0; k < m_XP; k++)
      {
        x = (k * m_Resolution.x);
        y = (j * m_Resolution.y);
        z = (i * m_Resolution.z);
        col = int(x / m->getXRes());
        row = int(y / m->getYRes());
        plane = int(z / m->getZRes());
        index_old = (plane * m->getXPoints() * m->getYPoints()) + (row * m->getXPoints()) + col;
        index = (i * m_XP * m_YP) + (j * m_XP) + k;
    newindicies[index] = index_old;
      }
    }
  }

  std::list<std::string> voxelArrayNames = m->getCellArrayNameList();
  for (std::list<std::string>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
  {
    std::string name = *iter;
    IDataArray::Pointer p = m->getCellData(*iter);
    // Make a copy of the 'p' array that has the same name. When placed into
    // the data container this will over write the current array with
    // the same name. At least in theory
    IDataArray::Pointer data = p->createNewArray(p->GetNumberOfTuples(), p->GetNumberOfComponents(), p->GetName());
    data->Resize(totalPoints);
    void* source = NULL;
    void* destination = NULL;
    size_t newIndicies_I = 0;
    int nComp = data->GetNumberOfComponents();
    for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++)
    {
      newIndicies_I = newindicies[i];

      source = p->GetVoidPointer((nComp * newIndicies_I));
      destination = data->GetVoidPointer((data->GetNumberOfComponents() * i));
      ::memcpy(destination, source, p->GetTypeSize() * data->GetNumberOfComponents());
    }
    m->addCellData(*iter, data);
  }
  m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z);
  m->setDimensions(m_XP, m_YP, m_ZP);

  notifyStatusMessage("Complete");
}
コード例 #3
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");
}
コード例 #4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int VoxelDataContainerWriter::writeCellData(hid_t dcGid)
{
  std::stringstream ss;
  int err = 0;
  VoxelDataContainer* m = getVoxelDataContainer();
  int64_t volDims[3] =
  { m->getXPoints(), m->getYPoints(), m->getZPoints() };
  float spacing[3] =
  { m->getXRes(), m->getYRes(), m->getZRes() };
  float origin[3] =
  { 0.0f, 0.0f, 0.0f };
  m->getOrigin(origin);

  writeCellXdmfGridHeader(origin, spacing, volDims);


  // Get the name of the .dream3d file that we are writing to:
  ssize_t nameSize = H5Fget_name(m_HdfFileId, NULL, 0) + 1;
  std::vector<char> nameBuffer(nameSize, 0);
  nameSize = H5Fget_name(m_HdfFileId, &(nameBuffer.front()), nameSize);

  std::string hdfFileName(&(nameBuffer.front()), nameSize);
  hdfFileName = MXAFileInfo::filename(hdfFileName);
  std::string xdmfGroupPath = std::string(":/") + VoxelDataContainer::ClassName() + std::string("/") + H5_CELL_DATA_GROUP_NAME;

  // Write the Voxel Data
  err = H5Utilities::createGroupsFromPath(H5_CELL_DATA_GROUP_NAME, dcGid);
  if(err < 0)
  {
    ss.str("");
    ss << "Error creating HDF Group " << H5_CELL_DATA_GROUP_NAME << std::endl;
    setErrorCondition(-63);
    notifyErrorMessage(ss.str(), err);
    H5Gclose(dcGid); // Close the Data Container Group
    return err;
  }
  hid_t cellGroupId = H5Gopen(dcGid, H5_CELL_DATA_GROUP_NAME, H5P_DEFAULT);
  if(err < 0)
  {
    ss.str("");
    ss << "Error writing string attribute to HDF Group " << H5_CELL_DATA_GROUP_NAME << std::endl;
    setErrorCondition(-64);
    notifyErrorMessage(ss.str(), err);
    H5Gclose(dcGid); // Close the Data Container Group
    return err;
  }
  NameListType names = m->getCellArrayNameList();
  for (NameListType::iterator iter = names.begin(); iter != names.end(); ++iter)
  {
    ss.str("");
    ss << "Writing Cell Data '" << *iter << "' to HDF5 File" << std::endl;
    notifyStatusMessage(ss.str());
    IDataArray::Pointer array = m->getCellData(*iter);
    err = array->writeH5Data(cellGroupId);
    if(err < 0)
    {
      ss.str("");
      ss << "Error writing array '" << *iter << "' to the HDF5 File";
      notifyErrorMessage(ss.str(), err);
      setErrorCondition(err);
      H5Gclose(cellGroupId); // Close the Cell Group
      H5Gclose(dcGid); // Close the Data Container Group
      return err;
    }
    array->writeXdmfAttribute( *m_XdmfPtr, volDims, hdfFileName, xdmfGroupPath, " (Cell)");
  }
  H5Gclose(cellGroupId); // Close the Cell Group
  writeXdmfGridFooter("Cell Data");
  return err;
}
コード例 #5
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void VoxelDataContainerWriter::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);
  dataCheck(false, 1, 1, 1);
  hid_t dcGid = -1;



  // Create the HDF5 Group for the Data Container
  err = H5Utilities::createGroupsFromPath(DREAM3D::HDF5::VoxelDataContainerName.c_str(), m_HdfFileId);
  if (err < 0)
  {
    ss.str("");
    ss << "Error creating HDF Group " << DREAM3D::HDF5::VoxelDataContainerName << std::endl;
    setErrorCondition(-60);
    notifyErrorMessage( ss.str(), err);
    return;
  }
  dcGid = H5Gopen(m_HdfFileId, DREAM3D::HDF5::VoxelDataContainerName.c_str(), H5P_DEFAULT );
  if (dcGid < 0)
  {
    ss.str("");
    ss << "Error opening Group " << DREAM3D::HDF5::VoxelDataContainerName << std::endl;
    setErrorCondition(-61);
    notifyErrorMessage( ss.str(), err);
    return;
  }

  // This just writes the header information
  int64_t volDims[3] =
  { m->getXPoints(), m->getYPoints(), m->getZPoints() };
  float spacing[3] =
  { m->getXRes(), m->getYRes(), m->getZRes() };
  float origin[3] =
  { 0.0f, 0.0f, 0.0f };
  m->getOrigin(origin);
  err = writeMetaInfo(DREAM3D::HDF5::VoxelDataContainerName, volDims, spacing, origin);
  if (err < 0)
  {
    ss.str("");
    ss <<  ":Error Writing header information to output file" << std::endl;
    setErrorCondition(-62);
    notifyErrorMessage( ss.str(), err);
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }

  err = writeVertexData(dcGid);
  if (err < 0)
  {
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }

  err = writeEdgeData(dcGid);
  if (err < 0)
  {
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }

  err = writeFaceData(dcGid);
  if (err < 0)
  {
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }

  err = writeCellData(dcGid);
  if (err < 0)
  {
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }

  err = writeFieldData(dcGid);
  if (err < 0)
  {
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }

  err = writeEnsembleData(dcGid);
  if (err < 0)
  {
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }

  // Now finally close the group and the HDf5 File
  H5Gclose(dcGid); // Close the Data Container Group



  notifyStatusMessage("Complete");
}
コード例 #6
0
ファイル: FindNeighbors.cpp プロジェクト: leavy/DREAM3D
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}