示例#1
0
  public ArrayList<String> collectLinks(String p) {
    ArrayList<String> PageLinks = new ArrayList<String>();
    try {

      URL url = new URL(p);
      BufferedReader br3 = new BufferedReader(new InputStreamReader(url.openStream()));
      String str = "";
      while (null != (str = br3.readLine())) {
        Pattern link =
            Pattern.compile(
                "<a target=\"_top\" href=\"/m/.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher match = link.matcher(str);
        while (match.find()) {
          String tmp = match.group();
          int start = tmp.indexOf('/');
          tmp = tmp.substring(start + 1, tmp.indexOf('\"', start + 1));
          if (Crawl.contains("http://www.rottentomatoes.com/" + tmp)
              || ToCrawl.contains("http://www.rottentomatoes.com/" + tmp)
              || PageLinks.contains("http://www.rottentomatoes.com/" + tmp)) continue;
          PageLinks.add("http://www.rottentomatoes.com/" + tmp);
          // bw4.write("http://www.rottentomatoes.com/"+tmp+"\r\n");
        }
      }

      br3.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return PageLinks;
  }
示例#2
0
  public void flipLayoutLeftRight() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (nl.processID.equals("null")) {
        nl.x =
            box.topleft.x
                + (box.width - (nl.x - box.topleft.x))
                - 60; // minus 60 which is the width of process node's box, since using upperleft
                      // coor
      } else if (isSecondary(nl)) {
        nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 60;
      } else {
        nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x = box.topleft.x + (box.width - (lp.x - box.topleft.x));
      }
    }
  }
示例#3
0
  // convert coordinates to relative coordinates with the top-left one as (0,0)
  public void convertToRelativePositions() {
    LayoutBox box = getExactLayoutBox();
    // System.out.println("Box
    // ("+box.topleft.x+","+box.topleft.y+");("+(box.topleft.x+box.width)+","+(box.topleft.y+box.height));
    Iterator<NodeLayout> e = nodes.iterator();
    NodeLayout nl;
    while (e.hasNext()) {
      nl = e.next();
      /* Debug code
      if(nl.x<box.topleft.x || nl.y<box.topleft.y || nl.x>(box.topleft.x+box.width) || nl.y>(box.topleft.y+box.height)){

          System.out.println("Invalid node     "+nl.x+","+nl.y);
      }
      //*/
      nl.x = nl.x - box.topleft.x;
      nl.y = nl.y - box.topleft.y;
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x = lp.x - box.topleft.x;
        lp.y = lp.y - box.topleft.y;
      }
    }
  }
示例#4
0
  /**
   * @return exact rectangle box bounding all the center points of the nodes and all the bend
   *     points.
   */
  public LayoutBox getExactLayoutBox() {

    Iterator<NodeLayout> e = nodes.iterator();
    double tlx = 0, tly = 0, brx = 0, bry = 0; // top left, bottom right
    NodeLayout nl;

    if (e.hasNext()) {
      nl = e.next();
      tlx = nl.x;
      tly = nl.y;
      brx = nl.x;
      bry = nl.y;
    }

    while (e.hasNext()) {
      nl = e.next();
      if (nl.x < tlx) {
        tlx = nl.x;
      }
      if (nl.x > brx) {
        brx = nl.x;
      }
      if (nl.y < tly) {
        tly = nl.y;
      }
      if (nl.y > bry) {
        bry = nl.y;
      }
    }

    Iterator<EdgeLayout> ee = edges.iterator();
    Iterator<LayoutPoint> be;
    LayoutPoint lp;
    EdgeLayout el;
    while (ee.hasNext()) {
      el = ee.next();
      be = el.bends.iterator();
      while (be.hasNext()) {
        lp = be.next();
        if (lp.x < tlx) {
          tlx = lp.x;
        }
        if (lp.x > brx) {
          brx = lp.x;
        }
        if (lp.y < tly) {
          tly = lp.y;
        }
        if (lp.y > bry) {
          bry = lp.y;
        }
      }
    }

    return new LayoutBox(tlx, tly, brx - tlx, bry - tly);
  }
示例#5
0
 public String toString() {
   if (isEmpty()) {
     return "";
   }
   StringBuffer sb = new StringBuffer();
   Iterator<NodeLayout> e = nodes.iterator();
   while (e.hasNext()) sb.append((e.next()).toString());
   sb.append("\n");
   Iterator<EdgeLayout> ee = edges.iterator();
   while (ee.hasNext()) sb.append((ee.next()).toString());
   return sb.toString();
 }
示例#6
0
  /** Generates array of XContour from local contours and modules. Used for TTF building. */
  private XContour[] toContours() {
    XContour[] retval;
    ArrayList<XContour> list = new ArrayList<>();
    XContour[] contours = m_glyph.getBody().getContour();
    for (int i = 0; i < contours.length; i++) {
      EContour contour = (EContour) contours[i];
      list.add(contour.toQuadratic());
    } // for i

    XModule[] modules = m_glyph.getBody().getModule();
    for (int i = 0; i < modules.length; i++) {
      EModuleInvoke module = (EModuleInvoke) modules[i];

      // push and pop happens inside toContour
      list.add(module.toContour(new AffineTransform()));
    } // for i

    if (list.size() == 0) return null;

    retval = new XContour[list.size()];
    for (int i = 0; i < list.size(); i++) {
      retval[i] = list.get(i);
    } // for i

    return retval;
  }
示例#7
0
  public String toBeautifiedString() {
    StringBuffer sb = new StringBuffer();

    Iterator<NodeLayout> e = nodes.iterator();
    while (e.hasNext()) sb.append((e.next()).toBeautifiedString());
    sb.append("\n");
    Iterator<EdgeLayout> ee = edges.iterator();
    while (ee.hasNext()) {
      sb.append((ee.next()).toBeautifiedString());
    }

    sb.append("\n\nNumber of Nodes: ");
    sb.append(nodes.size());
    sb.append("\nNumber of Edges: ");
    sb.append(edges.size() + "\n");

    return sb.toString();
  }
