ini.trakem2.display
Class Pipe

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

public class Pipe
extends ZDisplayable
implements Line3D, VectorData


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  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  long[] p_layer
          The array of Layers over which the points of this pipe live
protected  double[][] p_r
          The array of right control points, one for each clicked point.
protected  double[] p_width
          The width of each point.
protected  double[] p_width_i
          The interpolated width for each interpolated point.
 
Fields inherited from class ini.trakem2.display.ZDisplayable
layer_set
 
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
Pipe(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 Pipe from an XML entry.
Pipe(Project project, long id, java.lang.String title, float width, float height, float alpha, boolean visible, java.awt.Color color, boolean locked, java.awt.geom.AffineTransform at)
          Construct an unloaded Pipe from the database.
Pipe(Project project, java.lang.String title, double x, double y)
           
 
Method Summary
protected  int addPoint(int x_p, int y_p, double magnification, double bezier_finess, long layer_id)
          Add a point either at the end or between two existing points, with accuracy depending on magnification.
 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)
           
 VectorString3D asVectorString3D()
          Returns a non-calibrated VectorString3D.
protected  boolean calculateBoundingBox(boolean adjust_position, Layer la)
           
protected  boolean calculateBoundingBox(Layer la)
           
 Displayable clone(Project pr, boolean copy_id)
          Performs a deep copy of this object, without the links.
 boolean contains(Layer layer, int x, int y)
          Test whether the Pipe contains the given point at the given layer.
 boolean crop(java.util.List<Layer> range)
          Retain the data within the layer range, and through out all the rest.
 void destroy()
          Release all memory resources taken by this object.
static double distance(double x1, double y1, double x2, double y2)
          Calculate distance from one point to another.
protected  void dragControlPoint(int index, int x_d, int 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 by the given deltas.
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)
          Exports data, the tag is not opened nor closed.
protected  int findClosestPoint(int x_p, int 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, long[] p_layer, int x_p, int y_p, long lid, double magnification)
          Find a point in an array, 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)
           
 double[][][] generateMesh(double scale)
           
static java.util.List<javax.vecmath.Point3f> generateTriangles(double[][][] all_points, double scale)
          Accepts an arrays as that returned from methods generateJoints and makeTube: first dimension is the list of points, second dimension is the number of vertices defining the circular cross section of the tube, and third dimension is the x,y,z of each vertex.
 java.util.List<javax.vecmath.Point3f> generateTriangles(double scale, int parallels, int resample)
          Calibrated.
 java.awt.geom.Area getAreaAt(Layer layer)
          This area is meant to represent the entire area where a Displayable paints to in the @param layer.
 double[][] getBackbone()
          Returns a [p_i[0].length][4] array, with x,y,z,radius on the second part.
 java.awt.Rectangle getBounds(java.awt.Rectangle r, Layer layer)
          Returns the bounds of this object as it shows in the given layer, set into @param r.
 Layer getFirstLayer()
          Returns the layer of lowest Z coordinate where this ZDisplayable has a point in, or the creation layer if no points yet.
 java.lang.String getInfo()
          Returns id and project name; this method is meant to be overriden by any of the subclasses.
 java.util.Collection<java.lang.Long> getLayerIds()
          Get the list of Layer ids on which this ZDisplayable has data on.
 java.awt.Polygon getPerimeter()
          The exact perimeter of this pipe, in integer precision.
 java.lang.String[] getPointsForSQL()
          Return the list of query statements needed to insert all the points in the database.
 java.lang.String getUpdatePointForSQL(int index)
           
 boolean intersects(java.awt.geom.Area area, double z_first, double z_last)
           
 boolean intersects(Layer layer, java.awt.geom.Area area)
          Expects Area in world coords.
 boolean intersects(Layer layer, java.awt.Rectangle r)
          Expects Rectangle in world coords.
 boolean isDeletable()
           
 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)
           
protected  boolean layerRemoved(Layer la)
          Update internal datastructures to reflect the fact that @param layer has been removed from the containing LayerSet.
 int length()
          The number of clicked, backbone points in this pipe.
 boolean linkPatches()
          Scan the Display and link Patch objects that lay under this Pipe's bounding box.
static double[][][] makeTube(double[] px, double[] py, double[] pz, double[] p_width_i, int resample, int parallels, ij.measure.Calibration cal)
           
 ij.measure.ResultsTable measure(ij.measure.ResultsTable rt)
          Does nothing unless overriden.
 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)
           
 void mousePressed(java.awt.event.MouseEvent me, Layer layer, int x_p, int y_p, double mag)
           
 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)
           
 void paint(java.awt.Graphics2D g, java.awt.Rectangle srcRect, double magnification, boolean active, int channels, Layer active_layer, java.util.List<Layer> layers)
           
