Esempio n. 1
0
  /** Transfers internal line data to jReality */
  private void updateLines() {
    if (lineCoordinates.size() == 0) return;
    ilsf.setVertexCount(lineCoordinates.size());
    ilsf.setVertexCoordinates(lineCoordinates.toArray(new double[0][0]));

    Color[] pointColorsArray = new Color[lineColors.size() * 2];
    for (int i = 0; i < lineColors.size(); i++) {
      pointColorsArray[2 * i] = lineColors.get(i);
      pointColorsArray[2 * i + 1] = lineColors.get(i);
    }
    ilsf.setVertexColors(pointColorsArray);
    pointColorsArray = null;

    double[] pointSizesArray = new double[lineSizes.size() * 2];
    for (int i = 0; i < lineColors.size(); i++) {
      pointSizesArray[2 * i] = lineSizes.get(i);
      pointSizesArray[2 * i + 1] = lineSizes.get(i);
    }
    ilsf.setVertexRelativeRadii(pointSizesArray);

    ilsf.setEdgeCount(lineIndices.size() / 2);
    ilsf.setEdgeColors(lineColors.toArray(new Color[0]));

    int[] indicesArray = new int[lineIndices.size()];
    for (int i = 0; i < lineIndices.size(); ++i) indicesArray[i] = lineIndices.get(i);
    ilsf.setEdgeIndices(indicesArray);

    double[] sizesArray = new double[lineSizes.size()];
    for (int i = 0; i < lineSizes.size(); ++i) sizesArray[i] = lineSizes.get(i);
    ilsf.setEdgeRelativeRadii(sizesArray);

    int[] typesArray = new int[lineTypes.size()];
    for (int i = 0; i < lineTypes.size(); ++i) typesArray[i] = lineTypes.get(i);
    ilsf.setEdgeAttribute(Attribute.attributeForName("lineType"), new IntArray(typesArray));

    ilsf.update();
  }
Esempio n. 2
0
  public JRealityViewer() {
    psf = new PointSetFactory();
    pointCoordinates = new ArrayList<double[]>();
    pointColors = new ArrayList<Color>();
    pointSizes = new ArrayList<Double>();

    psf2 = new PointSetFactory();
    circleCenters = new ArrayList<double[]>();
    circleNormals = new ArrayList<double[]>();
    circleRadii = new ArrayList<Double>();
    circleColors = new ArrayList<Color>();

    ilsf = new IndexedLineSetFactory();
    lineCoordinates = new ArrayList<double[]>();
    lineIndices = new ArrayList<Integer>();
    lineSizes = new ArrayList<Double>();
    lineColors = new ArrayList<Color>();
    lineTypes = new ArrayList<Integer>();

    ifsf = new IndexedFaceSetFactory();
    polygonVertices = new ArrayList<double[][]>();
    polygonColors = new ArrayList<Color>();
    polygonTotalVertexCount = 0;

    sceneRoot = new SceneGraphComponent("root");

    // TODO: Set custom appearances for these components
    scenePoints = SceneGraphUtility.createFullSceneGraphComponent("points");
    scenePoints.setGeometry(psf.getGeometry());
    DefaultGeometryShader dgs =
        ShaderUtility.createDefaultGeometryShader(scenePoints.getAppearance(), true);
    dgs.createPointShader("my");

    sceneCircles = SceneGraphUtility.createFullSceneGraphComponent("circles");
    sceneCircles.setGeometry(psf2.getGeometry());
    dgs = ShaderUtility.createDefaultGeometryShader(sceneCircles.getAppearance(), true);
    dgs.createPointShader("circle");

    sceneLines = SceneGraphUtility.createFullSceneGraphComponent("lines");
    sceneLines.setGeometry(ilsf.getGeometry());
    dgs = ShaderUtility.createDefaultGeometryShader(sceneLines.getAppearance(), true);
    dgs.createPointShader("my");
    dgs.createLineShader("my");

    scenePolygons = new SceneGraphComponent("polygons");
    scenePolygons.setGeometry(ifsf.getGeometry());

    sceneMeshes = SceneGraphUtility.createFullSceneGraphComponent("meshes");

    sceneRoot.addChild(scenePoints);
    sceneRoot.addChild(sceneCircles);
    sceneRoot.addChild(sceneLines);
    sceneRoot.addChild(scenePolygons);
    sceneRoot.addChild(sceneMeshes);

    viewer = new JRViewer();
    viewer.setContent(sceneRoot);
    // viewer.registerPlugin(new DirectContent());
    viewer.registerPlugin(new ContentTools());
    // viewer.registerPlugin(new ContentLoader());
    // viewer.addBasicUI();

    // All plugins from as in BasicUI except shell
    viewer.registerPlugin(new Inspector());
    // viewer.registerPlugin(new Shell());

    viewer.registerPlugin(new BackgroundColor());
    viewer.registerPlugin(new DisplayOptions());
    viewer.registerPlugin(new ViewMenuBar());
    viewer.registerPlugin(new ViewToolBar());

    viewer.registerPlugin(new ExportMenu());
    viewer.registerPlugin(new CameraMenu());
    viewer.registerPlugin(new PropertiesMenu());
    //

    viewer.setShowPanelSlots(false, true, false, false);

    frame = new JFrame("Cindy3D");
    frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(viewer.startupLocal(), BorderLayout.CENTER);
    frame.pack();

    RenderingHintsShader rhs =
        ShaderUtility.createDefaultRenderingHintsShader(
            viewer.getViewer().getSceneRoot().getAppearance(), true);
    rhs.setTransparencyEnabled(true);

    // Set camera near and far plane
    camera = CameraUtility.getCamera(viewer.getViewer());
    camera.setNear(0.1);
    camera.setFar(1000.0);
  }