MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / CreateModelBound

Method CreateModelBound

GTE/Graphics/BoundTree.h:201–239  ·  view source on GitHub ↗

Compute the model bound for the subset of triangles. Return a line used for splitting the projections of the triangle centroids.

Source from the content-addressed store, hash-verified

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,

Callers

nothing calls this directly

Calls 6

ComputeFromDataMethod · 0.80
GetParametersMethod · 0.80
GetNumVerticesMethod · 0.45
GetTriangleMethod · 0.45
GetPositionMethod · 0.45
FitMethod · 0.45

Tested by

no test coverage detected