protected  void removePoint(int index)
          Remove a point from the bezier backbone and its two associated control points.
 void repaint(boolean repaint_navigator, Layer la)
          Repaints in the given ImageCanvas only the area corresponding to the bounding box of this Pipe.
protected  void resetControlPoints(int index)
          Set the control points to the same value as the backbone point which they control.
 void reverse()
          Reverses the order of the points in the arrays.
 void snapTo(int cx, int cy, int x_p, int y_p)
          x,y is the cursor position in offscreen coordinates.
 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 Pipe object in the .shapes file represented by the 'data' StringBuffer.
 
Methods inherited from class ini.trakem2.display.ZDisplayable
exportDTD, getBucketable, getLayerSet, paintsAt, remove, remove2, setColor, setLayer, setLayerSet, setLayerSet, setPosition, setVisible, softRemove, transformPoints, updateBucket, updateBucket
 
Methods inherited from class ini.trakem2.display.Displayable
adjustProperties, areThereLayerCrossLinks, canSendTo, clone, clone, commonDTDChildren, contains, deselect, displacePoints, findById, findNearestPoint, findNearestPoint, getAffineTransform, getAffineTransformCopy, getAlpha, getAnnotation, getArea, getAreaForBucket, getBoundingBox, getBoundingBox, getBoundingBox, getBounds, getColor, getComposite, getComposite, getCompositeMode, getHeight, getIntersection, getLayer, 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, inverseTransformPoint, isLinked, isLinked, isLinked, isLocked, isLocked2, isOnlyLinkedTo, isOnlyLinkedTo, isOutOfRepaintingClip, isOutOfRepaintingClip, isVisible, link, link, makeAdjustPropertiesDialog, mouseWheelMoved, paintAsBox, paintOffscreen, paintSnapshot, prePaint, preTransform, processAdjustPropertiesDialog, removeLinkedProperties, removeLinkedPropertiesFromOrigins, repaint, restXML, rotate, rotate, rotatePoints, scale, scale, scalePoints, setAffineTransform, setAlpha, setAlpha, setAnnotation, setCompositeMode, setDimensions, setDimensions, setLayer, setLinkedProperties, setLinkedProperty, setLocation, setLocked, setProperty, setTitle, setVisible, toString, transform, transformPoint, transformPoint, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformRectangle, translate, translate, unlink, unlink, unlinkAll, updateInDatabase, xmlError, xmlError
 
Methods inherited from class ini.trakem2.persistence.DBObject
addToDatabase, getId, getProject, getUniqueIdentifier, removeFromDatabase, updateInDatabase
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ini.trakem2.display.Line3D
getColor, getId, getLayerSet, getProject, toString
 

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.


p_layer

protected long[] p_layer
The array of Layers over which the points of this pipe live


p_width

protected double[] p_width
The width of each point.


p_width_i

protected double[] p_width_i
The interpolated width for each interpolated point.

Constructor Detail

Pipe

public Pipe(Project project,
            java.lang.String title,
            double x,
            double y)

Pipe

public Pipe(Project project,
            long id,
            java.lang.String title,
            float width,
            float height,
            float alpha,
            boolean visible,
            java.awt.Color color,
            boolean locked,
            java.awt.geom.AffineTransform at)
Construct an unloaded Pipe from the database. Points will be loaded later, when needed.


Pipe

public Pipe(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 Pipe from an XML entry.

Method Detail

findPoint

protected int findPoint(double[][] a,
                        long[] p_layer,
                        int x_p,
                        int y_p,
                        long lid,
                        double magnification)
Find a point in an array, with a precision dependent on the magnification. Only points in the current layer are found, the rest are ignored. Returns -1 if none found.


removePoint

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


distance

public static 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 by the given deltas.


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,
                                int x_d,
                                int 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(int x_p,
                       int y_p,
                       double magnification,
                       double bezier_finess,
                       long layer_id)
Add a point either at the end or between two existing points, with accuracy depending on magnification. The width of the new point is that of the closest point after which it is inserted.


findClosestPoint

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


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

keyPressed

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

mousePressed

public void mousePressed(java.awt.event.MouseEvent me,
                         Layer layer,
                         int x_p,
                         int y_p,
                         double mag)
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)
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)
Overrides:
mouseReleased in class Displayable

calculateBoundingBox

protected boolean calculateBoundingBox(Layer la)
Specified by:
calculateBoundingBox in class ZDisplayable

calculateBoundingBox

protected boolean calculateBoundingBox(boolean adjust_position,
                                       Layer la)

destroy

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

Overrides:
destroy in class Displayable

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()


repaint

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


getPerimeter

