| 86 | } |
| 87 | |
| 88 | void PLYWriter::regroup_attribute_names(Mesh& mesh) { |
| 89 | const size_t num_vertices = mesh.get_num_vertices(); |
| 90 | const size_t num_faces = mesh.get_num_faces(); |
| 91 | const size_t num_voxels = mesh.get_num_voxels(); |
| 92 | |
| 93 | m_vertex_attr_names.clear(); |
| 94 | m_face_attr_names.clear(); |
| 95 | m_voxel_attr_names.clear(); |
| 96 | |
| 97 | for (NameArray::const_iterator itr = m_attr_names.begin(); |
| 98 | itr != m_attr_names.end(); itr++) { |
| 99 | const std::string& name = *itr; |
| 100 | if (!mesh.has_attribute(name)) { |
| 101 | std::stringstream err_msg; |
| 102 | err_msg << "Outputing PLY file failed because attribute \"" |
| 103 | << name << "\" does not exist!" << std::endl; |
| 104 | throw RuntimeError(err_msg.str()); |
| 105 | } |
| 106 | |
| 107 | const VectorF& attr = mesh.get_attribute(name); |
| 108 | const size_t attr_size = attr.size(); |
| 109 | if (name.substr(0, 6) == "vertex" && num_vertices > 0 && attr_size % num_vertices == 0) { |
| 110 | m_vertex_attr_names.push_back(name); |
| 111 | } else if (name.substr(0, 4) == "face" && num_faces > 0 && attr_size % num_faces== 0) { |
| 112 | m_face_attr_names.push_back(name); |
| 113 | } else if (name.substr(0, 5) == "voxel" && num_voxels > 0 && attr_size % num_voxels== 0) { |
| 114 | m_voxel_attr_names.push_back(name); |
| 115 | } else if (name == "corner_texture" && num_faces > 0 && attr_size % num_faces == 0) { |
| 116 | m_face_attr_names.push_back(name); |
| 117 | } else { |
| 118 | // Use cardinality to determine attribute type. |
| 119 | if (num_vertices > 0 && attr_size % num_vertices == 0) { |
| 120 | m_vertex_attr_names.push_back(name); |
| 121 | } else if (num_faces > 0 && attr_size % num_faces == 0) { |
| 122 | m_face_attr_names.push_back(name); |
| 123 | } else if (num_voxels > 0 && attr_size % num_voxels == 0) { |
| 124 | m_voxel_attr_names.push_back(name); |
| 125 | } else { |
| 126 | std::cerr << "Unkown attribute type (" << name << ") ignored." |
| 127 | << std::endl; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void PLYWriter::add_vertex_elements_header(Mesh& mesh, p_ply& ply) { |
| 134 | const size_t dim = mesh.get_dim(); |
nothing calls this directly
no test coverage detected