示例#1
0
 @Override
 public void initArchitecture() {
   this.vizConfig = VizController.getInstance().getVizConfig();
   this.engine = VizController.getInstance().getEngine();
   mouseSelectionDiameter = vizConfig.getMouseSelectionDiameter();
   selectionUpdateWhileDragging = vizConfig.isMouseSelectionUpdateWhileDragging();
 }
  public void initArchitecture() {
    this.engine = VizController.getInstance().getEngine();
    this.drawable = VizController.getInstance().getDrawable();
    this.limits = VizController.getInstance().getLimits();
    this.vizController = VizController.getInstance();

    leaves =
        new ParamAVLTree<Octant>(
            new AVLItemAccessor<Octant>() {

              public int getNumber(Octant item) {
                return item.getNumber();
              }
            });
    visibleLeaves = new ArrayList<Octant>();
    selectedLeaves = new ArrayList<Octant>();

    iteratorQueue = new ConcurrentLinkedQueue<OctreeIterator>();
    iteratorQueue.add(new OctreeIterator());
    iteratorQueue.add(new OctreeIterator());
    iteratorQueue.add(new OctreeIterator());
    iteratorQueue.add(new OctreeIterator());

    float dis = size / (float) Math.pow(2, this.maxDepth + 1);
    root = new Octant(this, 0, dis, dis, dis, size);
  }
 @Override
 public void initArchitecture() {
   this.engine = VizController.getInstance().getEngine();
   controller = Lookup.getDefault().lookup(GraphController.class);
   this.vizConfig = VizController.getInstance().getVizConfig();
   this.modeManager = VizController.getInstance().getModeManager();
   this.limits = VizController.getInstance().getLimits();
 }
  public void select(Tool tool) {
    unselect();
    if (tool == null) {
      return;
    }

    // Connect events
    ArrayList<ToolEventHandler> handlers = new ArrayList<ToolEventHandler>();
    for (ToolEventListener toolListener : tool.getListeners()) {
      if (toolListener instanceof NodeClickEventListener) {
        NodeClickEventHandler h = new NodeClickEventHandler(toolListener);
        h.select();
        handlers.add(h);
      } else if (toolListener instanceof NodePressingEventListener) {
        NodePressingEventHandler h = new NodePressingEventHandler(toolListener);
        h.select();
        handlers.add(h);
      } else if (toolListener instanceof MouseClickEventListener) {
        MouseClickEventHandler h = new MouseClickEventHandler(toolListener);
        h.select();
        handlers.add(h);
      } else if (toolListener instanceof NodePressAndDraggingEventListener) {
        NodePressAndDraggingEventHandler h = new NodePressAndDraggingEventHandler(toolListener);
        h.select();
        handlers.add(h);

      } else {
        throw new RuntimeException(
            "The ToolEventListener "
                + toolListener.getClass().getSimpleName()
                + " cannot be recognized");
      }
    }
    currentHandlers = handlers.toArray(new ToolEventHandler[0]);
    switch (tool.getSelectionType()) {
      case NONE:
        VizController.getInstance().getSelectionManager().disableSelection();
        break;
      case SELECTION:
        VizController.getInstance().getSelectionManager().blockSelection(true);
        VizController.getInstance().getSelectionManager().setDraggingEnable(false);
        break;
      case SELECTION_AND_DRAGGING:
        VizController.getInstance().getSelectionManager().blockSelection(true);
        VizController.getInstance().getSelectionManager().setDraggingEnable(true);
        break;
    }
    currentTool = tool;
    unselectTool = currentTool.select();

    if (unselectTool) {
      toolbar.clearSelection();
      unselect();
    }
  }
  public void updateSelectedOctant(GL gl, GLU glu, float[] mousePosition, float[] pickRectangle) {
    // Start Picking mode
    int capacity =
        1 * 4 * visibleLeaves.size(); // 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.glDisable(GL.GL_CULL_FACE); // Disable flags

    gl.glInitNames();
    gl.glPushName(0);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    glu.gluPickMatrix(
        mousePosition[0],
        mousePosition[1],
        pickRectangle[0],
        pickRectangle[1],
        drawable.getViewport());
    gl.glMultMatrixd(drawable.getProjectionMatrix());

    gl.glMatrixMode(GL.GL_MODELVIEW);

    // Draw the nodes' cube int the select buffer
    int hitName = 1;
    for (int i = 0; i < visibleLeaves.size(); i++) {
      Octant node = visibleLeaves.get(i);
      gl.glLoadName(hitName);
      node.displayOctant(gl);
      hitName++;
    }

    // Restoring the original projection matrix
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glFlush();

    // Returning to normal rendering mode
    int nbRecords = gl.glRenderMode(GL.GL_RENDER);
    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);
    }

    // Clean previous selection
    selectedLeaves.clear();

    // Get the hits and put the node under selection in the selectionArray
    for (int i = 0; i < nbRecords; i++) {
      int hit = hitsBuffer.get(i * 4 + 3) - 1; // -1 Because of the glPushName(0)

      Octant nodeHit = visibleLeaves.get(hit);
      selectedLeaves.add(nodeHit);
    }
  }
    public void select() {
      currentListeners = new VizEventListener[2];
      currentListeners[0] =
          new VizEventListener() {

            public void handleEvent(VizEvent event) {
              toolEventListener.pressingNodes((Node[]) event.getData());
            }

            public Type getType() {
              return VizEvent.Type.NODE_LEFT_PRESSING;
            }
          };
      currentListeners[1] =
          new VizEventListener() {

            public void handleEvent(VizEvent event) {
              toolEventListener.released();
            }

            public Type getType() {
              return VizEvent.Type.MOUSE_RELEASED;
            }
          };
      VizController.getInstance().getVizEventManager().addListener(currentListeners);
    }
  public void displayOctree(GL gl, GLU glu) {
    gl.glDisable(GL.GL_CULL_FACE);
    gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
    for (Octant o : visibleLeaves) {
      gl.glColor3f(1, 0.5f, 0.5f);
      o.displayOctant(gl);
      o.displayOctantInfo(gl, glu);
    }
    if (!vizController.getVizConfig().isWireFrame()) {
      gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
    }

    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);
    }
  }
