Exemplo n.º 1
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());
}
Exemplo n.º 2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int BinaryNodesTrianglesReader::read()
{

    SurfaceMeshDataContainer *sm = getSurfaceMeshDataContainer();
    int err = 0;
    setErrorCondition(err);

    std::stringstream s;
    // Open the Nodes file for reading
    FILE* nodesFile = fopen(m_BinaryNodesFile.c_str(), "rb+");
    if(nodesFile == NULL)
    {
        s.str("");
        s << "Error opening nodes file '" << m_BinaryNodesFile << "'";
        setErrorCondition(786);
        //    PipelineMessage em (getHumanLabel(), s.str(), -1);
        //    addErrorMessage(em);
        //    notifyMessage(em);
        return getErrorCondition();
    }
    ScopedFileMonitor nodesMonitor(nodesFile);

    // Calculate how many nodes are in the file based on the file size
    fseek(nodesFile, 0, SEEK_END);
    size_t fLength = ftell(nodesFile);
    size_t nNodes = fLength / SurfaceMesh::NodesFile::ByteCount;
    fseek(nodesFile, 0, SEEK_SET);
    fLength = ftell(nodesFile);
    if(0 != fLength)
    {
        s.str("");
        s << getNameOfClass() << ": Error Could not rewind to beginning of file after nodes count.'" << m_BinaryNodesFile << "'";
        setErrorCondition(787);
        //    PipelineMessage em (getHumanLabel(), s.str(), -1);
        //    addErrorMessage(em);
        //    notifyMessage(em);
        return getErrorCondition();
    }
    s.str("");
    s << "Calc Node Count from Nodes.bin File: " << nNodes;
    notifyStatusMessage(s.str());

    // Open the triangles file for reading
    FILE* triFile = fopen(m_BinaryTrianglesFile.c_str(), "rb+");
    if(triFile == NULL)
    {
        s.str("");
        s << getNameOfClass() << ": Error opening Triangles file '" << m_BinaryTrianglesFile << "'";
        setErrorCondition(788);
        //    PipelineMessage em (getHumanLabel(), s.str(), -1);
        //    addErrorMessage(em);
        //    notifyMessage(em);
        return getErrorCondition();
    }

    ScopedFileMonitor trianglesMonitor(triFile);
    // Calculate how many Triangles are in the file based in the file size
    fseek(triFile, 0, SEEK_END);
    fLength = ftell(triFile);
    size_t nTriangles = fLength / SurfaceMesh::TrianglesFile::ByteCount;
    fseek(triFile, 0, SEEK_SET);
    fLength = ftell(triFile);
    if(0 != fLength)
    {
        s.str("");
        s << getNameOfClass() << ": Error Could not rewind to beginning of file after triangles count.'" << m_BinaryTrianglesFile << "'";
        setErrorCondition(789);
        //    PipelineMessage em (getHumanLabel(), s.str(), -1);
        //    addErrorMessage(em);
        //    notifyMessage(em);
        return getErrorCondition();
    }
    s.str("");
    s << "Calc Triangle Count from Triangles.bin File: " << nTriangles;
    notifyStatusMessage(s.str());

    // Allocate all the nodes
    typedef DREAM3D::SurfaceMesh::Vert_t Vert_t;
    StructArray<Vert_t>::Pointer m_NodeListPtr = StructArray<Vert_t>::CreateArray(nNodes, DREAM3D::VertexData::SurfaceMeshNodes);
    Vert_t* m_NodeList = m_NodeListPtr->GetPointer(0);

    Int8ArrayType::Pointer nodeTypePtr = Int8ArrayType::CreateArray(nNodes, 1, DREAM3D::VertexData::SurfaceMeshNodeType);
    nodeTypePtr->initializeWithZeros();
    int8_t* nodeType = nodeTypePtr->GetPointer(0);

    s.str("");
    s << "Reading Nodes file into Memory";
    notifyStatusMessage(s.str());
    size_t nread = 0;
    SurfaceMesh::NodesFile::NodesFileRecord_t nRecord;

    for (size_t i = 0; i < nNodes; i++)
    {

        nread = fread(&nRecord, SurfaceMesh::NodesFile::ByteCount, 1, nodesFile); // Read one set of positions from the nodes file
        if(nread != 1)
        {
            break;
        }
        DREAM3D::SurfaceMesh::Vert_t& node = m_NodeList[nRecord.nodeId];
        node.pos[0] = nRecord.x;
        node.pos[1] = nRecord.y;
        node.pos[2] = nRecord.z;
        nodeType[nRecord.nodeId] = nRecord.nodeKind;
    }

    s.str("");
    s << "Reading Triangles file into Memory";
    notifyStatusMessage(s.str());

    // Allocate all the Triangle Objects
    typedef DREAM3D::SurfaceMesh::Face_t Face_t;
    StructArray<Face_t>::Pointer m_TriangleListPtr = StructArray<Face_t>::CreateArray(nTriangles, DREAM3D::FaceData::SurfaceMeshFaces);
    Face_t* m_TriangleList = m_TriangleListPtr->GetPointer(0);
    ::memset(m_TriangleList, 0xAB, sizeof(Face_t) * nTriangles);

    DataArray<int32_t>::Pointer faceLabelPtr = DataArray<int32_t>::CreateArray(nTriangles, 2, DREAM3D::FaceData::SurfaceMeshFaceLabels);
    int32_t* faceLabels = faceLabelPtr->GetPointer(0);
    faceLabelPtr->initializeWithZeros();


    SurfaceMesh::TrianglesFile::TrianglesFileRecord_t tRecord;
    for (size_t i = 0; i < nTriangles; i++)
    {
        // Read from the Input Triangles Temp File
        nread = fread(&tRecord, SurfaceMesh::TrianglesFile::ByteCount, 1, triFile);
        if(nread != 1)
        {
            break;
        }

        DREAM3D::SurfaceMesh::Face_t& triangle = m_TriangleList[tRecord.triId];

        triangle.verts[0] = tRecord.nodeId_0;
        triangle.verts[1] = tRecord.nodeId_1;
        triangle.verts[2] = tRecord.nodeId_2;
        faceLabels[tRecord.triId * 2] = tRecord.label_0;
        faceLabels[tRecord.triId * 2 + 1] = tRecord.label_1;
    }

    sm->setVertices(m_NodeListPtr);
    sm->setFaces(m_TriangleListPtr);
    sm->addFaceData(faceLabelPtr->GetName(), faceLabelPtr);
    sm->addVertexData(nodeTypePtr->GetName(), nodeTypePtr);





    // The ScopedFileMonitor classes will take care of closing the files

    return getErrorCondition();
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FeatureFaceCurvatureFilter::dataCheck()
{
  setErrorCondition(0);
  DataArrayPath tempPath;

  TriangleGeom::Pointer triangles = getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName());

  QVector<IDataArray::Pointer> dataArrays;

  if(getErrorCondition() >= 0) { dataArrays.push_back(triangles->getTriangles()); }

  DataContainer::Pointer sm = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName(), false);
  if(getErrorCondition() < 0) { return; }


  // We do not know the size of the array so we can not use the macro so we just manually call
  // the needed methods that will propagate these array additions to the pipeline
  QVector<size_t> cDims(1, 1);
  tempPath = getFaceAttributeMatrixPath();
  tempPath.setDataArrayName(getSurfaceMeshPrincipalCurvature1sArrayName());
  m_SurfaceMeshPrincipalCurvature1sPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<double>, AbstractFilter, double>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_SurfaceMeshPrincipalCurvature1sPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_SurfaceMeshPrincipalCurvature1s = m_SurfaceMeshPrincipalCurvature1sPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { dataArrays.push_back(m_SurfaceMeshPrincipalCurvature1sPtr.lock()); }

  tempPath.setDataArrayName(getSurfaceMeshPrincipalCurvature2sArrayName());
  m_SurfaceMeshPrincipalCurvature2sPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<double>, AbstractFilter, double>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_SurfaceMeshPrincipalCurvature2sPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_SurfaceMeshPrincipalCurvature2s = m_SurfaceMeshPrincipalCurvature2sPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  if (m_ComputeGaussianCurvature == true)
  {
    tempPath.setDataArrayName(getSurfaceMeshGaussianCurvaturesArrayName());
    m_SurfaceMeshGaussianCurvaturesPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<double>, AbstractFilter, double>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_SurfaceMeshGaussianCurvaturesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    { m_SurfaceMeshGaussianCurvatures = m_SurfaceMeshGaussianCurvaturesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  }

  if (m_ComputeMeanCurvature == true)
  {
    tempPath.setDataArrayName(getSurfaceMeshMeanCurvaturesArrayName());
    m_SurfaceMeshMeanCurvaturesPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<double>, AbstractFilter, double>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_SurfaceMeshMeanCurvaturesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    { m_SurfaceMeshMeanCurvatures = m_SurfaceMeshMeanCurvaturesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  }

  if (m_ComputePrincipalDirectionVectors == true)
  {
    cDims[0] = 3;
    tempPath.setDataArrayName(getSurfaceMeshPrincipalDirection1sArrayName());
    m_SurfaceMeshPrincipalDirection1sPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<double>, AbstractFilter, double>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_SurfaceMeshPrincipalDirection1sPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    { m_SurfaceMeshPrincipalDirection1s = m_SurfaceMeshPrincipalDirection1sPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

    tempPath.setDataArrayName(getSurfaceMeshPrincipalDirection2sArrayName());
    m_SurfaceMeshPrincipalDirection2sPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<double>, AbstractFilter, double>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_SurfaceMeshPrincipalDirection2sPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    { m_SurfaceMeshPrincipalDirection2s = m_SurfaceMeshPrincipalDirection2sPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  }

  cDims[0] = 1;
  m_SurfaceMeshFeatureFaceIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFeatureFaceIdsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_SurfaceMeshFeatureFaceIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  {m_SurfaceMeshFeatureFaceIds = m_SurfaceMeshFeatureFaceIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { dataArrays.push_back(m_SurfaceMeshFeatureFaceIdsPtr.lock()); }

  cDims[0] = 2;
  m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  {m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { dataArrays.push_back(m_SurfaceMeshFaceLabelsPtr.lock()); }

  cDims[0] = 3;
  m_SurfaceMeshFaceNormalsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<double>, AbstractFilter>(this, getSurfaceMeshFaceNormalsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_SurfaceMeshFaceNormalsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_SurfaceMeshFaceNormals = m_SurfaceMeshFaceNormalsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { dataArrays.push_back(m_SurfaceMeshFaceNormalsPtr.lock()); }

  m_SurfaceMeshTriangleCentroidsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<double>, AbstractFilter>(this, getSurfaceMeshTriangleCentroidsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_SurfaceMeshTriangleCentroidsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_SurfaceMeshTriangleCentroids = m_SurfaceMeshTriangleCentroidsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { dataArrays.push_back(m_SurfaceMeshTriangleCentroidsPtr.lock()); }

  getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, dataArrays);
}
Exemplo n.º 4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void MergeColonies::dataCheck()
{
  setErrorCondition(0);
  DataArrayPath tempPath;

  GroupFeatures::dataCheck();
  if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer m = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, m_FeatureIdsArrayPath.getDataContainerName(), false);
  if(getErrorCondition() < 0 || NULL == m.get()) { return; }

  QVector<size_t> tDims(1, 0);
  m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getNewCellFeatureAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::CellFeature);

  QVector<size_t> cDims(1, 1);

  QVector<DataArrayPath> cellDataArrayPaths;
  QVector<DataArrayPath> featureDataArrayPaths;

  // Cell Data
  m_FeatureIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeatureIdsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { cellDataArrayPaths.push_back(getFeatureIdsArrayPath()); }

  m_CellPhasesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getCellPhasesArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_CellPhasesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_CellPhases = m_CellPhasesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { cellDataArrayPaths.push_back(getCellPhasesArrayPath()); }

  tempPath.update(getFeatureIdsArrayPath().getDataContainerName(), getFeatureIdsArrayPath().getAttributeMatrixName(), getCellParentIdsArrayName() );
  m_CellParentIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, -1, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_CellParentIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_CellParentIds = m_CellParentIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  if (m_IdentifyGlobAlpha == true)
  {
    tempPath.update(getFeatureIdsArrayPath().getDataContainerName(), getFeatureIdsArrayPath().getAttributeMatrixName(), getGlobAlphaArrayName() );
    m_GlobAlphaPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_GlobAlphaPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    { m_GlobAlpha = m_GlobAlphaPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  }

  // Feature Data
  m_FeaturePhasesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeaturePhasesArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_FeaturePhasesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_FeaturePhases = m_FeaturePhasesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { featureDataArrayPaths.push_back(getFeaturePhasesArrayPath()); }

  tempPath.update(getFeaturePhasesArrayPath().getDataContainerName(), getFeaturePhasesArrayPath().getAttributeMatrixName(), getFeatureParentIdsArrayName() );
  m_FeatureParentIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, -1, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_FeatureParentIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_FeatureParentIds = m_FeatureParentIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  cDims[0] = 4;
  m_AvgQuatsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getAvgQuatsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_AvgQuatsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_AvgQuats = m_AvgQuatsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() >= 0) { featureDataArrayPaths.push_back(getAvgQuatsArrayPath()); }

  // NewFeature Data
  cDims[0] = 1;
  tempPath.update(m_FeatureIdsArrayPath.getDataContainerName(), getNewCellFeatureAttributeMatrixName(), getActiveArrayName() );
  m_ActivePtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<bool>, AbstractFilter, bool>(this, tempPath, true, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_ActivePtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_Active = m_ActivePtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  // Ensemble Data
  m_CrystalStructuresPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<unsigned int>, AbstractFilter>(this, getCrystalStructuresArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_CrystalStructuresPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_CrystalStructures = m_CrystalStructuresPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
}
Exemplo n.º 5
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");
}
Exemplo n.º 6
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void INLWriter::dataCheck()
{
    setErrorCondition(0);

    getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getFeatureIdsArrayPath().getDataContainerName());

    if (getOutputFile().isEmpty() == true)
    {
        QString ss = QObject::tr("The output file must be set");
        notifyErrorMessage(getHumanLabel(), ss, -1);
        setErrorCondition(-387);
    }

    QFileInfo fi(getOutputFile());
    QDir parentPath = fi.path();
    if (parentPath.exists() == false)
    {
        QString ss = QObject::tr("The directory path for the output file does not exist. DREAM.3D will attempt to create this path during execution of the filter");
        notifyWarningMessage(getHumanLabel(), ss, -1);
    }

    QVector<DataArrayPath> cellDataArrayPaths;
    QVector<DataArrayPath> ensembleDataArrayPaths;

    QVector<size_t> cDims(1, 1);
    m_FeatureIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeatureIdsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    {
        m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0);    /* Now assign the raw pointer to data from the DataArray<T> object */
    }
    if(getErrorCondition() >= 0) {
        cellDataArrayPaths.push_back(getFeatureIdsArrayPath());
    }

    m_CellPhasesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getCellPhasesArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_CellPhasesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    {
        m_CellPhases = m_CellPhasesPtr.lock()->getPointer(0);    /* Now assign the raw pointer to data from the DataArray<T> object */
    }
    if(getErrorCondition() >= 0) {
        cellDataArrayPaths.push_back(getCellPhasesArrayPath());
    }

    m_CrystalStructuresPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<uint32_t>, AbstractFilter>(this,  getCrystalStructuresArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_CrystalStructuresPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    {
        m_CrystalStructures = m_CrystalStructuresPtr.lock()->getPointer(0);    /* Now assign the raw pointer to data from the DataArray<T> object */
    }
    if(getErrorCondition() >= 0) {
        ensembleDataArrayPaths.push_back(getCrystalStructuresArrayPath());
    }

    m_NumFeaturesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this,  getNumFeaturesArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_NumFeaturesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    {
        m_NumFeatures = m_NumFeaturesPtr.lock()->getPointer(0);    /* Now assign the raw pointer to data from the DataArray<T> object */
    }
    if(getErrorCondition() >= 0) {
        ensembleDataArrayPaths.push_back(getNumFeaturesArrayPath());
    }

    m_MaterialNamePtr = getDataContainerArray()->getPrereqArrayFromPath<StringDataArray, AbstractFilter>(this,  getMaterialNameArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if(getErrorCondition() >= 0) {
        ensembleDataArrayPaths.push_back(getMaterialNameArrayPath());
    }

    cDims[0] = 3;
    m_CellEulerAnglesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getCellEulerAnglesArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_CellEulerAnglesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    {
        m_CellEulerAngles = m_CellEulerAnglesPtr.lock()->getPointer(0);    /* Now assign the raw pointer to data from the DataArray<T> object */
    }
    if(getErrorCondition() >= 0) {
        cellDataArrayPaths.push_back(getCellEulerAnglesArrayPath());
    }

    getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, cellDataArrayPaths);
    getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, ensembleDataArrayPaths);
}
Exemplo n.º 7
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void EstablishMatrixPhase::dataCheck()
{
  setErrorCondition(0);
  DataArrayPath tempPath;

  getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getOutputCellAttributeMatrixPath().getDataContainerName());

  QVector<size_t> cDims(1, 1);
  m_PhaseTypesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<uint32_t>, AbstractFilter>(this, getInputPhaseTypesArrayPath(), cDims);
  if( NULL != m_PhaseTypesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_PhaseTypes = m_PhaseTypesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  m_StatsDataArray = getDataContainerArray()->getPrereqArrayFromPath<StatsDataArray, AbstractFilter>(this, getInputStatsArrayPath(), cDims);
  if(m_StatsDataArray.lock() == NULL)
  {
    QString ss = QObject::tr("Statistics array is not initialized correctly. The path is %1").arg(getInputStatsArrayPath().serialize());
    setErrorCondition(-308);
    notifyErrorMessage(getHumanLabel(), ss, -308);
  }

  cDims[0] = 1;
  // Cell Data
  tempPath.update(getOutputCellAttributeMatrixPath().getDataContainerName(), getOutputCellAttributeMatrixPath().getAttributeMatrixName(), getFeatureIdsArrayName() );
  m_FeatureIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, -1, cDims); /* Assigns the shared_ptr<>(this, tempPath, -1, dims); Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  tempPath.update(getOutputCellAttributeMatrixPath().getDataContainerName(), getOutputCellAttributeMatrixPath().getAttributeMatrixName(), getCellPhasesArrayName() );
  m_CellPhasesPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<>(this, tempPath, 0, dims); Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_CellPhasesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_CellPhases = m_CellPhasesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  if (m_UseMask == true)
  {
    m_MaskPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<bool>, AbstractFilter>(this, getMaskArrayPath(), cDims);
    if (NULL != m_MaskPtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    { m_Mask = m_MaskPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  }

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

  DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getOutputCellAttributeMatrixPath().getDataContainerName());

  QVector<size_t> tDims(1, 0);
  AttributeMatrix::Pointer cellFeatureAttrMat = m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getOutputCellFeatureAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::CellFeature);
  if(getErrorCondition() < 0 || NULL == cellFeatureAttrMat.get()) { return; }
  tDims[0] = m_PhaseTypesPtr.lock()->getNumberOfTuples();
  AttributeMatrix::Pointer cellEnsembleAttrMat = m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getOutputCellEnsembleAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::CellEnsemble);
  if(getErrorCondition() < 0 || NULL == cellEnsembleAttrMat.get()) { return; }

  // Feature Data
  tempPath.update(getOutputCellAttributeMatrixPath().getDataContainerName(), getOutputCellFeatureAttributeMatrixName(), getFeaturePhasesArrayName() );
  m_FeaturePhasesPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this,  tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_FeaturePhasesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_FeaturePhases = m_FeaturePhasesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  // Ensemble Data
  tempPath.update(getOutputCellAttributeMatrixPath().getDataContainerName(), getOutputCellEnsembleAttributeMatrixName(), getNumFeaturesArrayName() );
  m_NumFeaturesPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this,  tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_NumFeaturesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_NumFeatures = m_NumFeaturesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
}
Exemplo n.º 8
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void CropImageGeometry::dataCheck()
{
  if(getErrorCondition() < 0) { return; }
  setErrorCondition(0);

  // Validate the incoming DataContainer, Geometry, and AttributeMatrix ; bail if any do not exist since we plan on using them later on in the dataCheck
  // Error messages are handled by the getPrereq functions
  DataContainer::Pointer srcCellDataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getCellAttributeMatrixPath().getDataContainerName());
  ImageGeom::Pointer image = getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getCellAttributeMatrixPath().getDataContainerName());
  AttributeMatrix::Pointer srcCellAttrMat = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getCellAttributeMatrixPath(), -301);
  if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer destCellDataContainer = srcCellDataContainer;
  AttributeMatrix::Pointer destCellAttrMat;

  if (m_SaveAsNewDataContainer == true)
  {
    float ox = 0.0f, oy = 0.0f, oz = 0.0f, rx = 0.0f, ry = 0.0f, rz = 0.0f;
    size_t dx = 0, dy = 0, dz = 0;
    image->getOrigin(ox, oy, oz);
    image->getResolution(rx, ry, rz);
    image->getDimensions(dx, dy, dz);

    destCellDataContainer = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getNewDataContainerName());
    if(NULL == destCellDataContainer.get() || getErrorCondition() < 0)
    {
      return;
    }
    IGeometry::Pointer imageCopy = image->deepCopy();
    destCellDataContainer->setGeometry(imageCopy);

    destCellAttrMat = srcCellAttrMat->deepCopy();
    destCellDataContainer->addAttributeMatrix(destCellAttrMat->getName(), destCellAttrMat);
  }
  else
  {
    destCellAttrMat = srcCellAttrMat;
  }

  if(NULL == destCellDataContainer.get() || NULL == destCellAttrMat.get() || getErrorCondition() < 0)
  {
    return;
  }

  if (getXMax() < getXMin())
  {
    QString ss = QObject::tr("X Max (%1) less than X Min (%2)").arg(getXMax()).arg(getXMin());
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }
  if (getYMax() < getYMin())
  {
    QString ss = QObject::tr("Y Max (%1) less than Y Min (%2)").arg(getYMax()).arg(getYMin());
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }
  if (getZMax() < getZMin())
  {
    QString ss = QObject::tr("Z Max (%1) less than Z Min (%2)").arg(getZMax()).arg(getZMin());
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }
  if (getXMin() < 0)
  {
    QString ss = QObject::tr("X Min (%1) less than 0").arg(getXMin());
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }
  if (getYMin() < 0)
  {
    QString ss = QObject::tr("Y Min (%1) less than 0").arg(getYMin());
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }
  if (getZMin() < 0)
  {
    QString ss = QObject::tr("Z Min (%1) less than 0").arg(getZMin());
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }

  if (getXMax() > (static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getXPoints()) - 1))
  {
    QString ss = QObject::tr("The X Max (%1) is greater than the Image Geometry X extent (%2)").arg(getXMax()).arg(static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getXPoints()) - 1);
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }

  if (getYMax() > (static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getYPoints()) - 1))
  {
    QString ss = QObject::tr("The Y Max (%1) is greater than the Image Geometry Y extent (%2)").arg(getYMax()).arg(static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getYPoints()) - 1);
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }

  if (getZMax() > (static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getZPoints()) - 1))
  {
    QString ss = QObject::tr("The Z Max (%1) is greater than the Image Geometry Z extent (%2)").arg(getZMax()).arg(static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getZPoints()) - 1);
    notifyErrorMessage(getHumanLabel(), ss, -5550);
    setErrorCondition(-5550);
  }

  QVector<size_t> tDims(3, 0);
  if (getXMax() - getXMin() < 0) { setXMax(getXMin() + 1); }
  if (getYMax() - getYMin() < 0) { setYMax(getYMin() + 1); }
  if (getZMax() - getZMin() < 0) { setZMax(getZMin() + 1); }
  tDims[0] = (getXMax() - getXMin()) + 1;
  tDims[1] = (getYMax() - getYMin()) + 1;
  tDims[2] = (getZMax() - getZMin()) + 1;

  destCellDataContainer->getGeometryAs<ImageGeom>()->setDimensions(tDims[0], tDims[1], tDims[2]);

  // If any of the sanity checks fail above then we should NOT attempt to go any further.
  if (getErrorCondition() < 0) { return; }

  size_t totalPoints = 1;
  for(int i = 0; i < 3; i++) {
    if(tDims[i] != 0) { totalPoints *= tDims[i]; }
  }
  AttributeMatrix::Pointer newCellAttrMat = AttributeMatrix::New(tDims, destCellAttrMat->getName(), destCellAttrMat->getType());

  QList<QString> voxelArrayNames = destCellAttrMat->getAttributeArrayNames();
  for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
  {
    IDataArray::Pointer p = destCellAttrMat->getAttributeArray(*iter);
    //
    IDataArray::Pointer data = p->createNewArray(totalPoints, p->getComponentDimensions(), p->getName(), false);

    destCellAttrMat->removeAttributeArray(*iter);
    newCellAttrMat->addAttributeArray(*iter, data);
  }
  destCellDataContainer->removeAttributeMatrix(destCellAttrMat->getName());
  destCellDataContainer->addAttributeMatrix(newCellAttrMat->getName(), newCellAttrMat);


  if(m_RenumberFeatures == true)
  {
    QVector<size_t> cDims(1, 1);
    m_FeatureIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeatureIdsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    {
      m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0);
    } /* Now assign the raw pointer to data from the DataArray<T> object */

    AttributeMatrix::Pointer cellFeatureAttrMat = srcCellDataContainer->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName());
    if(NULL == cellFeatureAttrMat.get()) { return; }
    QVector<bool> activeObjects(cellFeatureAttrMat->getNumTuples(), true);
    cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock());
  }
}
Exemplo n.º 9
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void CropImageGeometry::execute()
{
  setErrorCondition(0);

  /* Normally, filters call dataCheck during the execute to reuse code.  Unfortunately, this cannot happen for this filter, because calling dataCheck
       would destroy an Attribute Matrix that we need during the execute.  Do not uncomment the code, and be careful when reusing code from either of
        these functions.  Make sure you understand how this works before you reuse any code. */
  //dataCheck();
  //if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer srcCellDataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getCellAttributeMatrixPath().getDataContainerName());
  AttributeMatrix::Pointer cellAttrMat = srcCellDataContainer->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
  DataContainer::Pointer destCellDataContainer = srcCellDataContainer;

  if (m_SaveAsNewDataContainer == true)
  {
    float ox = 0.0f, oy = 0.0f, oz = 0.0f, rx = 0.0f, ry = 0.0f, rz = 0.0f;
    srcCellDataContainer->getGeometryAs<ImageGeom>()->getOrigin(ox, oy, oz);
    srcCellDataContainer->getGeometryAs<ImageGeom>()->getResolution(rx, ry, rz);

    destCellDataContainer = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getNewDataContainerName());
    ImageGeom::Pointer image = ImageGeom::CreateGeometry(DREAM3D::Geometry::ImageGeometry);
    destCellDataContainer->setGeometry(image);

    destCellDataContainer->getGeometryAs<ImageGeom>()->setOrigin(ox, oy, oz);
    destCellDataContainer->getGeometryAs<ImageGeom>()->setResolution(rx, ry, rz);

    AttributeMatrix::Pointer cellAttrMatCopy = cellAttrMat->deepCopy();
    destCellDataContainer->addAttributeMatrix(cellAttrMatCopy->getName(), cellAttrMatCopy);
    cellAttrMat = destCellDataContainer->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
  }

  if(NULL == destCellDataContainer.get() || NULL == cellAttrMat.get() || getErrorCondition() < 0)
  {
    return;
  }


  // No matter where the AM is (same DC or new DC), we have the correct DC and AM pointers...now it's time to crop
  int64_t totalPoints = cellAttrMat->getNumTuples();

  size_t udims[3] =
  { 0, 0, 0 };
  srcCellDataContainer->getGeometryAs<ImageGeom>()->getDimensions(udims);
