Exemplo n.º 1
0
 @Override
 public boolean hasNext() {
   if (ibond == bondCount) return false;
   while ((bond = bonds[ibond++]) == null
       || (bsAtoms != null && (!bsAtoms.get(bond.atomIndex1) || !bsAtoms.get(bond.atomIndex2))))
     if (ibond == bondCount) return false;
   return true;
 }
Exemplo n.º 2
0
 private void getStateAtoms(SB sb) {
   BS bsDone = new BS();
   Map<String, BS> temp = new Hashtable<String, BS>();
   Map<String, BS> temp2 = new Hashtable<String, BS>();
   for (Ellipsoid e : atomEllipsoids.values()) {
     int iType = e.tensor.iType;
     if (bsDone.get(iType + 1)) continue;
     bsDone.set(iType + 1);
     boolean isADP = (e.tensor.iType == Tensor.TYPE_ADP);
     String cmd = (isADP ? null : "Ellipsoids set " + PT.esc(e.tensor.type));
     for (Ellipsoid e2 : atomEllipsoids.values()) {
       if (e2.tensor.iType != iType || isADP && !e2.isOn) continue;
       int i = e2.tensor.atomIndex1;
       //
       BSUtil.setMapBitSet(
           temp,
           i,
           i,
           (isADP
               ? "Ellipsoids " + e2.percent
               : cmd
                   + " scale "
                   + e2.scale
                   + (e2.options == null ? "" : " options " + PT.esc(e2.options))
                   + (e2.isOn ? " ON" : " OFF")));
       if (e2.colix != C.INHERIT_ALL)
         BSUtil.setMapBitSet(
             temp2, i, i, getColorCommand(cmd, e2.pid, e2.colix, translucentAllowed));
     }
   }
   sb.append(vwr.getCommands(temp, temp2, "select"));
 }
Exemplo n.º 3
0
 public void resetTransPolygons() {
   boolean isTranslucent = C.isColixTranslucent(colix);
   float translucentLevel = C.getColixTranslucencyFractional(colix);
   for (int i = 0; i < pc; i++)
     if (bsTransPolygons.get(i)) {
       if (!setABC(i)) continue;
       vcs[iA] = C.getColixTranslucent3(vcs[iA], isTranslucent, translucentLevel);
       vcs[iB] = C.getColixTranslucent3(vcs[iB], isTranslucent, translucentLevel);
       vcs[iC] = C.getColixTranslucent3(vcs[iC], isTranslucent, translucentLevel);
     }
   bsTransPolygons = null;
   polygonTranslucencies = null;
 }
Exemplo n.º 4
0
 private void setVis(Map<?, Ellipsoid> ellipsoids, BS bs, Atom[] atoms) {
   for (Ellipsoid e : ellipsoids.values()) {
     Tensor t = e.tensor;
     boolean isOK = (t != null && e.isValid && e.isOn);
     if (isOK && t.atomIndex1 >= 0) {
       if (t.iType == Tensor.TYPE_ADP) {
         boolean isModTensor = t.isModulated;
         boolean isUnmodTensor = t.isUnmodulated;
         boolean isModAtom = ms.isModulated(t.atomIndex1);
         isOK = (!isModTensor && !isUnmodTensor || isModTensor == isModAtom);
       }
       atoms[t.atomIndex1].setShapeVisibility(vf, true);
     }
     e.visible = isOK && (e.modelIndex < 0 || bs.get(e.modelIndex));
   }
 }