示例#8
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 select() {
      currentListener =
          new VizEventListener() {

            public void handleEvent(VizEvent event) {
              toolEventListener.clickNodes((Node[]) event.getData());
            }

            public Type getType() {
              return VizEvent.Type.NODE_LEFT_CLICK;
            }
          };
      VizController.getInstance().getVizEventManager().addListener(currentListener);
    }
示例#10
0
 public void cleanDeletedObjects(int classID) {
   for (Octant o : leaves) {
     for (cleanObjectsIterator.setNode(o.getTree(classID)); cleanObjectsIterator.hasNext(); ) {
       ModelImpl obj = cleanObjectsIterator.next();
       if (!obj.isCacheMatching(cacheMarker)) {
         removeObject(classID, obj);
         obj.resetOctant();
         if (vizController.getVizConfig().isCleanDeletedModels()) {
           obj.cleanModel();
         }
       }
     }
   }
 }
示例#11
0
  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);
  }
    public void select() {
      currentListener =
          new VizEventListener() {

            public void handleEvent(VizEvent event) {
              float[] data = (float[]) event.getData();
              int[] viewport = new int[] {(int) data[0], (int) data[1]};
              float[] threed = new float[] {data[2], data[3]};
              toolEventListener.mouseClick(viewport, threed);
            }

            public Type getType() {
              return VizEvent.Type.MOUSE_LEFT_CLICK;
            }
          };
      VizController.getInstance().getVizEventManager().addListener(currentListener);
    }
