/** * @brief readH5Data * @param parentId * @return */ virtual int readH5Data(hid_t parentId) { int err = 0; this->resize(0); std::vector<std::string> strings; err = H5Lite::readVectorOfStringDataset(parentId, getName().toStdString(), strings); m_Array.resize(strings.size()); for(std::vector<QString>::size_type i = 0; i < strings.size(); i++) { m_Array[i] = QString::fromStdString(strings[i]); } #if 0 IDataArray::Pointer p = H5DataArrayReader::ReadStringDataArray(parentId, getName()); if (p.get() == NULL) { return -1; } StringDataArray* srcPtr = StringDataArray::SafePointerDownCast(p.get()); size_t count = srcPtr->getNumberOfTuples(); for (size_t i = 0; i < count; ++i) { m_Array.push_back( srcPtr->getValue(i) ); } #endif return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FlattenImage::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); //int err = 0; int numImageComp = 1; IDataArray::Pointer iDataArray = m->getCellData(m_ImageDataArrayName); if(NULL != iDataArray.get()) { UInt8ArrayType* imageDataPtr = UInt8ArrayType::SafePointerDownCast(iDataArray.get()); if (NULL != imageDataPtr) { numImageComp = imageDataPtr->GetNumberOfComponents(); } } GET_PREREQ_DATA(m, DREAM3D, CellData, ImageData, ss, -301, unsigned char, UCharArrayType, voxels, numImageComp) // if(err == -301) // { // setErrorCondition(0); // err = 0; // GET_PREREQ_DATA(m, DREAM3D, CellData, ImageData, ss, -302, unsigned char, UCharArrayType, voxels, 3) // } CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, FlatImageData, ss, int32_t, Int32ArrayType, 0, voxels, 1) }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FlattenImage::dataCheck() { setErrorCondition(0); DataArrayPath tempPath; int32_t numImageComp = 1; IDataArray::Pointer iDataArray = getDataContainerArray()->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(this, getImageDataArrayPath()); if (getErrorCondition() < 0) { return; } if (NULL != iDataArray.get()) { numImageComp = iDataArray->getNumberOfComponents(); } QVector<size_t> cDims(1, numImageComp); m_ImageDataPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<uint8_t>, AbstractFilter>(this, getImageDataArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_ImageDataPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_ImageData = m_ImageDataPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 1; tempPath.update(m_ImageDataArrayPath.getDataContainerName(), m_ImageDataArrayPath.getAttributeMatrixName(), getFlatImageDataArrayName() ); m_FlatImageDataPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<uint8_t>, AbstractFilter, uint8_t>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_FlatImageDataPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FlatImageData = m_FlatImageDataPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
void writePointScalarData(DataContainer::Pointer dc, const QString& vertexAttributeMatrixName, const QString& dataName, const QString& dataType, bool writeBinaryData, FILE* vtkFile, int nT) { IDataArray::Pointer data = dc->getAttributeMatrix(vertexAttributeMatrixName)->getAttributeArray(dataName); QString ss; if (NULL != data.get()) { T* m = reinterpret_cast<T*>(data->getVoidPointer(0)); fprintf(vtkFile, "\n"); fprintf(vtkFile, "SCALARS %s %s\n", dataName.toLatin1().data(), dataType.toLatin1().data()); fprintf(vtkFile, "LOOKUP_TABLE default\n"); for(int i = 0; i < nT; ++i) { T swapped = 0x00; if(writeBinaryData == true) { swapped = static_cast<T>(m[i]); SIMPLib::Endian::FromSystemToBig::convert(swapped); fwrite(&swapped, sizeof(T), 1, vtkFile); } else { ss = QString::number(m[i]) + " "; fprintf(vtkFile, "%s ", ss.toLatin1().data()); //if (i%50 == 0) { fprintf(vtkFile, "\n"); } } } } }
void findHistogram(IDataArray::Pointer inputData, int32_t* ensembleArray, int32_t* eIds, int NumberOfBins, bool removeBiasedFeatures, bool* biasedFeatures) { DataArray<T>* featureArray = DataArray<T>::SafePointerDownCast(inputData.get()); if (NULL == featureArray) { return; } T* fPtr = featureArray->getPointer(0); size_t numfeatures = featureArray->getNumberOfTuples(); int32_t bin; int32_t ensemble; float min = 1000000.0f; float max = 0.0f; float value; for (size_t i = 1; i < numfeatures; i++) { value = fPtr[i]; if(value > max) { max = value; } if(value < min) { min = value; } } float stepsize = (max - min) / NumberOfBins; for (size_t i = 1; i < numfeatures; i++) { if(removeBiasedFeatures == false || biasedFeatures[i] == false) { ensemble = eIds[i]; bin = (fPtr[i] - min) / stepsize; if(bin >= NumberOfBins) { bin = NumberOfBins - 1; } ensembleArray[(NumberOfBins * ensemble) + bin]++; } } }
/** * @brief * @param parentId * @return */ virtual int readH5Data(hid_t parentId) { int err = 0; resize(0); IDataArray::Pointer p = H5DataArrayReader::ReadIDataArray(parentId, getName()); if (p.get() == NULL) { return -1; } m_Array = reinterpret_cast<T*>(p->getVoidPointer(0)); m_Size = p->getSize(); m_OwnsData = true; m_MaxId = (m_Size == 0) ? 0 : m_Size - 1; m_IsAllocated = true; m_Name = p->getName(); m_NumTuples = p->getNumberOfTuples(); m_CompDims = p->getComponentDimensions(); m_NumComponents = p->getNumberOfComponents(); // Tell the intermediate DataArray to release ownership of the data as we are going to be responsible // for deleting the memory p->releaseOwnership(); return err; }
void writeCellScalarData(DataContainer::Pointer dc, const QString& faceAttributeMatrixName, const QString& dataName, const QString& dataType, bool writeBinaryData, FILE* vtkFile, QMap<int32_t, int32_t>& featureIds, int32_t* m_SurfaceMeshFaceLabels) { TriangleGeom::Pointer triangleGeom = dc->getGeometryAs<TriangleGeom>(); int64_t numTriangles = triangleGeom->getNumberOfTris(); IDataArray::Pointer data = dc->getAttributeMatrix(faceAttributeMatrixName)->getAttributeArray(dataName); QString ss; if (NULL != data.get()) { int32_t totalCellsWritten = 0; T* m = reinterpret_cast<T*>(data->getVoidPointer(0)); fprintf(vtkFile, "\n"); fprintf(vtkFile, "SCALARS %s %s 1\n", dataName.toLatin1().data(), dataType.toLatin1().data()); fprintf(vtkFile, "LOOKUP_TABLE default\n"); // Loop over all the features for(QMap<int32_t, int32_t>::iterator featureIter = featureIds.begin(); featureIter != featureIds.end(); ++featureIter) { int32_t gid = featureIter.key(); // The current Feature Id size_t size = featureIter.value(); // The number of triangles for this feature id std::vector<T> buffer(size, 0); totalCellsWritten += size; size_t index = 0; for (int j = 0; j < numTriangles; j++) { if (m_SurfaceMeshFaceLabels[j * 2] != gid && m_SurfaceMeshFaceLabels[j * 2 + 1] != gid) { continue; } // Get the data T s0 = static_cast<T>(m[j]); if (m_SurfaceMeshFaceLabels[j * 2 + 1] == gid) { s0 = s0 * -1; } // Write the values to the buffer after an Endian swap. if(writeBinaryData == true) { SIMPLib::Endian::FromSystemToBig::convert(s0); buffer[index] = s0; ++index; } else { ss = QString::number(s0); fprintf(vtkFile, "%s\n", ss.toLatin1().data()); } } // Write the Buffer if(writeBinaryData == true) { fwrite(&(buffer.front()), sizeof(T), size, vtkFile); } } } }
void writeCellNormalData(DataContainer::Pointer dc, const QString& faceAttributeMatrixName, const QString& dataName, const QString& dataType, bool writeBinaryData, bool writeConformalMesh, FILE* vtkFile, int nT) { IDataArray::Pointer data = dc->getAttributeMatrix(faceAttributeMatrixName)->getAttributeArray(dataName); QString buf; QTextStream ss(&buf); if (NULL != data.get()) { T* m = reinterpret_cast<T*>(data->getVoidPointer(0)); fprintf(vtkFile, "\n"); fprintf(vtkFile, "NORMALS %s %s\n", dataName.toLatin1().data(), dataType.toLatin1().data()); for(int i = 0; i < nT; ++i) { T s0 = 0x00; T s1 = 0x00; T s2 = 0x00; if(writeBinaryData == true) { s0 = static_cast<T>(m[i * 3 + 0]); s1 = static_cast<T>(m[i * 3 + 1]); s2 = static_cast<T>(m[i * 3 + 2]); SIMPLib::Endian::FromSystemToBig::convert(s0); SIMPLib::Endian::FromSystemToBig::convert(s1); SIMPLib::Endian::FromSystemToBig::convert(s2); fwrite(&s0, sizeof(T), 1, vtkFile); fwrite(&s1, sizeof(T), 1, vtkFile); fwrite(&s2, sizeof(T), 1, vtkFile); if(false == writeConformalMesh) { s0 = static_cast<T>(m[i * 3 + 0]) * -1.0; s1 = static_cast<T>(m[i * 3 + 1]) * -1.0; s2 = static_cast<T>(m[i * 3 + 2]) * -1.0; SIMPLib::Endian::FromSystemToBig::convert(s0); SIMPLib::Endian::FromSystemToBig::convert(s1); SIMPLib::Endian::FromSystemToBig::convert(s2); fwrite(&s0, sizeof(T), 1, vtkFile); fwrite(&s1, sizeof(T), 1, vtkFile); fwrite(&s2, sizeof(T), 1, vtkFile); } } else { ss << m[i * 3 + 0] << " " << m[i * 3 + 1] << " " << m[i * 3 + 2] << " "; if(false == writeConformalMesh) { ss << -1.0 * m[i * 3 + 0] << " " << -1.0 * m[i * 3 + 1] << " " << -1.0 * m[i * 3 + 2] << " "; } fprintf(vtkFile, "%s ", buf.toLatin1().data()); buf.clear(); if (i % 50 == 0) { fprintf(vtkFile, "\n"); } } } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int AttributeMatrix::readAttributeArraysFromHDF5(hid_t amGid, bool preflight, AttributeMatrixProxy& attrMatProxy) { int err = 0; QMap<QString, DataArrayProxy> dasToRead = attrMatProxy.dataArrays; QString classType; for (QMap<QString, DataArrayProxy>::iterator iter = dasToRead.begin(); iter != dasToRead.end(); ++iter) { //qDebug() << "Reading the " << iter->name << " Array from the " << m_Name << " Attribute Matrix \n"; if(iter->flag == DREAM3D::Unchecked) { continue; } QH5Lite::readStringAttribute(amGid, iter->name, DREAM3D::HDF5::ObjectType, classType); // qDebug() << groupName << " Array: " << *iter << " with C++ ClassType of " << classType << "\n"; IDataArray::Pointer dPtr = IDataArray::NullPointer(); if(classType.startsWith("DataArray") == true) { dPtr = H5DataArrayReader::ReadIDataArray(amGid, iter->name, preflight); } else if(classType.compare("StringDataArray") == 0) { dPtr = H5DataArrayReader::ReadStringDataArray(amGid, iter->name, preflight); } else if(classType.compare("vector") == 0) { } else if(classType.compare("NeighborList<T>") == 0) { dPtr = H5DataArrayReader::ReadNeighborListData(amGid, iter->name, preflight); } else if(classType.compare("Statistics") == 0) { StatsDataArray::Pointer statsData = StatsDataArray::New(); statsData->setName(iter->name); statsData->readH5Data(amGid); dPtr = statsData; } // else if ( (iter->name).compare(DREAM3D::EnsembleData::Statistics) == 0) // { // StatsDataArray::Pointer statsData = StatsDataArray::New(); // statsData->setName(DREAM3D::EnsembleData::Statistics); // statsData->readH5Data(amGid); // dPtr = statsData; // } if (NULL != dPtr.get()) { addAttributeArray(dPtr->getName(), dPtr); } } H5Gclose(amGid); // Close the Cell Group return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int AttributeMatrix::addAttributeArrayFromHDF5Path(hid_t gid, QString name, bool preflight) { int err = 0; QString classType; QH5Lite::readStringAttribute(gid, name, DREAM3D::HDF5::ObjectType, classType); // qDebug() << groupName << " Array: " << *iter << " with C++ ClassType of " << classType << "\n"; IDataArray::Pointer dPtr = IDataArray::NullPointer(); if(classType.startsWith("DataArray") == true) { dPtr = H5DataArrayReader::ReadIDataArray(gid, name, preflight); if(preflight == true) { dPtr->resize(getNumTuples()); } } else if(classType.compare("StringDataArray") == 0) { dPtr = H5DataArrayReader::ReadStringDataArray(gid, name, preflight); if (preflight == true) { dPtr->resize(getNumTuples()); } } else if(classType.compare("vector") == 0) { } else if(classType.compare("NeighborList<T>") == 0) { dPtr = H5DataArrayReader::ReadNeighborListData(gid, name, preflight); if (preflight == true) { dPtr->resize(getNumTuples()); } } else if ( name.compare(DREAM3D::EnsembleData::Statistics) == 0) { StatsDataArray::Pointer statsData = StatsDataArray::New(); statsData->setName(DREAM3D::EnsembleData::Statistics); statsData->readH5Data(gid); dPtr = statsData; if (preflight == true) { dPtr->resize(getNumTuples()); } } if (NULL != dPtr.get()) { addAttributeArray(dPtr->getName(), dPtr); } return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VisualizeGBCDPoleFigure::dataCheck() { setErrorCondition(0); getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getGBCDArrayPath().getDataContainerName()); if (getOutputFile().isEmpty() == true) { QString ss = QObject::tr( "The output file must be set"); setErrorCondition(-1000); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } QFileInfo fi(getOutputFile()); QDir parentPath = fi.path(); if (parentPath.exists() == false && getInPreflight()) { QString ss = QObject::tr( "The directory path for the output file does not exist. DREAM.3D will attempt to create this path during execution of the filter"); notifyWarningMessage(getHumanLabel(), ss, -1); } if (fi.suffix().compare("") == 0) { setOutputFile(getOutputFile().append(".vtk")); } QVector<size_t> cDims(1, 1); 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 */ IDataArray::Pointer tmpGBCDPtr = getDataContainerArray()->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(this, getGBCDArrayPath()); if(getErrorCondition() < 0) { return; } if (NULL != tmpGBCDPtr.get()) { QVector<size_t> cDims = tmpGBCDPtr->getComponentDimensions(); m_GBCDPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<double>, AbstractFilter>(this, getGBCDArrayPath(), 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 */ } if (NULL != m_GBCDPtr.lock().get() && getPhaseOfInterest() >= m_GBCDPtr.lock()->getNumberOfTuples()) { QString ss = QObject::tr("The phase index is larger than the number of Ensembles").arg(ClassName()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LinkFieldMapToCellArray::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); IDataArray::Pointer data = m->getCellData(m_SelectedCellDataArrayName); if (NULL == data.get()) { ss.str(""); ss << "Selected array '" << m_SelectedCellDataArrayName << "' does not exist in the Voxel Data Container. Was it spelled correctly?"; setErrorCondition(-11001); addErrorMessage(getHumanLabel(),ss.str(),getErrorCondition()); return; } std::string dType = data->getTypeAsString(); IDataArray::Pointer p = IDataArray::NullPointer(); if (dType.compare("int32_t") == 0) { DataArray<int32_t>* field = DataArray<int32_t>::SafePointerDownCast(data.get()); m_SelectedCellData = field->GetPointer(0); } else { ss.str(""); ss << "Selected array '" << m_SelectedCellDataArrayName << "' is not an Integer array. Is this the array you want to use?"; setErrorCondition(-11001); addErrorMessage(getHumanLabel(),ss.str(),getErrorCondition()); return; } m->clearFieldData(); BoolArrayType::Pointer active = BoolArrayType::CreateArray(fields, 1, DREAM3D::FieldData::Active); // bool* mActive = m_Active->GetPointer(0); m->addFieldData(DREAM3D::FieldData::Active, active); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- std::vector<int32_t> TriangleOps::findAdjacentTriangles(SurfaceMeshDataContainer* sm, int32_t triangleIndex, int32_t label) { std::vector<int32_t> adjacentTris; // Get the master list of triangles for the mesh DREAM3D::SurfaceMesh::FaceList_t::Pointer facesPtr = sm->getFaces(); // DREAM3D::SurfaceMesh::Face_t* faces = facesPtr->GetPointer(0); IDataArray::Pointer flPtr = sm->getFaceData(DREAM3D::FaceData::SurfaceMeshFaceLabels); DataArray<int32_t>* faceLabelsPtr = DataArray<int32_t>::SafePointerDownCast(flPtr.get()); int32_t* faceLabels = faceLabelsPtr->GetPointer(0); // Get the Triangle Neighbor Structure MeshFaceNeighbors::Pointer triNeighbors = sm->getMeshFaceNeighborLists(); // For the specific triangle that was passed, get its neighbor list uint16_t count = triNeighbors->getNumberOfFaces(triangleIndex); int32_t* nList = triNeighbors->getNeighborListPointer(triangleIndex); if (count < 3) { std::cout << "Triangle Neighbor List had only " << count << " neighbors. Must be at least 3." << std::endl; BOOST_ASSERT(false); } else if (count == 3) // This triangle only has 3 neighbors so we are assuming all three have the same label set. { for (uint16_t n = 0; n < count; ++n) { adjacentTris.push_back(nList[n]); } } else { // Iterate over the indices to find triangles that match the label and are NOT the current triangle index for (uint16_t n = 0; n < count; ++n) { int32_t fl_0 = faceLabels[nList[n]*2]; int32_t fl_1 = faceLabels[nList[n]*2 + 1]; if ( (fl_0 == label || fl_1 == label) && (nList[n] != triangleIndex) ) { // std::cout << " Found Adjacent Triangle: " << t->tIndex << std::endl; adjacentTris.push_back(nList[n]); // ++index; } } } return adjacentTris; }
/** * @brief copyData This method copies all data from the <b>sourceArray</b> into * the current array starting at the target destination tuple offset value. * * For example if the DataArray has 10 tuples and the destTupleOffset = 5 then * then source data will be copied into the destination array starting at * destination tuple 5. In psuedo code it would be the following: * @code * destArray[5] = sourceArray[0]; * destArray[6] = sourceArray[1]; * ..... * @endcode * @param destTupleOffset * @param sourceArray * @return */ bool copyData(size_t destTupleOffset, IDataArray::Pointer sourceArray) { if(destTupleOffset >= m_Array.size()) { return false; } if(!sourceArray->isAllocated()) { return false; } if(sourceArray->getNumberOfComponents() != getNumberOfComponents()) { return false; } Self* source = dynamic_cast<Self*>(sourceArray.get()); size_t sourceNTuples = source->getNumberOfTuples(); for(size_t i = 0; i < sourceNTuples; i++) { m_Array[destTupleOffset + i] = source->getValue(i); } return true; }
/** * @brief * @param parentId * @return */ virtual int readH5Data(hid_t parentId) { int err = 0; this->Resize(0); IDataArray::Pointer p = H5DataArrayReader::readIDataArray(parentId, GetName()); if (p.get() == NULL) { return -1; } this->NumberOfComponents = p->GetNumberOfComponents(); this->Size = p->GetSize(); this->MaxId = (Size == 0) ? 0 : Size -1; this->Array = reinterpret_cast<T*>(p->GetVoidPointer(0)); p->releaseOwnership(); return err; }
void writeCellVectorData(DataContainer::Pointer dc, const QString& faceAttributeMatrixName, const QString& dataName, const QString& dataType, bool writeBinaryData, const QString& vtkAttributeType, FILE* vtkFile, QMap<int32_t, int32_t>& featureIds) { TriangleGeom::Pointer triangleGeom = dc->getGeometryAs<TriangleGeom>(); int64_t numTriangles = triangleGeom->getNumberOfTris(); IDataArray::Pointer data = dc->getAttributeMatrix(faceAttributeMatrixName)->getAttributeArray(dataName); QString ss; if (NULL != data.get()) { T* m = reinterpret_cast<T*>(data->getVoidPointer(0)); fprintf(vtkFile, "\n"); fprintf(vtkFile, "%s %s %s\n", vtkAttributeType.toLatin1().data(), dataName.toLatin1().data(), dataType.toLatin1().data()); for(int i = 0; i < numTriangles; ++i) { T s0 = 0x00; T s1 = 0x00; T s2 = 0x00; if(writeBinaryData == true) { s0 = static_cast<T>(m[i * 3 + 0]); s1 = static_cast<T>(m[i * 3 + 1]); s2 = static_cast<T>(m[i * 3 + 2]); SIMPLib::Endian::FromSystemToBig::convert(s0); SIMPLib::Endian::FromSystemToBig::convert(s1); SIMPLib::Endian::FromSystemToBig::convert(s2); fwrite(&s0, sizeof(T), 1, vtkFile); fwrite(&s1, sizeof(T), 1, vtkFile); fwrite(&s2, sizeof(T), 1, vtkFile); } else { ss << m[i * 3 + 0] << " " << m[i * 3 + 1] << " " << m[i * 3 + 2] << " "; fprintf(vtkFile, "%s ", ss.toLatin1().data()); if (i % 25 == 0) { fprintf(vtkFile, "\n"); } } } } }
void writeCellScalarData(DataContainer::Pointer dc, const QString& faceAttributeMatrixName, const QString& dataName, const QString& dataType, bool writeBinaryData, bool writeConformalMesh, FILE* vtkFile, int nT) { // Write the Feature Face ID Data to the file IDataArray::Pointer data = dc->getAttributeMatrix(faceAttributeMatrixName)->getAttributeArray(dataName); QString buf; QTextStream ss(&buf); if (NULL != data.get()) { T* m = reinterpret_cast<T*>(data->getVoidPointer(0)); fprintf(vtkFile, "\n"); fprintf(vtkFile, "SCALARS %s %s 1\n", dataName.toLatin1().data(), dataType.toLatin1().data()); fprintf(vtkFile, "LOOKUP_TABLE default\n"); for(int i = 0; i < nT; ++i) { T swapped = 0x00; if(writeBinaryData == true) { swapped = static_cast<T>(m[i]); SIMPLib::Endian::FromSystemToBig::convert(swapped); fwrite(&swapped, sizeof(T), 1, vtkFile); if(false == writeConformalMesh) { fwrite(&swapped, sizeof(T), 1, vtkFile); } } else { ss << m[i] << " "; if(false == writeConformalMesh) { ss << m[i] << " "; } fprintf(vtkFile, "%s", buf.toLatin1().data()); buf.clear(); if (i % 50 == 0) { fprintf(vtkFile, "\n"); } } } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool ModifiedLambertProjectionArray::copyData(size_t destTupleOffset, IDataArray::Pointer sourceArray) { if(!m_IsAllocated) { return false; } if(0 == m_ModifiedLambertProjectionArray.size()) { return false; } if(destTupleOffset >= m_ModifiedLambertProjectionArray.size()) { return false; } if(!sourceArray->isAllocated()) { return false; } Self* source = dynamic_cast<Self*>(sourceArray.get()); if(sourceArray->getNumberOfComponents() != getNumberOfComponents()) { return false; } if( sourceArray->getNumberOfTuples()*sourceArray->getNumberOfComponents() + destTupleOffset*getNumberOfComponents() > m_ModifiedLambertProjectionArray.size() ) { return false; } size_t sourceNTuples = source->getNumberOfTuples(); for(size_t i = 0; i < sourceNTuples; i++) { m_ModifiedLambertProjectionArray[destTupleOffset + i] = (*source)[i]; } return true; }
void writePointVectorData(DataContainer::Pointer dc, const QString& vertexAttributeMatrixName, const QString& dataName, const QString& dataType, bool writeBinaryData, bool writeConformalMesh, const QString& vtkAttributeType, FILE* vtkFile, int nT) { IDataArray::Pointer data = dc->getAttributeMatrix(vertexAttributeMatrixName)->getAttributeArray(dataName); QString ss; if (NULL != data.get()) { T* m = reinterpret_cast<T*>(data->getVoidPointer(0)); fprintf(vtkFile, "\n"); fprintf(vtkFile, "%s %s %s\n", vtkAttributeType.toLatin1().data(), dataName.toLatin1().data(), dataType.toLatin1().data()); for(int i = 0; i < nT; ++i) { T s0 = 0x00; T s1 = 0x00; T s2 = 0x00; if(writeBinaryData == true) { s0 = static_cast<T>(m[i * 3 + 0]); s1 = static_cast<T>(m[i * 3 + 1]); s2 = static_cast<T>(m[i * 3 + 2]); SIMPLib::Endian::FromSystemToBig::convert(s0); SIMPLib::Endian::FromSystemToBig::convert(s1); SIMPLib::Endian::FromSystemToBig::convert(s2); fwrite(&s0, sizeof(T), 1, vtkFile); fwrite(&s1, sizeof(T), 1, vtkFile); fwrite(&s1, sizeof(T), 1, vtkFile); } else { ss = QString::number(m[i * 3 + 0]) + " " + QString::number(m[i * 3 + 1]) + " " + QString::number(m[i * 3 + 2]) + " "; fprintf(vtkFile, "%s ", ss.toLatin1().data()); //if (i%50 == 0) { fprintf(vtkFile, "\n"); } } } } }
static void PopulateAttributeArrayComboBox(AbstractFilter* filter, FilterParameter* filterParameter, QComboBox* dcCombo, QComboBox* amCombo, QComboBox* aaCombo, DataContainerArrayProxy& dcaProxy) { FilterParameterType* fp = dynamic_cast<FilterParameterType*>(filterParameter); assert(fp != NULL); DataContainerArray::Pointer dca = filter->getDataContainerArray(); if (NULL == dca.get()) { return; } bool alreadyBlocked = false; if(aaCombo->signalsBlocked()) { alreadyBlocked = true; } aaCombo->blockSignals(true); aaCombo->clear(); // Get the selected Data Container Name from the DataContainerList Widget QString currentDCName = dcCombo->currentText(); QString currentAttrMatName = amCombo->currentText(); // Loop over the data containers until we find the proper data container QList<DataContainerProxy> containers = dcaProxy.dataContainers.values(); QListIterator<DataContainerProxy> containerIter(containers); QVector<QString> daTypes = fp->getDefaultAttributeArrayTypes(); QVector< QVector<size_t> > cDims = fp->getDefaultComponentDimensions(); while (containerIter.hasNext()) { DataContainerProxy dc = containerIter.next(); if (dc.name.compare(currentDCName) == 0) { // We found the proper Data Container, now populate the AttributeMatrix List QMap<QString, AttributeMatrixProxy> attrMats = dc.attributeMatricies; QMapIterator<QString, AttributeMatrixProxy> attrMatsIter(attrMats); while (attrMatsIter.hasNext()) { attrMatsIter.next(); QString amName = attrMatsIter.key(); if (amName.compare(currentAttrMatName) == 0) { // Clear the list of arrays from the QListWidget aaCombo->clear(); // We found the selected AttributeMatrix, so loop over this attribute matrix arrays and populate the list widget AttributeMatrixProxy amProxy = attrMatsIter.value(); QMap<QString, DataArrayProxy> dataArrays = amProxy.dataArrays; QMapIterator<QString, DataArrayProxy> dataArraysIter(dataArrays); while (dataArraysIter.hasNext()) { dataArraysIter.next(); //DataArrayProxy daProxy = dataArraysIter.value(); QString daName = dataArraysIter.key(); IDataArray::Pointer da = dca->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(NULL, DataArrayPath(dc.name, amProxy.name, daName)); aaCombo->addItem(daName); if (NULL != da.get() && ((daTypes.isEmpty() == false && daTypes.contains(da->getTypeAsString()) == false) || (cDims.isEmpty() == false && cDims.contains(da->getComponentDimensions()) == false))) { QStandardItemModel* model = qobject_cast<QStandardItemModel*>(aaCombo->model()); if (NULL != model) { QStandardItem* item = model->item(aaCombo->findText(daName)); if (NULL != item) { item->setFlags(item->flags() & ~Qt::ItemIsEnabled); } } } } } } } aaCombo->setCurrentIndex(-1); if(alreadyBlocked == false) { aaCombo->blockSignals(false); } } }
void writeCellNormalData(DataContainer::Pointer dc, const QString& faceAttributeMatrixName, const QString& dataName, const QString& dataType, bool writeBinaryData, FILE* vtkFile, QMap<int32_t, int32_t>& featureIds, int32_t* m_SurfaceMeshFaceLabels) { TriangleGeom::Pointer triangleGeom = dc->getGeometryAs<TriangleGeom>(); int64_t numTriangles = triangleGeom->getNumberOfTris(); IDataArray::Pointer data = dc->getAttributeMatrix(faceAttributeMatrixName)->getAttributeArray(dataName); QString buf; QTextStream ss(&buf); if (NULL != data.get()) { int32_t totalCellsWritten = 0; T* m = reinterpret_cast<T*>(data->getVoidPointer(0)); fprintf(vtkFile, "\n"); fprintf(vtkFile, "NORMALS %s %s\n", dataName.toLatin1().data(), dataType.toLatin1().data()); // Loop over all the features for(QMap<int32_t, int32_t>::iterator featureIter = featureIds.begin(); featureIter != featureIds.end(); ++featureIter) { int32_t gid = featureIter.key(); // The current Feature Id size_t size = featureIter.value(); // The number of triangles for this feature id std::vector<T> buffer(size * 3, 0); totalCellsWritten += size * 3; size_t index = 0; for (int j = 0; j < numTriangles; j++) { if (m_SurfaceMeshFaceLabels[j * 2] != gid && m_SurfaceMeshFaceLabels[j * 2 + 1] != gid) { continue; } // Get the data T s0 = static_cast<T>(m[j * 3 + 0]); T s1 = static_cast<T>(m[j * 3 + 1]); T s2 = static_cast<T>(m[j * 3 + 2]); // Flip the normal if needed because the current feature id is assigned to the triangle.labels[1] if (m_SurfaceMeshFaceLabels[j * 2 + 1] == gid ) { s0 *= -1.0; s1 *= -1.0; s2 *= -1.0; } // Write the values to the buffer after an Endian swap. if(writeBinaryData == true) { SIMPLib::Endian::FromSystemToBig::convert(s0); buffer[index] = s0; ++index; SIMPLib::Endian::FromSystemToBig::convert(s1); buffer[index] = s1; ++index; SIMPLib::Endian::FromSystemToBig::convert(s2); buffer[index] = s2; ++index; } else { ss << s0 << " " << s1 << " " << s2; fprintf(vtkFile, "%s\n", buf.toLatin1().data()); buf.clear(); } } // Write the Buffer if(writeBinaryData == true) { fwrite(&(buffer.front()), sizeof(T), size * 3, vtkFile); } } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindFeatureHistogram::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_SelectedFeatureArrayPath.getDataContainerName()); QString ss; IDataArray::Pointer inputData = m->getAttributeMatrix(m_SelectedFeatureArrayPath.getAttributeMatrixName())->getAttributeArray(m_SelectedFeatureArrayPath.getDataArrayName()); if (NULL == inputData.get()) { ss = QObject::tr("Selected array '%1' does not exist in the Voxel Data Container. Was it spelled correctly?").arg(m_SelectedFeatureArrayPath.getDataArrayName()); setErrorCondition(-11001); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } QString dType = inputData->getTypeAsString(); IDataArray::Pointer p = IDataArray::NullPointer(); if (dType.compare("int8_t") == 0) { findHistogram<int8_t>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("uint8_t") == 0) { findHistogram<uint8_t>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("int16_t") == 0) { findHistogram<int16_t>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("uint16_t") == 0) { findHistogram<uint16_t>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("int32_t") == 0) { findHistogram<int32_t>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("uint32_t") == 0) { findHistogram<uint32_t>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("int64_t") == 0) { findHistogram<int64_t>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("uint64_t") == 0) { findHistogram<uint64_t>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("float") == 0) { findHistogram<float>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("double") == 0) { findHistogram<double>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } else if (dType.compare("bool") == 0) { findHistogram<bool>(inputData, m_NewEnsembleArray, m_FeaturePhases, m_NumberOfBins, m_RemoveBiasedFeatures, m_BiasedFeatures); } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- IDataArray::Pointer H5DataArrayReader::readStringDataArray(hid_t gid, const std::string &name, bool preflightOnly) { herr_t err = -1; herr_t retErr = 1; hid_t typeId = -1; H5T_class_t attr_type; size_t attr_size; std::string res; std::vector<hsize_t> dims; //Reusable for the loop IDataArray::Pointer ptr = IDataArray::NullPointer(); //std::cout << "Reading Attribute " << *iter << std::endl; typeId = H5Lite::getDatasetType(gid, name); if (typeId < 0) { return ptr; } err = H5Lite::getDatasetInfo(gid, name, dims, attr_type, attr_size); if(err < 0) { std::cout << "Error in getAttributeInfo method in readUserMetaData." << std::endl; } else { std::string classType; err = H5Lite::readStringAttribute(gid, name, DREAM3D::HDF5::ObjectType, classType); if (err < 0) { return ptr; } int numComp = 1; err = H5Lite::readScalarAttribute(gid, name, DREAM3D::HDF5::NumComponents, numComp); if (err < 0) { numComp = 1; } if(H5Tequal(typeId, H5T_STD_U8BE) || H5Tequal(typeId, H5T_STD_U8LE) || H5Tequal(typeId, H5T_STD_I8BE) || H5Tequal(typeId, H5T_STD_I8LE) ) { if (preflightOnly == false) { IDataArray::Pointer bufferPtr = Detail::readH5Dataset<char>(gid, name, dims); const char* buf = reinterpret_cast<char*>(bufferPtr->GetVoidPointer(0)); // count the number of 0x00 characters which are the 'null termination' of each string size_t size = bufferPtr->GetNumberOfTuples(); size_t count = 0; for(size_t i = 0; i < size; ++i) { if(buf[i] == 0) { ++count; } } ptr = StringDataArray::CreateArray(count, name); StringDataArray* strArray = StringDataArray::SafePointerDownCast(ptr.get()); size_t start = 0; size_t index = 0; for(size_t i = 0; i < size; ++i) { if(buf[i] == 0) { std::string str( &(buf[start]) ); strArray->SetValue(index, str); ++index; start = i + 1; } } } else // We are preflighting only so just create a StringDataArray of lenght 1 { ptr = StringDataArray::CreateArray(1, name); } } } CloseH5T(typeId, err, retErr); return ptr; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int VoxelDataContainerWriter::writeFieldData(hid_t dcGid) { std::stringstream ss; int err = 0; VoxelDataContainer* m = getVoxelDataContainer(); #if WRITE_FIELD_XDMF // Get the name of the .dream3d file that we are writing to: ssize_t nameSize = H5Fget_name(m_HdfFileId, NULL, 0) + 1; std::vector<char> nameBuffer(nameSize, 0); nameSize = H5Fget_name(m_HdfFileId, &(nameBuffer.front()), nameSize); std::string hdfFileName(&(nameBuffer.front()), nameSize); hdfFileName = MXAFileInfo::filename(hdfFileName); std::string xdmfGroupPath = std::string(":/") + VoxelDataContainer::ClassName() + std::string("/") + H5_FIELD_DATA_GROUP_NAME; #endif int64_t volDims[3] = { 0,0,0 }; // Write the Field Data err = H5Utilities::createGroupsFromPath(H5_FIELD_DATA_GROUP_NAME, dcGid); if(err < 0) { std::cout << "Error creating HDF Group " << H5_FIELD_DATA_GROUP_NAME << std::endl; return err; } err = H5Lite::writeStringAttribute(dcGid, H5_FIELD_DATA_GROUP_NAME, H5_NAME, H5_FIELD_DATA_DEFAULT); if(err < 0) { return err; } hid_t fieldGroupId = H5Gopen(dcGid, H5_FIELD_DATA_GROUP_NAME, H5P_DEFAULT); if(err < 0) { ss.str(""); ss << "Error opening field Group " << H5_FIELD_DATA_GROUP_NAME << std::endl; setErrorCondition(-65); notifyErrorMessage( ss.str(), err); H5Gclose(dcGid); // Close the Data Container Group return err; } size_t total = 0; typedef std::vector<IDataArray*> VectorOfIDataArrays_t; VectorOfIDataArrays_t neighborListArrays; NameListType names = m->getFieldArrayNameList(); if (names.size() > 0) { IDataArray::Pointer array = m->getFieldData(names.front()); total = array->GetSize(); volDims[0] = total; volDims[1] = 1; volDims[2] = 1; #if WRITE_FIELD_XDMF ss.str(""); ss << "Field Data (" << total << ")"; writeFieldXdmfGridHeader(total, ss.str()); #endif } // Now loop over all the field data and write it out, possibly wrapping it with XDMF code also. for (NameListType::iterator iter = names.begin(); iter != names.end(); ++iter) { IDataArray::Pointer array = m->getFieldData(*iter); if (array->getTypeAsString().compare(NeighborList<int>::ClassName()) == 0) { neighborListArrays.push_back(array.get()); } else if (NULL != array.get()) { err = array->writeH5Data(fieldGroupId); if(err < 0) { ss.str(""); ss << "Error writing field array '" << (*iter).c_str() << "' to the HDF5 File"; notifyErrorMessage( ss.str(), err); setErrorCondition(err); H5Gclose(fieldGroupId); // Close the Cell Group H5Gclose(dcGid); // Close the Data Container Group return err; } #if WRITE_FIELD_XDMF array->writeXdmfAttribute( *m_XdmfPtr, volDims, hdfFileName, xdmfGroupPath, " (Field)"); #endif } } #if WRITE_FIELD_XDMF if (names.size() > 0) { writeXdmfGridFooter("Field Data"); } #endif // Write the NeighborLists onto their own grid // We need to determine how many total elements we are going to end up with and group the arrays by // those totals so we can minimize the number of grids typedef std::map<size_t, VectorOfIDataArrays_t> SizeToIDataArrays_t; SizeToIDataArrays_t sizeToDataArrays; for(VectorOfIDataArrays_t::iterator iter = neighborListArrays.begin(); iter < neighborListArrays.end(); ++iter) { IDataArray* array = (*iter); sizeToDataArrays[array->GetSize()].push_back(array); } // Now loop over each pair in the map creating a section in the XDMF and also writing the data to the HDF5 file for(SizeToIDataArrays_t::iterator pair = sizeToDataArrays.begin(); pair != sizeToDataArrays.end(); ++pair) { total = (*pair).first; VectorOfIDataArrays_t& arrays = (*pair).second; volDims[0] = total; volDims[1] = 1; volDims[2] = 1; #if WRITE_FIELD_XDMF ss.str(""); ss << "Neighbor Data (" << total << ")"; writeFieldXdmfGridHeader(total, ss.str()); #endif for(VectorOfIDataArrays_t::iterator iter = arrays.begin(); iter < arrays.end(); ++iter) { err = (*iter)->writeH5Data(fieldGroupId); if(err < 0) { ss.str(""); ss << "Error writing neighbor list field array '" << (*iter)->GetName() << "' to the HDF5 File"; notifyErrorMessage( ss.str(), err); setErrorCondition(err); H5Gclose(fieldGroupId); // Close the Cell Group H5Gclose(dcGid); // Close the Data Container Group return err; } #if WRITE_FIELD_XDMF (*iter)->writeXdmfAttribute( *m_XdmfPtr, volDims, hdfFileName, xdmfGroupPath, " (Neighbor Data)"); #endif } #if WRITE_FIELD_XDMF writeXdmfGridFooter(ss.str()); #endif } H5Gclose(fieldGroupId); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CalculateTriangleGroupCurvatures::operator()() const { // Get the Triangles Array // DREAM3D::SurfaceMesh::FaceList_t::Pointer trianglesPtr = m_SurfaceMeshDataContainer->getFaces(); // DREAM3D::SurfaceMesh::Face_t* triangles = trianglesPtr->GetPointer(0); IDataArray::Pointer flPtr = m_SurfaceMeshDataContainer->getFaceData(DREAM3D::FaceData::SurfaceMeshFaceLabels); DataArray<int32_t>* faceLabelsPtr = DataArray<int32_t>::SafePointerDownCast(flPtr.get()); int32_t* faceLabels = faceLabelsPtr->GetPointer(0); // Instantiate a FindNRingNeighbors class to use during the loop FindNRingNeighbors::Pointer nRingNeighborAlg = FindNRingNeighbors::New(); // Make Sure we have triangle centroids calculated IDataArray::Pointer centroidPtr = m_SurfaceMeshDataContainer->getFaceData(DREAM3D::FaceData::SurfaceMeshFaceCentroids); if (NULL == centroidPtr.get()) { std::cout << "Triangle Centroids are required for this algorithm" << std::endl; return; } DataArray<double>* centroids = DataArray<double>::SafePointerDownCast(centroidPtr.get()); // Make sure we have triangle normals calculated IDataArray::Pointer normalPtr = m_SurfaceMeshDataContainer->getFaceData(DREAM3D::FaceData::SurfaceMeshFaceNormals); if (NULL == normalPtr.get()) { std::cout << "Triangle Normals are required for this algorithm" << std::endl; return; } DataArray<double>* normals = DataArray<double>::SafePointerDownCast(normalPtr.get()); int32_t* fl = faceLabels + m_TriangleIds[0] * 2; int grain0 = 0; int grain1 = 0; if (fl[0] < fl[1]) { grain0 = fl[0]; grain1 = fl[1]; } else { grain0 = fl[1]; grain1 = fl[0]; } bool computeGaussian = (m_GaussianCurvature.get() != NULL); bool computeMean = (m_MeanCurvature.get() != NULL); bool computeDirection = (m_PrincipleDirection1.get() != NULL); std::stringstream ss; std::vector<int>::size_type tCount = m_TriangleIds.size(); // For each triangle in the group for(std::vector<int>::size_type i = 0; i < tCount; ++i) { if (m_ParentFilter->getCancel() == true) { return; } int triId = m_TriangleIds[i]; nRingNeighborAlg->setTriangleId(triId); nRingNeighborAlg->setRegionId0(grain0); nRingNeighborAlg->setRegionId1(grain1); nRingNeighborAlg->setRing(m_NRing); nRingNeighborAlg->setSurfaceMeshDataContainer(m_SurfaceMeshDataContainer); nRingNeighborAlg->generate(); DREAM3D::SurfaceMesh::UniqueFaceIds_t triPatch = nRingNeighborAlg->getNRingTriangles(); BOOST_ASSERT(triPatch.size() > 1); DataArray<double>::Pointer patchCentroids = extractPatchData(triId, triPatch, centroids->GetPointer(0), std::string("Patch_Centroids")); DataArray<double>::Pointer patchNormals = extractPatchData(triId, triPatch, normals->GetPointer(0), std::string("Patch_Normals")); // Translate the patch to the 0,0,0 origin double sub[3] = {patchCentroids->GetComponent(0,0),patchCentroids->GetComponent(0,1), patchCentroids->GetComponent(0,2)}; subtractVector3d(patchCentroids, sub); double np[3] = {patchNormals->GetComponent(0,0), patchNormals->GetComponent(0,1), patchNormals->GetComponent(0, 2) }; double seedCentroid[3] = {patchCentroids->GetComponent(0,0), patchCentroids->GetComponent(0,1), patchCentroids->GetComponent(0,2) }; double firstCentroid[3] = {patchCentroids->GetComponent(1,0), patchCentroids->GetComponent(1,1), patchCentroids->GetComponent(1,2) }; double temp[3] = {firstCentroid[0] - seedCentroid[0], firstCentroid[1] - seedCentroid[1], firstCentroid[2] - seedCentroid[2]}; double vp[3] = {0.0, 0.0, 0.0}; // Cross Product of np and temp MatrixMath::NormalizeVector(np); MatrixMath::CrossProduct(np, temp, vp); MatrixMath::NormalizeVector(vp); // get the third orthogonal vector double up[3] = {0.0, 0.0, 0.0}; MatrixMath::CrossProduct(vp, np, up); // this constitutes a rotation matrix to a local coordinate system double rot[3][3] = {{up[0], up[1], up[2]}, {vp[0], vp[1], vp[2]}, {np[0], np[1], np[2]} }; double out[3]; // Transform all centroids and normals to new coordinate system for(size_t m = 0; m < patchCentroids->GetNumberOfTuples(); ++m) { ::memcpy(out, patchCentroids->GetPointer(m*3), 3*sizeof(double)); MatrixMath::Multiply3x3with3x1(rot, patchCentroids->GetPointer(m*3), out); ::memcpy(patchCentroids->GetPointer(m*3), out, 3*sizeof(double)); ::memcpy(out, patchNormals->GetPointer(m*3), 3*sizeof(double)); MatrixMath::Multiply3x3with3x1(rot, patchNormals->GetPointer(m*3), out); ::memcpy(patchNormals->GetPointer(m*3), out, 3*sizeof(double)); // We rotate the normals now but we dont use them yet. If we start using part 3 of Goldfeathers paper then we // will need the normals. } { // Solve the Least Squares fit static const unsigned int NO_NORMALS = 3; static const unsigned int USE_NORMALS = 7; int cols = NO_NORMALS; if (m_UseNormalsForCurveFitting == true) { cols = USE_NORMALS; } int rows = patchCentroids->GetNumberOfTuples(); Eigen::MatrixXd A(rows, cols); Eigen::VectorXd b(rows); double x, y, z; for(int m = 0; m < rows; ++m) { x = patchCentroids->GetComponent(m, 0); y = patchCentroids->GetComponent(m, 1); z = patchCentroids->GetComponent(m, 2); A(m) = 0.5 * x * x; // 1/2 x^2 A(m + rows) = x * y; // x*y A(m + rows*2) = 0.5 * y * y; // 1/2 y^2 if (m_UseNormalsForCurveFitting == true) { A(m + rows*3) = x*x*x; A(m + rows*4) = x*x*y; A(m + rows*5) = x*y*y; A(m + rows*6) = y*y*y; } b[m] = z; // The Z Values } Eigen::Matrix2d M; if (false == m_UseNormalsForCurveFitting) { typedef Eigen::Matrix<double, NO_NORMALS, 1> Vector3d; Vector3d sln1 = A.colPivHouseholderQr().solve(b); // Now that we have the A, B, C constants we can solve the Eigen value/vector problem // to get the principal curvatures and pricipal directions. M << sln1(0), sln1(1), sln1(1), sln1(2); } else { typedef Eigen::Matrix<double, USE_NORMALS, 1> Vector7d; Vector7d sln1 = A.colPivHouseholderQr().solve(b); // Now that we have the A, B, C, D, E, F & G constants we can solve the Eigen value/vector problem // to get the principal curvatures and pricipal directions. M << sln1(0), sln1(1), sln1(1), sln1(2); } Eigen::SelfAdjointEigenSolver<Eigen::Matrix2d> eig(M); Eigen::SelfAdjointEigenSolver<Eigen::Matrix2d>::RealVectorType eValues = eig.eigenvalues(); Eigen::SelfAdjointEigenSolver<Eigen::Matrix2d>::MatrixType eVectors = eig.eigenvectors(); // Kappa1 >= Kappa2 double kappa1 = eValues(0) * -1;// Kappa 1 double kappa2 = eValues(1) * -1; //kappa 2 BOOST_ASSERT(kappa1 >= kappa2); m_PrincipleCurvature1->SetValue(triId, kappa1); m_PrincipleCurvature2->SetValue(triId, kappa2); if (computeGaussian == true) { m_GaussianCurvature->SetValue(triId, kappa1*kappa2); } if (computeMean == true) { m_MeanCurvature->SetValue(triId, (kappa1+kappa2)/2.0); } if (computeDirection == true) { Eigen::Matrix3d e_rot_T; e_rot_T.row(0) = Eigen::Vector3d(up[0], vp[0], np[0]); e_rot_T.row(1) = Eigen::Vector3d(up[1], vp[1], np[1]); e_rot_T.row(2) = Eigen::Vector3d(up[2], vp[2], np[2]); // Rotate our principal directions back into the original coordinate system Eigen::Vector3d dir1 ( eVectors.col(0)(0), eVectors.col(0)(1), 0.0 ); dir1 = e_rot_T * dir1; ::memcpy(m_PrincipleDirection1->GetPointer(triId * 3), dir1.data(), 3*sizeof(double) ); Eigen::Vector3d dir2 ( eVectors.col(1)(0), eVectors.col(1)(1), 0.0 ); dir2 = e_rot_T * dir2; ::memcpy(m_PrincipleDirection2->GetPointer(triId * 3), dir2.data(), 3*sizeof(double) ); } } } // End Loop over this triangle m_ParentFilter->tbbTaskProgress(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void MultiThresholdCells::execute() { int err = 0; std::stringstream ss; setErrorCondition(err); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The Voxel DataContainer Object was NULL", -999); return; } setErrorCondition(0); int64_t nPoints = m->getTotalPoints(); dataCheck(false, m->getTotalPoints(), m->getNumFieldTuples(), m->getNumEnsembleTuples()); if (getErrorCondition() < 0) { return; } /* Place all your code to execute your filter here. */ IDataArray::Pointer outputArrayPtr = m->getCellData(m_OutputArrayName); BoolArrayType* outputArray = BoolArrayType::SafeObjectDownCast<IDataArray*, BoolArrayType*>(outputArrayPtr.get()); if (NULL == outputArray) { setErrorCondition(-11002); notifyErrorMessage("Could not properly cast the output array to a BoolArrayType", getErrorCondition()); return; } m_Output = outputArray->GetPointer(0); // Prime our output array with the result of the first comparison { ComparisonInput_t& comp_0 = m_ComparisonInputs[0]; ThresholdFilterHelper filter(static_cast<DREAM3D::Comparison::Enumeration>(comp_0.compOperator), comp_0.compValue, outputArray); err = filter.execute(m->getCellData(comp_0.arrayName).get(), outputArrayPtr.get()); if (err < 0) { setErrorCondition(-13001); notifyErrorMessage("Error Executing threshold filter on first array", getErrorCondition()); return; } } for(size_t i = 1; i < m_ComparisonInputs.size(); ++i) { BoolArrayType::Pointer currentArrayPtr = BoolArrayType::CreateArray(m->getTotalPoints(), "TEMP"); currentArrayPtr->initializeWithZeros(); bool* currentArray = currentArrayPtr->GetPointer(0); ComparisonInput_t& compRef = m_ComparisonInputs[i]; ThresholdFilterHelper filter(static_cast<DREAM3D::Comparison::Enumeration>(compRef.compOperator), compRef.compValue, currentArrayPtr.get()); err = filter.execute(m->getCellData(compRef.arrayName).get(), currentArrayPtr.get()); if (err < 0) { setErrorCondition(-13002); notifyErrorMessage("Error Executing threshold filter on array", getErrorCondition()); return; } for (int64_t p = 0; p < nPoints; ++p) { if(m_Output[p] == false || currentArray[p] == false) { m_Output[p] = false; } } } /* Let the GUI know we are done with this filter */ notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void MatrixPhaseWidget::extractStatsData(AttributeMatrix::Pointer attrMat, int index) { setPhaseIndex(index); IDataArray::Pointer iDataArray = attrMat->getAttributeArray(DREAM3D::EnsembleData::CrystalStructures); unsigned int* attributeArray = boost::dynamic_pointer_cast< UInt32ArrayType >(iDataArray)->getPointer(0); m_CrystalStructure = attributeArray[index]; iDataArray = attrMat->getAttributeArray(DREAM3D::EnsembleData::PhaseTypes); attributeArray = boost::dynamic_pointer_cast< UInt32ArrayType >(iDataArray)->getPointer(0); m_PhaseType = attributeArray[index]; iDataArray = attrMat->getAttributeArray(DREAM3D::EnsembleData::Statistics); StatsDataArray* statsDataArray = StatsDataArray::SafeObjectDownCast<IDataArray*, StatsDataArray*>(iDataArray.get()); if (statsDataArray == NULL) { return; } StatsData::Pointer statsData = statsDataArray->getStatsData(index); MatrixStatsData* matrixStatsData = MatrixStatsData::SafePointerDownCast(statsData.get()); m_PhaseFraction = matrixStatsData->getPhaseFraction(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindFaceAverage::dataCheckSurfaceMesh(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer(); if(NULL == sm) { addErrorMessage(getHumanLabel(), "SurfaceMeshDataContainer is missing", -383); setErrorCondition(-383); } else { // We MUST have Triangles defined. if(sm->getFaces().get() == NULL) { addErrorMessage(getHumanLabel(), "SurfaceMesh DataContainer missing Triangles", -385); setErrorCondition(-385); } else { GET_PREREQ_DATA(sm, DREAM3D, FaceData, SurfaceMeshGrainFaceId, ss, -387, int32_t, Int32ArrayType, fields, 1) if(1==m_AverageMethod) { GET_PREREQ_DATA(sm, DREAM3D, FaceData, SurfaceMeshTriangleAreas, ss, -387, double, DoubleArrayType, fields, 1) } if(m_SelectedFaceArrayName.empty() == true) { setErrorCondition(-11000); addErrorMessage(getHumanLabel(), "An array from the Face Data Container must be selected.", getErrorCondition()); } else if(preflight) { IDataArray::Pointer inputData = sm->getFaceData(m_SelectedFaceArrayName); if (NULL == inputData.get()) { ss.str(""); ss << "Selected array '" << m_SelectedFaceArrayName << "' does not exist in the Surface Mesh Data Container. Was it spelled correctly?"; setErrorCondition(-11001); notifyErrorMessage(ss.str(), getErrorCondition()); return; } int numberOfComponents = inputData->GetNumberOfComponents(); std::string dType = inputData->getTypeAsString(); IDataArray::Pointer p = IDataArray::NullPointer(); if (dType.compare("int8_t") == 0) { p = Int8ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("uint8_t") == 0) { p = UInt8ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("int16_t") == 0) { p = Int16ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("uint16_t") == 0) { p = UInt16ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("int32_t") == 0) { p = Int32ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("uint32_t") == 0) { p = UInt32ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("int64_t") == 0) { p = Int64ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("uint64_t") == 0) { p = UInt64ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("float") == 0) { p = FloatArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("double") == 0) { p = DoubleArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("bool") == 0) { p = BoolArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } sm->addFieldData(p->GetName(), p); } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CopyFeatureArrayToElementArray::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } // Validate that the selected InArray has tuples equal to the largest // Feature Id; 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 int32_t numFeatures = static_cast<int32_t>(m_InArrayPtr.lock()->getNumberOfTuples()); bool mismatchedFeatures = false; int32_t largestFeature = 0; size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); for (size_t i = 0; i < totalPoints; i ++) { if (m_FeatureIds[i] > largestFeature) { largestFeature = m_FeatureIds[i]; if (largestFeature >= numFeatures) { mismatchedFeatures = true; break; } } } if (mismatchedFeatures == true) { QString ss = QObject::tr("The number of Features in the InArray array (%1) is larger than the largest Feature Id in the FeatureIds array").arg(numFeatures); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } if (largestFeature != (numFeatures - 1)) { QString ss = QObject::tr("The number of Features in the InArray array (%1) does not match the largest Feature Id in the FeatureIds array").arg(numFeatures); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } IDataArray::Pointer p = IDataArray::NullPointer(); if (TemplateHelpers::CanDynamicCast<Int8ArrayType>()(m_InArrayPtr.lock())) { p = copyData<int8_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<UInt8ArrayType>()(m_InArrayPtr.lock())) { p = copyData<uint8_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<Int16ArrayType>()(m_InArrayPtr.lock())) { p = copyData<int16_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<UInt16ArrayType>()(m_InArrayPtr.lock())) { p = copyData<uint16_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<Int32ArrayType>()(m_InArrayPtr.lock())) { p = copyData<int32_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<UInt32ArrayType>()(m_InArrayPtr.lock())) { p = copyData<uint32_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<Int64ArrayType>()(m_InArrayPtr.lock())) { p = copyData<int64_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<UInt64ArrayType>()(m_InArrayPtr.lock())) { p = copyData<uint64_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<FloatArrayType>()(m_InArrayPtr.lock())) { p = copyData<float>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<DoubleArrayType>()(m_InArrayPtr.lock())) { p = copyData<double>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<BoolArrayType>()(m_InArrayPtr.lock())) { p = copyData<bool>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else { QString ss = QObject::tr("The selected array was of unsupported type. The path is %1").arg(m_SelectedFeatureArrayPath.serialize()); setErrorCondition(-14000); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } if (p.get() != NULL) { p->setName(getCreatedArrayName()); AttributeMatrix::Pointer am = getDataContainerArray()->getAttributeMatrix(getFeatureIdsArrayPath()); am->addAttributeArray(p->getName(), p); } notifyStatusMessage(getHumanLabel(), "Complete"); }
static void PopulateAttributeArrayList(AbstractFilter* filter, FilterParameter* filterParameter, QComboBox* dcCombo, QComboBox* amCombo, WidgetType* attributeArraysWidget, DataContainerArrayProxy& dcaProxy, QVector<DataArrayPath> selectedPaths) { FilterParameterType* fp = dynamic_cast<FilterParameterType*>(filterParameter); assert(fp != NULL); DataContainerArray::Pointer dca = filter->getDataContainerArray(); if (NULL == dca.get()) { return; } attributeArraysWidget->blockSignals(true); attributeArraysWidget->clear(); // Get the selected Data Container Name from the DataContainerList Widget QString currentDCName = dcCombo->currentText(); QString currentAttrMatName = amCombo->currentText(); // Loop over the data containers until we find the proper data container QList<DataContainerProxy> containers = dcaProxy.dataContainers.values(); QListIterator<DataContainerProxy> containerIter(containers); QVector<QString> daTypes = fp->getDefaultAttributeArrayTypes(); QVector< QVector<size_t> > cDims = fp->getDefaultComponentDimensions(); while (containerIter.hasNext()) { DataContainerProxy dc = containerIter.next(); if (dc.name.compare(currentDCName) == 0) { // We found the proper Data Container, now populate the AttributeMatrix List QMap<QString, AttributeMatrixProxy> attrMats = dc.attributeMatricies; QMapIterator<QString, AttributeMatrixProxy> attrMatsIter(attrMats); while (attrMatsIter.hasNext()) { attrMatsIter.next(); QString amName = attrMatsIter.key(); if (amName.compare(currentAttrMatName) == 0) { // Clear the list of arrays from the QListWidget attributeArraysWidget->clear(); // We found the selected AttributeMatrix, so loop over this attribute matrix arrays and populate the list widget AttributeMatrixProxy amProxy = attrMatsIter.value(); QMap<QString, DataArrayProxy> dataArrays = amProxy.dataArrays; QMapIterator<QString, DataArrayProxy> dataArraysIter(dataArrays); while (dataArraysIter.hasNext()) { dataArraysIter.next(); QString daName = dataArraysIter.key(); QListWidgetItem* daItem = new QListWidgetItem(daName); daItem->setCheckState(Qt::Unchecked); for (int i = 0; i < selectedPaths.size(); i++) { if (selectedPaths.at(i).getDataArrayName() == daName) { daItem->setCheckState(Qt::Checked); } } IDataArray::Pointer da = dca->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(NULL, DataArrayPath(dc.name, amProxy.name, daName)); attributeArraysWidget->addItem(daItem); if (NULL != da.get() && ((daTypes.isEmpty() == false && daTypes.contains(da->getTypeAsString()) == false) || (cDims.isEmpty() == false && cDims.contains(da->getComponentDimensions()) == false))) { QList<QListWidgetItem*> rejectList = attributeArraysWidget->findItems(daName, Qt::MatchRecursive); for (int i = 0; i < rejectList.size(); i++) { QListWidgetItem* item = rejectList[i]; item->setFlags(item->flags() & ~Qt::ItemIsEnabled); } } } } } } } attributeArraysWidget->blockSignals(false); }