void render(Graphics3D g3d, ModelSet modelSet) { // , Rectangle rectClip
   if (!viewer.getRefreshing()) return;
   render1(g3d, modelSet); // , rectClip
   Rectangle band = viewer.getRubberBandSelection();
   if (band != null && g3d.setColix(viewer.getColixRubberband()))
     g3d.drawRect(band.x, band.y, 0, 0, band.width, band.height);
 }
Exemple #2
0
 protected void drawPolygon(float[] x, float[] y, int count) {
   // only polygons with 3 or 4 corners used
   if (count >= 3)
     ((Graphics3D) mG)
         .fillTriangle(
             mColix, (int) x[0], (int) y[0], mZ, (int) x[1], (int) y[1], mZ, (int) x[2],
             (int) y[2], mZ);
   if (count == 4)
     ((Graphics3D) mG)
         .fillTriangle(
             mColix, (int) x[2], (int) y[2], mZ, (int) x[3], (int) y[3], mZ, (int) x[0],
             (int) y[0], mZ);
 }
Exemple #3
0
 protected void drawString(String s, float x, float y) {
   if (mpTextSize > 1) {
     double strWidth = getStringWidth(s);
     ((Graphics3D) mG)
         .drawStringNoSlab(
             s, null, (int) (x - strWidth / 2.0), (int) (y + (double) mpTextSize / 3.0), 0);
   }
 }
Exemple #4
0
  private void colorData() {

    float[] vertexValues = meshData.vertexValues;
    short[] vertexColixes = meshData.vertexColixes;
    meshData.polygonColixes = null;
    float valueBlue = jvxlData.valueMappedToBlue;
    float valueRed = jvxlData.valueMappedToRed;
    short minColorIndex = jvxlData.minColorIndex;
    short maxColorIndex = jvxlData.maxColorIndex;
    if (params.colorEncoder == null) params.colorEncoder = new ColorEncoder(null);
    params.colorEncoder.setRange(
        params.valueMappedToRed, params.valueMappedToBlue, params.isColorReversed);
    for (int i = meshData.vertexCount; --i >= 0; ) {
      float value = vertexValues[i];
      if (minColorIndex >= 0) {
        if (value <= 0) vertexColixes[i] = minColorIndex;
        else if (value > 0) vertexColixes[i] = maxColorIndex;
      } else {
        if (value <= valueRed) value = valueRed;
        if (value >= valueBlue) value = valueBlue;
        vertexColixes[i] = params.colorEncoder.getColorIndex(value);
      }
    }

    if ((params.nContours > 0 || jvxlData.contourValues != null)
        && jvxlData.contourColixes == null) {
      int n = (jvxlData.contourValues == null ? params.nContours : jvxlData.contourValues.length);
      short[] colors = jvxlData.contourColixes = new short[n];
      float[] values = jvxlData.contourValues;
      if (values == null) values = jvxlData.contourValuesUsed;
      if (jvxlData.contourValuesUsed == null)
        jvxlData.contourValuesUsed = (values == null ? new float[n] : values);
      float dv = (valueBlue - valueRed) / (n + 1);
      // n + 1 because we want n lines between n + 1 slices
      params.colorEncoder.setRange(
          params.valueMappedToRed, params.valueMappedToBlue, params.isColorReversed);
      for (int i = 0; i < n; i++) {
        float v = (values == null ? valueRed + (i + 1) * dv : values[i]);
        jvxlData.contourValuesUsed[i] = v;
        colors[i] = Graphics3D.getColixTranslucent(params.colorEncoder.getArgb(v));
      }
      // TODO -- this strips translucency
      jvxlData.contourColors = Graphics3D.getHexCodes(colors);
    }
  }
  private void render1(Graphics3D g3d, ModelSet modelSet) { // , Rectangle rectClip

    if (modelSet == null || !viewer.mustRenderFlag()) return;

    logTime = viewer.getTestFlag1();

    viewer.finalizeTransformParameters();

    if (logTime) Logger.startTimer();

    try {
      g3d.renderBackground();
      if (renderers == null) renderers = new ShapeRenderer[JmolConstants.SHAPE_MAX];
      for (int i = 0; i < JmolConstants.SHAPE_MAX && g3d.currentlyRendering(); ++i) {
        Shape shape = modelSet.getShape(i);
        if (shape == null) continue;
        getRenderer(i, g3d).render(g3d, modelSet, shape);
      }

    } catch (Exception e) {
      Logger.error("rendering error -- perhaps use \"set refreshing FALSE/TRUE\" ? ");
    }
    if (logTime) Logger.checkTimer("render time");
  }
Exemple #6
0
 protected void setTextSize(int h) {
   mpTextSize = h;
   ((Graphics3D) mG).setFont(((Graphics3D) mG).getFont3D(h));
 }
Exemple #7
0
 protected void fillCircle(float x, float y, float r) {
   ((Graphics3D) mG).drawCircleCentered(mColix, (int) (2 * r), (int) x, (int) y, mZ, true);
 }
Exemple #8
0
 protected void drawDottedLine(DepictorLine theLine) {
   ((Graphics3D) mG)
       .drawDottedLine(
           new Point3i((int) theLine.x1, (int) theLine.y1, mZ),
           new Point3i((int) theLine.x2, (int) theLine.y2, mZ));
 }
