Exemplo n.º 1
0
  /** @see boogiepants.model.Displayable#display() */
  public Node display() {
    Appearance a = new Appearance();
    Group shape = new Sphere(.15f, a);
    a.setColoringAttributes(new ColoringAttributes(.5f, .5f, 1f, ColoringAttributes.NICEST));
    a.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, .3f));
    Transform3D t = new Transform3D();
    if (loPoint == null) {
      loPoint = new Point3d(0d, 0d, 0d);
    }
    t.set(new Vector3d(loPoint.x, loPoint.y, loPoint.z));
    transformGroupLo = new TransformGroup();
    transformGroupLo.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    transformGroupLo.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transformGroupLo.setTransform(t);
    transformGroupLo.addChild(shape);
    loEndpoint = endpoint(loPoint, transformGroupLo);
    Shape3D geom = (Shape3D) shape.getChild(0);
    geom.setUserData(loEndpoint);

    a = new Appearance();
    shape = new Sphere(.15f, a);
    a.setColoringAttributes(new ColoringAttributes(1f, .5f, .5f, ColoringAttributes.NICEST));
    a.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, .3f));
    t = new Transform3D();
    if (hiPoint == null) {
      hiPoint = new Point3d(0d, 0d, 0d);
    }
    t.set(new Vector3d(hiPoint.x, hiPoint.y, hiPoint.z));
    transformGroupHi = new TransformGroup();
    transformGroupHi.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    transformGroupHi.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transformGroupHi.setTransform(t);
    transformGroupHi.addChild(shape);
    hiEndpoint = endpoint(hiPoint, transformGroupHi);
    geom = (Shape3D) shape.getChild(0);
    geom.setUserData(hiEndpoint);

    container = new BranchGroup();
    container.setCapability(BranchGroup.ALLOW_DETACH);
    container.addChild(transformGroupHi);
    container.addChild(transformGroupLo);
    stickGroup = BoogiepantsDisplayWindow.getInstance().getStickGroup();

    behavior = new ScaleInstrumentBehavior(oscaddress, loPoint, hiPoint, stickGroup);
    container.addChild(behavior);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    behavior.setSchedulingBounds(bounds);

    editGroup = new BranchGroup();
    editGroup.setCapability(BranchGroup.ALLOW_DETACH);
    editGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    editGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    container.addChild(editGroup);

    behavior.computeLineLen();

    return container;
  }
Exemplo n.º 2
0
  /**
   * Simple algorithm to add or remove an edge from the selection Ideas: 1. Use one shape per quad
   * => easy, but can become very fast too big to fit in memory. => pb: flicker when adding /
   * removing because the scene is detached 2. Use only one shape, modify geometry TODO: pre-create
   * an empty shape to avoid initial flicker
   *
   * @param on
   * @param p
   * @param u
   * @param v
   * @param groupIdx2
   */
  protected void toggleSelectedEdge(boolean on, SelectionEdge se) {
    if (on) {
      // add the given edge to the list
      if (edgeSelection.contains(se)) return; // already in
      edgeSelection.add(se);
    } else {
      // remove the given edge from the list
      if (!edgeSelection.contains(se)) return; // not present
      edgeSelection.remove(se);
      if (edgeSelection.size() == 0) {
        LineArray la = (LineArray) edgeSelectionShape.getGeometry();
        la.setValidVertexCount(0);
        return;
      }
    }
    // Use in-memory arrays instead of NIO because edgeSelection should not
    // be too big
    // => faster
    LineArray la =
        new LineArray(
            edgeSelection.size() * 2,
            GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.BY_REFERENCE);
    double[] coords = new double[edgeSelection.size() * 2 * 3];
    float[] colors = new float[edgeSelection.size() * 2 * 3];

    for (int i = 0; i < coords.length; i += 6) {
      SelectionEdge edge = edgeSelection.get(i / 6);
      edge.updateCoords(grid, coords, i);
      edge.updateColors(colors, i);
    }
    la.setCoordRefDouble(coords);
    la.setColorRefFloat(colors);
    la.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
    // update edgeSelection Shape with the new edgeSelection list
    if (edgeSelectionShape == null) {
      Appearance a = new Appearance();
      // PolygonAttributes pa = new
      // PolygonAttributes(PolygonAttributes.POLYGON_LINE,
      // PolygonAttributes.CULL_NONE, 0);
      // pa.setPolygonOffset(1); // above edges
      // pa.setPolygonOffsetFactor(1);
      LineAttributes lat = new LineAttributes();
      lat.setLineWidth(2.0f);
      lat.setLineAntialiasingEnable(true);
      a.setLineAttributes(lat);
      // a.setPolygonAttributes(pa);
      edgeSelectionShape = new Shape3D(la, a);
      edgeSelectionShape.setUserData(this);
      edgeSelectionShape.setPickable(false);
      edgeSelectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
      edgeSelectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

      BranchGroup bg = new BranchGroup();
      bg.addChild(edgeSelectionShape);
      addChild(bg);
    } else edgeSelectionShape.setGeometry(la);
  }