示例#8
0
  public TTGlyph toSimpleGlyph() {
    // convert the file into array of contours
    XContour[] contours = toContours();
    if ((contours == null) && (!isRequiredGlyph())) {
      return null;
    } // if

    TTGlyph retval = new TTGlyph();
    retval.setSimple(true);
    retval.setAdvanceWidth(getAdvanceWidth());

    if (contours == null) {
      return retval;
    } // if

    ArrayList<EContourPoint> points = new ArrayList<>();
    for (int i = 0; i < contours.length; i++) {
      XContour contour = contours[i];
      XContourPoint[] contourPoints = contour.getContourPoint();
      for (int j = 0; j < contourPoints.length; j++) {
        points.add((EContourPoint) contourPoints[j]);
      } // for j
      retval.addEndPoint(points.size() - 1);
    } // for i

    for (EContourPoint point : points) {
      loadContourPoint(retval, point);
    } // for point

    boolean hasGridfit = false;
    // I need int i here.
    for (int i = 0; i < points.size(); i++) {
      EContourPoint point = points.get(i);

      if (!point.isRounded()) {
        continue;
      } // if

      hasGridfit = true;
      loadGridfit(retval, point, i);
    } // for i

    if (hasGridfit) {
      retval.addInstruction(TTGlyph.IUP1);
      retval.addInstruction(TTGlyph.IUP0);
    } // if

    // I need int i here.
    for (int i = 0; i < points.size(); i++) {
      EContourPoint point = points.get(i);
      if (point.getHint().length == 0) {
        continue;
      } // if

      loadHint(retval, point, i);
    } // for i

    return retval;
  }
示例#9
0
 public EdgeLayout getEdgeLayouts(String spid, String sid, String tpid, String tid) {
   Iterator<EdgeLayout> ee = edges.iterator();
   EdgeLayout el;
   while (ee.hasNext()) {
     el = ee.next();
     if (el.sourceNode.equals(sid) && el.targetNode.equals(tid)) {
       return el;
     }
   }
   return null;
 } // */
示例#10
0
  // convert coordinates to shifted coordinates with the top-left one as (xs,ys)
  public void convertToShiftedPositions(double xs, double ys) {
    convertToRelativePositions();
    Iterator<NodeLayout> e = nodes.iterator();
    NodeLayout nl;
    while (e.hasNext()) {
      nl = e.next();
      nl.x += xs;
      nl.y += ys;
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x += xs;
        lp.y += ys;
      }
    }
  }
示例#11
0
  public boolean addNodeLayout(String pid, String id, String c, double x, double y) {
    /*if(idToNode.containsKey(pid + id)){
        return false;
    } */

    NodeLayout newNode = new NodeLayout(pid, id, c, x, y);

    nodes.add(newNode);
    idToNode.put(pid + id, newNode);
    return true;
  }
示例#12
0
  public void filpLayoutUpDown() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (nl.cofactor.equalsIgnoreCase("true")) {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 12;
      } else {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.y = box.topleft.y + (box.height - (lp.y - box.topleft.y));
      }
    }
  }
示例#13
0
  public void flipLayoutUpDown() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (isSecondary(nl)) {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 12;
      } else {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.y = box.topleft.y + (box.height - (lp.y - box.topleft.y));
      }
    }
  }
示例#14
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(sourcepid + "," + sourceNode + "," + targetpid + "," + targetNode + ",");
   Iterator<LayoutPoint> e = bends.iterator();
   LayoutPoint b;
   while (e.hasNext()) {
     b = (LayoutPoint) e.next();
     sb.append(b.x + "," + b.y + ",");
   }
   sb.append("\n");
   return sb.toString();
 }
示例#15
0
 public LayoutInfo copyOfThisLayoutInfo() {
   LayoutInfo copyI = new LayoutInfo();
   for (NodeLayout nl : nodes) {
     copyI.addNodeLayout(nl.processID, nl.nodeID, nl.cofactor, nl.x, nl.y);
   }
   for (EdgeLayout el : edges) {
     ArrayList<LayoutPoint> copyBends = new ArrayList<LayoutPoint>();
     for (LayoutPoint lp : el.bends) {
       copyBends.add(new LayoutPoint(lp.x, lp.y));
     }
     copyI.addEdgeLayout(
         el.sourcepid,
         el.sourceNode,
         el.scofactor,
         el.targetpid,
         el.targetNode,
         el.tcofactor,
         copyBends);
   }
   return copyI;
 }
 public Command executeStep(Element stepRow) throws Exception {
   Command command = new Command();
   NodeList stepFields = stepRow.getElementsByTagName("td");
   String cmd = stepFields.item(0).getTextContent().trim();
   command.cmd = cmd;
   ArrayList<String> argList = new ArrayList<String>();
   if (stepFields.getLength() == 1) {
     // skip comments
     command.result = "OK";
     return command;
   }
   for (int i = 1; i < stepFields.getLength(); i++) {
     String content = stepFields.item(i).getTextContent();
     content = content.replaceAll(" +", " ");
     content = content.replace('\u00A0', ' ');
     content = content.trim();
     argList.add(content);
   }
   String args[] = argList.toArray(new String[0]);
   command.args = args;
   if (this.verbose) {
     System.out.println(cmd + " " + Arrays.asList(args));
   }
   try {
     command.result = this.commandProcessor.doCommand(cmd, args);
     command.error = false;
   } catch (Exception e) {
     command.result = e.getMessage();
     command.error = true;
   }
   command.failure = command.error && !cmd.startsWith("verify");
   if (this.verbose) {
     System.out.println(command.result);
   }
   return command;
 }
