Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/mesh/mesh_misc_functions.h
- This file was moved from extern/draco/dracoenc/src/draco/mesh/mesh_misc_functions.h.
| Show All 23 Lines | |||||
| // The file contains functions that use both Mesh and CornerTable as inputs. | // The file contains functions that use both Mesh and CornerTable as inputs. | ||||
| namespace draco { | namespace draco { | ||||
| // Creates a CornerTable from the position attribute of |mesh|. Returns nullptr | // Creates a CornerTable from the position attribute of |mesh|. Returns nullptr | ||||
| // on error. | // on error. | ||||
| std::unique_ptr<CornerTable> CreateCornerTableFromPositionAttribute( | std::unique_ptr<CornerTable> CreateCornerTableFromPositionAttribute( | ||||
| const Mesh *mesh); | const Mesh *mesh); | ||||
| // Creates a CornerTable from the first named attribute of |mesh| with a given | |||||
| // type. Returns nullptr on error. | |||||
| std::unique_ptr<CornerTable> CreateCornerTableFromAttribute( | |||||
| const Mesh *mesh, GeometryAttribute::Type type); | |||||
| // Creates a CornerTable from all attributes of |mesh|. Boundaries are | // Creates a CornerTable from all attributes of |mesh|. Boundaries are | ||||
| // automatically introduced on all attribute seams. Returns nullptr on error. | // automatically introduced on all attribute seams. Returns nullptr on error. | ||||
| std::unique_ptr<CornerTable> CreateCornerTableFromAllAttributes( | std::unique_ptr<CornerTable> CreateCornerTableFromAllAttributes( | ||||
| const Mesh *mesh); | const Mesh *mesh); | ||||
| // Returns true when the given corner lies opposite to an attribute seam. | // Returns true when the given corner lies opposite to an attribute seam. | ||||
| inline bool IsCornerOppositeToAttributeSeam(CornerIndex ci, | inline bool IsCornerOppositeToAttributeSeam(CornerIndex ci, | ||||
| const PointAttribute &att, | const PointAttribute &att, | ||||
| const Mesh &mesh, | const Mesh &mesh, | ||||
| const CornerTable &ct) { | const CornerTable &ct) { | ||||
| const CornerIndex opp_ci = ct.Opposite(ci); | const CornerIndex opp_ci = ct.Opposite(ci); | ||||
| if (opp_ci == kInvalidCornerIndex) | if (opp_ci == kInvalidCornerIndex) { | ||||
| return false; // No opposite corner == no attribute seam. | return false; // No opposite corner == no attribute seam. | ||||
| } | |||||
| // Compare attribute value indices on both ends of the opposite edge. | // Compare attribute value indices on both ends of the opposite edge. | ||||
| CornerIndex c0 = ct.Next(ci); | CornerIndex c0 = ct.Next(ci); | ||||
| CornerIndex c1 = ct.Previous(opp_ci); | CornerIndex c1 = ct.Previous(opp_ci); | ||||
| if (att.mapped_index(mesh.CornerToPointId(c0)) != | if (att.mapped_index(mesh.CornerToPointId(c0)) != | ||||
| att.mapped_index(mesh.CornerToPointId(c1))) | att.mapped_index(mesh.CornerToPointId(c1))) { | ||||
| return true; | return true; | ||||
| } | |||||
| c0 = ct.Previous(ci); | c0 = ct.Previous(ci); | ||||
| c1 = ct.Next(opp_ci); | c1 = ct.Next(opp_ci); | ||||
| if (att.mapped_index(mesh.CornerToPointId(c0)) != | if (att.mapped_index(mesh.CornerToPointId(c0)) != | ||||
| att.mapped_index(mesh.CornerToPointId(c1))) | att.mapped_index(mesh.CornerToPointId(c1))) { | ||||
| return true; | return true; | ||||
| } | |||||
| return false; | return false; | ||||
| } | } | ||||
| // Interpolates an attribute value on a face using given barycentric | // Interpolates an attribute value on a face using given barycentric | ||||
| // coordinates. InterpolatedVectorT should be a VectorD that corresponds to the | // coordinates. InterpolatedVectorT should be a VectorD that corresponds to the | ||||
| // values stored in the attribute. | // values stored in the attribute. | ||||
| // TODO(ostava): Find a better place for this. | // TODO(ostava): Find a better place for this. | ||||
| template <typename InterpolatedVectorT> | template <typename InterpolatedVectorT> | ||||
| InterpolatedVectorT ComputeInterpolatedAttributeValueOnMeshFace( | InterpolatedVectorT ComputeInterpolatedAttributeValueOnMeshFace( | ||||
| const Mesh &mesh, const PointAttribute &attribute, FaceIndex fi, | const Mesh &mesh, const PointAttribute &attribute, FaceIndex fi, | ||||
| const std::array<float, 3> &barycentric_coord) { | const std::array<float, 3> &barycentric_coord) { | ||||
| const Mesh::Face &face = mesh.face(fi); | const Mesh::Face &face = mesh.face(fi); | ||||
| // Get values for all three corners of the face. | // Get values for all three corners of the face. | ||||
| InterpolatedVectorT val[3]; | InterpolatedVectorT val[3]; | ||||
| for (int c = 0; c < 3; ++c) { | for (int c = 0; c < 3; ++c) { | ||||
| attribute.GetMappedValue(face[c], &(val[c][0])); | attribute.GetMappedValue(face[c], &(val[c][0])); | ||||
| } | } | ||||
| // Return an interpolated value. | // Return an interpolated value. | ||||
| return barycentric_coord[0] * val[0] + barycentric_coord[1] * val[1] + | InterpolatedVectorT res; | ||||
| barycentric_coord[2] * val[2]; | for (int d = 0; d < InterpolatedVectorT::dimension; ++d) { | ||||
| const float interpolated_component = barycentric_coord[0] * val[0][d] + | |||||
| barycentric_coord[1] * val[1][d] + | |||||
| barycentric_coord[2] * val[2][d]; | |||||
| if (std::is_integral<typename InterpolatedVectorT::Scalar>::value) { | |||||
| res[d] = std::floor(interpolated_component + 0.5f); | |||||
| } else { | |||||
| res[d] = interpolated_component; | |||||
| } | |||||
| } | |||||
| return res; | |||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||
| #endif // DRACO_MESH_MESH_MISC_FUNCTIONS_H_ | #endif // DRACO_MESH_MESH_MISC_FUNCTIONS_H_ | ||||