ini.trakem2.display
Class Profile

java.lang.Object
  extended by ini.trakem2.persistence.DBObject
      extended by ini.trakem2.display.Displayable
          extended by ini.trakem2.display.Profile
All Implemented Interfaces:
Paintable, VectorData

public class Profile
extends Displayable
implements VectorData

A class to be a user-outlined profile over an image, which is painted with a particular color and also holds an associated text label. TODO - label not implemented yet. - can't paint segments in different colors yet - the whole curve is updated when only a particular set of points needs readjustment - also, points are smooth, and options should be given to make them non-smooth.


Nested Class Summary
 
Nested classes/interfaces inherited from class ini.trakem2.display.Displayable
Displayable.DataPackage, Displayable.DoEdit, Displayable.DoEdits, Displayable.DoTransforms, Displayable.SliderListener
 
Field Summary
protected  boolean closed
          Paint/behave as open or closed curve.
protected  int n_points
          The number of points.
protected  double[][] p
          The array of clicked points.
protected  double[][] p_i
          The array of interpolated points generated from p, p_l and p_r.
protected  double[][] p_l
          The array of left control points, one for each clicked point.
protected  double[][] p_r
          The array of right control points, one for each clicked point.
 
Fields inherited from class ini.trakem2.display.Displayable
alpha, annotation, at, color, COMPOSITE_ADD, COMPOSITE_COLOR_YCBCR, COMPOSITE_DIFFERENCE, COMPOSITE_MULTIPLY, COMPOSITE_NORMAL, COMPOSITE_SUBTRACT, compositeModes, height, hs_linked, last_color, layer, linked_props, linked_props_origins, locked, props, TAG_ATTR1, TAG_ATTR2, title, visible, width
 
Fields inherited from class ini.trakem2.persistence.DBObject
id, project
 
Constructor Summary
Profile(Project project, long id, java.util.HashMap<java.lang.String,java.lang.String> ht, java.util.HashMap<Displayable,java.lang.String> ht_links)
          Construct a Bezier Profile from an XML entry.
Profile(Project project, long id, java.lang.String title, float alpha, boolean visible, java.awt.Color color, double[][][] bezarr, boolean closed, boolean locked, java.awt.geom.AffineTransform at)
          Construct a Bezier Profile from the database.
Profile(Project project, long id, java.lang.String title, float width, float height, float alpha, boolean visible, java.awt.Color color, boolean closed, boolean locked, java.awt.geom.AffineTransform at)
          Construct a Bezier Profile from the database, but the points will be loaded later, when actually needed, by calling setupForDisplay().
Profile(Project project, java.lang.String title, double x, double y)
          A new user-requested Profile.
Profile(Project project, java.lang.String title, double x, double y, java.awt.geom.Point2D.Double[] points)
          Construct a Bezier Profile object from a set of points mixed in this pattern: PCCPCCPCCPCCP , so, [PCC]n where P = backbone point and C = control point.
 
Method Summary
protected  int addPoint(double x_p, double y_p, double magnification, double bezier_finess)
          Add a point either at the end or between two existing points, with accuracy depending on magnification.
protected  void addPointsAtBegin(double[][] new_p_l, double[][] new_p, double[][] new_p_r)
           
protected  void addPointsAtEnd(double[][] new_p_l, double[][] new_p, double[][] new_p_r)
           
 boolean apply(Layer la, java.awt.geom.Area roi, mpicbg.models.CoordinateTransform ict)
          Applies the 2D transform @ict (which is expected to operate on the world coordinates version of the data contained here) only to the data that falls within the @param roi (in world coords), and then recomputes the bounding box and affine transform (to a translation or identity).
 boolean apply(VectorDataTransform vdt)
           
 void cache()
          Cache this Profile if needed.
protected  void calculateBoundingBox()
           
