7575import org .knime .core .node .NotConfigurableException ;
7676import org .knime .core .node .defaultnodesettings .DialogComponent ;
7777import org .knime .core .node .defaultnodesettings .DialogComponentColumnNameSelection ;
78+ import org .knime .core .node .defaultnodesettings .DialogComponentNumber ;
7879import org .knime .core .node .defaultnodesettings .DialogComponentStringSelection ;
80+ import org .knime .core .node .defaultnodesettings .SettingsModelDouble ;
7981import org .knime .core .node .defaultnodesettings .SettingsModelString ;
8082import org .knime .knip .base .data .IntervalValue ;
8183import org .knime .knip .base .data .img .ImgPlusCell ;
@@ -122,11 +124,17 @@ private static SettingsModelString createIntervalColumnModel() {
122124 return new SettingsModelString ("interval_column" , "" );
123125 }
124126
125- private DialogComponentStringSelection m_dcImgType ;
127+ private static SettingsModelDouble createBackgroundValueModel () {
128+ return new SettingsModelDouble ("background_value" , 0.0 );
129+ }
126130
127131 // dialog components
128132 private DialogComponent m_dcIntervalCol ;
129133
134+ private DialogComponentStringSelection m_dcImgType ;
135+
136+ private DialogComponentNumber m_dcBackgroundValue ;
137+
130138 // the default settings, i.e. if the respective globalsettings are not
131139 // set
132140 private String m_intervalCol = "" ;
@@ -150,11 +158,13 @@ private static SettingsModelString createIntervalColumnModel() {
150158
151159 private T2 m_resultType = null ;
152160
161+ // settings models
153162 private final SettingsModelString m_smImgType = createImgTypeModel ();
154163
155- // settings models
156164 private final SettingsModelString m_smIntervalCol = createIntervalColumnModel ();
157165
166+ private final SettingsModelDouble m_smBackgroundValue = createBackgroundValueModel ();
167+
158168 public ImgComposeOperator () {
159169 super ("compose_image_2" , "Compose Image" , "Compose Image" );
160170 }
@@ -163,16 +173,16 @@ public ImgComposeOperator() {
163173 * @param label
164174 * @param globalSettings
165175 */
166- public ImgComposeOperator (final GlobalSettings globalSettings ) {
167- this (globalSettings , null , null );
176+ private ImgComposeOperator (final GlobalSettings globalSettings ) {
177+ this (globalSettings , null , null , 0 );
168178 }
169179
170180 /**
171181 * @param label
172182 * @param globalSettings
173183 */
174184 @ SuppressWarnings ("unchecked" )
175- public ImgComposeOperator (final GlobalSettings globalSettings , final String colName , final String type ) {
185+ private ImgComposeOperator (final GlobalSettings globalSettings , final String colName , final String type , final double bgValue ) {
176186 super ("compose_image_2" , "Compose Image" , globalSettings );
177187
178188 if (colName != null ) {
@@ -181,10 +191,10 @@ public ImgComposeOperator(final GlobalSettings globalSettings, final String colN
181191 if (type != null ) {
182192 m_smImgType .setStringValue (type );
183193 }
194+ m_smBackgroundValue .setDoubleValue (bgValue );
184195
185196 m_intervalCol = m_smIntervalCol .getStringValue ();
186197 m_resultType = (T2 )NativeTypes .getTypeInstance (NativeTypes .valueOf (m_smImgType .getStringValue ()));
187-
188198 }
189199
190200 /*
@@ -201,7 +211,7 @@ private boolean addToImage(final ImgPlusValue<T1> val) {
201211 // Set segmented pixels to label
202212 final Cursor <T1 > patchCursor = patch .localizingCursor ();
203213 final T1 minVal = patch .firstElement ().createVariable ();
204- minVal .setReal (minVal . getMinValue ());
214+ minVal .setReal (m_smBackgroundValue . getDoubleValue ());
205215 while (patchCursor .hasNext ()) {
206216 patchCursor .fwd ();
207217 if (patchCursor .get ().compareTo (minVal ) == 0 ) {
@@ -324,6 +334,8 @@ private void createDCs() {
324334 NativeTypes .UNSIGNEDSHORTTYPE , NativeTypes .INTTYPE ,
325335 NativeTypes .UNSIGNEDINTTYPE , NativeTypes .LONGTYPE ,
326336 NativeTypes .FLOATTYPE , NativeTypes .DOUBLETYPE ));
337+
338+ m_dcBackgroundValue = new DialogComponentNumber (createBackgroundValueModel (), "Background value" , 1 );
327339 }
328340 }
329341
@@ -334,7 +346,7 @@ private void createDCs() {
334346 public AggregationOperator createInstance (final GlobalSettings globalSettings ,
335347 final OperatorColumnSettings opColSettings ) {
336348 return new ImgComposeOperator <T1 , T2 >(globalSettings , m_smIntervalCol .getStringValue (),
337- m_smImgType .getStringValue ());
349+ m_smImgType .getStringValue (), m_smBackgroundValue . getDoubleValue () );
338350 }
339351
340352 @ Override
@@ -361,7 +373,11 @@ protected DataType getDataType(final DataType origType) {
361373 */
362374 @ Override
363375 public String getDescription () {
364- return "Composes images from image patches." ;
376+ return "Composes images from image patches.\n "
377+ + "Options:\n "
378+ + "Interval: the size of the result image\n "
379+ + "Result image type: the type of the result image\n "
380+ + "Background value: this value will be ignored and not transferred to the result image." ;
365381 }
366382
367383 /**
@@ -401,6 +417,7 @@ public Component getSettingsPanel() {
401417 panel .setLayout (new BoxLayout (panel , BoxLayout .Y_AXIS ));
402418 panel .add (m_dcIntervalCol .getComponentPanel ());
403419 panel .add (m_dcImgType .getComponentPanel ());
420+ panel .add (m_dcBackgroundValue .getComponentPanel ());
404421 return panel ;
405422 }
406423
@@ -418,6 +435,7 @@ public void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec
418435 createDCs ();
419436 m_dcIntervalCol .loadSettingsFrom (settings , new DataTableSpec []{spec });
420437 m_dcImgType .loadSettingsFrom (settings , new DataTableSpec []{spec });
438+ m_dcBackgroundValue .loadSettingsFrom (settings , new DataTableSpec []{spec });
421439 }
422440
423441 /**
@@ -430,6 +448,13 @@ public void loadValidatedSettings(final NodeSettingsRO settings) throws InvalidS
430448 m_smIntervalCol .setStringValue ("" );
431449 }
432450 m_smImgType .loadSettingsFrom (settings );
451+
452+ try {
453+ m_smBackgroundValue .loadSettingsFrom (settings );
454+ }catch (InvalidSettingsException e ) {
455+ //backwards compatibility -
456+ //use default value if settings not available
457+ }
433458 }
434459
435460 /**
@@ -461,12 +486,14 @@ public void saveSettingsTo(final NodeSettingsWO settings) {
461486 try {
462487 m_dcIntervalCol .saveSettingsTo (settings );
463488 m_dcImgType .saveSettingsTo (settings );
489+ m_dcBackgroundValue .saveSettingsTo (settings );
464490 } catch (final InvalidSettingsException e ) {
465491 throw new RuntimeException (e .getMessage ());
466492 }
467493 } else {
468494 m_smIntervalCol .saveSettingsTo (settings );
469495 m_smImgType .saveSettingsTo (settings );
496+ m_smBackgroundValue .saveSettingsTo (settings );
470497 }
471498
472499 }
@@ -478,5 +505,6 @@ public void saveSettingsTo(final NodeSettingsWO settings) {
478505 public void validateSettings (final NodeSettingsRO settings ) throws InvalidSettingsException {
479506 m_smIntervalCol .validateSettings (settings );
480507 m_smImgType .validateSettings (settings );
508+ m_smBackgroundValue .validateSettings (settings );
481509 }
482510}
0 commit comments