Exemple #9
0
 protected void drawBlackLine(DepictorLine theLine) {
   ((Graphics3D) mG)
       .drawLine((int) theLine.x1, (int) theLine.y1, mZ, (int) theLine.x2, (int) theLine.y2, mZ);
 }
Exemple #10
0
 protected void setColor(Color c) {
   ((Graphics3D) mG).setColix(Graphics3D.getColix(c.getRGB()));
 }
 void setTranslucent(boolean isTranslucent, float translucentLevel) {
   colix = Graphics3D.getColixTranslucent(colix, isTranslucent, translucentLevel);
 }
Exemple #12
0
  void applyColorScale() {
    colorFractionBase = jvxlData.colorFractionBase = JvxlCoder.defaultColorFractionBase;
    colorFractionRange = jvxlData.colorFractionRange = JvxlCoder.defaultColorFractionRange;
    if (params.colorPhase == 0) params.colorPhase = 1;
    if (meshDataServer == null) {
      meshData.vertexColixes = new short[meshData.vertexCount];
    } else {
      meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES, null);
      if (params.contactPair == null)
        meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_COLOR_INDEXES, null);
    }
    // colorBySign is true when colorByPhase is true, but not vice-versa
    // old: boolean saveColorData = !(params.colorByPhase && !params.isBicolorMap &&
    // !params.colorBySign); //sorry!
    boolean saveColorData =
        (params.colorDensity || params.isBicolorMap || params.colorBySign || !params.colorByPhase);
    if (params.contactPair != null) saveColorData = false;
    // colors mappable always now
    jvxlData.isJvxlPrecisionColor = true;
    jvxlData.vertexCount = (contourVertexCount > 0 ? contourVertexCount : meshData.vertexCount);
    jvxlData.minColorIndex = -1;
    jvxlData.maxColorIndex = 0;
    jvxlData.contourValues = params.contoursDiscrete;
    jvxlData.isColorReversed = params.isColorReversed;
    if (!params.colorDensity)
      if (params.isBicolorMap && !params.isContoured || params.colorBySign) {
        jvxlData.minColorIndex =
            Graphics3D.getColixTranslucent(
                Graphics3D.getColix(params.isColorReversed ? params.colorPos : params.colorNeg),
                jvxlData.translucency != 0,
                jvxlData.translucency);
        jvxlData.maxColorIndex =
            Graphics3D.getColixTranslucent(
                Graphics3D.getColix(params.isColorReversed ? params.colorNeg : params.colorPos),
                jvxlData.translucency != 0,
                jvxlData.translucency);
      }
    jvxlData.isTruncated = (jvxlData.minColorIndex >= 0 && !params.isContoured);
    boolean useMeshDataValues =
        jvxlDataIs2dContour
            ||
            //      !jvxlDataIs2dContour && (params.isContoured && jvxlData.jvxlPlane != null ||
            hasColorData
            || vertexDataOnly
            || params.colorDensity
            || params.isBicolorMap && !params.isContoured;
    if (!useMeshDataValues) {
      if (haveSurfaceAtoms && meshData.vertexSource == null)
        meshData.vertexSource = new int[meshData.vertexCount];
      float min = Float.MAX_VALUE;
      float max = -Float.MAX_VALUE;
      float value;
      initializeMapping();
      for (int i = meshData.vertexCount; --i >= meshData.mergeVertexCount0; ) {
        /* right, so what we are doing here is setting a range within the
         * data for which we want red-->blue, but returning the actual
         * number so it can be encoded more precisely. This turned out to be
         * the key to making the JVXL contours work.
         *
         */
        if (params.colorBySets) {
          value = meshData.vertexSets[i];
        } else if (params.colorByPhase) {
          value = getPhase(meshData.vertices[i]);
          // else if (jvxlDataIs2dContour)
          // marchingSquares
          //    .getInterpolatedPixelValue(meshData.vertices[i]);
        } else {
          value = volumeData.lookupInterpolatedVoxelValue(meshData.vertices[i]);
          if (haveSurfaceAtoms) meshData.vertexSource[i] = getSurfaceAtomIndex();
        }
        if (value < min) min = value;
        if (value > max && value != Float.MAX_VALUE) max = value;
        meshData.vertexValues[i] = value;
      }
      if (params.rangeSelected && minMax == null) minMax = new float[] {min, max};
      finalizeMapping();
    }
    params.setMapRanges(this, true);
    jvxlData.mappedDataMin = params.mappedDataMin;
    jvxlData.mappedDataMax = params.mappedDataMax;
    jvxlData.valueMappedToRed = params.valueMappedToRed;
    jvxlData.valueMappedToBlue = params.valueMappedToBlue;
    if (params.contactPair == null) colorData();

    JvxlCoder.jvxlCreateColorData(jvxlData, (saveColorData ? meshData.vertexValues : null));

    if (haveSurfaceAtoms && meshDataServer != null)
      meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_VERTICES, null);

    if (meshDataServer != null && params.colorBySets)
      meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_SETS, null);
  }