protected  void calculateBoundingBox(boolean adjust_position)
          Calculate the bounding box of the curve in the shape of a Rectangle defined by x,y,width,height.
 boolean canSendTo(Layer target_layer)
          Returns false if the target_layer contains a profile that is directly linked to this profile.
 Displayable clone(Project pr, boolean copy_id)
          Performs a deep copy of this object, unlocked and visible.
 double computeArea()
          Calibrated, in units as specified at getLayerSet().getCalibration().getUnit() -- returns zero if this profile is not closed.
 double computeLength()
          Calibrated for pixel width only (that is, it assumes pixel aspect ratio 1:1), in units as specified at getLayerSet().getCalibration().getUnit()
 boolean containsPoint(int x_p, int y_p)
          Check if the given point (usually from a MOUSE_PRESSED MouseEvent) is contained within the boundaries of this object.
 void destroy()
          Release all memory resources taken by this object.
protected  double distance(double x1, double y1, double x2, double y2)
          Calculate distance from one point to another.
protected  void dragControlPoint(int index, double x_d, double y_d, double[][] p_dragged, double[][] p_adjusted, boolean symmetric)
          Drag a control point and adjust the other, dependent one, in a symmetric way or not.
protected  void dragPoint(int index, int dx, int dy)
          Move backbone point.
protected  void enlargeArrays()
          Increase the size of the arrays by 5 points.
static void exportDTD(java.lang.StringBuilder sb_header, java.util.HashSet<java.lang.String> hs, java.lang.String indent)
           
 void exportSVG(java.lang.StringBuffer data, double z_scale, java.lang.String indent)
          Does nothing unless overriden.
 void exportXML(java.lang.StringBuilder sb_body, java.lang.String indent, java.lang.Object any)
          The oid is this objects' id, whereas the 'id' tag will be the id of the wrapper Thing object.
protected  int findClosestPoint(double x_p, double y_p, double magnification, double bezier_finess)
          Find the closest point to an interpolated point with precision depending upon magnification.
protected  int findPoint(double[][] a, double x_p, double y_p, double magnification)
          Find a point in an array 'a', with a precision dependent on the magnification.
 void flush()
          Release memory resources used by this object: namely the arrays of points, which can be reloaded with a call to setupForDisplay()
protected  void generateInterpolatedPoints(double bezier_finess)
           
static java.util.List<javax.vecmath.Point3f> generateTriangles(ProjectThing pt, double scale)
          Takes a profile_list, scans for its Profile children, makes sublists of continuous profiles (if they happen to be branched), and then creates triangles for them using weighted vector strings.
 double[][][] getBezierArrays()
          Returns a triple array, each containing a [2][n_points] array specifiying the x,y of each left control point, backbone point and right control point respectively.
protected  double[][] getFirstPoint()
           
protected  double[][] getLastPoint()
           
 int getNearestPointIndex(double x_p, double y_p)
           
 java.awt.Polygon getPerimeter()
          The perimeter of this profile, in integer precision.
 VectorString2D getPerimeter2D()
          Returns the interpolated points as a VectorString2D, calibrated.
 int getPointCount()
          Returns the number of backbone points.
 boolean hasPoints()
           
 void insertBetween(int startIndex, int endIndex, double[][] tmp_p_l, double[][] tmp_p, double[][] tmp_p_r)
           
 boolean isClosed()
           
 boolean isDeletable()
           
 boolean isLinked()
          Returns true if it's linked to at least one patch in the same Layer.
 boolean isRoughlyInside(Layer layer, java.awt.Rectangle r)
          If this Displayable intersects with @param r or almost intersects, then returns true.
 void keyPressed(java.awt.event.KeyEvent ke)
           