示例#17
0
 public String toBeautifiedString() {
   StringBuffer sb = new StringBuffer();
   sb.append("sourcePID: " + sourcepid);
   sb.append("  sourceNodeId: " + sourceNode + "\n");
   sb.append("  targetPID: " + targetpid);
   sb.append("  targetNodeId: " + targetNode + "\n");
   Iterator<LayoutPoint> e = bends.iterator();
   LayoutPoint b;
   while (e.hasNext()) {
     b = (LayoutPoint) e.next();
     sb.append(" Bend Points: " + b.x + "," + b.y + "  ");
   }
   sb.append("\n\n");
   return sb.toString();
 }
  private boolean showDialog() {
    String[] types = {"RAW", "JPEG", "ZLIB"};
    GenericDialog gd = new GenericDialog("Generate Bricks");
    gd.addChoice("FileType", types, filetype);
    gd.addNumericField("JPEG quality", jpeg_quality, 0);
    gd.addNumericField("Max file size (MB)", bdsizelimit, 0);

    int[] wlist = WindowManager.getIDList();
    if (wlist == null) return false;

    String[] titles = new String[wlist.length];
    for (int i = 0; i < wlist.length; i++) titles[i] = "";

    int tnum = 0;
    for (int i = 0; i < wlist.length; i++) {
      ImagePlus imp = WindowManager.getImage(wlist[i]);
      if (imp != null) {
        titles[tnum] = imp.getTitle();
        tnum++;
      }
    }
    gd.addChoice("Source image: ", titles, titles[0]);

    gd.showDialog();
    if (gd.wasCanceled()) return false;

    filetype = types[gd.getNextChoiceIndex()];
    jpeg_quality = (int) gd.getNextNumber();
    if (jpeg_quality > 100) jpeg_quality = 100;
    if (jpeg_quality < 0) jpeg_quality = 0;
    bdsizelimit = (int) gd.getNextNumber();

    int id = gd.getNextChoiceIndex();
    lvImgTitle = new ArrayList<String>();
    lvImgTitle.add(titles[id]);

    Prefs.set("filetype.string", filetype);
    Prefs.set("jpeg_quality.int", jpeg_quality);
    Prefs.set("bdsizelimit.int", bdsizelimit);

    return true;
  }
示例#19
0
 // Return the shared nodes(with the same node id) with the other LayoutInfo
 public LinkedHashMap<NodeLayout, NodeLayout> sharedNodes(LayoutInfo info2) {
   LinkedHashMap<NodeLayout, NodeLayout> shared = new LinkedHashMap<NodeLayout, NodeLayout>();
   Iterator<NodeLayout> e = nodes.iterator();
   while (e.hasNext()) {
     NodeLayout nl = e.next();
     if (nl.cofactor.equalsIgnoreCase("true")) {
       continue;
     }
     NodeLayout nl2;
     Iterator<NodeLayout> e2 = info2.nodes.iterator();
     while (e2.hasNext()) {
       nl2 = e2.next();
       if (nl2.cofactor.equalsIgnoreCase("true")) {
         continue;
       }
       if (nl.nodeID.equals(nl2.nodeID)) {
         shared.put(nl, nl2);
       }
     }
   }
   return shared;
 }
示例#20
0
  // ## operation generateSpeciesStatus(ReactionModel,ArrayList,ArrayList,ArrayList)
  private LinkedHashMap generateSpeciesStatus(
      ReactionModel p_reactionModel,
      ArrayList p_speciesChemkinName,
      ArrayList p_speciesConc,
      ArrayList p_speciesFlux) {
    // #[ operation generateSpeciesStatus(ReactionModel,ArrayList,ArrayList,ArrayList)
    int size = p_speciesChemkinName.size();
    if (size != p_speciesConc.size() || size != p_speciesFlux.size())
      throw new InvalidSpeciesStatusException();
    LinkedHashMap speStatus = new LinkedHashMap();
    for (int i = 0; i < size; i++) {
      String name = (String) p_speciesChemkinName.get(i);
      int ID = parseIDFromChemkinName(name);
      Species spe = SpeciesDictionary.getInstance().getSpeciesFromID(ID);
      double conc = ((Double) p_speciesConc.get(i)).doubleValue();
      double flux = ((Double) p_speciesFlux.get(i)).doubleValue();

      System.out.println(
          String.valueOf(spe.getID())
              + '\t'
              + spe.getName()
              + '\t'
              + String.valueOf(conc)
              + '\t'
              + String.valueOf(flux));

      if (conc < 0) {
        double aTol = ReactionModelGenerator.getAtol();
        // if (Math.abs(conc) < aTol) conc = 0;
        // else throw new NegativeConcentrationException("species " + spe.getName() + " has negative
        // conc: " + String.valueOf(conc));
        if (conc < -100.0 * aTol)
          throw new NegativeConcentrationException(
              "Species " + spe.getName() + " has negative concentration: " + String.valueOf(conc));
      }

      SpeciesStatus ss = new SpeciesStatus(spe, 1, conc, flux);
      speStatus.put(spe, ss);
    }
    return speStatus;

    // #]
  }