Exemplo n.º 3
0
  private BranchGroup setApperancePackInBranchGroup(Shape3D shape, Node handle) {
    shape.setUserData(this);

    shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

    BranchGroup bg = new BranchGroup();
    bg.setCapability(BranchGroup.ALLOW_DETACH);
    bg.addChild(handle);
    bg.compile();
    return bg;
  }
Exemplo n.º 4
0
  /**
   * Simple algorithm to add or remove a quad from the selection Ideas: 1. Use one shape per quad =>
   * easy, but can become very fast too big to fit in memory. => pb: flicker when adding / removing
   * because the scene is detached 2. Use only one shape, modify geometry TODO: pre-create an empty
   * shape to avoid initial flicker
   *
   * @param on
   * @param p
   * @param u
   * @param v
   * @param groupIdx2
   */
  protected void toggleSelectedQuad(boolean on, SelectionQuad sq) {
    LOGGER.finest("on=" + on + " selectionQuad=" + sq);
    if (on) {
      // add the given quad to the list
      if (selection.contains(sq)) return; // already in
      selection.add(sq);
    } else {
      // remove the given quad from the list
      if (!selection.contains(sq)) return; // not present
      selection.remove(sq);
      if (selection.size() == 0) {
        QuadArray qa = (QuadArray) selectionShape.getGeometry();
        qa.setValidVertexCount(0);
        return;
      }
    }
    // Use in-memory arrays instead of NIO because selection should not be
    // too big
    // => faster
    QuadArray qa =
        new QuadArray(
            selection.size() * 4,
            GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.BY_REFERENCE);
    float[] coords = new float[selection.size() * 4 * 3];
    float[] colors = new float[selection.size() * 4 * 3];

    for (int i = 0; i < coords.length; i += 12) {
      SelectionQuad quad = selection.get(i / 12);
      quad.updateCoords(grid, coords, i);
      quad.updateColors(colors, i);
    }
    qa.setCoordRefFloat(coords);
    qa.setColorRefFloat(colors);
    qa.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
    // update selection Shape with the new selection list
    if (selectionShape == null) {
      Appearance a = new Appearance();
      PolygonAttributes pa =
          new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
      pa.setPolygonOffset(0.5f); // between faces and edges
      pa.setPolygonOffsetFactor(0.5f);
      a.setPolygonAttributes(pa);
      selectionShape = new Shape3D(qa, a);
      selectionShape.setUserData(this);
      selectionShape.setPickable(false);
      selectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
      selectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
      BranchGroup bg = new BranchGroup();
      bg.addChild(selectionShape);
      addChild(bg);
    } else selectionShape.setGeometry(qa);
  }
