001    package util.wavelet;
002    import java.util.List;
003    
004    /**  A relationship between two {@link Structure} instances in adjacent scales.
005     * It is a specific procedure and condition which defines a one-way relationship between a
006     * child {@link Structure} at wavelet scale j
007     * and an adjacent parent {@link Structure} at the next higher wavelet scale j+1.
008     * The default relationship is to consider the child to be connected to the parent
009     * if the maximum wavelet coefficient of the child intersects the parent.
010     *
011     * @author John Talbot
012     */
013    public class InterscaleRelationship {
014        
015        /** Child structure at scale j */
016        Structure child;
017    
018        /** Parent structure at scale j+1 which satisfies the interscale relationship
019         * with child structure at scale j. */    
020        Structure parent;
021        
022        /** True if child structure is local maximum. */
023        public boolean childLocalMaximum;
024       
025        /** 
026         * Construct the relationship between a parent structure and a child structure.
027         * Pre-condition: isRelated(child, parent) must be true.
028         *
029         * @param   child   structure at scale j
030         * @param   parent  structure at scale j+1
031         */
032        public InterscaleRelationship(Structure child, Structure parent) {
033            this.child  = child;
034            this.parent = parent;
035            
036            child.setParent(parent);
037            parent.addChild(child);
038           
039            Structure overlap = child.getOverlap(parent);
040            this.childLocalMaximum = (overlap != null && child.getMaximumValue() > overlap.getMaximumValue());
041        }
042       
043        /** 
044         * Is child structure at scale number j related to the parent structure in scale number j+1.
045         * False if parent scale number isn't j+1.
046         *
047         * @param   child   structure at scale j
048         * @param   parent  structure at scale j+1
049         * @return  true if child structure is related to parent structure
050         */
051        public static boolean isRelated(Structure child, Structure parent) {
052            return parent.contains(child.getPositionOfMaximum()) && (parent.getScaleNumber() - child.getScaleNumber()) == 1;
053        }
054    
055        /** 
056         * Is maximum wavelet coefficient in child structure greater than the maximum wavelet coefficient in the
057         * overlap with parent structure.
058         *
059         * @return   true if child structure at scale j is the local maximum relative to the parent structure at scale j+1.
060         */
061        public boolean isChildLocalMaximum() {
062            return childLocalMaximum;
063        }
064    
065        /** 
066         * Get child structure at scale j which satisfies the interscale relationship
067         * with parent structure at scale j+1.
068         *
069         * @return the child structure
070         */
071        public Structure getChild() {
072            return child;
073        }
074    
075        /** 
076         * Get parent structure at scale j+1 which satisfies the interscale relationship
077         * with child structure at scale j.
078         *
079         * @return   the parent structure
080         */   
081        public Structure getParent() {
082            return parent;
083        }
084    
085    }