Example #1
0
    /**
     * @brief
     * @param parentId
     * @return
     */
    virtual int readH5Data(hid_t parentId)
    {
      int err = 0;

      this->Resize(0);
      IDataArray::Pointer p = H5DataArrayReader::readIDataArray(parentId, GetName());
      if (p.get() == NULL)
      {
        return -1;
      }
      this->NumberOfComponents = p->GetNumberOfComponents();
      this->Size = p->GetSize();
      this->MaxId = (Size == 0) ? 0 : Size -1;
      this->Array = reinterpret_cast<T*>(p->GetVoidPointer(0));
      p->releaseOwnership();

      return err;
    }
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FieldDataCSVWriter::execute()
{
  int err = 0;
  setErrorCondition(err);
  VoxelDataContainer* m = getVoxelDataContainer();
  if(NULL == m)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The DataContainer Object was NULL", -999);
    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(m_FieldDataFile);
  if(!MXADir::mkdir(parentPath, true))
  {
    std::stringstream ss;
    ss << "Error creating parent path '" << parentPath << "'";
    notifyErrorMessage(ss.str(), -1);
    setErrorCondition(-1);
    return;
  }



  std::string filename = getFieldDataFile();

  std::ofstream outFile;
  outFile.open(filename.c_str(), std::ios_base::binary);
  char space = DREAM3D::GrainData::Delimiter;
  // Write the total number of grains
  outFile << m->getNumFieldTuples()-1 << std::endl;
  // Get all the names of the arrays from the Data Container
  std::list<std::string> headers = m->getFieldArrayNameList();

  std::vector<IDataArray::Pointer> data;

  //For checking if an array is a neighborlist
  NeighborList<int>::Pointer neighborlistPtr = NeighborList<int>::New();

  // Print the GrainIds Header before the rest of the headers
  outFile << DREAM3D::GrainData::GrainID;
  // Loop throught the list and print the rest of the headers, ignoring those we don't want
  for(std::list<std::string>::iterator iter = headers.begin(); iter != headers.end(); ++iter)
  {
    // Only get the array if the name does NOT match those listed
    IDataArray::Pointer p = m->getFieldData(*iter);
    if(p->getNameOfClass().compare(neighborlistPtr->getNameOfClass()) != 0)
    {
      if (p->GetNumberOfComponents() == 1) {
        outFile << space << (*iter);
      }
      else // There are more than a single component so we need to add multiple header values
      {
        for(int k = 0; k < p->GetNumberOfComponents(); ++k)
        {
          outFile << space << (*iter) << "_" << k;
        }
      }
      // Get the IDataArray from the DataContainer
      data.push_back(p);
    }
  }
  outFile << std::endl;

  // Get the number of tuples in the arrays
  size_t numTuples = data[0]->GetNumberOfTuples();
  std::stringstream ss;
  float threshold = 0.0f;

  // Skip the first grain
  for(size_t i = 1; i < numTuples; ++i)
  {
    if (((float)i / numTuples) * 100.0f > threshold) {
      ss.str("");
      ss << "Writing Field Data - " << ((float)i / numTuples) * 100 << "% Complete";
      notifyStatusMessage(ss.str());
      threshold = threshold + 5.0f;
      if (threshold < ((float)i / numTuples) * 100.0f) {
        threshold = ((float)i / numTuples) * 100.0f;
      }
    }

    // Print the grain id
    outFile << i;
    // Print a row of data
    for( std::vector<IDataArray::Pointer>::iterator p = data.begin(); p != data.end(); ++p)
    {
      outFile << space;
      (*p)->printTuple(outFile, i, space);
    }
    outFile << std::endl;
  }

  if(m_WriteNeighborListData == true)
  {
    // Print the GrainIds Header before the rest of the headers
    // Loop throught the list and print the rest of the headers, ignoring those we don't want
    for(std::list<std::string>::iterator iter = headers.begin(); iter != headers.end(); ++iter)
    {
      // Only get the array if the name does NOT match those listed
      IDataArray::Pointer p = m->getFieldData(*iter);
      if(p->getNameOfClass().compare(neighborlistPtr->getNameOfClass()) == 0)
      {
        outFile << DREAM3D::GrainData::GrainID << space << DREAM3D::GrainData::NumNeighbors << space << (*iter) << std::endl;
        size_t numTuples = p->GetNumberOfTuples();
        //	  float threshold = 0.0f;

        // Skip the first grain
        for(size_t i = 1; i < numTuples; ++i)
        {
          // Print the grain id
          outFile << i;
          // Print a row of data
          outFile << space;
          p->printTuple(outFile, i, space);
          outFile << std::endl;
        }
      }
    }
  }
  outFile.close();

  // If there is an error set this to something negative and also set a message
  notifyStatusMessage("FieldDataCSVWriter Completed");

}
Example #3
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FindFaceAverage::dataCheckSurfaceMesh(bool preflight, size_t voxels, size_t fields, size_t ensembles)
{
  setErrorCondition(0);
  std::stringstream ss;
  SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer();
  if(NULL == sm)
  {
    addErrorMessage(getHumanLabel(), "SurfaceMeshDataContainer is missing", -383);
    setErrorCondition(-383);
  }
  else
  {
    // We MUST have Triangles defined.
    if(sm->getFaces().get() == NULL)
    {
      addErrorMessage(getHumanLabel(), "SurfaceMesh DataContainer missing Triangles", -385);
      setErrorCondition(-385);
    }
    else
    {
      GET_PREREQ_DATA(sm, DREAM3D, FaceData, SurfaceMeshGrainFaceId, ss, -387, int32_t, Int32ArrayType, fields, 1)
      if(1==m_AverageMethod)
      {
        GET_PREREQ_DATA(sm, DREAM3D, FaceData, SurfaceMeshTriangleAreas, ss, -387, double, DoubleArrayType, fields, 1)
      }

      if(m_SelectedFaceArrayName.empty() == true)
      {
        setErrorCondition(-11000);
        addErrorMessage(getHumanLabel(), "An array from the Face Data Container must be selected.", getErrorCondition());
      }
      else if(preflight)
      {
        IDataArray::Pointer inputData = sm->getFaceData(m_SelectedFaceArrayName);
        if (NULL == inputData.get())
        {
          ss.str("");
          ss << "Selected array '" << m_SelectedFaceArrayName << "' does not exist in the Surface Mesh Data Container. Was it spelled correctly?";
          setErrorCondition(-11001);
          notifyErrorMessage(ss.str(), getErrorCondition());
          return;
        }

        int numberOfComponents = inputData->GetNumberOfComponents();
        std::string dType = inputData->getTypeAsString();
        IDataArray::Pointer p = IDataArray::NullPointer();
        if (dType.compare("int8_t") == 0)
        {
          p = Int8ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("uint8_t") == 0)
        {
          p = UInt8ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("int16_t") == 0)
        {
          p = Int16ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("uint16_t") == 0)
        {
          p = UInt16ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("int32_t") == 0)
        {
          p = Int32ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("uint32_t") == 0)
        {
          p = UInt32ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("int64_t") == 0)
        {
          p = Int64ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("uint64_t") == 0)
        {
          p = UInt64ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("float") == 0)
        {
          p = FloatArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("double") == 0)
        {
          p = DoubleArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        else if (dType.compare("bool") == 0)
        {
          p = BoolArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName);
        }
        sm->addFieldData(p->GetName(), p);
      }
    }
  }
Example #4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
std::string SurfaceMeshDataContainerWriter::writeXdmfAttributeDataHelper(int numComp, const std::string &attrType,
                                                                              const std::string &groupName,
                                                                              IDataArray::Pointer array,
                                                                              const std::string &centering,
                                                                              int precision, const std::string &xdmfTypeName)
{
  std::stringstream out;
  std::stringstream dimStr;
  std::stringstream dimStr1;
  std::stringstream dimStr1half;
  std::stringstream dimStr2;
  std::stringstream dimStr2half;

  if((numComp%2) == 1)
  {
    out << "    <Attribute Name=\"" << array->GetName() << "\" ";
    out << "AttributeType=\"" << attrType << "\" ";
    dimStr << array->GetNumberOfTuples() << " " << array->GetNumberOfComponents();
    out << "Center=\"" << centering << "\">" << std::endl;
    // Open the <DataItem> Tag
    out << "      <DataItem Format=\"HDF\" Dimensions=\"" << dimStr.str() <<  "\" ";
    out << "NumberType=\"" << xdmfTypeName << "\" " << "Precision=\"" << precision << "\" >" << std::endl;

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

    out << "        " << hdfFileName << ":/SurfaceMeshDataContainer/" << groupName << "/" << array->GetName() << std::endl;
    out << "      </DataItem>" << std::endl;
    out << "    </Attribute>" << std::endl << std::endl;
  }
  else
  {
    //First Slab
    out << "    <Attribute Name=\"" << array->GetName() << " (Field 0)\" ";
    out << "AttributeType=\"" << attrType << "\" ";
    dimStr1 << array->GetNumberOfTuples() << " " << array->GetNumberOfComponents();
    dimStr1half << array->GetNumberOfTuples() << " " << (array->GetNumberOfComponents()/2);
    out << "Center=\"" << centering << "\">" << std::endl;
    // Open the <DataItem> Tag
    out << "      <DataItem ItemType=\"HyperSlab\" Dimensions=\"" << dimStr1half.str() <<  "\" ";
    out << "Type=\"HyperSlab\" " << "Name=\"" << array->GetName() << " (Field 0)\" >" << std::endl;
    out << "        <DataItem Dimensions=\"3 2\" " << "Format=\"XML\" >" << std::endl;
    out << "          0        0" << std::endl;
    out << "          1        1" << std::endl;
    out << "          " << dimStr1half.str() << " </DataItem>" << std::endl;
    out << std::endl;
    out << "        <DataItem Format=\"HDF\" Dimensions=\"" << dimStr1.str() << "\" " << "NumberType=\"" << xdmfTypeName << "\" " << "Precision=\"" << precision << "\" >" << std::endl;
    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);
    out << "        " << hdfFileName << ":/SurfaceMeshDataContainer/" << groupName << "/" << array->GetName() << std::endl;
    out << "        </DataItem>" << std::endl;
    out << "      </DataItem>" << std::endl;
    out << "    </Attribute>" << std::endl << std::endl;

    //Second Slab
    out << "    <Attribute Name=\"" << array->GetName() << " (Field 1)\" ";
    out << "AttributeType=\"" << attrType << "\" ";
    dimStr2 << array->GetNumberOfTuples() << " " << array->GetNumberOfComponents();
    dimStr2half << array->GetNumberOfTuples() << " " << (array->GetNumberOfComponents()/2);
    out << "Center=\"" << centering << "\">" << std::endl;
    // Open the <DataItem> Tag
    out << "      <DataItem ItemType=\"HyperSlab\" Dimensions=\"" << dimStr2half.str() <<  "\" ";
    out << "Type=\"HyperSlab\" " << "Name=\"" << array->GetName() << " (Field 1)\" >" << std::endl;
    out << "        <DataItem Dimensions=\"3 2\" " << "Format=\"XML\" >" << std::endl;
    out << "          0        " << (array->GetNumberOfComponents()/2) << std::endl;
    out << "          1        1" << std::endl;
    out << "          " << dimStr2half.str() << " </DataItem>" << std::endl;
    out << std::endl;
    out << "        <DataItem Format=\"HDF\" Dimensions=\"" << dimStr2.str() << "\" " << "NumberType=\"" << xdmfTypeName << "\" " << "Precision=\"" << precision << "\" >" << std::endl;
    ssize_t nameSize2 = H5Fget_name(m_HdfFileId, NULL, 0) + 1;
    std::vector<char> nameBuffer2(nameSize2, 0);
    nameSize2 = H5Fget_name(m_HdfFileId, &(nameBuffer2.front()), nameSize2);
    std::string hdfFileName2(&(nameBuffer2.front()), nameSize2);
    hdfFileName2 = MXAFileInfo::filename(hdfFileName2);
    out << "        " << hdfFileName2 << ":/SurfaceMeshDataContainer/" << groupName << "/" << array->GetName() << std::endl;
    out << "        </DataItem>" << std::endl;
    out << "      </DataItem>" << std::endl;
    out << "    </Attribute>" << std::endl << std::endl;
  }
  return out.str();
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ConvertData::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles)
{
  setErrorCondition(0);
  std::stringstream ss;
  VoxelDataContainer* m = getVoxelDataContainer();

  if(m_SelectedCellArrayName.empty() == true)
  {
    ss.str("");
    ss << "The Input Voxel Cell Array Name is blank (empty) and a value must be filled in for the pipeline to complete.";
    setErrorCondition(-397);
    addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
  }

  if(m_OutputArrayName.empty() == true)
  {
    ss.str("");
    ss << "The Output Array Name is blank (empty) and a value must be filled in for the pipeline to complete.";
    setErrorCondition(-398);
    addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
  }


  int numberOfComponents = 0;
  IDataArray::Pointer iArray = m->getCellData(m_SelectedCellArrayName);
  if (NULL != iArray)
  {
    numberOfComponents = iArray->GetNumberOfComponents();
  }

  if (true == preflight)
  {
    IDataArray::Pointer p = IDataArray::NullPointer();
    if (m_ScalarType == Detail::Int8)
    {
      p = Int8ArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::UInt8)
    {
      p = UInt8ArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Int16)
    {
      p = Int16ArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::UInt16)
    {
      p = UInt16ArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Int32)
    {
      p = Int32ArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::UInt32)
    {
      p = UInt32ArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Int64)
    {
      p = Int64ArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::UInt64)
    {
      p = UInt64ArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Float)
    {
      p = FloatArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Double)
    {
      p = DoubleArrayType::CreateArray(voxels, numberOfComponents, m_OutputArrayName);
    }
    m->addCellData(p->GetName(), p);
  }
}