// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void IOSupport::addWarningMessage(const QString& filterName, const QString& warnDescription, int warnCode) { PipelineMessage em(getNameOfClass(), warnDescription, warnCode, PipelineMessage::Warning); em.setFilterHumanLabel(getHumanLabel()); em.setFilterClassName(getNameOfClass()); m_PipelineMessages.push_back(em); }
Box* superRepr(Box* _s) { RELEASE_ASSERT(_s->cls == super_cls, ""); BoxedSuper* s = static_cast<BoxedSuper*>(_s); if (s->obj_type) { return boxStringTwine(llvm::Twine("<super: <class '") + (s->type ? getNameOfClass(s->type) : "NULL") + "'>, <" + getNameOfClass(s->obj_type) + " object>>"); } else { return boxStringTwine(llvm::Twine("<super: <class '") + (s->type ? getNameOfClass(s->type) : "NULL") + "'>, <NULL>>"); } }
extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) { if (!PyType_Check(_cls)) raiseExcHelper(TypeError, "tuple.__new__(X): X is not a type object (%s)", getTypeName(_cls)); BoxedClass* cls = static_cast<BoxedClass*>(_cls); if (!isSubclass(cls, tuple_cls)) raiseExcHelper(TypeError, "tuple.__new__(%s): %s is not a subtype of tuple", getNameOfClass(cls), getNameOfClass(cls)); int args_sz = args->size(); int kwargs_sz = kwargs ? kwargs->d.size() : 0; if (args_sz + kwargs_sz > 1) raiseExcHelper(TypeError, "tuple() takes at most 1 argument (%d given)", args_sz + kwargs_sz); if (args_sz || kwargs_sz) { Box* elements; // if initializing from iterable argument, check common case positional args first if (args_sz) { elements = args->elts[0]; } else { assert(kwargs_sz); auto const seq = *(kwargs->d.begin()); auto const kw = static_cast<BoxedString*>(seq.first.value); if (kw->s() == "sequence") elements = seq.second; else raiseExcHelper(TypeError, "'%s' is an invalid keyword argument for this function", kw->data()); } if (cls == tuple_cls) { // Call PySequence_Tuple since it has some perf special-cases // that can make it quite a bit faster than the generic pyElements iteration: Box* r = PySequence_Tuple(elements); if (!r) throwCAPIException(); return r; } std::vector<Box*, StlCompatAllocator<Box*>> elts; for (auto e : elements->pyElements()) elts.push_back(e); return BoxedTuple::create(elts.size(), &elts[0], cls); } else { if (cls == tuple_cls) return EmptyTuple; return BoxedTuple::create(0, cls); } }
Box* typeRepr(BoxedClass* self) { if (isUserDefined(self)) { std::ostringstream os; os << "<class '"; Box* m = self->getattr("__module__"); RELEASE_ASSERT(m, ""); if (m->cls == str_cls) { BoxedString* sm = static_cast<BoxedString*>(m); os << sm->s << '.'; } Box* n = self->getattr("__name__"); RELEASE_ASSERT(n, ""); RELEASE_ASSERT(n->cls == str_cls, "should have prevented you from setting __name__ to non-string"); BoxedString* sn = static_cast<BoxedString*>(n); os << sn->s; os << "'>"; return boxString(os.str()); } else { char buf[80]; snprintf(buf, 80, "<type '%s'>", getNameOfClass(self)->c_str()); return boxStrConstant(buf); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void IOSupport::addErrorMessage(const QString& filterHumanLabel, const QString& errorDescription, int errorCode) { PipelineMessage em(getNameOfClass(), errorDescription, errorCode, PipelineMessage::Error); em.setFilterHumanLabel(getHumanLabel()); m_PipelineMessages.push_back(em); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void IOSupport::addWarningMessage(PipelineMessage& msg) { msg.setFilterHumanLabel(getHumanLabel()); msg.setFilterClassName(getNameOfClass()); m_PipelineMessages.push_back(msg); }
/** * * @param parentId * @return */ virtual int writeH5Data(hid_t parentId) { int err = 0; // Generate the number of neighbors array and also compute the total number // of elements that would be needed to flatten the array std::vector<int32_t> numNeighbors(_data.size()); size_t total = 0; for(size_t dIdx = 0; dIdx < _data.size(); ++dIdx) { numNeighbors[dIdx] = static_cast<int32_t>(_data[dIdx]->size()); total += _data[dIdx]->size(); } // Check to see if the NumNeighbors is already written to the file bool rewrite = false; if (H5Lite::datasetExists(parentId, DREAM3D::FieldData::NumNeighbors) == false) { rewrite = true; } else { std::vector<int32_t> fileNumNeigh(_data.size()); err = H5Lite::readVectorDataset(parentId, DREAM3D::FieldData::NumNeighbors, fileNumNeigh); if (err < 0) { return -602; } // Compare the 2 vectors to make sure they are exactly the same; if (fileNumNeigh.size() != numNeighbors.size()) { rewrite = true; } // The sizes are the same, now compare each value; int32_t* numNeighPtr = &(numNeighbors.front()); int32_t* fileNumNeiPtr = &(fileNumNeigh.front()); size_t nBytes = numNeighbors.size() * sizeof(int32_t); if (::memcmp(numNeighPtr, fileNumNeiPtr, nBytes) != 0) { rewrite = true; } } // Write out the NumNeighbors Array if(rewrite == true) { std::vector<hsize_t> dims(1, numNeighbors.size()); err = H5Lite::writeVectorDataset(parentId, DREAM3D::FieldData::NumNeighbors, dims, numNeighbors); if(err < 0) { return -603; } err = H5Lite::writeScalarAttribute(parentId, DREAM3D::FieldData::NumNeighbors, std::string(H5_NUMCOMPONENTS), 1); if(err < 0) { return -605; } err = H5Lite::writeStringAttribute(parentId, DREAM3D::FieldData::NumNeighbors, DREAM3D::HDF5::ObjectType, "DataArray<T>"); if(err < 0) { return -604; } } // Allocate an array of the proper size to we can concatenate all the arrays together into a single array that // can be written to the HDF5 File. This operation can ballon the memory size temporarily until this operation // is complete. std::vector<T> flat (total); size_t currentStart = 0; for(size_t dIdx = 0; dIdx < _data.size(); ++dIdx) { size_t nEle = _data[dIdx]->size(); if (nEle == 0) { continue; } T* start = &(_data[dIdx]->front()); // Get the pointer to the front of the array // T* end = start + nEle; // Get the pointer to the end of the array T* dst = &(flat.front()) + currentStart; ::memcpy(dst, start, nEle*sizeof(T)); currentStart += _data[dIdx]->size(); } int32_t rank = 1; hsize_t dims[1] = { total }; if (total > 0) { err = H5Lite::writePointerDataset(parentId, GetName(), rank, dims, &(flat.front())); if(err < 0) { return -605; } err = H5Lite::writeScalarAttribute(parentId, GetName(), std::string(H5_NUMCOMPONENTS), 1); if(err < 0) { return -606; } err = H5Lite::writeStringAttribute(parentId, GetName(), DREAM3D::HDF5::ObjectType, getNameOfClass()); if(err < 0) { return -607; } err = H5Lite::writeStringAttribute(parentId, GetName(), "Linked NumNeighbors Dataset", DREAM3D::FieldData::NumNeighbors); if(err < 0) { return -608; } } return err; }
/** * @brief writeXdmfAttribute * @param out * @param volDims * @param hdfFileName * @param groupPath * @return */ virtual int writeXdmfAttribute(QTextStream& out, int64_t* volDims, const QString& hdfFileName, const QString& groupPath, const QString& labelb) { out << "<!-- Xdmf is not supported for " << getNameOfClass() << " with type " << getTypeAsString() << " --> "; return -1; }
/** * @brief GetTypeName Returns a string representation of the type of data that is stored by this class. This * can be a primitive like char, float, int or the name of a class. * @return */ void getXdmfTypeAndSize(QString& xdmfTypeName, int& precision) { xdmfTypeName = getNameOfClass(); precision = 0; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void InitialReconstructionInitializer::execute() { SinogramPtr sinogram = getSinogram(); TomoInputsPtr input = getTomoInputs(); GeometryPtr geometry = getGeometry(); AdvancedParametersPtr advParams = getAdvParams(); Real_t sum = 0, max; #ifndef FORWARD_PROJECT_MODE input->delta_xz = sinogram->delta_r * input->delta_xz; input->delta_xy = input->delta_xz; //Find the maximum absolute tilt angle max = absMaxArray(sinogram->angles); //The max is going to be used to reconstruct a large area //However if its close to 90 this would result in a very large value - so truncate if(max > MBIR::Constants::k_MaxAngleStretch) { max = MBIR::Constants::k_MaxAngleStretch; } // Convert Max to radians max = max * M_PI / 180.0; input->LengthZ *= advParams->Z_STRETCH; input->LengthZ /= (input->interpolateFactor * sinogram->delta_r); //interpolation_factor; input->LengthZ = floor(input->LengthZ + 0.5) * input->interpolateFactor * sinogram->delta_r; //interpolation_factor; geometry->LengthX = ((sinogram->N_r * sinogram->delta_r)); geometry->N_x = floor(geometry->LengthX / input->delta_xz); //Number of voxels in x direction if(1 == input->extendObject) { std::cout << "KNOWN BUG FIX NEEDED HERE IF MAX = 90 degrees" << std::endl; geometry->LengthX = advParams->X_SHRINK_FACTOR * ((sinogram->N_r * sinogram->delta_r) / cos(max)) + input->LengthZ * tan(max); geometry->LengthX /= (input->interpolateFactor * sinogram->delta_r); geometry->LengthX = floor(geometry->LengthX + 0.5) * input->interpolateFactor * sinogram->delta_r; } #else geometry->LengthX = ((sinogram->N_r * sinogram->delta_r)); #endif//Forward projector mode end if // Geometry->LengthY = (Geometry->EndSlice- Geometry->StartSlice)*Geometry->delta_xy; geometry->LengthY = (input->yEnd - input->yStart + 1) * sinogram->delta_t; geometry->N_x = floor(geometry->LengthX / input->delta_xz); //Number of voxels in x direction geometry->N_z = floor(input->LengthZ / input->delta_xz); //Number of voxels in z direction geometry->N_y = floor(geometry->LengthY / input->delta_xy); //Number of measurements in y direction std::stringstream ss; ss << "Geometry->LengthX=" << geometry->LengthX << " nm" << std::endl; ss << "Geometry->LengthY=" << geometry->LengthY << " nm" << std::endl; ss << "Geometry->LengthZ=" << input->LengthZ << " nm" << std::endl; ss << "Geometry->Nz=" << geometry->N_z << std::endl; ss << "Geometry->Nx=" << geometry->N_x << std::endl; ss << "Geometry->Ny=" << geometry->N_y << std::endl; size_t dims[3] = { geometry->N_z, geometry->N_x, geometry->N_y }; geometry->Object = RealVolumeType::New(dims, "Geometry.Object"); // geometry->Object = (DATA_TYPE ***)get_3D(geometry->N_z, geometry->N_x, geometry->N_y, sizeof(DATA_TYPE));//Allocate space for the 3-D object //Coordinates of the left corner of the x-z object geometry->x0 = -geometry->LengthX / 2; geometry->z0 = -input->LengthZ / 2; // Geometry->y0 = -(sinogram->N_t * sinogram->delta_t)/2 + Geometry->StartSlice*Geometry->delta_xy; geometry->y0 = -(geometry->LengthY) / 2; ss << "Geometry->X0=" << geometry->x0 << std::endl; ss << "Geometry->Y0=" << geometry->y0 << std::endl; ss << "Geometry->Z0=" << geometry->z0 << std::endl; if(getVeryVerbose()) { std::cout << ss.str() << std::endl; } // Now we actually initialize the data to something. If a subclass is involved // then the subclasses version of initializeData() will be used instead initializeData(); //Doing a check sum to verify with matlab for (uint16_t y = 0; y < geometry->N_y; y++) { sum = 0; for (uint16_t x = 0; x < geometry->N_x; x++) { for (uint16_t z = 0; z < geometry->N_z; z++) { // sum += geometry->Object->d[k][j][i]; sum += geometry->Object->getValue(z, x, y); } } ss << "Geometry check sum Y:" << y << " Value:" << sum << std::endl; } //End of check sum if (getVeryVerbose()) { std::cout << ss.str() << std::endl; } setErrorCondition(0); setErrorMessage(""); ss.str(""); ss << getNameOfClass() << " Complete"; notify(ss.str(), 0, UpdateProgressMessage); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int main(int argc, char** argv) { std::cout << "Starting Conversion of H5Voxel to VTK with Feature ID and IPF Colors" << std::endl; if (argc < 3) { std::cout << "This program takes 2 arguments: Input .h5voxel file and output vtk file." << std::endl; return EXIT_FAILURE; } QString iFile = argv[1]; int err = 0; DataContainerArray::Pointer dca = DataContainerArray::New(); VolumeDataContainer::Pointer m = VolumeDataContainer::New(); dca->pushBack(m); DataContainerReader::Pointer h5Reader = DataContainerReader::New(); h5Reader->setInputFile(iFile); h5Reader->setDataContainerArray(dca); size_t dcDims[3]; float spacing[3]; float origin[3]; h5Reader->execute(); err = h5Reader->getErrorCondition(); if (err < 0) { setErrorCondition(err); // addErrorMessages(h5Reader->getErrorMessages()); return EXIT_FAILURE; } m->getDimensions(dcDims); m->getResolution(spacing); m->getOrigin(origin); int64_t dims[3] = {dcDims[0], dcDims[1], dcDims[2]}; /* Sanity check what we are trying to load to make sure it can fit in our address space. * Note that this does not guarantee the user has enough left, just that the * size of the volume can fit in the address space of the program */ #if (CMP_SIZEOF_SSIZE_T==4) int64_t max = std::numeric_limits<size_t>::max(); #else int64_t max = std::numeric_limits<int64_t>::max(); #endif if (dims[0] * dims[1] * dims[2] > max ) { err = -1; std::stringstream s; s << "The total number of elements '" << (dims[0] * dims[1] * dims[2]) << "' is greater than this program can hold. Try the 64 bit version."; setErrorCondition(err); setErrorMessage(s.str()); return EXIT_FAILURE; } if (dims[0] > max || dims[1] > max || dims[2] > max) { err = -1; std::stringstream s; s << "One of the dimensions is greater than the max index for this sysem. Try the 64 bit version."; s << " dim[0]=" << dims[0] << " dim[1]=" << dims[1] << " dim[2]=" << dims[2]; setErrorCondition(err); setErrorMessage(s.str()); return EXIT_FAILURE; } /* ************ End Sanity Check *************************** */ std::stringstream ss; std::cout << "Writing VTK file" << std::endl; FILE* f = fopen(argv[2], "wb"); WRITE_STRUCTURED_POINTS_HEADER("ASCII", m) // VoxelIPFColorScalarWriter<VolumeDataContainer> ipfWriter(m.get()); // ipfWriter.m_WriteBinaryFiles = false; // ipfWriter.writeScalars(f); int64_t totalPoints = m->getTotalPoints(); int32_t* m_FeatureIds = NULL; m_FeatureIds = m->getCellDataSizeCheck<int32_t, Int32ArrayType, AbstractFilter>(SIMPL::CellData::FeatureIds, totalPoints, 1, NULL); if (0 == m_FeatureIds ) { ss << "Filter " << getNameOfClass() << " requires the data array '" << "DREAM3D" << "::" << "CellData" << "::" << "FeatureIds" << "' to already be created prior to execution." << std::endl; setErrorCondition(-300); } WRITE_VTK_GRAIN_IDS_ASCII(m, SIMPL::CellData::FeatureIds, m_FeatureIds) fclose(f); std::cout << "Done Converting" << std::endl; return EXIT_SUCCESS; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int BinaryNodesTrianglesReader::read() { SurfaceMeshDataContainer *sm = getSurfaceMeshDataContainer(); int err = 0; setErrorCondition(err); std::stringstream s; // Open the Nodes file for reading FILE* nodesFile = fopen(m_BinaryNodesFile.c_str(), "rb+"); if(nodesFile == NULL) { s.str(""); s << "Error opening nodes file '" << m_BinaryNodesFile << "'"; setErrorCondition(786); // PipelineMessage em (getHumanLabel(), s.str(), -1); // addErrorMessage(em); // notifyMessage(em); return getErrorCondition(); } ScopedFileMonitor nodesMonitor(nodesFile); // Calculate how many nodes are in the file based on the file size fseek(nodesFile, 0, SEEK_END); size_t fLength = ftell(nodesFile); size_t nNodes = fLength / SurfaceMesh::NodesFile::ByteCount; fseek(nodesFile, 0, SEEK_SET); fLength = ftell(nodesFile); if(0 != fLength) { s.str(""); s << getNameOfClass() << ": Error Could not rewind to beginning of file after nodes count.'" << m_BinaryNodesFile << "'"; setErrorCondition(787); // PipelineMessage em (getHumanLabel(), s.str(), -1); // addErrorMessage(em); // notifyMessage(em); return getErrorCondition(); } s.str(""); s << "Calc Node Count from Nodes.bin File: " << nNodes; notifyStatusMessage(s.str()); // Open the triangles file for reading FILE* triFile = fopen(m_BinaryTrianglesFile.c_str(), "rb+"); if(triFile == NULL) { s.str(""); s << getNameOfClass() << ": Error opening Triangles file '" << m_BinaryTrianglesFile << "'"; setErrorCondition(788); // PipelineMessage em (getHumanLabel(), s.str(), -1); // addErrorMessage(em); // notifyMessage(em); return getErrorCondition(); } ScopedFileMonitor trianglesMonitor(triFile); // Calculate how many Triangles are in the file based in the file size fseek(triFile, 0, SEEK_END); fLength = ftell(triFile); size_t nTriangles = fLength / SurfaceMesh::TrianglesFile::ByteCount; fseek(triFile, 0, SEEK_SET); fLength = ftell(triFile); if(0 != fLength) { s.str(""); s << getNameOfClass() << ": Error Could not rewind to beginning of file after triangles count.'" << m_BinaryTrianglesFile << "'"; setErrorCondition(789); // PipelineMessage em (getHumanLabel(), s.str(), -1); // addErrorMessage(em); // notifyMessage(em); return getErrorCondition(); } s.str(""); s << "Calc Triangle Count from Triangles.bin File: " << nTriangles; notifyStatusMessage(s.str()); // Allocate all the nodes typedef DREAM3D::SurfaceMesh::Vert_t Vert_t; StructArray<Vert_t>::Pointer m_NodeListPtr = StructArray<Vert_t>::CreateArray(nNodes, DREAM3D::VertexData::SurfaceMeshNodes); Vert_t* m_NodeList = m_NodeListPtr->GetPointer(0); Int8ArrayType::Pointer nodeTypePtr = Int8ArrayType::CreateArray(nNodes, 1, DREAM3D::VertexData::SurfaceMeshNodeType); nodeTypePtr->initializeWithZeros(); int8_t* nodeType = nodeTypePtr->GetPointer(0); s.str(""); s << "Reading Nodes file into Memory"; notifyStatusMessage(s.str()); size_t nread = 0; SurfaceMesh::NodesFile::NodesFileRecord_t nRecord; for (size_t i = 0; i < nNodes; i++) { nread = fread(&nRecord, SurfaceMesh::NodesFile::ByteCount, 1, nodesFile); // Read one set of positions from the nodes file if(nread != 1) { break; } DREAM3D::SurfaceMesh::Vert_t& node = m_NodeList[nRecord.nodeId]; node.pos[0] = nRecord.x; node.pos[1] = nRecord.y; node.pos[2] = nRecord.z; nodeType[nRecord.nodeId] = nRecord.nodeKind; } s.str(""); s << "Reading Triangles file into Memory"; notifyStatusMessage(s.str()); // Allocate all the Triangle Objects typedef DREAM3D::SurfaceMesh::Face_t Face_t; StructArray<Face_t>::Pointer m_TriangleListPtr = StructArray<Face_t>::CreateArray(nTriangles, DREAM3D::FaceData::SurfaceMeshFaces); Face_t* m_TriangleList = m_TriangleListPtr->GetPointer(0); ::memset(m_TriangleList, 0xAB, sizeof(Face_t) * nTriangles); DataArray<int32_t>::Pointer faceLabelPtr = DataArray<int32_t>::CreateArray(nTriangles, 2, DREAM3D::FaceData::SurfaceMeshFaceLabels); int32_t* faceLabels = faceLabelPtr->GetPointer(0); faceLabelPtr->initializeWithZeros(); SurfaceMesh::TrianglesFile::TrianglesFileRecord_t tRecord; for (size_t i = 0; i < nTriangles; i++) { // Read from the Input Triangles Temp File nread = fread(&tRecord, SurfaceMesh::TrianglesFile::ByteCount, 1, triFile); if(nread != 1) { break; } DREAM3D::SurfaceMesh::Face_t& triangle = m_TriangleList[tRecord.triId]; triangle.verts[0] = tRecord.nodeId_0; triangle.verts[1] = tRecord.nodeId_1; triangle.verts[2] = tRecord.nodeId_2; faceLabels[tRecord.triId * 2] = tRecord.label_0; faceLabels[tRecord.triId * 2 + 1] = tRecord.label_1; } sm->setVertices(m_NodeListPtr); sm->setFaces(m_TriangleListPtr); sm->addFaceData(faceLabelPtr->GetName(), faceLabelPtr); sm->addVertexData(nodeTypePtr->GetName(), nodeTypePtr); // The ScopedFileMonitor classes will take care of closing the files return getErrorCondition(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ModifiedLambertProjectionArray::getXdmfTypeAndSize(QString& xdmfTypeName, int& precision) { xdmfTypeName = getNameOfClass(); precision = 0; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsDataArray::getXdmfTypeAndSize(QString& xdmfTypeName, int& precision) { xdmfTypeName = getNameOfClass(); precision = 0; }