Package net.wigis.graph.dnv

Examples of net.wigis.graph.dnv.DNVNode


      subGraph.setNodes( graph.getVisibleNodes( level ) );
      return subGraph;
    }
   
    List<DNVNode> nodes = new ArrayList<DNVNode>( graph.getVisibleNodes( level ).values() );
    DNVNode tempNode;
    if( nodes != null )
    {
      for( Iterator<DNVNode> i = nodes.iterator(); i.hasNext(); )
      {
        tempNode = i.next();
        if( tempNode.isVisible() && isNodeWithin( tempNode, minX, minY, maxX, maxY ) )
        {
          // Add the node
          subGraph.add( tempNode );
          // Add all the neighbor nodes
          subGraph.addAllNodes( tempNode.getNeighbors( true ) );
          // Add the edges to all the neighbors
          subGraph.addAllEdges( tempNode.getFromEdges( true ) );
          subGraph.addAllEdges( tempNode.getToEdges( true ) );
        }
      }
    }

    return subGraph;
View Full Code Here


        {
          value = "getWindowPosition();"; // needed for calculation of
          // label positions
          Collection<DNVNode> nodes = subGraph.getNodes().values();
          HashMap<Integer, Integer> realIdToId = new HashMap<Integer, Integer>();
          DNVNode tempNode = new DNVNode( graph );
          Vector2D position;
          int radius = ImageRenderer.getNodeWidth( getNodeSize(), getMinX(), getMaxX(), 1 );
          int j = 0;
          String imageFile;
          int tempRadius;
          String label;
          for( Iterator<DNVNode> i = nodes.iterator(); i.hasNext(); )
          {
            tempNode = i.next();
            label = tempNode.getLabel( interpolationLabels ).replaceAll( "'", "`" ).replaceAll( "\n", " " ).replaceAll( "\r", " " )
                .trim();
            position = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, getMinX(), getMaxX(), getMinY(),
                getMaxY(), getWidth(), getHeight(), tempNode.getPosition( true ) );
            tempRadius = (int)( radius * tempNode.getRadius() );

            imageFile = ImageRenderer.getURL( tempRadius, tempNode.getIcon(), tempNode.getColor(), showIcons, tempNode.isSelected(),
                tempNode.getId() );
            if( isShowLabels() && isCurvedLabels() )
            {
              imageFile += "&l=" + label + "&ls=" + labelSize + "&sl=" + curvedLabels + "&o=" + outlinedLabels;
            }
            value += "addNode(" + (int)position.getX() + "," + (int)position.getY() + "," + tempRadius + "," + tempNode.getId() + "," + j
                + ",'" + imageFile + "','" + label + "'," + ( showLabels && !curvedLabels ) + "," + tempNode.isSelected() + ");";
            realIdToId.put( tempNode.getId(), j );
            j++;
          }
          value += "nNodes = " + j + ";";

          Collection<DNVEdge> edges = subGraph.getEdges().values();
          DNVEdge tempEdge;
          DNVNode fromNode;
          DNVNode toNode;
          int fromId;
          int toId;
          j = 0;
          position = new Vector2D( tempNode.getPosition( true ) );
          Vector2D originalPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, getMinX(),
              getMaxX(), getMinY(), getMaxY(), getWidth(), getHeight(), position );
          position.setX( position.getX() + DNVEdge.DEFAULT_RESTING_DISTANCE );
          position = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, getMinX(), getMaxX(), getMinY(),
              getMaxY(), getWidth(), getHeight(), position );

          position = position.subtract( originalPosition );
          // float ratio = position.length() /
          // DNVEdge.DEFAULT_RESTING_DISTANCE;

          // value += "repellingIntensity = " +
          // Springs.getRepelling_intensity() * ratio + ";";
          // value += "springConstant = " + DNVEdge.DEFAULT_K / (ratio
          // *
          // ratio) + ";";
          for( Iterator<DNVEdge> i = edges.iterator(); i.hasNext(); )
          {
            tempEdge = i.next();
            fromNode = tempEdge.getFrom();
            toNode = tempEdge.getTo();
            fromId = realIdToId.get( fromNode.getId() );
            toId = realIdToId.get( toNode.getId() );
            value += "addEdge(" + j + "," + fromId + "," + toId + "," + position.length() + ");";
            j++;
          }

          value += "nEdges = " + j + ";";
