IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 14, 2009, 3:58:07 PM (17 years ago)
Author:
Paul Price
Message:

Fix streaksremove so that output CMF files have PHU called ext.hdr and table called ext.psf. Turned on -Wall -Werror and fixed a host of little problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/remove/src/Line.c

    r25001 r25082  
    3636    // If the current line is not vertical, check to see if the point
    3737    // is inside the two endpoints independent of direction
    38    
     38
    3939    if (line->begin.x != line->end.x)
    4040    {
     
    5959    ux = line->end.x - line->begin.x;
    6060    uy = line->end.y - line->begin.y;
    61    
     61
    6262    vx = x - line->begin.x;
    6363    vy = y - line->begin.y;
    64    
     64
    6565    double u_u = ux * ux + uy * uy;                         // (u . u)
    6666    double u_v = ux * vx + uy * vy;                         // (u . v)
    67    
     67
    6868    if (u_v <= 0) return vx * vx + vy * vy;                 // (v . v)
    6969    if (u_u <= u_v)
     
    7373        return wx * wx + wy * wy;                           // (w . w)
    7474    }
    75    
     75
    7676    // Compute P(b) is the base of the perpendicular dropped from tuple to
    7777    // the line
    78    
     78
    7979    b = u_v / u_u;
    8080    px = vx - b * ux;
     
    109109    double wx  = first->begin.x - second->begin.x;
    110110    double wy  = first->begin.y - second->begin.y;
    111    
     111
    112112    // Calculate the perpendicular product, dt
    113    
     113
    114114    double dt = dx1 * dy2 - dy1 * dx2;
    115    
     115
    116116    // Are the lines parallel?
    117    
     117
    118118    if (fabs (dt) <= 1e-8)
    119119    {
    120120        // Check to see if they are overlap
    121        
     121
    122122        if (dx1 * wy - dy1 * wx != 0 || dx2 * wy - dy2 * wx != 0) return 0;
    123        
     123
    124124        // The line are coplanar, so check to see if they are degenerate
    125        
     125
    126126        len1 = dx1 * dx1 + dy1 * dy1;
    127127        len2 = dx2 * dx2 + dy2 * dy2;
    128        
     128
    129129        // First, check to see if both lines are points and if they are
    130130        // distinct tuples
    131        
     131
    132132        if (len1 == 0 && len2 == 0)
    133133        {
     
    137137            return 1;
    138138        }
    139        
     139
    140140        // Check to see if the first line is a point and is inside the
    141141        // second line
    142        
     142
    143143        if (len1 == 0)
    144144        {
     
    148148                return 0;
    149149        }
    150        
     150
    151151        // Check to see if the second line is a point and is inside the
    152152        // first line
    153        
     153
    154154        if (len2 == 0)
    155155        {
     
    159159                return 0;
    160160        }
    161        
     161
    162162        // Since both lines are coplanar and have length, search for
    163163        // overlap tuples
    164        
     164
    165165        w2x = first->end.x - second->begin.x;
    166166        w2y = first->end.y - second->begin.y;
    167        
     167
    168168        t0 = (dx2 != 0) ? wx  / dx2 : wy  / dy2;
    169169        t1 = (dx2 != 0) ? w2x / dx2 : w2y / dy2;
    170        
     170
    171171        if (t0 > t1) SwapDouble (&t0, &t1);
    172172        if ((inFirstSegment || inSecondSegment) && (t0 > 1 || t1 < 0))
     
    176176        t0 = (t0 < 0) ? 0 : t0;             // Clip to min 0
    177177        t1 = (t1 > 1) ? 1 : t1;             // Clip to max 1
    178        
     178
    179179        // Set the first tuple of intersection
    180        
     180
    181181        tuple1->x = second->begin.x + t0 * dx2;
    182182        tuple1->y = second->begin.y + t0 * dy2;
    183        
     183
    184184        // Check to see if the intersection is a single tuple
    185        
     185
    186186        if (t0 == t1) return 1;
    187        
     187
    188188        // Otherwise, set the second tuple of intersection as well
    189        
     189
    190190        tuple2->x = second->begin.x + t1 * dx2;
    191191        tuple2->y = second->begin.y + t1 * dy2;
    192192        return 2;
    193193    }
    194    
     194
    195195    // The segments are skew and may intersect in a tuple.
    196196    // Get the intersect parameter for the first line
    197    
     197
    198198    double i1 = (dx2 * wy - dy2 * wx) / dt;
    199199    if (inFirstSegment && (i1 < 0 || i1 > 1)) return 0;
    200    
     200
    201201    // Get the intersect parameter for the second line
    202202
     
    226226    vertices[3].x = 0;       vertices[3].y = numRows;
    227227
     228    clipLine.begin.x = 0;
     229    clipLine.begin.y = 0;
     230    clipLine.end.x = 0;
     231    clipLine.end.y = 0;
     232
    228233    for (i = 0; i < 4 && found < 2; ++i)
    229234    {
     
    237242                ++found;
    238243            }
    239             else if (tuple1.x != clipLine.begin.x || 
     244            else if (tuple1.x != clipLine.begin.x ||
    240245                     tuple1.y != clipLine.begin.y)
    241246            {
     
    245250        }
    246251    }
    247    
     252
    248253    // If two endpoints are found, clip the line
    249    
     254
    250255    if (found > 1)
    251256    {
     
    283288    vertices[3].x = minX; vertices[3].y = maxY;
    284289
     290    clipLine.begin.x = 0;
     291    clipLine.begin.y = 0;
     292    clipLine.end.x = 0;
     293    clipLine.end.y = 0;
     294
    285295    for (i = 0; i < 4 && found < 2; ++i)
    286296    {
     
    294304                ++found;
    295305            }
    296             else if (tuple1.x != clipLine.begin.x || 
     306            else if (tuple1.x != clipLine.begin.x ||
    297307                     tuple1.y != clipLine.begin.y)
    298308            {
     
    302312        }
    303313    }
    304    
     314
    305315    // If two endpoints are found, clip the line
    306    
     316
    307317    if (found > 1)
    308318    {
     
    360370    @param[out] pixels list of PixelPos pointers corresponding
    361371                       based on the line settings
    362     @param[in] line Line to map to pixels   
     372    @param[in] line Line to map to pixels
    363373    @param[in] numCols maximum X (columns) for the line
    364374    @param[in] numRows maximum Y (rows) for the line            */
     
    367377{
    368378    Line offsetLine;
    369     PixelPos *pixel;
    370379    double slope, xOffset, yOffset, xMid, yMid;
    371380    int x, y, xBegin = numCols, yBegin = numRows, xEnd = 0, yEnd = 0;
    372381
    373382    // Extract the endpoints
    374    
     383
    375384    double x1 = line->begin.x;
    376385    double y1 = line->begin.y;
    377386    double x2 = line->end.x;
    378387    double y2 = line->end.y;
    379    
     388
    380389    // Determine the width and height of the line
    381    
     390
    382391    double dx = x2 - x1;
    383392    double dy = y2 - y1;
     
    403412
    404413    // Step point by point based on the dominate axis
    405    
     414
    406415    if (fabs (dx) > fabs (dy))
    407416    {
     
    411420        // If line is back to front, reorder endpoints and recompute
    412421        // the line width and height
    413        
     422
    414423        if (x1 > x2)
    415424        {
     
    421430
    422431        // Compute the slope of the line
    423        
     432
    424433        slope = dy / dx;
    425        
     434
    426435        // Compute the x and y offsets for the line width extent
    427436
    428         if (xBegin > xEnd) 
     437        if (xBegin > xEnd)
    429438            SwapInt (&xBegin, &xEnd);
    430439        else
     
    451460    }
    452461    else
    453     {       
     462    {
    454463        // -------------------
    455464        // vertical(ish) lines
     
    457466        // If line is back to front, reorder endpoints and recompute
    458467        // the line width and height
    459        
     468
    460469        if (y1 > y2)
    461470        {
     
    465474            dy = y2 - y1;
    466475        }
    467        
     476
    468477        // Compute the slope of the line
    469        
     478
    470479        slope = dx / dy;
    471        
     480
    472481        // Compute the x and y offsets for the line width extent
    473482
     
    481490        xMid = x1 + slope * (yBegin - y1);
    482491        xOffset = fabs (halfWidth * dr / dy);
    483        
     492
    484493        for (y = yBegin; y != yEnd; ++y)
    485494        {
Note: See TracChangeset for help on using the changeset viewer.