Exemplo n.º 5
0
  private boolean initializePolymer(BioShape bioShape) {
    BS bsDeleted = vwr.getDeletedAtoms();
    if (vwr.ms.isJmolDataFrameForModel(bioShape.modelIndex)) {
      controlPoints = bioShape.bioPolymer.getControlPoints(true, 0, false);
    } else {
      controlPoints =
          bioShape.bioPolymer.getControlPoints(isTraceAlpha, sheetSmoothing, invalidateSheets);
    }
    monomerCount = bioShape.monomerCount;
    bsRenderMesh = BS.newN(monomerCount);
    monomers = bioShape.monomers;
    reversed = bioShape.bioPolymer.reversed;
    leadAtomIndices = bioShape.bioPolymer.getLeadAtomIndices();

    bsVisible.clearAll();
    boolean haveVisible = false;
    if (invalidateMesh) bioShape.falsifyMesh();
    for (int i = monomerCount; --i >= 0; ) {
      if ((monomers[i].shapeVisibilityFlags & myVisibilityFlag) == 0
          || ms.isAtomHidden(leadAtomIndices[i])
          || bsDeleted != null && bsDeleted.get(leadAtomIndices[i])) continue;
      Atom lead = ms.at[leadAtomIndices[i]];
      if (!g3d.isInDisplayRange(lead.sX, lead.sY)) continue;
      bsVisible.set(i);
      haveVisible = true;
    }
    if (!haveVisible) return false;
    ribbonBorder = vwr.getBoolean(T.ribbonborder);

    // note that we are not treating a PhosphorusPolymer
    // as nucleic because we are not calculating the wing
    // vector correctly.
    // if/when we do that then this test will become
    // isNucleic = bioShape.bioPolymer.isNucleic();

    isNucleic = bioShape.bioPolymer instanceof NucleicPolymer;
    isCarbohydrate = bioShape.bioPolymer instanceof CarbohydratePolymer;
    haveControlPointScreens = false;
    wingVectors = bioShape.wingVectors;
    meshReady = bioShape.meshReady;
    meshes = bioShape.meshes;
    mads = bioShape.mads;
    colixes = bioShape.colixes;
    colixesBack = bioShape.colixesBack;
    setStructureTypes();
    return true;
  }
Exemplo n.º 6
0
 /**
  * @param doFill
  * @param i
  * @param thisTypeOnly true for Cartoon but not MeshRibbon
  */
 protected void renderHermiteRibbon(boolean doFill, int i, boolean thisTypeOnly) {
   // cartoons and meshRibbon
   setNeighbors(i);
   colix = getLeadColix(i);
   if (!setBioColix(colix)) return;
   colixBack = getLeadColixBack(i);
   if (doFill && (aspectRatio != 0 || isExport)) {
     if (setMads(i, thisTypeOnly) || isExport) {
       try {
         if ((meshes[i] == null || !meshReady[i])
             && !createMesh(i, madBeg, madMid, madEnd, aspectRatio, isNucleic ? 4 : 7)) return;
         meshes[i].setColix(colix);
         meshes[i].setColixBack(colixBack);
         bsRenderMesh.set(i);
         return;
       } catch (Exception e) {
         bsRenderMesh.clear(i);
         meshes[i] = null;
         Logger.error("render mesh error hermiteRibbon: " + e.toString());
         // System.out.println(e.getMessage());
       }
     }
   }
   g3d.drawHermite7(
       doFill,
       ribbonBorder,
       (reversed.get(i) ? -1 : 1) * (isNucleic ? 4 : 7),
       ribbonTopScreens[iPrev],
       ribbonTopScreens[i],
       ribbonTopScreens[iNext],
       ribbonTopScreens[iNext2],
       ribbonBottomScreens[iPrev],
       ribbonBottomScreens[i],
       ribbonBottomScreens[iNext],
       ribbonBottomScreens[iNext2],
       (int) aspectRatio,
       colixBack);
 }
Exemplo n.º 7
0
 private static float checkSlab(
     int tokType, T3 v, float val, float distance, P4 plane, T3[] ptCenters, BS bs) {
   float d;
   switch (tokType) {
     case T.decimal:
       return (val >= 0 && bs.get((int) val) ? 1 : -1);
     case T.min:
       d = distance - val;
       break;
     case T.max:
       d = val - distance;
       break;
     case T.plane:
       d = Measure.distanceToPlane(plane, v);
       break;
     case T.distance:
       d = minDist(v, ptCenters) - distance;
       break;
     default:
       d = -minDist(v, ptCenters) - distance;
       break;
   }
   return (Math.abs(d) < 0.0001f ? 0 : d);
 }