示例#21
0
  // ## operation readReactorOutputFile(ReactionModel)
  public SystemSnapshot readReactorOutputFile(ReactionModel p_reactionModel) {
    // #[ operation readReactorOutputFile(ReactionModel)
    try {
      // open output file and build the DOM tree
      String dir = System.getProperty("RMG.workingDirectory");
      String filename = "chemkin/reactorOutput.xml";
      File inputFile = new File(filename);

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setValidating(true); // validate the document with the DTD
      factory.setIgnoringElementContentWhitespace(true); // ignore whitespace
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse(inputFile);

      // get root element and its children
      Element root = doc.getDocumentElement();
      NodeList rootchildren = root.getChildNodes();

      // header is rootchildren.item(0)

      // get return message and check for successful run
      Element returnmessageElement = (Element) rootchildren.item(1);
      Text returnmessageText = (Text) returnmessageElement.getFirstChild();
      String returnmessage = returnmessageText.toString();
      returnmessage = returnmessage.trim();
      if (!returnmessage.contains("SUCCESSFULLY COMPLETED RUN.")) {
        System.out.println("External reactor model failed!");
        System.out.println("Reactor model error message: " + returnmessage);
        System.exit(0);
      }

      // get outputvalues element and its children
      Element outputvaluesElement = (Element) rootchildren.item(2);
      NodeList children = outputvaluesElement.getChildNodes();

      // get time
      Element timeElement = (Element) children.item(0);
      Text timeText = (Text) timeElement.getFirstChild();
      double time = Double.parseDouble(timeText.getData());
      String timeUnits = timeElement.getAttribute("units");

      // get systemstate element and its children
      Element systemstateElement = (Element) children.item(1);
      NodeList states = systemstateElement.getChildNodes();

      // get temperature and its units
      Element temperatureElement = (Element) states.item(0);
      String tempUnits = temperatureElement.getAttribute("units");
      Text temperatureText = (Text) temperatureElement.getFirstChild();
      double temp = Double.parseDouble(temperatureText.getData());
      Temperature T = new Temperature(temp, tempUnits);

      // get pressure and its units
      Element pressureElement = (Element) states.item(1);
      String presUnits = pressureElement.getAttribute("units");
      Text pressureText = (Text) pressureElement.getFirstChild();
      double pres = Double.parseDouble(pressureText.getData());
      Pressure P = new Pressure(pres, presUnits);

      // get species amounts (e.g. concentrations)
      ArrayList speciesIDs = new ArrayList();
      ArrayList amounts = new ArrayList();
      ArrayList fluxes = new ArrayList();
      String amountUnits = null;
      String fluxUnits = null;

      // loop thru all the species
      // begin at i=2, since T and P take already the first two position of states
      int nSpe = (states.getLength() - 2) / 2;
      int index = 0;
      LinkedHashMap inertGas = new LinkedHashMap();
      for (int i = 2; i < nSpe + 2; i++) {
        // get amount element and the units
        Element amountElement = (Element) states.item(i);
        amountUnits = amountElement.getAttribute("units");

        Element fluxElement = (Element) states.item(i + nSpe);
        fluxUnits = fluxElement.getAttribute("units");

        // get speciesid and store in an array list
        String thisSpeciesID = amountElement.getAttribute("speciesid");

        // get amount (e.g. concentraion) and store in an array list
        Text amountText = (Text) amountElement.getFirstChild();
        double thisAmount = Double.parseDouble(amountText.getData());
        if (thisAmount < 0) {
          double aTol = ReactionModelGenerator.getAtol();
          // if (Math.abs(thisAmount) < aTol) thisAmount = 0;
          // else throw new NegativeConcentrationException("Negative concentration in
          // reactorOutput.xml: " + thisSpeciesID);
          if (thisAmount < -100.0 * aTol)
            throw new NegativeConcentrationException(
                "Species "
                    + thisSpeciesID
                    + " has negative concentration: "
                    + String.valueOf(thisAmount));
        }

        // get amount (e.g. concentraion) and store in an array list
        Text fluxText = (Text) fluxElement.getFirstChild();
        double thisFlux = Double.parseDouble(fluxText.getData());

        if (thisSpeciesID.compareToIgnoreCase("N2") == 0
            || thisSpeciesID.compareToIgnoreCase("Ne") == 0
            || thisSpeciesID.compareToIgnoreCase("Ar") == 0) {
          inertGas.put(thisSpeciesID, new Double(thisAmount));
        } else {
          speciesIDs.add(index, thisSpeciesID);
          amounts.add(index, new Double(thisAmount));
          fluxes.add(index, new Double(thisFlux));
          index++;
        }
      }

      // print results for debugging purposes
      /**
       * System.out.println(returnmessage); System.out.println("Temp = " + temp + " " + tempUnits);
       * System.out.println("Pres = " + pres + " " + presUnits); for (int i = 0; i < amounts.size();
       * i++) { System.out.println(speciesIDs.get(i) + " " + amounts.get(i) + " " + amountUnits); }
       */
      ReactionTime rt = new ReactionTime(time, timeUnits);
      LinkedHashMap speStatus = generateSpeciesStatus(p_reactionModel, speciesIDs, amounts, fluxes);
      SystemSnapshot ss = new SystemSnapshot(rt, speStatus, T, P);
      ss.inertGas = inertGas;
      return ss;
    } catch (Exception e) {
      System.out.println("Error reading reactor model output: " + e.getMessage());
      System.exit(0);
      return null;
    }

    // #]
  }
  public void build_bricks() {

    ImagePlus imp;
    ImagePlus orgimp;
    ImageStack stack;
    FileInfo finfo;

    if (lvImgTitle.isEmpty()) return;
    orgimp = WindowManager.getImage(lvImgTitle.get(0));
    imp = orgimp;

    finfo = imp.getFileInfo();
    if (finfo == null) return;

    int[] dims = imp.getDimensions();
    int imageW = dims[0];
    int imageH = dims[1];
    int nCh = dims[2];
    int imageD = dims[3];
    int nFrame = dims[4];
    int bdepth = imp.getBitDepth();
    double xspc = finfo.pixelWidth;
    double yspc = finfo.pixelHeight;
    double zspc = finfo.pixelDepth;
    double z_aspect = Math.max(xspc, yspc) / zspc;

    int orgW = imageW;
    int orgH = imageH;
    int orgD = imageD;
    double orgxspc = xspc;
    double orgyspc = yspc;
    double orgzspc = zspc;

    lv = lvImgTitle.size();
    if (filetype == "JPEG") {
      for (int l = 0; l < lv; l++) {
        if (WindowManager.getImage(lvImgTitle.get(l)).getBitDepth() != 8) {
          IJ.error("A SOURCE IMAGE MUST BE 8BIT GLAYSCALE");
          return;
        }
      }
    }

    // calculate levels
    /*		int baseXY = 256;
    		int baseZ = 256;

    		if (z_aspect < 0.5) baseZ = 128;
    		if (z_aspect > 2.0) baseXY = 128;
    		if (z_aspect >= 0.5 && z_aspect < 1.0) baseZ = (int)(baseZ*z_aspect);
    		if (z_aspect > 1.0 && z_aspect <= 2.0) baseXY = (int)(baseXY/z_aspect);

    		IJ.log("Z_aspect: " + z_aspect);
    		IJ.log("BaseXY: " + baseXY);
    		IJ.log("BaseZ: " + baseZ);
    */

    int baseXY = 256;
    int baseZ = 128;
    int dbXY = Math.max(orgW, orgH) / baseXY;
    if (Math.max(orgW, orgH) % baseXY > 0) dbXY *= 2;
    int dbZ = orgD / baseZ;
    if (orgD % baseZ > 0) dbZ *= 2;
    lv = Math.max(log2(dbXY), log2(dbZ)) + 1;

    int ww = orgW;
    int hh = orgH;
    int dd = orgD;
    for (int l = 0; l < lv; l++) {
      int bwnum = ww / baseXY;
      if (ww % baseXY > 0) bwnum++;
      int bhnum = hh / baseXY;
      if (hh % baseXY > 0) bhnum++;
      int bdnum = dd / baseZ;
      if (dd % baseZ > 0) bdnum++;

      if (bwnum % 2 == 0) bwnum++;
      if (bhnum % 2 == 0) bhnum++;
      if (bdnum % 2 == 0) bdnum++;

      int bw = (bwnum <= 1) ? ww : ww / bwnum + 1 + (ww % bwnum > 0 ? 1 : 0);
      int bh = (bhnum <= 1) ? hh : hh / bhnum + 1 + (hh % bhnum > 0 ? 1 : 0);
      int bd = (bdnum <= 1) ? dd : dd / bdnum + 1 + (dd % bdnum > 0 ? 1 : 0);

      bwlist.add(bw);
      bhlist.add(bh);
      bdlist.add(bd);

      IJ.log("LEVEL: " + l);
      IJ.log("  width: " + ww);
      IJ.log("  hight: " + hh);
      IJ.log("  depth: " + dd);
      IJ.log("  bw: " + bw);
      IJ.log("  bh: " + bh);
      IJ.log("  bd: " + bd);

      int xyl2 = Math.max(ww, hh) / baseXY;
      if (Math.max(ww, hh) % baseXY > 0) xyl2 *= 2;
      if (lv - 1 - log2(xyl2) <= l) {
        ww /= 2;
        hh /= 2;
      }
      IJ.log("  xyl2: " + (lv - 1 - log2(xyl2)));

      int zl2 = dd / baseZ;
      if (dd % baseZ > 0) zl2 *= 2;
      if (lv - 1 - log2(zl2) <= l) dd /= 2;
      IJ.log("  zl2: " + (lv - 1 - log2(zl2)));

      if (l < lv - 1) {
        lvImgTitle.add(lvImgTitle.get(0) + "_level" + (l + 1));
        IJ.selectWindow(lvImgTitle.get(0));
        IJ.run(
            "Scale...",
            "x=- y=- z=- width="
                + ww
                + " height="
                + hh
                + " depth="
                + dd
                + " interpolation=Bicubic average process create title="
                + lvImgTitle.get(l + 1));
      }
    }

    for (int l = 0; l < lv; l++) {
      IJ.log(lvImgTitle.get(l));
    }

    Document doc = newXMLDocument();
    Element root = doc.createElement("BRK");
    root.setAttribute("version", "1.0");
    root.setAttribute("nLevel", String.valueOf(lv));
    root.setAttribute("nChannel", String.valueOf(nCh));
    root.setAttribute("nFrame", String.valueOf(nFrame));
    doc.appendChild(root);

    for (int l = 0; l < lv; l++) {
      IJ.showProgress(0.0);

      int[] dims2 = imp.getDimensions();
      IJ.log(
          "W: "
              + String.valueOf(dims2[0])
              + " H: "
              + String.valueOf(dims2[1])
              + " C: "
              + String.valueOf(dims2[2])
              + " D: "
              + String.valueOf(dims2[3])
              + " T: "
              + String.valueOf(dims2[4])
              + " b: "
              + String.valueOf(bdepth));

      bw = bwlist.get(l).intValue();
      bh = bhlist.get(l).intValue();
      bd = bdlist.get(l).intValue();

      boolean force_pow2 = false;
      /*			if(IsPowerOf2(bw) && IsPowerOf2(bh) && IsPowerOf2(bd)) force_pow2 = true;

      			if(force_pow2){
      				//force pow2
      				if(Pow2(bw) > bw) bw = Pow2(bw)/2;
      				if(Pow2(bh) > bh) bh = Pow2(bh)/2;
      				if(Pow2(bd) > bd) bd = Pow2(bd)/2;
      			}

      			if(bw > imageW) bw = (Pow2(imageW) == imageW) ? imageW : Pow2(imageW)/2;
      			if(bh > imageH) bh = (Pow2(imageH) == imageH) ? imageH : Pow2(imageH)/2;
      			if(bd > imageD) bd = (Pow2(imageD) == imageD) ? imageD : Pow2(imageD)/2;

      */
      if (bw > imageW) bw = imageW;
      if (bh > imageH) bh = imageH;
      if (bd > imageD) bd = imageD;

      if (bw <= 1 || bh <= 1 || bd <= 1) break;

      if (filetype == "JPEG" && (bw < 8 || bh < 8)) break;

      Element lvnode = doc.createElement("Level");
      lvnode.setAttribute("lv", String.valueOf(l));
      lvnode.setAttribute("imageW", String.valueOf(imageW));
      lvnode.setAttribute("imageH", String.valueOf(imageH));
      lvnode.setAttribute("imageD", String.valueOf(imageD));
      lvnode.setAttribute("xspc", String.valueOf(xspc));
      lvnode.setAttribute("yspc", String.valueOf(yspc));
      lvnode.setAttribute("zspc", String.valueOf(zspc));
      lvnode.setAttribute("bitDepth", String.valueOf(bdepth));
      root.appendChild(lvnode);

      Element brksnode = doc.createElement("Bricks");
      brksnode.setAttribute("brick_baseW", String.valueOf(bw));
      brksnode.setAttribute("brick_baseH", String.valueOf(bh));
      brksnode.setAttribute("brick_baseD", String.valueOf(bd));
      lvnode.appendChild(brksnode);

      ArrayList<Brick> bricks = new ArrayList<Brick>();
      int mw, mh, md, mw2, mh2, md2;
      double tx0, ty0, tz0, tx1, ty1, tz1;
      double bx0, by0, bz0, bx1, by1, bz1;
      for (int k = 0; k < imageD; k += bd) {
        if (k > 0) k--;
        for (int j = 0; j < imageH; j += bh) {
          if (j > 0) j--;
          for (int i = 0; i < imageW; i += bw) {
            if (i > 0) i--;
            mw = Math.min(bw, imageW - i);
            mh = Math.min(bh, imageH - j);
            md = Math.min(bd, imageD - k);

            if (force_pow2) {
              mw2 = Pow2(mw);
              mh2 = Pow2(mh);
              md2 = Pow2(md);
            } else {
              mw2 = mw;
              mh2 = mh;
              md2 = md;
            }

            if (filetype == "JPEG") {
              if (mw2 < 8) mw2 = 8;
              if (mh2 < 8) mh2 = 8;
            }

            tx0 = i == 0 ? 0.0d : ((mw2 - mw + 0.5d) / mw2);
            ty0 = j == 0 ? 0.0d : ((mh2 - mh + 0.5d) / mh2);
            tz0 = k == 0 ? 0.0d : ((md2 - md + 0.5d) / md2);

            tx1 = 1.0d - 0.5d / mw2;
            if (mw < bw) tx1 = 1.0d;
            if (imageW - i == bw) tx1 = 1.0d;

            ty1 = 1.0d - 0.5d / mh2;
            if (mh < bh) ty1 = 1.0d;
            if (imageH - j == bh) ty1 = 1.0d;

            tz1 = 1.0d - 0.5d / md2;
            if (md < bd) tz1 = 1.0d;
            if (imageD - k == bd) tz1 = 1.0d;

            bx0 = i == 0 ? 0.0d : (i + 0.5d) / (double) imageW;
            by0 = j == 0 ? 0.0d : (j + 0.5d) / (double) imageH;
            bz0 = k == 0 ? 0.0d : (k + 0.5d) / (double) imageD;

            bx1 = Math.min((i + bw - 0.5d) / (double) imageW, 1.0d);
            if (imageW - i == bw) bx1 = 1.0d;

            by1 = Math.min((j + bh - 0.5d) / (double) imageH, 1.0d);
            if (imageH - j == bh) by1 = 1.0d;

            bz1 = Math.min((k + bd - 0.5d) / (double) imageD, 1.0d);
            if (imageD - k == bd) bz1 = 1.0d;

            int x, y, z;
            x = i - (mw2 - mw);
            y = j - (mh2 - mh);
            z = k - (md2 - md);
            bricks.add(
                new Brick(
                    x, y, z, mw2, mh2, md2, 0, 0, tx0, ty0, tz0, tx1, ty1, tz1, bx0, by0, bz0, bx1,
                    by1, bz1));
          }
        }
      }

      Element fsnode = doc.createElement("Files");
      lvnode.appendChild(fsnode);

      stack = imp.getStack();

      int totalbricknum = nFrame * nCh * bricks.size();
      int curbricknum = 0;
      for (int f = 0; f < nFrame; f++) {
        for (int ch = 0; ch < nCh; ch++) {
          int sizelimit = bdsizelimit * 1024 * 1024;
          int bytecount = 0;
          int filecount = 0;
          int pd_bufsize = Math.max(sizelimit, bw * bh * bd * bdepth / 8);
          byte[] packed_data = new byte[pd_bufsize];
          String base_dataname =
              basename
                  + "_Lv"
                  + String.valueOf(l)
                  + "_Ch"
                  + String.valueOf(ch)
                  + "_Fr"
                  + String.valueOf(f);
          String current_dataname = base_dataname + "_data" + filecount;

          Brick b_first = bricks.get(0);
          if (b_first.z_ != 0) IJ.log("warning");
          int st_z = b_first.z_;
          int ed_z = b_first.z_ + b_first.d_;
          LinkedList<ImageProcessor> iplist = new LinkedList<ImageProcessor>();
          for (int s = st_z; s < ed_z; s++)
            iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));

          //					ImagePlus test;
          //					ImageStack tsst;
          //					test = NewImage.createByteImage("test", imageW, imageH, imageD,
          // NewImage.FILL_BLACK);
          //					tsst = test.getStack();
          for (int i = 0; i < bricks.size(); i++) {
            Brick b = bricks.get(i);

            if (ed_z > b.z_ || st_z < b.z_ + b.d_) {
              if (b.z_ > st_z) {
                for (int s = 0; s < b.z_ - st_z; s++) iplist.pollFirst();
                st_z = b.z_;
              } else if (b.z_ < st_z) {
                IJ.log("warning");
                for (int s = st_z - 1; s > b.z_; s--)
                  iplist.addFirst(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
                st_z = b.z_;
              }

              if (b.z_ + b.d_ > ed_z) {
                for (int s = ed_z; s < b.z_ + b.d_; s++)
                  iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
                ed_z = b.z_ + b.d_;
              } else if (b.z_ + b.d_ < ed_z) {
                IJ.log("warning");
                for (int s = 0; s < ed_z - (b.z_ + b.d_); s++) iplist.pollLast();
                ed_z = b.z_ + b.d_;
              }
            } else {
              IJ.log("warning");
              iplist.clear();
              st_z = b.z_;
              ed_z = b.z_ + b.d_;
              for (int s = st_z; s < ed_z; s++)
                iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
            }

            if (iplist.size() != b.d_) {
              IJ.log("Stack Error");
              return;
            }

            //						int zz = st_z;

            int bsize = 0;
            byte[] bdata = new byte[b.w_ * b.h_ * b.d_ * bdepth / 8];
            Iterator<ImageProcessor> ipite = iplist.iterator();
            while (ipite.hasNext()) {

              //							ImageProcessor tsip = tsst.getProcessor(zz+1);

              ImageProcessor ip = ipite.next();
              ip.setRoi(b.x_, b.y_, b.w_, b.h_);
              if (bdepth == 8) {
                byte[] data = (byte[]) ip.crop().getPixels();
                System.arraycopy(data, 0, bdata, bsize, data.length);
                bsize += data.length;
              } else if (bdepth == 16) {
                ByteBuffer buffer = ByteBuffer.allocate(b.w_ * b.h_ * bdepth / 8);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                short[] data = (short[]) ip.crop().getPixels();
                for (short e : data) buffer.putShort(e);
                System.arraycopy(buffer.array(), 0, bdata, bsize, buffer.array().length);
                bsize += buffer.array().length;
              } else if (bdepth == 32) {
                ByteBuffer buffer = ByteBuffer.allocate(b.w_ * b.h_ * bdepth / 8);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                float[] data = (float[]) ip.crop().getPixels();
                for (float e : data) buffer.putFloat(e);
                System.arraycopy(buffer.array(), 0, bdata, bsize, buffer.array().length);
                bsize += buffer.array().length;
              }
            }

            String filename =
                basename
                    + "_Lv"
                    + String.valueOf(l)
                    + "_Ch"
                    + String.valueOf(ch)
                    + "_Fr"
                    + String.valueOf(f)
                    + "_ID"
                    + String.valueOf(i);

            int offset = bytecount;
            int datasize = bdata.length;

            if (filetype == "RAW") {
              int dummy = -1;
              // do nothing
            }
            if (filetype == "JPEG" && bdepth == 8) {
              try {
                DataBufferByte db = new DataBufferByte(bdata, datasize);
                Raster raster = Raster.createPackedRaster(db, b.w_, b.h_ * b.d_, 8, null);
                BufferedImage img =
                    new BufferedImage(b.w_, b.h_ * b.d_, BufferedImage.TYPE_BYTE_GRAY);
                img.setData(raster);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
                String format = "jpg";
                Iterator<javax.imageio.ImageWriter> iter =
                    ImageIO.getImageWritersByFormatName("jpeg");
                javax.imageio.ImageWriter writer = iter.next();
                ImageWriteParam iwp = writer.getDefaultWriteParam();
                iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwp.setCompressionQuality((float) jpeg_quality * 0.01f);
                writer.setOutput(ios);
                writer.write(null, new IIOImage(img, null, null), iwp);
                // ImageIO.write(img, format, baos);
                bdata = baos.toByteArray();
                datasize = bdata.length;
              } catch (IOException e) {
                e.printStackTrace();
                return;
              }
            }
            if (filetype == "ZLIB") {
              byte[] tmpdata = new byte[b.w_ * b.h_ * b.d_ * bdepth / 8];
              Deflater compresser = new Deflater();
              compresser.setInput(bdata);
              compresser.setLevel(Deflater.DEFAULT_COMPRESSION);
              compresser.setStrategy(Deflater.DEFAULT_STRATEGY);
              compresser.finish();
              datasize = compresser.deflate(tmpdata);
              bdata = tmpdata;
              compresser.end();
            }

            if (bytecount + datasize > sizelimit && bytecount > 0) {
              BufferedOutputStream fis = null;
              try {
                File file = new File(directory + current_dataname);
                fis = new BufferedOutputStream(new FileOutputStream(file));
                fis.write(packed_data, 0, bytecount);
              } catch (IOException e) {
                e.printStackTrace();
                return;
              } finally {
                try {
                  if (fis != null) fis.close();
                } catch (IOException e) {
                  e.printStackTrace();
                  return;
                }
              }
              filecount++;
              current_dataname = base_dataname + "_data" + filecount;
              bytecount = 0;
              offset = 0;
              System.arraycopy(bdata, 0, packed_data, bytecount, datasize);
              bytecount += datasize;
            } else {
              System.arraycopy(bdata, 0, packed_data, bytecount, datasize);
              bytecount += datasize;
            }

            Element filenode = doc.createElement("File");
            filenode.setAttribute("filename", current_dataname);
            filenode.setAttribute("channel", String.valueOf(ch));
            filenode.setAttribute("frame", String.valueOf(f));
            filenode.setAttribute("brickID", String.valueOf(i));
            filenode.setAttribute("offset", String.valueOf(offset));
            filenode.setAttribute("datasize", String.valueOf(datasize));
            filenode.setAttribute("filetype", String.valueOf(filetype));

            fsnode.appendChild(filenode);

            curbricknum++;
            IJ.showProgress((double) (curbricknum) / (double) (totalbricknum));
          }
          if (bytecount > 0) {
            BufferedOutputStream fis = null;
            try {
              File file = new File(directory + current_dataname);
              fis = new BufferedOutputStream(new FileOutputStream(file));
              fis.write(packed_data, 0, bytecount);
            } catch (IOException e) {
              e.printStackTrace();
              return;
            } finally {
              try {
                if (fis != null) fis.close();
              } catch (IOException e) {
                e.printStackTrace();
                return;
              }
            }
          }
        }
      }

      for (int i = 0; i < bricks.size(); i++) {
        Brick b = bricks.get(i);
        Element bricknode = doc.createElement("Brick");
        bricknode.setAttribute("id", String.valueOf(i));
        bricknode.setAttribute("st_x", String.valueOf(b.x_));
        bricknode.setAttribute("st_y", String.valueOf(b.y_));
        bricknode.setAttribute("st_z", String.valueOf(b.z_));
        bricknode.setAttribute("width", String.valueOf(b.w_));
        bricknode.setAttribute("height", String.valueOf(b.h_));
        bricknode.setAttribute("depth", String.valueOf(b.d_));
        brksnode.appendChild(bricknode);

        Element tboxnode = doc.createElement("tbox");
        tboxnode.setAttribute("x0", String.valueOf(b.tx0_));
        tboxnode.setAttribute("y0", String.valueOf(b.ty0_));
        tboxnode.setAttribute("z0", String.valueOf(b.tz0_));
        tboxnode.setAttribute("x1", String.valueOf(b.tx1_));
        tboxnode.setAttribute("y1", String.valueOf(b.ty1_));
        tboxnode.setAttribute("z1", String.valueOf(b.tz1_));
        bricknode.appendChild(tboxnode);

        Element bboxnode = doc.createElement("bbox");
        bboxnode.setAttribute("x0", String.valueOf(b.bx0_));
        bboxnode.setAttribute("y0", String.valueOf(b.by0_));
        bboxnode.setAttribute("z0", String.valueOf(b.bz0_));
        bboxnode.setAttribute("x1", String.valueOf(b.bx1_));
        bboxnode.setAttribute("y1", String.valueOf(b.by1_));
        bboxnode.setAttribute("z1", String.valueOf(b.bz1_));
        bricknode.appendChild(bboxnode);
      }

      if (l < lv - 1) {
        imp = WindowManager.getImage(lvImgTitle.get(l + 1));
        int[] newdims = imp.getDimensions();
        imageW = newdims[0];
        imageH = newdims[1];
        imageD = newdims[3];
        xspc = orgxspc * ((double) orgW / (double) imageW);
        yspc = orgyspc * ((double) orgH / (double) imageH);
        zspc = orgzspc * ((double) orgD / (double) imageD);
        bdepth = imp.getBitDepth();
      }
    }

    File newXMLfile = new File(directory + basename + ".vvd");
    writeXML(newXMLfile, doc);

    for (int l = 1; l < lv; l++) {
      imp = WindowManager.getImage(lvImgTitle.get(l));
      imp.changes = false;
      imp.close();
    }
  }
