Why is wood used so slowly? Or am I using it wrong? I thought it was supposed to give privileges in a fast search.
public class Test
{
public Test(Mesh inputMesh)
{
mesh = inputMesh;
CreateRTree();
}
public Mesh mesh { get; private set; }
private RTree rTree;
private List<int> affectedVertices;
public void CreateRTree()
{
rTree = new RTree();
for (int i = 0; i < mesh.Vertices.Count; i++)
{
rTree.Insert(mesh.Vertices[i], i);
}
}
public void SearchRadius(Point3d centr, double radius)
{
affectedVertices = new List<int>();
rTree.Search(new Sphere(centr, radius), (sender, args) =>
{
affectedVertices.Add(args.Id);
});
}
public void ApplyMove(Point3d centr, Vector3d moveDirection, double intensity, double radius)
{
if (affectedVertices.Count == 0)
{
return;
}
Vector3d scaledDirection = moveDirection * intensity;
Vector3f moveDirectionF = (Vector3f)scaledDirection;
Parallel.ForEach(affectedVertices, vertexIndex =>
{
Point3d original = mesh.Vertices[vertexIndex];
double distance = original.DistanceToSquared(centr);
double factor = 0.5 * (1 + Math.Cos(Math.PI * (distance / (radius * radius))));
mesh.Vertices.SetVertex(vertexIndex, original + moveDirectionF * (float)factor);
});
}
}
TestTree.gh (3.5 MB)