static ij.measure.ResultsTable measure(Profile[] profiles, ij.measure.ResultsTable rt, long profile_list_id)
          Assumes Z-coord sorted list of profiles, as stored in a "profile_list" ProjectThing type.
 ij.measure.ResultsTable measure(ij.measure.ResultsTable rt)
          Measures the calibrated length, the lateral surface as the length times the layer thickness, and the volume (if closed) as the area times the layer thickness.
 void mouseDragged(java.awt.event.MouseEvent me, Layer layer, int x_p, int y_p, int x_d, int y_d, int x_d_old, int y_d_old)
          Execute the mouseDragged MouseEvent on this Profile.
 void mousePressed(java.awt.event.MouseEvent me, Layer layer, int x_p, int y_p, double mag)
          Execute the mousePressed MouseEvent on this Profile.
 void mouseReleased(java.awt.event.MouseEvent me, Layer layer, int x_p, int y_p, int x_d, int y_d, int x_r, int y_r)
          Execute the mouseReleased MouseEvent on this Profile.
 void paint(java.awt.Graphics2D g, java.awt.Rectangle srcRect, double magnification, boolean active, int channels, Layer active_layer, java.util.List<Layer> layers)
           
 void printPoints()
           
protected  boolean remove2(boolean check)
          Remove also from the trees if present; does nothing more than remove(boolean) unless overriden.
protected  void removePoint(int index)
          Remove a point from the bezier backbone and its two associated control points.
 void repaint()
          Repaint this Displayable in all Display instances that are showing it.
 void repaint(boolean repaint_navigator)
          Repaints in the given ImageCanvas only the area corresponding to the bounding box of this Profile.
protected  void resetControlPoints(int index)
          Set the control points to the same value as the backbone point which they control.
 void setColor(java.awt.Color c)
           
protected  void setPoints(double[][] p_l, double[][] p, double[][] p_r)
           
 void setPoints(double[][] p_l, double[][] p, double[][] p_r, boolean update)
           
 void snapTo(int cx, int cy, int x_p, int y_p)
          x,y is the cursor position in offscreen coordinates.
 boolean softRemove()
          Does nothing.
 void toggleClosed()
          Toggle curve closed/open.
 void toShapesFile(java.lang.StringBuffer data, java.lang.String group, java.lang.String color, double z_scale)
          Writes the data of this object as a Bezier object in the .shapes file represented by the 'data' StringBuffer.
 
Methods inherited from class ini.trakem2.display.Displayable
adjustProperties, areThereLayerCrossLinks, clone, clone, commonDTDChildren, contains, contains, deselect, displacePoints, exportDTD, findById, findNearestPoint, findNearestPoint, getAffineTransform, getAffineTransformCopy, getAlpha, getAnnotation, getArea, getAreaAt, getAreaForBucket, getBoundingBox, getBoundingBox, getBoundingBox, getBounds, getBounds, getBucketable, getColor, getComposite, getComposite, getCompositeMode, getHeight, getIntersection, getLayer, getLayerIds, getLayerSet, getLayersWithData, getLinked, getLinked, getLinkedBox, getLinkedGroup, getLinkedProperties, getLinkedProperties, getLinkedProperty, getLinkedProperty, getMinimalBoundingBox, getNameId, getPerimeter, getProperties, getProperty, getProperty, getShortTitle, getTitle, getWidth, getX, getXMLSafeValue, getXMLSafeValue, getY, hasLinkedGroupWithinLayer, hasProperties, intersects, intersects, intersects, intersects, inverseTransformPoint, isLinked, isLinked, isLocked, isLocked2, isOnlyLinkedTo, isOnlyLinkedTo, isOutOfRepaintingClip, isOutOfRepaintingClip, isVisible, link, link, linkPatches, makeAdjustPropertiesDialog, mouseWheelMoved, paintAsBox, paintOffscreen, paintSnapshot, prePaint, preTransform, processAdjustPropertiesDialog, remove, removeLinkedProperties, removeLinkedPropertiesFromOrigins, restXML, rotate, rotate, rotatePoints, scale, scale, scalePoints, setAffineTransform, setAlpha, setAlpha, setAnnotation, setCompositeMode, setDimensions, setDimensions, setLayer, setLayer, setLinkedProperties, setLinkedProperty, setLocation, setLocked, setProperty, setTitle, setVisible, setVisible, toString, transform, transformPoint, transformPoint, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformRectangle, translate, translate, unlink, unlink, unlinkAll, updateBucket, updateInDatabase, xmlError, xmlError
 
