Hi Michael,<div><br></div><div><div>> I've just started looking into to porting my existing ImageJ plugins</div><div>> to ImageJ2. I have hit a problem in that calls to functions like</div><div>> setDisplayRange seem not to take effect until my plugin returns.</div>



<div><br></div><div>Yes, that is expected behavior, and a consequence of how ImageJ2's legacy layer works.</div><div><br></div><div>> The following plugin lets me interactively adjust the image display<br></div>
<div>> range when run with ImageJ1 but with ImageJ2 there is no effect to the</div><div>> image until I close the plugIn dialog.</div><div><br></div><div><div>Right. The rule of thumb is that IJ1 plugins which interactively alter an image will not do so in ImageJ2, due to the way the legacy layer works.</div>

<div><br></div></div><div>> I also note that the ImageJ2 Adjust->Brightness/Contrast (appears new)<br></div>

<div>> can update the image interactively, whereas the Adjust->WindowLevel</div><div>> (looks like existing ImageJ1 UI) does not work.</div><div><br></div><div>We rewrote the Brightness/Contrast command specifically due to this issue. The goal is to port all of ImageJ1's interactive plugins to ImageJ2, to avoid this limitation in the legacy layer.</div>

<div><br></div><div>There is an ImageJ2 design page about backwards compatibility and the legacy layer online at:</div><div>    <a href="http://developer.imagej.net/compatibility">http://developer.imagej.net/compatibility</a></div>

<div><br></div><div>We may be able to overcome the limitation with interactive plugins to an extent, but it is difficult in general.</div><div><br></div><div>Another solution which is coming soon is that we are working on a toggle in the Help menu to fully switch back and forth between ImageJ1 and ImageJ2 modes. The legacy layer will translate all data structures upon switch, so you can run your interactive legacy plugins in ImageJ1 mode, then switch back to ImageJ2 when finished.</div>

<div><br></div><div>When you say you want to port your existing ImageJ plugins, do you mean use them in ImageJ2 via the legacy layer? (Which is what you have tried so far.) Or fully update the code to use ImageJ2 data structures? For the latter, the migration will be complete when no more ImageJ1 classes (ij.*) are used, but only ImageJ2 classes (imagej.*). If you decide to go that route, we would be very happy to help with the conversion process. The plan is to write a plugin porting guide, but we do not have one yet.</div>

<div><br></div><div>Regards,</div><div>Curtis</div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 7, 2012 at 4:57 PM, Michael Ellis <span dir="ltr"><<a href="mailto:michael.ellis@dsuk.biz" target="_blank">michael.ellis@dsuk.biz</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><span style="background-color:transparent">I've just started looking into to porting my existing ImageJ plugins to ImageJ2. I have hit a problem in that calls to functions like setDisplayRange seem not to take effect until my plugin returns.<span style="white-space:pre-wrap"> </span><span style="white-space:pre-wrap">        </span></span><div>



<span style="background-color:transparent"><br></span></div><div><span style="background-color:transparent">The following plugin lets me interactively adjust the image display range when run with ImageJ1 but with ImageJ2 there is no effect to the image until I close the plugIn dialog.<br>



</span><div><div><span style="background-color:transparent"><br></span><div><span style="background-color:transparent">I also note that the ImageJ2 Adjust->Brightness/Contrast (appears new) can update the image interactively, whereas the Adjust->WindowLevel (looks like existing ImageJ1 UI) does not work.</span></div>



<div><span style="background-color:transparent"><br></span></div><div><span style="background-color:transparent">Any help greatly appreciated!</span></div><div><span style="background-color:transparent"><br></span></div>


<div>
<span style="background-color:transparent">Example code below</span></div><div><br></div><div>//===========================================================================</div><div><br></div><div><br></div><div><div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="color:rgb(148,28,100)">package</span> SmartCapture;</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px">