#if (CMP_SIZEOF_SIZE_T == 4)
  typedef int32_t DimType;
#else
  typedef int64_t DimType;
#endif
  DimType dims[3] =
  { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), };

  // Check to see if the dims have actually changed.
  if(dims[0] == (m_XMax - m_XMin) && dims[1] == (m_YMax - m_YMin) && dims[2] == (m_ZMax - m_ZMin))
  {
    return;
  }

  // Get current origin
  float oldOrigin[3] = {0.0f, 0.0f, 0.0f};
  destCellDataContainer->getGeometryAs<ImageGeom>()->getOrigin(oldOrigin);

  // Check to make sure the new dimensions are not "out of bounds" and warn the user if they are
  if (dims[0] <= m_XMax)
  {
    QString ss = QObject::tr("The Max X value (%1) is greater than the Image Geometry X entent (%2)."
                             " This may lead to junk data being filled into the extra space.").arg(m_XMax).arg(dims[0]);
    setErrorCondition(-950);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }
  if (dims[1] <= m_YMax)
  {

    QString ss = QObject::tr("The Max Y value (%1) is greater than the Image Geometry Y entent (%2)."
                             " This may lead to junk data being filled into the extra space.").arg(m_YMax).arg(dims[1]);
    setErrorCondition(-951);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }
  if (dims[2] <= m_ZMax)
  {

    QString ss = QObject::tr("The Max Z value (%1) is greater than the Image Geometry Z entent (%2)."
                             " This may lead to junk data being filled into the extra space.").arg(m_ZMax).arg(dims[2]);
    setErrorCondition(-952);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }

  int64_t XP = ( (m_XMax - m_XMin) + 1 );
  int64_t YP = ( (m_YMax - m_YMin) + 1 );
  int64_t ZP = ( (m_ZMax - m_ZMin) + 1 );

  int64_t col = 0, row = 0, plane = 0;
  int64_t colold = 0, rowold = 0, planeold = 0;
  int64_t index = 0;
  int64_t index_old = 0;
  QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames();
  for (int64_t i = 0; i < ZP; i++)
  {
    QString ss = QObject::tr("Cropping Volume - Slice %1 of %2 Complete").arg(i).arg(ZP);
    notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
    planeold = (i + m_ZMin) * (srcCellDataContainer->getGeometryAs<ImageGeom>()->getXPoints() * srcCellDataContainer->getGeometryAs<ImageGeom>()->getYPoints());
    plane = (i * XP * YP);
    for (int64_t j = 0; j < YP; j++)
    {
      rowold = (j + m_YMin) * srcCellDataContainer->getGeometryAs<ImageGeom>()->getXPoints();
      row = (j * XP);
      for (int64_t k = 0; k < XP; k++)
      {
        colold = (k + m_XMin);
        col = k;
        index_old = planeold + rowold + colold;
        index = plane + row + col;
        for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
        {
          IDataArray::Pointer p = cellAttrMat->getAttributeArray(*iter);
          p->copyTuple(index_old, index);
        }
      }
    }
  }
  destCellDataContainer->getGeometryAs<ImageGeom>()->setDimensions(static_cast<size_t>(XP), static_cast<size_t>(YP), static_cast<size_t>(ZP));
  totalPoints = destCellDataContainer->getGeometryAs<ImageGeom>()->getNumberOfElements();
  QVector<size_t> tDims(3, 0);
  tDims[0] = XP;
  tDims[1] = YP;
  tDims[2] = ZP;
  cellAttrMat->setTupleDimensions(tDims); // THIS WILL CAUSE A RESIZE of all the underlying data arrays.

  if (m_RenumberFeatures == true)
  {
    totalPoints = destCellDataContainer->getGeometryAs<ImageGeom>()->getNumberOfElements();

    // This just sanity checks to make sure there were existing features before the cropping
    AttributeMatrix::Pointer cellFeatureAttrMat = srcCellDataContainer->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName());
    size_t totalFeatures = cellFeatureAttrMat->getNumTuples();
    QVector<bool> activeObjects(totalFeatures, false);
    if (0 == totalFeatures)
    {
      setErrorCondition(-600);
      notifyErrorMessage(getHumanLabel(), "The number of Features is 0 and should be greater than 0", getErrorCondition());
      return;
    }

    //QVector<size_t> cDims(1, 1);
    DataArrayPath dap = getFeatureIdsArrayPath();
    if(getSaveAsNewDataContainer())
    {
      dap.setDataContainerName(getNewDataContainerName());
    }
    m_FeatureIdsPtr = cellAttrMat->getAttributeArrayAs<Int32ArrayType>(dap.getDataArrayName()); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    { m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
    else
    {
      setErrorCondition(-601);
      QString ss = QObject::tr("The FeatureIds array with name '%1' was not found in the destination DataContainer. The expected path was '%2'")
                   .arg(dap.getDataArrayName()).arg(dap.serialize("/"));
      notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
      return;
    }

    // Find the unique set of feature ids
    for (int64_t i = 0; i < totalPoints; ++i)
    {
      int32_t currentFeatureId = m_FeatureIds[i];
      if (currentFeatureId < totalFeatures)
      {
        activeObjects[currentFeatureId] = true;
      }
      else
      {
        setErrorCondition(-601);
        QString ss = QObject::tr("The total number of Features from %1 is %2, but a value of %3 was found in DataArray %4.").arg(cellFeatureAttrMat->getName()).arg(totalFeatures).arg(currentFeatureId).arg(getFeatureIdsArrayPath().serialize("/"));
        qDebug() << ss;
        notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
        return;
      }
    }
    cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock());
  }

  if(m_UpdateOrigin == true)
  {
    float resolution[3] = {0.0f, 0.0f, 0.0f};
    destCellDataContainer->getGeometryAs<ImageGeom>()->getResolution(resolution);

    float origin[3] = {0.0f, 0.0f, 0.0f};
    destCellDataContainer->getGeometryAs<ImageGeom>()->getOrigin(origin);

    origin[0] = m_XMin * resolution[0] + oldOrigin[0];
    origin[1] = m_YMin * resolution[1] + oldOrigin[1];
    origin[2] = m_ZMin * resolution[2] + oldOrigin[2];

    destCellDataContainer->getGeometryAs<ImageGeom>()->setOrigin(origin);
  }

  notifyStatusMessage(getHumanLabel(), "Complete");
}
Exemplo n.º 10
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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");
}
Exemplo n.º 11
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int32_t FileWriter::writeFile()
{
    setErrorCondition(-1);
    notifyErrorMessage(getHumanLabel(), "FileWriter should be subclassed and functionality implemented there", -1);
    return -1;
}
Exemplo n.º 12
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void EbsdToH5Ebsd::execute()
{
  std::stringstream ss;
  herr_t err = 0;
  hid_t fileId = -1;

  if(m_OutputFile.empty() == true)
  {
    std::string s("EbsdToH5Ebsd Error: The output file was not set correctly or is empty. The current value is '");
    s.append("'. Please set the output file before running the importer. ");

    ss << "EbsdToH5Ebsd input filename was empty";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
    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_OutputFile);
  if(!MXADir::mkdir(parentPath, true))
  {
    std::stringstream ss;
    PipelineMessage em (getHumanLabel(), ss.str(), -1);
    addErrorMessage(em);
    setErrorCondition(-1);
    return;
  }

  // Create File
  fileId = H5Utilities::createFile(m_OutputFile);
  if(fileId < 0)
  {
    err = -1;
    ss.str("");
    ss << "The Output HDF5 file could not be created. Check Permissions, if the File is in use by another program.";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
    return;
  }

  HDF5ScopedFileSentinel sentinel(&fileId, true);

  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::ZResolution, m_ZResolution);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Z Resolution Scalar to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }
  unsigned int ui = static_cast<unsigned int>(m_RefFrameZDir);
  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::StackingOrder, ui);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Stacking Order Scalar to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  std::string s = Ebsd::StackingOrder::Utils::getStringForEnum(m_RefFrameZDir);
  err = H5Lite::writeStringAttribute(fileId, Ebsd::H5::StackingOrder, "Name", s);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Stacking Order Name Attribute to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::SampleTransformationAngle, m_SampleTransformationAngle);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Sample Transformation Angle to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  std::vector<hsize_t> dims(1,3);
  err = H5Lite::writeVectorDataset(fileId, Ebsd::H5::SampleTransformationAxis, dims, m_SampleTransformationAxis);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Sample Transformation Axis to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::EulerTransformationAngle, m_EulerTransformationAngle);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Euler Transformation Angle to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  err = H5Lite::writeVectorDataset(fileId, Ebsd::H5::EulerTransformationAxis, dims, m_EulerTransformationAxis);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Euler Transformation Axis to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  EbsdImporter::Pointer fileImporter;

  // Write the Manufacturer of the OIM file here
  // This list will grow to be the number of EBSD file formats we support
  std::string ext = MXAFileInfo::extension(m_EbsdFileList.front());
  if(ext.compare(Ebsd::Ang::FileExt) == 0)
  {
    err = H5Lite::writeStringDataset(fileId, Ebsd::H5::Manufacturer, Ebsd::Ang::Manufacturer);
    if(err < 0)
    {
      ss.str("");
      ss << "Could not write the Manufacturer Data to the HDF5 File";
      addErrorMessage(getHumanLabel(), ss.str(), err);
      setErrorCondition(-1);
    }
    fileImporter = H5AngImporter::New();
  }
  else if(ext.compare(Ebsd::Ctf::FileExt) == 0)
  {
    err = H5Lite::writeStringDataset(fileId, Ebsd::H5::Manufacturer, Ebsd::Ctf::Manufacturer);
    if(err < 0)
    {
      ss.str("");
      ss << "Could not write the Manufacturer Data to the HDF5 File";
      addErrorMessage(getHumanLabel(), ss.str(), err);
      setErrorCondition(-1);
    }
    fileImporter = H5CtfImporter::New();
  }
  else if(ext.compare(Ebsd::Mic::FileExt) == 0)
  {
    err = H5Lite::writeStringDataset(fileId, Ebsd::H5::Manufacturer, Ebsd::Mic::Manufacturer);
    if(err < 0)
    {
      ss.str("");
      ss << "Could not write the Manufacturer Data to the HDF5 File";
      addErrorMessage(getHumanLabel(), ss.str(), err);
      setErrorCondition(-1);
    }
    fileImporter = H5MicImporter::New();
  }
  else
  {
    err = -1;
    ss.str("");
    ss << "The File extension was not detected correctly";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
    return;
  }

  std::vector<int> indices;
  // Loop on Each EBSD File
  float total = static_cast<float>( m_ZEndIndex - m_ZStartIndex );
  int progress = 0;
  int64_t z = m_ZStartIndex;
  int64_t xDim = 0, yDim = 0;
  float xRes = 0.0f, yRes = 0.0f;
  /* There is a frailness about the z index and the file list. The programmer
   * using this code MUST ensure that the list of files that is sent into this
   * class is in the appropriate order to match up with the z index (slice index)
   * otherwise the import will have subtle errors. The programmer is urged NOT to
   * simply gather a list from the file system as those lists are sorted in such
   * a way that if the number of digits appearing in the filename are NOT the same
   * then the list will be wrong, ie, this example:
   *
   * slice_1.ang
   * slice_2.ang
   * ....
   * slice_10.ang
   *
   * Most, if not ALL C++ libraries when asked for that list will return the list
   * sorted like the following:
   *
   * slice_1.ang
   * slice_10.ang
   * slice_2.ang
   *
   * which is going to cause problems because the data is going to be placed
   * into the HDF5 file at the wrong index. YOU HAVE BEEN WARNED.
   */
  int64_t biggestxDim = 0;
  int64_t biggestyDim = 0;
  int totalSlicesImported = 0;
  for (std::vector<std::string>::iterator filepath = m_EbsdFileList.begin(); filepath != m_EbsdFileList.end(); ++filepath)
  {
    std::string ebsdFName = *filepath;
    progress = static_cast<int>( z - m_ZStartIndex );
    progress = (int)(100.0f * (float)(progress) / total);
    std::string msg = "Converting File: " + ebsdFName;
    ss.str("");

    notifyStatusMessage(msg.c_str());
    err = fileImporter->importFile(fileId, z, ebsdFName);
    if (err < 0)
    {
      if (err != -600)
      {
        setErrorCondition(fileImporter->getErrorCondition());
        notifyErrorMessage(fileImporter->getPipelineMessage(), getErrorCondition());
        return;
      }
      else
      {
        notifyWarningMessage(fileImporter->getPipelineMessage(), fileImporter->getErrorCondition() );
        //setErrorCondition(fileImporter->getErrorCondition() );
        err = 0;
      }
    }
    totalSlicesImported = totalSlicesImported + fileImporter->numberOfSlicesImported();

    fileImporter->getDims(xDim, yDim);
    fileImporter->getResolution(xRes, yRes);
    if(xDim > biggestxDim) biggestxDim = xDim;
    if(yDim > biggestyDim) biggestyDim = yDim;

    indices.push_back( static_cast<int>(z) );
    ++z;
    if(getCancel() == true)
    {
      notifyStatusMessage("Conversion was Canceled");
      return;
    }
  }

  // Write Z index start, Z index end and Z Resolution to the HDF5 file
  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::ZStartIndex, m_ZStartIndex);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Z Start Index Scalar to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  m_ZEndIndex = m_ZStartIndex + totalSlicesImported - 1;
  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::ZEndIndex, m_ZEndIndex);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the Z End Index Scalar to the HDF5 File";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::XPoints, biggestxDim);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the XPoints Scalar to HDF5 file";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::YPoints, biggestyDim);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the YPoints Scalar to HDF5 file";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::XResolution, xRes);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the XResolution Scalar to HDF5 file";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  err = H5Lite::writeScalarDataset(fileId, Ebsd::H5::YResolution, yRes);
  if(err < 0)
  {
    ss.str("");
    ss << "Could not write the YResolution Scalar to HDF5 file";
    addErrorMessage(getHumanLabel(), ss.str(), err);
    setErrorCondition(-1);
  }

  if(false == getCancel())
  {
    // Write an Index data set which contains all the z index values which
    // should help speed up the reading side of this file
    std::vector<hsize_t> dims(1, indices.size());
    err = H5Lite::writeVectorDataset(fileId, Ebsd::H5::Index, dims, indices);
  }
  err = H5Utilities::closeFile(fileId);
  fileId = -1;
  notifyStatusMessage("Import Complete");
}
Exemplo n.º 13
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RawBinaryReader::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);


  // Get the total size of the array from the options
  size_t voxels = m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
  if (m_OverRideOriginResolution == true)
  {
    m->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z);
    m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z);
  }
  m->setDimensions(m_Dimensions.x, m_Dimensions.y, m_Dimensions.z);


  array = IDataArray::NullPointer();
  if (m_ScalarType == Detail::Int8)
  {
    Int8ArrayType::Pointer p = Int8ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<int8_t>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::UInt8)
  {
    UInt8ArrayType::Pointer p = UInt8ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<uint8_t>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::Int16)
  {
    Int16ArrayType::Pointer p = Int16ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<int16_t>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::UInt16)
  {
    UInt16ArrayType::Pointer p = UInt16ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<uint16_t>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::Int32)
  {
    Int32ArrayType::Pointer p = Int32ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<int32_t>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::UInt32)
  {
    UInt32ArrayType::Pointer p = UInt32ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<uint32_t>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::Int64)
  {
    Int64ArrayType::Pointer p = Int64ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<int64_t>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::UInt64)
  {
    UInt64ArrayType::Pointer p = UInt64ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<uint64_t>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::Float)
  {
    FloatArrayType::Pointer p = FloatArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<float>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }
  else if (m_ScalarType == Detail::Double)
  {
    DoubleArrayType::Pointer p = DoubleArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
    err = ReadBinaryFile<double>(p, m_InputFile, m_SkipHeaderBytes);
    if (err >= 0 ) { SWAP_ARRAY(p)
          array = p;}
  }

  if (NULL != array.get())
  {
    m->addCellData(array->GetName(), array);
  }
  else if(err == RBR_FILE_NOT_OPEN )
  {
    setErrorCondition(RBR_FILE_NOT_OPEN);
    notifyErrorMessage("RawBinaryReader was unable to open the specified file.", getErrorCondition());
  }
  else if (err == RBR_FILE_TOO_SMALL)
  {
    setErrorCondition(RBR_FILE_TOO_SMALL);
    notifyErrorMessage("The file size is smaller than the allocated size.", getErrorCondition());
  }
  else if (err == RBR_FILE_TOO_BIG)
  {
    notifyWarningMessage("The file size is larger than the allocated size.", RBR_FILE_TOO_BIG);
  }
  else if(err == RBR_READ_EOF)
  {
    setErrorCondition(RBR_READ_EOF);
    notifyErrorMessage("RawBinaryReader read past the end of the specified file.", getErrorCondition());
  }

  /* Let the GUI know we are done with this filter */
  notifyStatusMessage("Complete");
}
Exemplo n.º 14
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RawBinaryReader::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles)
{
  setErrorCondition(0);
  std::stringstream ss;
  VoxelDataContainer* m = getVoxelDataContainer();

  if (getInputFile().empty() == true)
  {
    ss << ClassName() << " needs the Input File Set and it was not.";
    setErrorCondition(-387);
    addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
  }
  else if (MXAFileInfo::exists(getInputFile()) == false)
  {
    ss << "The input file does not exist.";
    setErrorCondition(-388);
    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());
  }

  if (m_NumberOfComponents < 1)
  {
    ss.str("");
    ss << "The number of components must be larger than Zero";
    setErrorCondition(-391);
    addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
  }

  if (m_Dimensionality < 1)
  {
    ss.str("");
    ss << "The dimensionality must be larger than Zero";
    setErrorCondition(-389);
    addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
  }

  if (  m_Dimensions.x == 0 || m_Dimensions.y == 0 || m_Dimensions.z == 0)
  {
    ss.str("");
    ss << "One of the dimensions has a size less than or Equal to Zero (0). The minimum size must be greater than One (1).";
    setErrorCondition(-390);
    addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
  }

  if (true == preflight)
  {
    size_t allocatedBytes = 0;
    IDataArray::Pointer p = IDataArray::NullPointer();
    if (m_ScalarType == Detail::Int8)
    {
      p = Int8ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(int8_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::UInt8)
    {
      p = UInt8ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(uint8_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::Int16)
    {
      p = Int16ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(int16_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::UInt16)
    {
      p = UInt16ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(uint16_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::Int32)
    {
      p = Int32ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(int32_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::UInt32)
    {
      p = UInt32ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(uint32_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::Int64)
    {
      p = Int64ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(int64_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::UInt64)
    {
      p = UInt64ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(uint64_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::Float)
    {
      p = FloatArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(float) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }
    else if (m_ScalarType == Detail::Double)
    {
      p = DoubleArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName);
      allocatedBytes = sizeof(double) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z;
    }

    // Sanity Check Allocated Bytes versus size of file
    uint64_t fileSize = MXAFileInfo::fileSize(m_InputFile);
    int check = SanityCheckFileSizeVersusAllocatedSize(allocatedBytes, fileSize, m_SkipHeaderBytes);
    if (check == -1)
    {
      ss.str("");
      ss << "The file size is " << fileSize << " but the number of bytes needed to fill the array is " << allocatedBytes << ". This condition would cause an error reading the input file.";
      ss << " Please adjust the input parameters to match the size of the file or select a different data file.";
      setErrorCondition(RBR_FILE_TOO_SMALL);
      addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
    }
    else if (check == 1)
    {
      ss.str("");
      ss << "The file size is " << fileSize << " but the number of bytes needed to fill the array is " << allocatedBytes << " which is less than the size of the file.";
      ss << " DREAM3D will read only the first part of the file into the array.";
      addWarningMessage(getHumanLabel(), ss.str(), RBR_FILE_TOO_BIG);
    }

    m->addCellData(p->GetName(), p);

    m->setDimensions(m_Dimensions.x, m_Dimensions.y, m_Dimensions.z);
    m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z);
    m->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z);
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FindDirectionalModuli::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  //get number of features
  size_t totalFeatures = m_DirectionalModuliPtr.lock()->getNumberOfTuples();

  //wrap quats
  QuatF* avgQuats = reinterpret_cast<QuatF*>(m_AvgQuats);

  // //fill compliance matrix for each phase
  // typedef Eigen::Matrix<float, 6, 6> Matrix6f;
  // size_t totalPhases = m_CrystalCompliancesPtr.lock()->getNumberOfTuples();
  // std::vector<Matrix6f, Eigen::aligned_allocator<Matrix6f> > compliance(totalPhases, Matrix6f::Zero());
  // for(int i = 0; i < totalPhases; i++)
  // {
  //   size_t index = i * 36;
  //   compliance[i] << m_CrystalCompliances[index + 0],  m_CrystalCompliances[index + 1],  m_CrystalCompliances[index + 2],  m_CrystalCompliances[index + 3],  m_CrystalCompliances[index + 4],  m_CrystalCompliances[index + 5],
  //                    m_CrystalCompliances[index + 6],  m_CrystalCompliances[index + 7],  m_CrystalCompliances[index + 8],  m_CrystalCompliances[index + 9],  m_CrystalCompliances[index + 10], m_CrystalCompliances[index + 11],
  //                    m_CrystalCompliances[index + 12], m_CrystalCompliances[index + 13], m_CrystalCompliances[index + 14], m_CrystalCompliances[index + 15], m_CrystalCompliances[index + 16], m_CrystalCompliances[index + 17],
  //                    m_CrystalCompliances[index + 18], m_CrystalCompliances[index + 19], m_CrystalCompliances[index + 20], m_CrystalCompliances[index + 21], m_CrystalCompliances[index + 22], m_CrystalCompliances[index + 23],
  //                    m_CrystalCompliances[index + 24], m_CrystalCompliances[index + 25], m_CrystalCompliances[index + 26], m_CrystalCompliances[index + 27], m_CrystalCompliances[index + 28], m_CrystalCompliances[index + 29],
  //                    m_CrystalCompliances[index + 30], m_CrystalCompliances[index + 31], m_CrystalCompliances[index + 32], m_CrystalCompliances[index + 33], m_CrystalCompliances[index + 34], m_CrystalCompliances[index + 35] ;
  // }

  QuatF q1, q2, qTotal;
  float sampleLoading[3];
  //float crystalLoading[3];

  //normalize loading direction
  sampleLoading[0] = m_LoadingDirection.x;
  sampleLoading[1] = m_LoadingDirection.y;
  sampleLoading[2] = m_LoadingDirection.z;
  MatrixMath::Normalize3x1(sampleLoading);

  //determine a rotation that aligns the loading with the sample 100 direction (as quaternion)
  if(sampleLoading[0] >= 1.0f - std::numeric_limits<float>::epsilon())
  {
    //already 100 aligned
    QuaternionMathF::Identity(q2);
  }
  else if(sampleLoading[0] <= -1.0f + std::numeric_limits<float>::epsilon())
  {
    //-100 aligned (rotate 180 deg about any non 100 axis)
    q2.x = 0.0f;
    q2.y = 0.0f;
    q2.z = 1.0f;
    q2.w = 0.0f;
  }
  else
  {
    //not a special case, get appropriate quaternion manually
    /* for two unit vectors u and v the quaternion defining the rotation (u -> v)
     *  n = u x v
     *  q.x = n.x
     *  q.y = n.y
     *  q.z = n.z
     *  q.w = 1 + u.v
     *  normalize q
     */
    q2.x = 0.0f;
    q2.y = sampleLoading[2];
    q2.z = -sampleLoading[1];
    q2.w = 1.0f + sampleLoading[0];
    QuaternionMathF::UnitQuaternion(q2);
  }

  //loop over all grains
  for (size_t i = 0; i < totalFeatures; i++)
  {
    //default to 0
    m_DirectionalModuli[i] = 0;

    //get phase and crystal structure
    size_t phase = m_FeaturePhases[i];
    size_t xtal = m_CrystalStructures[phase];
    if(xtal < Ebsd::CrystalStructure::LaueGroupEnd)
    {
      //concatenate rotation with crystal orientation (determine rotation from crystal frame to sample loading direction)
      QuaternionMathF::Copy(avgQuats[i], q1);
      QuaternionMathF::Multiply(q1, q2, qTotal);

      /*
      This method is straightforward but computationally very expensive/wasteful (since it computes the full rotated compliance matrix and we only need s'11)

      //convert orientation to rotation matrix and invert (need rotation from crystal -> sample frame)
      QuaternionMathF::Conjugate(qTotal);
      OrientationMath::QuattoMat(q1, g);

      //construct 6x6 compliance rotation matrix (after Applied Mechanics of Solids, A.F. Bower: pg. 80)
        //compute quadrants of stiffness rotation matrix
        float k1[3][3];
        float k2[3][3];
        float k3[3][3];
        float k4[3][3];
        for(int j = 0; j < 3; j++)
        {
          int j1mod3 = (j + 1) % 3;
          int j2mod3 = (j + 2) % 3;
          for(int k = 0; k < 3; k++)
          {
            int k1mod3 = (k + 1) % 3;
            int k2mod3 = (k + 2) % 3;
            k1[j][k] = g[j][k] * g[j][k];
            k2[j][k] = 2.0f * g[j][k1mod3] * g[j][k2mod3];
            k3[j][k] = g[j1mod3][k] * g[j2mod3][k];
            k4[j][k] = g[j1mod3][k1mod3] * g[j2mod3][k2mod3] + g[j1mod3][k2mod3] * g[j2mod3][k1mod3];
          }
        }

        //assemble stiffness rotation matrix
        Matrix6f k;
        k << k1[0][0], k1[0][1], k1[0][2], k2[0][0], k2[0][1], k2[0][2],
             k1[1][0], k1[1][1], k1[1][2], k2[1][0], k2[1][1], k2[1][2],
             k1[2][0], k1[2][1], k1[2][2], k2[2][0], k2[2][1], k2[2][2],
             k3[0][0], k3[0][1], k3[0][2], k4[0][0], k4[0][1], k4[0][2],
             k3[1][0], k3[1][1], k3[1][2], k4[1][0], k4[1][1], k4[1][2],
             k3[2][0], k3[2][1], k3[2][2], k4[2][0], k4[2][1], k4[2][2];

        //compute compliance rotation matrix
        k = k.inverse();

      //rotate compliance to sample frame
      Matrix6f sampleCompliance = (k.transpose() * compliance[phase]) * k;

      //compute modulus
      m_DirectionalModuli[i] = 1.0f / sampleCompliance(0, 0);

      */

      //Instead I've solved the above symbolically for the quaternion derivted rotation matrix
      // float g00 = (1.0f - (2.0f * q1.y * q1.y) - (2.0f * q1.z * q1.z));
      // float g01 = ((2.0f * q1.x * q1.y) - (2.0f * q1.z * q1.w));
      // float g02 = ((2.0f * q1.x * q1.z) + (2.0f * q1.y * q1.w));

      // float g10 = ((2.0f * q1.x * q1.y) + (2.0f * q1.z * q1.w));
      // float g11 = (1.0f - (2.0f * q1.x * q1.x) - (2.0f * q1.z * q1.z));
      // float g12 = (2.0f * q1.y * q1.z) - (2.0f * q1.x * q1.w);

      // float g20 = ((2.0f * q1.x * q1.z) - (2.0f * q1.y * q1.w));
      // float g21 = (2.0f * q1.y * q1.z) + (2.0f * q1.x * q1.w);
      // float g22 = (1.0f - (2.0f * q1.x * q1.x) - (2.0f * q1.y * q1.y));

      //everything simplifies to a function of 4 factors
      // float a = g11 * g22 - g12 * g21;
      // float b = g12 * g20 - g10 * g22;
      // float c = g10 * g21 - g11 * g20;
      // float denom = powf(g02 * g11 * g20 - g01 * g12 * g20 - g02 * g10 * g21 + g00 * g12 * g21 + g01 * g10 * g22 - g00 * g11 * g22, 4);

      //these can be expressed more compactly directly from quaternions (especially if a unit quaternion is assumed)
      float a = 1.0f - 2.0f * (qTotal.y * qTotal.y + qTotal.z * qTotal.z);
      float b = 2.0f * (qTotal.x * qTotal.y - qTotal.z * qTotal.w);
      float c = 2.0f * (qTotal.x * qTotal.z + qTotal.y * qTotal.w);
      //denom = 1.0

      //squares are used extensively, compute once
      float a2 = a * a;
      float b2 = b * b;
      float c2 = c * c;

      //compute rotated compliance weightings
      float s11Coef = a2 * a2;//a^4
      float s22Coef = b2 * b2;//b^4
      float s33Coef = c2 * c2;//c^4
      float s44Coef = b2 * c2;//b^2 c^2
      float s55Coef = a2 * c2;//a^2 c^2
      float s66Coef = a2 * b2;//a^2 b^2

      float s12Coef = 2.0f * a2 * b2;//2 a^2 b^2
      float s23Coef = 2.0f * b2 * c2;//2 b^2 c^2
      float s13Coef = 2.0f * a2 * c2;//2 a^2 c^2

      float s14Coef = 2.0f * a2 * b * c;//2 a^2 b c
      float s15Coef = 2.0f * a2 * a * c;//2 a^3 c
      float s16Coef = 2.0f * a2 * a * b;//2 a^3 b

      float s24Coef = 2.0f * b2 * b * c;//2 b^3 c
      float s25Coef = 2.0f * b2 * a * c;//2 a b^2 c
      float s26Coef = 2.0f * b2 * a * b;//2 a b^3
      float s34Coef = 2.0f * c2 * b * c;//2 b c^3
      float s35Coef = 2.0f * c2 * a * c;//2 a c^3
      float s36Coef = 2.0f * c2 * a * b;//2 a b c^2

      float s45Coef = 2.0f * a * b * c2;//2 a b c^2
      float s46Coef = 2.0f * a * b2 * c;//2 a b^2 c
      float s56Coef = 2.0f * a2 * b * c;//2 a^2 b c

      //compute rotated compliance
      size_t index = 36 * phase;
      float s11prime = s11Coef * m_CrystalCompliances[index + 0] +
                       s12Coef * m_CrystalCompliances[index + 1] +
                       s13Coef * m_CrystalCompliances[index + 2] +
                       s14Coef * m_CrystalCompliances[index + 3] +
                       s15Coef * m_CrystalCompliances[index + 4] +
                       s16Coef * m_CrystalCompliances[index + 5] +

                       s22Coef * m_CrystalCompliances[index + 7] +
                       s23Coef * m_CrystalCompliances[index + 8] +
                       s24Coef * m_CrystalCompliances[index + 9] +
                       s25Coef * m_CrystalCompliances[index + 10] +
                       s26Coef * m_CrystalCompliances[index + 11] +

                       s33Coef * m_CrystalCompliances[index + 14] +
                       s34Coef * m_CrystalCompliances[index + 15] +
                       s35Coef * m_CrystalCompliances[index + 16] +
                       s36Coef * m_CrystalCompliances[index + 17] +

                       s44Coef * m_CrystalCompliances[index + 21] +
                       s45Coef * m_CrystalCompliances[index + 22] +
                       s46Coef * m_CrystalCompliances[index + 23] +

                       s55Coef * m_CrystalCompliances[index + 28] +
                       s56Coef * m_CrystalCompliances[index + 29] +

                       s66Coef * m_CrystalCompliances[index + 35];

      //compute modulus
      m_DirectionalModuli[i] = 1.0f / s11prime;
    }
  }

  notifyStatusMessage(getHumanLabel(), "Completed");
}
Exemplo n.º 16
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");
}
Exemplo n.º 17
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void InitializeData::dataCheck()
{
  setErrorCondition(0);

  getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getCellAttributeMatrixPath(), -301);

  ImageGeom::Pointer image = getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getCellAttributeMatrixPath().getDataContainerName());
  if(NULL == image.get()) { return; }

  if (getXMax() < getXMin())
  {
    QString ss = QObject::tr("X Max (%1) less than X Min (%2)").arg(getXMax()).arg(getXMin());
    setErrorCondition(-5551);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  if (getYMax() < getYMin())
  {
    QString ss = QObject::tr("Y Max (%1) less than Y Min (%2)").arg(getYMax()).arg(getYMin());
    setErrorCondition(-5552);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  if (getZMax() < getZMin())
  {
    QString ss = QObject::tr("Z Max (%1) less than Z Min (%2)").arg(getZMax()).arg(getZMin());
    setErrorCondition(-5553);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  if (getXMin() < 0)
  {
    QString ss = QObject::tr("X Min (%1) less than 0").arg(getXMin());
    setErrorCondition(-5554);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  if (getYMin() < 0)
  {
    QString ss = QObject::tr("Y Min (%1) less than 0").arg(getYMin());
    setErrorCondition(-5555);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  if (getZMin() < 0)
  {
    QString ss = QObject::tr("Z Min (%1) less than 0").arg(getZMin());
    setErrorCondition(-5556);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  if (getXMax() > (static_cast<int64_t>(image->getXPoints()) - 1))
  {
    QString ss = QObject::tr("The X Max you entered of %1 is greater than your Max X Point of %2").arg(getXMax()).arg(static_cast<int64_t>(image->getXPoints()) - 1);
    setErrorCondition(-5557);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  if (getYMax() > (static_cast<int64_t>(image->getYPoints()) - 1))
  {
    QString ss = QObject::tr("The Y Max you entered of %1 is greater than your Max Y Point of %2").arg(getYMax()).arg(static_cast<int64_t>(image->getYPoints()) - 1);
    setErrorCondition(-5558);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  if (getZMax() > (static_cast<int64_t>(image->getZPoints()) - 1))
  {
    QString ss = QObject::tr("The Z Max you entered of %1) greater than your Max Z Point of %2").arg(getZMax()).arg(static_cast<int64_t>(image->getZPoints()) - 1);
    setErrorCondition(-5559);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int32_t INLWriter::writeFile()
{
    setErrorCondition(0);
    dataCheck();
    if(getErrorCondition() < 0) {
        return getErrorCondition();
    }

    DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getFeatureIdsArrayPath().getDataContainerName());

    size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples();

    int32_t err = 0;
    size_t dims[3] = { 0, 0, 0 };
    m->getGeometryAs<ImageGeom>()->getDimensions(dims);
    float res[3] = { 0.0f, 0.0f, 0.0f };
    m->getGeometryAs<ImageGeom>()->getResolution(res);
    float origin[3] = { 0.0f, 0.0f, 0.0f };
    m->getGeometryAs<ImageGeom>()->getOrigin(origin);

    // Make sure any directory path is also available as the user may have just typed
    // in a path without actually creating the full path
    QFileInfo fi(getOutputFile());
    QDir dir(fi.path());
    if (!dir.mkpath("."))
    {
        QString ss = QObject::tr("Error creating parent path '%1'").arg(fi.path());
        notifyErrorMessage(getHumanLabel(), ss, -1);
        setErrorCondition(-1);
        return -1;
    }

    FILE* f = fopen(getOutputFile().toLatin1().data(), "wb");
    if (NULL == f)
    {
        QString ss = QObject::tr("Error opening output file '%1'").arg(getOutputFile());
        notifyErrorMessage(getHumanLabel(), ss, -1);
        setErrorCondition(-1);
        return -1;
    }

    // Write the header, Each line starts with a "#" symbol
    fprintf(f, "# File written from %s\r\n", SIMPLib::Version::PackageComplete().toLatin1().data());
    fprintf(f, "# DateTime: %s\r\n", QDateTime::currentDateTime().toString().toLatin1().data());
    fprintf(f, "# X_STEP: %f\r\n", res[0]);
    fprintf(f, "# Y_STEP: %f\r\n", res[1]);
    fprintf(f, "# Z_STEP: %f\r\n", res[2]);
    fprintf(f, "#\r\n");
    fprintf(f, "# X_MIN: %f\r\n", origin[0]);
    fprintf(f, "# Y_MIN: %f\r\n", origin[1]);
    fprintf(f, "# Z_MIN: %f\r\n", origin[2]);
    fprintf(f, "#\r\n");
    fprintf(f, "# X_MAX: %f\r\n", origin[0] + (dims[0]*res[0]));
    fprintf(f, "# Y_MAX: %f\r\n", origin[1] + (dims[1]*res[1]));
    fprintf(f, "# Z_MAX: %f\r\n", origin[2] + (dims[2]*res[2]));
    fprintf(f, "#\r\n");
    fprintf(f, "# X_DIM: %llu\r\n", static_cast<long long unsigned int>(dims[0]));
    fprintf(f, "# Y_DIM: %llu\r\n", static_cast<long long unsigned int>(dims[1]));
    fprintf(f, "# Z_DIM: %llu\r\n", static_cast<long long unsigned int>(dims[2]));
    fprintf(f, "#\r\n");

    StringDataArray* materialNames = m_MaterialNamePtr.lock().get();

#if 0
    -------------------------------------------- -
# Phase_1: MOX with 30% Pu
# Symmetry_1: 43
# Features_1: 4
#
# Phase_2: Brahman
# Symmetry_2: 62
# Features_2: 6
#
# Phase_3: Void
# Symmetry_3: 22
# Features_3: 1
#
# Total_Features: 11
    -------------------------------------------- -
#endif


    uint32_t symmetry = 0;
    int32_t count = static_cast<int32_t>(materialNames->getNumberOfTuples());
    for (int32_t i = 1; i < count; ++i)
    {
        QString matName = materialNames->getValue(i);
        fprintf(f, "# Phase_%d: %s\r\n", i, matName.toLatin1().data());
        symmetry = m_CrystalStructures[i];
        symmetry = mapCrystalSymmetryToTslSymmetry(symmetry);
        fprintf(f, "# Symmetry_%d: %u\r\n", i, symmetry);
        fprintf(f, "# Features_%d: %d\r\n", i, m_NumFeatures[i]);
        fprintf(f, "#\r\n");
    }

    std::set<int32_t> uniqueFeatureIds;
    for (size_t i = 0; i < totalPoints; ++i)
    {
        uniqueFeatureIds.insert(m_FeatureIds[i]);
    }
    count = static_cast<int32_t>(uniqueFeatureIds.size());
    fprintf(f, "# Num_Features: %d \r\n", count);
    fprintf(f, "#\r\n");

    //  fprintf(f, "# Column 1-3: phi1, PHI, phi2 (orientation of point in radians)\r\n");
    //  fprintf(f, "# Column 4-6: x, y, z (coordinates of point in microns)\r\n");
    //  fprintf(f, "# Column 7: Feature ID\r\n");
    //  fprintf(f, "# Column 8: Phase ID\r\n");

    fprintf(f, "# phi1 PHI phi2 x y z FeatureId PhaseId Symmetry\r\n");

    float phi1 = 0.0f, phi = 0.0f, phi2 = 0.0f;
    float xPos = 0.0f, yPos = 0.0f, zPos = 0.0f;
    int32_t featureId = 0;
    int32_t phaseId = 0;

    size_t index = 0;
    for (size_t z = 0; z < dims[2]; ++z)
    {
        for (size_t y = 0; y < dims[1]; ++y)
        {
            for (size_t x = 0; x < dims[0]; ++x)
            {
                index = (z * dims[0] * dims[1]) + (dims[0] * y) + x;
                phi1 = m_CellEulerAngles[index * 3];
                phi = m_CellEulerAngles[index * 3 + 1];
                phi2 = m_CellEulerAngles[index * 3 + 2];
                xPos = origin[0] + (x * res[0]);
                yPos = origin[1] + (y * res[1]);
                zPos = origin[2] + (z * res[2]);
                featureId = m_FeatureIds[index];
                phaseId = m_CellPhases[index];
                symmetry = m_CrystalStructures[phaseId];
                if (phaseId > 0)
                {
                    if (symmetry == Ebsd::CrystalStructure::Cubic_High)
                    {
                        symmetry = Ebsd::Ang::PhaseSymmetry::Cubic;
                    }
                    else if (symmetry == Ebsd::CrystalStructure::Hexagonal_High)
                    {
                        symmetry = Ebsd::Ang::PhaseSymmetry::DiHexagonal;
                    }
                    else
                    {
                        symmetry = Ebsd::Ang::PhaseSymmetry::UnknownSymmetry;
                    }
                }
                else
                {
                    symmetry = Ebsd::Ang::PhaseSymmetry::UnknownSymmetry;
                }

                fprintf(f, "%f %f %f %f %f %f %d %d %d\r\n", phi1, phi, phi2, xPos, yPos, zPos, featureId, phaseId, symmetry);
            }
        }
    }

    fclose(f);

    notifyStatusMessage(getHumanLabel(), "Complete");
    return err;
}
Exemplo n.º 20
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int VoxelDataContainerWriter::writeFieldData(hid_t dcGid)
{
  std::stringstream ss;
  int err = 0;
  VoxelDataContainer* m = getVoxelDataContainer();

#if WRITE_FIELD_XDMF
// 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_FIELD_DATA_GROUP_NAME;
#endif

  int64_t volDims[3] = { 0,0,0 };


  // Write the Field Data
  err = H5Utilities::createGroupsFromPath(H5_FIELD_DATA_GROUP_NAME, dcGid);
  if(err < 0)
  {
    std::cout << "Error creating HDF Group " << H5_FIELD_DATA_GROUP_NAME << std::endl;
    return err;
  }
  err = H5Lite::writeStringAttribute(dcGid, H5_FIELD_DATA_GROUP_NAME, H5_NAME, H5_FIELD_DATA_DEFAULT);
  if(err < 0)
  {
    return err;
  }

  hid_t fieldGroupId = H5Gopen(dcGid, H5_FIELD_DATA_GROUP_NAME, H5P_DEFAULT);
  if(err < 0)
  {
    ss.str("");
    ss << "Error opening field Group " << H5_FIELD_DATA_GROUP_NAME << std::endl;
    setErrorCondition(-65);
    notifyErrorMessage( ss.str(), err);
    H5Gclose(dcGid); // Close the Data Container Group
    return err;
  }

  size_t total = 0;
  typedef std::vector<IDataArray*> VectorOfIDataArrays_t;
  VectorOfIDataArrays_t neighborListArrays;

  NameListType names = m->getFieldArrayNameList();
  if (names.size() > 0)
  {
    IDataArray::Pointer array = m->getFieldData(names.front());
    total = array->GetSize();
    volDims[0] = total;
    volDims[1] = 1;
    volDims[2] = 1;
#if WRITE_FIELD_XDMF
    ss.str("");
    ss << "Field Data (" << total << ")";
    writeFieldXdmfGridHeader(total, ss.str());
#endif
  }
  // Now loop over all the field data and write it out, possibly wrapping it with XDMF code also.
  for (NameListType::iterator iter = names.begin(); iter != names.end(); ++iter)
  {
    IDataArray::Pointer array = m->getFieldData(*iter);
    if (array->getTypeAsString().compare(NeighborList<int>::ClassName()) == 0)
    {
      neighborListArrays.push_back(array.get());
    }
    else if (NULL != array.get())
    {
      err = array->writeH5Data(fieldGroupId);
      if(err < 0)
      {
        ss.str("");
        ss << "Error writing field array '" << (*iter).c_str() << "' to the HDF5 File";
        notifyErrorMessage( ss.str(), err);
        setErrorCondition(err);
        H5Gclose(fieldGroupId); // Close the Cell Group
        H5Gclose(dcGid); // Close the Data Container Group
        return err;
      }
#if WRITE_FIELD_XDMF
      array->writeXdmfAttribute( *m_XdmfPtr, volDims, hdfFileName, xdmfGroupPath, " (Field)");
#endif
    }
  }


#if WRITE_FIELD_XDMF
  if (names.size() > 0)
  {
    writeXdmfGridFooter("Field Data");
  }
#endif

  // Write the NeighborLists onto their own grid
  // We need to determine how many total elements we are going to end up with and group the arrays by
  // those totals so we can minimize the number of grids
  typedef std::map<size_t, VectorOfIDataArrays_t> SizeToIDataArrays_t;
  SizeToIDataArrays_t sizeToDataArrays;

  for(VectorOfIDataArrays_t::iterator iter = neighborListArrays.begin(); iter < neighborListArrays.end(); ++iter)
  {
    IDataArray* array = (*iter);
    sizeToDataArrays[array->GetSize()].push_back(array);
  }

  // Now loop over each pair in the map creating a section in the XDMF and also writing the data to the HDF5 file
  for(SizeToIDataArrays_t::iterator pair = sizeToDataArrays.begin(); pair != sizeToDataArrays.end(); ++pair)
  {
    total = (*pair).first;
    VectorOfIDataArrays_t& arrays = (*pair).second;
    volDims[0] = total;
    volDims[1] = 1;
    volDims[2] = 1;
    #if WRITE_FIELD_XDMF
    ss.str("");
    ss << "Neighbor Data (" << total << ")";
    writeFieldXdmfGridHeader(total, ss.str());
    #endif
    for(VectorOfIDataArrays_t::iterator iter = arrays.begin(); iter < arrays.end(); ++iter)
    {
      err = (*iter)->writeH5Data(fieldGroupId);
      if(err < 0)
      {
        ss.str("");
        ss << "Error writing neighbor list field array '" << (*iter)->GetName() << "' to the HDF5 File";
        notifyErrorMessage( ss.str(), err);
        setErrorCondition(err);
        H5Gclose(fieldGroupId); // Close the Cell Group
        H5Gclose(dcGid); // Close the Data Container Group
        return err;
      }
#if WRITE_FIELD_XDMF
      (*iter)->writeXdmfAttribute( *m_XdmfPtr, volDims, hdfFileName, xdmfGroupPath, " (Neighbor Data)");
#endif
    }
#if WRITE_FIELD_XDMF
    writeXdmfGridFooter(ss.str());
#endif

  }

  H5Gclose(fieldGroupId);
  return err;
}
Exemplo n.º 21
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void  EstablishMatrixPhase::establish_matrix()
{
  notifyStatusMessage(getHumanLabel(), "Establishing Matrix");
  SIMPL_RANDOMNG_NEW()

  DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getOutputCellAttributeMatrixPath().getDataContainerName());

  StatsDataArray& statsDataArray = *(m_StatsDataArray.lock());

  size_t udims[3] =
  { 0, 0, 0 };
  m->getGeometryAs<ImageGeom>()->getDimensions(udims);
#if (CMP_SIZEOF_SIZE_T == 4)
  typedef int32_t DimType;
#else
  typedef int64_t DimType;
#endif
  DimType dims[3] =
  {
    static_cast<DimType>(udims[0]),
    static_cast<DimType>(udims[1]),
    static_cast<DimType>(udims[2]),
  };

  sizex = dims[0] * m->getGeometryAs<ImageGeom>()->getXRes();
  sizey = dims[1] * m->getGeometryAs<ImageGeom>()->getYRes();
  sizez = dims[2] * m->getGeometryAs<ImageGeom>()->getZRes();
  totalvol = sizex * sizey * sizez;

  size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples();
  size_t currentnumfeatures = m_FeaturePhasesPtr.lock()->getNumberOfTuples();
  size_t numensembles = m_PhaseTypesPtr.lock()->getNumberOfTuples();
  QVector<size_t> tDims(1, 1);
  if (currentnumfeatures == 0)
  {
    m->getAttributeMatrix(m_OutputCellFeatureAttributeMatrixName)->resizeAttributeArrays(tDims);
    updateFeatureInstancePointers();
    currentnumfeatures = 1;
  }
  firstMatrixFeature = currentnumfeatures;
  float random = 0.0f;
  float totalmatrixfractions = 0.0f;

  for (size_t i = 1; i < numensembles; ++i)
  {
    if (m_PhaseTypes[i] == DREAM3D::PhaseType::MatrixPhase)
    {
      MatrixStatsData* mp = MatrixStatsData::SafePointerDownCast(statsDataArray[i].get());
      if (NULL == mp)
      {
        QString ss = QObject::tr("Tried to cast a statsDataArray[%1].get() to a MatrixStatsData* "
                                 "pointer but this resulted in a NULL pointer. The value at m_PhaseTypes[%2] = %3 does not match up "
                                 "with the type of pointer stored in the StatsDataArray (MatrixStatsData)\n")
                     .arg(i).arg(i).arg(m_PhaseTypes[i]);
        notifyErrorMessage(getHumanLabel(), ss, -666);
        setErrorCondition(-666);
        return;
      }
      matrixphases.push_back(i);
      matrixphasefractions.push_back(mp->getPhaseFraction());
      totalmatrixfractions = totalmatrixfractions + mp->getPhaseFraction();
    }
  }
  for (int32_t i = 0; i < matrixphases.size(); i++)
  {
    matrixphasefractions[i] = matrixphasefractions[i] / totalmatrixfractions;
    if (i > 0) { matrixphasefractions[i] = matrixphasefractions[i] + matrixphasefractions[i - 1]; }
  }
  size_t j = 0;
  for (size_t i = 0; i < totalPoints; ++i)
  {
    if ((m_UseMask == false && m_FeatureIds[i] <= 0) || (m_UseMask == true && m_Mask[i] == true && m_FeatureIds[i] <= 0))
    {
      random = static_cast<float>( rg.genrand_res53() );
      j = 0;
      while (random > matrixphasefractions[j])
      {
        j++;
      }
      if (m->getAttributeMatrix(m_OutputCellFeatureAttributeMatrixName)->getNumTuples() <= (firstMatrixFeature + j))
      {
        tDims[0] = (firstMatrixFeature + j) + 1;
        m->getAttributeMatrix(m_OutputCellFeatureAttributeMatrixName)->resizeAttributeArrays(tDims);
        updateFeatureInstancePointers();
        m_NumFeatures[j] = 1;
      }
      m_FeatureIds[i] = (firstMatrixFeature + j);
      m_CellPhases[i] = matrixphases[j];
      m_FeaturePhases[(firstMatrixFeature + j)] = matrixphases[j];
    }
    else if (m_UseMask == true && m_Mask[i] == false)
    {
      m_FeatureIds[i] = 0;
      m_CellPhases[i] = 0;
    }
  }
}
Exemplo n.º 22
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RemoveArrays::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles)
{
  setErrorCondition(0);
  typedef std::set<std::string> NameList_t;

  VoxelDataContainer* m = getVoxelDataContainer();
  if (NULL != m)
  {
    for(NameList_t::iterator iter = m_SelectedVoxelCellArrays.begin(); iter != m_SelectedVoxelCellArrays.end(); ++iter)
    {
      m->removeCellData(*iter);
    }
    for(NameList_t::iterator iter = m_SelectedVoxelFieldArrays.begin(); iter != m_SelectedVoxelFieldArrays.end(); ++iter)
    {
      m->removeFieldData(*iter);
    }
    for(NameList_t::iterator iter = m_SelectedVoxelEnsembleArrays.begin(); iter != m_SelectedVoxelEnsembleArrays.end(); ++iter)
    {
      m->removeEnsembleData(*iter);
    }
  }



  SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer();
  if (NULL != sm)
  {
    for(NameList_t::iterator iter = m_SelectedSurfaceVertexArrays.begin(); iter != m_SelectedSurfaceVertexArrays.end(); ++iter)
    {
      sm->removeVertexData(*iter);
    }
    for(NameList_t::iterator iter = m_SelectedSurfaceFaceArrays.begin(); iter != m_SelectedSurfaceFaceArrays.end(); ++iter)
    {
      sm->removeFaceData(*iter);
    }
    for(NameList_t::iterator iter = m_SelectedSurfaceEdgeArrays.begin(); iter != m_SelectedSurfaceEdgeArrays.end(); ++iter)
    {
      sm->removeEdgeData(*iter);
    }
    for(NameList_t::iterator iter = m_SelectedSurfaceFieldArrays.begin(); iter != m_SelectedSurfaceFieldArrays.end(); ++iter)
    {
      sm->removeFieldData(*iter);
    }
    for(NameList_t::iterator iter = m_SelectedSurfaceEnsembleArrays.begin(); iter != m_SelectedSurfaceEnsembleArrays.end(); ++iter)
    {
      sm->removeEnsembleData(*iter);
    }
  }

  SolidMeshDataContainer* sol = getSolidMeshDataContainer();
  if (NULL != sol)
  {
    for(NameList_t::iterator iter = m_SelectedSolidMeshVertexArrays.begin(); iter != m_SelectedSolidMeshVertexArrays.end(); ++iter)
    {
      sol->removeVertexData(*iter);
    }
    for(NameList_t::iterator iter = m_SelectedSolidMeshFaceArrays.begin(); iter != m_SelectedSolidMeshFaceArrays.end(); ++iter)
    {
      sol->removeFaceData(*iter);
    }
    for(NameList_t::iterator iter = m_SelectedSolidMeshEdgeArrays.begin(); iter != m_SelectedSolidMeshEdgeArrays.end(); ++iter)
    {
      sol->removeEdgeData(*iter);
    }
  }

}
Exemplo n.º 23
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void MergeColonies::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  axisTolerance = m_AxisTolerance * SIMPLib::Constants::k_Pi / 180.0f;

  GroupFeatures::execute();

  size_t totalFeatures = m_ActivePtr.lock()->getNumberOfTuples();
  if (totalFeatures < 2)
  {
    setErrorCondition(-87000);
    notifyErrorMessage(getHumanLabel(), "The number of Grouped Features was 0 or 1 which means no grouped Features were detected. A grouping value may be set too high", getErrorCondition());
    return;
  }

  int32_t numParents = 0;
  size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples();
  for (size_t k = 0; k < totalPoints; k++)
  {
    int32_t featurename = m_FeatureIds[k];
    m_CellParentIds[k] = m_FeatureParentIds[featurename];
    if (m_FeatureParentIds[featurename] > numParents) { numParents = m_FeatureParentIds[featurename]; }
  }
  numParents += 1;

  notifyStatusMessage(getHumanLabel(), "Characterizing Colonies");
  characterize_colonies();

  if (true == m_RandomizeParentIds)
  {
    // Generate all the numbers up front
    const int32_t rangeMin = 1;
    const int32_t rangeMax = numParents - 1;
    typedef boost::uniform_int<int32_t> NumberDistribution;
    typedef boost::mt19937 RandomNumberGenerator;
    typedef boost::variate_generator < RandomNumberGenerator&,
            NumberDistribution > Generator;

    NumberDistribution distribution(rangeMin, rangeMax);
    RandomNumberGenerator generator;
    Generator numberGenerator(generator, distribution);

    generator.seed(static_cast<boost::uint32_t>( QDateTime::currentMSecsSinceEpoch() )); // seed with the current time

    DataArray<int32_t>::Pointer rndNumbers = DataArray<int32_t>::CreateArray(numParents, "_INTERNAL_USE_ONLY_NewParentIds");
    int32_t* pid = rndNumbers->getPointer(0);
    pid[0] = 0;
    QSet<int32_t> parentIdSet;
    parentIdSet.insert(0);
    for (int32_t i = 1; i < numParents; ++i)
    {
      pid[i] = i; // numberGenerator();
      parentIdSet.insert(pid[i]);
    }

    int32_t r = 0;
    int32_t temp = 0;

    //--- Shuffle elements by randomly exchanging each with one other.
    for (int32_t i = 1; i < numParents; i++)
    {
      r = numberGenerator(); // Random remaining position.
      if (r >= numParents)
      {
        continue;
      }
      temp = pid[i];
      pid[i] = pid[r];
      pid[r] = temp;
    }

    // Now adjust all the Feature Id values for each Voxel
    for (size_t i = 0; i < totalPoints; ++i)
    {
      m_CellParentIds[i] = pid[ m_CellParentIds[i] ];
      m_FeatureParentIds[m_FeatureIds[i]] = m_CellParentIds[i];
    }
  }

  if (m_IdentifyGlobAlpha == true)
  {
    identify_globAlpha();
  }

  notifyStatusMessage(getHumanLabel(), "Complete");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int32_t LaplacianSmoothing::edgeBasedSmoothing()
{
  int32_t err = 0;
  DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceDataContainerName());
  IGeometry2D::Pointer surfaceMesh = sm->getGeometryAs<IGeometry2D>();
  float* verts = surfaceMesh->getVertexPointer(0);
  int64_t nvert = surfaceMesh->getNumberOfVertices();

  // Generate the Lambda Array
  err = generateLambdaArray();
  if (err < 0)
  {
    setErrorCondition(-557);
    notifyErrorMessage(getHumanLabel(), "Error generating the lambda array", getErrorCondition());
    return err;
  }

  // Get a Pointer to the Lambda array for conveneince
  DataArray<float>::Pointer lambdas = getLambdaArray();
  float* lambda = lambdas->getPointer(0);

  //  Generate the Unique Edges
  if (NULL == surfaceMesh->getEdges().get())
  {
    err = surfaceMesh->findEdges();
  }
  if (err < 0)
  {
    setErrorCondition(-560);
    notifyErrorMessage(getHumanLabel(), "Error retrieving the shared edge list", getErrorCondition());
    return getErrorCondition();
  }

  int64_t* uedges = surfaceMesh->getEdgePointer(0);
  int64_t nedges = surfaceMesh->getNumberOfEdges();

  DataArray<int32_t>::Pointer numConnections = DataArray<int32_t>::CreateArray(nvert, "_INTERNAL_USE_ONLY_Laplacian_Smoothing_NumberConnections_Array");
  numConnections->initializeWithZeros();
  int32_t* ncon = numConnections->getPointer(0);

  QVector<size_t> cDims(1, 3);
  DataArray<double>::Pointer deltaArray = DataArray<double>::CreateArray(nvert, cDims, "_INTERNAL_USE_ONLY_Laplacian_Smoothing_Delta_Array");
  deltaArray->initializeWithZeros();
  double* delta = deltaArray->getPointer(0);

  double dlta = 0.0;
  for (int32_t q = 0; q < m_IterationSteps; q++)
  {
    if (getCancel() == true) { return -1; }
    QString ss = QObject::tr("Iteration %1 of %2").arg(q).arg(m_IterationSteps);
    notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
    for (int64_t i = 0; i < nedges; i++)
    {
      int64_t in1 = uedges[2 * i];   // row of the first vertex
      int64_t in2 = uedges[2 * i + 1]; // row the second vertex

      for (int32_t j = 0; j < 3; j++)
      {
        Q_ASSERT( static_cast<size_t>(3 * in1 + j) < static_cast<size_t>(nvert * 3) );
        Q_ASSERT( static_cast<size_t>(3 * in2 + j) < static_cast<size_t>(nvert * 3) );
        dlta = verts[3 * in2 + j] - verts[3 * in1 + j];
        delta[3 * in1 + j] += dlta;
        delta[3 * in2 + j] += -1.0 * dlta;
      }
      ncon[in1] += 1;
      ncon[in2] += 1;
    }

    float ll = 0.0f;
    for (int64_t i = 0; i < nvert; i++)
    {
      for (int32_t j = 0; j < 3; j++)
      {
        int64_t in0 = 3 * i + j;
        dlta = delta[in0] / ncon[i];

        ll = lambda[i];
        verts[3 * i + j] += ll * dlta;
        delta[in0] = 0.0; // reset for next iteration
      }
      ncon[i] = 0; // reset for next iteration
    }
  }

  return err;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void NearestPointFuseRegularGrids::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer refDC = getDataContainerArray()->getDataContainer(m_ReferenceCellAttributeMatrixPath.getDataContainerName());
  DataContainer::Pointer sampleDC = getDataContainerArray()->getDataContainer(m_SamplingCellAttributeMatrixPath.getDataContainerName());

  AttributeMatrix::Pointer refAttrMat = refDC->getAttributeMatrix(m_ReferenceCellAttributeMatrixPath.getAttributeMatrixName());
  AttributeMatrix::Pointer sampleAttrMat = sampleDC->getAttributeMatrix(m_SamplingCellAttributeMatrixPath.getAttributeMatrixName());

  // Get dimensions and resolutions of two grids
  size_t _refDims[3] = { 0, 0, 0 };
  size_t _sampleDims[3] = { 0, 0, 0 };
  float refRes[3] = { 0.0f, 0.0f, 0.0f };
  float sampleRes[3] = { 0.0f, 0.0f, 0.0f };
  float refOrigin[3] = { 0.0f, 0.0f, 0.0f };
  float sampleOrigin[3] = { 0.0f, 0.0f, 0.0f };
  refDC->getGeometryAs<ImageGeom>()->getDimensions(_refDims);
  sampleDC->getGeometryAs<ImageGeom>()->getDimensions(_sampleDims);
  refDC->getGeometryAs<ImageGeom>()->getResolution(refRes);
  sampleDC->getGeometryAs<ImageGeom>()->getResolution(sampleRes);
  refDC->getGeometryAs<ImageGeom>()->getOrigin(refOrigin);
  sampleDC->getGeometryAs<ImageGeom>()->getOrigin(sampleOrigin);

  // Further down we divide by sampleRes, so here check to make sure that no components of the resolution are 0
  // This would be incredible unusual behavior if it were to occur, hence why we don't spend the time
  // doing the validation up in the dataCheck
  bool zeroRes = false;
  for (size_t i = 0; i < 3; i++)
  {
    if (sampleRes[i] == 0.0f)
    {
      zeroRes = true;
      break;
    }
  }

  if (zeroRes == true)
  {
    QString ss = QObject::tr("A component of the resolution for the Image Geometry associated with DataContainer '%1' is 0. This would result in a division by 0 operation").arg(m_SamplingCellAttributeMatrixPath.getDataContainerName());
    setErrorCondition(-5555);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }

  int64_t refDims[3] = { 0, 0, 0 };
  int64_t sampleDims[3] = { 0, 0, 0 };
  for (size_t i = 0; i < 3; i++)
  {
    refDims[i] = static_cast<int64_t>(_refDims[i]);
    sampleDims[i] = static_cast<int64_t>(_sampleDims[i]);
  }

  int64_t numRefTuples = refDims[0] * refDims[1] * refDims[2];

  float x = 0.0f, y = 0.0f, z = 0.0f;
  int64_t col = 0, row = 0, plane = 0;
  int64_t refIndex = 0;
  int64_t sampleIndex = 0;
  int64_t planeComp = 0, rowComp = 0;

  // Create arrays on the reference grid to hold data present on the sampling grid
  QList<QString> voxelArrayNames = sampleAttrMat->getAttributeArrayNames();
  for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
  {
    IDataArray::Pointer p = sampleAttrMat->getAttributeArray(*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(numRefTuples, p->getComponentDimensions(), p->getName());
    refAttrMat->addAttributeArray(p->getName(), data);
  }

  bool outside  = false;
  for (int64_t i = 0; i < refDims[2]; i++)
  {
    planeComp = i * refDims[0] * refDims[1];
    for (int64_t j = 0; j < refDims[1]; j++)
    {
      rowComp = j * refDims[0];
      for (int64_t k = 0; k < refDims[0]; k++)
      {
        outside = false;
        x = (k * refRes[0] + refOrigin[0]);
        y = (j * refRes[1] + refOrigin[1]);
        z = (i * refRes[2] + refOrigin[2]);
        if ((x - sampleOrigin[0]) < 0) { outside = true; }
        else { col = int64_t((x - sampleOrigin[0]) / sampleRes[0]); }
        if ((y - sampleOrigin[1]) < 0) { outside = true; }
        else { row = int64_t((y - sampleOrigin[1]) / sampleRes[1]); }
        if ((z - sampleOrigin[2]) < 0) { outside = true; }
        else { plane = int64_t((z - sampleOrigin[2]) / sampleRes[2]); }
        if (col > sampleDims[0] ||  row > sampleDims[1] ||  plane > sampleDims[2]) { outside = true; }
        if (outside == false)
        {
          sampleIndex = (plane * sampleDims[0] * sampleDims[1]) + (row * sampleDims[0]) + col;
          refIndex = planeComp + rowComp + k;
          for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
          {
            IDataArray::Pointer p = sampleAttrMat->getAttributeArray(*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 = refAttrMat->getAttributeArray(*iter);
            void* source = NULL;
            void* destination = NULL;
            int nComp = data->getNumberOfComponents();

            source = p->getVoidPointer((nComp * sampleIndex));
            destination = data->getVoidPointer((nComp * refIndex));
            ::memcpy(destination, source, p->getTypeSize() * nComp);
          }
        }
      }
    }
  }

  notifyStatusMessage(getHumanLabel(), "Complete");
}
void LaplacianSmoothing::writeVTKFile(const QString& outputVtkFile)
{

  DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceDataContainerName());  /* Place all your code to execute your filter here. */
  VertexArray& nodes = *(sm->getVertices());
  int nNodes = nodes.getNumberOfTuples();
  bool m_WriteBinaryFile = true;

  FILE* vtkFile = NULL;
  vtkFile = fopen(outputVtkFile.toLatin1().data(), "wb");
  if (NULL == vtkFile)
  {
    setErrorCondition(-90123);
    QString ss = QObject::tr("Error creating file '%1'").arg(outputVtkFile);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }
  Detail::ScopedFileMonitor vtkFileMonitor(vtkFile);

  fprintf(vtkFile, "# vtk DataFile Version 2.0\n");
  fprintf(vtkFile, "Data set from DREAM.3D Surface Meshing Module\n");
  if (m_WriteBinaryFile)
  {
    fprintf(vtkFile, "BINARY\n");
  }
  else
  {
    fprintf(vtkFile, "ASCII\n");
  }
  fprintf(vtkFile, "DATASET POLYDATA\n");


  fprintf(vtkFile, "POINTS %d float\n", nNodes);
  float pos[3] = {0.0f, 0.0f, 0.0f};

  size_t totalWritten = 0;
  // Write the POINTS data (Vertex)
  for (int i = 0; i < nNodes; i++)
  {
    VertexArray::Vert_t& n = nodes[i]; // Get the current Node
    //  if (m_SurfaceMeshNodeType[i] > 0)
    {
      pos[0] = static_cast<float>(n.pos[0]);
      pos[1] = static_cast<float>(n.pos[1]);
      pos[2] = static_cast<float>(n.pos[2]);
      if (m_WriteBinaryFile == true)
      {
        SIMPLib::Endian::FromSystemToBig::convert<float>(pos[0]);
        SIMPLib::Endian::FromSystemToBig::convert<float>(pos[1]);
        SIMPLib::Endian::FromSystemToBig::convert<float>(pos[2]);
        totalWritten = fwrite(pos, sizeof(float), 3, vtkFile);
        if (totalWritten != sizeof(float) * 3)
        {

        }
      }
      else
      {
        fprintf(vtkFile, "%4.4f %4.4f %4.4f\n", pos[0], pos[1], pos[2]); // Write the positions to the output file
      }
    }
  }

  // Write the triangle indices into the vtk File
  FaceArray& triangles = *(sm->getFaces());
  int triangleCount = 0;
  int end = triangles.getNumberOfTuples();
  int featureInterest = 9;
  for(int i = 0; i < end; ++i)
  {
    //FaceArray::Face_t* tri = triangles.getPointer(i);
    if (m_SurfaceMeshFaceLabels[i * 2] == featureInterest || m_SurfaceMeshFaceLabels[i * 2 + 1] == featureInterest)
    {
      ++triangleCount;
    }
  }


  int tData[4];
  // Write the CELLS Data
  //  int start = 3094380;
  //  int end = 3094450;
  //  int triangleCount = end - start;
  qDebug() << "---------------------------------------------------------------------------" << "\n";
  qDebug() << outputVtkFile << "\n";
  fprintf(vtkFile, "\nPOLYGONS %d %d\n", triangleCount, (triangleCount * 4));
  for (int tid = 0; tid < end; ++tid)
  {
    //FaceArray::Face_t* tri = triangles.getPointer(tid);
    if (m_SurfaceMeshFaceLabels[tid * 2] == featureInterest || m_SurfaceMeshFaceLabels[tid * 2 + 1] == featureInterest)
    {
      tData[1] = triangles[tid].verts[0];
      tData[2] = triangles[tid].verts[1];
      tData[3] = triangles[tid].verts[2];
      //      qDebug() << tid << "\n  " << nodes[tData[1]].coord[0] << " " << nodes[tData[1]].coord[1]  << " " << nodes[tData[1]].coord[2]  << "\n";
      //      qDebug() << "  " << nodes[tData[2]].coord[0] << " " << nodes[tData[2]].coord[1]  << " " << nodes[tData[2]].coord[2]  << "\n";
      //      qDebug() << "  " << nodes[tData[3]].coord[0] << " " << nodes[tData[3]].coord[1]  << " " << nodes[tData[3]].coord[2]  << "\n";
      if (m_WriteBinaryFile == true)
      {
        tData[0] = 3; // Push on the total number of entries for this entry
        SIMPLib::Endian::FromSystemToBig::convert<int>(tData[0]);
        SIMPLib::Endian::FromSystemToBig::convert<int>(tData[1]); // Index of Vertex 0
        SIMPLib::Endian::FromSystemToBig::convert<int>(tData[2]); // Index of Vertex 1
        SIMPLib::Endian::FromSystemToBig::convert<int>(tData[3]); // Index of Vertex 2
        fwrite(tData, sizeof(int), 4, vtkFile);
      }
      else
      {
        fprintf(vtkFile, "3 %d %d %d\n", tData[1], tData[2], tData[3]);
      }
    }
  }

  fprintf(vtkFile, "\n");
}
Exemplo n.º 27
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void MultiEmmpmFilter::dataCheck()
{
  setErrorCondition(0);

  if (DataArrayPath::ValidateVector(getInputDataArrayVector()) == false)
  {
    setErrorCondition(-62000);
    QString ss = QObject::tr("All Attribute Arrays must belong to the same Data Container and Attribute Matrix");
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }

  QVector<size_t> cDims(1, 1); // We need a single component, gray scale image

#if 0
  m_InputImagePtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<uint8_t>, AbstractFilter>(this, getInputDataArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if (NULL != m_InputImagePtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  {
    m_InputImage = m_InputImagePtr.lock()->getPointer(0);
  } /* Now assign the raw pointer to data from the DataArray<T> object */
  if (getErrorCondition() < 0) { return; }

  ImageGeom::Pointer image = getDataContainerArray()->getDataContainer(getInputDataArrayPath().getDataContainerName())->getPrereqGeometry<ImageGeom, AbstractFilter>(this);
  if (getErrorCondition() < 0 || NULL == image.get()) { return; }

  m_OutputImagePtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<uint8_t>, AbstractFilter, uint8_t>(this, getOutputDataArrayPath(), 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if (NULL != m_OutputImagePtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  {
    m_OutputImage = m_OutputImagePtr.lock()->getPointer(0);
  } /* Now assign the raw pointer to data from the DataArray<T> object */

#endif

  if (getOutputArrayPrefix().isEmpty())
  {
    setErrorCondition(-62002);
    QString message = QObject::tr("Using a prefix (even a single alphanumeric value) is required so that the output Xdmf files can be written correctly");
    notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
  }

  if (getInputDataArrayVector().isEmpty())
  {
    setErrorCondition(-62003);
    QString message = QObject::tr("At least one Attribute Array must be selected");
    notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
    return;
  }

  DataArrayPath inputAMPath = DataArrayPath::GetAttributeMatrixPath(getInputDataArrayVector());

  AttributeMatrix::Pointer inAM = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, inputAMPath, -301);
  if(getErrorCondition() < 0 || NULL == inAM.get()) { return; }

  // Now create our output attributeMatrix which will contain all of our segmented images
  QVector<size_t> tDims = inAM->getTupleDimensions();
  AttributeMatrix::Pointer outAM = getDataContainerArray()->getDataContainer(inputAMPath.getDataContainerName())->createNonPrereqAttributeMatrix<AbstractFilter>(this, getOutputAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::Cell);
  if(getErrorCondition() < 0 || NULL == outAM.get()) { return; }

  // Get the list of checked array names from the input data arrays list
  QList<QString> arrayNames = DataArrayPath::GetDataArrayNames(getInputDataArrayVector());

  for (int32_t i = 0; i < arrayNames.size(); i++ )
  {
    QString daName = arrayNames.at(i);
    QString newName = getOutputArrayPrefix() + arrayNames.at(i);
    inputAMPath.setDataArrayName(daName);

    getDataContainerArray()->getPrereqArrayFromPath<DataArray<uint8_t>, AbstractFilter>(this, inputAMPath, cDims);
    if (getErrorCondition() < 0) { return; }

    outAM->createAndAddAttributeArray<UInt8ArrayType, AbstractFilter, uint8_t>(this, newName, 0, cDims);
  }

  // The EM/MPM Library has a hard coded MAX Classes of 16
  if (getNumClasses() > 15)
  {
    setErrorCondition(-62000);
    QString ss = QObject::tr("The maximum number of classes is 15");
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
  // It does not make any sense if we want anything less than 2 classes
  if (getNumClasses() < 2)
  {
    setErrorCondition(-62001);
    QString ss = QObject::tr("The minimum number of classes is 2");
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FindDirectionalModuli::dataCheck()
{
  DataArrayPath tempPath;
  setErrorCondition(0);

  //create moduli
  QVector<size_t> dims(1, 1);
  tempPath.update(getFeaturePhasesArrayPath().getDataContainerName(), getFeaturePhasesArrayPath().getAttributeMatrixName(), getDirectionalModuliArrayName() );
  m_DirectionalModuliPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<float>, AbstractFilter, float>(this, tempPath, 0, dims);
  if( NULL != m_DirectionalModuliPtr.lock().get() )
  { m_DirectionalModuli = m_DirectionalModuliPtr.lock()->getPointer(0); }

  //check feature phases
  m_FeaturePhasesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeaturePhasesArrayPath(), dims);
  if( NULL != m_FeaturePhasesPtr.lock().get() )
  { m_FeaturePhases = m_FeaturePhasesPtr.lock()->getPointer(0); }

  //check crystal structures
  m_CrystalStructuresPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<unsigned int>, AbstractFilter>(this, getCrystalStructuresArrayPath(), dims);
  if( NULL != m_CrystalStructuresPtr.lock().get() )
  { m_CrystalStructures = m_CrystalStructuresPtr.lock()->getPointer(0); }
  dims[0] = 3;

  //check quats
  dims[0] = 4;
  m_AvgQuatsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getAvgQuatsArrayPath(), dims);
  if( NULL != m_AvgQuatsPtr.lock().get() )
  { m_AvgQuats = m_AvgQuatsPtr.lock()->getPointer(0); }

  //check compliances
  QVector<size_t> complianceDims(2, 6);
  m_CrystalCompliancesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getCrystalCompliancesArrayPath(), complianceDims);
  if( NULL != m_CrystalCompliancesPtr.lock().get() )
  { m_CrystalCompliances = m_CrystalCompliancesPtr.lock()->getPointer(0); }

  //make sure the direction isn't undefined
  if(0 == m_LoadingDirection.x && 0 == m_LoadingDirection.y && 0 == m_LoadingDirection.z)
  {
    setErrorCondition(-1);
    notifyErrorMessage(getHumanLabel(), "A non-zero direction must be choosen", getErrorCondition());
  }

  //make sure quats + phases are from same attribute matrix + data container
  if( !getFeaturePhasesArrayPath().sameAttributeMatrixPath(getAvgQuatsArrayPath()) )
  {
    setErrorCondition(-2);
    notifyErrorMessage(getHumanLabel(), "Feature Phases and Average Quats must belong to the same DataContainer / AtributreMatrix", getErrorCondition());
  }

  //make sure compliances + crystal structures are from the same attribute matrix + data container
  if( !getCrystalStructuresArrayPath().sameAttributeMatrixPath(getCrystalCompliancesArrayPath()) )
  {
    setErrorCondition(-2);
    notifyErrorMessage(getHumanLabel(), "Crystal Structures and Crystal Compliances must belong to the same DataContainer / AtributreMatrix", getErrorCondition());
  }

  //make sure everything is in the same data container (may not be true for synthetic volumes using a stats gen container but the user can copy the ensemble attribute matrix over)
  if( !getAvgQuatsArrayPath().sameDataContainer(getCrystalStructuresArrayPath()) )
  {
    setErrorCondition(-2);
    notifyErrorMessage(getHumanLabel(), "Crystal Structures and Average Quaternions must belong to the same DataContainer", getErrorCondition());
  }
}
Exemplo n.º 29
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FeatureFaceCurvatureFilter::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName());

  // Get our Reference counted Array of Face Structures
  TriangleGeom::Pointer triangleGeom = sm->getGeometryAs<TriangleGeom>();

  // Just to double check we have everything.
  int64_t numTriangles = triangleGeom->getNumberOfTris();

  // Make sure the Face Connectivity is created because the FindNRing algorithm needs this and will
  // assert if the data is NOT in the SurfaceMesh Data Container
  ElementDynamicList::Pointer vertLinks = triangleGeom->getElementsContainingVert();
  if (NULL == vertLinks.get())
  {
    triangleGeom->findElementsContainingVert();
  }

  // get the QMap from the SharedFeatureFaces filter
  SharedFeatureFaces_t sharedFeatureFaces;

  int32_t maxFaceId = 0;
  for (int64_t t = 0; t < numTriangles; ++t)
  {
    if (m_SurfaceMeshFeatureFaceIds[t] > maxFaceId) { maxFaceId = m_SurfaceMeshFeatureFaceIds[t]; }
  }
  std::vector<int32_t> faceSizes(maxFaceId + 1, 0);
  // Loop through all the Triangles and assign each one to a unique Feature Face Id.
  for (int64_t t = 0; t < numTriangles; ++t)
  {
    faceSizes[m_SurfaceMeshFeatureFaceIds[t]]++;
  }

  // Allocate all the vectors that we need
  for (size_t iter = 0; iter < faceSizes.size(); ++iter)
  {
    FaceIds_t v;
    v.reserve(faceSizes[iter]);
    sharedFeatureFaces[iter] = v;
  }

  // Loop through all the Triangles and assign each one to a unique Feature Face Id.
  for(int64_t t = 0; t < numTriangles; ++t)
  {
    sharedFeatureFaces[m_SurfaceMeshFeatureFaceIds[t]].push_back(t);
  }

  m_TotalFeatureFaces = sharedFeatureFaces.size();
  m_CompletedFeatureFaces = 0;

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


#ifdef SIMPLib_USE_PARALLEL_ALGORITHMS
  tbb::task_group* g = new tbb::task_group;
#else

#endif
  // typedef here for conveneince
  typedef SharedFeatureFaces_t::iterator SharedFeatureFaceIterator_t;

  for(SharedFeatureFaceIterator_t iter = sharedFeatureFaces.begin(); iter != sharedFeatureFaces.end(); ++iter)
  {
    QString ss = QObject::tr("Working on Face Id %1/%2").arg((*iter).first).arg(maxFaceId);
    notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);

    FaceIds_t& triangleIds = (*iter).second;
#ifdef SIMPLib_USE_PARALLEL_ALGORITHMS
    if (doParallel == true)
    {
      g->run(CalculateTriangleGroupCurvatures(m_NRing, triangleIds, m_UseNormalsForCurveFitting,
                                              m_SurfaceMeshPrincipalCurvature1sPtr.lock(), m_SurfaceMeshPrincipalCurvature2sPtr.lock(),
                                              m_SurfaceMeshPrincipalDirection1sPtr.lock(), m_SurfaceMeshPrincipalDirection2sPtr.lock(),
                                              m_SurfaceMeshGaussianCurvaturesPtr.lock(), m_SurfaceMeshMeanCurvaturesPtr.lock(), triangleGeom,
                                              m_SurfaceMeshFaceLabelsPtr.lock(),
                                              m_SurfaceMeshFaceNormalsPtr.lock(),
                                              m_SurfaceMeshTriangleCentroidsPtr.lock(),
                                              this ) );
    }
    else
#endif
    {
      CalculateTriangleGroupCurvatures curvature(m_NRing, triangleIds, m_UseNormalsForCurveFitting,
                                                 m_SurfaceMeshPrincipalCurvature1sPtr.lock(), m_SurfaceMeshPrincipalCurvature2sPtr.lock(),
                                                 m_SurfaceMeshPrincipalDirection1sPtr.lock(), m_SurfaceMeshPrincipalDirection2sPtr.lock(),
                                                 m_SurfaceMeshGaussianCurvaturesPtr.lock(), m_SurfaceMeshMeanCurvaturesPtr.lock(), triangleGeom,
                                                 m_SurfaceMeshFaceLabelsPtr.lock(),
                                                 m_SurfaceMeshFaceNormalsPtr.lock(),
                                                 m_SurfaceMeshTriangleCentroidsPtr.lock(),
                                                 this );
      curvature();
    }
  }
  // *********************** END END END END END END  ********************************************************************

#ifdef SIMPLib_USE_PARALLEL_ALGORITHMS
  g->wait(); // Wait for all the threads to complete before moving on.
  delete g;
#endif

  /* Let the GUI know we are done with this filter */
  notifyStatusMessage(getHumanLabel(), "Complete");
}
Exemplo n.º 30
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ReadH5Ebsd::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles)
{
  setErrorCondition(0);
  std::stringstream ss;
  VoxelDataContainer* m = getVoxelDataContainer();
  if (NULL == m)
  {
    ss.str("");
    ss << getHumanLabel() << "The VoxelDataContainer was NULL and this is NOT allowed. There is an error in the programming. Please contact the developers";
    setErrorCondition(-1);
    addErrorMessage(getHumanLabel(), ss.str(), -1);
    return;
  }

  if (m_InputFile.empty() == true && m_Manufacturer == Ebsd::UnknownManufacturer)
  {
    ss.str("");
    ss << getHumanLabel() << ": Either the H5Ebsd file must exist or the Manufacturer must be set";
    setErrorCondition(-1);
    addErrorMessage(getHumanLabel(), ss.str(), -1);
  }
  else if (MXAFileInfo::exists(m_InputFile) == false)
  {
    ss << "The input file does not exist.";
    setErrorCondition(-388);
    addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition());
  }
  else if (m_InputFile.empty() == false)
  {
    H5EbsdVolumeInfo::Pointer reader = H5EbsdVolumeInfo::New();
    reader->setFileName(m_InputFile);
    int err = reader->readVolumeInfo();
    if (err < 0)
    {
      ss << getHumanLabel() << ": Error reading VolumeInfo from H5Ebsd File";
      setErrorCondition(-1);
      addErrorMessage(getHumanLabel(), ss.str(), -1);
      return;
    }

    std::string manufacturer = reader->getManufacturer();
    if(manufacturer.compare(Ebsd::Ang::Manufacturer) == 0)
    {
      m_Manufacturer = Ebsd::TSL;
    }
    else if(manufacturer.compare(Ebsd::Ctf::Manufacturer) == 0)
    {
      m_Manufacturer = Ebsd::HKL;
    }
    else if(manufacturer.compare(Ebsd::Mic::Manufacturer) == 0)
    {
      m_Manufacturer = Ebsd::HEDM;
    }
    else
    {
      ss << getHumanLabel() << ": Original Data source could not be determined. It should be TSL, HKL or HEDM";
      setErrorCondition(-1);
      addErrorMessage(getHumanLabel(), ss.str(), -1);
      return;
    }

    int64_t dims[3];
    float res[3];
    reader->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);
    m->setOrigin(0.0f, 0.0f, 0.0f);
  }

  H5EbsdVolumeReader::Pointer reader;
  std::vector<std::string> names;

  if (m_Manufacturer == Ebsd::TSL)
  {
    AngFields fields;
    reader = H5AngVolumeReader::New();
    names = fields.getFilterFields<std::vector<std::string> > ();
  }
  else if (m_Manufacturer == Ebsd::HKL)
  {
    CtfFields fields;
    reader = H5CtfVolumeReader::New();
    names = fields.getFilterFields<std::vector<std::string> > ();
  }
  else if (m_Manufacturer == Ebsd::HEDM)
  {
    MicFields fields;
    reader = H5MicVolumeReader::New();
    names = fields.getFilterFields<std::vector<std::string> > ();
  }
  else
  {
    ss << getHumanLabel() << ": Original Data source could not be determined. It should be TSL or HKL";
    setErrorCondition(-1);
    addErrorMessage(getHumanLabel(), ss.str(), -1);
    return;
  }

  for (size_t i = 0; i < names.size(); ++i)
  {
    if (reader->getPointerType(names[i]) == Ebsd::Int32)
    {
      Int32ArrayType::Pointer array = Int32ArrayType::CreateArray(voxels, names[i]);
      m->addCellData(names[i], array);
    }
    else if (reader->getPointerType(names[i]) == Ebsd::Float)
    {
      FloatArrayType::Pointer array = FloatArrayType::CreateArray(voxels, names[i]);
      m->addCellData(names[i], array);
    }
  }

  CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, CellEulerAngles, ss, float, FloatArrayType, 0, voxels, 3)
  CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, CellPhases, ss, int32_t, Int32ArrayType, 0, voxels, 1)


  typedef DataArray<unsigned int> XTalStructArrayType;
  CREATE_NON_PREREQ_DATA(m, DREAM3D, EnsembleData, CrystalStructures, ss, unsigned int, XTalStructArrayType, Ebsd::CrystalStructure::UnknownCrystalStructure, ensembles, 1)
  CREATE_NON_PREREQ_DATA(m, DREAM3D, EnsembleData, LatticeConstants, ss, float, FloatArrayType, 0.0, ensembles, 6)

  StringDataArray::Pointer materialNames = StringDataArray::CreateArray(1, DREAM3D::EnsembleData::MaterialName);
  m->addEnsembleData( DREAM3D::EnsembleData::MaterialName, materialNames);

  ADD_HELP_INDEX_ENTRY(EnsembleData, MaterialName, XTalStructArrayType, 1);
}