Search in sources :

Example 1 with NodeModeler

use of org.gephi.visualization.model.node.NodeModeler in project gephi by gephi.

the class DataBridge method updateWorld.

public synchronized boolean updateWorld() {
    boolean force = false;
    if (graphModel != null) {
        graphModel.getGraph().writeLock();
    }
    try {
        if ((observer != null && observer.isDestroyed()) || (graphModel != null && graph.getView() != graphModel.getVisibleView())) {
            if (observer != null && !observer.isDestroyed()) {
                observer.destroy();
            }
            observer = null;
            if (graphModel != null) {
                graph = graphModel.getGraphVisible();
                observer = graphModel.createGraphObserver(graph, false);
                force = true;
            }
        }
    } finally {
        if (graphModel != null) {
            graphModel.getGraph().readUnlockAll();
            graphModel.getGraph().writeUnlock();
        }
    }
    if (force || (observer != null && (observer.isNew() || observer.hasGraphChanged())) || hasColumnsChanged()) {
        if (observer.isNew()) {
            observer.hasGraphChanged();
        }
        NodeModeler nodeModeler = engine.getNodeModeler();
        EdgeModeler edgeModeler = engine.getEdgeModeler();
        Octree octree = engine.getOctree();
        //Stats
        int removedNodes = 0;
        int addedNodes = 0;
        int removedEdges = 0;
        int addedEdges = 0;
        graph.readLock();
        try {
            boolean isView = !graph.getView().isMainView();
            for (int i = 0; i < nodes.length; i++) {
                NodeModel node = nodes[i];
                if (node != null && (node.getNode().getStoreId() == -1 || (isView && !graph.contains(node.getNode())))) {
                    //Removed
                    octree.removeNode(node);
                    nodes[i] = null;
                    removedNodes++;
                }
            }
            for (Node node : graph.getNodes()) {
                int id = node.getStoreId();
                NodeModel model;
                if (id >= nodes.length || nodes[id] == null) {
                    growNodes(id);
                    model = nodeModeler.initModel(node);
                    octree.addNode(model);
                    nodes[id] = model;
                    addedNodes++;
                } else {
                    model = nodes[id];
                }
                textManager.refreshNode(graph, model, textModel);
            }
            for (int i = 0; i < edges.length; i++) {
                EdgeModel edge = edges[i];
                if (edge != null && (edge.getEdge().getStoreId() == -1 || (isView && !graph.contains(edge.getEdge())))) {
                    //Removed
                    int sourceId = edge.getEdge().getSource().getStoreId();
                    int targetId = edge.getEdge().getTarget().getStoreId();
                    NodeModel sourceModel = sourceId == -1 ? null : nodes[sourceId];
                    NodeModel targetModel = targetId == -1 ? null : nodes[targetId];
                    if (sourceModel != null) {
                        sourceModel.removeEdge(edge);
                    }
                    if (targetModel != null && sourceModel != targetModel) {
                        targetModel.removeEdge(edge);
                    }
                    edges[i] = null;
                    removedEdges++;
                }
            }
            float minWeight = Float.MAX_VALUE;
            float maxWeight = Float.MIN_VALUE;
            for (Edge edge : graph.getEdges()) {
                int id = edge.getStoreId();
                EdgeModel model;
                if (id >= edges.length || edges[id] == null) {
                    growEdges(id);
                    NodeModel sourceModel = nodes[edge.getSource().getStoreId()];
                    NodeModel targetModel = nodes[edge.getTarget().getStoreId()];
                    model = edgeModeler.initModel(edge, sourceModel, targetModel);
                    sourceModel.addEdge(model);
                    if (targetModel != sourceModel) {
                        targetModel.addEdge(model);
                    }
                    edges[id] = model;
                    addedEdges++;
                } else {
                    model = edges[id];
                }
                float w = (float) edge.getWeight(graph.getView());
                model.setWeight(w);
                minWeight = Math.min(w, minWeight);
                maxWeight = Math.max(w, maxWeight);
                textManager.refreshEdge(graph, model, textModel);
            }
            if (!isView) {
                limits.setMaxWeight(maxWeight);
                limits.setMinWeight(minWeight);
            }
        } finally {
            graph.readUnlockAll();
        }
        return true;
    } else if (observer == null) {
        Octree octree = engine.getOctree();
        if (!octree.isEmpty()) {
            octree.clear();
        }
    }
    return false;
}
Also used : NodeModel(org.gephi.visualization.model.node.NodeModel) NodeModeler(org.gephi.visualization.model.node.NodeModeler) EdgeModeler(org.gephi.visualization.model.edge.EdgeModeler) Node(org.gephi.graph.api.Node) Octree(org.gephi.visualization.octree.Octree) Edge(org.gephi.graph.api.Edge) EdgeModel(org.gephi.visualization.model.edge.EdgeModel)

Example 2 with NodeModeler

use of org.gephi.visualization.model.node.NodeModeler in project gephi by gephi.

the class CompatibilityEngine method initObject3dClass.

@Override
public void initObject3dClass() {
    nodeModeler = new NodeModeler(this);
    edgeModeler = new EdgeModeler(this);
    nodeModeler.setEnabled(true);
    edgeModeler.setEnabled(vizController.getVizModel().isShowEdges());
}
Also used : NodeModeler(org.gephi.visualization.model.node.NodeModeler) EdgeModeler(org.gephi.visualization.model.edge.EdgeModeler)

Aggregations

EdgeModeler (org.gephi.visualization.model.edge.EdgeModeler)2 NodeModeler (org.gephi.visualization.model.node.NodeModeler)2 Edge (org.gephi.graph.api.Edge)1 Node (org.gephi.graph.api.Node)1 EdgeModel (org.gephi.visualization.model.edge.EdgeModel)1 NodeModel (org.gephi.visualization.model.node.NodeModel)1 Octree (org.gephi.visualization.octree.Octree)1