Methods inherited from class ini.trakem2.persistence.DBObject
addToDatabase, getId, getInfo, getProject, getUniqueIdentifier, removeFromDatabase, updateInDatabase
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

n_points

protected int n_points
The number of points.


p

protected double[][] p
The array of clicked points.


p_l

protected double[][] p_l
The array of left control points, one for each clicked point.


p_r

protected double[][] p_r
The array of right control points, one for each clicked point.


p_i

protected double[][] p_i
The array of interpolated points generated from p, p_l and p_r.


closed

protected boolean closed
Paint/behave as open or closed curve.

Constructor Detail

Profile

public Profile(Project project,
               java.lang.String title,
               double x,
               double y)
A new user-requested Profile.


Profile

public Profile(Project project,
               java.lang.String title,
               double x,
               double y,
               java.awt.geom.Point2D.Double[] points)
Construct a Bezier Profile object from a set of points mixed in this pattern: PCCPCCPCCPCCP , so, [PCC]n where P = backbone point and C = control point. This results from a BezierApproximation on a path of points as drawed with the mouse. Keep in mind the control points will NOT have the same tangents, but this may be either left like that or corrected with some smoothing algorithm.


Profile

public Profile(Project project,
               long id,
               java.lang.String title,
               float alpha,
               boolean visible,
               java.awt.Color color,
               double[][][] bezarr,
               boolean closed,
               boolean locked,
               java.awt.geom.AffineTransform at)
Construct a Bezier Profile from the database.


Profile

public Profile(Project project,
               long id,
               java.lang.String title,
               float width,
               float height,
               float alpha,
               boolean visible,
               java.awt.Color color,
               boolean closed,
               boolean locked,
               java.awt.geom.AffineTransform at)
Construct a Bezier Profile from the database, but the points will be loaded later, when actually needed, by calling setupForDisplay().


Profile

public Profile(Project project,
               long id,
               java.util.HashMap<java.lang.String,java.lang.String> ht,
               java.util.HashMap<Displayable,java.lang.String> ht_links)
Construct a Bezier Profile from an XML entry.

Method Detail

enlargeArrays

protected void enlargeArrays()
Increase the size of the arrays by 5 points.


getPointCount

public int getPointCount()
Returns the number of backbone points.


isClosed

public boolean isClosed()

findPoint

protected int findPoint(double[][] a,
                        double x_p,
                        double y_p,
                        double magnification)
Find a point in an array 'a', with a precision dependent on the magnification.


removePoint

protected void removePoint(int index)
Remove a point from the bezier backbone and its two associated control points.


distance

protected double distance(double x1,
                          double y1,
                          double x2,
                          double y2)
Calculate distance from one point to another.


dragPoint

protected void dragPoint(int index,
                         int dx,
                         int dy)
Move backbone point.


resetControlPoints

protected void resetControlPoints(int index)
Set the control points to the same value as the backbone point which they control.


dragControlPoint

protected void dragControlPoint(int index,
                                double x_d,
                                double y_d,
                                double[][] p_dragged,
                                double[][] p_adjusted,
                                boolean symmetric)
Drag a control point and adjust the other, dependent one, in a symmetric way or not.


addPoint

protected int addPoint(double x_p,
                       double y_p,
                       double magnification,
                       double bezier_finess)
Add a point either at the end or between two existing points, with accuracy depending on magnification. Does not update the database. x_p,y_p are in the local space.


findClosestPoint

protected int findClosestPoint(double x_p,
                               double y_p,
                               double magnification,
                               double bezier_finess)
Find the closest point to an interpolated point with precision depending upon magnification. The point x_p,y_p is in local coordinates.


toggleClosed

public void toggleClosed()
Toggle curve closed/open.


generateInterpolatedPoints

protected void generateInterpolatedPoints(double bezier_finess)

paint

public void paint(java.awt.Graphics2D g,
                  java.awt.Rectangle srcRect,
                  double magnification,
                  boolean active,
                  int channels,
                  Layer active_layer,
                  java.util.List<Layer> layers)