Exemplo n.º 5
0
  protected void makeWires() {
    Wire[] wires = createWireList();

    if (wires.length == 0) return;

    FloatBuffer nioWires =
        ByteBuffer.allocateDirect(wires.length * 2 * 3 * 4)
            .order(ByteOrder.nativeOrder())
            .asFloatBuffer();

    for (int i = 0; i < wires.length; i++) {
      nioWires.put(wires[i].getCoordinates(grid));
    }

    // Create edge shapes directly, don't make it appear in graph
    LineArray la =
        new NioLineArray(wires.length * 2, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
    la.setCoordRefBuffer(new J3DBuffer(nioWires));
    int colSize = wires.length * 2 * 3;
    FloatBuffer nioWireColors =
        ByteBuffer.allocateDirect(colSize * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
    float[] colors = getColorForOrder(-2, 0);
    for (int i = 0; i < colSize; i += 3) nioWireColors.put(colors);
    la.setColorRefBuffer(new J3DBuffer(nioWireColors));
    la.setUserData(new int[] {-2, 0});
    Appearance a = new Appearance();
    // PolygonAttributes pa = new
    // PolygonAttributes(PolygonAttributes.POLYGON_LINE,
    // PolygonAttributes.CULL_NONE, 0);
    // pa.setPolygonOffset(2);
    // pa.setPolygonOffsetFactor(2);
    // a.setPolygonAttributes(pa);
    /*
     * LineAttributes lat = new LineAttributes(); lat.setLineWidth(2.0f);
     * a.setLineAttributes(lat);
     */
    Shape3D s3d = new Shape3D(la, a);
    PickTool.setCapabilities(s3d, PickTool.INTERSECT_FULL);
    s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    s3d.setCapability(Node.ALLOW_PICKABLE_READ);
    s3d.setCapability(Node.ALLOW_PICKABLE_WRITE);
    s3d.setPickable(true); // by default, can be changed with actions
    s3d.setUserData(this); // this object will handle edges
    addChild(s3d);
    allEdgeShapes.add(s3d);
  }
Exemplo n.º 6
0
  protected void makeGroups() {
    int totalQuads = 0;
    int totalInternalEdges = 0;
    int totalExternalEdges = 0;
    // loop over each group
    // loop over each group
    int[] groupID = provider.getDomainIDs();

    for (int g = 0; g < groupID.length; ++g) {
      LOGGER.finest("generating java3d tree for group number " + groupID[g]);
      // Set of EdgeLine objects. Overlapping edges on the same line are
      // merged together
      HashMap<EdgeLine, EdgeLine> externalEdges = new HashMap<EdgeLine, EdgeLine>();
      // Same trick for internal edges.
      HashMap<EdgeLine, EdgeLine> internalEdges = new HashMap<EdgeLine, EdgeLine>();
      FDDomain fdDomain = (FDDomain) provider.getDomain(groupID[g]);
      baseColor.put(new Integer(g), fdDomain.getColor());
      Plate[] plates = domainToPlates(fdDomain);

      if (plates.length == 0) continue;

      // Create plates for this group
      FloatBuffer nioCoords =
          ByteBuffer.allocateDirect(plates.length * 4 * 3 * 4)
              .order(ByteOrder.nativeOrder())
              .asFloatBuffer();
      FloatBuffer nioColors =
          ByteBuffer.allocateDirect(plates.length * 4 * 3 * 4)
              .order(ByteOrder.nativeOrder())
              .asFloatBuffer();
      float[] baseColor = getColorForOrder(g, 0);
      // System.out.println(baseColor[0]+" "+baseColor[1]+" "+baseColor[2]);
      for (int np = 0; np < plates.length; ++np) {
        Plate p = plates[np];
        // put coordinates
        nioCoords.put(p.getCoordinates(grid));
        // put colors for the 4 vertices
        nioColors.put(baseColor);
        nioColors.put(baseColor);
        nioColors.put(baseColor);
        nioColors.put(baseColor);
        // Merge external edges
        addEdge(externalEdges, getLine(p, 2, p.min1), p.min2, p.max2);
        addEdge(externalEdges, getLine(p, 2, p.max1), p.min2, p.max2);
        addEdge(externalEdges, getLine(p, 1, p.min2), p.min1, p.max1);
        addEdge(externalEdges, getLine(p, 1, p.max2), p.min1, p.max1);
        // Merge internal edges
        for (int i = p.min1 + 1; i < p.max1; ++i)
          addEdge(internalEdges, getLine(p, 2, i), p.min2, p.max2);
        for (int j = p.min2 + 1; j < p.max2; ++j)
          addEdge(internalEdges, getLine(p, 1, j), p.min1, p.max1);
      }
      // use by reference array of colors => fast to change!
      QuadArray qa =
          new NioQuadArray(plates.length * 4, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
      qa.setCoordRefBuffer(new J3DBuffer(nioCoords));
      qa.setColorRefBuffer(new J3DBuffer(nioColors));
      qa.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
      qa.setCapabilityIsFrequent(GeometryArray.ALLOW_COLOR_WRITE);
      Appearance a = new Appearance();
      PolygonAttributes pa =
          new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
      pa.setPolygonOffset(1);
      pa.setPolygonOffsetFactor(1);
      a.setPolygonAttributes(pa);
      Shape3D s3d = new Shape3D(qa, a);
      PickTool.setCapabilities(s3d, PickTool.INTERSECT_FULL);
      s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
      s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
      s3d.setCapability(Node.ALLOW_PICKABLE_READ);
      s3d.setCapability(Node.ALLOW_PICKABLE_WRITE);
      s3d.setPickable(true);
      s3d.setUserData(new BehindShape(s3d, plates, g));

      this.addChild(s3d);

      // Create edge shapes directly, don't make them appear in graph
      int nInternalEdges = 0;
      for (Iterator<EdgeLine> it = internalEdges.keySet().iterator(); it.hasNext(); ) {
        EdgeLine el = it.next();
        nInternalEdges += el.getNumberOfEdges();
      }
      if (nInternalEdges > 0) {
        DoubleBuffer nioInternalEdges =
            ByteBuffer.allocateDirect(nInternalEdges * 2 * 3 * 8)
                .order(ByteOrder.nativeOrder())
                .asDoubleBuffer();
        // create edge coords
        for (Iterator<EdgeLine> it = internalEdges.keySet().iterator(); it.hasNext(); ) {
          EdgeLine el = it.next();
          nioInternalEdges.put(el.getCoords(grid));
        }
        LineArray la =
            new NioLineArray(nInternalEdges * 2, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
        la.setCoordRefBuffer(new J3DBuffer(nioInternalEdges));
        int colSize = nInternalEdges * 2 * 3;
        FloatBuffer nioInternalColors =
            ByteBuffer.allocateDirect(colSize * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
        float[] colors = getColorForOrder(g, 2);
        for (int i = 0; i < colSize; i += 3) nioInternalColors.put(colors);
        la.setColorRefBuffer(new J3DBuffer(nioInternalColors));
        la.setUserData(new int[] {g, 2});
        a = new Appearance();
        // pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE,
        // PolygonAttributes.CULL_NONE, 0);
        // pa.setPolygonOffset(4);
        // pa.setPolygonOffsetFactor(4);
        // a.setPolygonAttributes(pa);
        // LineAttributes lat = new LineAttributes();
        // lat.setLineAntialiasingEnable(true);
        // a.setLineAttributes(lat);
        // RenderingAttributes ra = new RenderingAttributes();
        // ra.setAlphaTestFunction(RenderingAttributes.GREATER);
        // ra.setAlphaTestValue(0.5f);
        // a.setRenderingAttributes(ra);
        s3d = new Shape3D(la, a);
        PickTool.setCapabilities(s3d, PickTool.INTERSECT_FULL);
        s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
        s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
        s3d.setCapability(Node.ALLOW_PICKABLE_READ);
        s3d.setCapability(Node.ALLOW_PICKABLE_WRITE);
        s3d.setPickable(false); // by default, see actions
        s3d.setUserData(this); // this object will handle edges
        this.addChild(s3d);
        allEdgeShapes.add(s3d);
      }
      // Now, create external edge
      int nExternalEdges = 0;
      for (Iterator<EdgeLine> it = externalEdges.keySet().iterator(); it.hasNext(); ) {
        EdgeLine el = it.next();
        nExternalEdges += el.getNumberOfEdges();
      }
      if (nExternalEdges > 0) {
        DoubleBuffer nioExternalEdges =
            ByteBuffer.allocateDirect(nExternalEdges * 2 * 3 * 8)
                .order(ByteOrder.nativeOrder())
                .asDoubleBuffer();
        // create edge coords
        for (Iterator<EdgeLine> it = externalEdges.keySet().iterator(); it.hasNext(); ) {
          EdgeLine el = it.next();
          nioExternalEdges.put(el.getCoords(grid));
        }
        LineArray la =
            new NioLineArray(nExternalEdges * 2, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
        la.setCoordRefBuffer(new J3DBuffer(nioExternalEdges));
        int colSize = nExternalEdges * 2 * 3;
        FloatBuffer nioExternalColors =
            ByteBuffer.allocateDirect(colSize * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
        float[] colors = getColorForOrder(g, 4);
        for (int i = 0; i < colSize; i += 3) nioExternalColors.put(colors);
        la.setColorRefBuffer(new J3DBuffer(nioExternalColors));
        la.setUserData(new int[] {g, 4});
        a = new Appearance();
        // pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE,
        // PolygonAttributes.CULL_NONE, 0);
        // pa.setPolygonOffset(3);
        // pa.setPolygonOffsetFactor(3);
        // a.setPolygonAttributes(pa);
        s3d = new Shape3D(la, a);
        PickTool.setCapabilities(s3d, PickTool.INTERSECT_FULL);
        s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
        s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
        s3d.setCapability(Node.ALLOW_PICKABLE_READ);
        s3d.setCapability(Node.ALLOW_PICKABLE_WRITE);
        s3d.setPickable(false); // by default, see actions
        s3d.setUserData(this); // this object will handle edges
        this.addChild(s3d);
        allEdgeShapes.add(s3d);
      }
      totalQuads += plates.length;
      totalInternalEdges += nInternalEdges;
      totalExternalEdges += nExternalEdges;
    }
    System.out.println("Total quads: " + totalQuads);
    System.out.println("Total Internal Plate edges: " + totalInternalEdges);
    System.out.println("Total External Plate edges: " + totalExternalEdges);
  }
Exemplo n.º 7
0
  public void createTriangles(
      IfcRoot ifcRootObject, IfcModelInterface ifcModel, TransformGroup buildingTransformGroup)
      throws RenderEngineException {
    RenderEngineInstance instance =
        ifcEngineModel.getInstanceFromExpressId(ifcRootObject.getExpressId());
    RenderEngineInstanceVisualisationProperties instanceInModelling =
        instance.getVisualisationProperties();
    if (instanceInModelling.getPrimitiveCount() != 0) {
      Appearance appearance = appearances.getAppearance(ifcRootObject);
      if (appearance != null) {
        Point3f[] coordinates = new Point3f[instanceInModelling.getPrimitiveCount() * 3];
        Vector3f[] normals = new Vector3f[instanceInModelling.getPrimitiveCount() * 3];
        for (int i = instanceInModelling.getStartIndex();
            i < instanceInModelling.getPrimitiveCount() * 3 + instanceInModelling.getStartIndex();
            i += 3) {
          int offsetIndex = i - instanceInModelling.getStartIndex();
          int i1 = geometry.getIndex(i);
          int i2 = geometry.getIndex(i + 1);
          int i3 = geometry.getIndex(i + 2);

          coordinates[offsetIndex] =
              new Point3f(
                  geometry.getVertex(i1 * 3),
                  geometry.getVertex(i1 * 3 + 1),
                  geometry.getVertex(i1 * 3 + 2));
          coordinates[offsetIndex + 1] =
              new Point3f(
                  geometry.getVertex(i3 * 3),
                  geometry.getVertex(i3 * 3 + 1),
                  geometry.getVertex(i3 * 3 + 2));
          coordinates[offsetIndex + 2] =
              new Point3f(
                  geometry.getVertex(i2 * 3),
                  geometry.getVertex(i2 * 3 + 1),
                  geometry.getVertex(i2 * 3 + 2));

          normals[offsetIndex] =
              new Vector3f(
                  geometry.getNormal(i1 * 3),
                  geometry.getNormal(i1 * 3 + 1),
                  geometry.getNormal(i1 * 3 + 2));
          normals[offsetIndex + 1] =
              new Vector3f(
                  geometry.getNormal(i3 * 3),
                  geometry.getNormal(i3 * 3 + 1),
                  geometry.getNormal(i3 * 3 + 2));
          normals[offsetIndex + 2] =
              new Vector3f(
                  geometry.getNormal(i2 * 3),
                  geometry.getNormal(i2 * 3 + 1),
                  geometry.getNormal(i2 * 3 + 2));
        }
        TriangleArray triangleArray =
            new TriangleArray(
                coordinates.length, GeometryArray.COORDINATES | GeometryArray.NORMALS);
        triangleArray.setCoordinates(0, coordinates);
        triangleArray.setNormals(0, normals);
        Shape3D myShape = new Shape3D(triangleArray, appearance);
        buildingTransformGroup.addChild(myShape);
        myShape.setUserData(ifcRootObject);
      }
    }
  }