示例#23
0
 public boolean isEmpty() {
   return nodes.isEmpty(); // && edges.isEmpty() && idToNode.isEmpty();
 }
示例#24
0
 public void addEdgeLayout(
     String sp, String s, String sc, String tp, String t, String tc, ArrayList<LayoutPoint> b) {
   EdgeLayout el = new EdgeLayout(sp, s, sc, tp, t, tc);
   el.setBends(b);
   edges.add(el);
 }
示例#25
0
  public void CrawlRT(String RTPage) throws IOException {
    ArrayList<String> t = new ArrayList<String>();
    String crawlData;
    String crawlData2;
    String crawlData3;

    FileReader freader = new FileReader("Crawl.txt");
    BufferedReader br = new BufferedReader(freader);
    FileReader freader2 = new FileReader("Tocrawl.txt");
    BufferedReader br2 = new BufferedReader(freader2);
    FileWriter fwriter2 = new FileWriter("Tocrawl.txt", true);
    BufferedWriter bw2 = new BufferedWriter(fwriter2);
    FileWriter fwriter = new FileWriter("Crawl.txt", true);
    BufferedWriter bw = new BufferedWriter(fwriter);

    /*while(null != (crawlData2 = br.readLine()))
    {
    	if(crawlData2 !=null)
    		Crawl.add(crawlData2);
    }
    t = collectLinks(RTPage);
    Iterator<String> e3= t.iterator();
    while(e3.hasNext())
    {
    	String ee = e3.next();

    		if(!Crawl.contains(ee))
    		{
    			bw2.write(ee+"\r\n");
    		}



    }
    br.close();
    br2.close();
    bw.close();
    bw2.close();*/

    if (null == (crawlData = br.readLine()))
    // if(true)
    {
      // initial iteration
      bw.write(RTPage + "\r\n");
      Crawl.add(RTPage);
      t = collectLinks(RTPage);
      ToCrawl.addAll(t);
    } else {
      // collect data from files and load to array lists
      while (null != (crawlData2 = br.readLine())) {
        if (crawlData2 != null) Crawl.add(crawlData2);
      }

      while (null != (crawlData3 = br2.readLine())) {
        if (crawlData3 != null) ToCrawl.add(crawlData3);
      }
    }
    System.out.println("Crawlled");

    // Number of movies to be crawled
    for (int i = 0; i < 1000; i++) {
      if (ToCrawl.size() > 0) {
        Crawl.removeAll(Collections.singleton(null));
        ToCrawl.removeAll(Collections.singleton(null));
        String c = ToCrawl.get(0);
        if (Crawl.contains(c)) ToCrawl.remove(c);
        else {
          // collect links and collect data from a particular link
          Crawl.add(c);
          t = collectLinks(c);
          CollectData(c);
          ToCrawl.remove(c);
          Iterator<String> e3 = t.iterator();
          while (e3.hasNext()) {
            String ee = e3.next();
            if (!ToCrawl.contains(ee)) {
              if (!Crawl.contains(ee)) {
                ToCrawl.add(ee);
              }
            }
          }
          bw.write(c + "\r\n");
        }
      }
    }

    System.out.println("To Be Crawlled");
    Iterator<String> e2 = ToCrawl.iterator();
    while (e2.hasNext()) {
      // write to file the movies still to be crawled.
      bw2.write(e2.next() + "\r\n");
    }

    prop.setProperty("Id", Integer.toString(n));
    prop.store(new FileOutputStream("config.properties"), null);
    br.close();
    br2.close();
    bw.close();
    bw2.close();
  }
