//------------- Undersampling Simulation ------------- void IMT_MRGui::simu_undersampling(agile::GPUMatrix<TType>* Coil, unsigned num_coils) { unsigned num_rows = Coil->getNumRows(); unsigned num_columns = Coil->getNumColumns(); agile::GPUMatrix<TType_real> Simul_matrix; std::vector<TType_real> simul_vector; std::vector<TType_real> simul_vector_2; simul_vector.clear(); for(int r=0; r<num_rows; ++r) { if( ((r % _factor_y) == 0) || ((r >= (num_rows-_ref_lines)/2) && (r < (num_rows+_ref_lines)/2)) ) for(int c=0; c<num_columns; ++c) { if( ((c % _factor_x) == 0) || ((c >= (num_columns-_ref_lines)/2) && (c < (num_columns+_ref_lines)/2)) ) simul_vector.push_back(1); else simul_vector.push_back(0); } else for(int c=0; c<num_columns; ++c) { simul_vector.push_back(0); } } unsigned num_rows_2; unsigned num_columns_2; bool fileexist = true; QString path="simul_pattern.bin"; std::ifstream mat_file(path.toStdString().c_str(), std::ifstream::binary); if (!mat_file.is_open()) //check if file exists fileexist=false; else agile::readMatrixFile(path.toStdString().c_str(), num_rows_2, num_columns_2, simul_vector_2); if(fileexist && ((num_rows_2 != num_rows)||(num_columns_2 != num_columns))) { Simul_matrix.assignFromHost(num_rows, num_columns, &zero_vec_cpu_[0]); std::cerr<<"\n Simulation Pattern Matrix Dimension problem - check simul_pattern.bin"; } else if(fileexist) { Simul_matrix.assignFromHost(num_rows, num_columns, &simul_vector_2[0]); qDebug()<<"\n Simulation Pattern Matrix - simul_pattern.bin - assigned"; } else // assign calculated simul_vector Simul_matrix.assignFromHost(num_rows, num_columns, &simul_vector[0]); for(int i=0; i<num_coils; ++i) { agile::multiplyElementwise(Simul_matrix, Coil[i], Coil[i]); } }
void OBJWriter::write(const std::vector<boost::shared_ptr<glutils::Face> >& faces, const std::string& filename) { std::ofstream file(filename); std::ofstream mat_file(filename + ".mtl"); boost::filesystem::path p(filename + ".mtl"); file << "mtllib " << p.filename().string() << std::endl; file << std::endl; file << "# List of geometric vertices" << std::endl; for (int j = 0; j < faces.size(); ++j) { for (int k = 0; k < faces[j]->vertices.size(); ++k) { file << "v " << faces[j]->vertices[k].position.x << " " << faces[j]->vertices[k].position.y << " " << faces[j]->vertices[k].position.z << std::endl; } } file << std::endl; file << "# List of texture coordinates" << std::endl; for (int j = 0; j < faces.size(); ++j) { if (faces[j]->vertices.size() < 3) continue; if (faces[j]->vertices[0].texCoord.x == 0 && faces[j]->vertices[0].texCoord.y == 0 && faces[j]->vertices[1].texCoord.x == 0 && faces[j]->vertices[1].texCoord.y == 0 && faces[j]->vertices[2].texCoord.x == 0 && faces[j]->vertices[2].texCoord.y == 0) continue; for (int k = 0; k < faces[j]->vertices.size(); ++k) { file << "vt " << faces[j]->vertices[k].texCoord.x << " " << faces[j]->vertices[k].texCoord.y << std::endl; } } file << std::endl; file << "# List of vertex normals" << std::endl; for (int j = 0; j < faces.size(); ++j) { for (int k = 0; k < faces[j]->vertices.size(); ++k) { file << "vn " << faces[j]->vertices[k].normal.x << " " << faces[j]->vertices[k].normal.y << " " << faces[j]->vertices[k].normal.z << std::endl; } } file << std::endl; int positionId = 1; int texCoordId = 1; int materialId = 1; Material material; for (int j = 0; j < faces.size(); ++j) { if (faces[j]->vertices.size() < 3) continue; bool textureEnabled = true; if (faces[j]->texture.empty()) { textureEnabled = false; } if (faces[j]->vertices[0].texCoord.x == 0 && faces[j]->vertices[0].texCoord.y == 0 && faces[j]->vertices[1].texCoord.x == 0 && faces[j]->vertices[1].texCoord.y == 0 && faces[j]->vertices[2].texCoord.x == 0 && faces[j]->vertices[2].texCoord.y == 0) { textureEnabled = false; } Material new_material; if (textureEnabled) { new_material = Material(faces[j]->texture); } else { new_material = Material(faces[j]->vertices[0].color); } if (!new_material.equals(material)) { material = new_material; mat_file << "newmtl Material" << materialId << std::endl; mat_file << material.to_string() << std::endl; file << std::endl; file << "usemtl Material" << materialId << std::endl; materialId++; } for (int k = 0; k < faces[j]->vertices.size() / 3; ++k) { file << "f "; for (int l = 0; l < 3; ++l) { if (l > 0) { file << " "; } file << positionId; file << "/"; if (faces[j]->vertices[k].texCoord.x != 0 || faces[j]->vertices[k].texCoord.y != 0 || faces[j]->vertices[k + 1].texCoord.x != 0 || faces[j]->vertices[k + 1].texCoord.y != 0 || faces[j]->vertices[k + 2].texCoord.x != 0 || faces[j]->vertices[k + 2].texCoord.y != 0) { file << texCoordId++; } file << "/" << positionId++; } file << std::endl; } } file.close(); }