Skip to content

Commit

Permalink
v.0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ekatrukha committed Jan 23, 2025
1 parent 7efff06 commit 6c6046f
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/main/java/bigtrace/BigTraceActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;


import org.scijava.ui.behaviour.io.InputTriggerConfig;
import org.scijava.ui.behaviour.util.Actions;
import org.scijava.ui.behaviour.util.Behaviours;

import bigtrace.geometry.Line3D;
import bigtrace.gui.Rotate3DViewerStyle;
import bigtrace.rois.LineTrace3D;
import bigtrace.rois.Roi3D;
import bigtrace.rois.RoiManager3D;
import bigtrace.volume.VolumeMisc;
import bvvpg.vistools.BvvHandle;


public class BigTraceActions < T extends RealType< T > & NativeType< T > >
{
Expand All @@ -28,12 +33,14 @@ public class BigTraceActions < T extends RealType< T > & NativeType< T > >
final Actions actions;

public BigTraceActions(final BigTrace<T> bt_)
{

{
bt = bt_;
actions = new Actions( new InputTriggerConfig() );
installActions();
installBehaviors();
}


public void installActions()
{
//final Actions actions = new Actions( new InputTriggerConfig() );
Expand Down Expand Up @@ -84,6 +91,24 @@ public void installActions()


}

/** install smoother rotation **/
void installBehaviors()
{
final BvvHandle handle = bt.bvv_main.getBvvHandle();
//change drag rotation for navigation "3D Viewer" style
final Rotate3DViewerStyle dragRotate = new Rotate3DViewerStyle( 0.75, handle);
final Rotate3DViewerStyle dragRotateFast = new Rotate3DViewerStyle( 2.0, handle);
final Rotate3DViewerStyle dragRotateSlow = new Rotate3DViewerStyle( 0.1, handle);

final Behaviours behaviours = new Behaviours( new InputTriggerConfig() );
behaviours.behaviour( dragRotate, "drag rotate", "button1" );
behaviours.behaviour( dragRotateFast, "drag rotate fast", "shift button1" );
behaviours.behaviour( dragRotateSlow, "drag rotate slow", "ctrl button1" );
behaviours.install( handle.getTriggerbindings(), "BigTrace Behaviours" );
}


/** find a brightest pixel in the direction of a click
* and add a new 3D point to active ROI OR
* start a new ROI (if none selected)
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/bigtrace/gui/Rotate3DViewerStyle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package bigtrace.gui;


import net.imglib2.realtransform.AffineTransform3D;

import org.scijava.ui.behaviour.DragBehaviour;

import bvvpg.vistools.BvvHandle;

public class Rotate3DViewerStyle implements DragBehaviour
{
/**
* Coordinates where mouse dragging started.
*/
private double oX, oY;

private final double speed;
/**
* One step of rotation (radian).
*/
final private static double step = Math.PI / 180;

private int centerX = 0, centerY = 0;
final BvvHandle bvvHandle;
private final AffineTransform3D transform = new AffineTransform3D();
private final AffineTransform3D affineDragStart = new AffineTransform3D();
private final AffineTransform3D affineDragCurrent = new AffineTransform3D();

public Rotate3DViewerStyle( final double speed, BvvHandle bvvHandle_)
{
this.bvvHandle = bvvHandle_;
this.speed = speed;
}

@Override
public void init( final int x, final int y )
{
oX = x;
oY = y;
centerX = bvvHandle.getViewerPanel().getDisplay().getWidth()/2;
centerY = bvvHandle.getViewerPanel().getDisplay().getHeight()/2;
//affineDragStart.set(bvvHandle.getViewerPanel().state().getViewerTransform());
//transform.get( affineDragStart );
}

@Override
public void drag( final int x, final int y )
{
final double dX = oX - x;
final double dY = oY - y;

affineDragCurrent.set( affineDragStart );

// center shift
affineDragCurrent.set( affineDragCurrent.get( 0, 3 ) - centerX, 0, 3 );
affineDragCurrent.set( affineDragCurrent.get( 1, 3 ) - centerY, 1, 3 );
final double v = step * speed;
affineDragCurrent.rotate( 0, -dY * v );
affineDragCurrent.rotate( 1, dX * v );

// center un-shift
affineDragCurrent.set( affineDragCurrent.get( 0, 3 ) + centerX, 0, 3 );
affineDragCurrent.set( affineDragCurrent.get( 1, 3 ) + centerY, 1, 3 );

//does not depend on how far we from initial click
oX = x;
oY = y;

transform.set( bvvHandle.getViewerPanel().state().getViewerTransform() );
transform.preConcatenate( affineDragCurrent );
bvvHandle.getViewerPanel().state().setViewerTransform(transform);
}

@Override
public void end( final int x, final int y )
{}

}

0 comments on commit 6c6046f

Please sign in to comment.