Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/mesh/mesh_stripifier.h
- This file was moved from extern/draco/dracoenc/src/draco/mesh/mesh_stripifier.h.
| Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
| private: | private: | ||||
| bool Prepare(const Mesh &mesh) { | bool Prepare(const Mesh &mesh) { | ||||
| mesh_ = &mesh; | mesh_ = &mesh; | ||||
| num_strips_ = 0; | num_strips_ = 0; | ||||
| num_encoded_faces_ = 0; | num_encoded_faces_ = 0; | ||||
| // TODO(ostava): We may be able to avoid computing the corner table if we | // TODO(ostava): We may be able to avoid computing the corner table if we | ||||
| // already have it stored somewhere. | // already have it stored somewhere. | ||||
| corner_table_ = CreateCornerTableFromPositionAttribute(mesh_); | corner_table_ = CreateCornerTableFromPositionAttribute(mesh_); | ||||
| if (corner_table_ == nullptr) | if (corner_table_ == nullptr) { | ||||
| return false; | return false; | ||||
| } | |||||
| // Mark all faces as unvisited. | // Mark all faces as unvisited. | ||||
| is_face_visited_.assign(mesh.num_faces(), false); | is_face_visited_.assign(mesh.num_faces(), false); | ||||
| return true; | return true; | ||||
| } | } | ||||
| // Returns local id of the longest strip that can be created from the given | // Returns local id of the longest strip that can be created from the given | ||||
| // face |fi|. | // face |fi|. | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | private: | ||||
| PointIndex CornerToPointIndex(CornerIndex ci) const { | PointIndex CornerToPointIndex(CornerIndex ci) const { | ||||
| return mesh_->CornerToPointId(ci); | return mesh_->CornerToPointId(ci); | ||||
| } | } | ||||
| // Returns the opposite corner in case the opposite triangle does not lie | // Returns the opposite corner in case the opposite triangle does not lie | ||||
| // across an attribute seam. Otherwise return kInvalidCornerIndex. | // across an attribute seam. Otherwise return kInvalidCornerIndex. | ||||
| CornerIndex GetOppositeCorner(CornerIndex ci) const { | CornerIndex GetOppositeCorner(CornerIndex ci) const { | ||||
| const CornerIndex oci = corner_table_->Opposite(ci); | const CornerIndex oci = corner_table_->Opposite(ci); | ||||
| if (oci < 0) | if (oci < 0) { | ||||
| return kInvalidCornerIndex; | return kInvalidCornerIndex; | ||||
| } | |||||
| // Ensure the point ids are same on both sides of the shared edge between | // Ensure the point ids are same on both sides of the shared edge between | ||||
| // the triangles. | // the triangles. | ||||
| if (CornerToPointIndex(corner_table_->Next(ci)) != | if (CornerToPointIndex(corner_table_->Next(ci)) != | ||||
| CornerToPointIndex(corner_table_->Previous(oci))) | CornerToPointIndex(corner_table_->Previous(oci))) { | ||||
| return kInvalidCornerIndex; | return kInvalidCornerIndex; | ||||
| } | |||||
| if (CornerToPointIndex(corner_table_->Previous(ci)) != | if (CornerToPointIndex(corner_table_->Previous(ci)) != | ||||
| CornerToPointIndex(corner_table_->Next(oci))) | CornerToPointIndex(corner_table_->Next(oci))) { | ||||
| return kInvalidCornerIndex; | return kInvalidCornerIndex; | ||||
| } | |||||
| return oci; | return oci; | ||||
| } | } | ||||
| void GenerateStripsFromCorner(int local_strip_id, CornerIndex ci); | void GenerateStripsFromCorner(int local_strip_id, CornerIndex ci); | ||||
| const Mesh *mesh_; | const Mesh *mesh_; | ||||
| std::unique_ptr<CornerTable> corner_table_; | std::unique_ptr<CornerTable> corner_table_; | ||||
| Show All 9 Lines | private: | ||||
| // Last encoded point. | // Last encoded point. | ||||
| PointIndex last_encoded_point_; | PointIndex last_encoded_point_; | ||||
| }; | }; | ||||
| template <typename OutputIteratorT, typename IndexTypeT> | template <typename OutputIteratorT, typename IndexTypeT> | ||||
| bool MeshStripifier::GenerateTriangleStripsWithPrimitiveRestart( | bool MeshStripifier::GenerateTriangleStripsWithPrimitiveRestart( | ||||
| const Mesh &mesh, IndexTypeT primitive_restart_index, | const Mesh &mesh, IndexTypeT primitive_restart_index, | ||||
| OutputIteratorT out_it) { | OutputIteratorT out_it) { | ||||
| if (!Prepare(mesh)) | if (!Prepare(mesh)) { | ||||
| return false; | return false; | ||||
| } | |||||
| // Go over all faces and generate strips from the first unvisited one. | // Go over all faces and generate strips from the first unvisited one. | ||||
| for (FaceIndex fi(0); fi < mesh.num_faces(); ++fi) { | for (FaceIndex fi(0); fi < mesh.num_faces(); ++fi) { | ||||
| if (is_face_visited_[fi]) | if (is_face_visited_[fi]) { | ||||
| continue; | continue; | ||||
| } | |||||
| const int longest_strip_id = FindLongestStripFromFace(fi); | const int longest_strip_id = FindLongestStripFromFace(fi); | ||||
| // Separate triangle strips with the primitive restart index. | // Separate triangle strips with the primitive restart index. | ||||
| if (num_strips_ > 0) { | if (num_strips_ > 0) { | ||||
| *out_it++ = primitive_restart_index; | *out_it++ = primitive_restart_index; | ||||
| } | } | ||||
| StoreStrip(longest_strip_id, out_it); | StoreStrip(longest_strip_id, out_it); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| template <typename OutputIteratorT> | template <typename OutputIteratorT> | ||||
| bool MeshStripifier::GenerateTriangleStripsWithDegenerateTriangles( | bool MeshStripifier::GenerateTriangleStripsWithDegenerateTriangles( | ||||
| const Mesh &mesh, OutputIteratorT out_it) { | const Mesh &mesh, OutputIteratorT out_it) { | ||||
| if (!Prepare(mesh)) | if (!Prepare(mesh)) { | ||||
| return false; | return false; | ||||
| } | |||||
| // Go over all faces and generate strips from the first unvisited one. | // Go over all faces and generate strips from the first unvisited one. | ||||
| for (FaceIndex fi(0); fi < mesh.num_faces(); ++fi) { | for (FaceIndex fi(0); fi < mesh.num_faces(); ++fi) { | ||||
| if (is_face_visited_[fi]) | if (is_face_visited_[fi]) { | ||||
| continue; | continue; | ||||
| } | |||||
| const int longest_strip_id = FindLongestStripFromFace(fi); | const int longest_strip_id = FindLongestStripFromFace(fi); | ||||
| // Separate triangle strips by degenerate triangles. There will be either | // Separate triangle strips by degenerate triangles. There will be either | ||||
| // three or four degenerate triangles inserted based on the number of | // three or four degenerate triangles inserted based on the number of | ||||
| // triangles that are already encoded in the output strip (three degenerate | // triangles that are already encoded in the output strip (three degenerate | ||||
| // triangles for even number of existing triangles, four degenerate | // triangles for even number of existing triangles, four degenerate | ||||
| // triangles for odd number of triangles). | // triangles for odd number of triangles). | ||||
| Show All 32 Lines | |||||