public java.awt.Polygon getPerimeter()
The exact perimeter of this pipe, 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 Pipe object in the .shapes file represented by the 'data' StringBuffer.


getPointsForSQL

public java.lang.String[] getPointsForSQL()
Return the list of query statements needed to insert all the points in the database.


getUpdatePointForSQL

public java.lang.String getUpdatePointForSQL(int index)

isDeletable

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

length

public int length()
The number of clicked, backbone points in this pipe.

Specified by:
length in interface Line3D

contains

public boolean contains(Layer layer,
                        int x,
                        int y)
Test whether the Pipe contains the given point at the given layer. What it does: generates subpolygons that are present in the given layer, and tests whether the point is contained in any of them.

Overrides:
contains in class Displayable

linkPatches

public boolean linkPatches()
Scan the Display and link Patch objects that lay under this Pipe's bounding box.

Specified by:
linkPatches in class ZDisplayable
Returns:
whether the locking state changed.

getFirstLayer

public Layer getFirstLayer()
Returns the layer of lowest Z coordinate where this ZDisplayable has a point in, or the creation layer if no points yet.

Specified by:
getFirstLayer in class ZDisplayable

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

getBackbone

public double[][] getBackbone()
Returns a [p_i[0].length][4] array, with x,y,z,radius on the second part. Not translated to x,y but local!


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)
Exports data, the tag is not opened nor closed.

Overrides:
exportXML in class ZDisplayable

exportDTD

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

generateMesh

public double[][][] generateMesh(double scale)

clone

public Displayable clone(Project pr,
                         boolean copy_id)
Performs a deep copy of this object, without the links.

Specified by:
clone in class Displayable

generateTriangles

public java.util.List<javax.vecmath.Point3f> generateTriangles(double scale,
                                                               int parallels,
                                                               int resample)
Calibrated.

Specified by:
generateTriangles in interface Line3D

generateTriangles

public static java.util.List<javax.vecmath.Point3f> generateTriangles(double[][][] all_points,
                                                                      double scale)
Accepts an arrays as that returned from methods generateJoints and makeTube: first dimension is the list of points, second dimension is the number of vertices defining the circular cross section of the tube, and third dimension is the x,y,z of each vertex.


makeTube

public static double[][][] makeTube(double[] px,
                                    double[] py,
                                    double[] pz,
                                    double[] p_width_i,
                                    int resample,
                                    int parallels,
                                    ij.measure.Calibration cal)

asVectorString3D

public VectorString3D asVectorString3D()
Returns a non-calibrated VectorString3D.

Specified by:
asVectorString3D in interface Line3D

getInfo

public java.lang.String getInfo()
Description copied from class: DBObject
Returns id and project name; this method is meant to be overriden by any of the subclasses.

Overrides:
getInfo in class DBObject

intersects

public boolean intersects(java.awt.geom.Area area,
                          double z_first,
                          double z_last)
Specified by:
intersects in class ZDisplayable
Parameters:
area - is expected in world coordinates.

intersects

public boolean intersects(Layer layer,
                          java.awt.Rectangle r)
Expects Rectangle in world coords.

Overrides:
intersects in class Displayable

intersects

public boolean intersects(Layer layer,
                          java.awt.geom.Area area)
Expects Area in world coords.

Overrides:
intersects in class Displayable

getBounds

public java.awt.Rectangle getBounds(java.awt.Rectangle r,
                                    Layer layer)
Returns the bounds of this object as it shows in the given layer, set into @param r.

Overrides:
getBounds in class Displayable

measure

public ij.measure.ResultsTable measure(ij.measure.ResultsTable rt)
Description copied from class: Displayable
Does nothing unless overriden.

Overrides:
measure in class Displayable

reverse

public void reverse()
Reverses the order of the points in the arrays.


crop

public boolean crop(java.util.List<Layer> range)
Retain the data within the layer range, and through out all the rest.

Overrides:
crop in class ZDisplayable

layerRemoved

protected boolean layerRemoved(Layer la)
Description copied from class: ZDisplayable
Update internal datastructures to reflect the fact that @param layer has been removed from the containing LayerSet.

Overrides:
layerRemoved in class ZDisplayable

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

getLayerIds

public java.util.Collection<java.lang.Long> getLayerIds()
Description copied from class: ZDisplayable
Get the list of Layer ids on which this ZDisplayable has data on.

Overrides:
getLayerIds in class ZDisplayable

getAreaAt

public java.awt.geom.Area getAreaAt(Layer layer)
Description copied from class: Displayable
This area is meant to represent the entire area where a Displayable paints to in the @param layer. But for some this is reduced to areas with data, not with interpolated data. For example, a Polyine would show a list of little 1x1 rectangles for each point in the @param layer.

Overrides:
getAreaAt in class Displayable

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