private void updateEdges(HierarchicalGraph graph) {
    Modeler edgeInit = engine.getModelClasses()[AbstractEngine.CLASS_EDGE].getCurrentModeler();
    Modeler arrowInit = engine.getModelClasses()[AbstractEngine.CLASS_ARROW].getCurrentModeler();

    EdgeIterable edgeIterable;
    edgeIterable = graph.getEdges();

    float minWeight = Float.POSITIVE_INFINITY;
    float maxWeight = Float.NEGATIVE_INFINITY;

    TimeInterval timeInterval = DynamicUtilities.getVisibleInterval(dynamicModel);

    for (Edge edge : edgeIterable) {
      if (edge.getSource().getNodeData().getModel() == null
          || edge.getTarget().getNodeData().getModel() == null) {
        continue;
      }
      float weight = 1f;
      if (timeInterval == null) {
        weight = edge.getWeight();
      } else {
        weight = edge.getWeight(timeInterval.getLow(), timeInterval.getHigh());
      }
      minWeight = Math.min(minWeight, weight);
      maxWeight = Math.max(maxWeight, weight);
      Edge2dModel obj = (Edge2dModel) edge.getEdgeData().getModel();
      if (obj == null) {
        // Model is null, ADD
        obj = (Edge2dModel) edgeInit.initModel(edge.getEdgeData());
        engine.addObject(AbstractEngine.CLASS_EDGE, obj);
        if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop()) {
          Arrow2dModel arrowObj = (Arrow2dModel) arrowInit.initModel(edge.getEdgeData());
          engine.addObject(AbstractEngine.CLASS_ARROW, arrowObj);
          arrowObj.setCacheMarker(cacheMarker);
          arrowObj.setWeight(weight);
          obj.setArrow(arrowObj);
        }
      } else if (!obj.isValid()) {
        engine.addObject(AbstractEngine.CLASS_EDGE, obj);
        if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop()) {
          Arrow2dModel arrowObj = obj.getArrow();
          engine.addObject(AbstractEngine.CLASS_ARROW, arrowObj);
          arrowObj.setCacheMarker(cacheMarker);
          arrowObj.setWeight(weight);
        }
      } else {
        if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop() && edge.isDirected()) {
          Arrow2dModel arrowObj = obj.getArrow();
          arrowObj.setCacheMarker(cacheMarker);
          arrowObj.setWeight(weight);
        }
      }
      obj.setWeight(weight);
      obj.setCacheMarker(cacheMarker);
    }

    limits.setMinWeight(minWeight);
    limits.setMaxWeight(maxWeight);
  }
