#include "MyMeshData.h" namespace X3DTK { namespace MESH { void VertexDistanceData::setDistance(float distance) { _distance = distance; } void computeVerticesDistance(MyMesh *M) { // computing distance to (0, 0, 0) point. float maxDistance = 0.0f; // Getting the vertices. const MESH::MyMesh::MFVertex &vertices = M->getVertices(); // Iterating the vertices. for (MyMesh::MFVertex::const_iterator v = vertices.begin(); v != vertices.end(); ++v) { // Getting the point. const SFPoint3f &P =(*v)->data().getPoint(); SFVec3f OP = P - SFPoint3f::null; float distance = OP.norm(); // Setting the distance. (*v)->data().setDistance(distance); // Updating the maximum distance. if (distance > maxDistance) maxDistance = distance; } // normalizing in [0, 1] for (MyMesh::MFVertex::const_iterator nv = vertices.begin(); nv != vertices.end(); ++nv) (*nv)->data().setDistance((*nv)->data().getDistance()/maxDistance); } } }