示例#13
0
  public void createModelClassesCompatibility(CompatibilityEngine engine) {
    // NODE
    nodeClass = new ModelClass(0, "NODE", true, true, true, false);
    NodeSphereModeler modeler3d = new NodeSphereModeler(engine);
    NodeDiskModeler modeler2d = new NodeDiskModeler(engine);
    NodeRectangleModeler modelerRect = new NodeRectangleModeler(engine);
    nodeClass.addModeler(modeler3d);
    nodeClass.addModeler(modeler2d);
    nodeClass.addModeler(modelerRect);
    if (VizController.getInstance().getVizModel().isUse3d()) {
      nodeClass.setCurrentModeler(modeler3d);
    } else {
      nodeClass.setCurrentModeler(modeler2d);
    }

    // EDGE
    edgeClass = new ModelClass(1, "EDGE", false, true, false, true);
    EdgeModeler edgeModeler = new EdgeModeler(engine);
    edgeClass.addModeler(edgeModeler);
    edgeClass.setCurrentModeler(edgeModeler);
  }
    public void select() {
      currentListeners = new VizEventListener[3];
      currentListeners[0] =
          new VizEventListener() {

            public void handleEvent(VizEvent event) {
              toolEventListener.pressNodes((Node[]) event.getData());
            }

            public Type getType() {
              return VizEvent.Type.NODE_LEFT_PRESS;
            }
          };
      currentListeners[1] =
          new VizEventListener() {

            public void handleEvent(VizEvent event) {
              float[] mouseDrag = (float[]) event.getData();
              toolEventListener.drag(mouseDrag[0], mouseDrag[1]);
            }

            public Type getType() {
              return VizEvent.Type.DRAG;
            }
          };
      currentListeners[2] =
          new VizEventListener() {

            public void handleEvent(VizEvent event) {
              toolEventListener.released();
            }

            public Type getType() {
              return VizEvent.Type.MOUSE_RELEASED;
            }
          };
      VizController.getInstance().getVizEventManager().addListener(currentListeners);
    }
示例#15
0
 public TextColorMode() {
   this.vizConfig = VizController.getInstance().getVizConfig();
 }
 public void unselect() {
   VizController.getInstance().getVizEventManager().removeListener(currentListener);
   toolEventListener = null;
   currentListener = null;
 }
  public JComponent getToolbar() {

    // Get tools ui
    HashMap<ToolUI, Tool> toolMap = new HashMap<ToolUI, Tool>();
    List<ToolUI> toolsUI = new ArrayList<ToolUI>();
    for (Tool tool : tools) {
      ToolUI ui = tool.getUI();
      if (ui != null) {
        toolsUI.add(ui);
        toolMap.put(ui, tool);
      }
    }
    // Sort by priority
    Collections.sort(
        toolsUI,
        new Comparator() {

          public int compare(Object o1, Object o2) {
            Integer p1 = ((ToolUI) o1).getPosition();
            Integer p2 = ((ToolUI) o2).getPosition();
            return p1.compareTo(p2);
          }
        });

    // Create toolbar
    final Toolbar toolbar = new Toolbar();
    for (final ToolUI toolUI : toolsUI) {
      final Tool tool = toolMap.get(toolUI);
      JToggleButton btn;
      if (toolUI.getIcon() != null) {
        btn = new JToggleButton(toolUI.getIcon());
      } else {
        btn =
            new JToggleButton(
                new ImageIcon(getClass().getResource("/org/gephi/desktop/tools/tool.png")));
      }
      btn.setToolTipText(toolUI.getName() + " - " + toolUI.getDescription());
      btn.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              // Let the user unselect a tool (by clicking on it again) without having to select
              // other tool:
              if (tool == currentTool) {
                toolbar.clearSelection();
                unselect();
              } else {
                select(tool);

                if (!unselectTool) propertiesBar.select(toolUI.getPropertiesBar(tool));
              }
            }
          });
      toolbar.add(btn);
    }

    // SelectionManager events
    VizController.getInstance()
        .getSelectionManager()
        .addChangeListener(
            new ChangeListener() {

              public void stateChanged(ChangeEvent e) {
                SelectionManager selectionManager =
                    VizController.getInstance().getSelectionManager();

                if (selectionManager.isRectangleSelection() && currentTool != null) {
                  toolbar.clearSelection();
                  unselect();
                } else if (selectionManager.isSelectionEnabled()
                    && currentTool != null
                    && currentTool.getSelectionType() == ToolSelectionType.NONE) {
                  toolbar.clearSelection();
                  unselect();
                } else if (selectionManager.isDraggingEnabled() && currentTool != null) {
                  toolbar.clearSelection();
                  unselect();
                }
              }
            });

    this.toolbar = toolbar;

    return toolbar;
  }
