// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AvizoUniformCoordinateWriter::dataCheck()
{
    setErrorCondition(0);

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

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

    if(m_OutputFile.isEmpty() == true)
    {
        QString ss = QObject::tr("The output file must be set before executing this filter.");
        setErrorCondition(-1);
        notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    }
    if(m_WriteFeatureIds == true)
    {
        QVector<size_t> dims(1, 1);
        m_FeatureIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeatureIdsArrayPath(), 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 */
        }
    }
}
예제 #2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ScaleVolume::execute()
{
  setErrorCondition(0);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  if (m_ApplyToVoxelVolume == true)
  {
    DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName());
    ImageGeom::Pointer image = m->getGeometryAs<ImageGeom>();

    float resolution[3] = { 0.0f, 0.0f, 0.0f };
    image->getResolution(resolution);
    resolution[0] *= m_ScaleFactor.x;
    resolution[1] *= m_ScaleFactor.y;
    resolution[2] *= m_ScaleFactor.z;
    image->setResolution(resolution);
  }

  if (m_ApplyToSurfaceMesh == true)
  {
    updateSurfaceMesh();
  }

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

  DataContainer::Pointer dataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getDataContainerSelection());
  if (getErrorCondition() < 0) { return; }

  ImageGeom::Pointer image = dataContainer->getGeometryAs<ImageGeom>();

  size_t dims[3] = { 0, 0, 0 };
  image->getDimensions(dims);


  if (dims[2] < getNumZVoxels())
  {
    QString str;
    QTextStream ss(&str);
    ss << "Number of Z Voxels does not meet required value during execution of the filter. \n";
    ss << "  Required Z Voxels: " << m_NumZVoxels << "\n";
    ss << "  Current Z Voxels: " << dims[2];

    setErrorCondition(-7788);
    notifyErrorMessage(getHumanLabel(), str, getErrorCondition());
    bool needMoreData = true;
    emit decisionMade(needMoreData);
  }

  notifyStatusMessage(getHumanLabel(), "Complete");
}
예제 #4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AlignSections::dataCheck()
{
  setErrorCondition(0);
  DataArrayPath tempPath;

  ImageGeom::Pointer image = getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getDataContainerName());
  if(getErrorCondition() < 0) { return; }

  if (image->getXPoints() <= 1 || image->getYPoints() <= 1 || image->getZPoints() <= 1)
  {
    QString ss = QObject::tr("The Image Geometry is not 3D and cannot be run through this filter. The dimensions are (%1,%2,%3)").arg(image->getXPoints()).arg(image->getYPoints()).arg(image->getZPoints());
    setErrorCondition(-3010);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }

  tempPath.update(getDataContainerName(), getCellAttributeMatrixName(), "");
  getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, tempPath, -301);

  if (true == m_WriteAlignmentShifts && m_AlignmentShiftFileName.isEmpty() == true)
  {
    QString ss = QObject::tr("The alignment shift file name is empty");
    setErrorCondition(-1);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }
}
예제 #5
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FindMaxima::dataCheck()
{
  setErrorCondition(0);
  DataArrayPath tempPath;

  //check for required arrays
  QVector<size_t> compDims(1, 1);
  m_SelectedCellArrayPtr = TemplateHelpers::GetPrereqArrayFromPath<AbstractFilter>()(this, getSelectedCellArrayPath(), compDims);
  if(NULL != m_SelectedCellArrayPtr.lock().get())
  {
    m_SelectedCellArray = m_SelectedCellArrayPtr.lock().get();
  }
  if(getErrorCondition() < 0) { return; }

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

  //configured created name / location
  tempPath.update(getSelectedCellArrayPath().getDataContainerName(), getSelectedCellArrayPath().getAttributeMatrixName(), getNewCellArrayName() );

  DataContainer::Pointer dataContiner = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getSelectedCellArrayPath().getDataContainerName() );
  AttributeMatrix::Pointer attrMatrix = dataContiner->getPrereqAttributeMatrix<AbstractFilter>(this, getSelectedCellArrayPath().getAttributeMatrixName(), 80000);
  IDataArray::Pointer redArrayptr = attrMatrix->getPrereqIDataArray<IDataArray, AbstractFilter>(this, getSelectedCellArrayPath().getDataArrayName(), 80000);

  //create new boolean array
  tempPath.update(getSelectedCellArrayPath().getDataContainerName(), getSelectedCellArrayPath().getAttributeMatrixName(), getNewCellArrayName() );
  m_NewCellArrayPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<bool>, AbstractFilter, bool>(this, tempPath, 0, compDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_NewCellArrayPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_NewCellArray = m_NewCellArrayPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

}
예제 #6
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
FloatVec3_t CropImageGeometry::getCurrentVolumeDataContainerResolutions()
{
  DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName());
  FloatVec3_t data;
  if (NULL != m)
  {
    ImageGeom::Pointer image = m->getGeometryAs<ImageGeom>();
    if (image.get() != NULL)
    {
      data.x = image->getXRes();
      data.y = image->getYRes();
      data.z = image->getZRes();
    }
    else
    {
      data.x = 0;
      data.y = 0;
      data.z = 0;
    }

  }
  else
  {
    data.x = 0;
    data.y = 0;
    data.z = 0;
  }
  return data;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AlignSectionsFeatureCentroid::dataCheck()
{
  setErrorCondition(0);

  // Set the DataContainerName and AttributematrixName for the Parent Class (AlignSections) to Use.
  // These are checked for validity in the Parent Class dataCheck
  setDataContainerName(m_GoodVoxelsArrayPath.getDataContainerName());
  setCellAttributeMatrixName(m_GoodVoxelsArrayPath.getAttributeMatrixName());

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


  ImageGeom::Pointer image = getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, m_GoodVoxelsArrayPath.getDataContainerName());
  if(getErrorCondition() < 0) { return; }

  if (m_ReferenceSlice > image->getZPoints())
  {
    QString ss = QObject::tr("The Image Geometry extent (%1) is smaller than the supplied reference slice (%2)").arg(image->getZPoints()).arg(m_ReferenceSlice);
    setErrorCondition(-5556);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
  }

  QVector<size_t> cDims(1, 1);
  m_GoodVoxelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<bool>, AbstractFilter>(this, getGoodVoxelsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_GoodVoxelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_GoodVoxels = m_GoodVoxelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() < 0) { return; }
}
예제 #8
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void GrayToRGB::dataCheck()
{
    setErrorCondition(0);
    DataArrayPath tempPath;

    //check for required arrays
    QVector<size_t> compDims(1, 1);
    m_RedPtr = TemplateHelpers::GetPrereqArrayFromPath<AbstractFilter>()(this, getRedArrayPath(), compDims);
    if(NULL != m_RedPtr.lock().get())
    {
        m_Red = m_RedPtr.lock().get();
    }
    m_GreenPtr = TemplateHelpers::GetPrereqArrayFromPath<AbstractFilter>()(this, getGreenArrayPath(), compDims);
    if(NULL != m_GreenPtr.lock().get())
    {
        m_Green = m_GreenPtr.lock().get();
    }
    m_BluePtr = TemplateHelpers::GetPrereqArrayFromPath<AbstractFilter>()(this, getBlueArrayPath(), compDims);
    if(NULL != m_BluePtr.lock().get())
    {
        m_Blue = m_BluePtr.lock().get();
    }

    //configured created name / location
    tempPath.update(getRedArrayPath().getDataContainerName(), getRedArrayPath().getAttributeMatrixName(), getNewCellArrayName() );


    DataContainer::Pointer redDC = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getRedArrayPath().getDataContainerName() );
    if(getErrorCondition() < 0) {
        return;
    }
    AttributeMatrix::Pointer redAM = redDC->getPrereqAttributeMatrix<AbstractFilter>(this, getRedArrayPath().getAttributeMatrixName(), 80000);
    if(getErrorCondition() < 0) {
        return;
    }
    IDataArray::Pointer redArrayptr = redAM->getPrereqIDataArray<IDataArray, AbstractFilter>(this, getRedArrayPath().getDataArrayName(), 80000);
    if(getErrorCondition() < 0) {
        return;
    }
    ImageGeom::Pointer image = redDC->getPrereqGeometry<ImageGeom, AbstractFilter>(this);
    if(getErrorCondition() < 0 || NULL == image.get()) {
        return;
    }

    //create new array of same type
    compDims[0] = 3;
    m_NewCellArrayPtr = TemplateHelpers::CreateNonPrereqArrayFromArrayType()(this, tempPath, compDims, redArrayptr);
    if( NULL != m_NewCellArrayPtr.lock().get() )
    {
        m_NewCellArray = m_NewCellArrayPtr.lock()->getVoidPointer(0);
    }
}
예제 #9
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FindEllipsoidError::dataCheck()
{
  DataArrayPath tempPath;
  setErrorCondition(0);


  QVector<size_t> dims(1, 1);
  m_FeatureIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeatureIdsArrayPath(), 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 */
  if(getErrorCondition() < 0) { return; }

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

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

  dims[0] = 3;
  m_AxisEulerAnglesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getAxisEulerAnglesArrayPath(), dims);
  if( NULL != m_AxisEulerAnglesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_AxisEulerAngles = m_AxisEulerAnglesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  dims[0] = 3;
  m_AxisLengthsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getAxisLengthsArrayPath(), dims);
  if( NULL != m_AxisLengthsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_AxisLengths = m_AxisLengthsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

  dims[0] = 1;
  m_NumCellsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getNumCellsArrayPath(), dims);
  if( NULL != m_NumCellsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_NumCells = m_NumCellsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */

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

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

}
예제 #10
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RGBToGray::dataCheck()
{
  setErrorCondition(0);
  DataArrayPath tempPath = getSelectedCellArrayArrayPath();

  //check for required arrays
  QVector<size_t> compDims(1, 3);
  m_SelectedCellArrayPtr = TemplateHelpers::GetPrereqArrayFromPath<AbstractFilter>()(this, tempPath, compDims);
  if(NULL != m_SelectedCellArrayPtr.lock().get())
  {
    m_SelectedCellArray = m_SelectedCellArrayPtr.lock().get();
  }
  else // Something went wrong because that should have worked. Bail out now.
  {
    return;
  }


#if 0
  //get type
  QString typeName = getDataContainerArray()->getDataContainer(getSelectedCellArrayArrayPath().getDataContainerName())->getAttributeMatrix(getSelectedCellArrayArrayPath().getAttributeMatrixName())->getAttributeArray(getSelectedCellArrayArrayPath().getDataArrayName())->getTypeAsString();;
  int type = TemplateUtilities::getTypeFromTypeName(typeName);

  //create new array of same type
  dims[0] = 1;
  TEMPLATE_CREATE_NONPREREQ_ARRAY(NewCellArray, tempPath, dims, type);
#endif

  DataContainer::Pointer dc = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getSelectedCellArrayArrayPath().getDataContainerName() );
  if(getErrorCondition() < 0) { return; }
  AttributeMatrix::Pointer am = dc->getPrereqAttributeMatrix<AbstractFilter>(this, getSelectedCellArrayArrayPath().getAttributeMatrixName(), 80000);
  if(getErrorCondition() < 0) { return; }
  IDataArray::Pointer data = am->getPrereqIDataArray<IDataArray, AbstractFilter>(this, getSelectedCellArrayArrayPath().getDataArrayName(), 80000);
  if(getErrorCondition() < 0) { return; }
  ImageGeom::Pointer image = dc->getPrereqGeometry<ImageGeom, AbstractFilter>(this);
  if(getErrorCondition() < 0 || NULL == image.get()) { return; }
  compDims[0] = 1;
  //configured created name / location

  tempPath.setDataArrayName(getNewCellArrayName());
  m_NewCellArrayPtr = TemplateHelpers::CreateNonPrereqArrayFromArrayType()(this, tempPath, compDims, data);
  if( NULL != m_NewCellArrayPtr.lock().get() )
  {
    m_NewCellArray = m_NewCellArrayPtr.lock()->getVoidPointer(0);
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void SetOriginResolutionImageGeom::dataCheck()
{
  setErrorCondition(0);

  ImageGeom::Pointer image = getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getDataContainerName());
  if(getErrorCondition() < 0)
  {
    return;
  }
  if(getChangeOrigin())
  {
    image->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z);
  }
  if(getChangeResolution())
  {
    image->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z);
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RequiredZThickness::dataCheck()
{
  setErrorCondition(0);
  if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer dataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getDataContainerSelection());
  if (getErrorCondition() < 0) { return; }

  ImageGeom::Pointer image = dataContainer->getGeometryAs<ImageGeom>();
  if( NULL == image.get() )
  {
    setErrorCondition(-7789);
    notifyErrorMessage(getHumanLabel(), "Missing Image Geometry in the selected DataContainer", getErrorCondition());
    return;
  }

  size_t dims[3] = { 0, 0, 0 };
  image->getDimensions(dims);


  if (dims[2] < getNumZVoxels() && m_PreflightCheck)
  {
    setErrorCondition(-7787);
    QString str;
    QTextStream ss(&str);
    ss << "Number of Z Voxels does not meet required value during preflight of the filter. \n";
    ss << "  Required Z Voxels: " << m_NumZVoxels << "\n";
    ss << "  Current Z Voxels: " << dims[2];

    notifyErrorMessage(getHumanLabel(), str, getErrorCondition());
  } 
  else if (dims[2] < getNumZVoxels() && !m_PreflightCheck)
  {
    QString str;
    QTextStream ss(&str);
    ss << "Number of Z Voxels does not meet required value during preflight but will be checked during pipeline execution.\n";
    ss << "  Required Z Voxels: " << m_NumZVoxels << "\n";
    ss << "  Current Z Voxels: " << dims[2];

    notifyWarningMessage(getHumanLabel(), str, getErrorCondition());
  }

}
예제 #13
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void Watershed::dataCheck()
{
  setErrorCondition(0);
  DataArrayPath tempPath;

  QVector<size_t> dims(1, 1);
  m_SelectedCellArrayPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<ImageProcessing::DefaultPixelType>, AbstractFilter>(this, getSelectedCellArrayPath(), dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
  if( NULL != m_SelectedCellArrayPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
  { m_SelectedCellArray = m_SelectedCellArrayPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  if(getErrorCondition() < 0) { return; }

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

  tempPath.update(getSelectedCellArrayPath().getDataContainerName(), getSelectedCellArrayPath().getAttributeMatrixName(), getFeatureIdsArrayName() );
  m_FeatureIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 0, 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 */
}
예제 #14
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void SineParamsSegmentFeatures::dataCheck()
{
  DataArrayPath tempPath;
  setErrorCondition(0);

  //Set the DataContainerName for the Parent Class (SegmentFeatures) to Use
  setDataContainerName(m_SineParamsArrayPath.getDataContainerName());

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

  DataContainer::Pointer m = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getDataContainerName(), false);
  if(getErrorCondition() < 0 || NULL == m) { return; }
  QVector<size_t> tDims(1, 0);
  AttributeMatrix::Pointer cellFeatureAttrMat = m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCellFeatureAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::CellFeature);
  if(getErrorCondition() < 0 || NULL == cellFeatureAttrMat.get()) { return; }

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

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

  dims[0] = 1;
  tempPath.update(getDataContainerName(), m_SineParamsArrayPath.getAttributeMatrixName(), getFeatureIdsArrayName() );
  m_FeatureIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 0, 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 */
  if(m_UseGoodVoxels == true)
  {
    m_GoodVoxelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<bool>, AbstractFilter>(this, getGoodVoxelsArrayPath(), dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */
    if( NULL != m_GoodVoxelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */
    { m_GoodVoxels = m_GoodVoxelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */
  }
  tempPath.update(getDataContainerName(), getCellFeatureAttributeMatrixName(), getActiveArrayName() );
  m_ActivePtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<bool>, AbstractFilter, bool>(this, tempPath, true, dims); /* 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 */
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void RegularizeZSpacing::dataCheck()
{
    setErrorCondition(0);

    if (getNewZRes() <= 0)
    {
        QString ss = QObject::tr("The new Z resolution Y (%1) must be positive").arg(getNewZRes());
        setErrorCondition(-5555);
        notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    }

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

    if (!inFile.good())
    {
        QString ss = QObject::tr("Unable to open input file with name '%1'").arg(getInputFile());
        setErrorCondition(-5556);
        notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
        return;
    }

    ImageGeom::Pointer image = getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getCellAttributeMatrixPath().getDataContainerName());
    AttributeMatrix::Pointer cellAttrMat = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getCellAttributeMatrixPath(), -301);
    if(getErrorCondition() < 0) {
        return;
    }

    float zval = 0.0f;
    for (size_t iter = 0; iter < image->getZPoints() + 1; iter++)
    {
        inFile >> zval;
    }
    size_t zP = static_cast<size_t>(zval / getNewZRes());
    if(zP == 0) {
        zP = 1;
    }

    if (getInPreflight())
    {
        image->setDimensions(image->getXPoints(), image->getYPoints(), zP);
        QVector<size_t> tDims(3, 0);
        tDims[0] = image->getXPoints();
        tDims[1] = image->getYPoints();
        tDims[2] = zP;
        cellAttrMat->resizeAttributeArrays(tDims);
    }

    inFile.close();
}
예제 #16
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void InitializeData::dataCheck()
{
  setErrorCondition(0);

  if (m_CellAttributeMatrixPaths.size() <= 0)
  {
    QString ss = "At least one data array must be selected.";
    setErrorCondition(-5550);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }

  DataArrayPath attributeMatrixPath(m_CellAttributeMatrixPaths[0].getDataContainerName(), m_CellAttributeMatrixPaths[0].getAttributeMatrixName(), "");
  getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, attributeMatrixPath, -301);

  ImageGeom::Pointer image = getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, attributeMatrixPath.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());
  }

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

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

  QString attrMatName = attributeMatrixPath.getAttributeMatrixName();
  QList<QString> voxelArrayNames = DataArrayPath::GetDataArrayNames(m_CellAttributeMatrixPaths);

  for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
  {
    IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter);

    QString type = p->getTypeAsString();
    if (type == "int8_t")
    {
      checkInitialization<int8_t>(p);
    }
    else if (type == "int16_t")
    {
      checkInitialization<int16_t>(p);
    }
    else if (type == "int32_t")
    {
      checkInitialization<int32_t>(p);
    }
    else if (type == "int64_t")
    {
      checkInitialization<int64_t>(p);
    }
    else if (type == "uint8_t")
    {
      checkInitialization<uint8_t>(p);
    }
    else if (type == "uint16_t")
    {
      checkInitialization<uint16_t>(p);
    }
    else if (type == "uint32_t")
    {
      checkInitialization<uint32_t>(p);
    }
    else if (type == "uint64_t")
    {
      checkInitialization<uint64_t>(p);
    }
    else if (type == "float")
    {
      checkInitialization<float>(p);
    }
    else if (type == "double")
    {
      checkInitialization<double>(p);
    }

    if (getErrorCondition() < 0)
    {
      return;
    }
  }
}
예제 #17
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ReadImage::dataCheck()
{
  setErrorCondition(0);

  //check file name exists
  if(getInputFileName().isEmpty())
  {
    setErrorCondition(-1);
    notifyErrorMessage(getHumanLabel(), "The input file name must be set before executing this filter.", getErrorCondition());
    return;
  }

  //read image metadata
  itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(getInputFileName().toLocal8Bit().constData(), itk::ImageIOFactory::ReadMode);
  if(NULL == imageIO)
  {
    setErrorCondition(-2);
    QString message = QObject::tr("Unable to read image '%1'").arg(getInputFileName());
    notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
    return;
  }
  imageIO->SetFileName(getInputFileName().toLocal8Bit().data());
  imageIO->ReadImageInformation();

  //get size of image
  const size_t numDimensions = imageIO->GetNumberOfDimensions();
  int xdim = imageIO->GetDimensions(0);
  int ydim = imageIO->GetDimensions(1);
  int zdim = 1;
  if(3 != numDimensions)
  {
    if(2 == numDimensions)
    {
      //allow 2 dimensional images (as 3d image with size 1 in the z direction)
    }
    else
    {
      QString message = QObject::tr("3 dimensional image required (slected image dimensions: %1)").arg(numDimensions);
      setErrorCondition(-3);
      notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
      return;
    }
  }
  else
  {
    zdim = imageIO->GetDimensions(2);
  }

  //determine if container/attribute matrix already exist. if so check size compatibility
  DataArrayPath createdPath;
  DataContainer::Pointer m;
  AttributeMatrix::Pointer cellAttrMat;
  createdPath.update(getDataContainerName(), getCellAttributeMatrixName(), getImageDataArrayName() );

  m = getDataContainerArray()->getDataContainer(getDataContainerName());
  bool createAttributeMatrix = false;

  if(NULL == m.get()) //datacontainer doesn't exist->create
  {
    m = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getDataContainerName());
    ImageGeom::Pointer image = ImageGeom::CreateGeometry(DREAM3D::Geometry::ImageGeometry);
    m->setGeometry(image);
    m->getGeometryAs<ImageGeom>()->setDimensions(xdim, ydim, zdim);
    double zRes = 1;
    double zOrigin = 0;
    if(3 == numDimensions)
    {
      zRes = imageIO->GetSpacing(2);
      zOrigin = imageIO->GetOrigin(2);
    }
    m->getGeometryAs<ImageGeom>()->setResolution(imageIO->GetSpacing(0), imageIO->GetSpacing(0), zRes);
    m->getGeometryAs<ImageGeom>()->setOrigin(imageIO->GetOrigin(0), imageIO->GetOrigin(1), zOrigin);
    createAttributeMatrix = true;
    if(getErrorCondition() < 0) { return; }
  }
  else   //datacontainer exists, check if attribute matrix exists
  {
    bool dcExists = m->doesAttributeMatrixExist(getCellAttributeMatrixName());
    ImageGeom::Pointer image = m->getPrereqGeometry<ImageGeom, AbstractFilter>(this);
    if(getErrorCondition() < 0) { return; }

    size_t iDims[3] = { 0, 0, 0 };
    float iRes[3] = { 0.0f, 0.0f, 0.0f };
    float iOrigin[4] = { 0.0f, 0.0f, 0.0f };
    image->getDimensions(iDims);
    image->getResolution(iRes);
    image->getOrigin(iOrigin);

    if(dcExists &&  NULL != image.get())//attribute matrix exists, check compatibility
    {
      //get matrix
      cellAttrMat = m->getPrereqAttributeMatrix<AbstractFilter>(this, getCellAttributeMatrixName(), false);
      if(getErrorCondition() < 0) { return; }

      //check dimension compatibility
      QVector<size_t> tDims = cellAttrMat->getTupleDimensions();
      if(tDims[0] != xdim || iDims[0] != xdim)
      {
        QString message = QObject::tr("The x size of '%1' (%2) does not match the x size of '%3' (%4)").arg(getInputFileName()).arg(xdim).arg(getDataContainerName() + "/" + getCellAttributeMatrixName()).arg(tDims[0]);
        setErrorCondition(-4);
        notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
        return;
      }
      if(tDims[1] != ydim || iDims[1] != ydim)
      {
        QString message = QObject::tr("The y size of '%1' (%2) does not match the x size of '%3' (%4)").arg(getInputFileName()).arg(ydim).arg(getDataContainerName() + "/" + getCellAttributeMatrixName()).arg(tDims[1]);
        setErrorCondition(-5);
        notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
        return;
      }
      if(3 == numDimensions)
      {
        if(tDims[2] != zdim || iDims[2] != zdim)
        {
          QString message = QObject::tr("The z size of '%1' (%2) does not match the x size of '%3' (%4)").arg(getInputFileName()).arg(zdim).arg(getDataContainerName() + "/" + getCellAttributeMatrixName()).arg(tDims[2]);
          setErrorCondition(-6);
          notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
          return;
        }
      }
      else
      {
        if(tDims[2] != 1 || iDims[2] != 1)
        {
          QString message = QObject::tr("The z size of '%1' (%2) does not match the x size of '%3' (1)").arg(getInputFileName()).arg(zdim).arg(getDataContainerName() + "/" + getCellAttributeMatrixName());
          setErrorCondition(-7);
          notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
          return;
        }
      }
    }
    else //attribute matrix doesn't exist, create
    {
      createAttributeMatrix = true;
    }
  }

  //image/attribute matrix dimensions
  QVector<size_t> tDims(3, 0);
  tDims[0] = xdim;
  tDims[1] = ydim;
  tDims[2] = zdim;

  //create attribute matrix if needed
  if(createAttributeMatrix)
  {
    //create attribute matrix
    cellAttrMat = m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCellAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::Cell);
    if(getErrorCondition() < 0) { return; }
  }

  //check pixel type (scalar, vector, etc) for support
  QVector<size_t> componentDims(1, 0);
  itk::ImageIOBase::IOPixelType pixelType = imageIO->GetPixelType();

  switch(pixelType)
  {

    case itk::ImageIOBase::SCALAR:
      componentDims[0] = 1;
      break;
    case itk::ImageIOBase::RGB:
      componentDims[0] = 3;
      break;
    case itk::ImageIOBase::RGBA:
      componentDims[0] = 4;
      break;
    default:
      setErrorCondition(-80001);
      notifyErrorMessage(getHumanLabel(), "The Pixel Type of the image is not supported with DREAM3D.", getErrorCondition());
  }

  // Check to make sure everything is OK with reading the image
  if(getErrorCondition() < 0)
  {
    std::string pixelTypeName = itk::ImageIOBase::GetPixelTypeAsString(pixelType);
    QString message = QObject::tr("The pixel type of '%1' (%2) is unsupported").arg(getInputFileName()).arg(QString::fromStdString(pixelTypeName));
    notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
    return;
  }

  //Now get how the actual image data is stored.
  IDataArray::Pointer data;
  itk::ImageIOBase::IOComponentType componentType = imageIO->GetComponentType();
  if(itk::ImageIOBase::CHAR == componentType)
  {
    data = Int8ArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::UCHAR == componentType)
  {
    data = UInt8ArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::SHORT == componentType)
  {
    data = Int16ArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::USHORT == componentType)
  {
    data = UInt16ArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::INT == componentType)
  {
    data = Int32ArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::UINT == componentType)
  {
    data = UInt32ArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::LONG == componentType)
  {
    data = Int64ArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::ULONG == componentType)
  {
    data = UInt64ArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::FLOAT == componentType)
  {
    data = FloatArrayType::CreateArray(0, "Temp", false);
  }
  else if(itk::ImageIOBase::DOUBLE == componentType)
  {
    data = DoubleArrayType::CreateArray(0, "Temp", false);
  }
  else
  {
    std::string componentTypeName = itk::ImageIOBase::GetComponentTypeAsString(componentType);
    QString message = QObject::tr("The component type type of '%1' (%2) is unsupported").arg(getInputFileName()).arg(QString::fromStdString(componentTypeName));
    setErrorCondition(-9);
    notifyErrorMessage(getHumanLabel(), message, getErrorCondition());
    return;
  }

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

  m_ImageDataPtr = TemplateHelpers::CreateNonPrereqArrayFromArrayType()(this, createdPath, componentDims, data);
  if( NULL != m_ImageDataPtr.lock().get() )
  {
    m_ImageData = m_ImageDataPtr.lock()->getVoidPointer(0);
  }
}
예제 #18
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int VTKFileReader::readHeader()
{

  int err = 0;
  if (getInputFile().isEmpty() == true)
  {
    setErrorCondition(-1);
    notifyErrorMessage(getHumanLabel(), "FileName was not set and must be valid", -1);
    return -1;
  }

  if (NULL == getDataContainerArray()->getDataContainer(getDataContainerName()).get())
  {
    setErrorCondition(-1);
    notifyErrorMessage(getHumanLabel(), "DataContainer Pointer was NULL and must be valid", -1);
    return -1;
  }

  QFile in(getInputFile());
  if (!in.open(QIODevice::ReadOnly | QIODevice::Text))
  {
    QString msg = QObject::tr("VTF file could not be opened: %1").arg(getInputFile());
    setErrorCondition(-100);
    notifyErrorMessage(getHumanLabel(), msg, getErrorCondition());
    return -100;
  }

  QByteArray buf;
  buf = in.readLine(); // Read Line 1 - VTK Version Info

  buf = in.readLine(); // Read Line 2 - User Comment
  setComment(QString(buf.trimmed()));

  buf = in.readLine(); // Read Line 3 - BINARY or ASCII
  QString fileType(buf);
  if (fileType.startsWith("BINARY") == true)
  {
    setFileIsBinary(true);
  }
  else if (fileType.startsWith("ASCII") == true)
  {
    setFileIsBinary(false);
  }
  else
  {
    err = -1;
    qDebug()
        << "The file type of the VTK legacy file could not be determined. It should be ASCII' or 'BINARY' and should appear on line 3 of the file."
        ;
    return err;
  }


  QList<QByteArray> tokens;
  buf = in.readLine(); // Read Line 4 - Type of Dataset
  {
    tokens = buf.split(' ');
    setDatasetType(QString(tokens[1]));
  }


  buf = in.readLine(); // Read Line 5 which is the Dimension values
  bool ok = false;
  int64_t dims[3];
  tokens = buf.split(' ');
  dims[0] = tokens[1].toLongLong(&ok, 10);
  dims[1] = tokens[2].toLongLong(&ok, 10);
  dims[2] = tokens[3].toLongLong(&ok, 10);
#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;
    QString ss = QObject::tr("The total number of elements '%1' is greater than this program can hold. Try the 64 bit version.").arg(dims[0] * dims[1] * dims[2]);
    setErrorCondition(err);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return err;
  }

  if (dims[0] > max || dims[1] > max || dims[2] > max)
  {
    err = -1;
    QString ss = QObject::tr("One of the dimensions is greater than the max index for this sysem. Try the 64 bit version. dim[0]=%1  dim[1]=%2im[2]=%3")\
                 .arg(dims[0]).arg(dims[1]).arg(dims[2]);
    setErrorCondition(err);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return err;
  }

  size_t dcDims[3] = { static_cast<size_t>(dims[0]), static_cast<size_t>(dims[1]), static_cast<size_t>(dims[2]) };
  DataContainer::Pointer dc = getDataContainerArray()->getDataContainer(getDataContainerName());
  if (dc.get() == NULL)
  {
    return -1;
  }
  ImageGeom::Pointer image = dc->getGeometryAs<ImageGeom>();
  if (image.get() == NULL)
  {
    return -1;
  }
  image->setDimensions(dcDims);

  buf = in.readLine(); // Read Line 6 which is the Origin values
  float origin[3];
  tokens = buf.split(' ');
  origin[0] = tokens[1].toFloat(&ok);
  origin[1] = tokens[2].toFloat(&ok);
  origin[2] = tokens[3].toFloat(&ok);
  image->setOrigin(origin);

  buf = in.readLine(); // Read Line 7 which is the Scaling values
  float resolution[3];
  tokens = buf.split(' ');
  resolution[0] = tokens[1].toFloat(&ok);
  resolution[1] = tokens[2].toFloat(&ok);
  resolution[2] = tokens[3].toFloat(&ok);
  image->setResolution(resolution);

  return err;

}
예제 #19
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int DataContainer::readMeshDataFromHDF5(hid_t dcGid, bool preflight)
{
  herr_t err = 0;
  unsigned int geometryType = DREAM3D::GeometryType::UnknownGeometry;

  err = QH5Lite::readScalarAttribute(dcGid, DREAM3D::Geometry::Geometry, DREAM3D::Geometry::GeometryType, geometryType);
  if (err < 0)
  {
    return err;
  }

  hid_t geometryId = H5Gopen(dcGid, DREAM3D::Geometry::Geometry.toLatin1().data(), H5P_DEFAULT);
  if (geometryId < 0)
  {
    return -1;
  }
  HDF5ScopedGroupSentinel gSentinel(&geometryId, false);

  IGeometry::Pointer geomPtr = IGeometry::NullPointer();

  if (NULL == m_Geometry.get())
  {
    switch(geometryType)
    {
      case DREAM3D::GeometryType::ImageGeometry:
      {
        ImageGeom::Pointer image = ImageGeom::New();
        err = image->readGeometryFromHDF5(geometryId, preflight);
        err = GeometryHelpers::GeomIO::ReadMetaDataFromHDF5(dcGid, image);
        setGeometry(image);
        break;
      }
      case DREAM3D::GeometryType::VertexGeometry:
      {
        VertexGeom::Pointer vertices = VertexGeom::New();
        err = vertices->readGeometryFromHDF5(geometryId, preflight);
        err = GeometryHelpers::GeomIO::ReadMetaDataFromHDF5(dcGid, vertices);
        setGeometry(vertices);
        break;
      }
      case DREAM3D::GeometryType::EdgeGeometry:
      {
        EdgeGeom::Pointer edges = EdgeGeom::New();
        err = edges->readGeometryFromHDF5(geometryId, preflight);
        err = GeometryHelpers::GeomIO::ReadMetaDataFromHDF5(dcGid, edges);
        setGeometry(edges);
        break;
      }
      case DREAM3D::GeometryType::TriangleGeometry:
      {
        TriangleGeom::Pointer triangles = TriangleGeom::New();
        err = triangles->readGeometryFromHDF5(geometryId, preflight);
        err = GeometryHelpers::GeomIO::ReadMetaDataFromHDF5(dcGid, triangles);
        setGeometry(triangles);
        break;
      }
      case DREAM3D::GeometryType::QuadGeometry:
      {
        QuadGeom::Pointer quads = QuadGeom::New();
        err = quads->readGeometryFromHDF5(geometryId, preflight);
        err = GeometryHelpers::GeomIO::ReadMetaDataFromHDF5(dcGid, quads);
        setGeometry(quads);
        break;
      }
      case DREAM3D::GeometryType::UnknownGeometry:
        setGeometry(geomPtr);
        break;
      default:
        setGeometry(geomPtr);
        break;
    }
  }

  return err;
}
예제 #20
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());
  }
}
예제 #21
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());
  }
}
예제 #22
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());
  }
}