Polygon Circle

Help
toni
2012-11-26
2013-05-29
  • toni
    toni
    2012-11-26

    Hi everybody!

    Im trying to make a circle with the Polygon Renderer(i know i could just use for example the shape renderer, but i need it like this). The circle should consist out of 4 Nodes and 4 curved Edges. Right now i have the problem, that the edges enter all the nodes on the sides, which is ok for the top, and bottom node, but does not work for the left and the right node, and so i dont get a perfect circle but more something egg-shaped. Does anybody know how i can change the position the edges enter the nodes or ho to rotate this nodes for 90 degrees?

    ublic void createCircle(Point pos, final int size ){
             d.addControlListener(new DragControl(){            
                 public void mouseClicked(MouseEvent e){
                     
                    
                     
                 mousePos=e.getPoint();              
                     Point2D absPos=  d.getAbsoluteCoordinate(mousePos, null);
                     groupCount++;
                     int first, last;
                     first=nodeId;
                     Node n1 = graph.addNode(); 
                     n1.set("positionx",absPos.getX()-size/2);
                     n1.set("positiony", absPos.getY());
                     n1.set("height", nodeSize);
                     n1.set("width", nodeSize);
                     n1.set("renderType","ellipse");
                     n1.set("gender",1);     
                     n1.set("group",groupCount); 
                     n1.set("id",nodeId++); 
                     
                     
                     Node n2 = graph.addNode(); 
                     n2.set("positionx",absPos.getX()+size/2);
                     n2.set("positiony", absPos.getY());
                     n2.set("height", nodeSize);
                     n2.set("width", nodeSize);
                     n2.set("renderType","ellipse");
                     n2.set("gender",1);      
                     n2.set("group",groupCount); 
                     n2.set("id",nodeId++); 
                     
                     Node n3 = graph.addNode(); 
                     n3.set("positionx",absPos.getX());
                     n3.set("positiony", absPos.getY()-size/2);
                     n3.set("height", nodeSize);
                     n3.set("width", nodeSize);
                     n3.set("renderType","ellipse");
                     n3.set("gender",1);  
                     n3.set("group",groupCount); 
                     n3.set("id",nodeId++);
                     last=nodeId;
                     
                     Node n4 = graph.addNode(); 
                     n4.set("positionx",absPos.getX());
                     n4.set("positiony", absPos.getY()+size/2);
                     n4.set("height", nodeSize);
                     n4.set("width", nodeSize);
                     n4.set("renderType","ellipse");
                     n4.set("gender",1);    
                     n4.set("group",groupCount); 
                     n4.set("id",nodeId++);
                                     
                     graph.addEdge(n3, n1);
                     graph.addEdge(n3, n2);
                     graph.addEdge(n4, n2);
                     graph.addEdge(n4, n1);
                     
    .
    .
    .
    .
                 }
             });
         }
    
     
  • Björn Kruse
    Björn Kruse
    2012-11-27

    I just know that AggregateDemo contains an example for the use of PolygonRenderer.
    See https://github.com/prefuse/Prefuse/blob/master/demos/prefuse/demos/AggregateDemo.java

    (It calculates the convex hull over the nodes in one aggregate.) There are a few settings for edge types in PolygonRenderer and it is based on a float array which contains the points. It should not be necessary to create multiple nodes just to draw one circle. Just create a float array datafield, fill its values and pass the datafield name to PolygonRenderer - at least this is how I understand it   ; )
    Also nodes cannot be rotated, afaik.

    Sorry, not much I can help here.
    Regards, Björn

     
  • toni
    toni
    2012-11-27

    Thank you very much for your help!
    I already know this example, my program is based on it and your answer might help my on the next step which is coloring this circle, but i need the nodes and edges as well, because it should be possible to resize and combine this circle with other graphical primitives like rectangles during runtime.

    I made a mistake in the first post by mentioning the polygon renderer, i actually only use it to color my polygons, which are drawn with a ShapeRenderer and an Edge renderer. So for example to make a rectangel i create 4 nodes for each corner, then connect these edges and then colour the inner part of the rectangle with the polygon renderer.

    This works fine for rectangles but when it comes to circle, i create 4 nodes and want them to be connected by curved edges, but the problem is that these edges enter the nodes always on the side and not on top, what deforms my circle

    I hope my  problem is a little bit clearer now

     
  • Björn Kruse
    Björn Kruse
    2012-12-07

    Hmm, it is against prefuse concept to use multiple nodes to render one item.

    Maybe you should use decorators, with them you can have multiple visualItems (and thus multiple graphical representations) for one source-/dataItem. See http://home.arcor.de/gutn8/prefuse/ for AggregateDecoratorDemo, which demonstrates this.

    Or maybe implement your own renderer. Once you have it it will be much more flexible and much easier to handle in the prefuse framework.

    best regards,
    Björn