Specified by:
paint in interface Paintable
Overrides:
paint in class Displayable

mousePressed

public void mousePressed(java.awt.event.MouseEvent me,
                         Layer layer,
                         int x_p,
                         int y_p,
                         double mag)
Execute the mousePressed MouseEvent on this Profile.

Overrides:
mousePressed in class Displayable

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent me,
                         Layer layer,
                         int x_p,
                         int y_p,
                         int x_d,
                         int y_d,
                         int x_d_old,
                         int y_d_old)
Execute the mouseDragged MouseEvent on this Profile.

Overrides:
mouseDragged in class Displayable

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me,
                          Layer layer,
                          int x_p,
                          int y_p,
                          int x_d,
                          int y_d,
                          int x_r,
                          int y_r)
Execute the mouseReleased MouseEvent on this Profile.

Overrides:
mouseReleased in class Displayable

calculateBoundingBox

protected void calculateBoundingBox()

calculateBoundingBox

protected void calculateBoundingBox(boolean adjust_position)
Calculate the bounding box of the curve in the shape of a Rectangle defined by x,y,width,height. If adjust_position is true, then points are made local to the minimal x,y.


repaint

public void repaint()
Description copied from class: Displayable
Repaint this Displayable in all Display instances that are showing it.

Overrides:
repaint in class Displayable

repaint

public void repaint(boolean repaint_navigator)
Repaints in the given ImageCanvas only the area corresponding to the bounding box of this Profile.


containsPoint

public boolean containsPoint(int x_p,
                             int y_p)
Check if the given point (usually from a MOUSE_PRESSED MouseEvent) is contained within the boundaries of this object. The point is expected as local coordinates.


destroy

public void destroy()
Release all memory resources taken by this object.

Overrides:
destroy in class Displayable

cache

public void cache()
Cache this Profile if needed.


flush

public void flush()
Release memory resources used by this object: namely the arrays of points, which can be reloaded with a call to setupForDisplay()


getPerimeter

public java.awt.Polygon getPerimeter()
The perimeter of this profile, in integer precision.

Overrides:
getPerimeter in class Displayable

toShapesFile

public void toShapesFile(java.lang.StringBuffer data,
                         java.lang.String group,
                         java.lang.String color,
                         double z_scale)
Writes the data of this object as a Bezier object in the .shapes file represented by the 'data' StringBuffer. The z_scale is added to manually correct for sample squashing under the coverslip.


exportSVG

public void exportSVG(java.lang.StringBuffer data,
                      double z_scale,
                      java.lang.String indent)
Description copied from class: Displayable
Does nothing unless overriden.

Overrides:
exportSVG in class Displayable

getBezierArrays

public double[][][] getBezierArrays()
Returns a triple array, each containing a [2][n_points] array specifiying the x,y of each left control point, backbone point and right control point respectively. All of them are copies.


isDeletable

public boolean isDeletable()
Specified by:
isDeletable in class Displayable

isLinked

public boolean isLinked()
Returns true if it's linked to at least one patch in the same Layer. Otherwise returns false.

Overrides:
isLinked in class Displayable

canSendTo

public boolean canSendTo(Layer target_layer)
Returns false if the target_layer contains a profile that is directly linked to this profile.

Overrides:
canSendTo in class Displayable

getFirstPoint

protected double[][] getFirstPoint()

getLastPoint

protected double[][] getLastPoint()

hasPoints

public boolean hasPoints()

setPoints

protected void setPoints(double[][] p_l,
                         double[][] p,
                         double[][] p_r)

setPoints

public void setPoints(double[][] p_l,
                      double[][] p,
                      double[][] p_r,
                      boolean update)

addPointsAtBegin

protected void addPointsAtBegin(double[][] new_p_l,
                                double[][] new_p,
                                double[][] new_p_r)

addPointsAtEnd

protected void addPointsAtEnd(double[][] new_p_l,
                              double[][] new_p,
                              double[][] new_p_r)

getNearestPointIndex

public int getNearestPointIndex(double x_p,
                                double y_p)

