Compute the model bound for the subset of triangles. Return a line used for splitting the projections of the triangle centroids.
| 199 | // Compute the model bound for the subset of triangles. Return a |
| 200 | // line used for splitting the projections of the triangle centroids. |
| 201 | void CreateModelBound(size_t i0, size_t i1, std::vector<int32_t>& inSplit, |
| 202 | Vector3<float>& origin, Vector3<float>& direction) |
| 203 | { |
| 204 | // Tag vertices that are used in the submesh. |
| 205 | size_t const numVertices = mMesh->GetNumVertices(); |
| 206 | std::vector<bool> valid(numVertices, false); |
| 207 | for (size_t i = i0; i <= i1; ++i) |
| 208 | { |
| 209 | std::array<int32_t, 3> vertex{}; |
| 210 | mMesh->GetTriangle(inSplit[i], vertex); |
| 211 | for (size_t j = 0; j < 3; ++j) |
| 212 | { |
| 213 | valid[vertex[j]] = true; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // Create a contiguous set of vertices in the submesh. |
| 218 | std::vector<Vector3<float>> meshVertices{}; |
| 219 | for (size_t i = 0; i < numVertices; ++i) |
| 220 | { |
| 221 | if (valid[i]) |
| 222 | { |
| 223 | meshVertices.push_back(mMesh->GetPosition(i)); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // Compute the bound for the submesh. |
| 228 | uint32_t numSubvertices = static_cast<uint32_t>(meshVertices.size()); |
| 229 | uint32_t stride = static_cast<uint32_t>(sizeof(Vector3<float>)); |
| 230 | mModelBound.ComputeFromData(numSubvertices, stride, |
| 231 | reinterpret_cast<char const*>(meshVertices.data())); |
| 232 | |
| 233 | // Compute a splitting line for the submesh. |
| 234 | ApprOrthogonalLine3<float> fitter{}; |
| 235 | fitter.Fit(meshVertices); |
| 236 | auto const& line = fitter.GetParameters(); |
| 237 | origin = line.origin; |
| 238 | direction = line.direction; |
| 239 | } |
| 240 | |
| 241 | static void SplitTriangles(std::vector<Vector3<float>> const& centroids, |
| 242 | size_t i0, size_t i1, std::vector<int32_t>& inSplit, |
nothing calls this directly
no test coverage detected