* Centers a mesh about the origin. * Also rescales the mesh to unit radius if == true. */
| 312 | * Also rescales the mesh to unit radius if <rescale> == true. |
| 313 | */ |
| 314 | void VertexPositionGeometry::normalize(const Vector3& origin, bool rescale) { |
| 315 | |
| 316 | // Compute center of mass. |
| 317 | Vector3 center = centerOfMass(); |
| 318 | |
| 319 | // Translate to origin [of original mesh]. |
| 320 | double radius = 0; |
| 321 | for (Vertex v : mesh.vertices()) { |
| 322 | inputVertexPositions[v] -= center; |
| 323 | radius = std::max(radius, inputVertexPositions[v].norm()); |
| 324 | } |
| 325 | |
| 326 | // Rescale. |
| 327 | if (rescale) { |
| 328 | for (Vertex v : mesh.vertices()) { |
| 329 | inputVertexPositions[v] /= radius; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | // Translate to origin [of original mesh]. |
| 334 | for (Vertex v : mesh.vertices()) { |
| 335 | inputVertexPositions[v] += origin; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | } // namespace surface |
| 340 | } // namespace geometrycentral |
no outgoing calls