示例#26
0
  /**
   * return a list of queues for connected groups of pathways place pathways according to the order
   * of the queues and the list
   *
   * @param layouts
   * @param dependOn the index number of pathway this one depends on, -1 if no dependency
   * @return
   */
  public static ArrayList<Queue> pathwayQueues(LayoutInfo[] layouts, int[] dependOn) {
    ArrayList<Queue> queues =
        new ArrayList<Queue>(); // each queue is for a disconnected group of pathways
    int n = layouts.length;
    boolean[] added = new boolean[n]; // whether the pathway is added into a queue
    // boolean[] processed = new boolean[n];//whether all neighbours of this pathway are added into
    // some queue
    Queue<Integer> toProcess = new LinkedList<Integer>();

    // current queue to add pathways into
    // if not null, then exists a queue to add pathways into
    // otherwise need to create a new queue(for disconnected group of pathways)
    Queue currentQueue = null;

    Arrays.sort(layouts, new LayoutBoxSizeComparator());

    /*TODO delete
    LayoutInfo tmp0 = layouts[0];
    LayoutInfo tmp1 = layouts[1];
    LayoutInfo tmp2 = layouts[2];
    LayoutInfo tmp3 = layouts[3];
    LayoutInfo tmp6 = layouts[6];
    layouts[3]=tmp1;
    layouts[2]=tmp6;
    layouts[1]=tmp2;
    layouts[6]=tmp0;
    layouts[0] = tmp3;
    /*
    for(LayoutInfo i:layouts){
        System.out.println(i.getExactLayoutBox().size());
    }
    //*/

    for (int i = n - 1; i >= 0; i--) {
      if (added[i]) {
        continue;
      }

      currentQueue = new LinkedList<Integer>(); // current queue to add connected pathways into
      queues.add(currentQueue);
      toProcess.add(i);
      currentQueue.add(i);
      added[i] = true;
      dependOn[i] = -1;

      while (toProcess.size() != 0) {
        int p = toProcess.remove();
        for (int j = n - 2; j >= 0; j--) { // the first one is already added, so search from n-2
          // find all non-visited neighbour pathways of layout[p]
          if (added[j]) {
            continue;
          }
          if (layouts[p].sharedNodes(layouts[j]).size() > 0 && !added[j]) {
            currentQueue.add(j);
            toProcess.add(j);
            added[j] = true;
            dependOn[j] = p;
          }
        }
        // processed[p]=true;
      }
      currentQueue = null; // finished a connected group of pathways
    }

    return queues;
  }
示例#27
0
 // empty this info object
 public void clearInfo() {
   nodes.clear();
   edges.clear();
   idToNode.clear();
 }