| 116 | } |
| 117 | |
| 118 | void NodeWriter::write_elem_file(const std::string& filename, Mesh& mesh) { |
| 119 | const size_t num_voxels = mesh.get_num_voxels(); |
| 120 | const size_t vertex_per_voxel = mesh.get_vertex_per_voxel(); |
| 121 | if (num_voxels == 0) return; |
| 122 | if (vertex_per_voxel != 4) { |
| 123 | throw IOError("Only tet element is supported in .ele file."); |
| 124 | } |
| 125 | |
| 126 | std::ofstream fout(filename.c_str()); |
| 127 | fout.precision(16); |
| 128 | if (!is_anonymous()) { |
| 129 | fout << "# Generated with PyMesh" << std::endl; |
| 130 | } |
| 131 | VectorF region; |
| 132 | if (m_with_region_attribute) { |
| 133 | if (!mesh.has_attribute("region")) { |
| 134 | throw IOError("Attribute \"region\" does not exist."); |
| 135 | } else { |
| 136 | region = mesh.get_attribute("region"); |
| 137 | assert(num_voxels == region.size()); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | const VectorI& voxels = mesh.get_voxels(); |
| 142 | fout << num_voxels << " 4 " << m_with_region_attribute << std::endl; |
| 143 | for (size_t i=0; i<num_voxels; i++) { |
| 144 | fout << i; |
| 145 | for (size_t j=0; j<4; j++) { |
| 146 | fout << " " << voxels[i*4+ j]; |
| 147 | } |
| 148 | if (m_with_region_attribute) { |
| 149 | fout << " " << region[i]; |
| 150 | } |
| 151 | fout << std::endl; |
| 152 | } |
| 153 | } |
| 154 |
nothing calls this directly
no test coverage detected