View Full Code Here

      // a temporary hashmap storing results to avoid adding same node twice
      Map<Integer,DNVNode> results = new HashMap<Integer,DNVNode>();
     
      if( !searchInputText.trim().equals( "" ) )
      {
        DNVNode tempNode;
        String label = "";
        String contents;
        String[] splitText = searchInputText.split( "\n" );
        if( splitText.length == 1 )
        {
          splitText = searchInputText.split( " OR " );
          if( splitText.length == 1 )
          {
            splitText = searchInputText.split( " or " );
          }
        }
 
        String originalInput = searchInputText;
        for( int i = 0; i < splitText.length; i++ )
        {
          searchInputText = splitText[i];
          searchInputText = searchInputText.replaceAll( "\n", "" );
          System.out.println( "searching for [" + searchInputText + "]" );
          if( !searchInputText.equals( "" ) )
          {
            for( Iterator<DNVNode> nodes = graph.getNodes( level ).iterator(); nodes.hasNext(); )
            {
              tempNode = nodes.next();
 
              label = tempNode.getLabel();
              if( searchIncludeFullLabel )
              {
                if( tempNode.getProperty( "Full Label" ) != null )
                {
                  label += " " + tempNode.getProperty( "Full Label" );
                }
              }
 
              if( label.toLowerCase().contains( searchInputText.toLowerCase() ) )
              {
                tempNode.setSelected( true );
                results.put( tempNode.getId(), tempNode );
              }
              else if( searchIncludeContents )
              {
                contents = tempNode.getProperty( "Contents" );
                if( contents != null && !contents.equals( "" ) )
                {
                  if( contents.toLowerCase().contains( searchInputText.toLowerCase() ) )
                  {
                    tempNode.setSelected( true );
                    results.put( tempNode.getId(), tempNode );
                  }
                }
              }
            }
          }
View Full Code Here

   * @return the node contents
   */
  public String getNodeContents()
  {
    int id = Request.getIntegerParameter( "id" );
    DNVNode node = (DNVNode)graph.getNodeById( id );
    String value = "";
    if( node != null )
    {
      value = node.getProperty( "Contents" );
      if( value == null )
      {
        value = "";
      }

View Full Code Here

   * @return the node label
   */
  public String getNodeLabel()
  {
    int id = Request.getIntegerParameter( "id" );
    DNVNode node = (DNVNode)graph.getNodeById( id );
    String value = "";
    if( node != null )
    {
      value = node.getLabel();
      if( value == null )
      {
        value = "";
      }
    }
View Full Code Here

    PaintBean pb = (PaintBean)ContextLookup.lookup( "paintBean", request );
    if( pb == null )
      return;

    int id = ServletHelper.getIntParameter( "id", request );
    DNVNode node = (DNVNode)pb.getGraph().getNodeById( id );
    if( node == null )
      return;

    float red = node.getColor().getX();
    float green = node.getColor().getY();
    float blue = node.getColor().getZ();
    String label = node.getLabel();

    Vector3D color = new Vector3D( red, green, blue );
    int size = ServletHelper.getIntParameter( "s", request );
    String icon = node.getIcon();
    boolean showIcons = true;
    if( icon == null || icon.equals( "" ) )
    {
      showIcons = false;
    }

    if( pb != null )
    {
      boolean showLabels = pb.isShowLabels() && pb.isCurvedLabels();
      int imageSize = size + 2;
      if( label == null || label.equals( "" ) )
      {
        showLabels = false;
        label = "";
      }
      else if( showLabels )
      {
        imageSize = getImageSize( label, size, pb );
      }

      BufferedImage img = new BufferedImage( imageSize, imageSize, BufferedImage.TYPE_INT_ARGB );
      Graphics g = img.createGraphics();
      Graphics2D g2d = (Graphics2D)g;
      g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );

      // g.clearRect( 0, 0, size + 1, size + 1 );
      Vector2D pos = new Vector2D( imageSize / 2, imageSize / 2 );
      size /= node.getRadius();
      try
      {
        ImageRenderer.drawLabel( g2d, node, pos, size, label, pb.isShowLabels(), pb.isCurvedLabels(), pb.isOutlinedLabels(),
            pb.getLabelSize(), 1, 1, 1, pb.isScaleNodesOnZoom(), pb.isHighlightNeighbors(), pb.getMaxLabelLength(),
            pb.getCurvedLabelAngle(), pb.isDrawLabelBox(), pb.isBoldLabels(),
View Full Code Here

          globalMinX -= 10;
          globalMaxX += 10;
        }
        double yBuffer = ( globalMaxY - globalMinY ) * pb.getWhiteSpaceBuffer();
        double xBuffer = ( globalMaxX - globalMinX ) * pb.getWhiteSpaceBuffer();
        DNVNode selectedNode = null;
        globalMaxY += yBuffer;
        globalMinY -= yBuffer;
        globalMaxX += xBuffer;
        globalMinX -= xBuffer;

        if( !sameNode )
        {
          List<DNVNode> nodes = graph.getNodes( level );
          SortByLabelSize sbls = new SortByLabelSize( pb.isHighlightNeighbors() );
          Collections.sort( nodes, sbls );
          DNVNode node;
          Vector2D screenPosition;
          double distance;
          double minDistance = Integer.MAX_VALUE;
          int nodeI = -1;
          int distX = 0; // dist b/w this node and mouse click
          int distY = 0;

          // Check if user clicked on a solid node label
          for( int i = nodes.size() - 1; i >= 0; i-- )
          {
            node = nodes.get( i );
            if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) == null )
            {
              screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY, maxY,
                  width, height, node.getPosition( true ) );
              ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition, null,
                  (int)Math.round( pb.getNodeSize() * node.getRadius() ), node.getLabel( pb.isInterpolationLabels() ), pb
                      .isCurvedLabels()
                      || node.isCurvedLabel(), pb.getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb
                      .getMaxLabelLength(), pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
              if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
                  && mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
              {
                distX = (int)( mouseDownX - screenPosition.getX() );
                distY = (int)( mouseDownY - screenPosition.getY() );
                node.setProperty( "distX", "" + distX );
                node.setProperty( "distY", "" + distY );
                minDistance = 0;
                nodeI = i;
                break;
              }
            }
          }

          if( nodeI == -1 )
          {
            // loop thru all nodes to find closest node
            for( int i = nodes.size() - 1; i >= 0; i-- )
            {
              node = nodes.get( i );
              if( node.isVisible() )
              {
                screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
                    maxY, width, height, node.getPosition( true ) );

                // find node closest to mouseDown
                distX = (int)( mouseDownX - screenPosition.getX() );
                distY = (int)( mouseDownY - screenPosition.getY() );

                distance = distX * distX + distY * distY;

                if( distance < minDistance )
                {
                  node.setProperty( "distX", "" + distX );
                  node.setProperty( "distY", "" + distY );

                  minDistance = distance;
                  nodeI = i;
                }
              }
            }
          }

          if( nodes.size() > 0 && nodeI != -1 )
          {
            node = nodes.get( nodeI );

            double nodeWidth;
            nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
            // check if selected node is close enough to mouseDown
            if( Settings.DEBUG )
              System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );

            if( Math.sqrt( minDistance ) >= nodeWidth )
            {
              // Still no node selected so check nodes with faded
              // labels
              for( int i = nodes.size() - 1; i >= 0; i-- )
              {
                node = nodes.get( i );
                if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) != null
                    && Float.parseFloat( node.getProperty( "faded" ) ) > 0.1 )
                {
                  screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX,
                      minY, maxY, width, height, node.getPosition( true ) );
                  ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition,
                      null, (int)Math.round( pb.getNodeSize() * node.getRadius() ),
                      node.getLabel( pb.isInterpolationLabels() ), pb.isCurvedLabels() || node.isCurvedLabel(), pb
                          .getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb.getMaxLabelLength(),
                      pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
                  if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
                      && mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
                  {
                    distX = (int)( mouseDownX - screenPosition.getX() );
                    distY = (int)( mouseDownY - screenPosition.getY() );
                    node.setProperty( "distX", "" + distX );
                    node.setProperty( "distY", "" + distY );
                    minDistance = 0;
                    nodeI = i;
                    break;
                  }
                }
              }
            }

            node = nodes.get( nodeI );

            nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
            // check if selected node is close enough to mouseDown
            if( Settings.DEBUG )
              System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
            if( Math.sqrt( minDistance ) < nodeWidth )
            {
View Full Code Here

      y = tempNode.getY();
      id = tempNode.getId();
      selected = tempNode.isSelected();
      nodeWorldPos = ImageRenderer.transformScreenToWorld( x, y, minX, maxX, minY, maxY, pb.getGlobalMinX(), pb.getGlobalMaxX(), pb
          .getGlobalMinY(), pb.getGlobalMaxY(), pb.getWidth(), pb.getHeight() );
      DNVNode node = (DNVNode)graph.getNodeById( id );
      if( node != null )
      {
        Vector2D movement = ImageRenderer.getMovement( node, nodeWorldPos );
        node.moveRelatedNodes( movement, true, false );
        node.setPosition( nodeWorldPos );
        if( selected )
        {
          pb.setSelectedNode( node, false );
          noOneSelected = false;
        }
View Full Code Here

   * @return the publication
   */
  private Publication generateGraphFromPublicationsArray( Publication p, DNVGraph g, int count )
  {
    Author a = null;
    DNVNode pub = null;
    DNVNode aut = null;
    DNVEdge edge = null;
    Iterator<Publication> iterator = this.searchResults.iterator();
    while( iterator.hasNext() )
    {
      p = iterator.next();

      if( p.selected )
      {
        pub = new DNVNode( g );
        pub.setLabel( p.getTitle() );
        pub.setRadius( PUBLICATION_NODE_RADIUS );
        pub.setPosition( (float)Math.random(), (float)Math.random() );
        pub.setColor( new Vector3D( 0.2f, 0.2f, 0.8f ) );
        g.addNode( 0, pub );

        // iterate for all authors in this result
        Iterator<Author> aiterator = p.getAuthors().iterator();
        aut = null;
        while( aiterator.hasNext() )
        {
          // check if the author already exists in the graph
          a = aiterator.next();
          if( g.getNodeById( a.getId() ) != null )
          {
            aut = (DNVNode)g.getNodeById( a.getId() );
          }
          else
          {
            aut = new DNVNode( g );
            aut.setId( a.getId() );
            aut.setLabel( a.getName() );
            aut.setRadius( AUTHOR_NODE_RADIUS );
            aut.setPosition( (float)Math.random(), (float)Math.random() );
            aut.setColor( new Vector3D( 0.5f, 0.7f, 0.4f ) );
            g.addNode( 0, aut );
          }

          edge = new DNVEdge( 0, DNVEdge.DEFAULT_RESTING_DISTANCE, false, aut, pub, g );
          edge.setId( count );
          g.addNode( 0, edge );
          log( "adding node and title: " + pub.getLabel() + " author: " + aut.getLabel() );
          count++;
        }
      }
    }
    return p;
View Full Code Here

        Integer lowDegreeNodeId = tuple.getMiddle();
       
        //first add all the tuple nodes with the higher degree node in the center, no redundancy
        if(!traveledNodesId.contains(highDegreeNodeId)){
          traveledNodesId.add(highDegreeNodeId);
          DNVNode middlenode = graph.getNode(level, highDegreeNodeId);
          //List<DNVNode> neighbors = middlenode.getNeighbors();
         
          //get all the neighbors of the higher degree node which haven't been traveled
          ArrayList<DNVNode> neighbors = new ArrayList<DNVNode>();
          for(DNVEdge edge : middlenode.getFromEdges()){
            if(!traveledNodesId.contains(edge.getToId())){
              neighbors.add(graph.getNode(level, edge.getToId()));
            }
          }
          for(DNVEdge edge : middlenode.getToEdges()){
            if(!traveledNodesId.contains(edge.getFromId())){
              neighbors.add(graph.getNode(level, edge.getFromId()));
            }
          }
         
          for(int i = 0; i < neighbors.size(); i++){
            for(int j = i + 1; j < neighbors.size(); j++){
              Integer degree1 = neighbors.get(i).getConnectivity();
              Integer degree2 = neighbors.get(j).getConnectivity();             
              Integer leftNodeId, rightNodeId;
              DNVNode leftNode, rightNode;
              DNVEdge leftEdge, rightEdge, middleEdge;
              Tuple<Integer, Integer, Integer> degreeTuple;
              //for each node tuple, the left node degree should be no smaller than the right one
              if(degree1 >= degree2){
                leftNode = neighbors.get(i);
                rightNode = neighbors.get(j);             
                degreeTuple = new Tuple<Integer, Integer, Integer>(degree1, highDegree,degree2);
              }else{
                leftNode = neighbors.get(j);
                rightNode = neighbors.get(i);
                degreeTuple = new Tuple<Integer, Integer, Integer>(degree2, highDegree,degree1);
              }
              leftNodeId = leftNode.getId();
              rightNodeId = rightNode.getId();
              leftEdge = middlenode.getEdgeToNeighbor(leftNodeId);
              rightEdge = middlenode.getEdgeToNeighbor(rightNodeId);
             
              if(!degreeOccurTableDK3.containsKey(degreeTuple)){
                degreeOccurTableDK3.put(degreeTuple, 0)
                degreeUniqueEdgeTableDK3.put(degreeTuple, new HashSet<DNVEdge>());
                degreeUniqueNodeTableDK3.put(degreeTuple, new HashSet<DNVNode>());
              }         
              degreeOccurTableDK3.put(degreeTuple, degreeOccurTableDK3.get(degreeTuple) + 1);
              degreeUniqueEdgeTableDK3.get(degreeTuple).add(leftEdge);
              degreeUniqueEdgeTableDK3.get(degreeTuple).add(rightEdge);
              degreeUniqueNodeTableDK3.get(degreeTuple).add(middlenode);
              degreeUniqueNodeTableDK3.get(degreeTuple).add(leftNode);
              degreeUniqueNodeTableDK3.get(degreeTuple).add(rightNode);
             
              if(leftNode.getNeighbors().contains(rightNode) || rightNode.getNeighbors().contains(leftNode)){
                middleEdge = leftNode.getEdgeToNeighbor(rightNodeId);
                Triangle triangle = new Triangle(leftNode, middlenode, rightNode, leftEdge, middleEdge, rightEdge);
                triangles.add(triangle);
                degreeUniqueEdgeTableDK3.get(degreeTuple).add(middleEdge);
                triangleCnt++;
              }else{
                Line line = new Line(leftNode, middlenode, rightNode, leftEdge, rightEdge);
                lines.add(line);
                lineCnt++;
              }
              cnt++;
            }
          }
        }
       
        if(traveledNodesId.contains(lowDegreeNodeId)){
          continue;
        }
        //next get all the tuple nodes with the lower degree node in the center and the higher degree node at one end
        DNVNode middlenode = graph.getNode(level, lowDegreeNodeId);
        DNVNode leftNode = graph.getNode(level, highDegreeNodeId);
        DNVEdge leftEdge = tuple.getRight();
        DNVEdge rightEdge, middleEdge;
        //get all the neighbors of the lower degree node which haven't been traveled
        ArrayList<DNVNode> neighbors = new ArrayList<DNVNode>();
        for(DNVEdge edge : middlenode.getFromEdges()){
          if(!traveledNodesId.contains(edge.getToId())){
            neighbors.add(graph.getNode(level, edge.getToId()));
          }
        }
        for(DNVEdge edge : middlenode.getToEdges()){
          if(!traveledNodesId.contains(edge.getFromId())){
            neighbors.add(graph.getNode(level, edge.getFromId()));
          }
        }
        for(DNVNode neighbor : neighbors){
          Integer neighborId = neighbor.getId();
          Integer neighborDegree = neighbor.getConnectivity();
          rightEdge = middlenode.getEdgeToNeighbor(neighborId);
          Tuple<Integer, Integer, Integer> degreeTuple = new Tuple<Integer, Integer, Integer>(highDegree, lowDegree, neighborDegree);
          if(!degreeOccurTableDK3.containsKey(degreeTuple)){
            //degreeEdgeTableDK3.put(degreeTuple, new ArrayList<Pair<DNVEdge, DNVEdge>>());
            degreeOccurTableDK3.put(degreeTuple, 0)
            degreeUniqueEdgeTableDK3.put(degreeTuple, new HashSet<DNVEdge>());
            degreeUniqueNodeTableDK3.put(degreeTuple, new HashSet<DNVNode>());
          }
          //degreeEdgeTableDK3.get(degreeTuple).add(new Pair<DNVEdge,DNVEdge>(tuple.getRight(),middlenode.getEdgeToNeighbor(neighborId)));
          degreeOccurTableDK3.put(degreeTuple, degreeOccurTableDK3.get(degreeTuple) + 1);

          degreeUniqueEdgeTableDK3.get(degreeTuple).add(leftEdge);
          degreeUniqueEdgeTableDK3.get(degreeTuple).add(rightEdge);
          degreeUniqueNodeTableDK3.get(degreeTuple).add(middlenode);
          degreeUniqueNodeTableDK3.get(degreeTuple).add(leftNode);
          degreeUniqueNodeTableDK3.get(degreeTuple).add(neighbor);
         
         
          if(leftNode.getNeighbors().contains(neighbor) || neighbor.getNeighbors().contains(leftNode)){
            middleEdge = leftNode.getEdgeToNeighbor(neighborId);
            Triangle triangle = new Triangle(leftNode, middlenode, neighbor, leftEdge, middleEdge, rightEdge);
            triangles.add(triangle);
            degreeUniqueEdgeTableDK3.get(degreeTuple).add(middleEdge);
            triangleCnt++;
          }else{
View Full Code Here

TOP

Related Classes of net.wigis.graph.dnv.DNVNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.