// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void Watershed::execute() { //int err = 0; dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath().getAttributeMatrixName(); //wrap m_RawImageData as itk::image ImageProcessing::DefaultImageType::Pointer inputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_SelectedCellArray); //create gradient magnitude filter notifyStatusMessage(getHumanLabel(), "Calculating Gradient Magnitude"); typedef itk::GradientMagnitudeImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType > GradientMagnitudeImageFilterType; GradientMagnitudeImageFilterType::Pointer gradientMagnitudeImageFilter = GradientMagnitudeImageFilterType::New(); gradientMagnitudeImageFilter->SetInput(inputImage); gradientMagnitudeImageFilter->Update(); //watershed image notifyStatusMessage(getHumanLabel(), "Watershedding"); typedef itk::WatershedImageFilter<ImageProcessing::DefaultImageType> WatershedFilterType; WatershedFilterType::Pointer watershed = WatershedFilterType::New(); watershed->SetThreshold(m_Threshold); watershed->SetLevel(m_Level); watershed->SetInput(gradientMagnitudeImageFilter->GetOutput()); //execute filter try { watershed->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::GradientMagnitudeImageFilter filter. Error Message returned from ITK:\n %1").arg(err.GetDescription()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } //get output and copy to grainids typedef itk::Image<unsigned long, ImageProcessing::ImageDimension> WatershedImageType; WatershedImageType::Pointer output = watershed->GetOutput(); WatershedImageType::RegionType filterRegion = output->GetLargestPossibleRegion(); typedef itk::ImageRegionConstIterator<itk::Image<unsigned long, ImageProcessing::ImageDimension> > WatershedIteratorType; WatershedIteratorType it(output, filterRegion); it.GoToBegin(); int index = 0; while(!it.IsAtEnd()) { m_FeatureIds[index] = it.Get(); ++it; ++index; } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LinkFeatureMapToElementArray::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); size_t totalPoints = m_SelectedCellDataPtr.lock()->getNumberOfTuples(); int32_t maxIndex = 0; std::vector<bool> active; for (size_t i = 0; i < totalPoints; i++) { int32_t index = m_SelectedCellData[i]; if ((index + 1) > maxIndex) { active.resize(index + 1); active[index] = true; maxIndex = index + 1; } } QVector<size_t> tDims(1, maxIndex); m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); for (int32_t i = 0; i < maxIndex; i++) { m_Active[i] = active[i]; } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ConvertData::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSelectedCellArrayPath( reader->readDataArrayPath( "SelectedCellArrayPath", getSelectedCellArrayPath() ) ); setScalarType( reader->readValue("ScalarType", getScalarType()) ); setOutputArrayName( reader->readString( "OutputArrayName", getOutputArrayName() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindMaxima::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSelectedCellArrayPath( reader->readDataArrayPath( "SelectedCellArrayPath", getSelectedCellArrayPath() ) ); setMinValue( reader->readValue( "MinValue", getMinValue() ) ); setNewCellArrayName( reader->readString( "NewCellArrayName", getNewCellArrayName() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LinkFeatureMapToElementArray::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setCellFeatureAttributeMatrixName(reader->readString("CellFeatureAttributeMatrixName", getCellFeatureAttributeMatrixName())); setActiveArrayName(reader->readString("ActiveArrayName", getActiveArrayName())); setSelectedCellArrayPath( reader->readDataArrayPath( "SelectedCellArrayPath", getSelectedCellArrayPath() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void Watershed::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSelectedCellArrayPath( reader->readDataArrayPath( "SelectedCellArrayPath", getSelectedCellArrayPath() ) ); setFeatureIdsArrayName( reader->readString( "FeatureIdsArrayName", getFeatureIdsArrayName() ) ); setThreshold( reader->readValue( "Threshold", getThreshold() ) ); setLevel( reader->readValue( "Level", getLevel() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SobelEdge::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSelectedCellArrayPath( reader->readDataArrayPath( "SelectedCellArrayPath", getSelectedCellArrayPath() ) ); setNewCellArrayName( reader->readString( "NewCellArrayName", getNewCellArrayName() ) ); setSaveAsNewArray( reader->readValue( "SaveAsNewArray", getSaveAsNewArray() ) ); setSlice( reader->readValue( "Slice", getSlice() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int Watershed::writeFilterParameters(AbstractFilterParametersWriter* writer, int index) { writer->openFilterGroup(this, index); writer->writeValue( "SelectedCellArrayPath", getSelectedCellArrayPath() ); writer->writeValue( "FeatureIdsArrayName", getFeatureIdsArrayName() ); writer->writeValue( "Threshold", getThreshold() ); writer->writeValue( "Level", getLevel() ); writer->closeFilterGroup(); return ++index; // we want to return the next index that was just written to }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ImageMath::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSelectedCellArrayPath( reader->readDataArrayPath( "SelectedCellArrayPath", getSelectedCellArrayPath() ) ); setOperator( reader->readValue( "Operator", getOperator() ) ); setValue( reader->readValue( "Value", getValue() ) ); setSaveAsNewArray( reader->readValue( "SaveAsNewArray", getSaveAsNewArray() ) ); setNewCellArrayName( reader->readString( "NewCellArrayName", getNewCellArrayName() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LinkFeatureMapToElementArray::dataCheck() { setErrorCondition(0); DataArrayPath tempPath; DataContainer::Pointer m = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getSelectedCellArrayPath().getDataContainerName(), false); if(getErrorCondition() < 0 || NULL == m.get()) { return; } QVector<size_t> tDims(1, 0); m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCellFeatureAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::CellFeature); QVector<size_t> cDims(1, 1); m_SelectedCellDataPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSelectedCellArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SelectedCellDataPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SelectedCellData = m_SelectedCellDataPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() < 0) { return; } tempPath.update(getSelectedCellArrayPath().getDataContainerName(), getCellFeatureAttributeMatrixName(), getActiveArrayName() ); m_ActivePtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<bool>, AbstractFilter, bool>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_ActivePtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_Active = m_ActivePtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindMaxima::execute() { QString ss; dataCheck(); if(getErrorCondition() < 0) { setErrorCondition(-10000); ss = QObject::tr("DataCheck did not pass during execute"); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } //get volume container DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath().getAttributeMatrixName(); //get input data IDataArray::Pointer inputData = m_SelectedCellArrayPtr.lock(); //execute type dependant portion using a Private Implementation that takes care of figuring out if // we can work on the correct type and actually handling the algorithm execution. We pass in "this" so // that the private implementation can get access to the current object to pass up status notifications, // progress or handle "cancel" if needed. if(FindMaximaPrivate<int8_t>()(inputData)) { FindMaximaPrivate<int8_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<uint8_t>()(inputData) ) { FindMaximaPrivate<uint8_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<int16_t>()(inputData) ) { FindMaximaPrivate<int16_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<uint16_t>()(inputData) ) { FindMaximaPrivate<uint16_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<int32_t>()(inputData) ) { FindMaximaPrivate<int32_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<uint32_t>()(inputData) ) { FindMaximaPrivate<uint32_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<int64_t>()(inputData) ) { FindMaximaPrivate<int64_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<uint64_t>()(inputData) ) { FindMaximaPrivate<uint64_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<float>()(inputData) ) { FindMaximaPrivate<float>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<double>()(inputData) ) { FindMaximaPrivate<double>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else { setErrorCondition(-10001); ss = QObject::tr("A Supported DataArray type was not used for an input array."); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ImageMath::execute() { //int err = 0; dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath().getAttributeMatrixName(); //wrap m_RawImageData as itk::image ImageProcessing::DefaultImageType::Pointer inputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_SelectedCellArray); //define filter types typedef itk::AddImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType, ImageProcessing::FloatImageType> AddType; typedef itk::SubtractImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType, ImageProcessing::FloatImageType> SubtractType; typedef itk::MultiplyImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType, ImageProcessing::FloatImageType> MultiplyType; typedef itk::DivideImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType, ImageProcessing::FloatImageType> DivideType; typedef itk::MinimumImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType, ImageProcessing::FloatImageType> MinType; typedef itk::MaximumImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType, ImageProcessing::FloatImageType> MaxType; typedef itk::BinaryFunctorImageFilter< ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType, ImageProcessing::FloatImageType, ImageProcessing::Functor::Gamma<ImageProcessing::FloatPixelType> > GammaType; typedef itk::LogImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> LogType; typedef itk::ExpImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> ExpType; typedef itk::SquareImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> SquareType; typedef itk::SqrtImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> SqrtType; typedef itk::InvertIntensityImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType> InvertType; //set up filter to cap image range + round typedef itk::UnaryFunctorImageFilter< ImageProcessing::FloatImageType, ImageProcessing::DefaultImageType, ImageProcessing::Functor::LimitsRound<ImageProcessing::FloatPixelType, ImageProcessing::DefaultPixelType> > LimitsRoundType; LimitsRoundType::Pointer limitsRound = LimitsRoundType::New(); //apply selected operation switch(m_Operator) { case 0://add { AddType::Pointer add = AddType::New(); add->SetInput1(inputImage); add->SetConstant2(m_Value); limitsRound->SetInput(add->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 1://subtract { SubtractType::Pointer subtract = SubtractType::New(); subtract->SetInput1(inputImage); subtract->SetConstant2(m_Value); limitsRound->SetInput(subtract->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 2://multiply { MultiplyType::Pointer multiply = MultiplyType::New(); multiply->SetInput1(inputImage); multiply->SetConstant2(m_Value); limitsRound->SetInput(multiply->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 3://divide { DivideType::Pointer divide = DivideType::New(); divide->SetInput1(inputImage); divide->SetConstant2(m_Value); limitsRound->SetInput(divide->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 4://min { MinType::Pointer minimum = MinType::New(); minimum->SetInput1(inputImage); minimum->SetConstant2(m_Value); limitsRound->SetInput(minimum->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 5://max { MaxType::Pointer maximum = MaxType::New(); maximum->SetInput1(inputImage); maximum->SetConstant2(m_Value); limitsRound->SetInput(maximum->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 6://gamma { GammaType::Pointer gamma = GammaType::New(); gamma->SetInput1(inputImage); gamma->SetConstant2(m_Value); limitsRound->SetInput(gamma->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 7://log { LogType::Pointer logfilter = LogType::New(); logfilter->SetInput(inputImage); limitsRound->SetInput(logfilter->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 8://exp { ExpType::Pointer expfilter = ExpType::New(); expfilter->SetInput(inputImage); limitsRound->SetInput(expfilter->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 9://square { SquareType::Pointer square = SquareType::New(); square->SetInput(inputImage); limitsRound->SetInput(square->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 10://squareroot { SqrtType::Pointer sqrtfilter = SqrtType::New(); sqrtfilter->SetInput(inputImage); limitsRound->SetInput(sqrtfilter->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 11://invert { InvertType::Pointer invert = InvertType::New(); invert->SetInput(inputImage); ITKUtilitiesType::SetITKFilterOutput(invert->GetOutput(), m_NewCellArrayPtr.lock()); invert->Update(); } break; } //array name changing/cleanup if(m_SaveAsNewArray == false) { AttributeMatrix::Pointer attrMat = m->getAttributeMatrix(m_SelectedCellArrayPath.getAttributeMatrixName()); attrMat->removeAttributeArray(m_SelectedCellArrayPath.getDataArrayName()); attrMat->renameAttributeArray(m_NewCellArrayName, m_SelectedCellArrayPath.getDataArrayName()); } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindMaxima::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(FilterParameter::New("Input Array", "SelectedCellArrayPath", FilterParameterWidgetType::DataArraySelectionWidget, getSelectedCellArrayPath(), false, "")); parameters.push_back(FilterParameter::New("Minimum Peak Intensity", "MinValue", FilterParameterWidgetType::DoubleWidget, getMinValue(), false, "")); parameters.push_back(FilterParameter::New("Created Array Name", "NewCellArrayName", FilterParameterWidgetType::StringWidget, getNewCellArrayName(), false, "")); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CreateFeatureArrayFromElementArray::dataCheck() { setErrorCondition(0); if (getCreatedArrayName().isEmpty() == true) { setErrorCondition(-11002); notifyErrorMessage(getHumanLabel(), "The new Feature Array name must be set", getErrorCondition()); return; } 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 */ m_InArrayPtr = getDataContainerArray()->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(this, getSelectedCellArrayPath()); getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getCellFeatureAttributeMatrixName(), -301); if(getErrorCondition() < 0 ) { return; } DataArrayPath tempPath(getCellFeatureAttributeMatrixName().getDataContainerName(), getCellFeatureAttributeMatrixName().getAttributeMatrixName(), getCreatedArrayName()); TemplateHelpers::CreateNonPrereqArrayFromArrayType()(this, tempPath, m_InArrayPtr.lock()->getComponentDimensions(), m_InArrayPtr.lock()); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LinkFeatureMapToElementArray::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(SeparatorFilterParameter::New("Element Data", FilterParameter::RequiredArray)); { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateCategoryRequirement(DREAM3D::TypeNames::Int32, 1, DREAM3D::AttributeMatrixObjectType::Element); parameters.push_back(DataArraySelectionFilterParameter::New("Element Attribute Array to Link", "SelectedCellArrayPath", getSelectedCellArrayPath(), FilterParameter::RequiredArray, req)); } parameters.push_back(SeparatorFilterParameter::New("Feature Data", FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Feature Attribute Matrix", "CellFeatureAttributeMatrixName", getCellFeatureAttributeMatrixName(), FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Active", "ActiveArrayName", getActiveArrayName(), FilterParameter::CreatedArray)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ImageMath::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(FilterParameter::New("Array to Operate On", "SelectedCellArrayPath", FilterParameterWidgetType::DataArraySelectionWidget, getSelectedCellArrayPath(), false, "")); { ChoiceFilterParameter::Pointer parameter = ChoiceFilterParameter::New(); parameter->setHumanLabel("Operator"); parameter->setPropertyName("Operator"); parameter->setWidgetType(FilterParameterWidgetType::ChoiceWidget); QVector<QString> choices; choices.push_back("Add"); choices.push_back("Subtract"); choices.push_back("Multiply"); choices.push_back("Divide"); choices.push_back("Min"); choices.push_back("Max"); choices.push_back("Gamma"); choices.push_back("Log"); choices.push_back("Exp"); choices.push_back("Square"); choices.push_back("Square Root"); choices.push_back("Invert"); parameter->setChoices(choices); parameters.push_back(parameter); } parameters.push_back(FilterParameter::New("Value", "Value", FilterParameterWidgetType::DoubleWidget, getValue(), false, "")); QStringList linkedProps; linkedProps << "NewCellArrayName"; parameters.push_back(LinkedBooleanFilterParameter::New("Save As New Array", "SaveAsNewArray", getSaveAsNewArray(), linkedProps, false)); parameters.push_back(FilterParameter::New("Created Array Name", "NewCellArrayName", FilterParameterWidgetType::StringWidget, getNewCellArrayName(), false, "")); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void Watershed::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(FilterParameter::New("Image Data Array", "SelectedCellArrayPath", FilterParameterWidgetType::DataArraySelectionWidget, getSelectedCellArrayPath(), false, "")); parameters.push_back(FilterParameter::New("Feature Ids Array", "FeatureIdsArrayName", FilterParameterWidgetType::StringWidget, getFeatureIdsArrayName(), false, "")); parameters.push_back(FilterParameter::New("Threshold", "Threshold", FilterParameterWidgetType::DoubleWidget, getThreshold(), false)); parameters.push_back(FilterParameter::New("Level", "Level", FilterParameterWidgetType::DoubleWidget, getLevel(), false)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void MultiOtsuThreshold::execute() { //int err = 0; dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath().getAttributeMatrixName(); //get dims size_t udims[3] = {0, 0, 0}; m->getGeometryAs<ImageGeom>()->getDimensions(udims); #if (CMP_SIZEOF_SIZE_T == 4) typedef int32_t DimType; #else typedef int64_t DimType; #endif DimType dims[3] = { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), }; //wrap input as itk image ImageProcessing::DefaultImageType::Pointer inputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_SelectedCellArray); if(m_Slice) { //define 2d histogram generator typedef itk::OtsuMultipleThresholdsImageFilter< ImageProcessing::DefaultSliceType, ImageProcessing::DefaultSliceType > ThresholdType; ThresholdType::Pointer otsuThresholder = ThresholdType::New(); //wrap output buffer as image ImageProcessing::DefaultImageType::Pointer outputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_NewCellArray); //loop over slices for(int i = 0; i < dims[2]; i++) { //get slice ImageProcessing::DefaultSliceType::Pointer slice = ITKUtilitiesType::ExtractSlice(inputImage, ImageProcessing::ZSlice, i); //threshold otsuThresholder->SetInput(slice); otsuThresholder->SetNumberOfThresholds(m_Levels); otsuThresholder->SetLabelOffset(1); //execute filters try { otsuThresholder->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::OtsuMultipleThresholdsImageFilter filter. Error Message returned from ITK:\n %1").arg(err.GetDescription()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } //copy back into volume ITKUtilitiesType::SetSlice(outputImage, otsuThresholder->GetOutput(), ImageProcessing::ZSlice, i); } } else { typedef itk::OtsuMultipleThresholdsImageFilter< ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType > ThresholdType; ThresholdType::Pointer otsuThresholder = ThresholdType::New(); otsuThresholder->SetInput(inputImage); otsuThresholder->SetNumberOfThresholds(m_Levels); otsuThresholder->SetLabelOffset(1); ITKUtilitiesType::SetITKFilterOutput(otsuThresholder->GetOutput(), m_NewCellArrayPtr.lock()); //execute filters try { otsuThresholder->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::OtsuMultipleThresholdsImageFilter filter. Error Message returned from ITK:\n %1").arg(err.GetDescription()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } } //array name changing/cleanup if(m_SaveAsNewArray == false) { AttributeMatrix::Pointer attrMat = m->getAttributeMatrix(m_SelectedCellArrayPath.getAttributeMatrixName()); attrMat->removeAttributeArray(m_SelectedCellArrayPath.getDataArrayName()); attrMat->renameAttributeArray(m_NewCellArrayName, m_SelectedCellArrayPath.getDataArrayName()); } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CreateFeatureArrayFromElementArray::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(SeparatorFilterParameter::New("Element Data", FilterParameter::RequiredArray)); { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateCategoryRequirement(DREAM3D::Defaults::AnyPrimitive, DREAM3D::Defaults::AnyComponentSize, DREAM3D::AttributeMatrixObjectType::Element); parameters.push_back(DataArraySelectionFilterParameter::New("Element Data to Copy to Feature Data", "SelectedCellArrayPath", getSelectedCellArrayPath(), FilterParameter::RequiredArray, req)); } { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateCategoryRequirement(DREAM3D::TypeNames::Int32, 1, DREAM3D::AttributeMatrixObjectType::Element); parameters.push_back(DataArraySelectionFilterParameter::New("Feature Ids", "FeatureIdsArrayPath", getFeatureIdsArrayPath(), FilterParameter::RequiredArray, req)); } parameters.push_back(SeparatorFilterParameter::New("Feature Data", FilterParameter::CreatedArray)); { AttributeMatrixSelectionFilterParameter::RequirementType req = AttributeMatrixSelectionFilterParameter::CreateRequirement(DREAM3D::AttributeMatrixType::CellFeature, DREAM3D::Defaults::AnyGeometry); parameters.push_back(AttributeMatrixSelectionFilterParameter::New("Feature Attribute Matrix", "CellFeatureAttributeMatrixName", getCellFeatureAttributeMatrixName(), FilterParameter::CreatedArray, req)); } parameters.push_back(StringFilterParameter::New("Copied Attribute Array", "CreatedArrayName", getCreatedArrayName(), FilterParameter::CreatedArray)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SobelEdge::execute() { dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath().getAttributeMatrixName(); //wrap m_RawImageData as itk::image ImageProcessing::DefaultImageType::Pointer inputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_SelectedCellArray); if(m_Slice) { //wrap output array ImageProcessing::DefaultImageType::Pointer outputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_NewCellArray); //get dimensions size_t udims[3] = {0, 0, 0}; m->getGeometryAs<ImageGeom>()->getDimensions(udims); #if (CMP_SIZEOF_SIZE_T == 4) typedef int32_t DimType; #else typedef int64_t DimType; #endif DimType dims[3] = { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), }; //create edge filter typedef itk::SobelEdgeDetectionImageFilter<ImageProcessing::DefaultSliceType, ImageProcessing::FloatSliceType> SobelFilterType; SobelFilterType::Pointer sobelFilter = SobelFilterType::New(); //convert result back to uint8 typedef itk::RescaleIntensityImageFilter<ImageProcessing::FloatSliceType, ImageProcessing::DefaultSliceType> RescaleImageType; RescaleImageType::Pointer rescaleFilter = RescaleImageType::New(); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); //loop over slices applying filters for(int i = 0; i < dims[2]; ++i) { QString ss = QObject::tr("Finding Edges On Slice: %1").arg(i + 1); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); //get slice ImageProcessing::DefaultSliceType::Pointer inputSlice = ITKUtilitiesType::ExtractSlice(inputImage, ImageProcessing::ZSlice, i); //run filters sobelFilter->SetInput(inputSlice); rescaleFilter->SetInput(sobelFilter->GetOutput()); //execute filters try { sobelFilter->Update(); rescaleFilter->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::SobelEdgeDetectionImageFilter filter. Error Message returned from ITK:\n %1").arg(err.GetDescription()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } //copy into volume ITKUtilitiesType::SetSlice(outputImage, rescaleFilter->GetOutput(), ImageProcessing::ZSlice, i); } } else { //create edge filter typedef itk::SobelEdgeDetectionImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> SobelFilterType; SobelFilterType::Pointer sobelFilter = SobelFilterType::New(); sobelFilter->SetInput(inputImage); //convert result back to uint8 typedef itk::RescaleIntensityImageFilter<ImageProcessing::FloatImageType, ImageProcessing::DefaultImageType> RescaleImageType; RescaleImageType::Pointer rescaleFilter = RescaleImageType::New(); rescaleFilter->SetInput(sobelFilter->GetOutput()); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); //have filter write to dream3d array instead of creating its own buffer ITKUtilitiesType::SetITKFilterOutput(rescaleFilter->GetOutput(), m_NewCellArrayPtr.lock()); //execute filters try { sobelFilter->Update(); rescaleFilter->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::SobelEdgeDetectionImageFilter filter. Error Message returned from ITK:\n %1").arg(err.GetDescription()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } } //array name changing/cleanup if(m_SaveAsNewArray == false) { AttributeMatrix::Pointer attrMat = m->getAttributeMatrix(m_SelectedCellArrayPath.getAttributeMatrixName()); attrMat->removeAttributeArray(m_SelectedCellArrayPath.getDataArrayName()); attrMat->renameAttributeArray(m_NewCellArrayName, m_SelectedCellArrayPath.getDataArrayName()); } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 SobelEdge::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(FilterParameter::New("Array to Process", "SelectedCellArrayPath", FilterParameterWidgetType::DataArraySelectionWidget, getSelectedCellArrayPath(), false, "")); QStringList linkedProps; linkedProps << "NewCellArrayName"; parameters.push_back(LinkedBooleanFilterParameter::New("Save As New Array", "SaveAsNewArray", getSaveAsNewArray(), linkedProps, false)); parameters.push_back(FilterParameter::New("Created Array Name", "NewCellArrayName", FilterParameterWidgetType::StringWidget, getNewCellArrayName(), false, "")); parameters.push_back(FilterParameter::New("Slice at a Time", "Slice", FilterParameterWidgetType::BooleanWidget, getSlice(), false)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ConvertData::setupFilterParameters() { FilterParameterVector parameters; { ChoiceFilterParameter::Pointer parameter = ChoiceFilterParameter::New(); parameter->setHumanLabel("Scalar Type"); parameter->setPropertyName("ScalarType"); QVector<QString> choices; choices.push_back("signed int 8 bit"); choices.push_back("unsigned int 8 bit"); choices.push_back("signed int 16 bit"); choices.push_back("unsigned int 16 bit"); choices.push_back("signed int 32 bit"); choices.push_back("unsigned int 32 bit"); choices.push_back("signed int 64 bit"); choices.push_back("unsigned int 64 bit"); choices.push_back(" Float 32 bit"); choices.push_back(" Double 64 bit"); parameter->setChoices(choices); parameter->setCategory(FilterParameter::Parameter); parameters.push_back(parameter); } parameters.push_back(DataArraySelectionFilterParameter::New("Attribute Array to Convert", "SelectedCellArrayPath", getSelectedCellArrayPath(), FilterParameter::RequiredArray)); parameters.push_back(StringFilterParameter::New("Converted Attribute Array", "OutputArrayName", getOutputArrayName(), FilterParameter::CreatedArray)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CreateFeatureArrayFromElementArray::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(SeparatorFilterParameter::New("Element Data", FilterParameter::RequiredArray)); parameters.push_back(DataArraySelectionFilterParameter::New("Element Data to Copy to Feature Data", "SelectedCellArrayPath", getSelectedCellArrayPath(), FilterParameter::RequiredArray)); parameters.push_back(DataArraySelectionFilterParameter::New("Feature Ids", "FeatureIdsArrayPath", getFeatureIdsArrayPath(), FilterParameter::RequiredArray)); parameters.push_back(SeparatorFilterParameter::New("Feature Data", FilterParameter::CreatedArray)); parameters.push_back(AttributeMatrixSelectionFilterParameter::New("Feature Attribute Matrix", "CellFeatureAttributeMatrixName", getCellFeatureAttributeMatrixName(), FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Copied Attribute Array", "CreatedArrayName", getCreatedArrayName(), FilterParameter::CreatedArray)); setFilterParameters(parameters); }