Beispiel #1
0
  public void addNode(NodeModel node) {
    if (node.getOctant() != null) {
      throw new RuntimeException("Can't add a node to two octants");
    }
    Octant octant = root;
    int depth = octant.depth;

    clampPosition(node);

    while (depth < maxDepth) {
      if (octant.children == null) {
        subdivide(octant);
      }

      int index = node.octreePosition(octant.posX, octant.posY, octant.posZ, octant.size);
      octant = octant.children[index];
      depth = octant.depth;
    }

    if (octant.isEmpty()) {
      addLeaf(octant);
    }

    octant.addNode(node);
    node.setOctant(octant);
  }
Beispiel #2
0
 public boolean repositionNodes() {
   List<NodeModel> movedNodes = new ArrayList<NodeModel>();
   for (int i = 0; i < length; i++) {
     Octant leaf = leaves[i];
     if (leaf != null) {
       int l = leaf.nodesLength;
       NodeModel[] nodes = leaf.nodes;
       for (int j = 0; j < l; j++) {
         NodeModel node = nodes[j];
         if (node != null) {
           if (!node.isInOctreeLeaf(leaf)) {
             removeNode(node);
             movedNodes.add(node);
           }
         }
       }
     }
   }
   if (!movedNodes.isEmpty()) {
     for (NodeModel node : movedNodes) {
       addNode(node);
     }
     return true;
   }
   return false;
 }
Beispiel #3
0
 public void removeNode(NodeModel node) {
   Octant octant = node.getOctant();
   octant.removeNode(node);
   if (octant.isEmpty()) {
     removeLeaf(octant);
   }
   node.setOctant(null);
 }
Beispiel #4
0
 @Override
 public boolean hasNext() {
   pointer = null;
   while (pointer == null) {
     while (edgeId < edgeLength && pointer == null) {
       pointer = edges[edgeId++];
     }
     if (pointer == null) {
       if (nodeItr.hasNext()) {
         NodeModel node = nodeItr.next();
         edges = node.getEdges();
         edgeLength = edges.length;
         edgeId = 0;
       } else {
         return false;
       }
     }
   }
   return true;
 }
Beispiel #5
0
 private void clampPosition(NodeModel nodeModel) {
   // Clamp Hack to avoid nodes to be outside octree
   float quantum = size / 2;
   Node node = nodeModel.getNode();
   float x = node.x();
   float y = node.y();
   float z = node.z();
   if (x > root.posX + quantum) {
     node.setX(root.posX + quantum);
   } else if (x < root.posX - quantum) {
     node.setX(root.posX - quantum);
   }
   if (y > root.posY + quantum) {
     node.setY(root.posY + quantum);
   } else if (y < root.posY - quantum) {
     node.setY(root.posY - quantum);
   }
   if (z > root.posZ + quantum) {
     node.setZ(root.posZ + quantum);
   } else if (z < root.posZ - quantum) {
     node.setZ(root.posZ - quantum);
   }
 }
Beispiel #6
0
 @Override
 public void textNodeColor(Renderer renderer, NodeModel nodeModel) {
   textColor(renderer, nodeModel, nodeModel.isSelected() || nodeModel.isHighlight());
 }