traceline.c

00001 /*
00002 *    Copyright (c) 2007. The BATI team. All right reserved.
00003 *
00004 *    This file is part of BATI library.
00005 *
00006 *    BATI library is free software: you can redistribute it and/or modify
00007 *    it under the terms of the GNU General Public License as published by
00008 *    the Free Software Foundation, either version 3 of the License, or
00009 *    (at your option) any later version.
00010 *
00011 *    BATI library  is distributed in the hope that it will be useful,
00012 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *    GNU General Public License for more details.
00015 *
00016 *    You should have received a copy of the GNU General Public License
00017 *    along with BATI library.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #include <math.h>
00020 #include "proto2D.h"
00021 
00046 short breshenham(imau1 *image,short x1, short y1, short x2,short y2,short intensity)
00047     
00048 {
00049   short switch1;
00050   short inx1, inxy;
00051   short  stopX;
00052   short diffX, diffY, helpdiff;
00053   short x,y,flag=0;
00054 
00055   /* wenn der Ausganspunkt in der Mitte liegt wird erst in eine Rtg gegangen und dann in die entgegengesetzte, deshalb gibt es neben den eigentlichen x,y,z Zaehlern noch entgegengesetze */
00056   diffX=x2-x1;
00057   diffY=y2-y1;
00058   if (fabs(diffY)>fabs(diffX)){
00059     flag=1;
00060     x=y1;
00061     y=x1;
00062     stopX=y2;
00063     helpdiff=diffX;
00064     diffX=diffY;
00065     diffY=helpdiff;       
00066   }
00067   else{
00068     flag=0;
00069     x=x1;
00070     y=y1;
00071     stopX=x2;    
00072   }
00073  switch1=2*fabs(diffY)-fabs(diffX);
00074  inx1=2*fabs(diffY);
00075  inxy=2*(fabs(diffY)-fabs(diffX));    
00076 
00077     
00078   while  (x!=stopX)  {         
00079     if (flag==0) {  
00080       image->p[y][x]=intensity; 
00081     }
00082     else{
00083       image->p[x][y]=intensity;       
00084     }
00085      if (diffX<0)
00086        x--;      
00087      else
00088        x++;      
00089      if (switch1>0){
00090        if (diffY<0)      
00091          y--;
00092        else
00093          y++;   
00094        switch1+=inxy;  
00095      }
00096      else
00097        switch1+=inx1;       
00098   }      
00099   image->p[y2][x2]=intensity;    
00100   return 0;
00101 }

Generated on Tue Apr 22 13:31:04 2008 for ima2D by  doxygen 1.5.3