//----------------------------------------------------------------------------//
//                                                                            //
//                             I c o n G l y p h                              //
//                                                                            //
//  Copyright (C) Herve Bitteur 2000-2006. All rights reserved.               //
//  This software is released under the terms of the GNU General Public       //
//  License. Please contact the author at herve.bitteur@laposte.net           //
//  to report bugs & suggestions.                                             //
//----------------------------------------------------------------------------//
//
package omr.glyph;

import omr.lag.JunctionAllPolicy;
import omr.lag.LagBuilder;
import omr.lag.VerticalOrientation;

import omr.score.PagePoint;
import omr.score.ScoreConstants;

import omr.sheet.Picture;
import omr.sheet.PixelPoint;
import omr.sheet.Scale;

import omr.ui.icon.SymbolIcon;

import java.awt.Rectangle;

/**
 * Class <code>IconGlyph</code> is an articial glyph, built from an icon. It is
 * used to generate glyphs for training, when no real glyph (glyph retrieved
 * from scanned sheet) is available.
 *
 * @author Herv&eacute; Bitteur
 * @version $Id$
 */
public class IconGlyph
    extends Glyph
{
    //~ Instance fields --------------------------------------------------------

    /** The underlying icon */
    private SymbolIcon icon;

    //~ Constructors -----------------------------------------------------------

    //-----------//
    // IconGlyph //
    //-----------//
    /**
     * Build an (artificial) glyph out of a symbol icon. This construction is
     * meant to populate and train on glyph shapes for which we have no real
     * instance yet.
     *
     * @param icon the appearance of the glyph
     * @param shape the corresponding shape
     */
    public IconGlyph (SymbolIcon icon,
                      Shape      shape)
    {
        try {
            // Build a picture
            Picture  picture = new Picture(icon.getImage(), 2.0f);

            // Build related vertical lag
            GlyphLag vLag = new GlyphLag(new VerticalOrientation());
            vLag.setName("iconLag");
            vLag.setVertexClass(GlyphSection.class);
            new LagBuilder<GlyphLag, GlyphSection>().rip(
                vLag,
                picture,
                0, // minRunLength
                new JunctionAllPolicy()); // catch all

            // Retrieve the whole glyph made of all sections
            setLag(vLag);

            for (GlyphSection section : vLag.getSections()) {
                addSection(section, /* link => */
                           true);
            }

            //vLag.dump("Icon Lag");
            //glyph.drawAscii();

            // Glyph features
            setShape(shape);

            // Ordinate (approximate value)
            Rectangle box = getContourBox();
            int       y = box.y;

            // Staff interline value
            setInterline(2 * ScoreConstants.INTER_LINE);

            // Mass center
            PixelPoint centroid = getCentroid();
            Scale      scale = new Scale(2 * ScoreConstants.INTER_LINE, 1);
            PagePoint  pgCentroid = scale.toPagePoint(centroid);

            // Number of connected stems
            setStemNumber(icon.getStemNumber());

            // Has a related ledger ?
            setHasLedger(icon.hasLedger());

            // Vertical position wrt staff
            setPitchPosition(icon.getPitchPosition());

            //glyph.dump();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    //~ Methods ----------------------------------------------------------------

    //---------//
    // setIcon //
    //---------//
    /**
     * Assign the related icon
     *
     * @param val the icon
     */
    public void setIcon (SymbolIcon val)
    {
        this.icon = val;
    }

    //---------//
    // getIcon //
    //---------//
    /**
     * Report the related icon
     *
     * @return the icon
     */
    public SymbolIcon getIcon ()
    {
        return icon;
    }
}

@@ -745,16 +745,80 @@
 glyph;%0A%0A
+import omr.constant.Constant;%0Aimport omr.constant.ConstantSet;%0A%0A
 import o
@@ -1077,24 +1077,49 @@
 ymbolIcon;%0A%0A
+import omr.util.Logger;%0A%0A
 import java.
@@ -1431,16 +1431,466 @@
 Glyph%0A%7B%0A
+    //~ Static fields/initializers ---------------------------------------------%0A%0A    private static final Constants constants = new Constants();%0A    private static final Logger    logger = Logger.getLogger(IconGlyph.class);%0A%0A    /**%0A     * Reduction of icon image versus normal glyph size. The ascii descriptions%0A     * are half the size of their real glyph equivalent, so reduction is 2%0A     */%0A    private static final double descReduction = 2f;%0A%0A
     //~ 
@@ -2555,16 +2555,91 @@
   try %7B%0A
+            final int displayFactor = constants.displayFactor.getValue();%0A%0A
         
@@ -2726,11 +2726,25 @@
 ), 2
-.0f
+f * displayFactor
 );%0A%0A
@@ -3696,20 +3696,21 @@
     
-setI
+int i
 nterline
 (2 *
@@ -3705,18 +3705,32 @@
 nterline
-(2
+ = displayFactor
  * Score
@@ -3749,16 +3749,52 @@
 TER_LINE
+;%0A            setInterline(interline
 );%0A%0A    
@@ -3910,37 +3910,17 @@
 ale(
-2 * ScoreConstants.INTER_LINE
+interline
 , 1)
@@ -4276,23 +4276,75 @@
     
-//glyph.dump();
+if (logger.isFineEnabled()) %7B%0A                dump();%0A            %7D
 %0A   
@@ -4917,11 +4917,584 @@
 n;%0A    %7D
+%0A%0A    //~ Inner Classes ----------------------------------------------------------%0A%0A    //-----------//%0A    // Constants //%0A    //-----------//%0A    private static class Constants%0A        extends ConstantSet%0A    %7B%0A        /** This ratio has no impact on glyph moments, it is meant only for%0A            display of the icon glyph in utilities such as the GlyphVerifier */%0A        Constant.Integer displayFactor = new Constant.Integer(%0A            4,%0A            %22Scaling factor for IconGlyph display%22);%0A%0A        Constants ()%0A        %7B%0A            initialize();%0A        %7D%0A    %7D
 %0A%7D%0A

Clarified the need for ratio of description size / interline