// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 */ } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- IntVec3_t CropImageGeometry::getCurrentVolumeDataContainerDimensions() { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName()); IntVec3_t data; if (NULL != m.get() ) { ImageGeom::Pointer image = m->getGeometryAs<ImageGeom>(); if (image.get() != NULL) { data.x = image->getXPoints(); data.y = image->getYPoints(); data.z = image->getZPoints(); } else { data.x = 0; data.y = 0; data.z = 0; } } else { data.x = 0; data.y = 0; data.z = 0; } return data; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void MergeTwins::dataCheck() { setErrorCondition(0); DataArrayPath tempPath; GroupFeatures::dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, m_FeatureIdsArrayPath.getDataContainerName(), false); if(getErrorCondition() < 0 || NULL == m.get()) { return; } QVector<size_t> tDims(1, 0); m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getNewCellFeatureAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::CellFeature); QVector<size_t> cDims(1, 1); QVector<DataArrayPath> dataArrayPaths; // Cell Data m_FeatureIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeatureIdsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ tempPath.update(m_FeatureIdsArrayPath.getDataContainerName(), m_FeatureIdsArrayPath.getAttributeMatrixName(), getCellParentIdsArrayName() ); m_CellParentIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, -1, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_CellParentIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_CellParentIds = m_CellParentIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ // Feature Data m_FeaturePhasesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeaturePhasesArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_FeaturePhasesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FeaturePhases = m_FeaturePhasesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrayPaths.push_back(getFeaturePhasesArrayPath()); } tempPath.update(m_FeaturePhasesArrayPath.getDataContainerName(), m_FeaturePhasesArrayPath.getAttributeMatrixName(), getFeatureParentIdsArrayName() ); m_FeatureParentIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, -1, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_FeatureParentIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FeatureParentIds = m_FeatureParentIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 4; m_AvgQuatsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getAvgQuatsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_AvgQuatsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_AvgQuats = m_AvgQuatsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrayPaths.push_back(getAvgQuatsArrayPath()); } // New Feature Data cDims[0] = 1; tempPath.update(m_FeatureIdsArrayPath.getDataContainerName(), getNewCellFeatureAttributeMatrixName(), getActiveArrayName() ); m_ActivePtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<bool>, AbstractFilter, bool>(this, tempPath, true, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_ActivePtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_Active = m_ActivePtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ // Ensemble Data m_CrystalStructuresPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<unsigned int>, AbstractFilter>(this, getCrystalStructuresArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_CrystalStructuresPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_CrystalStructures = m_CrystalStructuresPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, dataArrayPaths); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void EBSDSegmentFeatures::dataCheck() { setErrorCondition(0); DataArrayPath tempPath; SegmentFeatures::dataCheck(); if(getErrorCondition() < 0) { return; } // Set the DataContainerName for the Parent Class (SegmentFeatures) to Use setDataContainerName(m_QuatsArrayPath.getDataContainerName()); DataContainer::Pointer m = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, 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<DataArrayPath> dataArrayPaths; QVector<size_t> cDims(1, 1); if(m_UseGoodVoxels == true) { 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) { dataArrayPaths.push_back(getGoodVoxelsArrayPath()); } } m_CellPhasesPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getCellPhasesArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_CellPhasesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_CellPhases = m_CellPhasesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrayPaths.push_back(getCellPhasesArrayPath()); } tempPath.update(getDataContainerName(), m_QuatsArrayPath.getAttributeMatrixName(), getFeatureIdsArrayName() ); m_FeatureIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ tempPath.update(getDataContainerName(), getCellFeatureAttributeMatrixName(), getActiveArrayName() ); m_ActivePtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<bool>, AbstractFilter, bool>(this, tempPath, true, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_ActivePtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_Active = m_ActivePtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ m_CrystalStructuresPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<uint32_t>, AbstractFilter>(this, getCrystalStructuresArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_CrystalStructuresPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_CrystalStructures = m_CrystalStructuresPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 4; m_QuatsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getQuatsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_QuatsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_Quats = m_QuatsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrayPaths.push_back(getQuatsArrayPath()); } getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, dataArrayPaths); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void DataContainerBundle::removeDataContainer(DataContainer::Pointer dc) { for(qint32 i = 0; i < m_DataContainers.size(); i++) { if(m_DataContainers[i].get() == dc.get()) { m_DataContainers.remove(i); return; } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindGBCD::dataCheckSurfaceMesh() { setErrorCondition(0); initialize(); DataArrayPath tempPath; getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); DataContainer::Pointer sm = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), false); if(getErrorCondition() < 0 || NULL == sm.get()) { return; } QVector<size_t> tDims(1, m_CrystalStructuresPtr.lock()->getNumberOfTuples()); sm->createNonPrereqAttributeMatrix<AbstractFilter>(this, getFaceEnsembleAttributeMatrixName(), tDims, SIMPL::AttributeMatrixType::FaceEnsemble); QVector<size_t> cDims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 3; m_SurfaceMeshFaceNormalsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<double>, AbstractFilter>(this, getSurfaceMeshFaceNormalsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceNormalsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceNormals = m_SurfaceMeshFaceNormalsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 1; m_SurfaceMeshFaceAreasPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<double>, AbstractFilter>(this, getSurfaceMeshFaceAreasArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceAreasPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceAreas = m_SurfaceMeshFaceAreasPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ // call the sizeGBCD function to get the GBCD ranges, dimensions, etc. Note that the input parameters do not affect the size and can be dummy values here; sizeGBCD(0, 0); cDims.resize(6); cDims[0] = m_GbcdSizes[0]; cDims[1] = m_GbcdSizes[1]; cDims[2] = m_GbcdSizes[2]; cDims[3] = m_GbcdSizes[3]; cDims[4] = m_GbcdSizes[4]; cDims[5] = 2; tempPath.update(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), getFaceEnsembleAttributeMatrixName(), getGBCDArrayName() ); m_GBCDPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<double>, AbstractFilter, double>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_GBCDPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_GBCD = m_GBCDPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindModulusMismatch::dataCheckSurfaceMesh() { DataArrayPath tempPath; setErrorCondition(0); DataContainer::Pointer sm = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); if(getErrorCondition() < 0 || NULL == sm.get()) { return; } QVector<size_t> dims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ dims[0] = 1; tempPath.update(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), m_SurfaceMeshFaceLabelsArrayPath.getAttributeMatrixName(), getSurfaceMeshDeltaModulusArrayName() ); m_SurfaceMeshDeltaModulusPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<float>, AbstractFilter, float>(this, tempPath, 180.0, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshDeltaModulusPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshDeltaModulus = m_SurfaceMeshDeltaModulusPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
static void PopulateDataContainerComboBox(AbstractFilter* filter, FilterParameter* filterParameter, QComboBox* dcCombo, DataContainerArrayProxy& dcaProxy) { FilterParameterType* fp = dynamic_cast<FilterParameterType*>(filterParameter); assert(fp != NULL); DataContainerArray::Pointer dca = filter->getDataContainerArray(); // Populate the DataContainerArray Combo Box with all the DataContainers QList<DataContainerProxy> dcList = dcaProxy.dataContainers.values(); QListIterator<DataContainerProxy> iter(dcList); dcCombo->clear(); QVector<unsigned int> defVec = fp->getDefaultGeometryTypes(); while(iter.hasNext() ) { DataContainerProxy dcProxy = iter.next(); DataContainer::Pointer dc = dca->getDataContainer(dcProxy.name); IGeometry::Pointer geom = IGeometry::NullPointer(); uint32_t geomType = 999; if (NULL != dc.get()) { geom = dc->getGeometry(); } if (NULL != geom.get()) { geomType = geom->getGeometryType(); } dcCombo->addItem(dcProxy.name); if (defVec.isEmpty() == false) { if (defVec.contains(geomType) == false) { QStandardItemModel* model = qobject_cast<QStandardItemModel*>(dcCombo->model()); if (NULL != model) { QStandardItem* item = model->item(dcCombo->findText(dcProxy.name)); if (NULL != item) { item->setFlags(item->flags() & ~Qt::ItemIsEnabled); } } } } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int DataContainerReader::readDataContainerBundles(hid_t fileId, DataContainerArray::Pointer dca) { herr_t err = 0; hid_t dcbGroupId = H5Gopen(fileId, DREAM3D::StringConstants::DataContainerBundleGroupName.toLatin1().constData(), H5P_DEFAULT); if (dcbGroupId < 0) { // NO Bundles are available to read so just return. // QString ss = QObject::tr("Error opening HDF5 Group '%1' ").arg(DREAM3D::StringConstants::DataContainerBundleGroupName); // setErrorCondition(-75); // notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return 0; } HDF5ScopedGroupSentinel sentinel(&dcbGroupId, false); QList<QString> groupNames; err = QH5Utilities::getGroupObjects(dcbGroupId, H5Utilities::H5Support_GROUP, groupNames); if (err < 0) { QString ss = QObject::tr("Error getting group objects from HDF5 group '%1' ").arg(DREAM3D::StringConstants::DataContainerBundleGroupName); setErrorCondition(-76); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return err; } char sep = 0x1E; QListIterator<QString> iter(groupNames); while (iter.hasNext() ) { QString bundleName = iter.next(); DataContainerBundle::Pointer bundle = DataContainerBundle::New(bundleName); hid_t bundleId = H5Gopen(dcbGroupId, bundleName.toLatin1().constData(), H5P_DEFAULT); sentinel.addGroupId(&bundleId); // Make sure this group gets closed // Read in the Data Container Names QString dcNames; err = QH5Lite::readStringDataset(bundleId, DREAM3D::StringConstants::DataContainerNames, dcNames); if (err < 0) { QString ss = QObject::tr("Error reading DataContainer group names from HDF5 group '%1' ").arg(bundleName); setErrorCondition(-75); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return err; } QStringList dcNameList = dcNames.split(QString(sep)); QStringListIterator nameIter(dcNameList); while(nameIter.hasNext() ) { QString dcName = nameIter.next(); DataContainer::Pointer dc = dca->getDataContainer(dcName); if (NULL == dc.get() ) { qDebug() << "Data Container '" << dcName << "' was NULL" << " " << __FILE__ << "(" << __LINE__ << ")"; } bundle->addDataContainer(dc); } QString metaArrays; err = QH5Lite::readStringDataset(bundleId, DREAM3D::StringConstants::MetaDataArrays, metaArrays); if (err < 0) { QString ss = QObject::tr("Error reading DataContainerBundle meta data arrays from HDF5 group '%1' ").arg(bundleName); setErrorCondition(-76); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return err; } QStringList metaNameList = metaArrays.split(QString(sep)); bundle->setMetaDataArrays(metaNameList); dca->addDataContainerBundle(bundle); } H5Gclose(dcbGroupId); dcbGroupId = -1; return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CombineAttributeMatrices::dataCheck() { setErrorCondition(0); DataArrayPath tempPath; DataContainer::Pointer m = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getFirstAttributeMatrixPath().getDataContainerName(), false); if (getErrorCondition() < 0 || NULL == m.get()) { return; } if (getFirstAttributeMatrixPath().getDataContainerName().compare(getSecondAttributeMatrixPath().getDataContainerName()) != 0) { QString ss = QObject::tr("The selected attribute matrices must be in the same data container and currently are not"); setErrorCondition(-5557); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } if (getFirstAttributeMatrixPath().getAttributeMatrixName().compare(getSecondAttributeMatrixPath().getAttributeMatrixName()) == 0) { QString ss = QObject::tr("The selected attribute matrices must be different and currently are the same"); setErrorCondition(-5558); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } AttributeMatrix::Pointer firstAttrMat = m->getPrereqAttributeMatrix(this, getFirstAttributeMatrixPath().getAttributeMatrixName(), -301); AttributeMatrix::Pointer secondAttrMat = m->getPrereqAttributeMatrix(this, getSecondAttributeMatrixPath().getAttributeMatrixName(), -301); if (getErrorCondition() < 0) { return; } if (firstAttrMat->getType() != secondAttrMat->getType()) { QString ss = QObject::tr("The selected attribute matrices must be of the same type (ie Feature) and currently are not"); setErrorCondition(-5559); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } if (getErrorCondition() < 0) { return; } //Note that the minus 1 in the totalTuples calculation is to account for the fact that the zeroth tuple in the two attribute matrices should only be counted once, not twice. //All Feature or Ensemble AMs should start from 1 and the zeroth tuple can be combined in the two AMs size_t totalTuples = firstAttrMat->getNumTuples() + secondAttrMat->getNumTuples() - 1; QVector<size_t> tDims(1, totalTuples); m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCombinedAttributeMatrixName(), tDims, firstAttrMat->getType()); if (getErrorCondition() < 0) { return; } AttributeMatrix::Pointer combinedAttrMat = m->getAttributeMatrix(getCombinedAttributeMatrixName()); QVector<size_t> cDims(1, 1); m_FirstIndexPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFirstIndexArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if (NULL != m_FirstIndexPtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FirstIndex = m_FirstIndexPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if (getErrorCondition() < 0) { return; } m_SecondIndexPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSecondIndexArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if (NULL != m_SecondIndexPtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SecondIndex = m_SecondIndexPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if (getErrorCondition() < 0) { return; } // Create arrays on the reference grid to hold data present on the sampling grid QList<QString> fArrayNames = firstAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = fArrayNames.begin(); iter != fArrayNames.end(); ++iter) { tempPath.update(getFirstAttributeMatrixPath().getDataContainerName(), getCombinedAttributeMatrixName(), *iter); IDataArray::Pointer tmpDataArray = firstAttrMat->getPrereqIDataArray<IDataArray, AbstractFilter>(this, *iter, -90001); if (getErrorCondition() >= 0) { QVector<size_t> cDims = tmpDataArray->getComponentDimensions(); TemplateHelpers::CreateNonPrereqArrayFromArrayType()(this, tempPath, cDims, tmpDataArray); } } QList<QString> sArrayNames = secondAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = sArrayNames.begin(); iter != sArrayNames.end(); ++iter) { tempPath.update(getSecondAttributeMatrixPath().getDataContainerName(), getCombinedAttributeMatrixName(), *iter); IDataArray::Pointer tmpDataArray = secondAttrMat->getPrereqIDataArray<IDataArray, AbstractFilter>(this, *iter, -90001); if (getErrorCondition() >= 0) { if (fArrayNames.contains(*iter) == false) { QVector<size_t> cDims = tmpDataArray->getComponentDimensions(); TemplateHelpers::CreateNonPrereqArrayFromArrayType()(this, tempPath, cDims, tmpDataArray); } } } tempPath.update(getFirstIndexArrayPath().getDataContainerName(), getFirstIndexArrayPath().getAttributeMatrixName(), getNewIndexArrayName()); m_NewIndexPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if (NULL != m_NewIndexPtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_NewIndex = m_NewIndexPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if (getErrorCondition() < 0) { return; } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CropImageGeometry::execute() { setErrorCondition(0); /* Normally, filters call dataCheck during the execute to reuse code. Unfortunately, this cannot happen for this filter, because calling dataCheck would destroy an Attribute Matrix that we need during the execute. Do not uncomment the code, and be careful when reusing code from either of these functions. Make sure you understand how this works before you reuse any code. */ //dataCheck(); //if(getErrorCondition() < 0) { return; } DataContainer::Pointer srcCellDataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getCellAttributeMatrixPath().getDataContainerName()); AttributeMatrix::Pointer cellAttrMat = srcCellDataContainer->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName()); DataContainer::Pointer destCellDataContainer = srcCellDataContainer; if (m_SaveAsNewDataContainer == true) { float ox = 0.0f, oy = 0.0f, oz = 0.0f, rx = 0.0f, ry = 0.0f, rz = 0.0f; srcCellDataContainer->getGeometryAs<ImageGeom>()->getOrigin(ox, oy, oz); srcCellDataContainer->getGeometryAs<ImageGeom>()->getResolution(rx, ry, rz); destCellDataContainer = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getNewDataContainerName()); ImageGeom::Pointer image = ImageGeom::CreateGeometry(DREAM3D::Geometry::ImageGeometry); destCellDataContainer->setGeometry(image); destCellDataContainer->getGeometryAs<ImageGeom>()->setOrigin(ox, oy, oz); destCellDataContainer->getGeometryAs<ImageGeom>()->setResolution(rx, ry, rz); AttributeMatrix::Pointer cellAttrMatCopy = cellAttrMat->deepCopy(); destCellDataContainer->addAttributeMatrix(cellAttrMatCopy->getName(), cellAttrMatCopy); cellAttrMat = destCellDataContainer->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName()); } if(NULL == destCellDataContainer.get() || NULL == cellAttrMat.get() || getErrorCondition() < 0) { return; } // No matter where the AM is (same DC or new DC), we have the correct DC and AM pointers...now it's time to crop int64_t totalPoints = cellAttrMat->getNumTuples(); size_t udims[3] = { 0, 0, 0 }; srcCellDataContainer->getGeometryAs<ImageGeom>()->getDimensions(udims); #if (CMP_SIZEOF_SIZE_T == 4) typedef int32_t DimType; #else typedef int64_t DimType; #endif DimType dims[3] = { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), }; // Check to see if the dims have actually changed. if(dims[0] == (m_XMax - m_XMin) && dims[1] == (m_YMax - m_YMin) && dims[2] == (m_ZMax - m_ZMin)) { return; } // Get current origin float oldOrigin[3] = {0.0f, 0.0f, 0.0f}; destCellDataContainer->getGeometryAs<ImageGeom>()->getOrigin(oldOrigin); // Check to make sure the new dimensions are not "out of bounds" and warn the user if they are if (dims[0] <= m_XMax) { QString ss = QObject::tr("The Max X value (%1) is greater than the Image Geometry X entent (%2)." " This may lead to junk data being filled into the extra space.").arg(m_XMax).arg(dims[0]); setErrorCondition(-950); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } if (dims[1] <= m_YMax) { QString ss = QObject::tr("The Max Y value (%1) is greater than the Image Geometry Y entent (%2)." " This may lead to junk data being filled into the extra space.").arg(m_YMax).arg(dims[1]); setErrorCondition(-951); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } if (dims[2] <= m_ZMax) { QString ss = QObject::tr("The Max Z value (%1) is greater than the Image Geometry Z entent (%2)." " This may lead to junk data being filled into the extra space.").arg(m_ZMax).arg(dims[2]); setErrorCondition(-952); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } int64_t XP = ( (m_XMax - m_XMin) + 1 ); int64_t YP = ( (m_YMax - m_YMin) + 1 ); int64_t ZP = ( (m_ZMax - m_ZMin) + 1 ); int64_t col = 0, row = 0, plane = 0; int64_t colold = 0, rowold = 0, planeold = 0; int64_t index = 0; int64_t index_old = 0; QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames(); for (int64_t i = 0; i < ZP; i++) { QString ss = QObject::tr("Cropping Volume - Slice %1 of %2 Complete").arg(i).arg(ZP); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); planeold = (i + m_ZMin) * (srcCellDataContainer->getGeometryAs<ImageGeom>()->getXPoints() * srcCellDataContainer->getGeometryAs<ImageGeom>()->getYPoints()); plane = (i * XP * YP); for (int64_t j = 0; j < YP; j++) { rowold = (j + m_YMin) * srcCellDataContainer->getGeometryAs<ImageGeom>()->getXPoints(); row = (j * XP); for (int64_t k = 0; k < XP; k++) { colold = (k + m_XMin); col = k; index_old = planeold + rowold + colold; index = plane + row + col; for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = cellAttrMat->getAttributeArray(*iter); p->copyTuple(index_old, index); } } } } destCellDataContainer->getGeometryAs<ImageGeom>()->setDimensions(static_cast<size_t>(XP), static_cast<size_t>(YP), static_cast<size_t>(ZP)); totalPoints = destCellDataContainer->getGeometryAs<ImageGeom>()->getNumberOfElements(); QVector<size_t> tDims(3, 0); tDims[0] = XP; tDims[1] = YP; tDims[2] = ZP; cellAttrMat->setTupleDimensions(tDims); // THIS WILL CAUSE A RESIZE of all the underlying data arrays. if (m_RenumberFeatures == true) { totalPoints = destCellDataContainer->getGeometryAs<ImageGeom>()->getNumberOfElements(); // This just sanity checks to make sure there were existing features before the cropping AttributeMatrix::Pointer cellFeatureAttrMat = srcCellDataContainer->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName()); size_t totalFeatures = cellFeatureAttrMat->getNumTuples(); QVector<bool> activeObjects(totalFeatures, false); if (0 == totalFeatures) { setErrorCondition(-600); notifyErrorMessage(getHumanLabel(), "The number of Features is 0 and should be greater than 0", getErrorCondition()); return; } //QVector<size_t> cDims(1, 1); DataArrayPath dap = getFeatureIdsArrayPath(); if(getSaveAsNewDataContainer()) { dap.setDataContainerName(getNewDataContainerName()); } m_FeatureIdsPtr = cellAttrMat->getAttributeArrayAs<Int32ArrayType>(dap.getDataArrayName()); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ else { setErrorCondition(-601); QString ss = QObject::tr("The FeatureIds array with name '%1' was not found in the destination DataContainer. The expected path was '%2'") .arg(dap.getDataArrayName()).arg(dap.serialize("/")); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } // Find the unique set of feature ids for (int64_t i = 0; i < totalPoints; ++i) { int32_t currentFeatureId = m_FeatureIds[i]; if (currentFeatureId < totalFeatures) { activeObjects[currentFeatureId] = true; } else { setErrorCondition(-601); QString ss = QObject::tr("The total number of Features from %1 is %2, but a value of %3 was found in DataArray %4.").arg(cellFeatureAttrMat->getName()).arg(totalFeatures).arg(currentFeatureId).arg(getFeatureIdsArrayPath().serialize("/")); qDebug() << ss; notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } } cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock()); } if(m_UpdateOrigin == true) { float resolution[3] = {0.0f, 0.0f, 0.0f}; destCellDataContainer->getGeometryAs<ImageGeom>()->getResolution(resolution); float origin[3] = {0.0f, 0.0f, 0.0f}; destCellDataContainer->getGeometryAs<ImageGeom>()->getOrigin(origin); origin[0] = m_XMin * resolution[0] + oldOrigin[0]; origin[1] = m_YMin * resolution[1] + oldOrigin[1]; origin[2] = m_ZMin * resolution[2] + oldOrigin[2]; destCellDataContainer->getGeometryAs<ImageGeom>()->setOrigin(origin); } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CropImageGeometry::dataCheck() { if(getErrorCondition() < 0) { return; } setErrorCondition(0); // Validate the incoming DataContainer, Geometry, and AttributeMatrix ; bail if any do not exist since we plan on using them later on in the dataCheck // Error messages are handled by the getPrereq functions DataContainer::Pointer srcCellDataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getCellAttributeMatrixPath().getDataContainerName()); ImageGeom::Pointer image = getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getCellAttributeMatrixPath().getDataContainerName()); AttributeMatrix::Pointer srcCellAttrMat = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getCellAttributeMatrixPath(), -301); if(getErrorCondition() < 0) { return; } DataContainer::Pointer destCellDataContainer = srcCellDataContainer; AttributeMatrix::Pointer destCellAttrMat; if (m_SaveAsNewDataContainer == true) { float ox = 0.0f, oy = 0.0f, oz = 0.0f, rx = 0.0f, ry = 0.0f, rz = 0.0f; size_t dx = 0, dy = 0, dz = 0; image->getOrigin(ox, oy, oz); image->getResolution(rx, ry, rz); image->getDimensions(dx, dy, dz); destCellDataContainer = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getNewDataContainerName()); if(NULL == destCellDataContainer.get() || getErrorCondition() < 0) { return; } IGeometry::Pointer imageCopy = image->deepCopy(); destCellDataContainer->setGeometry(imageCopy); destCellAttrMat = srcCellAttrMat->deepCopy(); destCellDataContainer->addAttributeMatrix(destCellAttrMat->getName(), destCellAttrMat); } else { destCellAttrMat = srcCellAttrMat; } if(NULL == destCellDataContainer.get() || NULL == destCellAttrMat.get() || getErrorCondition() < 0) { return; } if (getXMax() < getXMin()) { QString ss = QObject::tr("X Max (%1) less than X Min (%2)").arg(getXMax()).arg(getXMin()); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } if (getYMax() < getYMin()) { QString ss = QObject::tr("Y Max (%1) less than Y Min (%2)").arg(getYMax()).arg(getYMin()); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } if (getZMax() < getZMin()) { QString ss = QObject::tr("Z Max (%1) less than Z Min (%2)").arg(getZMax()).arg(getZMin()); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } if (getXMin() < 0) { QString ss = QObject::tr("X Min (%1) less than 0").arg(getXMin()); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } if (getYMin() < 0) { QString ss = QObject::tr("Y Min (%1) less than 0").arg(getYMin()); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } if (getZMin() < 0) { QString ss = QObject::tr("Z Min (%1) less than 0").arg(getZMin()); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } if (getXMax() > (static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getXPoints()) - 1)) { QString ss = QObject::tr("The X Max (%1) is greater than the Image Geometry X extent (%2)").arg(getXMax()).arg(static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getXPoints()) - 1); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } if (getYMax() > (static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getYPoints()) - 1)) { QString ss = QObject::tr("The Y Max (%1) is greater than the Image Geometry Y extent (%2)").arg(getYMax()).arg(static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getYPoints()) - 1); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } if (getZMax() > (static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getZPoints()) - 1)) { QString ss = QObject::tr("The Z Max (%1) is greater than the Image Geometry Z extent (%2)").arg(getZMax()).arg(static_cast<int64_t>(destCellDataContainer->getGeometryAs<ImageGeom>()->getZPoints()) - 1); notifyErrorMessage(getHumanLabel(), ss, -5550); setErrorCondition(-5550); } QVector<size_t> tDims(3, 0); if (getXMax() - getXMin() < 0) { setXMax(getXMin() + 1); } if (getYMax() - getYMin() < 0) { setYMax(getYMin() + 1); } if (getZMax() - getZMin() < 0) { setZMax(getZMin() + 1); } tDims[0] = (getXMax() - getXMin()) + 1; tDims[1] = (getYMax() - getYMin()) + 1; tDims[2] = (getZMax() - getZMin()) + 1; destCellDataContainer->getGeometryAs<ImageGeom>()->setDimensions(tDims[0], tDims[1], tDims[2]); // If any of the sanity checks fail above then we should NOT attempt to go any further. if (getErrorCondition() < 0) { return; } size_t totalPoints = 1; for(int i = 0; i < 3; i++) { if(tDims[i] != 0) { totalPoints *= tDims[i]; } } AttributeMatrix::Pointer newCellAttrMat = AttributeMatrix::New(tDims, destCellAttrMat->getName(), destCellAttrMat->getType()); QList<QString> voxelArrayNames = destCellAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = destCellAttrMat->getAttributeArray(*iter); // IDataArray::Pointer data = p->createNewArray(totalPoints, p->getComponentDimensions(), p->getName(), false); destCellAttrMat->removeAttributeArray(*iter); newCellAttrMat->addAttributeArray(*iter, data); } destCellDataContainer->removeAttributeMatrix(destCellAttrMat->getName()); destCellDataContainer->addAttributeMatrix(newCellAttrMat->getName(), newCellAttrMat); if(m_RenumberFeatures == true) { QVector<size_t> cDims(1, 1); m_FeatureIdsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFeatureIdsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ AttributeMatrix::Pointer cellFeatureAttrMat = srcCellDataContainer->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName()); if(NULL == cellFeatureAttrMat.get()) { return; } QVector<bool> activeObjects(cellFeatureAttrMat->getNumTuples(), true); cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock()); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void 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); } }