HE_Mesh library: getClosestPoint()

I´m tying to make a sketch that "project" on a HE_Mesh mesh any random external point, any point located out of the mesh surface. Does anybody know which can be the better way?

I tried the HE_Mesh method : getClosestPoint (final WB_Point p, final WB_KDTree< WB_Point, Long > vertexTree)

So given any query point like:

WB_Point randomPoint;

And given a vertexTree, KD-tree from myMesh (from vertexTree()) that returns a KD-tree containing all vertices. WB_KDTree<WB_Coordinate, Long> myVertexTree = mesh.getVertexTree();

Then I get trouble trying to make a sentence like this:

WB_Point myClosestPoint = mesh.getClosestPoint(randomPoint, myVertexTree);

The problem is that the method getClosestPoint ( WB_Point , WB_KDTree<WB_Point, Long > ) in the type HE_Mesh is not applicable for the arguments WB_KDTree <WB_Coordinate, Long>

Is there any method like getVertexTree() that returns a WB_KDTree<WB_Point, Long>, or how can I translate the WB_KDTree<WB_Coordinate, Long> into a WB_KDTree<WB_Point, Long>

Answers

  • Here´s an example:

        HE_Mesh mesh;
        WB_Render render;
        WB_Point randomPoint;
        WB_Point pointOnSurface;
    
        float sizeWorld = 300;
    
        public void setup() {
            size(800, 800, OPENGL);
            smooth(8);
            randomPoint = new WB_Point(random(sizeWorld), random(sizeWorld), random(sizeWorld));
            HEC_Sphere creator=new HEC_Sphere();
            creator.setRadius(100).setUFacets(32).setVFacets(32);
            mesh=new HE_Mesh(creator); 
            render=new WB_Render(this);
    
            // getting the projection point on the surface
            WB_KDTree<WB_Coordinate, Long> myVertexTree = mesh.getVertexTree();
            pointOnSurface = mesh.getClosestPoint(randomPoint, myVertexTree);
            //  
        }
    
        public void draw() {
            background(255);
            directionalLight(255, 255, 255, 1, 1, -1);
            directionalLight(127, 127, 127, -1, -1, 1);
            translate(400, 400, 100);
            rotateY(mouseX*1.0f/width*TWO_PI);
            rotateX(mouseY*1.0f/height*TWO_PI);
            stroke(0,100);
            render.drawEdges(mesh);
            stroke(255,10,10);
            render.drawPoint(randomPoint,5);
            render.drawPoint(pointOnSurface,5);
    
        }
    
  • I realized that the getFaceTree() method gets back a WB_KDTree <WB_Point, Long>. ( instead of the getVertexTree()that returns a WB_KDTree<WB_Coordinate, Long>) But any query gives a null... What I am doing wrong?

    For example:

    public class HeMeshProjectOnSphere extends PApplet {
    
        PeasyCam cam;
        HE_Mesh mesh;
        WB_Render render;
        WB_Point randomPoint;
        WB_Point pointOnFace;
        HE_Vertex pointOnVertex;
    
        float sizeWorld = 300;
    
        public void setup() {
            size(800, 800, OPENGL);
            cam = new PeasyCam(this, 500);
            render=new WB_Render(this);
            smooth(8);
    
            HEC_Sphere creator=new HEC_Sphere();
            creator.setRadius(100).setUFacets(32).setVFacets(32);
            mesh=new HE_Mesh(creator); 
    
            randomPoint = new WB_Point(random(sizeWorld), random(sizeWorld), random(sizeWorld));
    
            // trying to get the projection point on a mesh (face, vertex,...)
            WB_KDTree <WB_Point, Long> myFaceTree = mesh.getFaceTree();
            pointOnFace = mesh.getClosestPoint(randomPoint, myFaceTree);    
            pointOnVertex = mesh.getClosestVertex(randomPoint, myFaceTree);
    
            println(myFaceTree.toString());
            println (pointOnFace);
            println (pointOnVertex);
        }
    
        public void draw() {
            background(255);
    
            stroke(0,100);
            render.drawEdges(mesh);
    
            stroke(255,10,10);
            render.drawPoint(randomPoint,5);
            if (pointOnFace != null) render.drawPoint(pointOnFace,5);   
            if (pointOnVertex != null) render.drawPoint(pointOnVertex,5);
        }
    
  • Solved by the author of HE_Mesh in the v 2.0.14. Thanks Frederick Vanhoutte !! ^:)^

Sign In or Register to comment.