// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VtkStructuredPointsReader::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setVertexDataContainerName(reader->readString("VertexDataContainerName", getVertexDataContainerName())); setVolumeDataContainerName(reader->readString("VolumeDataContainerName", getVolumeDataContainerName() ) ); setCellAttributeMatrixName(reader->readString("CellAttributeMatrixName", getCellAttributeMatrixName() ) ); setVertexAttributeMatrixName(reader->readString("VertexAttributeMatrixName", getVertexAttributeMatrixName() ) ); setInputFile( reader->readString( "InputFile", getInputFile() ) ); setReadPointData(reader->readValue("ReadPointData", getReadPointData())); setReadCellData(reader->readValue("ReadCellData", getReadCellData())); reader->closeFilterGroup(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 InsertAtoms::assign_points(QVector<VertexGeom::Pointer> points, QVector<BoolArrayType::Pointer> inFeature) { size_t count = 0; int32_t numFeatures = points.size(); for (int32_t i = 0; i < numFeatures; i++) { int64_t numPoints = points[i]->getNumberOfVertices(); bool* inside = inFeature[i]->getPointer(0); for (int64_t j = 0; j < numPoints; j++) { if (inside[j] == true) { count++; } } } DataContainer::Pointer v = getDataContainerArray()->getDataContainer(getVertexDataContainerName()); VertexGeom::Pointer vertices = VertexGeom::CreateGeometry(count, DREAM3D::VertexData::SurfaceMeshNodes); AttributeMatrix::Pointer vertexAttrMat = v->getAttributeMatrix(getVertexAttributeMatrixName()); QVector<size_t> tDims(1, count); vertexAttrMat->resizeAttributeArrays(tDims); updateVertexInstancePointers(); count = 0; float coords[3] = { 0.0f, 0.0f, 0.0f }; for (int32_t i = 0; i < numFeatures; i++) { int64_t numPoints = points[i]->getNumberOfVertices(); bool* inside = inFeature[i]->getPointer(0); for (int64_t j = 0; j < numPoints; j++) { if (inside[j] == true) { coords[0] = points[i]->getVertexPointer(j)[0]; coords[1] = points[i]->getVertexPointer(j)[1]; coords[2] = points[i]->getVertexPointer(j)[2]; vertices->setCoords(count, coords); m_AtomFeatureLabels[count] = i; count++; } } } v->setGeometry(vertices); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VtkStructuredPointsReader::setupFilterParameters() { FilterParameterVector parameters; parameters.push_back(InputFileFilterParameter::New("Input VTK File", "InputFile", getInputFile(), FilterParameter::Parameter)); QStringList linkedProps; linkedProps << "VertexDataContainerName" << "VertexAttributeMatrixName"; parameters.push_back(LinkedBooleanFilterParameter::New("Read Point Data", "ReadPointData", getReadPointData(), linkedProps, FilterParameter::Parameter)); linkedProps.clear(); linkedProps << "VolumeDataContainerName" << "CellAttributeMatrixName"; parameters.push_back(LinkedBooleanFilterParameter::New("Read Cell Data", "ReadCellData", getReadCellData(), linkedProps, FilterParameter::Parameter)); parameters.push_back(StringFilterParameter::New("Point Data Data Container", "VertexDataContainerName", getVertexDataContainerName(), FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Cell Data Data Container", "VolumeDataContainerName", getVolumeDataContainerName(), FilterParameter::CreatedArray)); parameters.push_back(SeparatorFilterParameter::New("Cell Data", FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Point Data Attribute Matrix", "VertexAttributeMatrixName", getVertexAttributeMatrixName(), FilterParameter::CreatedArray)); parameters.push_back(StringFilterParameter::New("Cell Data Attribute Matrix", "CellAttributeMatrixName", getCellAttributeMatrixName(), FilterParameter::CreatedArray)); setFilterParameters(parameters); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t VtkStructuredPointsReader::readDataTypeSection(std::istream& in, int32_t numValues, const std::string& nextKeyWord) { QByteArray buf(kBufferSize, '\0'); char* line = buf.data(); // Read keywords until end-of-file while (this->readString(in, line, kBufferSize)) { // read scalar data if ( ! strncmp(lowerCase(line, kBufferSize), "scalars", 7) ) { if ( this->readScalarData(in, numValues) <= 0 ) { return 0; } } // read vector data else if ( ! strncmp(line, "vectors", 7) ) { if ( this->readVectorData(in, numValues) <= 0 ) { return 0; } } #if 0 // // read 3x3 tensor data // else if ( ! strncmp(line, "tensors", 7) ) { if ( ! this->ReadTensorData(a, numPts) ) { return 0; } } // // read normals data // else if ( ! strncmp(line, "normals", 7) ) { if ( ! this->ReadNormalData(a, numPts) ) { return 0; } } // // read texture coordinates data // else if ( ! strncmp(line, "texture_coordinates", 19) ) { if ( ! this->ReadTCoordsData(a, numPts) ) { return 0; } } // // read the global id data // else if ( ! strncmp(line, "global_ids", 10) ) { if ( ! this->ReadGlobalIds(a, numPts) ) { return 0; } } // // read the pedigree id data // else if ( ! strncmp(line, "pedigree_ids", 10) ) { if ( ! this->ReadPedigreeIds(a, numPts) ) { return 0; } } // // read color scalars data // else if ( ! strncmp(line, "color_scalars", 13) ) { if ( ! this->ReadCoScalarData(a, numPts) ) { return 0; } } // // read lookup table. Associate with scalar data. // else if ( ! strncmp(line, "lookup_table", 12) ) { if ( ! this->ReadLutData(a) ) { return 0; } } // // read field of data // else if ( ! strncmp(line, "field", 5) ) { vtkFieldData* f; if ( ! (f = this->ReadFieldData()) ) { return 0; } for(int i = 0; i < f->GetNumberOfArrays(); i++) { a->AddArray(f->GetAbstractArray(i)); } f->Delete(); } #endif // maybe bumped into cell data else if ( ! strncmp(line, nextKeyWord.c_str(), 9) ) { bool ok = false; if (readString(in, line, 256)) { if (nextKeyWord.compare("cell_data") == 0) { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getVolumeDataContainerName()); m_CurrentAttrMat = m->getAttributeMatrix(getCellAttributeMatrixName()); int32_t ncells = QString(line).toInt(&ok); this->readDataTypeSection(in, ncells, "point_data"); } else if (nextKeyWord.compare("point_data") == 0) { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getVertexDataContainerName()); m_CurrentAttrMat = m->getAttributeMatrix(getVertexAttributeMatrixName()); int32_t npts = QString(line).toInt(&ok); this->readDataTypeSection(in, npts, "cell_data"); } } } else { //vtkErrorMacro(<< "Unsupported point attribute type: " << line //<< " for file: " << (this->FileName?this->FileName:"(Null FileName)")); return 0; } } return 1; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t VtkStructuredPointsReader:: readFile() { int32_t err = 0; DataContainer::Pointer volDc = getDataContainerArray()->getDataContainer(getVolumeDataContainerName()); AttributeMatrix::Pointer volAm = volDc->getAttributeMatrix(getCellAttributeMatrixName()); DataContainer::Pointer vertDc = getDataContainerArray()->getDataContainer(getVertexDataContainerName()); AttributeMatrix::Pointer vertAm = vertDc->getAttributeMatrix(getVertexAttributeMatrixName()); std::ifstream in(getInputFile().toLatin1().constData(), std::ios_base::in | std::ios_base::binary); if (!in.is_open()) { QString msg = QObject::tr("Error opening output file '%1'").arg(getInputFile()); setErrorCondition(-61003); notifyErrorMessage(getHumanLabel(), msg, getErrorCondition()); return -100; } QByteArray buf(kBufferSize, '\0'); char* buffer = buf.data(); err = readLine(in, buffer, kBufferSize); // Read Line 1 - VTK Version Info err = readLine(in, buffer, kBufferSize); // Read Line 2 - User Comment setComment(QString(buf)); err = readLine(in, buffer, kBufferSize); // Read Line 3 - BINARY or ASCII QString fileType(buf); if (fileType.startsWith("BINARY") == true) { setFileIsBinary(true); } else if (fileType.startsWith("ASCII") == true) { setFileIsBinary(false); } else { QString ss = QObject::tr("The file type of the VTK legacy file could not be determined. It should be 'ASCII' or 'BINARY' and should appear on line 3 of the file"); setErrorCondition(-61004); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } // Read Line 4 - Type of Dataset err = readLine(in, buffer, kBufferSize); QList<QByteArray> words = buf.split(' '); if (words.size() != 2) { QString ss = QObject::tr("Error reading the type of data set. Was expecting 2 words but got %1").arg(QString(buf)); setErrorCondition(-61005); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } QString dataset(words.at(1)); dataset = dataset.trimmed(); setDatasetType(dataset); // Should be STRUCTURED_POINTS bool ok = false; err = readLine(in, buffer, kBufferSize); // Read Line 5 which is the Dimension values // But we need the 'extents' which is one less in all directions (unless dim=1) QVector<size_t> dims(3, 0); QList<QByteArray> tokens = buf.split(' '); dims[0] = tokens[1].toInt(&ok, 10); dims[1] = tokens[2].toInt(&ok, 10); dims[2] = tokens[3].toInt(&ok, 10); QVector<size_t> tDims(3, 0); tDims[0] = dims[0]; tDims[1] = dims[1]; tDims[2] = dims[2]; vertAm->setTupleDimensions(tDims); vertDc->getGeometryAs<ImageGeom>()->setDimensions(dims.data()); tDims[0] = dims[0] - 1; tDims[1] = dims[1] - 1; tDims[2] = dims[2] - 1; volAm->setTupleDimensions(tDims); volDc->getGeometryAs<ImageGeom>()->setDimensions(tDims.data()); err = readLine(in, buffer, kBufferSize); // Read Line 7 which is the Scaling values tokens = buf.split(' '); float resolution[3]; resolution[0] = tokens[1].toFloat(&ok); resolution[1] = tokens[2].toFloat(&ok); resolution[2] = tokens[3].toFloat(&ok); volDc->getGeometryAs<ImageGeom>()->setResolution(resolution); vertDc->getGeometryAs<ImageGeom>()->setResolution(resolution); err = readLine(in, buffer, kBufferSize); // Read Line 6 which is the Origin values tokens = buf.split(' '); float origin[3]; origin[0] = tokens[1].toFloat(&ok); origin[1] = tokens[2].toFloat(&ok); origin[2] = tokens[3].toFloat(&ok); volDc->getGeometryAs<ImageGeom>()->setOrigin(origin); vertDc->getGeometryAs<ImageGeom>()->setOrigin(origin); // Read the first key word which should be POINT_DATA or CELL_DATA err = readLine(in, buffer, kBufferSize); // Read Line 6 which is the first type of data we are going to read tokens = buf.split(' '); QString word = QString(tokens[0]); int32_t npts = 0, ncells = 0; int32_t numPts = 0; if ( word.startsWith("CELL_DATA") ) { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getVolumeDataContainerName()); m_CurrentAttrMat = m->getAttributeMatrix(getCellAttributeMatrixName()); ncells = tokens[1].toInt(&ok); if (m_CurrentAttrMat->getNumTuples() != ncells) { setErrorCondition(-61006); notifyErrorMessage(getHumanLabel(), QString("Number of cells does not match number of tuples in the Attribute Matrix"), getErrorCondition()); return getErrorCondition(); } this->readDataTypeSection(in, ncells, "point_data"); } else if ( word.startsWith("POINT_DATA") ) { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getVertexDataContainerName()); m_CurrentAttrMat = m->getAttributeMatrix(getVertexAttributeMatrixName()); npts = tokens[1].toInt(&ok); if (m_CurrentAttrMat->getNumTuples() != npts) { setErrorCondition(-61007); notifyErrorMessage(getHumanLabel(), QString("Number of points does not match number of tuples in the Attribute Matrix"), getErrorCondition()); return getErrorCondition(); } this->readDataTypeSection(in, numPts, "cell_data"); } // Close the file since we are done with it. in.close(); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VtkStructuredPointsReader::dataCheck() { initialize(); setErrorCondition(0); QFileInfo fi(getInputFile()); if (getInputFile().isEmpty() == true) { QString ss = QObject::tr("The input file must be set"); setErrorCondition(-61000); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } else if (fi.exists() == false) { QString ss = QObject::tr("The input file does not exist"); setErrorCondition(-61001); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } // First shot Sanity Checks. if(!getReadCellData() && !getReadPointData()) { QString ss = QObject::tr("At least one of Read Point Data or Read Cell Data must be checked"); setErrorCondition(-61002); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } // Last chance sanity check if(getErrorCondition() < 0) { return; } // Create a Vertex Data Container even though we may remove it later. We need it later // on in order to set the proper AttributeMatrix DataContainer::Pointer pointData_DataContainer = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getVertexDataContainerName()); if(getErrorCondition() < 0 && NULL == pointData_DataContainer) { return; } ImageGeom::Pointer pointDataGeom = ImageGeom::CreateGeometry(getVertexDataContainerName()); pointData_DataContainer->setGeometry(pointDataGeom); QVector<size_t> tDims(1, 0); AttributeMatrix::Pointer pointAttrMat = pointData_DataContainer->createNonPrereqAttributeMatrix<AbstractFilter>(this, getVertexAttributeMatrixName(), tDims, SIMPL::AttributeMatrixType::Cell); if(getErrorCondition() < 0) { return; } // Create a Volume Data Container even though we may remove it later. We need it later // on in order to set the proper AttributeMatrix DataContainer::Pointer cellData_DataContainer = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getVolumeDataContainerName()); if(getErrorCondition() < 0 && NULL == cellData_DataContainer) { return; } ImageGeom::Pointer cellDataGeom = ImageGeom::CreateGeometry(getVolumeDataContainerName()); cellData_DataContainer->setGeometry(cellDataGeom); tDims.resize(3); tDims[0] = 0; tDims[1] = 0; tDims[2] = 0; AttributeMatrix::Pointer cellAttrMat = cellData_DataContainer->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCellAttributeMatrixName(), tDims, SIMPL::AttributeMatrixType::Cell); if(getErrorCondition() < 0) { return; } // Scan through the file readFile(); // now check to see what the user wanted if (!getReadPointData()) { getDataContainerArray()->removeDataContainer(getVertexDataContainerName()); } if (!getReadCellData()) { getDataContainerArray()->removeDataContainer(getVolumeDataContainerName()); } // If there was no Cell Data, remove that dataContainer if (cellAttrMat->getNumAttributeArrays() == 0) { getDataContainerArray()->removeDataContainer(getVolumeDataContainerName()); } // If there were no Point Arrays then remove that dataContainer if (pointAttrMat->getNumAttributeArrays() == 0) { getDataContainerArray()->removeDataContainer(getVertexDataContainerName()); } }