Package base.drawable

Examples of base.drawable.CategoryWeight


    public void mergeWithShadow( final Shadow  shade )
    {
        Category          sobj_type;
        CategoryWeightF   this_twgf;
        CategoryWeight    sobj_twgt;
        CategoryWeight[]  sobj_twgts;
        double            overlap_duration;
        float             box_overlap_ratio;
        double            sobj_overlap_ratio;
        double            ave_num_real_objs;
        int               idx;

        overlap_duration   = super.getIntersectionDuration( shade );
        box_overlap_ratio  = (float) (overlap_duration / box_duration);
        sobj_overlap_ratio = overlap_duration / shade.getDuration();
        ave_num_real_objs  = sobj_overlap_ratio * shade.getNumOfRealObjects();

        sobj_twgts = shade.arrayOfCategoryWeights();
        for ( idx = sobj_twgts.length-1 ; idx >= 0 ; idx-- ) {
            sobj_twgt = sobj_twgts[ idx ];
            sobj_type = sobj_twgt.getCategory();
            this_twgf = (CategoryWeightF) map_type2twgf.get( sobj_type );
            if ( this_twgf == null ) {
                // sobj_twgt's clone + rescaling ratios & num_real_objs
                this_twgf = new CategoryWeightF( sobj_twgt );
                this_twgf.rescaleAllRatios( box_overlap_ratio );
                this_twgf.rescaleDrawableCount( sobj_overlap_ratio );
                map_type2twgf.put( sobj_type, this_twgf );
            }
            else {
                this_twgf.addDrawableCount( sobj_overlap_ratio
                                          * sobj_twgt.getDrawableCount() );
                this_twgf.addAllRatios( sobj_twgt, box_overlap_ratio );
            }
        }
        num_real_objs += ave_num_real_objs;

View Full Code Here


        int iRange  = iFinal-iStart+1// width uncut by image border
        int iWidth  = iTail-iHead+1;    // width possibly cut by the image
        int jHeight = jTail-jHead+1;

        CategoryWeight[]  twgts;
        CategoryWeight    twgt = null;
        int               idx, twgts_length;
        float             tot_wgt, height_per_wgt;
        int               iLevel, iDelta, iCenter;
        int               jLevel, jDelta, jCenter;
        int               jDeltaTotal;
        boolean           isInclusive;

        jDeltaTotal  = 0;
        twgts        = shade.arrayOfCategoryWeights();
        twgts_length = twgts.length;
        if (    DisplayType == CUMULATIVE_INCLUSION_ID
             || DisplayType == CUMULATIVE_EXCLUSION_ID
             || DisplayType == CUMULATIVE_EXCLUSION_BASE_ID ) {
            isInclusive = ( DisplayType == CUMULATIVE_INCLUSION_ID );
            if ( isInclusive ) {
                Arrays.sort( twgts, CategoryWeight.INCL_RATIO_ORDER );
                // Compute the pixel height per unit weight
                tot_wgt = 0.0f;
                for ( idx = 0; idx < twgts_length; idx++ ) {
                    twgt = twgts[ idx ];
                    if ( twgt.getCategory().isVisible() )
                        tot_wgt += twgt.getRatio( isInclusive );
                }
                height_per_wgt = (float) jHeight / tot_wgt;
            }
            else {
                Arrays.sort( twgts, CategoryWeight.EXCL_RATIO_ORDER );
                height_per_wgt = jHeight;
            }

            // set sub-rectangles' height from the bottom, ie. jHead+jTail
            jLevel = jHead + jHeight;  // jLevel = jTail + 1
            for ( idx = twgts_length-1; idx >= 0; idx-- ) {
                twgt = twgts[ idx ];
                if ( twgt.getCategory().isVisible() ) {
                    jDelta = (int) ( height_per_wgt
                                   * twgt.getRatio( isInclusive ) + 0.5f );
                    if ( jDelta > 0 ) {
                        if ( jLevel > jHead ) {
                            if ( jLevel-jDelta >= jHead ) {
                                jLevel  -= jDelta;
                                twgt.setPixelHeight( jDelta );
                            }
                            else {
                                twgt.setPixelHeight( jLevel - jHead );
                                jLevel = jHead;
                            }
                        }
                        else
                            twgt.setPixelHeight( 0 );
                    }
                    else
                        twgt.setPixelHeight( 0 );
                }
                else
                    twgt.setPixelHeight( 0 );
                jDeltaTotal += twgt.getPixelHeight();
            }
            shade.setTotalPixelHeight( jDeltaTotal )// for isPixelIn()
        }
        else if (    DisplayType == OVERLAP_INCLUSION_ID
                  || DisplayType == OVERLAP_EXCLUSION_ID ) {
            isInclusive = ( DisplayType == OVERLAP_INCLUSION_ID );
            if ( isInclusive )
                Arrays.sort( twgts, CategoryWeight.INCL_RATIO_ORDER );
            else
                Arrays.sort( twgts, CategoryWeight.EXCL_RATIO_ORDER );
            jLevel = Integer.MAX_VALUE; // JLevel should be named as JDelta_prev
            iDelta = iRange;
            for ( idx = twgts_length-1; idx >= 0; idx-- ) {
                twgt = twgts[ idx ];
                if ( twgt.getCategory().isVisible() ) {
                    jDelta = (int) ( twgt.getRatio( isInclusive ) * jHeight
                                   + 0.5f );
                    twgt.setPixelHeight( jDelta );
                    if ( jDelta >= jLevel )
                        iDelta -= MinCategorySeparation;
                    twgt.setPixelWidth( iDelta );
                    jLevel = jDelta;
                }
                else
                    twgt.setPixelHeight( 0 );
            }
        }
        else { // if ( DisplayType == FIT_MOST_LEGENDS_ID )
            Arrays.sort( twgts, CategoryWeight.INCL_RATIO_ORDER );
            int num_visible_twgts = 0;
            for ( idx = 0; idx < twgts_length; idx++ ) {
                if ( twgts[ idx ].getCategory().isVisible() )
                    num_visible_twgts++;
            }
            jDelta = (int) ( (float) jHeight / num_visible_twgts );
            if ( jDelta < MinCategoryHeight )
                jDelta = MinCategoryHeight;
            // set sub-rectangles' height from the bottom, ie. jHead+jTail
            jLevel = jHead + jHeight;  // jLevel = jTail + 1
            for ( idx = twgts_length-1; idx >= 0; idx-- ) {
                twgt = twgts[ idx ];
                if ( twgt.getCategory().isVisible() ) {
                    if ( jLevel > jHead ) {
                        if ( jLevel-jDelta >= jHead ) {
                            jLevel  -= jDelta;
                            twgt.setPixelHeight( jDelta );
                        }
                        else {
                            twgt.setPixelHeight( jLevel - jHead );
                            jLevel = jHead;
                        }
                    }
                    else
                        twgt.setPixelHeight( 0 );
                }
                else
                    twgt.setPixelHeight( 0 );
            }
        }

        // Fill the color of the sub-rectangles from the bottom, ie. jHead+jTail
        int num_sub_rects_drawn = 0;
        if (    DisplayType == OVERLAP_INCLUSION_ID
             || DisplayType == OVERLAP_EXCLUSION_ID ) {
            // iBoxXXXX : variables that twgt isn't cut by image border
            int iBoxHead, iBoxTail, iBoxWidth;
            jCenter = jHead  + jHeight / 2; // i.e. jCenter % jHead & jTail
            iCenter = iStart + iRange / 2// i.e. iCenter % iStart & iFinal
            for ( idx = twgts_length-1; idx >= 0; idx-- ) {
                twgt       = twgts[ idx ];
                jDelta     = twgt.getPixelHeight();
                iBoxWidth  = twgt.getPixelWidth();
                if ( jDelta > 0 && iBoxWidth > 0 ) {
                    iBoxHead = iCenter - iBoxWidth / 2;
                    iBoxTail = iBoxHead + iBoxWidth;
                    iLevel   = ( iBoxHead >= 0 ? iBoxHead : 0 );
                    iDelta   = ( iBoxTail < iImageWidth ?
                                 iBoxTail : iImageWidth ) - iLevel;
                    g.setColor( twgt.getCategory().getColor() );
                    g.fillRect( iLevel, jCenter-jDelta/2, iDelta, jDelta );
                    num_sub_rects_drawn++;
                }
            }
        }
        else {
            /*
            if (    DisplayType == FIT_MOST_LEGENDS_ID )
                 || DisplayType == CUMULATIVE_INCLUSION_ID
                 || DisplayType == CUMULATIVE_EXCLUSION_ID
                 || DisplayType == CUMULATIVE_EXCLUSION_BASE_ID )
            */
            jLevel = jHead + jHeight;  // jLevel = jTail + 1
            if ( DisplayType == CUMULATIVE_EXCLUSION_ID )
                jLevel -= ( jHeight - jDeltaTotal ) / 2;
            for ( idx = twgts_length-1; idx >= 0; idx-- ) {
                twgt     = twgts[ idx ];
                jDelta   = twgt.getPixelHeight();
                if ( jDelta > 0 ) {
                    jLevel  -= jDelta;
                    g.setColor( twgt.getCategory().getColor() );
                    g.fillRect( iHead, jLevel, iWidth, jDelta );
                    num_sub_rects_drawn++;
                }
            }
        }
View Full Code Here

            strbuf.append( "\n" );
   
            StringBuffer      linebuf;
            Topology          shade_topo;
            CategoryWeight[]  twgts;
            CategoryWeight    twgt;
            String            twgt_str;
            int               print_status;
            int               idx;

            shade_topo  = shade.getCategory().getTopology();

            // linebuf = new StringBuffer( "Number of Real Drawables = " );
            linebuf = new StringBuffer( "Number of Real " );
            linebuf.append( shade_topo + "s = " );
            linebuf.append( shade.getNumOfRealObjects() );
            if ( num_cols < linebuf.length() )
                num_cols = linebuf.length();
            num_rows++;
            strbuf.append( "\n" + linebuf.toString() );
            strbuf.append( "\n" );
   
            print_status = getPrintStatus( shade_topo );
            strbuf.append( "\n" + CategoryWeight.getPrintTitle(print_status) );
            twgts = shade.arrayOfCategoryWeights();
            for ( idx = 0; idx < twgts.length; idx++ ) {
                twgt     = twgts[ idx ];
                twgt_str = twgt.toInfoBoxString( print_status );
                if ( twgt.getCategory().equals( type ) ) {
                    twgt_str += "  <---";
                    if ( num_cols < twgt_str.length() + 6 )
                        num_cols = twgt_str.length() + 6;
                }
                else {
View Full Code Here

        jHead    = jStart;
        jTail    = jFinal;
        jHeight  = jTail-jHead+1;

        CategoryWeight[]  twgts;
        CategoryWeight    twgt = null;
        int               idx, twgts_length;

        twgts        = shade.arrayOfCategoryWeights();
        twgts_length = twgts.length;

        // Locate the sub-rectangle from the bottom, ie. jHead+jTail
        int iLevel, iDelta, iCenter;
        int jLevel, jDelta, jCenter;
        if (    DisplayType == OVERLAP_INCLUSION_ID
             || DisplayType == OVERLAP_EXCLUSION_ID ) {
            int iImageWidth, iRange;
            // iBoxXXXX : variables that twgt isn't cut by image border
            int iBoxHead, iBoxTail, iBoxWidth;
            iImageWidth = coord_xform.getImageWidth();
            iRange      = iFinal - iStart + 1; // width uncut by image border
            jCenter     = jHead  + jHeight / 2;// i.e. jCenter % jHead & jTail
            iCenter     = iStart + iRange / 2; // i.e. iCenter % iStart & iFinal
            for ( idx = 0; idx < twgts_length; idx++ ) {
                twgt      = twgts[ idx ];
                jDelta    = twgt.getPixelHeight();
                iBoxWidth = twgt.getPixelWidth();
                if ( jDelta > 0 && iBoxWidth > 0 ) {
                    jLevel = jCenter - jDelta / 2;
                    if ( pt_y >= jLevel && pt_y < jLevel+jDelta ) {
                        iBoxHead = iCenter - iBoxWidth / 2;
                        iBoxTail = iBoxHead + iBoxWidth;
                        iLevel   = ( iBoxHead >= 0 ? iBoxHead : 0 );
                        iDelta   = ( iBoxTail < iImageWidth ?
                                     iBoxTail : iImageWidth ) - iLevel;
                        if ( pt_x >= iLevel && pt_x < iLevel+iDelta )
                            return twgt.getCategory();
                    }
                }
            }
        }
        else {
            /*
            if (    DisplayType == FIT_MOST_LEGENDS_ID
                 || DisplayType == CUMULATIVE_INCLUSION_ID
                 || DisplayType == CUMULATIVE_EXCLUSION_ID
                 || DisplayType == CUMULATIVE_EXCLUSION_BASE_ID )
            */
            jLevel = jHead + jHeight;  // jLevel = jTail + 1
            if ( DisplayType == CUMULATIVE_EXCLUSION_ID )
                jLevel -= ( jHeight - shade.getTotalPixelHeight() ) / 2;
            for ( idx = twgts_length-1; idx >= 0; idx-- ) {
                twgt     = twgts[ idx ];
                jDelta   = twgt.getPixelHeight();
                if ( jDelta > 0 ) {
                    jLevel  -= jDelta;
                    if ( pt_y >= jLevel && pt_y < jLevel+jDelta )
                        return twgt.getCategory();
                }
            }
        }

        return null; // mean failure, need something other than null
View Full Code Here

TOP

Related Classes of base.drawable.CategoryWeight

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.