示例#1
0
 void excludeMaximumSet() {
   if (meshDataServer != null)
     meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES, null);
   meshData.getSurfaceSet();
   BitSet bs;
   for (int i = meshData.nSets; --i >= 0; )
     if ((bs = meshData.surfaceSet[i]) != null && bs.cardinality() > params.maxSet)
       meshData.invalidateSurfaceSet(i);
   updateSurfaceData();
   if (meshDataServer != null) meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_SETS, null);
 }
示例#2
0
 public int addTriangleCheck(
     int iA, int iB, int iC, int check, int check2, boolean isAbsolute, int color) {
   if (marchingSquares != null && params.isContoured) {
     if (color == 0) // from marching cubes
     return marchingSquares.addTriangle(iA, iB, iC, check, check2);
     color = 0; // from marchingSquares
   }
   return (meshDataServer != null
       ? meshDataServer.addTriangleCheck(iA, iB, iC, check, check2, isAbsolute, color)
       : isAbsolute && !MeshData.checkCutoff(iA, iB, iC, meshData.vertexValues)
           ? -1
           : meshData.addTriangleCheck(iA, iB, iC, check, check2, color));
 }
示例#3
0
 public void slabIsosurface(List<Object[]> slabInfo) {
   if (meshDataServer != null)
     meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES, null);
   meshData.slabPolygons(slabInfo, true);
   if (meshDataServer != null)
     meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_VERTICES, null);
 }
示例#4
0
 void updateTriangles() {
   if (meshDataServer == null) {
     meshData.invalidatePolygons();
   } else {
     meshDataServer.invalidateTriangles();
   }
 }
示例#5
0
  private void processContent() {
    try {
      BufferedReader br = new BufferedReader(new InputStreamReader(contentURL.openStream()));

      data = new MeshData(false);
      while (true) {
        String line = br.readLine();
        lineNum++;
        if (line == null) break;

        if (line.length() == 0 || line.charAt(0) == '#') {
          continue;
        }
        while (line.charAt(line.length() - 1) == '\\') {
          String nextLine = br.readLine();
          lineNum++;
          line = line.substring(0, line.length() - 1) + " " + nextLine;
        }
        parseLine(line);
      }

    } catch (IOException ex) {
      System.err.println(ex.getLocalizedMessage());
      return;
    }

    finishCurrentMesh();

    data.finalizeData();
  }
示例#6
0
  private void finishCurrentMesh() {
    if (faces.size() == 0) {
      return;
    }

    VertexMap map = new VertexMap();

    // Now build up the geometry
    int[] vertIndices = new int[faces.size()];

    for (int i = 0; i < faces.size(); ++i) {
      FaceVert fv = faces.get(i);
      Vec3d pos = vertices.get(fv.v - 1);
      Vec2d texCoord = null;
      if (fv.t != -1) texCoord = texCoords.get(fv.t - 1);
      Vec3d normal = null;
      if (fv.n != -1) {
        normal = normals.get(fv.n - 1);
      } else {
        // This face does not have a normal, we'd better generate one from the vertices
        int faceInd = i / 3;
        Vec3d p0 = vertices.get(faces.get(faceInd * 3 + 0).v - 1);
        Vec3d p1 = vertices.get(faces.get(faceInd * 3 + 1).v - 1);
        Vec3d p2 = vertices.get(faces.get(faceInd * 3 + 2).v - 1);
        Vec3d d0 = new Vec3d();
        d0.sub3(p1, p0);
        Vec3d d1 = new Vec3d();
        d1.sub3(p2, p0);
        normal = new Vec3d();
        normal.cross3(d0, d1);
        normal.normalize3();
      }

      vertIndices[i] = map.getVertIndex(pos, normal, texCoord);
    }

    int matIndex = getMaterialIndex(activeMat);

    data.addSubMesh(map.getVertList(), vertIndices);
    data.addSubMeshInstance(numLoadedMeshes++, matIndex, -1, new Mat4d(), null, null);

    faces.clear();
  }
示例#7
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);
    }
  }
示例#8
0
  // Load the material in the return data (if necessary) and return the appropriate index
  private int getMaterialIndex(String matName) {
    Integer loaded = loadedMaterials.get(matName);
    if (loaded != null) {
      return loaded;
    }
    // Otherwise load it
    int newIndex = loadedMaterials.size();
    Material mat = materialMap.get(matName);
    parseAssert(mat != null);

    int transType = mat.alpha == 1.0 ? MeshData.NO_TRANS : MeshData.A_ONE_TRANS;
    data.addMaterial(
        mat.diffuseTex,
        mat.relDiffuseTex,
        mat.diffuse,
        mat.ambient,
        mat.spec,
        mat.shininess,
        transType,
        new Color4d(1, 1, 1, mat.alpha));
    loadedMaterials.put(matName, newIndex);
    return newIndex;
  }
示例#9
0
 void updateSurfaceData() {
   meshData.setVertexSets(true);
   updateTriangles();
   if (params.bsExcluded[1] == null) params.bsExcluded[1] = new BitSet();
   meshData.updateInvalidatedVertices(params.bsExcluded[1]);
 }
示例#10
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);
  }
示例#11
0
 public int addVertexCopy(Point3f vertexXYZ, float value, int assocVertex) {
   if (Float.isNaN(value) && assocVertex != MarchingSquares.EDGE_POINT) return -1;
   if (meshDataServer == null) return meshData.addVertexCopy(vertexXYZ, value, assocVertex);
   return meshDataServer.addVertexCopy(vertexXYZ, value, assocVertex);
 }