def smooth_tangents(self, include_uv_tol=False,
                        root_node=None,
                        pos_tol=DEFAULT_POSITION_TOLERANCE,
                        nor_smooth_tol=DEFAULT_NORMAL_SMOOTH_TOLERANCE,
                        uv_tol=DEFAULT_UV_TOLERANCE):
        def tangents_are_similar(t1, t2, b1, b2, nor_smooth_tol):
            """Test if both the tangents and binormals are similar."""
            tangent_similar = vmath.v3is_similar(t1, t2, nor_smooth_tol)
            binormal_similar = vmath.v3is_similar(b1, b2, nor_smooth_tol)
            return tangent_similar and binormal_similar

        if not root_node:
            if not self.kdtree:
                # Create a kd-tree to optimize the smoothing performance
                self.kdtree = pointmap.build_kdtree(self.positions)
            root_node = self.kdtree

        uvs = self.uvs[0]
        for i, p in enumerate(self.positions):
            original_tangent = self.tangents[i]
            original_binormal = self.binormals[i]
            accumulate_tangent = (0, 0, 0)
            accumulate_binormal = (0, 0, 0)
            accumulated_indexes = [ ]

            # Generate a list of indexes for the positions close to the evaluation vertex.
            if include_uv_tol:
                uv = uvs[i]
                similiar_positions_indexes = root_node.points_within_uv_distance(self.positions, p, pos_tol,
                                                                                 uvs, uv, uv_tol)
            else:
                similiar_positions_indexes = root_node.points_within_distance(self.positions, p, pos_tol)

            for i in similiar_positions_indexes:
                this_tangent = self.tangents[i]
                this_binormal = self.binormals[i]
                if tangents_are_similar(this_tangent, original_tangent,
                                        this_binormal, original_binormal, nor_smooth_tol):
                    accumulate_tangent = vmath.v3add(accumulate_tangent, this_tangent)
                    accumulate_binormal = vmath.v3add(accumulate_binormal, this_binormal)
                    accumulated_indexes.append(i)
            smooth_tangent = vmath.v3unitcube_clamp(vmath.v3normalize(accumulate_tangent))
            smooth_binormal = vmath.v3unitcube_clamp(vmath.v3normalize(accumulate_binormal))
            for i in accumulated_indexes:
                self.tangents[i] = smooth_tangent
                self.binormals[i] = smooth_binormal
Distribute keys to servers - requires preceding with 'test' or 'prod'
dataset/ETHPy150Open turbulenz/turbulenz_tools/turbulenz_tools/tools/mesh.py/Mesh.smooth_tangents--crossover with--dataset/ETHPy150Open sahana/eden/static/scripts/tools/fabfile.py/distribute_keys