<commit_before>//
// LociDataBrowser.java
//

/*
LOCI 4D Data Browser plugin for quick browsing of 4D datasets in ImageJ.
Copyright (C) 2005-@year@ <NAME>, <NAME>, <NAME>
and <NAME>.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Library General Public License for more details.

You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.plugins.browser;

import ij.*;
import ij.gui.GenericDialog;
import ij.gui.MessageDialog;
import ij.gui.ImageCanvas;
import ij.io.FileInfo;
import java.awt.Frame;
import loci.formats.*;

/**
 * LociDataBrowser is a plugin for ImageJ that allows for browsing of 4D
 * image data (stacks of image planes over time) with two-channel support.
 *
 * @author <NAME> at wisc.edu
 * @author <NAME> yutaiwong at wisc.edu
 * @author <NAME> ctrueden at wisc.edu
 * @author <NAME> linkert at cs.wisc.edu
 */
public class LociDataBrowser {

  // -- Constants --

  /** Debugging flag. */
  protected static final boolean DEBUG = false;

  // -- Fields --

  /** Filename for each index. */
  protected String[] names;

  /** The file format reader used by the plugin. */
  protected IFormatReader reader;
  
  /** The file stitcher used by the reader.*/
  protected FileStitcher fStitch;
  
  /** The CustomWindow used to display data.*/
  protected CustomWindow cw;

  /** The current file name. */
  protected String id;

  /** Whether dataset has multiple Z, T and C positions. */
  protected boolean hasZ, hasT, hasC;

  /** Number of Z, T and C positions. */
  protected int numZ, numT, numC;

  /** Lengths of all dimensional axes; lengths[0] equals image depth. */
  protected int[] lengths;

  /** Indices into lengths array for Z, T and C. */
  protected int zIndex, tIndex, cIndex;

  /** Whether stack is accessed from disk as needed. */
  protected boolean virtual;

  /** Cache manager (if virtual stack is used). */
  protected CacheManager manager;

  /** Series to use in a multi-series file. */
  protected int series;

  private ImageStack stack;

  // -- Constructor --

  /** Constructs a new data browser. */
  public LociDataBrowser() {
    fStitch = new FileStitcher();
    reader = new ChannelSeparator(fStitch);
  }
  
  public LociDataBrowser(String name) {
    this();
    id = name;
    virtual = true;
  }
  
  public LociDataBrowser(boolean merged) {
    fStitch = new FileStitcher();
    if(merged) reader = new ChannelMerger(fStitch);
    else reader = new ChannelSeparator(fStitch);
  }
  
  public LociDataBrowser(String name, boolean merged) {
    this(merged);
    id = name;
    virtual = true;
  }
  
  public LociDataBrowser(IFormatReader r, FileStitcher fs, String name) {
    virtual = true;
    reader = r;
    fStitch = fs;
    id = name;
  }

  // -- LociDataBrowser API methods --

  /** 
  * Displays the given ImageJ image in a 4D browser window.
  * NB: this method is needed only internally. Do not call.
  */
  private void show(ImagePlus imp) {
    int stackSize = imp == null ? 0 : imp.getStackSize();

    if (stackSize == 0) {
      IJ.showMessage("Cannot show invalid image.");
      return;
    }

    if (stackSize == 1 && !virtual) {
      // show single image normally
      imp.show();
      return;
    }

    cw = new CustomWindow(this, imp, new ImageCanvas(imp));
  }
  
  /** Set the length of each dimensional axis and the dimension order. */
  public void setDimensions(int sizeZ, int sizeC, int sizeT, int z,
    int c, int t)
  {
    numZ = sizeZ;
    numC = sizeC;
    numT = sizeT;

    hasZ = numZ > 1;
    hasC = numC > 1;
    hasT = numT > 1;

    lengths = new int[3];
    lengths[z] = numZ;
    lengths[c] = numC;
    lengths[t] = numT;

    zIndex = z;
    cIndex = c;
    tIndex = t;
  }
  
  /** Reset all dimensional data in case they've switched.*/
  public void setDimensions() {
    String order = null;
    
    if (fStitch != null) {
      try {
        numZ = fStitch.getSizeZ(id);
        numC = fStitch.getEffectiveSizeC(id);
        numT = fStitch.getSizeT(id);
        order = fStitch.getDimensionOrder(id);
      }
      catch (Exception exc) {
        if (DEBUG) exc.printStackTrace();
        exceptionMessage(exc);
        return;
      }
    }
    else {
      try {
        numZ = reader.getSizeZ(id);
        numC = reader.getEffectiveSizeC(id);
        numT = reader.getSizeT(id);
        order = reader.getDimensionOrder(id);
      }
      catch (Exception exc) {
        if (DEBUG) exc.printStackTrace();
        exceptionMessage(exc);
        return;
      }
    }
    
    hasZ = numZ > 1;
    hasC = numC > 1;<commit_msg>Browser: 1) fix of channels being off bug<commit_after>//
// LociDataBrowser.java
//

/*
LOCI 4D Data Browser plugin for quick browsing of 4D datasets in ImageJ.
Copyright (C) 2005-@year@ <NAME>, <NAME>, <NAME>
and <NAME>.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Library General Public License for more details.

You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.plugins.browser;

import ij.*;
import ij.gui.GenericDialog;
import ij.gui.MessageDialog;
import ij.gui.ImageCanvas;
import ij.io.FileInfo;
import java.awt.Frame;
import loci.formats.*;

/**
 * LociDataBrowser is a plugin for ImageJ that allows for browsing of 4D
 * image data (stacks of image planes over time) with two-channel support.
 *
 * @author <NAME> at wisc.edu
 * @author <NAME> yutaiwong at wisc.edu
 * @author <NAME> ctrueden at wisc.edu
 * @author <NAME> linkert at cs.wisc.edu
 */
public class LociDataBrowser {

