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

      resize(0);
      IDataArray::Pointer p = H5DataArrayReader::ReadIDataArray(parentId, getName());
      if (p.get() == NULL)
      {
        return -1;
      }
      m_Array = reinterpret_cast<T*>(p->getVoidPointer(0));
      m_Size = p->getSize();
      m_OwnsData = true;
      m_MaxId = (m_Size == 0) ? 0 : m_Size - 1;
      m_IsAllocated = true;
      m_Name = p->getName();
      m_NumTuples = p->getNumberOfTuples();
      m_CompDims = p->getComponentDimensions();
      m_NumComponents = p->getNumberOfComponents();

      // Tell the intermediate DataArray to release ownership of the data as we are going to be responsible
      // for deleting the memory
      p->releaseOwnership();
      return err;
    }
IDataArray::Pointer copyData(IDataArray::Pointer inputData, size_t totalPoints, int32_t* featureIds)
{
  QString cellArrayName = inputData->getName();

  typename DataArray<T>::Pointer feature = std::dynamic_pointer_cast<DataArray<T> >(inputData);
  if (NULL == feature) { return IDataArray::NullPointer();  }

  QVector<size_t> cDims = inputData->getComponentDimensions();
  typename DataArray<T>::Pointer cell = DataArray<T>::CreateArray(totalPoints, cDims, cellArrayName);

  T* fPtr = feature->getPointer(0);
  T* cPtr = cell->getPointer(0);

  int32_t numComp = feature->getNumberOfComponents();
  int32_t featureIdx = 0;

  for (size_t i = 0; i < totalPoints; ++i)
  {
    // Get the feature id (or what ever the user has selected as their "Feature" identifier
    featureIdx = featureIds[i];
    // Now get the pointer to the start of the tuple for the Feature Array at the given Feature Id Index value
    T* fSourcePtr = fPtr + (numComp * featureIdx);
    // Now get the pointer to the start of the tuple for the Cell Array at the proper index
    T* cDestPtr = cPtr + (numComp * i);

    // Now just raw copy the bytes from the source to the destination
    ::memcpy(cDestPtr, fSourcePtr, sizeof(T) * numComp);
  }
  return cell;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int AttributeMatrix::readAttributeArraysFromHDF5(hid_t amGid, bool preflight, AttributeMatrixProxy& attrMatProxy)
{
    int err = 0;
    QMap<QString, DataArrayProxy> dasToRead = attrMatProxy.dataArrays;
    QString classType;
    for (QMap<QString, DataArrayProxy>::iterator iter = dasToRead.begin(); iter != dasToRead.end(); ++iter)
    {
        //qDebug() << "Reading the " << iter->name << " Array from the " << m_Name << " Attribute Matrix \n";
        if(iter->flag == DREAM3D::Unchecked)
        {
            continue;
        }
        QH5Lite::readStringAttribute(amGid, iter->name, DREAM3D::HDF5::ObjectType, classType);
        //   qDebug() << groupName << " Array: " << *iter << " with C++ ClassType of " << classType << "\n";
        IDataArray::Pointer dPtr = IDataArray::NullPointer();

        if(classType.startsWith("DataArray") == true)
        {
            dPtr = H5DataArrayReader::ReadIDataArray(amGid, iter->name, preflight);
        }
        else if(classType.compare("StringDataArray") == 0)
        {
            dPtr = H5DataArrayReader::ReadStringDataArray(amGid, iter->name, preflight);
        }
        else if(classType.compare("vector") == 0)
        {

        }
        else if(classType.compare("NeighborList<T>") == 0)
        {
            dPtr = H5DataArrayReader::ReadNeighborListData(amGid, iter->name, preflight);
        }
        else if(classType.compare("Statistics") == 0)
        {
            StatsDataArray::Pointer statsData = StatsDataArray::New();
            statsData->setName(iter->name);
            statsData->readH5Data(amGid);
            dPtr = statsData;
        }
        //    else if ( (iter->name).compare(DREAM3D::EnsembleData::Statistics) == 0)
        //    {
        //      StatsDataArray::Pointer statsData = StatsDataArray::New();
        //      statsData->setName(DREAM3D::EnsembleData::Statistics);
        //      statsData->readH5Data(amGid);
        //      dPtr = statsData;
        //    }

        if (NULL != dPtr.get())
        {
            addAttributeArray(dPtr->getName(), dPtr);
        }

    }
    H5Gclose(amGid); // Close the Cell Group
    return err;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int AttributeMatrix::addAttributeArray(const QString& name, IDataArray::Pointer data)
{
    if (data->getName().compare(name) != 0)
    {
        qDebug() << "Adding Attribute Array with different array name than key name" << "\n";
        qDebug() << "Key name: " << name << "\n";
        qDebug() << "Array Name:" << data->getName() << "\n";
        data->setName(name);
    }
    if(getNumTuples() != data->getNumberOfTuples())
    {
        qDebug() << "AttributeMatrix::Name: " << getName() << "  dataArray::name:  " << data->getName() << " Type: " << data->getTypeAsString();
        qDebug() << "getNumTuples(): " << getNumTuples() << "  data->getNumberOfTuples(): " << data->getNumberOfTuples();
    }
    Q_ASSERT(getNumTuples() == data->getNumberOfTuples());

    m_AttributeArrays[name] = data;
    return 0;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int AttributeMatrix::addAttributeArrayFromHDF5Path(hid_t gid, QString name, bool preflight)
{
    int err = 0;
    QString classType;
    QH5Lite::readStringAttribute(gid, name, DREAM3D::HDF5::ObjectType, classType);
    //   qDebug() << groupName << " Array: " << *iter << " with C++ ClassType of " << classType << "\n";
    IDataArray::Pointer dPtr = IDataArray::NullPointer();

    if(classType.startsWith("DataArray") == true)
    {
        dPtr = H5DataArrayReader::ReadIDataArray(gid, name, preflight);
        if(preflight == true)
        {
            dPtr->resize(getNumTuples());
        }
    }
    else if(classType.compare("StringDataArray") == 0)
    {
        dPtr = H5DataArrayReader::ReadStringDataArray(gid, name, preflight);
        if (preflight == true)
        {
            dPtr->resize(getNumTuples());
        }
    }
    else if(classType.compare("vector") == 0)
    {

    }
    else if(classType.compare("NeighborList<T>") == 0)
    {
        dPtr = H5DataArrayReader::ReadNeighborListData(gid, name, preflight);
        if (preflight == true)
        {
            dPtr->resize(getNumTuples());
        }
    }
    else if ( name.compare(DREAM3D::EnsembleData::Statistics) == 0)
    {
        StatsDataArray::Pointer statsData = StatsDataArray::New();
        statsData->setName(DREAM3D::EnsembleData::Statistics);
        statsData->readH5Data(gid);
        dPtr = statsData;
        if (preflight == true)
        {
            dPtr->resize(getNumTuples());
        }
    }

    if (NULL != dPtr.get())
    {
        addAttributeArray(dPtr->getName(), dPtr);
    }

    return err;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString AttributeMatrix::writeXdmfAttributeData(IDataArray::Pointer array, const QString& centering, const QString& dataContainerName, const QString& hdfFileName, const uint8_t gridType)
{
    QString xdmfText;
    QTextStream out(&xdmfText);

    int precision = 0;
    QString xdmfTypeName;
    array->getXdmfTypeAndSize(xdmfTypeName, precision);
    if (0 == precision)
    {
        out << "<!-- " << array->getName() << " has unkown type or unsupported type or precision for XDMF to understand" << " -->" << "\n";
        return xdmfText;
    }
    int numComp = array->getNumberOfComponents();
    QString attrType = "";
    if(numComp == 1)
    {
        attrType = "Scalar";
    }
    //we are assuming a component of 2 is for scalars on either side of a single object (ie faceIds)
    if(numComp == 2)
    {
        attrType = "Scalar";
    }
    if(numComp == 3)
    {
        attrType = "Vector";
    }
    if(numComp == 6)
    {
        attrType = "Vector";
    }
    //  if(numComp == 6) { attrType = "Tensor6"; }
    if(numComp == 9)
    {
        attrType = "Tensor";
    }
    QString block = writeXdmfAttributeDataHelper(numComp, attrType, dataContainerName, array, centering, precision, xdmfTypeName, hdfFileName, gridType);

    out << block;

    return xdmfText;
}
void InitializeData::checkInitialization(IDataArray::Pointer p)
{
  QString arrayName = p->getName();

  if (m_InitType == Manual)
  {
    double input = m_InitValue;
    if (input < static_cast<double>(std::numeric_limits<T>().lowest()) || input > static_cast<double>(std::numeric_limits<T>().max()))
    {
      setErrorCondition(-4000);
      QString ss = QObject::tr("%1: The initialization value could not be converted. The valid range is %2 to %3").arg(arrayName).arg(std::numeric_limits<T>::min()).arg(std::numeric_limits<T>::max());
      notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
      return;
    }
  }
  else if (m_InitType == RandomWithRange)
  {
    double min = m_InitRange.first;
    double max = m_InitRange.second;
    if (min > max)
    {
      QString ss = arrayName + ": Invalid initialization range.  Minimum value is larger than maximum value.";
      setErrorCondition(-5550);
      notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
      return;
    }
    else if (min < static_cast<double>(std::numeric_limits<T>().lowest()) || max > static_cast<double>(std::numeric_limits<T>().max()))
    {
      setErrorCondition(-4001);
      QString ss = QObject::tr("%1: The initialization range can only be from %2 to %3").arg(arrayName).arg(std::numeric_limits<T>::min()).arg(std::numeric_limits<T>::max());
      notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
      return;
    }
    else if (min == max)
    {
      setErrorCondition(-4002);
      QString ss = arrayName + ": The initialization range must have differing values";
      notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
      return;
    }
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void NearestPointFuseRegularGrids::dataCheck()
{
  setErrorCondition(0);

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

  AttributeMatrix::Pointer refAttrMat = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getReferenceCellAttributeMatrixPath(), -301);
  AttributeMatrix::Pointer sampleAttrMat = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getSamplingCellAttributeMatrixPath(), -301);
  if(getErrorCondition() < 0) { return; }

  // 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(refAttrMat->getNumTuples(), p->getComponentDimensions(), p->getName());
    refAttrMat->addAttributeArray(p->getName(), data);
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString AttributeMatrix::writeXdmfAttributeDataHelper(int numComp, const QString& attrType,
        const QString& dataContainerName,
        IDataArray::Pointer array,
        const QString& centering,
        int precision, const QString& xdmfTypeName, const QString& hdfFileName, const uint8_t gridType)
{
    QString buf;
    QTextStream out(&buf);

    QString tupleStr;
    for(int i = m_TupleDims.size() - 1; i >= 0 ; i--)
    {
        tupleStr = tupleStr + QString::number(m_TupleDims[i]) + QString(" ");
    }
    QString dimStr = tupleStr + QString::number(array->getNumberOfComponents());
    QString dimStrHalf = tupleStr + QString::number(array->getNumberOfComponents() / 2);

    if(numComp == 1 || numComp == 3 || numComp == 9)
        //  if(numComp == 1 || numComp == 3 || numComp == 6 || numComp == 9)
    {
        out << "    <Attribute Name=\"" << array->getName() << "\" ";
        out << "AttributeType=\"" << attrType << "\" ";
        out << "Center=\"" << centering << "\">" << "\n";
        // Open the <DataItem> Tag
        out << "      <DataItem Format=\"HDF\" Dimensions=\"" << dimStr <<  "\" ";
        out << "NumberType=\"" << xdmfTypeName << "\" " << "Precision=\"" << precision << "\" >" << "\n";
        out << "        " << hdfFileName << ":/DataContainers/" << dataContainerName << "/" << getName() << "/" << array->getName() << "\n";
        out << "      </DataItem>" << "\n";
        out << "    </Attribute>" << "\n";
    }
    else if(numComp == 2 || numComp == 6)
        //  else if(numComp == 2)
    {
        //First Slab
        out << "    <Attribute Name=\"" << array->getName() << " (Feature 0)\" ";
        out << "AttributeType=\"" << attrType << "\" ";

        out << "Center=\"" << centering << "\">" << "\n";
        // Open the <DataItem> Tag
        out << "      <DataItem ItemType=\"HyperSlab\" Dimensions=\"" << dimStrHalf <<  "\" ";
        out << "Type=\"HyperSlab\" " << "Name=\"" << array->getName() << " (Feature 0)\" >" << "\n";
        out << "        <DataItem Dimensions=\"3 2\" " << "Format=\"XML\" >" << "\n";
        out << "          0        0" << "\n";
        out << "          1        1" << "\n";
        out << "          " << dimStrHalf << " </DataItem>" << "\n";
        out << "\n";
        out << "        <DataItem Format=\"HDF\" Dimensions=\"" << dimStr << "\" " << "NumberType=\"" << xdmfTypeName << "\" " << "Precision=\"" << precision << "\" >" << "\n";

        out << "        " << hdfFileName << ":/DataContainers/" << dataContainerName << "/" << getName() << "/" << array->getName() << "\n";
        out << "        </DataItem>" << "\n";
        out << "      </DataItem>" << "\n";
        out << "    </Attribute>" << "\n" << "\n";

        //Second Slab
        out << "    <Attribute Name=\"" << array->getName() << " (Feature 1)\" ";
        out << "AttributeType=\"" << attrType << "\" ";

        out << "Center=\"" << centering << "\">" << "\n";
        // Open the <DataItem> Tag
        out << "      <DataItem ItemType=\"HyperSlab\" Dimensions=\"" << dimStrHalf <<  "\" ";
        out << "Type=\"HyperSlab\" " << "Name=\"" << array->getName() << " (Feature 1)\" >" << "\n";
        out << "        <DataItem Dimensions=\"3 2\" " << "Format=\"XML\" >" << "\n";
        out << "          0        " << (array->getNumberOfComponents() / 2) << "\n";
        out << "          1        1" << "\n";
        out << "          " << dimStrHalf << " </DataItem>" << "\n";
        out << "\n";
        out << "        <DataItem Format=\"HDF\" Dimensions=\"" << dimStr << "\" " << "NumberType=\"" << xdmfTypeName << "\" " << "Precision=\"" << precision << "\" >" << "\n";
        out << "        " << hdfFileName << ":/DataContainers/" << dataContainerName << "/" << getName() << "/" << array->getName() << "\n";
        out << "        </DataItem>" << "\n";
        out << "      </DataItem>" << "\n";
        out << "    </Attribute>" << "\n";
    }
    return buf;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void CopyFeatureArrayToElementArray::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  // Validate that the selected InArray has tuples equal to the largest
  // Feature Id; the filter would not crash otherwise, but the user should
  // be notified of unanticipated behavior ; this cannot be done in the dataCheck since
  // we don't have acces to the data yet
  int32_t numFeatures = static_cast<int32_t>(m_InArrayPtr.lock()->getNumberOfTuples());
  bool mismatchedFeatures = false;
  int32_t largestFeature = 0;
  size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples();
  for (size_t i = 0; i < totalPoints; i ++)
  {
    if (m_FeatureIds[i] > largestFeature)
    {
      largestFeature = m_FeatureIds[i];
      if (largestFeature >= numFeatures)
      {
        mismatchedFeatures = true;
        break;
      }
    }
  }

  if (mismatchedFeatures == true)
  {
    QString ss = QObject::tr("The number of Features in the InArray array (%1) is larger than the largest Feature Id in the FeatureIds array").arg(numFeatures);
    setErrorCondition(-5555);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }

  if (largestFeature != (numFeatures - 1))
  {
    QString ss = QObject::tr("The number of Features in the InArray array (%1) does not match the largest Feature Id in the FeatureIds array").arg(numFeatures);
    setErrorCondition(-5555);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }

  IDataArray::Pointer p = IDataArray::NullPointer();

  if (TemplateHelpers::CanDynamicCast<Int8ArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<int8_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<UInt8ArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<uint8_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<Int16ArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<int16_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<UInt16ArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<uint16_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<Int32ArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<int32_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<UInt32ArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<uint32_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<Int64ArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<int64_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<UInt64ArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<uint64_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<FloatArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<float>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<DoubleArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<double>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else if (TemplateHelpers::CanDynamicCast<BoolArrayType>()(m_InArrayPtr.lock()))
  {
    p = copyData<bool>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds);
  }
  else
  {
    QString ss = QObject::tr("The selected array was of unsupported type. The path is %1").arg(m_SelectedFeatureArrayPath.serialize());
    setErrorCondition(-14000);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }

  if (p.get() != NULL)
  {
    p->setName(getCreatedArrayName());
    AttributeMatrix::Pointer am = getDataContainerArray()->getAttributeMatrix(getFeatureIdsArrayPath());
    am->addAttributeArray(p->getName(), p);
  }

  notifyStatusMessage(getHumanLabel(), "Complete");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RotateSampleRefFrame::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

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

  float rotAngle = m_RotationAngle * SIMPLib::Constants::k_Pi / 180.0;

  int64_t xp = 0, yp = 0, zp = 0;
  float xRes = 0.0f, yRes = 0.0f, zRes = 0.0f;
  int64_t xpNew = 0, ypNew = 0, zpNew = 0;
  float xResNew = 0.0f, yResNew = 0.0f, zResNew = 0.0f;
  RotateSampleRefFrameImplArg_t params;

  xp = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getXPoints());
  xRes = m->getGeometryAs<ImageGeom>()->getXRes();
  yp = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getYPoints());
  yRes = m->getGeometryAs<ImageGeom>()->getYRes();
  zp = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getZPoints());
  zRes = m->getGeometryAs<ImageGeom>()->getZRes();

  params.xp = xp;
  params.xRes = xRes;
  params.yp = yp;
  params.yRes = yRes;
  params.zp = zp;
  params.zRes = zRes;

  size_t col = 0, row = 0, plane = 0;
  float rotMat[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } };
  float coords[3] = { 0.0f, 0.0f, 0.0f };
  float newcoords[3] = { 0.0f, 0.0f, 0.0f };
  float xMin = std::numeric_limits<float>::max();
  float xMax = std::numeric_limits<float>::min();
  float yMin = std::numeric_limits<float>::max();
  float yMax = std::numeric_limits<float>::min();
  float zMin = std::numeric_limits<float>::max();
  float zMax = std::numeric_limits<float>::min();

  FOrientArrayType om(9);
  FOrientTransformsType::ax2om(FOrientArrayType(m_RotationAxis.x, m_RotationAxis.y, m_RotationAxis.z, rotAngle), om);
  om.toGMatrix(rotMat);
  for (int32_t i = 0; i < 8; i++)
  {
    if (i == 0) { col = 0, row = 0, plane = 0; }
    if (i == 1) { col = xp - 1, row = 0, plane = 0; }
    if (i == 2) { col = 0, row = yp - 1, plane = 0; }
    if (i == 3) { col = xp - 1, row = yp - 1, plane = 0; }
    if (i == 4) { col = 0, row = 0, plane = zp - 1; }
    if (i == 5) { col = xp - 1, row = 0, plane = zp - 1; }
    if (i == 6) { col = 0, row = yp - 1, plane = zp - 1; }
    if (i == 7) { col = xp - 1, row = yp - 1, plane = zp - 1; }
    coords[0] = static_cast<float>(col * xRes);
    coords[1] = static_cast<float>(row * yRes);
    coords[2] = static_cast<float>(plane * zRes);
    MatrixMath::Multiply3x3with3x1(rotMat, coords, newcoords);
    if (newcoords[0] < xMin) { xMin = newcoords[0]; }
    if (newcoords[0] > xMax) { xMax = newcoords[0]; }
    if (newcoords[1] < yMin) { yMin = newcoords[1]; }
    if (newcoords[1] > yMax) { yMax = newcoords[1]; }
    if (newcoords[2] < zMin) { zMin = newcoords[2]; }
    if (newcoords[2] > zMax) { zMax = newcoords[2]; }
  }
  float xAxis[3] = {1, 0, 0};
  float yAxis[3] = {0, 1, 0};
  float zAxis[3] = {0, 0, 1};
  float xAxisNew[3] = { 0.0f, 0.0f, 0.0f };
  float yAxisNew[3] = { 0.0f, 0.0f, 0.0f };
  float zAxisNew[3] = { 0.0f, 0.0f, 0.0f };
  MatrixMath::Multiply3x3with3x1(rotMat, xAxis, xAxisNew);
  MatrixMath::Multiply3x3with3x1(rotMat, yAxis, yAxisNew);
  MatrixMath::Multiply3x3with3x1(rotMat, zAxis, zAxisNew);
  float closestAxis = 0.0f;
  xResNew = xRes;
  closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(xAxis, xAxisNew));
  if (fabs(GeometryMath::CosThetaBetweenVectors(yAxis, xAxisNew)) > closestAxis) { xResNew = yRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(yAxis, xAxisNew)); }
  if (fabs(GeometryMath::CosThetaBetweenVectors(zAxis, xAxisNew)) > closestAxis) { xResNew = zRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, xAxisNew)); }
  yResNew = yRes;
  closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(yAxis, yAxisNew));
  if (fabs(GeometryMath::CosThetaBetweenVectors(xAxis, yAxisNew)) > closestAxis) { yResNew = xRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(xAxis, yAxisNew)); }
  if (fabs(GeometryMath::CosThetaBetweenVectors(zAxis, yAxisNew)) > closestAxis) { yResNew = zRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, yAxisNew)); }
  zResNew = zRes;
  closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, zAxisNew));
  if (fabs(GeometryMath::CosThetaBetweenVectors(xAxis, zAxisNew)) > closestAxis) { zResNew = xRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(xAxis, zAxisNew)); }
  if (fabs(GeometryMath::CosThetaBetweenVectors(yAxis, zAxisNew)) > closestAxis) { zResNew = yRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(yAxis, zAxisNew)); }

  xpNew = static_cast<int64_t>(nearbyint((xMax - xMin) / xResNew) + 1);
  ypNew = static_cast<int64_t>(nearbyint((yMax - yMin) / yResNew) + 1);
  zpNew = static_cast<int64_t>(nearbyint((zMax - zMin) / zResNew) + 1);

  params.xpNew = xpNew;
  params.xResNew = xResNew;
  params.xMinNew = xMin;
  params.ypNew = ypNew;
  params.yResNew = yResNew;
  params.yMinNew = yMin;
  params.zpNew = zpNew;
  params.zResNew = zResNew;
  params.zMinNew = zMin;

  int64_t newNumCellTuples = params.xpNew * params.ypNew * params.zpNew;

  DataArray<int64_t>::Pointer newIndiciesPtr = DataArray<int64_t>::CreateArray(newNumCellTuples, "_INTERNAL_USE_ONLY_RotateSampleRef_NewIndicies");
  newIndiciesPtr->initializeWithValue(-1);
  int64_t* newindicies = newIndiciesPtr->getPointer(0);

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

