// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void QuadGeom::addAttributeMatrix(const QString& name, AttributeMatrix::Pointer data) { if (data->getType() != 0 || data->getType() != 1 || data->getType() != 2) { // QuadGeom can only accept vertex, edge, or face Attribute Matrices return; } if (data->getType() == 0 && static_cast<int64_t>(data->getNumTuples()) != getNumberOfVertices()) { return; } if (data->getType() == 1 && static_cast<int64_t>(data->getNumTuples()) != getNumberOfEdges()) { return; } if (data->getType() == 2 && data->getNumTuples() != getNumberOfElements()) { return; } if (data->getName().compare(name) != 0) { data->setName(name); } m_AttributeMatrices[name] = data; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void MoveData::dataCheck() { setErrorCondition(0); DataArrayPath amSrcPath = getAttributeMatrixSource(); DataArrayPath amDestPath = getAttributeMatrixDestination(); DataArrayPath daSrcPath = getDataArraySource(); if (getWhatToMove() == k_MoveAttributeMatrix) { DataContainer::Pointer amDestDataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getDataContainerDestination()); DataContainer::Pointer amSrcDataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, amSrcPath.getDataContainerName()); AttributeMatrix::Pointer amSrcAttributeMatrix = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, amSrcPath, -301); if(getErrorCondition() < 0) { return; } if (amSrcDataContainer->getName() == amDestDataContainer->getName()) { QString ss = QObject::tr("The source and destination Data Container are the same. Is this what you meant to do?"); notifyWarningMessage(getHumanLabel(), ss, getErrorCondition()); return; } amDestDataContainer->addAttributeMatrix(amSrcAttributeMatrix->getName(), amSrcAttributeMatrix); amSrcDataContainer->removeAttributeMatrix(amSrcAttributeMatrix->getName()); } else if (getWhatToMove() == k_MoveDataArray ) { AttributeMatrix::Pointer daSrcAttributeMatrix = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, daSrcPath, -301); AttributeMatrix::Pointer daDestAttributeMatrix = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, amDestPath, -301); IDataArray::Pointer daSrcDataArray = getDataContainerArray()->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(this, daSrcPath); if(getErrorCondition() < 0) { return; } if (daDestAttributeMatrix->getNumTuples() != daSrcDataArray->getNumberOfTuples()) { setErrorCondition(-11019); QString ss = QObject::tr("The number of tuples of source Attribute Array (%1) and destination Attribute Matrix (%2) do not match").arg(daSrcDataArray->getNumberOfTuples()).arg(daDestAttributeMatrix->getNumTuples()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } else if (amSrcPath == amDestPath) { QString ss = QObject::tr("The source and destination Attribute Matrix are the same. Is this what you meant to do?"); notifyWarningMessage(getHumanLabel(), ss, getErrorCondition()); return; } daDestAttributeMatrix->addAttributeArray(daSrcPath.getDataArrayName(), daSrcDataArray); daSrcAttributeMatrix->removeAttributeArray(daSrcPath.getDataArrayName()); } else { setErrorCondition(-11020); QString ss = QObject::tr("Neither an Attribute Matrix nor an Attribute Array was selected to be moved"); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeResolution::preflight() { setInPreflight(true); emit preflightAboutToExecute(); emit updateFilterParameters(this); dataCheck(); if (getErrorCondition() < 0) { emit preflightExecuted(); setInPreflight(false); return; } DataContainer::Pointer m; if (m_SaveAsNewDataContainer == false) { m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName()); } else { m = getDataContainerArray()->getDataContainer(getNewDataContainerName()); } size_t dims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->getDimensions(dims); float sizex = (dims[0]) * m->getGeometryAs<ImageGeom>()->getXRes(); float sizey = (dims[1]) * m->getGeometryAs<ImageGeom>()->getYRes(); float sizez = (dims[2]) * m->getGeometryAs<ImageGeom>()->getZRes(); size_t m_XP = size_t(sizex / m_Resolution.x); size_t m_YP = size_t(sizey / m_Resolution.y); size_t m_ZP = size_t(sizez / m_Resolution.z); if (m_XP == 0) { m_XP = 1; } if (m_YP == 0) { m_YP = 1; } if (m_ZP == 0) { m_ZP = 1; } m->getGeometryAs<ImageGeom>()->setDimensions(m_XP, m_YP, m_ZP); m->getGeometryAs<ImageGeom>()->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); QVector<size_t> tDims(3, 0); tDims[0] = m_XP; tDims[1] = m_YP; tDims[2] = m_ZP; m->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName())->setTupleDimensions(tDims); if (m_RenumberFeatures == true) { AttributeMatrix::Pointer cellFeatureAttrMat = m->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName()); QVector<bool> activeObjects(cellFeatureAttrMat->getNumTuples(), true); cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock()); } emit preflightExecuted(); setInPreflight(false); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CombineAttributeMatrices::execute() { setErrorCondition(0); dataCheck(); if (getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getFirstAttributeMatrixPath().getDataContainerName()); AttributeMatrix::Pointer firstAttrMat = m->getAttributeMatrix(getFirstAttributeMatrixPath().getAttributeMatrixName()); AttributeMatrix::Pointer secondAttrMat = m->getAttributeMatrix(getSecondAttributeMatrixPath().getAttributeMatrixName()); AttributeMatrix::Pointer combinedAttrMat = m->getAttributeMatrix(getCombinedAttributeMatrixName()); size_t firstAttrMatNumTuples = firstAttrMat->getNumTuples(); size_t totalTuples1 = m_SecondIndexPtr.lock()->getNumberOfTuples(); size_t totalTuples2 = m_SecondIndexPtr.lock()->getNumberOfTuples(); for (size_t i = 0; i < totalTuples1; i++) { if (m_FirstIndex > 0) { m_NewIndex[i] = m_FirstIndex[i]; } } for (size_t i = 0; i < totalTuples2; i++) { //subtract 1 from the index plus numTuples because the second index should be shifted to account for the zeroth tuple (all AMs above element start at tuple 1) if (m_SecondIndex[i] > 0 && m_NewIndex[i] == 0) m_NewIndex[i] = m_SecondIndex[i] + firstAttrMatNumTuples - 1; else if (m_SecondIndex[i] > 0 && m_NewIndex[i] != 0) { QString ss = QObject::tr("When copying the indices, the indices of the two attribute matrices overlapped. The index of the first attribute matrix was kept."); notifyWarningMessage(getHumanLabel(), ss, -111); } } QList<QString> arrayNames = firstAttrMat->getAttributeArrayNames(); size_t location = 0; for (QList<QString>::iterator iter = arrayNames.begin(); iter != arrayNames.end(); ++iter) { IDataArray::Pointer fromDataArray = firstAttrMat->getAttributeArray(*iter); IDataArray::Pointer toDataArray = combinedAttrMat->getAttributeArray(*iter); EXECUTE_FUNCTION_TEMPLATE(this, copyData, fromDataArray, fromDataArray, toDataArray, location); } arrayNames.clear(); arrayNames = secondAttrMat->getAttributeArrayNames(); location = firstAttrMatNumTuples; for (QList<QString>::iterator iter = arrayNames.begin(); iter != arrayNames.end(); ++iter) { IDataArray::Pointer fromDataArray = secondAttrMat->getAttributeArray(*iter); IDataArray::Pointer toDataArray = combinedAttrMat->getAttributeArray(*iter); EXECUTE_FUNCTION_TEMPLATE(this, copyData, fromDataArray, fromDataArray, toDataArray, location); } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VertexGeom::addAttributeMatrix(const QString& name, AttributeMatrix::Pointer data) { if (data->getType() != 0) { // VertexGeom can only accept vertex Attribute Matrices return; } if (data->getNumTuples() != getNumberOfElements()) { return; } if (data->getName().compare(name) != 0) { data->setName(name); } m_AttributeMatrices[name] = data; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void MinNeighbors::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } // If running on a single phase, validate that the user has not entered a phase number // that is not in the system ; the filter would not crash otherwise, but the user should // be notified of unanticipated behavior ; this cannot be done in the dataCheck since // we don't have acces to the data yet if (m_ApplyToSinglePhase == true) { AttributeMatrix::Pointer featAttrMat = getDataContainerArray()->getDataContainer(getFeaturePhasesArrayPath().getDataContainerName())->getAttributeMatrix(getFeaturePhasesArrayPath().getAttributeMatrixName()); size_t numFeatures = featAttrMat->getNumTuples(); bool unavailablePhase = true; for (size_t i = 0; i < numFeatures; i++) { if (m_FeaturePhases[i] == m_PhaseNumber) { unavailablePhase = false; break; } } if (unavailablePhase == true) { QString ss = QObject::tr("The phase number (%1) is not available in the supplied Feature phases array with path (%2)").arg(m_PhaseNumber).arg(m_FeaturePhasesArrayPath.serialize()); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } } QVector<bool> activeObjects = merge_containedfeatures(); if(getErrorCondition() < 0) { return; } assign_badpoints(); DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_NumNeighborsArrayPath.getDataContainerName()); AttributeMatrix::Pointer cellFeatureAttrMat = m->getAttributeMatrix(m_NumNeighborsArrayPath.getAttributeMatrixName()); cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock()); // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }
int32_t readDataChunk(AttributeMatrix::Pointer attrMat, std::istream& in, bool inPreflight, bool binary, const QString& scalarName, int32_t scalarNumComp) { size_t numTuples = attrMat->getNumTuples(); QVector<size_t> tDims = attrMat->getTupleDimensions(); QVector<size_t> cDims(1, scalarNumComp); typename DataArray<T>::Pointer data = DataArray<T>::CreateArray(tDims, cDims, scalarName, !inPreflight); data->initializeWithZeros(); attrMat->addAttributeArray(data->getName(), data); if (inPreflight == true) { return skipVolume<T>(in, binary, numTuples * scalarNumComp); } else { if (binary) { int32_t err = vtkReadBinaryData<T>(in, data->getPointer(0), numTuples, scalarNumComp); if( err < 0 ) { std::cout << "Error Reading Binary Data '" << scalarName.toStdString() << "' " << attrMat->getName().toStdString() << " numTuples = " << numTuples << std::endl; return err; } if(BIGENDIAN == 0) {data->byteSwapElements(); } } else { T value = static_cast<T>(0.0); size_t totalSize = numTuples * scalarNumComp; for (size_t i = 0; i < totalSize; ++i) { in >> value; data->setValue(i, value); } } } return 0; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void NearestPointFuseRegularGrids::dataCheck() { setErrorCondition(0); getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getReferenceCellAttributeMatrixPath().getDataContainerName()); getDataContainerArray()->getPrereqGeometryFromDataContainer<ImageGeom, AbstractFilter>(this, getSamplingCellAttributeMatrixPath().getDataContainerName()); AttributeMatrix::Pointer refAttrMat = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getReferenceCellAttributeMatrixPath(), -301); AttributeMatrix::Pointer sampleAttrMat = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, getSamplingCellAttributeMatrixPath(), -301); if(getErrorCondition() < 0) { return; } // Create arrays on the reference grid to hold data present on the sampling grid QList<QString> voxelArrayNames = sampleAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = sampleAttrMat->getAttributeArray(*iter); // Make a copy of the 'p' array that has the same name. When placed into // the data container this will over write the current array with // the same name. At least in theory IDataArray::Pointer data = p->createNewArray(refAttrMat->getNumTuples(), p->getComponentDimensions(), p->getName()); refAttrMat->addAttributeArray(p->getName(), data); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeResolution::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m; if(m_SaveAsNewDataContainer == false) { m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName()); } else { m = getDataContainerArray()->getDataContainer(getNewDataContainerName()); } if(m->getGeometryAs<ImageGeom>()->getXRes() == m_Resolution.x && m->getGeometryAs<ImageGeom>()->getYRes() == m_Resolution.y && m->getGeometryAs<ImageGeom>()->getZRes() == m_Resolution.z) { return; } AttributeMatrix::Pointer cellAttrMat = m->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName()); size_t dims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->getDimensions(dims); float sizex = (dims[0]) * m->getGeometryAs<ImageGeom>()->getXRes(); float sizey = (dims[1]) * m->getGeometryAs<ImageGeom>()->getYRes(); float sizez = (dims[2]) * m->getGeometryAs<ImageGeom>()->getZRes(); size_t m_XP = size_t(sizex / m_Resolution.x); size_t m_YP = size_t(sizey / m_Resolution.y); size_t m_ZP = size_t(sizez / m_Resolution.z); if (m_XP == 0) { m_XP = 1; } if (m_YP == 0) { m_YP = 1; } if (m_ZP == 0) { m_ZP = 1; } size_t totalPoints = m_XP * m_YP * m_ZP; float x = 0.0f, y = 0.0f, z = 0.0f; size_t col = 0, row = 0, plane = 0; size_t index; size_t index_old; std::vector<size_t> newindicies(totalPoints); for (size_t i = 0; i < m_ZP; i++) { QString ss = QObject::tr("Changing Resolution - %1 Percent Complete").arg(((float)i / m->getGeometryAs<ImageGeom>()->getZPoints()) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); for (size_t j = 0; j < m_YP; j++) { for (size_t k = 0; k < m_XP; k++) { x = (k * m_Resolution.x); y = (j * m_Resolution.y); z = (i * m_Resolution.z); col = size_t(x / m->getGeometryAs<ImageGeom>()->getXRes()); row = size_t(y / m->getGeometryAs<ImageGeom>()->getYRes()); plane = size_t(z / m->getGeometryAs<ImageGeom>()->getZRes()); index_old = (plane * m->getGeometryAs<ImageGeom>()->getXPoints() * m->getGeometryAs<ImageGeom>()->getYPoints()) + (row * m->getGeometryAs<ImageGeom>()->getXPoints()) + col; index = (i * m_XP * m_YP) + (j * m_XP) + k; newindicies[index] = index_old; } } } QVector<size_t> tDims(3, 0); tDims[0] = m_XP; tDims[1] = m_YP; tDims[2] = m_ZP; AttributeMatrix::Pointer newCellAttrMat = AttributeMatrix::New(tDims, cellAttrMat->getName(), cellAttrMat->getType()); QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = cellAttrMat->getAttributeArray(*iter); // Make a copy of the 'p' array that has the same name. When placed into // the data container this will over write the current array with // the same name. At least in theory. IDataArray::Pointer data = p->createNewArray(p->getNumberOfTuples(), p->getComponentDimensions(), p->getName()); data->resize(totalPoints); void* source = NULL; void* destination = NULL; size_t newIndicies_I = 0; int nComp = data->getNumberOfComponents(); for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++) { newIndicies_I = newindicies[i]; source = p->getVoidPointer((nComp * newIndicies_I)); destination = data->getVoidPointer((data->getNumberOfComponents() * i)); ::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents()); } cellAttrMat->removeAttributeArray(*iter); newCellAttrMat->addAttributeArray(*iter, data); } m->getGeometryAs<ImageGeom>()->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); m->getGeometryAs<ImageGeom>()->setDimensions(m_XP, m_YP, m_ZP); m->removeAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName()); m->addAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName(), newCellAttrMat); // Feature Ids MUST already be renumbered. if (m_RenumberFeatures == true) { totalPoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements(); AttributeMatrix::Pointer cellFeatureAttrMat = m->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName()); size_t totalFeatures = cellFeatureAttrMat->getNumTuples(); QVector<bool> activeObjects(totalFeatures, false); if (0 == totalFeatures) { notifyErrorMessage(getHumanLabel(), "The number of Features is 0 and should be greater than 0", -600); return; } updateCellInstancePointers(); // Find the unique set of feature ids for (size_t i = 0; i < totalPoints; ++i) { activeObjects[m_FeatureIds[i]] = true; } cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock()); } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void 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 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); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t FeatureInfoReader::readFile() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return getErrorCondition(); } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); AttributeMatrix::Pointer cellFeatureAttrMat = m->getAttributeMatrix(getCellFeatureAttributeMatrixName()); std::ifstream inFile; inFile.open(getInputFile().toLatin1().data(), std::ios_base::binary); if (!inFile) { QString ss = QObject::tr("Error opening input file: %1").arg(getInputFile()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } int32_t numfeatures = 0; int32_t gnum = 0, phase = 0; int32_t maxphase = 0; float ea1 = 0.0f, ea2 = 0.0f, ea3 = 0.0f; inFile >> numfeatures; if (0 == numfeatures) { QString ss = QObject::tr("The number of Features (%1) specified in the file must be greater than zero").arg(numfeatures); setErrorCondition(-600); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); int32_t maxFeatureId = 0; for (size_t i = 0; i < totalPoints; i++) { if (m_FeatureIds[i] > maxFeatureId) { maxFeatureId = m_FeatureIds[i]; } } if (numfeatures != maxFeatureId) { QString ss = QObject::tr("The number of Features (%1) specified in the file does not correspond to the maximum Feature Id (%2) in the selected Feature Ids array").arg(numfeatures).arg(maxFeatureId); setErrorCondition(-600); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } QVector<size_t> tDims(1, numfeatures + 1); cellFeatureAttrMat->setTupleDimensions(tDims); updateFeatureInstancePointers(); for (int32_t i = 0; i < numfeatures; i++) { inFile >> gnum >> phase >> ea1 >> ea2 >> ea3; if (gnum > maxFeatureId) { QString ss = QObject::tr("A Feature Id (%1) specified in the file is larger than the maximum Feature Id (%2) in the selected Feature Ids array").arg(numfeatures).arg(maxFeatureId); setErrorCondition(-600); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } m_FeatureEulerAngles[3 * gnum] = ea1; m_FeatureEulerAngles[3 * gnum + 1] = ea2; m_FeatureEulerAngles[3 * gnum + 2] = ea3; m_FeaturePhases[gnum] = phase; if (phase > maxphase) { maxphase = phase; } } if (m_CreateCellLevelArrays == true) { for (size_t i = 0; i < totalPoints; i++) { gnum = m_FeatureIds[i]; m_CellEulerAngles[3 * i] = m_FeatureEulerAngles[3 * gnum]; m_CellEulerAngles[3 * i + 1] = m_FeatureEulerAngles[3 * gnum + 1]; m_CellEulerAngles[3 * i + 2] = m_FeatureEulerAngles[3 * gnum + 2]; m_CellPhases[i] = m_FeaturePhases[gnum]; } } if (m_RenumberFeatures == true) { size_t totalFeatures = cellFeatureAttrMat->getNumTuples(); // Find the unique set of feature ids QVector<bool> activeObjects(totalFeatures, false); for (size_t i = 0; i < totalPoints; ++i) { activeObjects[m_FeatureIds[i]] = true; } cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock()); } notifyStatusMessage(getHumanLabel(), "Complete"); return 0; }