<br>
</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="color:rgb(148,28,100)">import</span> java.awt.AWTEvent;</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="color:rgb(148,28,100)">import</span> ij.IJ;</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="color:rgb(148,28,100)">import</span> ij.ImagePlus;</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="color:rgb(148,28,100)">import</span> ij.gui.DialogListener;</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="color:rgb(148,28,100)">import</span> ij.gui.GenericDialog;</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="color:rgb(148,28,100)">import</span> ij.plugin.filter.ExtendedPlugInFilter;</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="color:rgb(148,28,100)">import</span> ij.plugin.filter.PlugInFilterRunner;</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="color:rgb(148,28,100)">import</span> ij.process.ImageProcessor;</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px">



<br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="color:rgb(148,28,100)">public</span> <span style="color:rgb(148,28,100)">class</span> Test_IJ2 <span style="color:rgb(148,28,100)">implements</span> ExtendedPlugInFilter, DialogListener {</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span><span style="color:rgb(148,28,100)">private</span> <span style="color:rgb(148,28,100)">final</span> <span style="color:rgb(148,28,100)">static</span> String <span style="color:rgb(4,49,195)">PLUGIN_NAME</span> = Test_IJ2.<span style="color:rgb(148,28,100)">class</span>.getSimpleName();</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(76,143,117)">



<span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">      </span></span><span style="color:rgb(148,28,100)">private</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(148,28,100)">static</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(148,28,100)">int</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(4,49,195)">FLAGS</span><span style="color:rgb(0,0,0)"> = </span>// bitwise or of the following flags:</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(76,143,117)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">  </span></span><span style="color:rgb(4,49,195)">DOES_8G</span><span style="color:rgb(0,0,0)"> | </span><span style="color:rgb(4,49,195)">KEEP_PREVIEW</span><span style="color:rgb(0,0,0)">; </span>// When using preview, the preview image can be kept as a result</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span>ImagePlus <span style="color:rgb(4,49,195)">imp</span>;</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(148,28,100)">



<span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">      </span></span>private<span style="color:rgb(0,0,0)"> </span>double<span style="color:rgb(0,0,0)"> </span><span style="color:rgb(4,49,195)">low</span><span style="color:rgb(0,0,0)">;</span></div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(148,28,100)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">  </span></span>private<span style="color:rgb(0,0,0)"> </span>double<span style="color:rgb(0,0,0)"> </span><span style="color:rgb(4,49,195)">high</span><span style="color:rgb(0,0,0)">;</span></div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span><span style="color:rgb(148,28,100)">public</span> <span style="color:rgb(148,28,100)">int</span> setup(String arg, ImagePlus imp) {</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px">



<br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap">         </span><span style="color:rgb(148,28,100)">if</span> (imp == <span style="color:rgb(148,28,100)">null</span>) {</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(58,64,244)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">                   </span>IJ.error(</span><span style="color:rgb(4,49,195)">PLUGIN_NAME</span><span style="color:rgb(0,0,0)">, </span>"No image.\nOpen or create an image first then run "</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(4,49,195)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">                                    </span>+ </span>PLUGIN_NAME<span style="color:rgb(0,0,0)">);</span></div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(148,28,100)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">                  </span></span>return<span style="color:rgb(0,0,0)"> </span><span style="color:rgb(4,49,195)">DONE</span><span style="color:rgb(0,0,0)">;</span></div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap">               </span>}</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px">



<br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap">         </span><span style="color:rgb(148,28,100)">this</span>.<span style="color:rgb(4,49,195)">imp</span> = imp;</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(148,28,100)">



<span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">              </span></span>return<span style="color:rgb(0,0,0)"> </span><span style="color:rgb(4,49,195)">FLAGS</span><span style="color:rgb(0,0,0)">;</span></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span>}</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span><span style="color:rgb(148,28,100)">public</span> <span style="color:rgb(148,28,100)">int</span> showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px">



<br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap">         </span><span style="color:rgb(148,28,100)">assert</span> (imp != <span style="color:rgb(148,28,100)">null</span>);</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap">               </span><span style="color:rgb(148,28,100)">if</span> (imp == <span style="color:rgb(148,28,100)">null</span>)</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(148,28,100)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">                  </span></span>return<span style="color:rgb(0,0,0)"> </span><span style="color:rgb(4,49,195)">DONE</span><span style="color:rgb(0,0,0)">;</span></div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span>GenericDialog gd = <span style="color:rgb(148,28,100)">new</span> GenericDialog(<span style="color:rgb(4,49,195)">PLUGIN_NAME</span> + <span style="color:rgb(58,64,244)">"..."</span>);</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap">               </span>gd.addMessage(imp.getTitle());</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span>gd.addSlider(<span style="color:rgb(58,64,244)">"low"</span>, 0, 255, 0);</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span>gd.addSlider(<span style="color:rgb(58,64,244)">"high"</span>, 0, 255, 255);</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span>gd.addPreviewCheckbox(pfr, <span style="color:rgb(58,64,244)">" Preview"</span>);</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span>gd.addDialogListener(<span style="color:rgb(148,28,100)">this</span>);</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(76,143,117)">



<span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">              </span>gd.showDialog(); </span>// user input (or reading from macro) happens here</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span><span style="color:rgb(148,28,100)">if</span> (gd.wasCanceled()) <span style="color:rgb(76,143,117)">// dialog </span><span style="text-decoration:underline;color:rgb(76,143,117)">cancelled</span><span style="color:rgb(76,143,117)">?</span></div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(148,28,100)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">                  </span></span>return<span style="color:rgb(0,0,0)"> </span><span style="color:rgb(4,49,195)">DONE</span><span style="color:rgb(0,0,0)">;</span></div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap">               </span><span style="color:rgb(148,28,100)">return</span> IJ.setupDialog(imp, <span style="color:rgb(4,49,195)">FLAGS</span>);</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap">       </span>}</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px">



<br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco"><span style="white-space:pre-wrap"> </span><span style="color:rgb(148,28,100)">public</span> <span style="color:rgb(148,28,100)">boolean</span> dialogItemChanged(GenericDialog gd, AWTEvent e) {</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span><span style="color:rgb(4,49,195)">low</span> = gd.getNextNumber();</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span><span style="color:rgb(4,49,195)">high</span> = gd.getNextNumber();</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span>IJ.log(String.format(<span style="color:rgb(58,64,244)">"low=%g high=%g\n"</span>, <span style="color:rgb(4,49,195)">low</span>, <span style="color:rgb(4,49,195)">high</span>));</div>



<div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(148,28,100)">



<span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">              </span></span>return<span style="color:rgb(0,0,0)"> </span>true<span style="color:rgb(0,0,0)">;</span></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span>}</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span><span style="color:rgb(148,28,100)">public</span> <span style="color:rgb(148,28,100)">void</span> run(ImageProcessor ip) {</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;color:rgb(58,64,244)">



<span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">              </span>IJ.log(</span>"run called\n"<span style="color:rgb(0,0,0)">);</span></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span><span style="color:rgb(4,49,195)">imp</span>.setDisplayRange(<span style="color:rgb(4,49,195)">low</span>, <span style="color:rgb(4,49,195)">high</span>);</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span>}</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span><span style="color:rgb(148,28,100)">public</span> <span style="color:rgb(148,28,100)">void</span> setNPasses(<span style="color:rgb(148,28,100)">int</span> nPasses) {</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">             </span>IJ.log(String.format(<span style="color:rgb(58,64,244)">"setNPasses(%d)\n"</span>, nPasses));</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



<span style="white-space:pre-wrap">     </span>}</div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco;min-height:15px"><br></div><div style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-size:11px;line-height:normal;font-family:Monaco">



}</div></div><div><br></div></div></div></div></div></div><br>_______________________________________________<br>
ImageJ-devel mailing list<br>
<a href="mailto:ImageJ-devel@imagej.net" target="_blank">ImageJ-devel@imagej.net</a><br>
<a href="http://imagej.net/mailman/listinfo/imagej-devel" target="_blank">http://imagej.net/mailman/listinfo/imagej-devel</a><br>
<br></blockquote></div><br></div></div>