示例#18
0
 public void initArchitecture() {
   this.drawable = VizController.getInstance().getDrawable();
   this.limits = VizController.getInstance().getLimits();
   this.vizController = VizController.getInstance();
 }
  public void initArchitecture() {
    model = VizController.getInstance().getVizModel().getTextModel();
    vizConfig = VizController.getInstance().getVizConfig();
    drawable = VizController.getInstance().getDrawable();
    initRenderer();

    // Init sizemodes
    for (SizeMode s : sizeModes) {
      s.init();
    }

    // Model listening
    model.addChangeListener(
        new ChangeListener() {

          public void stateChanged(ChangeEvent e) {
            if (!nodeRenderer.getFont().equals(model.getNodeFont())) {
              nodeRenderer.setFont(model.getNodeFont());
            }
            if (!edgeRenderer.getFont().equals(model.getEdgeFont())) {
              edgeRenderer.setFont(model.getEdgeFont());
            }
            nodeRefresh = true;
            edgeRefresh = true;
          }
        });

    // Model change
    VizController.getInstance()
        .getVizModel()
        .addPropertyChangeListener(
            new PropertyChangeListener() {

              public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("init")) {
                  TextManager.this.model = VizController.getInstance().getVizModel().getTextModel();

                  // Initialize columns if needed
                  if (model.getNodeTextColumns() == null
                      || model.getNodeTextColumns().length == 0) {
                    AttributeController attributeController =
                        Lookup.getDefault().lookup(AttributeController.class);
                    if (attributeController != null && attributeController.getModel() != null) {
                      AttributeModel attributeModel = attributeController.getModel();
                      AttributeColumn[] nodeCols =
                          new AttributeColumn[] {
                            attributeModel
                                .getNodeTable()
                                .getColumn(PropertiesColumn.NODE_LABEL.getIndex())
                          };
                      AttributeColumn[] edgeCols =
                          new AttributeColumn[] {
                            attributeModel
                                .getEdgeTable()
                                .getColumn(PropertiesColumn.EDGE_LABEL.getIndex())
                          };
                      model.setTextColumns(nodeCols, edgeCols);
                    }
                  }

                  DynamicModel dynamicModel = dynamicController.getModel();
                  if (dynamicModel != null) {
                    currentTimeInterval = dynamicModel.getVisibleInterval();
                    builder.setDefaultEstimator(dynamicModel.getEstimator());
                    builder.setNumberEstimator(dynamicModel.getNumberEstimator());
                  } else {
                    currentTimeInterval = null;
                  }
                }
              }
            });

    // Settings
    antialised = vizConfig.isLabelAntialiased();
    mipmap = vizConfig.isLabelMipMap();
    fractionalMetrics = vizConfig.isLabelFractionalMetrics();
    renderer3d = false;

    // Dynamic change
    dynamicController = Lookup.getDefault().lookup(DynamicController.class);
    dynamicController.addModelListener(
        new DynamicModelListener() {

          public void dynamicModelChanged(DynamicModelEvent event) {
            if (event.getEventType().equals(DynamicModelEvent.EventType.VISIBLE_INTERVAL)) {
              currentTimeInterval = (TimeInterval) event.getData();
            }
          }
        });
  }
 public void selectCluster(Cluster cluster) {
   SelectionManager selectionManager = VizController.getInstance().getSelectionManager();
   selectionManager.resetSelection();
   selectionManager.selectNodes(cluster.getNodes());
 }
示例#21
0
 @Override
 public void defaultEdgeColor(Renderer renderer) {
   color = VizController.getInstance().getVizModel().getTextModel().edgeColor;
 }