#ifdef SIMPLib_USE_PARALLEL_ALGORITHMS
  if (doParallel == true)
  {
    tbb::parallel_for(tbb::blocked_range3d<int64_t, int64_t, int64_t>(0, params.zpNew, 0, params.ypNew, 0, params.xpNew),
                      RotateSampleRefFrameImpl(newIndiciesPtr, &params, rotMat, m_SliceBySlice), tbb::auto_partitioner());
  }
  else
#endif
  {
    RotateSampleRefFrameImpl serial(newIndiciesPtr, &params, rotMat, m_SliceBySlice);
    serial.convert(0, params.zpNew, 0, params.ypNew, 0, params.xpNew);
  }

  // This could technically be parallelized also where each thread takes an array to adjust. Except
  // that the DataContainer is NOT thread safe or re-entrant so that would actually be a BAD idea.
  QString attrMatName = getCellAttributeMatrixPath().getAttributeMatrixName();
  QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames();

  // resize attribute matrix
  QVector<size_t> tDims(3);
  tDims[0] = params.xpNew;
  tDims[1] = params.ypNew;
  tDims[2] = params.zpNew;
  m->getAttributeMatrix(attrMatName)->resizeAttributeArrays(tDims);

  for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
  {
    IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->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.
    IDataArray::Pointer data = p->createNewArray(newNumCellTuples, p->getComponentDimensions(), p->getName());
    void* source = NULL;
    void* destination = NULL;
    int64_t newIndicies_I = 0;
    int32_t nComp = data->getNumberOfComponents();
    for (size_t i = 0; i < static_cast<size_t>(newNumCellTuples); i++)
    {
      newIndicies_I = newindicies[i];
      if(newIndicies_I >= 0)
      {
        source = p->getVoidPointer((nComp * newIndicies_I));
        if (NULL == source)
        {
          QString ss = QObject::tr("The index is outside the bounds of the source array");
          setErrorCondition(-11004);
          notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
          return;
        }
        destination = data->getVoidPointer((data->getNumberOfComponents() * i));
        ::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents());
      }
      else
      {
        data->initializeTuple(i, 0);
      }
    }
    m->getAttributeMatrix(attrMatName)->addAttributeArray(*iter, data);
  }
  m->getGeometryAs<ImageGeom>()->setResolution(params.xResNew, params.yResNew, params.zResNew);
  m->getGeometryAs<ImageGeom>()->setDimensions(params.xpNew, params.ypNew, params.zpNew);
  m->getGeometryAs<ImageGeom>()->setOrigin(xMin, yMin, zMin);

  notifyStatusMessage(getHumanLabel(), "Complete");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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 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());
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ConvertData::dataCheck()
{
  setErrorCondition(0);

  DataContainer::Pointer m = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getSelectedCellArrayPath().getDataContainerName(), false);

  QString ss;
  if (m_OutputArrayName.isEmpty() == true)
  {
    ss = QObject::tr("The output array name must be set");
    setErrorCondition(-398);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }

  if (getInPreflight())
  {
    AttributeMatrix::Pointer cellAttrMat = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, m_SelectedCellArrayPath, -301);
    if(getErrorCondition() < 0) { return; }

    IDataArray::Pointer p = getDataContainerArray()->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(this, getSelectedCellArrayPath());
    if(getErrorCondition() < 0) { return; }

    QVector<size_t> dims = p->getComponentDimensions();
    size_t voxels = cellAttrMat->getNumTuples();
    if (m_ScalarType == Detail::Int8)
    {
      p = Int8ArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::UInt8)
    {
      p = UInt8ArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Int16)
    {
      p = Int16ArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::UInt16)
    {
      p = UInt16ArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Int32)
    {
      p = Int32ArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::UInt32)
    {
      p = UInt32ArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Int64)
    {
      p = Int64ArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::UInt64)
    {
      p = UInt64ArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Float)
    {
      p = FloatArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    else if (m_ScalarType == Detail::Double)
    {
      p = DoubleArrayType::CreateArray(voxels, dims, m_OutputArrayName);
    }
    cellAttrMat->addAttributeArray(p->getName(), p);
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void WarpRegularGrid::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer m;
  if (m_SaveAsNewDataContainer == false) { m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName()); }
  else { m = getDataContainerArray()->getDataContainer(getNewDataContainerName()); }

  AttributeMatrix::Pointer cellAttrMat = m->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
  AttributeMatrix::Pointer newCellAttrMat = cellAttrMat->deepCopy();

  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);
  size_t totalPoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements();

  float x = 0.0f, y = 0.0f, z = 0.0f;
  float newX = 0.0f, newY = 0.0f;
  int col = 0.0f, row = 0.0f, plane = 0.0f;
  size_t index;
  size_t index_old;
  std::vector<size_t> newindicies(totalPoints);
  std::vector<bool> goodPoint(totalPoints, true);

  for (size_t i = 0; i < dims[2]; i++)
  {
    QString ss = QObject::tr("Warping Data - %1 Percent Complete").arg(((float)i / dims[2]) * 100);
    notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
    for (size_t j = 0; j < dims[1]; j++)
    {
      for (size_t k = 0; k < dims[0]; k++)
      {
        x = static_cast<float>((k * res[0]));
        y = static_cast<float>((j * res[1]));
        z = static_cast<float>((i * res[2]));
        index = (i * dims[0] * dims[1]) + (j * dims[0]) + k;

        determine_warped_coordinates(x, y, newX, newY);
        col = newX / res[0];
        row = newY / res[1];
        plane = i;

        index_old = (plane * dims[0] * dims[1]) + (row * dims[0]) + col;
        newindicies[index] = index_old;
        if (col > 0 && col < dims[0] && row > 0 && row < dims[1]) { goodPoint[index] = true; }
        else { goodPoint[index] = false; }
      }
    }
  }

  QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames();
  for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
  {
    IDataArray::Pointer p = cellAttrMat->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(p->getNumberOfTuples(), p->getComponentDimensions(), p->getName());
    data->resize(totalPoints);
    void* source = NULL;
    void* destination = NULL;
    size_t newIndicies_I = 0;
    int nComp = data->getNumberOfComponents();
    for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++)
    {
      newIndicies_I = newindicies[i];

      if(goodPoint[i] == true)
      {
        source = p->getVoidPointer((nComp * newIndicies_I));
        destination = data->getVoidPointer((data->getNumberOfComponents() * i));
        ::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents());
      }
      else
      {
        int var = 0;
        data->initializeTuple(i, &var);
      }
    }
    cellAttrMat->removeAttributeArray(*iter);
    newCellAttrMat->addAttributeArray(*iter, data);
  }
  m->removeAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
  m->addAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName(), newCellAttrMat);

  notifyStatusMessage(getHumanLabel(), "Complete");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ChangeResolution::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer m;
  if(m_SaveAsNewDataContainer == false)
  {
    m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName());
  }
  else
  {
    m = getDataContainerArray()->getDataContainer(getNewDataContainerName());
  }

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

  AttributeMatrix::Pointer cellAttrMat = m->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());

  size_t dims[3] = { 0, 0, 0 };
  m->getGeometryAs<ImageGeom>()->getDimensions(dims);

  float sizex = (dims[0]) * m->getGeometryAs<ImageGeom>()->getXRes();
  float sizey = (dims[1]) * m->getGeometryAs<ImageGeom>()->getYRes();
  float sizez = (dims[2]) * m->getGeometryAs<ImageGeom>()->getZRes();
  size_t m_XP = size_t(sizex / m_Resolution.x);
  size_t m_YP = size_t(sizey / m_Resolution.y);
  size_t m_ZP = size_t(sizez / m_Resolution.z);
  if (m_XP == 0) { m_XP = 1; }
  if (m_YP == 0) { m_YP = 1; }
  if (m_ZP == 0) { m_ZP = 1; }
  size_t totalPoints = m_XP * m_YP * m_ZP;

  float x = 0.0f, y = 0.0f, z = 0.0f;
  size_t col = 0, row = 0, plane = 0;
  size_t index;
  size_t index_old;
  std::vector<size_t> newindicies(totalPoints);

  for (size_t i = 0; i < m_ZP; i++)
  {
    QString ss = QObject::tr("Changing Resolution - %1 Percent Complete").arg(((float)i / m->getGeometryAs<ImageGeom>()->getZPoints()) * 100);
    notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
    for (size_t j = 0; j < m_YP; j++)
    {
      for (size_t k = 0; k < m_XP; k++)
      {
        x = (k * m_Resolution.x);
        y = (j * m_Resolution.y);
        z = (i * m_Resolution.z);
        col = size_t(x / m->getGeometryAs<ImageGeom>()->getXRes());
        row = size_t(y / m->getGeometryAs<ImageGeom>()->getYRes());
        plane = size_t(z / m->getGeometryAs<ImageGeom>()->getZRes());
        index_old = (plane * m->getGeometryAs<ImageGeom>()->getXPoints() * m->getGeometryAs<ImageGeom>()->getYPoints()) + (row * m->getGeometryAs<ImageGeom>()->getXPoints()) + col;
        index = (i * m_XP * m_YP) + (j * m_XP) + k;
        newindicies[index] = index_old;
      }
    }
  }

  QVector<size_t> tDims(3, 0);
  tDims[0] = m_XP;
  tDims[1] = m_YP;
  tDims[2] = m_ZP;
  AttributeMatrix::Pointer newCellAttrMat = AttributeMatrix::New(tDims, cellAttrMat->getName(), cellAttrMat->getType());

  QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames();
  for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
  {
    IDataArray::Pointer p = cellAttrMat->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(p->getNumberOfTuples(), p->getComponentDimensions(), p->getName());
    data->resize(totalPoints);
    void* source = NULL;
    void* destination = NULL;
    size_t newIndicies_I = 0;
    int nComp = data->getNumberOfComponents();
    for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++)
    {
      newIndicies_I = newindicies[i];
      source = p->getVoidPointer((nComp * newIndicies_I));
      destination = data->getVoidPointer((data->getNumberOfComponents() * i));
      ::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents());
    }
    cellAttrMat->removeAttributeArray(*iter);
    newCellAttrMat->addAttributeArray(*iter, data);
  }
  m->getGeometryAs<ImageGeom>()->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z);
  m->getGeometryAs<ImageGeom>()->setDimensions(m_XP, m_YP, m_ZP);
  m->removeAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
  m->addAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName(), newCellAttrMat);

  // Feature Ids MUST already be renumbered.
  if (m_RenumberFeatures == true)
  {
    totalPoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements();
    AttributeMatrix::Pointer cellFeatureAttrMat = m->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName());
    size_t totalFeatures = cellFeatureAttrMat->getNumTuples();
    QVector<bool> activeObjects(totalFeatures, false);
    if (0 == totalFeatures)
    {
      notifyErrorMessage(getHumanLabel(), "The number of Features is 0 and should be greater than 0", -600);
      return;
    }

    updateCellInstancePointers();

    // Find the unique set of feature ids
    for (size_t i = 0; i < totalPoints; ++i)
    {
      activeObjects[m_FeatureIds[i]] = true;
    }
    cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock());
  }

  notifyStatusMessage(getHumanLabel(), "Complete");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RegularizeZSpacing::execute()
{
    setErrorCondition(0);
    dataCheck();
    if(getErrorCondition() < 0) {
        return;
    }

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

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

    std::ifstream inFile;
    inFile.open(m_InputFile.toLatin1().data());

    float zval = 0.0f;
    std::vector<float> zboundvalues(dims[2] + 1, 0.0);
    for (size_t iter = 0; iter < dims[2] + 1; iter++)
    {
        inFile >> zval;
        zboundvalues[iter] = zval;
    }
    inFile.close();

    float xRes = m->getGeometryAs<ImageGeom>()->getXRes();
    float yRes = m->getGeometryAs<ImageGeom>()->getYRes();

    float sizez = zboundvalues[dims[2]];
    size_t m_XP = dims[0];
    size_t m_YP = dims[1];
    size_t m_ZP = static_cast<size_t>(sizez / m_NewZRes);
    if (m_ZP == 0) {
        m_ZP = 1;
    }
    size_t totalPoints = m_XP * m_YP * m_ZP;

    size_t index = 0, oldindex = 0;
    size_t plane = 0;
    std::vector<size_t> newindicies(totalPoints, 0);
    for (size_t i = 0; i < m_ZP; i++)
    {
        plane = 0;
        for (size_t iter = 1; iter < dims[2]; iter++)
        {
            if ((i * m_NewZRes) > zboundvalues[iter]) {
                plane = iter;
            }
        }
        for (size_t j = 0; j < m_YP; j++)
        {
            for (size_t k = 0; k < m_XP; k++)
            {
                oldindex = (plane * dims[0] * dims[1]) + (j * dims[0]) + k;
                index = (i * dims[0] * dims[1]) + (j * dims[0]) + k;
                newindicies[index] = oldindex;
            }
        }
    }

    AttributeMatrix::Pointer cellAttrMat = m->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
    QVector<size_t> tDims(3, 0);
    tDims[0] = m_XP;
    tDims[1] = m_YP;
    tDims[2] = m_ZP;
    AttributeMatrix::Pointer newCellAttrMat = AttributeMatrix::New(tDims, cellAttrMat->getName(), cellAttrMat->getType());

    QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames();
    for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
    {
        IDataArray::Pointer p = cellAttrMat->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(p->getNumberOfTuples(), p->getComponentDimensions(), p->getName());
        data->resize(totalPoints);
        void* source = NULL;
        void* destination = NULL;
        size_t newIndicies_I = 0;
        int nComp = data->getNumberOfComponents();
        for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++)
        {
            newIndicies_I = newindicies[i];

            source = p->getVoidPointer((nComp * newIndicies_I));
            destination = data->getVoidPointer((data->getNumberOfComponents() * i));
            ::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents());
        }
        cellAttrMat->removeAttributeArray(*iter);
        newCellAttrMat->addAttributeArray(*iter, data);
    }
    m->getGeometryAs<ImageGeom>()->setResolution(xRes, yRes, m_NewZRes);
    m->getGeometryAs<ImageGeom>()->setDimensions(m_XP, m_YP, m_ZP);
    m->removeAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
    m->addAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName(), newCellAttrMat);

    notifyStatusMessage(getHumanLabel(), "Complete");
}