示例#2
0
  public void updateVisibleOctant(GL2 gl) {
    if (leavesCount > 0) {
      // Limits
      refreshLimits();

      // Switch to OpenGL2 select mode
      int capacity = 1 * 4 * leavesCount; // Each object take in maximium : 4 * name stack depth
      IntBuffer hitsBuffer = Buffers.newDirectIntBuffer(capacity);
      gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer);
      gl.glRenderMode(GL2.GL_SELECT);
      gl.glInitNames();
      gl.glPushName(0);
      gl.glDisable(GL2.GL_CULL_FACE); // Disable flags
      // Draw the nodes cube in the select buffer
      for (Octant n : leaves) {
        if (n != null) {
          gl.glLoadName(n.leafId);
          n.displayOctant(gl);
          n.visible = false;
        }
      }
      visibleLeaves = 0;
      int nbRecords = gl.glRenderMode(GL2.GL_RENDER);
      if (vizController.getVizModel().isCulling()) {
        gl.glEnable(GL2.GL_CULL_FACE);
        gl.glCullFace(GL2.GL_BACK);
      }

      // Get the hits and add the nodes' objects to the array
      int depth = Integer.MAX_VALUE;
      int minDepth = -1;
      for (int i = 0; i < nbRecords; i++) {
        int hit = hitsBuffer.get(i * 4 + 3); // -1 Because of the glPushName(0)
        int minZ = hitsBuffer.get(i * 4 + 1);
        if (minZ < depth) {
          depth = minZ;
          minDepth = hit;
        }

        Octant nodeHit = leaves[hit];
        nodeHit.visible = true;
        visibleLeaves++;
      }
      if (minDepth != -1) {
        Octant closestOctant = leaves[minDepth];
        Vec3f pos =
            new Vec3f(closestOctant.getPosX(), closestOctant.getPosY(), closestOctant.getPosZ());
        limits.setClosestPoint(pos);
      }
    }
  }
  public void updateVisibleOctant(GL gl) {
    // Limits
    refreshLimits();

    // Switch to OpenGL select mode
    int capacity = 1 * 4 * leaves.getCount(); // Each object take in maximium : 4 * name stack depth
    IntBuffer hitsBuffer = BufferUtil.newIntBuffer(capacity);
    gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer);
    gl.glRenderMode(GL.GL_SELECT);
    gl.glInitNames();
    gl.glPushName(0);
    gl.glDisable(GL.GL_CULL_FACE); // Disable flags
    // Draw the nodes cube in the select buffer
    for (Octant n : leaves) {
      n
          .resetUpdatePositionFlag(); // Profit from the loop to do this, because this method is
                                      // always after updating position
      gl.glLoadName(n.getNumber());
      n.displayOctant(gl);
    }
    int nbRecords = gl.glRenderMode(GL.GL_RENDER);
    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);
    }
    visibleLeaves.clear();

    // Get the hits and add the nodes' objects to the array
    int depth = Integer.MAX_VALUE;
    int minDepth = -1;
    for (int i = 0; i < nbRecords; i++) {
      int hit = hitsBuffer.get(i * 4 + 3); // -1 Because of the glPushName(0)
      int minZ = hitsBuffer.get(i * 4 + 1);
      if (minZ < depth) {
        depth = minZ;
        minDepth = hit;
      }

      Octant nodeHit = leaves.getItem(hit);
      visibleLeaves.add(nodeHit);
    }
    if (minDepth != -1) {
      Octant closestOctant = leaves.getItem(minDepth);
      Vec3f pos =
          new Vec3f(closestOctant.getPosX(), closestOctant.getPosY(), closestOctant.getPosZ());
      limits.setClosestPoint(pos);
    }
    // System.out.println(minDepth);
  }
  private void refreshLimits() {

    float minX = Float.POSITIVE_INFINITY;
    float maxX = Float.NEGATIVE_INFINITY;
    float minY = Float.POSITIVE_INFINITY;
    float maxY = Float.NEGATIVE_INFINITY;
    float minZ = Float.POSITIVE_INFINITY;
    float maxZ = Float.NEGATIVE_INFINITY;

    for (Octant o : leaves) {
      float octanSize = o.getSize() / 2f;
      minX = Math.min(minX, o.getPosX() - octanSize);
      maxX = Math.max(maxX, o.getPosX() + octanSize);
      minY = Math.min(minY, o.getPosY() - octanSize);
      maxY = Math.max(maxY, o.getPosY() + octanSize);
      minZ = Math.min(minZ, o.getPosZ() - octanSize);
      maxZ = Math.max(maxZ, o.getPosZ() + octanSize);
    }

    int viewportMinX = Integer.MAX_VALUE;
    int viewportMaxX = Integer.MIN_VALUE;
    int viewportMinY = Integer.MAX_VALUE;
    int viewportMaxY = Integer.MIN_VALUE;
    double[] point;

    point = drawable.myGluProject(minX, minY, minZ); // bottom far left
    viewportMinX = Math.min(viewportMinX, (int) point[0]);
    viewportMinY = Math.min(viewportMinY, (int) point[1]);
    viewportMaxX = Math.max(viewportMaxX, (int) point[0]);
    viewportMaxY = Math.max(viewportMaxY, (int) point[1]);

    point = drawable.myGluProject(minX, minY, maxZ); // bottom near left
    viewportMinX = Math.min(viewportMinX, (int) point[0]);
    viewportMinY = Math.min(viewportMinY, (int) point[1]);
    viewportMaxX = Math.max(viewportMaxX, (int) point[0]);
    viewportMaxY = Math.max(viewportMaxY, (int) point[1]);

    point = drawable.myGluProject(minX, maxY, maxZ); // up near left
    viewportMinX = Math.min(viewportMinX, (int) point[0]);
    viewportMinY = Math.min(viewportMinY, (int) point[1]);
    viewportMaxX = Math.max(viewportMaxX, (int) point[0]);
    viewportMaxY = Math.max(viewportMaxY, (int) point[1]);

    point = drawable.myGluProject(maxX, minY, maxZ); // bottom near right
    viewportMinX = Math.min(viewportMinX, (int) point[0]);
    viewportMinY = Math.min(viewportMinY, (int) point[1]);
    viewportMaxX = Math.max(viewportMaxX, (int) point[0]);
    viewportMaxY = Math.max(viewportMaxY, (int) point[1]);

    point = drawable.myGluProject(maxX, minY, minZ); // bottom far right
    viewportMinX = Math.min(viewportMinX, (int) point[0]);
    viewportMinY = Math.min(viewportMinY, (int) point[1]);
    viewportMaxX = Math.max(viewportMaxX, (int) point[0]);
    viewportMaxY = Math.max(viewportMaxY, (int) point[1]);

    point = drawable.myGluProject(maxX, maxY, minZ); // up far right
    viewportMinX = Math.min(viewportMinX, (int) point[0]);
    viewportMinY = Math.min(viewportMinY, (int) point[1]);
    viewportMaxX = Math.max(viewportMaxX, (int) point[0]);
    viewportMaxY = Math.max(viewportMaxY, (int) point[1]);

    point = drawable.myGluProject(maxX, maxY, maxZ); // up near right
    viewportMinX = Math.min(viewportMinX, (int) point[0]);
    viewportMinY = Math.min(viewportMinY, (int) point[1]);
    viewportMaxX = Math.max(viewportMaxX, (int) point[0]);
    viewportMaxY = Math.max(viewportMaxY, (int) point[1]);

    point = drawable.myGluProject(minX, maxY, minZ); // up far left
    viewportMinX = Math.min(viewportMinX, (int) point[0]);
    viewportMinY = Math.min(viewportMinY, (int) point[1]);
    viewportMaxX = Math.max(viewportMaxX, (int) point[0]);
    viewportMaxY = Math.max(viewportMaxY, (int) point[1]);

    limits.setMinXoctree(minX);
    limits.setMaxXoctree(maxX);
    limits.setMinYoctree(minY);
    limits.setMaxYoctree(maxY);
    limits.setMinZoctree(minZ);
    limits.setMaxZoctree(maxZ);

    limits.setMinXviewport(viewportMinX);
    limits.setMaxXviewport(viewportMaxX);
    limits.setMinYviewport(viewportMinY);
    limits.setMaxYviewport(viewportMaxY);
  }