// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void GoldfeatherReader::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer(); if (getInputFile().empty() == true) { ss << ClassName() << " needs the Input File Set and it was not."; setErrorCondition(-387); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } else if (MXAFileInfo::exists(getInputFile()) == false) { ss << "The input file does not exist."; setErrorCondition(-388); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } DREAM3D::SurfaceMesh::VertListPointer_t vertices = DREAM3D::SurfaceMesh::VertList_t::CreateArray(1, DREAM3D::VertexData::SurfaceMeshNodes); DREAM3D::SurfaceMesh::FaceListPointer_t triangles = DREAM3D::SurfaceMesh::FaceList_t::CreateArray(1, DREAM3D::FaceData::SurfaceMeshFaces); sm->setVertices(vertices); sm->setFaces(triangles); DoubleArrayType::Pointer normalsPtr = DoubleArrayType::CreateArray(1, 3, DREAM3D::VertexData::SurfaceMeshNodeNormals); //addCreatedCellData( normalsPtr->GetName()); sm->addVertexData(normalsPtr->GetName(), normalsPtr); DoubleArrayType::Pointer pcurv1Ptr = DoubleArrayType::CreateArray(1, 1, "Principal_Curvature_1"); //addCreatedCellData( pcurv1Ptr->GetName()); sm->addVertexData(pcurv1Ptr->GetName(), pcurv1Ptr); DoubleArrayType::Pointer pcurv2Ptr = DoubleArrayType::CreateArray(1, 1, "Principal_Curvature_2"); // addCreatedCellData( pcurv2Ptr->GetName()); sm->addVertexData(pcurv2Ptr->GetName(), pcurv2Ptr); DoubleArrayType::Pointer pDirection1Ptr = DoubleArrayType::CreateArray(1, 3, "Principal_Direction_1"); // addCreatedCellData( pDirection1Ptr->GetName()); sm->addVertexData(pDirection1Ptr->GetName(), pDirection1Ptr); DoubleArrayType::Pointer pDirection2Ptr = DoubleArrayType::CreateArray(1, 3, "Principal_Direction_2"); // addCreatedCellData( pDirection2Ptr->GetName()); sm->addVertexData(pDirection2Ptr->GetName(), pDirection2Ptr); DataArray<int32_t>::Pointer faceLabelPtr = DataArray<int32_t>::CreateArray(1, 2, DREAM3D::FaceData::SurfaceMeshFaceLabels); // addCreatedFieldData( faceLabelPtr->GetName()); sm->addFaceData(faceLabelPtr->GetName(), faceLabelPtr); DoubleArrayType::Pointer triNormalsPtr = DoubleArrayType::CreateArray(1, 3, DREAM3D::FaceData::SurfaceMeshFaceNormals); // addCreatedFieldData( triNormalsPtr->GetName()); sm->addFaceData(triNormalsPtr->GetName(), triNormalsPtr); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void GoldfeatherReader::execute() { int err = 0; std::stringstream ss; setErrorCondition(err); SurfaceMeshDataContainer* m = getSurfaceMeshDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The Voxel DataContainer Object was NULL", -999); return; } setErrorCondition(0); FILE* f = fopen(m_InputFile.c_str(), "r"); if (NULL == f) { setErrorCondition(-999); notifyErrorMessage("Error opening Input file", getErrorCondition()); return; } ScopedFileMonitor fileMonitor(f); int nNodes = 0; fscanf(f, "%d\n", &nNodes); dataCheck(false, nNodes, 1, 1); // Allocate the Nodes, Normals, curvatures and principal direction vectors DREAM3D::SurfaceMesh::VertListPointer_t nodesPtr = DREAM3D::SurfaceMesh::VertList_t::CreateArray(nNodes, DREAM3D::VertexData::SurfaceMeshNodes); nodesPtr->initializeWithZeros(); DREAM3D::SurfaceMesh::Vert_t* nodes = nodesPtr->GetPointer(0); DoubleArrayType::Pointer normalsPtr = DoubleArrayType::CreateArray(nNodes, 3, DREAM3D::VertexData::SurfaceMeshNodeNormals); double* normals = normalsPtr->GetPointer(0); DoubleArrayType::Pointer pcurv1Ptr = DoubleArrayType::CreateArray(nNodes, 1, "Principal_Curvature_1"); double* pcurv1 = pcurv1Ptr->GetPointer(0); DoubleArrayType::Pointer pcurv2Ptr = DoubleArrayType::CreateArray(nNodes, 1, "Principal_Curvature_2"); double* pcurv2 = pcurv2Ptr->GetPointer(0); DoubleArrayType::Pointer pDirection1Ptr = DoubleArrayType::CreateArray(nNodes, 3, "Principal_Direction_1"); double* pDirection1 = pDirection1Ptr->GetPointer(0); DoubleArrayType::Pointer pDirection2Ptr = DoubleArrayType::CreateArray(nNodes, 3, "Principal_Direction_2"); double* pDirection2 = pDirection2Ptr->GetPointer(0); float x, y, z, n0, n1, n2, p1, p2; for(int n = 0; n < nNodes; ++n) { fscanf(f, "%f %f %f %f %f %f %f %f\n", &x, &y, &z, &n0, &n1, &n2, &p1, &p2); nodes[n].pos[0] = x; nodes[n].pos[1] = y; nodes[n].pos[2] = z; normals[n*3+0] = n0; normals[n*3+1] = n1; normals[n*3+2] = n2; pcurv1[n] = p1; pcurv2[n] = p2; // Read the next line of the data which is the principal direction vectors fscanf(f, "%f %f %f %f %f %f\n", &x, &y, &z, &n0, &n1, &n2); pDirection1[n*3+0] = x; pDirection1[n*3+1] = y; pDirection1[n*3+2] = z; pDirection2[n*3+0] = n0; pDirection2[n*3+1] = n1; pDirection2[n*3+2] = n2; } m->setVertices(nodesPtr); m->addVertexData(normalsPtr->GetName(), normalsPtr); m->addVertexData(pcurv1Ptr->GetName(), pcurv1Ptr); m->addVertexData(pcurv2Ptr->GetName(), pcurv2Ptr); m->addVertexData(pDirection1Ptr->GetName(), pDirection1Ptr); m->addVertexData(pDirection2Ptr->GetName(), pDirection2Ptr); int nTriangles = 0; err = fscanf(f, "%d\n", &nTriangles); if (err < 0) { off_t fpos; fpos = ftell(f); setErrorCondition(-876); notifyErrorMessage("Error Reading the number of Triangles from the file", getErrorCondition()); return; } DREAM3D::SurfaceMesh::FaceListPointer_t trianglesPtr = DREAM3D::SurfaceMesh::FaceList_t::CreateArray(nTriangles, DREAM3D::FaceData::SurfaceMeshFaces); trianglesPtr->initializeWithZeros(); DREAM3D::SurfaceMesh::Face_t* triangles = trianglesPtr->GetPointer(0); DataArray<int32_t>::Pointer faceLabelPtr = DataArray<int32_t>::CreateArray(nTriangles, 2, DREAM3D::FaceData::SurfaceMeshFaceLabels); faceLabelPtr->initializeWithZeros(); int32_t* faceLabels = faceLabelPtr->GetPointer(0); DoubleArrayType::Pointer triNormalsPtr = DoubleArrayType::CreateArray(nTriangles, 3, DREAM3D::FaceData::SurfaceMeshFaceNormals); double* triNormals = triNormalsPtr->GetPointer(0); for(int t = 0; t < nTriangles; ++t) { fscanf(f, "%f %f %f %f %f %f", &x, &y, &z, &n0, &n1, &n2); triangles[t].verts[0] = x; triangles[t].verts[1] = y; triangles[t].verts[2] = z; // triangles[t].tIndex = t; faceLabels[t*2] = 0; faceLabels[t*2+1] = 1; triNormals[t*3+0] = n0; triNormals[t*3+1] = n1; triNormals[t*3+2] = n2; } m->setFaces(trianglesPtr); m->addFaceData(faceLabelPtr->GetName(), faceLabelPtr); m->addFaceData(triNormalsPtr->GetName(), triNormalsPtr); /* Let the GUI know we are done with this filter */ notifyStatusMessage("Complete"); }
void ConvertData(T* ptr, VoxelDataContainer* m, int32_t scalarType, const std::string &name) { int numberOfComponents = ptr->GetNumberOfComponents(); int voxels = ptr->GetNumberOfTuples(); size_t size = ptr->GetSize(); if (scalarType == Detail::Int8) { Int8ArrayType::Pointer p = Int8ArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } else if (scalarType == Detail::UInt8) { UInt8ArrayType::Pointer p = UInt8ArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } else if (scalarType == Detail::Int16) { Int16ArrayType::Pointer p = Int16ArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } else if (scalarType == Detail::UInt16) { UInt16ArrayType::Pointer p = UInt16ArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } else if (scalarType == Detail::Int32) { Int32ArrayType::Pointer p = Int32ArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } else if (scalarType == Detail::UInt32) { UInt32ArrayType::Pointer p = UInt32ArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } else if (scalarType == Detail::Int64) { Int64ArrayType::Pointer p = Int64ArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } else if (scalarType == Detail::UInt64) { UInt64ArrayType::Pointer p = UInt64ArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } else if (scalarType == Detail::Float) { FloatArrayType::Pointer p = FloatArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); } else if (scalarType == Detail::Double) { DoubleArrayType::Pointer p = DoubleArrayType::CreateArray(voxels, numberOfComponents, name); m->addCellData(p->GetName(), p); for(size_t v = 0; v < size; ++v) { p->SetValue(v, ptr->GetValue(v) ); } } }