// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindTwinBoundarySchmidFactors::dataCheckSurfaceMesh() { setErrorCondition(0); DataArrayPath tempPath; QVector<DataArrayPath> dataArrayPaths; getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); QVector<size_t> cDims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrayPaths.push_back(getSurfaceMeshFaceLabelsArrayPath()); } cDims[0] = 3; m_SurfaceMeshFaceNormalsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<double>, AbstractFilter>(this, getSurfaceMeshFaceNormalsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceNormalsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceNormals = m_SurfaceMeshFaceNormalsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrayPaths.push_back(getSurfaceMeshFaceNormalsArrayPath()); } tempPath.update(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName(), getSurfaceMeshFaceLabelsArrayPath().getAttributeMatrixName(), getSurfaceMeshTwinBoundarySchmidFactorsArrayName() ); m_SurfaceMeshTwinBoundarySchmidFactorsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<float>, AbstractFilter, float>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshTwinBoundarySchmidFactorsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshTwinBoundarySchmidFactors = m_SurfaceMeshTwinBoundarySchmidFactorsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 1; m_SurfaceMeshTwinBoundaryPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<bool>, AbstractFilter>(this, getSurfaceMeshTwinBoundaryArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshTwinBoundaryPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshTwinBoundary = m_SurfaceMeshTwinBoundaryPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrayPaths.push_back(getSurfaceMeshTwinBoundaryArrayPath()); } getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, dataArrayPaths); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LaplacianSmoothing::dataCheck() { TriangleGeom::Pointer triangles = getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); QVector<IDataArray::Pointer> faceDataArrays; QVector<IDataArray::Pointer> nodeDataArrays; if(getErrorCondition() >= 0) { faceDataArrays.push_back(triangles->getTriangles()); nodeDataArrays.push_back(triangles->getVertices()); } QVector<size_t> cDims(1, 1); m_SurfaceMeshNodeTypePtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int8_t>, AbstractFilter>(this, getSurfaceMeshNodeTypeArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshNodeTypePtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshNodeType = m_SurfaceMeshNodeTypePtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { nodeDataArrays.push_back(m_SurfaceMeshNodeTypePtr.lock()); } cDims[0] = 2; m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { faceDataArrays.push_back(m_SurfaceMeshFaceLabelsPtr.lock()); } getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, faceDataArrays); getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, nodeDataArrays); setSurfaceDataContainerName(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t AbaqusSurfaceMeshWriter::writeNodes(FILE* f) { TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); float* nodes = triangleGeom->getVertexPointer(0); int64_t numNodes = triangleGeom->getNumberOfVertices(); int32_t err = 0; fprintf(f, "*Node,NSET=NALL\n"); //1, 72.520433763730, 70.306420652241, 100.000000000000 // Abaqus Starts number at 1 NOT 0(Zero). for (int64_t i = 1; i <= numNodes; ++i) { fprintf(f, "%lld, %0.6f, %0.6f, %0.6f\n", (long long int)i, nodes[(i - 1) * 3], nodes[(i - 1) * 3 + 1], nodes[(i - 1) * 3 + 2]); } return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t AbaqusSurfaceMeshWriter::writeTriangles(FILE* f) { int32_t err = 0; TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); int64_t numTri = triangleGeom->getNumberOfTris(); int64_t* triangles = triangleGeom->getTriPointer(0); fprintf(f, "*ELEMENT, TYPE=%s\n", TRI_ELEMENT_TYPE); for (int64_t i = 1; i <= numTri; ++i) { // When we get the node index, add 1 to it because Abaqus number is 1 based. int64_t nId0 = triangles[(i - 1) * 3] + 1; int64_t nId1 = triangles[(i - 1) * 3 + 1] + 1; int64_t nId2 = triangles[(i - 1) * 3 + 2] + 1; fprintf(f, "%lld, %lld, %lld, %lld\n", (long long int)i, (long long int)nId0, (long long int)nId1, (long long int)nId2); } return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void InsertAtoms::dataCheck() { setErrorCondition(0); DataArrayPath tempPath; TriangleGeom::Pointer triangles = getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); QVector<IDataArray::Pointer> dataArrays; if(getErrorCondition() >= 0) { dataArrays.push_back(triangles->getTriangles()); } DataContainer::Pointer v = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getVertexDataContainerName()); if(getErrorCondition() < 0) { return; } VertexGeom::Pointer vertices = VertexGeom::CreateGeometry(0, DREAM3D::Geometry::VertexGeometry); v->setGeometry(vertices); QVector<size_t> tDims(1, 0); AttributeMatrix::Pointer vertexAttrMat = v->createNonPrereqAttributeMatrix<AbstractFilter>(this, getVertexAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::Vertex); if(getErrorCondition() < 0 || NULL == vertexAttrMat.get()) { return; } QVector<size_t> cDims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrays.push_back(m_SurfaceMeshFaceLabelsPtr.lock()); } cDims[0] = 4; m_AvgQuatsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<float>, AbstractFilter>(this, getAvgQuatsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_AvgQuatsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_AvgQuats = m_AvgQuatsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 1; tempPath.update(getVertexDataContainerName(), getVertexAttributeMatrixName(), getAtomFeatureLabelsArrayName() ); m_AtomFeatureLabelsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, -301, cDims); /* Assigns the shared_ptr<>(this, tempPath, -301, dims); Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_AtomFeatureLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_AtomFeatureLabels = m_AtomFeatureLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, dataArrays); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void InsertAtoms::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(FloatVec3FilterParameter::New("Lattice Constants (Angstroms)", "LatticeConstants", getLatticeConstants(), FilterParameter::Parameter)); { ChoiceFilterParameter::Pointer parameter = ChoiceFilterParameter::New(); parameter->setHumanLabel("Crystal Basis"); parameter->setPropertyName("Basis"); QVector<QString> choices; choices.push_back("Simple Cubic"); choices.push_back("Body Centered Cubic"); choices.push_back("Face Centered Cubic"); parameter->setChoices(choices); parameter->setCategory(FilterParameter::Parameter); parameters.push_back(parameter); } parameters.push_back(SeparatorFilterParameter::New("Face Data", FilterParameter::RequiredArray)); { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateRequirement(DREAM3D::TypeNames::Int32, 2, DREAM3D::AttributeMatrixType::Face, DREAM3D::GeometryType::TriangleGeometry); parameters.push_back(DataArraySelectionFilterParameter::New("Face Labels", "SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath(), FilterParameter::RequiredArray, req)); } parameters.push_back(SeparatorFilterParameter::New("Cell Feature Data", FilterParameter::RequiredArray)); { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateRequirement(DREAM3D::TypeNames::Float, 4, DREAM3D::AttributeMatrixType::CellFeature, DREAM3D::GeometryType::ImageGeometry); parameters.push_back(DataArraySelectionFilterParameter::New("Average Quaternions", "AvgQuatsArrayPath", getAvgQuatsArrayPath(), FilterParameter::RequiredArray, req)); } parameters.push_back(StringFilterParameter::New("Data Container", "VertexDataContainerName", getVertexDataContainerName(), FilterParameter::CreatedArray)); parameters.push_back(SeparatorFilterParameter::New("Vertex Data", FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Vertex Attribute Matrix", "VertexAttributeMatrixName", getVertexAttributeMatrixName(), FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Atom Feature Labels", "AtomFeatureLabelsArrayName", getAtomFeatureLabelsArrayName(), FilterParameter::CreatedArray)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int SurfaceMeshToNonconformalVtk::writeCellData(FILE* vtkFile, QMap<int32_t, int32_t>& featureIds) { int err = 0; if (NULL == vtkFile) { return -1; } DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName()); // Write the triangle region ids TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); int64_t numTriangles = triangleGeom->getNumberOfTris(); int swapped; // This is like a "section header" fprintf(vtkFile, "\n"); fprintf(vtkFile, "CELL_DATA %lld\n", (long long int)(numTriangles * 2)); int32_t totalCellsWritten = 0; // Write the FeatureId Data to the file fprintf(vtkFile, "SCALARS FeatureID int 1\n"); 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<int32_t> buffer(size, 0); totalCellsWritten += size; // Endian Swap our current feature Id since we are going to write it a bunch of times. swapped = gid; SIMPLib::Endian::FromSystemToBig::convert(swapped); size_t index = 0; // Loop over all the triangles looking for the current feature id // this is probably sub-optimal as if we have 1000 features we are going to loop 1000 times but this will use the // least amount of memory. We could run a filter to group the triangles by feature but then we would need an // additional amount of memory equal to 3X the memory used for the triangle list because every triangle will be listed // twice. We could get some slightly better performance if we buffered 4K worth of data then wrote out that data // in one chunk versus what we are doing here. for (int j = 0; j < numTriangles; j++) { if (m_SurfaceMeshFaceLabels[j * 2] == gid || m_SurfaceMeshFaceLabels[j * 2 + 1] == gid) { if(m_WriteBinaryFile == true) { buffer[index] = swapped; ++index; } else { fprintf(vtkFile, "%d\n", gid); } } } // Write the Buffer if(m_WriteBinaryFile == true) { fwrite(&(buffer.front()), sizeof(int32_t), size, vtkFile); } } #if 0 // Write the Original Triangle ID Data to the file fprintf(vtkFile, "\n"); fprintf(vtkFile, "SCALARS TriangleID int 1\n"); fprintf(vtkFile, "LOOKUP_TABLE default\n"); for(int i = 0; i < triangleCount * 2; ++i) { //Triangle& t = triangles[i]; // Get the current Node if(m_WriteBinaryFile == true) { swapped = i; SIMPLib::Endian::FromSystemToBig::convert(swapped); fwrite(&swapped, sizeof(int), 1, vtkFile); fwrite(&swapped, sizeof(int), 1, vtkFile); } else { fprintf(vtkFile, "%d\n", i); fprintf(vtkFile, "%d\n", i); } } #endif QString attrMatName = m_SurfaceMeshFaceLabelsArrayPath.getAttributeMatrixName(); notifyStatusMessage(getHumanLabel(), "Writing Face Normals..."); writeCellNormalData<double>(sm, attrMatName, SIMPL::FaceData::SurfaceMeshFaceNormals, "double", m_WriteBinaryFile, vtkFile, featureIds, m_SurfaceMeshFaceLabels); notifyStatusMessage(getHumanLabel(), "Writing Principal Curvature 1"); writeCellScalarData<double>(sm, attrMatName, SIMPL::FaceData::SurfaceMeshPrincipalCurvature1, "double", m_WriteBinaryFile, vtkFile, featureIds, m_SurfaceMeshFaceLabels); notifyStatusMessage(getHumanLabel(), "Writing Principal Curvature 2"); writeCellScalarData<double>(sm, attrMatName, SIMPL::FaceData::SurfaceMeshPrincipalCurvature2, "double", m_WriteBinaryFile, vtkFile, featureIds, m_SurfaceMeshFaceLabels); notifyStatusMessage(getHumanLabel(), "Writing Feature Face Id"); writeCellScalarData<int32_t>(sm, attrMatName, SIMPL::FaceData::SurfaceMeshFeatureFaceId, "int", m_WriteBinaryFile, vtkFile, featureIds, m_SurfaceMeshFaceLabels); notifyStatusMessage(getHumanLabel(), "Writing Gaussian Curvature"); writeCellScalarData<double>(sm, attrMatName, SIMPL::FaceData::SurfaceMeshGaussianCurvatures, "double", m_WriteBinaryFile, vtkFile, featureIds, m_SurfaceMeshFaceLabels); notifyStatusMessage(getHumanLabel(), "Writing Mean Curvature"); writeCellScalarData<double>(sm, attrMatName, SIMPL::FaceData::SurfaceMeshMeanCurvatures, "double", m_WriteBinaryFile, vtkFile, featureIds, m_SurfaceMeshFaceLabels); #if 0 writeCellVectorData<double>(sm, attrMatName, SIMPL::CellData::SurfaceMeshPrincipalDirection1, "double", m_WriteBinaryFile, "VECTORS", vtkFile, nT); writeCellVectorData<double>(sm, attrMatName, SIMPL::CellData::SurfaceMeshPrincipalDirection2, "double", m_WriteBinaryFile, "VECTORS", vtkFile, nT); writeCellNormalData<double>(sm, attrMatName, "Goldfeather_Triangle_Normals", "double", m_WriteBinaryFile, vtkFile, nT); #endif return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SurfaceMeshToNonconformalVtk::execute() { int err = 0; setErrorCondition(err); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName()); TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); float* nodes = triangleGeom->getVertexPointer(0); int64_t* triangles = triangleGeom->getTriPointer(0); qint64 numNodes = triangleGeom->getNumberOfVertices(); int64_t numTriangles = triangleGeom->getNumberOfTris(); // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path QFileInfo fi(getOutputVtkFile()); QDir parentPath = fi.path(); if(!parentPath.mkpath(".")) { QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath.absolutePath()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } // Open the output VTK File for writing FILE* vtkFile = NULL; vtkFile = fopen(getOutputVtkFile().toLatin1().data(), "wb"); if (NULL == vtkFile) { QString ss = QObject::tr("Error creating file '%1'").arg(getOutputVtkFile()); setErrorCondition(-18542); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } ScopedFileMonitor vtkFileMonitor(vtkFile); notifyStatusMessage(getHumanLabel(), "Writing Vertex Data ...."); fprintf(vtkFile, "# vtk DataFile Version 2.0\n"); fprintf(vtkFile, "Data set from DREAM.3D Surface Meshing Module\n"); if (m_WriteBinaryFile) { fprintf(vtkFile, "BINARY\n"); } else { fprintf(vtkFile, "ASCII\n"); } fprintf(vtkFile, "DATASET POLYDATA\n"); int numberWrittenNodes = 0; for (int i = 0; i < numNodes; i++) { // Node& n = nodes[i]; // Get the current Node if (m_SurfaceMeshNodeType[i] > 0) { ++numberWrittenNodes; } else { qDebug() << "Node Type Invalid: " << i << "::" << (int)(m_SurfaceMeshNodeType[i]) ;} } fprintf(vtkFile, "POINTS %d float\n", numberWrittenNodes); float pos[3] = {0.0f, 0.0f, 0.0f}; size_t totalWritten = 0; // Write the POINTS data (Vertex) for (int i = 0; i < numNodes; i++) { if (m_SurfaceMeshNodeType[i] > 0) { pos[0] = static_cast<float>(nodes[i * 3]); pos[1] = static_cast<float>(nodes[i * 3 + 1]); pos[2] = static_cast<float>(nodes[i * 3 + 2]); if (m_WriteBinaryFile == true) { SIMPLib::Endian::FromSystemToBig::convert(pos[0]); SIMPLib::Endian::FromSystemToBig::convert(pos[1]); SIMPLib::Endian::FromSystemToBig::convert(pos[2]); totalWritten = fwrite(pos, sizeof(float), 3, vtkFile); if(totalWritten != 3) {} } else { fprintf(vtkFile, "%f %f %f\n", pos[0], pos[1], pos[2]); // Write the positions to the output file } } } // Write the triangle indices into the vtk File notifyStatusMessage(getHumanLabel(), "Writing Faces ...."); int tData[4]; // Store all the unique Spins QMap<int32_t, int32_t> featureTriangleCount; for (int i = 0; i < numTriangles; i++) { if (featureTriangleCount.find(m_SurfaceMeshFaceLabels[i * 2]) == featureTriangleCount.end()) { featureTriangleCount[m_SurfaceMeshFaceLabels[i * 2]] = 1; } else { featureTriangleCount[m_SurfaceMeshFaceLabels[i * 2]]++; } if (featureTriangleCount.find(m_SurfaceMeshFaceLabels[i * 2 + 1]) == featureTriangleCount.end()) { featureTriangleCount[m_SurfaceMeshFaceLabels[i * 2 + 1]] = 1; } else { featureTriangleCount[m_SurfaceMeshFaceLabels[i * 2 + 1]]++; } } // Write the POLYGONS fprintf(vtkFile, "\nPOLYGONS %lld %lld\n", (long long int)(numTriangles * 2), (long long int)(numTriangles * 2 * 4)); size_t totalCells = 0; // Loop over all the features for(QMap<int32_t, int32_t>::iterator featureIter = featureTriangleCount.begin(); featureIter != featureTriangleCount.end(); ++featureIter) { totalCells += featureIter.value(); } Q_ASSERT(totalCells == (size_t)(numTriangles * 2) ); // Loop over all the features for(QMap<int32_t, int32_t>::iterator featureIter = featureTriangleCount.begin(); featureIter != featureTriangleCount.end(); ++featureIter) { int32_t gid = featureIter.key(); // The current Feature Id int32_t numTriToWrite = featureIter.value(); // The number of triangles for this feature uint8_t doWrite = 0; // Loop over all the triangles looking for the current feature id // this is probably sub-optimal as if we have 1000 features we are going to loop 1000 times but this will use the // least amount of memory. We could run a filter to group the triangles by feature but then we would need an // additional amount of memory equal to 3X the memory used for the triangle list because every triangle will be listed // twice. We could get some slightly better performance if we buffered 4K worth of data then wrote out that data // in one chunk versus what we are doing here. for (int j = 0; j < numTriangles; j++) { doWrite = 0; if (m_SurfaceMeshFaceLabels[j * 2] == gid ) { doWrite = 1; } else if (m_SurfaceMeshFaceLabels[j * 2 + 1] == gid) { doWrite = 2; } // We need to flip the winding of the triangle if (doWrite == 0) { continue; } // Labels in the triangle did match the current feature id. if (doWrite == 1) { tData[0] = 3; // Push on the total number of entries for this entry tData[1] = triangles[j * 3]; tData[2] = triangles[j * 3 + 1]; tData[3] = triangles[j * 3 + 2]; } else { tData[0] = 3; // Push on the total number of entries for this entry tData[1] = triangles[j * 3 + 2]; tData[2] = triangles[j * 3 + 1]; tData[3] = triangles[j * 3]; } if (m_WriteBinaryFile == true) { SIMPLib::Endian::FromSystemToBig::convert(tData[0]); SIMPLib::Endian::FromSystemToBig::convert(tData[1]); // Index of Vertex 0 SIMPLib::Endian::FromSystemToBig::convert(tData[2]); // Index of Vertex 1 SIMPLib::Endian::FromSystemToBig::convert(tData[3]); // Index of Vertex 2 fwrite(tData, sizeof(int), 4, vtkFile); } else { fprintf(vtkFile, "3 %d %d %d\n", tData[1], tData[2], tData[3]); } numTriToWrite--; } if (numTriToWrite != 0) { qDebug() << "Not enough triangles written: " << gid << "::" << numTriToWrite << " Total Triangles to Write " << featureIter.value(); } } // Write the POINT_DATA section err = writePointData(vtkFile); // Write the CELL_DATA section err = writeCellData(vtkFile, featureTriangleCount); fprintf(vtkFile, "\n"); setErrorCondition(0); notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SurfaceMeshToNonconformalVtk::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSurfaceMeshNodeTypeArrayPath(reader->readDataArrayPath("SurfaceMeshNodeTypeArrayPath", getSurfaceMeshNodeTypeArrayPath() ) ); setSurfaceMeshFaceLabelsArrayPath(reader->readDataArrayPath("SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath() ) ); setOutputVtkFile( reader->readString( "OutputVtkFile", getOutputVtkFile() ) ); setWriteBinaryFile( reader->readValue("WriteBinaryFile", getWriteBinaryFile()) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int SurfaceMeshToVtk::writeCellData(FILE* vtkFile) { int err = 0; if (NULL == vtkFile) { return -1; } DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName()); // Write the triangle region ids TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); int64_t nT = triangleGeom->getNumberOfTris(); int numTriangles = nT; int swapped; if (false == m_WriteConformalMesh) { numTriangles = nT * 2; } // This is like a "section header" fprintf(vtkFile, "\n"); fprintf(vtkFile, "CELL_DATA %d\n", numTriangles); // Write the FeatureId Data to the file fprintf(vtkFile, "SCALARS FeatureID int 1\n"); fprintf(vtkFile, "LOOKUP_TABLE default\n"); for(int i = 0; i < nT; ++i) { //FaceArray::Face_t& t = triangles[i]; // Get the current Node if(m_WriteBinaryFile == true) { swapped = m_SurfaceMeshFaceLabels[i * 2]; SIMPLib::Endian::FromSystemToBig::convert(swapped); fwrite(&swapped, sizeof(int), 1, vtkFile); if(false == m_WriteConformalMesh) { swapped = m_SurfaceMeshFaceLabels[i * 2 + 1]; SIMPLib::Endian::FromSystemToBig::convert(swapped); fwrite(&swapped, sizeof(int), 1, vtkFile); } } else { fprintf(vtkFile, "%d\n", m_SurfaceMeshFaceLabels[i * 2]); if(false == m_WriteConformalMesh) { fprintf(vtkFile, "%d\n", m_SurfaceMeshFaceLabels[i * 2 + 1]); } } } #if 0 // Write the Original Triangle ID Data to the file fprintf(vtkFile, "\n"); fprintf(vtkFile, "SCALARS TriangleID int 1\n"); fprintf(vtkFile, "LOOKUP_TABLE default\n"); for(int i = 0; i < nT; ++i) { //Triangle& t = triangles[i]; // Get the current Node if(m_WriteBinaryFile == true) { swapped = i; SIMPLib::Endian::FromSystemToBig::convert(swapped); fwrite(&swapped, sizeof(int), 1, vtkFile); if(false == m_WriteConformalMesh) { fwrite(&swapped, sizeof(int), 1, vtkFile); } } else { fprintf(vtkFile, "%d\n", i); if(false == m_WriteConformalMesh) { fprintf(vtkFile, "%d\n", i); } } } #endif QString attrMatName = m_SurfaceMeshFaceLabelsArrayPath.getAttributeMatrixName(); writeCellScalarData<int32_t>(sm, attrMatName, DREAM3D::FaceData::SurfaceMeshFeatureFaceId, "int", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, nT); writeCellScalarData<double>(sm, attrMatName, DREAM3D::FaceData::SurfaceMeshPrincipalCurvature1, "double", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, nT); writeCellScalarData<double>(sm, attrMatName, DREAM3D::FaceData::SurfaceMeshPrincipalCurvature2, "double", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, nT); writeCellVectorData<double>(sm, attrMatName, DREAM3D::FaceData::SurfaceMeshPrincipalDirection1, "double", m_WriteBinaryFile, m_WriteConformalMesh, "VECTORS", vtkFile, nT); writeCellVectorData<double>(sm, attrMatName, DREAM3D::FaceData::SurfaceMeshPrincipalDirection2, "double", m_WriteBinaryFile, m_WriteConformalMesh, "VECTORS", vtkFile, nT); writeCellScalarData<double>(sm, attrMatName, DREAM3D::FaceData::SurfaceMeshGaussianCurvatures, "double", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, nT); writeCellScalarData<double>(sm, attrMatName, DREAM3D::FaceData::SurfaceMeshMeanCurvatures, "double", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, nT); writeCellNormalData<double>(sm, attrMatName, DREAM3D::FaceData::SurfaceMeshFaceNormals, "double", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, nT); writeCellNormalData<double>(sm, attrMatName, "Goldfeather_Triangle_Normals", "double", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, nT); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AbaqusSurfaceMeshWriter::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(OutputFileFilterParameter::New("Output File", "OutputFile", getOutputFile(), FilterParameter::Parameter, "*.inp")); parameters.push_back(SeparatorFilterParameter::New("Face Data", FilterParameter::RequiredArray)); { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateRequirement(DREAM3D::TypeNames::Int32, 2, DREAM3D::AttributeMatrixType::Face, DREAM3D::GeometryType::TriangleGeometry); parameters.push_back(DataArraySelectionFilterParameter::New("Face Labels", "SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath(), FilterParameter::RequiredArray, req)); } setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t AbaqusSurfaceMeshWriter::writeFeatures(FILE* f) { //*Elset, elset=Feature1 //1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 int32_t err = 0; TriangleGeom::Pointer triangleGeo = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); int64_t nTriangles = triangleGeo->getNumberOfTris(); // Store all the unique Spins std::set<int32_t> uniqueSpins; for (int64_t i = 0; i < nTriangles; i++) { uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2]); uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2 + 1]); } int32_t spin = 0; //Loop over the unique Spins for (std::set<int32_t>::iterator spinIter = uniqueSpins.begin(); spinIter != uniqueSpins.end(); ++spinIter ) { spin = *spinIter; if (spin < 0) { continue; } fprintf(f, "*ELSET, ELSET=Feature%d\n", spin); { QString ss = QObject::tr("Writing ELSET for Feature Id %1").arg(spin); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); } // Loop over all the triangles for this spin int64_t lineCount = 0; for (int64_t t = 0; t < nTriangles; ++t) { if (m_SurfaceMeshFaceLabels[t * 2] != spin && m_SurfaceMeshFaceLabels[t * 2 + 1] != spin) { continue; // We do not match either spin so move to the next triangle } // Only print 15 Triangles per line if (lineCount == 15) { fprintf (f, ", %lld\n", (long long int)(t)); lineCount = 0; } else if(lineCount == 0) // First value on the line { fprintf(f, "%lld", (long long int)(t)); lineCount++; } else { fprintf(f, ", %lld", (long long int)(t)); lineCount++; } } // Make sure we have a new line at the end of the section if (lineCount != 0) { fprintf(f, "\n"); } } return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AbaqusSurfaceMeshWriter::execute() { int32_t err = 0; setErrorCondition(err); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path QFileInfo fi(getOutputFile()); QDir parentPath = fi.path(); if(!parentPath.mkpath(".")) { QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath.absolutePath()); setErrorCondition(-8005); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } TriangleGeom::Pointer triangleGeom = sm->getGeometryAs<TriangleGeom>(); // Store all the unique Spins std::set<int32_t> uniqueSpins; for (int64_t i = 0; i < triangleGeom->getNumberOfTris(); i++) { uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2]); uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2 + 1]); } FILE* f = fopen(m_OutputFile.toLatin1().data(), "wb"); ScopedFileMonitor fileMonitor(f); err = writeHeader(f, triangleGeom->getNumberOfVertices(), triangleGeom->getNumberOfTris(), uniqueSpins.size() - 1); if(err < 0) { QString ss = QObject::tr("Error writing header for file '%1'").arg(m_OutputFile); setErrorCondition(-8001); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } err = writeNodes(f); if(err < 0) { QString ss = QObject::tr("Error writing nodes for file '%1'").arg(m_OutputFile); setErrorCondition(-8002); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } err = writeTriangles(f); if(err < 0) { QString ss = QObject::tr("Error writing triangles for file '%1'").arg(m_OutputFile); setErrorCondition(-8003); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } err = writeFeatures(f); if(err < 0) { QString ss = QObject::tr("Error writing Features for file '%1'").arg(m_OutputFile); setErrorCondition(-8004); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AbaqusSurfaceMeshWriter::dataCheck() { setErrorCondition(0); if (m_OutputFile.isEmpty() == true) { setErrorCondition(-1003); notifyErrorMessage(getHumanLabel(), "The output file must be set", getErrorCondition()); } QFileInfo fi(m_OutputFile); QDir parentPath = fi.path(); if (parentPath.exists() == false) { 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); } QVector<IDataArray::Pointer> dataArrays; TriangleGeom::Pointer triangles = getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); if(getErrorCondition() >= 0) { dataArrays.push_back(triangles->getTriangles()); } QVector<size_t> cDims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if(getErrorCondition() >= 0) { dataArrays.push_back(m_SurfaceMeshFaceLabelsPtr.lock()); } getDataContainerArray()->validateNumberOfTuples<AbstractFilter>(this, dataArrays); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void GenerateFaceSchuhMisorientationColoring::dataCheckSurfaceMesh() { DataArrayPath tempPath; setErrorCondition(0); DataContainer::Pointer sm = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), false); if(getErrorCondition() < 0) { return; } QVector<size_t> dims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ dims[0] = 3; tempPath.update(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), m_SurfaceMeshFaceLabelsArrayPath.getAttributeMatrixName(), getSurfaceMeshFaceSchuhMisorientationColorsArrayName() ); m_SurfaceMeshFaceSchuhMisorientationColorsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<uint8_t>, AbstractFilter, uint8_t>(this, tempPath, 0, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceSchuhMisorientationColorsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceSchuhMisorientationColors = m_SurfaceMeshFaceSchuhMisorientationColorsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SurfaceMeshToVtk::execute() { int err = 0; setErrorCondition(err); dataCheck(); if(getErrorCondition() < 0) { return; } setErrorCondition(0); DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName()); /* Place all your code to execute your filter here. */ TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); float* nodes = triangleGeom->getVertexPointer(0); int64_t* triangles = triangleGeom->getTriPointer(0); qint64 numNodes = triangleGeom->getNumberOfVertices(); int64_t numTriangles = triangleGeom->getNumberOfTris(); // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path QFileInfo fi(getOutputVtkFile()); QDir parentPath = fi.path(); if(!parentPath.mkpath(".")) { QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath.absolutePath()); notifyErrorMessage(getHumanLabel(), ss, -1); setErrorCondition(-1); return; } // Open the output VTK File for writing FILE* vtkFile = NULL; vtkFile = fopen(getOutputVtkFile().toLatin1().data(), "wb"); if (NULL == vtkFile) { QString ss = QObject::tr("Error creating file '%1'").arg(getOutputVtkFile()); notifyErrorMessage(getHumanLabel(), ss, -18542); setErrorCondition(-18542); return; } ScopedFileMonitor vtkFileMonitor(vtkFile); fprintf(vtkFile, "# vtk DataFile Version 2.0\n"); fprintf(vtkFile, "Data set from DREAM.3D Surface Meshing Module\n"); if (m_WriteBinaryFile) { fprintf(vtkFile, "BINARY\n"); } else { fprintf(vtkFile, "ASCII\n"); } fprintf(vtkFile, "DATASET POLYDATA\n"); int numberWrittenumNodes = 0; for (int i = 0; i < numNodes; i++) { // Node& n = nodes[i]; // Get the current Node if (m_SurfaceMeshNodeType[i] > 0) { ++numberWrittenumNodes; } } fprintf(vtkFile, "POINTS %d float\n", numberWrittenumNodes); float pos[3] = {0.0f, 0.0f, 0.0f}; size_t totalWritten = 0; // Write the POINTS data (Vertex) for (int i = 0; i < numNodes; i++) { if (m_SurfaceMeshNodeType[i] > 0) { pos[0] = static_cast<float>(nodes[i * 3]); pos[1] = static_cast<float>(nodes[i * 3 + 1]); pos[2] = static_cast<float>(nodes[i * 3 + 2]); if (m_WriteBinaryFile == true) { SIMPLib::Endian::FromSystemToBig::convert(pos[0]); SIMPLib::Endian::FromSystemToBig::convert(pos[1]); SIMPLib::Endian::FromSystemToBig::convert(pos[2]); totalWritten = fwrite(pos, sizeof(float), 3, vtkFile); if (totalWritten != sizeof(float) * 3) { } } else { fprintf(vtkFile, "%f %f %f\n", pos[0], pos[1], pos[2]); // Write the positions to the output file } } } int tData[4]; int triangleCount = numTriangles; // int tn1, tn2, tn3; if (false == m_WriteConformalMesh) { triangleCount = numTriangles * 2; } // Write the POLYGONS fprintf(vtkFile, "\nPOLYGONS %d %d\n", triangleCount, (triangleCount * 4)); for (int j = 0; j < numTriangles; j++) { // Triangle& t = triangles[j]; tData[1] = triangles[j * 3]; tData[2] = triangles[j * 3 + 1]; tData[3] = triangles[j * 3 + 2]; if (m_WriteBinaryFile == true) { tData[0] = 3; // Push on the total number of entries for this entry SIMPLib::Endian::FromSystemToBig::convert(tData[0]); SIMPLib::Endian::FromSystemToBig::convert(tData[1]); // Index of Vertex 0 SIMPLib::Endian::FromSystemToBig::convert(tData[2]); // Index of Vertex 1 SIMPLib::Endian::FromSystemToBig::convert(tData[3]); // Index of Vertex 2 fwrite(tData, sizeof(int), 4, vtkFile); if (false == m_WriteConformalMesh) { tData[0] = tData[1]; tData[1] = tData[3]; tData[3] = tData[0]; tData[0] = 3; SIMPLib::Endian::FromSystemToBig::convert(tData[0]); fwrite(tData, sizeof(int), 4, vtkFile); } } else { fprintf(vtkFile, "3 %d %d %d\n", tData[1], tData[2], tData[3]); if (false == m_WriteConformalMesh) { fprintf(vtkFile, "3 %d %d %d\n", tData[3], tData[2], tData[1]); } } } // Write the POINT_DATA section err = writePointData(vtkFile); // Write the CELL_DATA section err = writeCellData(vtkFile); fprintf(vtkFile, "\n"); setErrorCondition(0); notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int SurfaceMeshToVtk::writePointData(FILE* vtkFile) { int err = 0; if (NULL == vtkFile) { return -1; } DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName()); TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); qint64 numNodes = triangleGeom->getNumberOfVertices(); int64_t numberWrittenumNodes = 0; // Write the Node Type Data to the file for (int i = 0; i < numNodes; i++) { if (m_SurfaceMeshNodeType[i] > 0) { ++numberWrittenumNodes; } } // This is the section header fprintf(vtkFile, "\n"); fprintf(vtkFile, "POINT_DATA %lld\n", (long long int)(numberWrittenumNodes)); fprintf(vtkFile, "SCALARS Node_Type char 1\n"); fprintf(vtkFile, "LOOKUP_TABLE default\n"); for(int i = 0; i < numNodes; ++i) { if(m_SurfaceMeshNodeType[i] > 0) { if(m_WriteBinaryFile == true) { // Normally, we would byte swap to big endian but since we are only writing // 1 byte Char values, nothing to swap. fwrite(m_SurfaceMeshNodeType + i, sizeof(char), 1, vtkFile); } else { fprintf(vtkFile, "%d ", m_SurfaceMeshNodeType[i]); } } } QString attrMatName = m_SurfaceMeshNodeTypeArrayPath.getAttributeMatrixName(); #if 1 // This is from the Goldfeather Paper writePointVectorData<double>(sm, attrMatName, "Principal_Direction_1", "double", m_WriteBinaryFile, m_WriteConformalMesh, "VECTORS", vtkFile, numNodes); // This is from the Goldfeather Paper writePointVectorData<double>(sm, attrMatName, "Principal_Direction_2", "double", m_WriteBinaryFile, m_WriteConformalMesh, "VECTORS", vtkFile, numNodes); // This is from the Goldfeather Paper writePointScalarData<double>(sm, attrMatName, "Principal_Curvature_1", "double", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, numNodes); // This is from the Goldfeather Paper writePointScalarData<double>(sm, attrMatName, "Principal_Curvature_2", "double", m_WriteBinaryFile, m_WriteConformalMesh, vtkFile, numNodes); #endif // This is from the Goldfeather Paper writePointVectorData<double>(sm, attrMatName, DREAM3D::VertexData::SurfaceMeshNodeNormals, "double", m_WriteBinaryFile, m_WriteConformalMesh, "VECTORS", vtkFile, numNodes); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AbaqusSurfaceMeshWriter::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSurfaceMeshFaceLabelsArrayPath(reader->readDataArrayPath("SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath() ) ); setOutputFile( reader->readString( "OutputFile", getOutputFile() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SurfaceMeshToVtk::setupFilterParameters() { QVector<FilterParameter::Pointer> parameters; parameters.push_back(OutputFileFilterParameter::New("Output Vtk File", "OutputVtkFile", getOutputVtkFile(), FilterParameter::Parameter)); parameters.push_back(BooleanFilterParameter::New("Write Binary Vtk File", "WriteBinaryFile", getWriteBinaryFile(), FilterParameter::Parameter)); parameters.push_back(BooleanFilterParameter::New("Write Conformal Mesh", "WriteConformalMesh", getWriteConformalMesh(), FilterParameter::Parameter)); { DataArraySelectionFilterParameter::RequirementType req; parameters.push_back(DataArraySelectionFilterParameter::New("SurfaceMeshFaceLabels", "SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath(), FilterParameter::RequiredArray, req)); } { DataArraySelectionFilterParameter::RequirementType req; parameters.push_back(DataArraySelectionFilterParameter::New("SurfaceMeshNodeType", "SurfaceMeshNodeTypeArrayPath", getSurfaceMeshNodeTypeArrayPath(), FilterParameter::RequiredArray, req)); } parameters.push_back(SeparatorFilterParameter::New("Vertex Data", FilterParameter::RequiredArray)); { MultiDataArraySelectionFilterParameter::RequirementType req; req.dcGeometryTypes = QVector<unsigned int>(1, DREAM3D::GeometryType::TriangleGeometry); req.amTypes = QVector<unsigned int>(1, DREAM3D::AttributeMatrixType::Vertex); parameters.push_back(MultiDataArraySelectionFilterParameter::New("Vertex Arrays", "SelectedVertexArrays", getSelectedVertexArrays(), FilterParameter::RequiredArray, req)); } parameters.push_back(SeparatorFilterParameter::New("Face Data", FilterParameter::RequiredArray)); { MultiDataArraySelectionFilterParameter::RequirementType req; req.dcGeometryTypes = QVector<unsigned int>(1, DREAM3D::GeometryType::TriangleGeometry); req.amTypes = QVector<unsigned int>(1, DREAM3D::AttributeMatrixType::Face); parameters.push_back(MultiDataArraySelectionFilterParameter::New("Face Arrays", "SelectedFaceArrays", getSelectedFaceArrays(), FilterParameter::RequiredArray, req)); } setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindModulusMismatch::setupFilterParameters() { FilterParameterVector parameters; { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateCategoryRequirement(DREAM3D::Defaults::AnyPrimitive, 1, DREAM3D::AttributeMatrixObjectType::Any); parameters.push_back(DataArraySelectionFilterParameter::New("Moduli", "ModuliArrayPath", getModuliArrayPath(), FilterParameter::RequiredArray, req)); } { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateCategoryRequirement(DREAM3D::Defaults::AnyPrimitive, 2, DREAM3D::AttributeMatrixObjectType::Any); parameters.push_back(DataArraySelectionFilterParameter::New("SurfaceMeshFaceLabels", "SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath(), FilterParameter::RequiredArray, req)); } parameters.push_back(StringFilterParameter::New("SurfaceMeshDeltaModulus", "SurfaceMeshDeltaModulusArrayName", getSurfaceMeshDeltaModulusArrayName(), FilterParameter::CreatedArray)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SurfaceMeshToNonconformalVtk::dataCheck() { setErrorCondition(0); QString ss; if (m_OutputVtkFile.isEmpty() == true) { setErrorCondition(-1003); notifyErrorMessage(getHumanLabel(), "Vtk Output file is Not set correctly", -1003); } DataContainer::Pointer sm = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), false); if(getErrorCondition() < 0) { return; } TriangleGeom::Pointer triangles = sm->getPrereqGeometry<TriangleGeom, AbstractFilter>(this); if(getErrorCondition() < 0) { return; } // We MUST have Nodes if (NULL == triangles->getVertices().get()) { setErrorCondition(-386); notifyErrorMessage(getHumanLabel(), "DataContainer Geometry missing Vertices", getErrorCondition()); } // We MUST have Triangles defined also. if (NULL == triangles->getTriangles().get()) { setErrorCondition(-387); notifyErrorMessage(getHumanLabel(), "DataContainer Geometry missing Triangles", getErrorCondition()); } QVector<size_t> dims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ dims[0] = 1; m_SurfaceMeshNodeTypePtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int8_t>, AbstractFilter>(this, getSurfaceMeshNodeTypeArrayPath(), dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshNodeTypePtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshNodeType = m_SurfaceMeshNodeTypePtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
// ----------------------------------------------------------------------------- void FindModulusMismatch::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSurfaceMeshDeltaModulusArrayName(reader->readString("SurfaceMeshDeltaModulusArrayName", getSurfaceMeshDeltaModulusArrayName() ) ); setSurfaceMeshFaceLabelsArrayPath(reader->readDataArrayPath("SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath() ) ); setModuliArrayPath(reader->readDataArrayPath("ModuliArrayPath", getModuliArrayPath() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int SurfaceMeshToNonconformalVtk::writePointData(FILE* vtkFile) { int err = 0; if (NULL == vtkFile) { return -1; } DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(m_SurfaceMeshNodeTypeArrayPath.getDataContainerName()); TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); //Get the Number of Vertex points in the mesh with a valid node type qint64 numNodes = triangleGeom->getNumberOfVertices(); int nNodes = 0; // int swapped; for (int i = 0; i < numNodes; i++) { if (m_SurfaceMeshNodeType[i] > 0) { ++nNodes; } else { qDebug() << "Node Type Invalid: " << i << "::" << (int)(m_SurfaceMeshNodeType[i]) ;} } // This is the section header fprintf(vtkFile, "\n"); fprintf(vtkFile, "POINT_DATA %d\n", nNodes); fprintf(vtkFile, "SCALARS Node_Type char 1\n"); fprintf(vtkFile, "LOOKUP_TABLE default\n"); for(int i = 0; i < numNodes; ++i) { if(m_SurfaceMeshNodeType[i] > 0) { if(m_WriteBinaryFile == true) { // swapped = m_SurfaceMeshNodeType[i]; // SIMPLib::Endian::FromSystemToBig::convert(swapped); fwrite(m_SurfaceMeshNodeType + i, sizeof(char), 1, vtkFile); } else { fprintf(vtkFile, "%d ", m_SurfaceMeshNodeType[i]); } } } QString attrMatName = m_SurfaceMeshNodeTypeArrayPath.getAttributeMatrixName(); #if 1 // This is from the Goldfeather Paper writePointVectorData<double>(sm, attrMatName, "Principal_Direction_1", "double", m_WriteBinaryFile, "VECTORS", vtkFile, numNodes); // This is from the Goldfeather Paper writePointVectorData<double>(sm, attrMatName, "Principal_Direction_2", "double", m_WriteBinaryFile, "VECTORS", vtkFile, numNodes); // This is from the Goldfeather Paper writePointScalarData<double>(sm, attrMatName, "Principal_Curvature_1", "double", m_WriteBinaryFile, vtkFile, numNodes); // This is from the Goldfeather Paper writePointScalarData<double>(sm, attrMatName, "Principal_Curvature_2", "double", m_WriteBinaryFile, vtkFile, numNodes); #endif // This is from the Goldfeather Paper writePointVectorData<double>(sm, attrMatName, SIMPL::VertexData::SurfaceMeshNodeNormals, "double", m_WriteBinaryFile, "VECTORS", vtkFile, numNodes); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindModulusMismatch::dataCheckSurfaceMesh() { DataArrayPath tempPath; setErrorCondition(0); DataContainer::Pointer sm = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); if(getErrorCondition() < 0 || NULL == sm.get()) { return; } QVector<size_t> dims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ dims[0] = 1; tempPath.update(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), m_SurfaceMeshFaceLabelsArrayPath.getAttributeMatrixName(), getSurfaceMeshDeltaModulusArrayName() ); m_SurfaceMeshDeltaModulusPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<float>, AbstractFilter, float>(this, tempPath, 180.0, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshDeltaModulusPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshDeltaModulus = m_SurfaceMeshDeltaModulusPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SurfaceMeshToNonconformalVtk::setupFilterParameters() { QVector<FilterParameter::Pointer> parameters; parameters.push_back(OutputFileFilterParameter::New("Output Vtk File", "OutputVtkFile", getOutputVtkFile(), FilterParameter::Parameter)); parameters.push_back(BooleanFilterParameter::New("Write Binary Vtk File", "WriteBinaryFile", getWriteBinaryFile(), FilterParameter::Parameter)); { DataArraySelectionFilterParameter::RequirementType req; parameters.push_back(DataArraySelectionFilterParameter::New("SurfaceMeshFaceLabels", "SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath(), FilterParameter::RequiredArray, req)); } { DataArraySelectionFilterParameter::RequirementType req; parameters.push_back(DataArraySelectionFilterParameter::New("SurfaceMeshNodeType", "SurfaceMeshNodeTypeArrayPath", getSurfaceMeshNodeTypeArrayPath(), FilterParameter::RequiredArray, req)); } setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SharedFeatureFaceFilter::dataCheck() { setErrorCondition(0); DataArrayPath tempPath; getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); DataContainer::Pointer sm = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), false); if(getErrorCondition() < 0) { return; } QVector<size_t> tDims(1, 0); AttributeMatrix::Pointer facefeatureAttrMat = sm->createNonPrereqAttributeMatrix<AbstractFilter>(this, getFaceFeatureAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::FaceFeature); if(getErrorCondition() < 0 || NULL == facefeatureAttrMat.get()) { return; } QVector<size_t> cDims(1, 2); m_SurfaceMeshFaceLabelsPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSurfaceMeshFaceLabelsArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceMeshFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFaceLabels = m_SurfaceMeshFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 1; tempPath.update(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), m_SurfaceMeshFaceLabelsArrayPath.getAttributeMatrixName(), getSurfaceMeshFeatureFaceIdsArrayName() ); m_SurfaceMeshFeatureFaceIdsPtr = 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_SurfaceMeshFeatureFaceIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFeatureFaceIds = m_SurfaceMeshFeatureFaceIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ tempPath.update(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), getFaceFeatureAttributeMatrixName(), getSurfaceMeshFeatureFaceNumTrianglesArrayName() ); m_SurfaceMeshFeatureFaceNumTrianglesPtr = 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_SurfaceMeshFeatureFaceNumTrianglesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFeatureFaceNumTriangles = m_SurfaceMeshFeatureFaceNumTrianglesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ cDims[0] = 2; tempPath.update(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName(), getFaceFeatureAttributeMatrixName(), getSurfaceMeshFeatureFaceLabelsArrayName() ); m_SurfaceMeshFeatureFaceLabelsPtr = 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_SurfaceMeshFeatureFaceLabelsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceMeshFeatureFaceLabels = m_SurfaceMeshFeatureFaceLabelsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void InsertAtoms::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setVertexDataContainerName(reader->readString("VertexDataContainerName", getVertexDataContainerName() ) ); setVertexAttributeMatrixName(reader->readString("VertexAttributeMatrixName", getVertexAttributeMatrixName() ) ); setAtomFeatureLabelsArrayName(reader->readString("AtomFeatureLabelsArrayName", getAtomFeatureLabelsArrayName() ) ); setAvgQuatsArrayPath(reader->readDataArrayPath("AvgQuatsArrayPath", getAvgQuatsArrayPath() ) ); setSurfaceMeshFaceLabelsArrayPath(reader->readDataArrayPath("SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath() ) ); setLatticeConstants( reader->readFloatVec3("LatticeConstants", getLatticeConstants() ) ); setBasis( reader->readValue("Basis", getBasis() ) ); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SharedFeatureFaceFilter::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(SeparatorFilterParameter::New("Face Data", FilterParameter::RequiredArray)); { DataArraySelectionFilterParameter::RequirementType req = DataArraySelectionFilterParameter::CreateRequirement(DREAM3D::TypeNames::Int32, 2, DREAM3D::AttributeMatrixType::Face, DREAM3D::GeometryType::TriangleGeometry); parameters.push_back(DataArraySelectionFilterParameter::New("Face Labels", "SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath(), FilterParameter::RequiredArray, req)); } parameters.push_back(SeparatorFilterParameter::New("Face Data", FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Feature Face Ids", "SurfaceMeshFeatureFaceIdsArrayName", getSurfaceMeshFeatureFaceIdsArrayName(), FilterParameter::CreatedArray)); parameters.push_back(SeparatorFilterParameter::New("Face Feature Data", FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Face Feature Attribute Matrix", "FaceFeatureAttributeMatrixName", getFaceFeatureAttributeMatrixName(), FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Face Labels", "SurfaceMeshFeatureFaceLabelsArrayName", getSurfaceMeshFeatureFaceLabelsArrayName(), FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Number of Triangles", "SurfaceMeshFeatureFaceNumTrianglesArrayName", getSurfaceMeshFeatureFaceNumTrianglesArrayName(), FilterParameter::CreatedArray)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void InsertAtoms::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } // Validate that the selected AvgQuats array 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 numFeaturesIn = static_cast<int32_t>(m_AvgQuatsPtr.lock()->getNumberOfTuples()); bool mismatchedFeatures = true; int32_t largestFeature = 0; size_t numTuples = m_SurfaceMeshFaceLabelsPtr.lock()->getNumberOfTuples(); for (size_t i = 0; i < numTuples; i++) { if (m_SurfaceMeshFaceLabels[2 * i] > largestFeature) { largestFeature = m_SurfaceMeshFaceLabels[2 * i]; if (largestFeature >= numFeaturesIn) { mismatchedFeatures = true; break; } } else if (m_SurfaceMeshFaceLabels[2 * i + 1] > largestFeature) { largestFeature = m_SurfaceMeshFaceLabels[2 * i + 1]; if (largestFeature >= numFeaturesIn) { mismatchedFeatures = true; break; } } } if (mismatchedFeatures == true) { QString ss = QObject::tr("The number of Features in the AvgQuats array (%1) is larger than the largest Feature Id in the SurfaceMeshFaceLabels array").arg(numFeaturesIn); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } if (largestFeature != (numFeaturesIn - 1)) { QString ss = QObject::tr("The number of Features in the AvgQuats array (%1) does not match the largest Feature Id in the SurfaceMeshFaceLabels array").arg(numFeaturesIn); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } FloatVec3_t latticeConstants; latticeConstants.x = m_LatticeConstants.x / 10000.0; latticeConstants.y = m_LatticeConstants.y / 10000.0; latticeConstants.z = m_LatticeConstants.z / 10000.0; DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); SIMPL_RANDOMNG_NEW() #ifdef SIMPLib_USE_PARALLEL_ALGORITHMS tbb::task_scheduler_init init; bool doParallel = true; #endif // pull down faces TriangleGeom::Pointer triangleGeom = sm->getGeometryAs<TriangleGeom>(); int64_t numFaces = m_SurfaceMeshFaceLabelsPtr.lock()->getNumberOfTuples(); // create array to hold bounding vertices for each face FloatArrayType::Pointer llPtr = FloatArrayType::CreateArray(3, "Lower_Left_Internal_Use_Only"); FloatArrayType::Pointer urPtr = FloatArrayType::CreateArray(3, "Upper_Right_Internal_Use_Only"); float* ll = llPtr->getPointer(0); float* ur = urPtr->getPointer(0); VertexGeom::Pointer faceBBs = VertexGeom::CreateGeometry(2 * numFaces, "faceBBs"); // walk through faces to see how many features there are int32_t g1 = 0, g2 = 0; int32_t maxFeatureId = 0; for (int64_t i = 0; i < numFaces; i++) { g1 = m_SurfaceMeshFaceLabels[2 * i]; g2 = m_SurfaceMeshFaceLabels[2 * i + 1]; if (g1 > maxFeatureId) { maxFeatureId = g1; } if (g2 > maxFeatureId) { maxFeatureId = g2; } } // add one to account for feature 0 int32_t numFeatures = maxFeatureId + 1; // create a dynamic list array to hold face lists Int32Int32DynamicListArray::Pointer faceLists = Int32Int32DynamicListArray::New(); QVector<int32_t> linkCount(numFeatures, 0); // fill out lists with number of references to cells typedef boost::shared_array<int32_t> SharedInt32Array_t; SharedInt32Array_t linkLocPtr(new int32_t[numFaces]); int32_t* linkLoc = linkLocPtr.get(); ::memset(linkLoc, 0, numFaces * sizeof(int32_t)); // traverse data to determine number of faces belonging to each feature for (int64_t i = 0; i < numFaces; i++) { g1 = m_SurfaceMeshFaceLabels[2 * i]; g2 = m_SurfaceMeshFaceLabels[2 * i + 1]; if (g1 > 0) { linkCount[g1]++; } if (g2 > 0) { linkCount[g2]++; } } // now allocate storage for the faces faceLists->allocateLists(linkCount); // traverse data again to get the faces belonging to each feature for (int64_t i = 0; i < numFaces; i++) { g1 = m_SurfaceMeshFaceLabels[2 * i]; g2 = m_SurfaceMeshFaceLabels[2 * i + 1]; if (g1 > 0) { faceLists->insertCellReference(g1, (linkLoc[g1])++, i); } if (g2 > 0) { faceLists->insertCellReference(g2, (linkLoc[g2])++, i); } // find bounding box for each face GeometryMath::FindBoundingBoxOfFace(triangleGeom, i, ll, ur); faceBBs->setCoords(2 * i, ll); faceBBs->setCoords(2 * i + 1, ur); } // generate the list of sampling points fom subclass QVector<VertexGeom::Pointer> points(numFeatures); QVector<BoolArrayType::Pointer> inFeature(numFeatures); for (int32_t i = 0; i < numFeatures; i++) { points[i] = VertexGeom::CreateGeometry(0, "_INTERNAL_USE_ONLY_points"); inFeature[i] = BoolArrayType::CreateArray(0, "_INTERNAL_USE_ONLY_inside"); } QuatF* avgQuats = reinterpret_cast<QuatF*>(m_AvgQuats); #ifdef SIMPLib_USE_PARALLEL_ALGORITHMS if (doParallel == true) { tbb::parallel_for(tbb::blocked_range<size_t>(0, numFeatures), InsertAtomsImpl(triangleGeom, faceLists, faceBBs, avgQuats, latticeConstants, m_Basis, points, inFeature), tbb::auto_partitioner()); } else #endif { InsertAtomsImpl serial(triangleGeom, faceLists, faceBBs, avgQuats, latticeConstants, m_Basis, points, inFeature); serial.checkPoints(0, numFeatures); } assign_points(points, inFeature); notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SharedFeatureFaceFilter::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setFaceFeatureAttributeMatrixName(reader->readString("FaceFeatureAttributeMatrixName", getFaceFeatureAttributeMatrixName() ) ); setSurfaceMeshFeatureFaceIdsArrayName(reader->readString("SurfaceMeshFeatureFaceIdsArrayName", getSurfaceMeshFeatureFaceIdsArrayName() ) ); setSurfaceMeshFeatureFaceLabelsArrayName(reader->readString("SurfaceMeshFeatureFaceLabelsArrayName", getSurfaceMeshFeatureFaceLabelsArrayName() ) ); setSurfaceMeshFeatureFaceNumTrianglesArrayName(reader->readString("SurfaceMeshFeatureFaceNumTrianglesArrayName", getSurfaceMeshFeatureFaceNumTrianglesArrayName() ) ); setSurfaceMeshFaceLabelsArrayPath(reader->readDataArrayPath("SurfaceMeshFaceLabelsArrayPath", getSurfaceMeshFaceLabelsArrayPath() ) ); reader->closeFilterGroup(); }