\hypertarget{classthree__B}{
\subsection{three\_\-B Class Reference}
\label{classthree__B}\index{three\_\-B@{three\_\-B}}
}


ImageJ plugin class.  




Inherits PlugInFilter.

\subsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
int \hyperlink{classthree__B_aa12aa5b0195e10a083ad35c02b34c209}{setup} (String arg\_\-, ImagePlus img)
\item 
void \hyperlink{classthree__B_a1be03ca90bbaa0ae202733313bfbc941}{run} (ImageProcessor ip)
\end{DoxyCompactItemize}
\subsubsection*{Package Attributes}
\begin{DoxyCompactItemize}
\item 
ImagePlus \hyperlink{classthree__B_a5ce586559de837bdfe43ed4d2cc7adc8}{window}
\item 
ByteProcessor \hyperlink{classthree__B_a7aebf83c5ec627cff4214f46cc419dfb}{mask}
\item 
String \hyperlink{classthree__B_ac5681e0f7c482d92f4bc4fbe84141345}{arg}
\end{DoxyCompactItemize}


\subsubsection{Detailed Description}
ImageJ plugin class. 

Definition at line 132 of file three\_\-B.java.



\subsubsection{Member Function Documentation}
\hypertarget{classthree__B_aa12aa5b0195e10a083ad35c02b34c209}{
\index{three\_\-B@{three\_\-B}!setup@{setup}}
\index{setup@{setup}!three_B@{three\_\-B}}
\paragraph[{setup}]{\setlength{\rightskip}{0pt plus 5cm}int three\_\-B::setup (
\begin{DoxyParamCaption}
\item[{String}]{arg\_\-, }
\item[{ImagePlus}]{img}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classthree__B_aa12aa5b0195e10a083ad35c02b34c209}


Definition at line 138 of file three\_\-B.java.



References arg, and window.


\begin{DoxyCode}
                                                 {
        window = img;
        arg=arg_;

        return ROI_REQUIRED + SUPPORTS_MASKING + STACK_REQUIRED +NO_CHANGES + DOE
      S_16 + DOES_32 + DOES_8G;
    }
\end{DoxyCode}
\hypertarget{classthree__B_a1be03ca90bbaa0ae202733313bfbc941}{
\index{three\_\-B@{three\_\-B}!run@{run}}
\index{run@{run}!three_B@{three\_\-B}}
\paragraph[{run}]{\setlength{\rightskip}{0pt plus 5cm}void three\_\-B::run (
\begin{DoxyParamCaption}
\item[{ImageProcessor}]{ip}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classthree__B_a1be03ca90bbaa0ae202733313bfbc941}


Definition at line 145 of file three\_\-B.java.



References SPair::a, arg, SPair::b, Util::getFileName(), mask, Util::read(), and window.


\begin{DoxyCode}
                                       {



        //Load the config file contents
        Reader cfgstream = new InputStreamReader(getClass().getClassLoader().getR
      esourceAsStream("multispot5.cfg"));
        String cfg = Util.read(cfgstream);

        try{
            cfgstream.close();
        }
        catch(IOException close_err){
            Toolkit.getDefaultToolkit().beep();
            ij.IJ.showStatus("Error reading config file.");
            return;
        }

        //Some basic error checking if reading of the config file from
        //the JAR archive fails.
        if(cfg == "")
        {
            Toolkit.getDefaultToolkit().beep();
            ij.IJ.showStatus("Error reading config file.");
            return;
        }


        //The image from getMask() is only the size of the ROI
        //We need it to be congruent with the original image, in order
        //to work with the C++ code.
        mask = new ByteProcessor(ip.getWidth(), ip.getHeight());

        int x = ip.getRoi().x;
        int y = ip.getRoi().y;
        
        //Rectangular selections do not have a mask set, so we get
        //a null pointer exception when we try to copy.
        //So, we have to manually set the pixels, rather than just
        //copy them
        try{
            mask.copyBits(ip.getMask(), x, y, Blitter.COPY);
        }
        catch(NullPointerException e)
        {
            for(int r=0; r < ip.getRoi().height; r++)
                for(int c=0; c < ip.getRoi().width; c++)
                    mask.set(c+x, r+y, 255);
        }
        
        //Count the number of set pixels in the mask. This is used to 
        //warn the user if the number is not within a reasonable range.
        int count=0;
        for(int r=0; r < mask.getHeight(); r++)
            for(int c=0; c < mask.getWidth(); c++)
                if(mask.get(c, r) != 0)
                    count ++;


        //The non-config file parameters are the range of frames to  operate on
        //and the pixel size in nm (the config works in terms of FWHM in pixels).
      
        //These have to be sepficied whether the basic or advanced dialog is used
      .
        int  firstfr;
        int lastfr;
        double pixel_size_in_nm;

        ImageStack s = window.getStack();

        if(arg.equals("advanced"))
        {
            AdvancedDialog ad = new AdvancedDialog(cfg, s.getSize());
            if(!ad.wasOKed())
                return;
            cfg = ad.getTextArea1().getText();
            

            /*pixel_size_in_nm = ad.getPixelSize();
            firstfr = ad.getFirstFrame();
            lastfr = ad.getLastFrame();*/


            pixel_size_in_nm = ad.getNextNumber();
            firstfr = (int)ad.getNextNumber();
            lastfr = (int)ad.getNextNumber();
        }
        else
        {
            ThreeBDialog gd = new ThreeBDialog(count, mask.getWidth()*mask.getHei
      ght(), s.getSize());

            gd.showDialog();
        
            if(!gd.wasOKed())
                return;

            /*final double fwhm = gd.getFWHM();
            pixel_size_in_nm = gd.getPixelSize();
            final int initial_spots = gd.getSpots();
            firstfr = gd.getFirstFrame();
            lastfr = gd.getLastFrame();*/

            //We have to use getNextNumber, otherwise macro recording does not wo
      rk.
            final double fwhm = gd.getNextNumber();
            pixel_size_in_nm = gd.getNextNumber();
            final int initial_spots = (int)gd.getNextNumber();
            firstfr = (int)gd.getNextNumber();
            lastfr = (int)gd.getNextNumber();


            //Compute the parameters of the log-normal prior such that the mode
            //matches the size of the spots.
            final double sigma = (fwhm / pixel_size_in_nm) / (2*Math.sqrt(2*Math.
      log(2)));
            final double blur_sigma=0.1;

            //s = exp(mu-sig^2)
            //ln s = mu - sig^2
            //mu = ln s + sig^2

            final double blur_mu = Math.log(sigma) + blur_sigma*blur_sigma;
            
            //Initialized from the current time.
            Random rng = new Random();
            //


            //Append stuff to the config file now. This will be parsed later in C
      ++.
            cfg = cfg + "placement.uniform.num_spots=" + Integer.toString(initial
      _spots) + "\n"
                      + "blur.mu="    + Double.toString(blur_mu) + "\n" 
                      + "blur.sigma=" + Double.toString(blur_sigma) + "\n"
                      + "seed=" + Integer.toString(rng.nextInt(16777216)) + "\n";
      

        }
        
        //Acquire a filename to save moderately safely.
        SPair f = Util.getFileName(window.getTitle());
        final String fname = f.a;
        final String fullname = f.b;

        if(fname!= null)
        {
            //Create the 3B runner and the control panel, then execute the contro
      l panel in the
            //GUI thread.
            final Rectangle roi = ip.getRoi();
            final double pixel_size_in_nm_ = pixel_size_in_nm;
            final ThreeBRunner tbr = new ThreeBRunner(mask, s, cfg, fullname, fir
      stfr, lastfr);

            SwingUtilities.invokeLater(
                    new Runnable() {
                            public void run() {
                                    new EControlPanel(roi, pixel_size_in_nm_, fna
      me, tbr);
                            }
                    }
            );

        }
    }
\end{DoxyCode}


\subsubsection{Member Data Documentation}
\hypertarget{classthree__B_a5ce586559de837bdfe43ed4d2cc7adc8}{
\index{three\_\-B@{three\_\-B}!window@{window}}
\index{window@{window}!three_B@{three\_\-B}}
\paragraph[{window}]{\setlength{\rightskip}{0pt plus 5cm}ImagePlus {\bf three\_\-B::window}\hspace{0.3cm}{\ttfamily  \mbox{[}package\mbox{]}}}}
\label{classthree__B_a5ce586559de837bdfe43ed4d2cc7adc8}


Definition at line 134 of file three\_\-B.java.



Referenced by run(), and setup().

\hypertarget{classthree__B_a7aebf83c5ec627cff4214f46cc419dfb}{
\index{three\_\-B@{three\_\-B}!mask@{mask}}
\index{mask@{mask}!three_B@{three\_\-B}}
\paragraph[{mask}]{\setlength{\rightskip}{0pt plus 5cm}ByteProcessor {\bf three\_\-B::mask}\hspace{0.3cm}{\ttfamily  \mbox{[}package\mbox{]}}}}
\label{classthree__B_a7aebf83c5ec627cff4214f46cc419dfb}


Definition at line 135 of file three\_\-B.java.



Referenced by run().

\hypertarget{classthree__B_ac5681e0f7c482d92f4bc4fbe84141345}{
\index{three\_\-B@{three\_\-B}!arg@{arg}}
\index{arg@{arg}!three_B@{three\_\-B}}
\paragraph[{arg}]{\setlength{\rightskip}{0pt plus 5cm}String {\bf three\_\-B::arg}\hspace{0.3cm}{\ttfamily  \mbox{[}package\mbox{]}}}}
\label{classthree__B_ac5681e0f7c482d92f4bc4fbe84141345}


Definition at line 136 of file three\_\-B.java.



Referenced by run(), and setup().



The documentation for this class was generated from the following file:\begin{DoxyCompactItemize}
\item 
\hyperlink{three__B_8java}{three\_\-B.java}\end{DoxyCompactItemize}
