/* * post process of a mesh instance to update the values of all the nodes values * @pre: a valid mesh instance * @post: update the nodes values based on approximation of the average of neighbours values refer to equation 9 on the notes */ void post_process(MESH& m) { // Translate the triangle-averaged values to node-averaged values // Implement Equation 8 from your pseudocode here // iterate through all the nodes for ( auto it = m.node_begin(); it!= m.node_end(); ++it) { QVar sum = QVar(0,0,0); double sumTriArea = 0; // for each node, iterate through its adjacent triangles for (auto adji = m.vertex_begin((*it).index()); adji != m.vertex_end((*it).index()); ++ adji) { auto tri = (*adji); sum += tri.area() * tri.value(); sumTriArea += tri.area(); } (*it).value() = sum/sumTriArea; // update nodes value } }