Skip to content

Commit

Permalink
Merge pull request #243 from knime-ip/efficient_labeling_editor
Browse files Browse the repository at this point in the history
Reuse incoming LabelingCell if nothing has changed
  • Loading branch information
AndreasBurger committed Oct 31, 2015
2 parents 8952641 + d7dd001 commit fad9e35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* @param <T>
* @param <L>
*/
public class LabelingEditorNodeFactory<T extends RealType<T> & NativeType<T>, L extends Comparable<L>>
extends NodeFactory<LabelingEditorNodeModel<T>> {
public class LabelingEditorNodeFactory<T extends RealType<T> & NativeType<T>, L>
extends NodeFactory<LabelingEditorNodeModel> {

/**
* {@inheritDoc}
*/
@Override
public LabelingEditorNodeModel<T> createNodeModel() {
return new LabelingEditorNodeModel<T>();
public LabelingEditorNodeModel createNodeModel() {
return new LabelingEditorNodeModel();
}

/**
Expand All @@ -39,17 +39,18 @@ public int getNrNodeViews() {
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public NodeView<LabelingEditorNodeModel<T>> createNodeView(final int i,
final LabelingEditorNodeModel<T> nodeModel) {
public NodeView<LabelingEditorNodeModel> createNodeView(final int i,
final LabelingEditorNodeModel nodeModel) {
return new TableCellViewNodeView(nodeModel);
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("rawtypes")
@Override
public NodeDialogPane createNodeDialogPane() {
return new LabelingEditorNodeDialog<T, L>();
return new LabelingEditorNodeDialog();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedIntType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
import net.imglib2.util.Util;
import net.imglib2.view.Views;

/**
Expand All @@ -41,8 +40,8 @@
*
* @param <L>
*/
public class LabelingEditorNodeModel<L extends Comparable<L>>
extends TwoValuesToCellNodeModel<LabelingValue<L>, ImgPlusValue<?>, LabelingCell<String>> {
public class LabelingEditorNodeModel
extends TwoValuesToCellNodeModel<LabelingValue<?>, ImgPlusValue<?>, LabelingCell<String>> {

static String LABEL_SETTINGS_KEY = "editedLabels";

Expand Down Expand Up @@ -81,7 +80,7 @@ protected void computeDataRow(final DataRow row) {

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected LabelingCell<String> compute(final LabelingValue<L> cellValue1, final ImgPlusValue<?> cellValue2)
protected LabelingCell compute(final LabelingValue<?> cellValue1, final ImgPlusValue<?> cellValue2)
throws Exception {

// Get RowKey of current row
Expand All @@ -92,29 +91,19 @@ protected LabelingCell<String> compute(final LabelingValue<L> cellValue1, final
final Map<RowColKey, LabelingEditorChangeTracker> map = m_annotationsSM.getTrackerMap();
// Get the tracker of the current row
final LabelingEditorChangeTracker currentTrack = map.get(k);

// if(!currentTrack.isDirty())
// TODO: Unmodified Cell handling.

RandomAccessibleInterval<LabelingType<String>> src = null;

if (currentTrack != null) {
if (!currentTrack.isDirty())
return (LabelingCell) cellValue1;

// Convert the input label to string, and then to the modified
// label.
src = Converters.convert(cellValue1.getLabeling(), new LabelingEditorLabelingConverter<L>(currentTrack),
cellValue1.getLabeling().randomAccess().get().createVariable(String.class));
RandomAccessibleInterval<LabelingType<String>> src = null;

} else {
// Convert the label to string
src = Converters.convert((RandomAccessibleInterval<LabelingType<L>>) cellValue1.getLabeling(),
new ToStringLabelingConverter<L>(),
(LabelingType<String>) Util.getTypeFromInterval(cellValue1.getLabeling()).createVariable());
}
// Convert the input label to string, and then to the modified
// label.
src = Converters.convert(cellValue1.getLabeling(), new LabelingEditorLabelingConverter(currentTrack),
cellValue1.getLabeling().randomAccess().get().createVariable(String.class));

// Create a new labeling and copy the values of the source-labeling
ImgLabeling<L, ? extends IntegerType<?>> lab = (ImgLabeling<L, ? extends IntegerType<?>>) cellValue1
.getLabeling();
ImgLabeling<?, ? extends IntegerType<?>> lab = (ImgLabeling) cellValue1.getLabeling();

final RandomAccessibleInterval<? extends IntegerType<?>> img = lab.getIndexImg();
Img newStorageImg = null;
Expand Down

0 comments on commit fad9e35

Please sign in to comment.