Skip to content

Commit

Permalink
Fix issue where CropImageGeometry was not emitting the proper error m…
Browse files Browse the repository at this point in the history
…essages

when the user selects to renumber the grains and no Feature Attribute
Matrix exists.
  • Loading branch information
imikejackson committed Aug 15, 2017
1 parent 810ef72 commit e4a14c5
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions Source/Plugins/Sampling/SamplingFilters/CropImageGeometry.cpp
Expand Up @@ -96,30 +96,33 @@ void CropImageGeometry::setupFilterParameters()
parameters.push_back(SIMPL_NEW_INTEGER_FP("Y Max (Row) [Inclusive]", YMax, FilterParameter::Parameter, CropImageGeometry));
parameters.push_back(SIMPL_NEW_INTEGER_FP("Z Max (Plane) [Inclusive]", ZMax, FilterParameter::Parameter, CropImageGeometry));
QStringList linkedProps;
linkedProps << "CellFeatureAttributeMatrixPath"
<< "FeatureIdsArrayPath";
parameters.push_back(SIMPL_NEW_LINKED_BOOL_FP("Renumber Features", RenumberFeatures, FilterParameter::Parameter, CropImageGeometry, linkedProps));
linkedProps.clear();
linkedProps << "NewDataContainerName";
parameters.push_back(SIMPL_NEW_BOOL_FP("Update Origin", UpdateOrigin, FilterParameter::Parameter, CropImageGeometry));
parameters.push_back(SIMPL_NEW_LINKED_BOOL_FP("Save As New Data Container", SaveAsNewDataContainer, FilterParameter::Parameter, CropImageGeometry, linkedProps));
parameters.push_back(SIMPL_NEW_STRING_FP("Data Container", NewDataContainerName, FilterParameter::CreatedArray, CropImageGeometry));

parameters.push_back(SeparatorFilterParameter::New("Cell Data", FilterParameter::RequiredArray));
{
AttributeMatrixSelectionFilterParameter::RequirementType req = AttributeMatrixSelectionFilterParameter::CreateRequirement(AttributeMatrix::Type::Cell, IGeometry::Type::Image);
parameters.push_back(SIMPL_NEW_AM_SELECTION_FP("Cell Attribute Matrix", CellAttributeMatrixPath, FilterParameter::RequiredArray, CropImageGeometry, req));
}

parameters.push_back(SeparatorFilterParameter::New("Renumber Features Parameters", FilterParameter::RequiredArray));
linkedProps.clear();
linkedProps << "CellFeatureAttributeMatrixPath"
<< "FeatureIdsArrayPath";
parameters.push_back(SIMPL_NEW_LINKED_BOOL_FP("Renumber Features", RenumberFeatures, FilterParameter::Parameter, CropImageGeometry, linkedProps));
{
DataArraySelectionFilterParameter::RequirementType req =
DataArraySelectionFilterParameter::CreateRequirement(SIMPL::TypeNames::Int32, 1, AttributeMatrix::Type::Cell, IGeometry::Type::Image);
parameters.push_back(SIMPL_NEW_DA_SELECTION_FP("Feature Ids", FeatureIdsArrayPath, FilterParameter::RequiredArray, CropImageGeometry, req));
}
parameters.push_back(SeparatorFilterParameter::New("Cell Feature Data", FilterParameter::RequiredArray));
//parameters.push_back(SeparatorFilterParameter::New("Cell Feature Data", FilterParameter::RequiredArray));
{
AttributeMatrixSelectionFilterParameter::RequirementType req =
AttributeMatrixSelectionFilterParameter::CreateRequirement(AttributeMatrix::Type::CellFeature, IGeometry::Type::Image);
parameters.push_back(SIMPL_NEW_AM_SELECTION_FP("Cell Feature Attribute Matrix", CellFeatureAttributeMatrixPath, FilterParameter::RequiredArray, CropImageGeometry, req));
}
parameters.push_back(SIMPL_NEW_STRING_FP("Data Container", NewDataContainerName, FilterParameter::CreatedArray, CropImageGeometry));
setFilterParameters(parameters);
}

Expand Down Expand Up @@ -318,18 +321,29 @@ void CropImageGeometry::dataCheck()
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(nullptr != m_FeatureIdsPtr.lock().get()) /* Validate the Weak Pointer wraps a non-nullptr pointer to a DataArray<T> object */
m_FeatureIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(nullptr, getFeatureIdsArrayPath(), cDims);
if(nullptr != m_FeatureIdsPtr.lock().get())
{
m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0);
} /* Now assign the raw pointer to data from the DataArray<T> object */
}
else
{
QString ss =
QObject::tr("The DataArray '%1' which defines the Feature Ids to renumber is invalid. Does it exist? Is it the correct type?").arg(getFeatureIdsArrayPath().serialize("/"));
setErrorCondition(-55500);
notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
}

AttributeMatrix::Pointer cellFeatureAttrMat = srcCellDataContainer->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName());
AttributeMatrix::Pointer cellFeatureAttrMat = srcCellDataContainer->getPrereqAttributeMatrix<AbstractFilter>(nullptr, getCellFeatureAttributeMatrixPath().getAttributeMatrixName(), -56);
if(nullptr == cellFeatureAttrMat.get())
{
QString ss =
QObject::tr("The AttributeMatrix '%1' is invalid. Does it exist? Is it the correct type?. The AttributeMatrix defines where the segmented features are stored.").arg(getCellFeatureAttributeMatrixPath().serialize("/"));
setErrorCondition(-55501);
notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
return;
}

QVector<bool> activeObjects(cellFeatureAttrMat->getNumberOfTuples(), true);
cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock());
}
Expand Down

0 comments on commit e4a14c5

Please sign in to comment.