  // -- Constants --

  /** Debugging flag. */
  protected static final boolean DEBUG = false;

  // -- Fields --

  /** Filename for each index. */
  protected String[] names;

  /** The file format reader used by the plugin. */
  protected IFormatReader reader;
  
  /** The file stitcher used by the reader.*/
  protected FileStitcher fStitch;
  
  /** The CustomWindow used to display data.*/
  protected CustomWindow cw;

  /** The current file name. */
  protected String id;

  /** Whether dataset has multiple Z, T and C positions. */
  protected boolean hasZ, hasT, hasC;

  /** Number of Z, T and C positions. */
  protected int numZ, numT, numC;

  /** Lengths of all dimensional axes; lengths[0] equals image depth. */
  protected int[] lengths;

  /** Indices into lengths array for Z, T and C. */
  protected int zIndex, tIndex, cIndex;

  /** Whether stack is accessed from disk as needed. */
  protected boolean virtual;

  /** Cache manager (if virtual stack is used). */
  protected CacheManager manager;

  /** Series to use in a multi-series file. */
  protected int series;

  private ImageStack stack;

  // -- Constructor --

  /** Constructs a new data browser. */
  public LociDataBrowser() {
    fStitch = new FileStitcher();
    reader = new ChannelSeparator(fStitch);
  }
  
  public LociDataBrowser(String name) {
    this();
    id = name;
    virtual = true;
  }
  
  public LociDataBrowser(boolean merged) {
    fStitch = new FileStitcher();
    if(merged) reader = new ChannelMerger(fStitch);
    else reader = new ChannelSeparator(fStitch);
  }
  
  public LociDataBrowser(String name, boolean merged) {
    this(merged);
    id = name;
    virtual = true;
  }
  
  public LociDataBrowser(IFormatReader r, FileStitcher fs, String name) {
    virtual = true;
    reader = r;
    fStitch = fs;
    id = name;
  }

  // -- LociDataBrowser API methods --

  /** 
  * Displays the given ImageJ image in a 4D browser window.
  * NB: this method is needed only internally. Do not call.
  */
  private void show(ImagePlus imp) {
    int stackSize = imp == null ? 0 : imp.getStackSize();

    if (stackSize == 0) {
      IJ.showMessage("Cannot show invalid image.");
      return;
    }

    if (stackSize == 1 && !virtual) {
      // show single image normally
      imp.show();
      return;
    }

    cw = new CustomWindow(this, imp, new ImageCanvas(imp));
  }
  
  /** Set the length of each dimensional axis and the dimension order. */
  public void setDimensions(int sizeZ, int sizeC, int sizeT, int z,
    int c, int t)
  {
    numZ = sizeZ;
    numC = sizeC;
    numT = sizeT;

    hasZ = numZ > 1;
    hasC = numC > 1;
    hasT = numT > 1;

    lengths = new int[3];
    lengths[z] = numZ;
    lengths[c] = numC;
    lengths[t] = numT;

    zIndex = z;
    cIndex = c;
    tIndex = t;
  }
  
  /** Reset all dimensional data in case they've switched.*/
  public void setDimensions() {
    String order = null;
    
    if (fStitch != null) {
      try {
        numZ = fStitch.getSizeZ(id);
        if(reader instanceof ChannelMerger) numC = fStitch.getEffectiveSizeC(id);
        else numC = fStitch.getSizeC(id);
        numT = fStitch.getSizeT(id);
        order = fStitch.getDimensionOrder(id);
      }
      catch (Exception exc) {
        if (DEBUG) exc.printStackTrace();
        exceptionMessage(exc);
        return;
      }
    }
    else {
      try {
        numZ = reader.getSizeZ(id);
        if(reader instanceof ChannelMerger) numC = reader.getEffectiveSizeC(id);
        else numC = reader.getSizeC(id);
        numT = reader.getSizeT(id);
        order = reader.getDimensionOrder(id);
      }
      catch (Exception exc) {
        if (DEBUG) exc.printStackTrace();
        exceptionMessage(exc);
        return;
      }
    }
    
    hasZ = numZ > 1;
    hasC = numC > 1;
{'fraction_non_alphanumeric': 0.10362395462847256, 'fraction_numerical': 0.0064404498702297416, 'mean_word_length': 2.6841359773371103, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4216911', 'n_tokens_mistral': 3303, 'n_tokens_neox': 3182, 'n_words': 1160}