Exemplo n.º 8
0
  /**
   * @param distance a distance from a plane or point
   * @param plane a slabbing plane
   * @param ptCenters a set of atoms to measure distance from
   * @param vData when not null, this is a query, not an actual slabbing
   * @param fData vertex values or other data to overlay
   * @param bsSource TODO
   * @param meshSurface second surface; not implemented -- still some problems there
   * @param andCap to cap this off, crudely only
   * @param doClean compact set - draw only
   * @param tokType type of slab
   * @param isGhost translucent slab, so we mark slabbed triangles
   */
  public void getIntersection(
      float distance,
      P4 plane,
      P3[] ptCenters,
      Lst<P3[]> vData,
      float[] fData,
      BS bsSource,
      MeshSurface meshSurface,
      boolean andCap,
      boolean doClean,
      int tokType,
      boolean isGhost) {
    boolean isSlab = (vData == null);
    P3[] pts = null;
    if (fData == null) {
      if (tokType == T.decimal && bsSource != null) {
        if (vertexSource == null) return;
        fData = new float[vc];
        for (int i = 0; i < vc; i++)
          if ((fData[i] = vertexSource[i]) == -1) System.out.println("meshsurface hmm");
      } else {
        fData = vvs;
      }
    }
    Map<String, Integer> mapEdge = new Hashtable<String, Integer>();

    /*
    Vector3f vNorm = null;
    Vector3f vBC = null;
    Vector3f vAC = null;
    Point3f[] pts2 = null;
    Vector3f vTemp3 = null;
    Point4f planeTemp = null;
    boolean isMeshIntersect = (meshSurface != null);
    if (isMeshIntersect) {
      // NOT IMPLEMENTED
      vBC = new Vector3f();
      vAC = new Vector3f();
      vNorm = new Vector3f();
      plane = new Point4f();
      planeTemp = new Point4f();
      vTemp3 = new Vector3f();
      pts2 = new Point3f[] { null, new Point3f(), new Point3f() };
    }
    */
    if (ptCenters != null || isGhost)
      andCap = false; // can only cap faces, and no capping of ghosts
    float[] values = new float[2];
    float[] fracs = new float[2];
    double absD = Math.abs(distance);
    float d1, d2, d3, valA, valB, valC;
    int sourceA = 0, sourceB = 0, sourceC = 0, setA = 0;
    Lst<int[]> iPts = (andCap ? new Lst<int[]>() : null);
    if (pc == 0) {
      for (int i = mergeVertexCount0; i < vc; i++) {
        if (Float.isNaN(fData[i])
            || checkSlab(tokType, vs[i], fData[i], distance, plane, ptCenters, bsSource) > 0)
          bsSlabDisplay.clear(i);
      }
      return;
    }
    int iLast = pc;
    for (int i = mergePolygonCount0; i < iLast; i++) {
      if (!setABC(i)) continue;
      BS bsSlab = (bsSlabGhost != null && bsSlabGhost.get(i) ? bsSlabGhost : bsSlabDisplay);
      int check1 = pis[i][3];
      int check2 = (checkCount == 2 ? pis[i][4] : 0);
      T3 vA = vs[iA];
      T3 vB = vs[iB];
      T3 vC = vs[iC];
      valA = fData[iA];
      valB = fData[iB];
      valC = fData[iC];
      if (vertexSource != null) {
        sourceA = vertexSource[iA];
        sourceB = vertexSource[iB];
        sourceC = vertexSource[iC];
      }
      if (vertexSets != null) setA = vertexSets[iA];
      d1 =
          checkSlab(
              tokType,
              vA,
              valA,
              (bsSource == null ? distance : sourceA),
              plane,
              ptCenters,
              bsSource);
      d2 =
          checkSlab(
              tokType,
              vB,
              valB,
              (bsSource == null ? distance : sourceB),
              plane,
              ptCenters,
              bsSource);
      d3 =
          checkSlab(
              tokType,
              vC,
              valC,
              (bsSource == null ? distance : sourceC),
              plane,
              ptCenters,
              bsSource);
      int test1 =
          (d1 != 0 && d1 < 0 ? 1 : 0) + (d2 != 0 && d2 < 0 ? 2 : 0) + (d3 != 0 && d3 < 0 ? 4 : 0);

      /*
            if (iA == 955 || iB == 955 || iC == 955) {
              System.out.println(i + " " + iA + " " + iB + " " + iC + " "+ d1 + " " + d2 + " " + d3 + " " + test1);
              System.out.println("testing messhsurf ");
            }
      */
      /*
      if (isMeshIntersect && test1 != 7 && test1 != 0) {
        // NOT IMPLEMENTED
        boolean isOK = (d1 == 0 && d2 * d3 >= 0 || d2 == 0 && (d1 * d3) >= 0 || d3 == 0
            && d1 * d2 >= 0);
        if (isOK)
          continue;
        // We have a potential crossing. Now to find the exact point of crossing
        // the other isosurface.
        if (checkIntersection(vA, vB, vC, meshSurface, pts2, vNorm, vBC, vAC,
            plane, planeTemp, vTemp3)) {
          iD = addIntersectionVertex(pts2[0], 0, sourceA, mapEdge, -1, -1); // have to choose some source
          addPolygon(iA, iB, iD, check1 & 1, check2, 0, bsSlabDisplay);
          addPolygon(iD, iB, iC, check1 & 2, check2, 0, bsSlabDisplay);
          addPolygon(iA, iD, iC, check1 & 4, check2, 0, bsSlabDisplay);
          test1 = 0; // toss original
          iLast = polygonCount;
        } else {
          // process normally for now
          // not fully implemented -- need to check other way as well.
        }
      }
      */
      switch (test1) {
        default:
        case 7:
        case 0:
          // all on the same side
          break;
        case 1:
        case 6:
          // BC on same side
          if (ptCenters == null)
            pts =
                new P3[] {
                  interpolatePoint(vA, vB, -d1, d2, valA, valB, values, fracs, 0),
                  interpolatePoint(vA, vC, -d1, d3, valA, valC, values, fracs, 1)
                };
          else
            pts =
                new P3[] {
                  interpolateSphere(vA, vB, -d1, -d2, absD, valA, valB, values, fracs, 0),
                  interpolateSphere(vA, vC, -d1, -d3, absD, valA, valC, values, fracs, 1)
                };
          break;
        case 2:
        case 5:
          // AC on same side
          if (ptCenters == null)
            pts =
                new P3[] {
                  interpolatePoint(vB, vA, -d2, d1, valB, valA, values, fracs, 1),
                  interpolatePoint(vB, vC, -d2, d3, valB, valC, values, fracs, 0)
                };
          else
            pts =
                new P3[] {
                  interpolateSphere(vB, vA, -d2, -d1, absD, valB, valA, values, fracs, 1),
                  interpolateSphere(vB, vC, -d2, -d3, absD, valB, valC, values, fracs, 0)
                };
          break;
        case 3:
        case 4:
          // AB on same side need A-C, B-C
          if (ptCenters == null)
            pts =
                new P3[] {
                  interpolatePoint(vC, vA, -d3, d1, valC, valA, values, fracs, 0),
                  interpolatePoint(vC, vB, -d3, d2, valC, valB, values, fracs, 1)
                };
          else
            pts =
                new P3[] {
                  interpolateSphere(vC, vA, -d3, -d1, absD, valC, valA, values, fracs, 0),
                  interpolateSphere(vC, vB, -d3, -d2, absD, valC, valB, values, fracs, 1)
                };
          break;
      }
      doClear = true;
      doGhost = isGhost;
      doCap = andCap;
      BS bs;
      // adjust for minor discrepencies
      // for (int j = 0; j < 2; j++)
      // if (fracs[j] == 0)
      // fracs[1 - j] = (fracs[1 - j] < 0.5 ? 0 : 1);

      if (isSlab) {
        //        iD = iE = -1;
        switch (test1) {
            //             A
            //            / \
            //           B---C
          case 0:
            // all on the same side -- toss
            doCap = false;
            break;
          case 7:
            // all on the same side -- keep
            continue;
          case 1:
          case 6:
            //          0  A  0
            //            / \
            //        0 -------- 1
            //          /     \
            //       1 B-------C  1
            boolean tossBC = (test1 == 1);
            if (tossBC || isGhost) {
              // 1: BC on side to toss -- +tossBC+isGhost  -tossBC+isGhost
              if (!getDE(fracs, 0, iA, iB, iC, tossBC)) break;
              if (iD < 0)
                iD = addIntersectionVertex(pts[0], values[0], sourceA, setA, mapEdge, iA, iB);
              if (iE < 0)
                iE = addIntersectionVertex(pts[1], values[1], sourceA, setA, mapEdge, iA, iC);
              bs = (tossBC ? bsSlab : bsSlabGhost);
              addPolygonV3(iA, iD, iE, check1 & 5 | 2, check2, 0, bs);
              if (!isGhost) break;
            }
            // BC on side to keep -- -tossBC+isGhost,  +tossBC+isGhost
            if (!getDE(fracs, 1, iA, iC, iB, tossBC)) break;
            bs = (tossBC ? bsSlabGhost : bsSlab);
            if (iE < 0) {
              iE = addIntersectionVertex(pts[0], values[0], sourceB, setA, mapEdge, iA, iB);
              addPolygonV3(iE, iB, iC, check1 & 3, check2, 0, bs);
            }
            if (iD < 0) {
              iD = addIntersectionVertex(pts[1], values[1], sourceC, setA, mapEdge, iA, iC);
              addPolygonV3(iD, iE, iC, check1 & 4 | 1, check2, 0, bs);
            }
            break;
          case 5:
          case 2:
            //              A
            //            \/ \
            //            /\  \
            //           B--\--C
            //               \
            //
            boolean tossAC = (test1 == 2);
            if (tossAC || isGhost) {
              // AC on side to toss
              if (!getDE(fracs, 0, iB, iC, iA, tossAC)) break;
              bs = (tossAC ? bsSlab : bsSlabGhost);
              if (iE < 0)
                iE = addIntersectionVertex(pts[0], values[0], sourceB, setA, mapEdge, iB, iA);
              if (iD < 0)
                iD = addIntersectionVertex(pts[1], values[1], sourceB, setA, mapEdge, iB, iC);
              addPolygonV3(iE, iB, iD, check1 & 3 | 4, check2, 0, bs);
              if (!isGhost) break;
            }
            // AC on side to keep
            if (!getDE(fracs, 1, iB, iA, iC, tossAC)) break;
            bs = (tossAC ? bsSlabGhost : bsSlab);
            if (iD < 0) {
              iD = addIntersectionVertex(pts[0], values[0], sourceA, setA, mapEdge, iB, iA);
              addPolygonV3(iA, iD, iC, check1 & 5, check2, 0, bs);
            }
            if (iE < 0) {
              iE = addIntersectionVertex(pts[1], values[1], sourceC, setA, mapEdge, iB, iC);
              addPolygonV3(iD, iE, iC, check1 & 2 | 1, check2, 0, bs);
            }
            break;
          case 4:
          case 3:
            //              A
            //             / \/
            //            /  /\
            //           B--/--C
            //             /
            //
            boolean tossAB = (test1 == 4);
            if (tossAB || isGhost) {
              if (!getDE(fracs, 0, iC, iA, iB, tossAB)) break;
              if (iD < 0)
                iD = addIntersectionVertex(pts[0], values[0], sourceC, setA, mapEdge, iA, iC); // CA
              if (iE < 0)
                iE = addIntersectionVertex(pts[1], values[1], sourceC, setA, mapEdge, iB, iC); // CB
              bs = (tossAB ? bsSlab : bsSlabGhost);
              addPolygonV3(iD, iE, iC, check1 & 6 | 1, check2, 0, bs);
              if (!isGhost) break;
            }
            // AB on side to keep
            if (!getDE(fracs, 1, iC, iB, iA, tossAB)) break;
            bs = (tossAB ? bsSlabGhost : bsSlab);
            if (iE < 0) {
              iE = addIntersectionVertex(pts[0], values[0], sourceA, setA, mapEdge, iA, iC); // CA
              addPolygonV3(iA, iB, iE, check1 & 5, check2, 0, bs);
            }
            if (iD < 0) {
              iD = addIntersectionVertex(pts[1], values[1], sourceB, setA, mapEdge, iB, iC); // CB
              addPolygonV3(iE, iB, iD, check1 & 2 | 4, check2, 0, bs);
            }
            break;
        }
        if (doClear) {
          bsSlab.clear(i);
          if (doGhost) bsSlabGhost.set(i);
        }
        if (doCap) {
          iPts.addLast(new int[] {iD, iE});
        }
      } else if (pts != null) {
        vData.addLast(pts);
      }
    }
    if (andCap && iPts.size() > 0) {
      P3 center = new P3();
      for (int i = iPts.size(); --i >= 0; ) {
        int[] ipts = iPts.get(i);
        center.add(vs[ipts[0]]);
        center.add(vs[ipts[1]]);
      }
      center.scale(0.5f / iPts.size());
      int v0 = addIntersectionVertex(center, 0, -1, setA, mapEdge, -1, -1);
      for (int i = iPts.size(); --i >= 0; ) {
        int[] ipts = iPts.get(i);
        // int p =
        addPolygonV3(ipts[0], v0, ipts[1], 0, 0, 0, bsSlabDisplay);
      }
    }

    if (!doClean) return;
    BS bsv = new BS();
    BS bsp = new BS();
    for (int i = 0; i < pc; i++) {
      if (pis[i] == null) continue;
      bsp.set(i);
      for (int j = 0; j < 3; j++) bsv.set(pis[i][j]);
    }
    int n = 0;
    int nPoly = bsp.cardinality();
    if (nPoly != pc) {
      int[] map = new int[vc];
      for (int i = 0; i < vc; i++) if (bsv.get(i)) map[i] = n++;
      T3[] vTemp = new P3[n];
      n = 0;
      for (int i = 0; i < vc; i++) if (bsv.get(i)) vTemp[n++] = vs[i];
      int[][] pTemp = AU.newInt2(nPoly);
      nPoly = 0;
      for (int i = 0; i < pc; i++)
        if (pis[i] != null) {
          for (int j = 0; j < 3; j++) pis[i][j] = map[pis[i][j]];
          pTemp[nPoly++] = pis[i];
        }
      vs = vTemp;
      vc = n;
      pis = pTemp;
      pc = nPoly;
    }
  }