insertBetween

public void insertBetween(int startIndex,
                          int endIndex,
                          double[][] tmp_p_l,
                          double[][] tmp_p,
                          double[][] tmp_p_r)

printPoints

public void printPoints()

snapTo

public void snapTo(int cx,
                   int cy,
                   int x_p,
                   int y_p)
x,y is the cursor position in offscreen coordinates.

Overrides:
snapTo in class Displayable

exportXML

public void exportXML(java.lang.StringBuilder sb_body,
                      java.lang.String indent,
                      java.lang.Object any)
Description copied from class: Displayable
The oid is this objects' id, whereas the 'id' tag will be the id of the wrapper Thing object.

Overrides:
exportXML in class Displayable

exportDTD

public static void exportDTD(java.lang.StringBuilder sb_header,
                             java.util.HashSet<java.lang.String> hs,
                             java.lang.String indent)

getPerimeter2D

public VectorString2D getPerimeter2D()
Returns the interpolated points as a VectorString2D, calibrated. Returns null if there aren't any points.


keyPressed

public void keyPressed(java.awt.event.KeyEvent ke)
Overrides:
keyPressed in class Displayable

setColor

public void setColor(java.awt.Color c)
Overrides:
setColor in class Displayable

clone

public Displayable clone(Project pr,
                         boolean copy_id)
Performs a deep copy of this object, unlocked and visible.

Specified by:
clone in class Displayable

generateTriangles

public static java.util.List<javax.vecmath.Point3f> generateTriangles(ProjectThing pt,
                                                                      double scale)
Takes a profile_list, scans for its Profile children, makes sublists of continuous profiles (if they happen to be branched), and then creates triangles for them using weighted vector strings.


softRemove

public boolean softRemove()
Does nothing.

Overrides:
softRemove in class Displayable

remove2

protected boolean remove2(boolean check)
Description copied from class: Displayable
Remove also from the trees if present; does nothing more than remove(boolean) unless overriden.

Overrides:
remove2 in class Displayable

computeLength

public double computeLength()
Calibrated for pixel width only (that is, it assumes pixel aspect ratio 1:1), in units as specified at getLayerSet().getCalibration().getUnit()


computeArea

public double computeArea()
Calibrated, in units as specified at getLayerSet().getCalibration().getUnit() -- returns zero if this profile is not closed.


measure

public ij.measure.ResultsTable measure(ij.measure.ResultsTable rt)
Measures the calibrated length, the lateral surface as the length times the layer thickness, and the volume (if closed) as the area times the layer thickness.

Overrides:
measure in class Displayable

measure

public static ij.measure.ResultsTable measure(Profile[] profiles,
                                              ij.measure.ResultsTable rt,
                                              long profile_list_id)
Assumes Z-coord sorted list of profiles, as stored in a "profile_list" ProjectThing type. .


apply

public boolean apply(Layer la,
                     java.awt.geom.Area roi,
                     mpicbg.models.CoordinateTransform ict)
              throws java.lang.Exception
Description copied from interface: VectorData
Applies the 2D transform @ict (which is expected to operate on the world coordinates version of the data contained here) only to the data that falls within the @param roi (in world coords), and then recomputes the bounding box and affine transform (to a translation or identity). Does not consider links.

Specified by:
apply in interface VectorData
Parameters:
la - Only data at this Layer may be transformed.
roi - Only data inside this world-coordinates Area may be transformed.
ict - The transform to apply to the data that is in @param la and within @param roi.
Throws:
java.lang.Exception

apply

public boolean apply(VectorDataTransform vdt)
              throws java.lang.Exception
Specified by:
apply in interface VectorData
Throws:
java.lang.Exception

isRoughlyInside

public boolean isRoughlyInside(Layer layer,
                               java.awt.Rectangle r)
Description copied from class: Displayable
If this Displayable intersects with @param r or almost intersects, then returns true. This method is meant to be very fast, and err on the "yes" and never on the "no".

Overrides:
isRoughlyInside in class Displayable