Skip to content

Commit

Permalink
Add a 'basic' setting panel to the mesh smoother.
Browse files Browse the repository at this point in the history
It filters with mu = 1., lambda -0, which is like applying heavy
Laplace smoothing.
  • Loading branch information
tinevez committed Nov 21, 2023
1 parent 2b400d0 commit ba88e50
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ public MeshSmootherController( final Model model, final SelectionModel selection
this.model = model;
this.selectionModel = selectionModel;
this.logger = logger;
final MeshSmootherModel smootherModel = new MeshSmootherModel();
this.gui = new MeshSmootherPanel( smootherModel );
this.gui = new MeshSmootherPanel();
this.smoother = new MeshSmoother( logger );

gui.btnRun.addActionListener( e -> run( smootherModel ) );
gui.btnRun.addActionListener( e -> run( gui.getModel() ) );
gui.btnUndo.addActionListener( e -> undo() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import fiji.plugin.trackmate.gui.displaysettings.SliderPanel;
import fiji.plugin.trackmate.gui.displaysettings.SliderPanelDouble;
Expand All @@ -43,17 +41,34 @@ public class MeshSmootherPanel extends JPanel

final JRadioButton rdbtnAll;

public MeshSmootherPanel( final MeshSmootherModel model )
{
final BoundedDoubleElement smoothing = StyleElements.boundedDoubleElement( "Smoothing (%)", 0., 100., () -> model.getMu() * 100., v -> model.setSmoothing( v / 100. ) );
final IntElement nIters1 = StyleElements.intElement( "N iterations", 1, 50, model::getNIters, model::setNIters );
final BoundedDoubleElement mu = StyleElements.boundedDoubleElement( "µ", 0., 1., model::getMu, model::setMu );
final BoundedDoubleElement lambda = StyleElements.boundedDoubleElement( "-λ", 0., 1., () -> -model.getLambda(), l -> model.setLambda( -l ) );
final EnumElement< TaubinWeightType > weightType = StyleElements.enumElement( "weight type", TaubinWeightType.values(), model::getWeightType, model::setWeightType );
final IntElement nIters2 = StyleElements.intElement( "N iterations", 1, 50, model::getNIters, model::setNIters );
private final MeshSmootherModel modelBasic;

private final MeshSmootherModel modelSimple;

private final MeshSmootherModel modelAdvanced;

final List< StyleElement > simpleElements = Arrays.asList( smoothing, nIters1 );
final List< StyleElement > advancedElements = Arrays.asList( mu, lambda, nIters2, weightType );
private final JTabbedPane mainPanel;

public MeshSmootherPanel()
{
this.modelBasic = new MeshSmootherModel();
modelBasic.setMu( 1. );
modelBasic.setLambda( 0. );
modelBasic.setWeightType( TaubinWeightType.NAIVE );
final IntElement nItersBasic = StyleElements.intElement( "N iterations", 1, 50, modelBasic::getNIters, modelBasic::setNIters );
final List< StyleElement > superSimpleElements = Arrays.asList( nItersBasic );

this.modelSimple = new MeshSmootherModel();
final BoundedDoubleElement smoothing = StyleElements.boundedDoubleElement( "Smoothing (%)", 0., 100., () -> modelSimple.getMu() * 100., v -> modelSimple.setSmoothing( v / 100. ) );
final IntElement nItersSimple = StyleElements.intElement( "N iterations", 1, 50, modelSimple::getNIters, modelSimple::setNIters );
final List< StyleElement > simpleElements = Arrays.asList( smoothing, nItersSimple );

this.modelAdvanced = new MeshSmootherModel();
final BoundedDoubleElement mu = StyleElements.boundedDoubleElement( "µ", 0., 1., modelAdvanced::getMu, modelAdvanced::setMu );
final BoundedDoubleElement lambda = StyleElements.boundedDoubleElement( "-λ", 0., 1., () -> -modelAdvanced.getLambda(), l -> modelAdvanced.setLambda( -l ) );
final EnumElement< TaubinWeightType > weightType = StyleElements.enumElement( "weight type", TaubinWeightType.values(), modelAdvanced::getWeightType, modelAdvanced::setWeightType );
final IntElement nItersAdvanced = StyleElements.intElement( "N iterations", 1, 50, modelAdvanced::getNIters, modelAdvanced::setNIters );
final List< StyleElement > advancedElements = Arrays.asList( mu, lambda, nItersAdvanced, weightType );

setLayout( new BorderLayout( 0, 0 ) );

Expand Down Expand Up @@ -89,9 +104,16 @@ public MeshSmootherPanel( final MeshSmootherModel model )
this.btnRun = new JButton( "Run" );
buttonPanel.add( btnRun );

final JTabbedPane mainPanel = new JTabbedPane( JTabbedPane.TOP );
this.mainPanel = new JTabbedPane( JTabbedPane.TOP );
add( mainPanel, BorderLayout.CENTER );

final JPanel panelSuperSimple = new JPanel();
panelSuperSimple.setOpaque( false );
panelSuperSimple.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) );
final MyStyleElementVisitors superSimplePanelVisitor = new MyStyleElementVisitors( panelSuperSimple );
superSimpleElements.forEach( el -> el.accept( superSimplePanelVisitor ) );
mainPanel.addTab( "Basic", null, panelSuperSimple, null );

final JPanel panelSimple = new JPanel();
panelSimple.setOpaque( false );
panelSimple.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) );
Expand All @@ -110,30 +132,20 @@ public MeshSmootherPanel( final MeshSmootherModel model )
buttonGroup.add( rdbtnAll );
buttonGroup.add( rdbtnSelection );
rdbtnSelection.setSelected( true );
}

mainPanel.addChangeListener( new ChangeListener()
public MeshSmootherModel getModel()
{
switch ( mainPanel.getSelectedIndex() )
{

@Override
public void stateChanged( final ChangeEvent e )
{
if ( mainPanel.getSelectedIndex() == 0 )
{
// Simple.
model.setSmoothing( smoothing.get() );
model.setNIters( nIters1.get() );
model.setWeightType( TaubinWeightType.NAIVE );
}
else
{
// Advanced.
model.setMu( mu.get() );
model.setLambda( lambda.get() );
model.setNIters( nIters2.get() );
model.setWeightType( weightType.getValue() );
}
}
} );
case 0:
return modelBasic;
case 1:
return modelSimple;
case 2:
return modelAdvanced;
}
throw new IllegalStateException( "Cannot handle mesh smoothing settings type number " + ( mainPanel.getSelectedIndex() ) );
}

private static class MyStyleElementVisitors implements StyleElementVisitor
Expand Down Expand Up @@ -210,7 +222,7 @@ private Font getFont()

public static void main( final String[] args )
{
final MeshSmootherPanel panel = new MeshSmootherPanel( new MeshSmootherModel() );
final MeshSmootherPanel panel = new MeshSmootherPanel();

final JFrame frame = new JFrame( "Smoothing params" );
frame.getContentPane().add( panel );
Expand Down

0 comments on commit ba88e50

Please sign in to comment.