Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleBresenham.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 // must be first:
26 //#include <Base/Common/LeakChecking.h>
27 
28 
29 /**
30  @example ExampleBresenham.cpp
31  @relates Bresenham,BresenhamCircle,Scanline
32  @brief Example for using bresenham drawing circle and line
33  @ingroup g_examples
34  @author MIP
35 */
36 
37 #include "Base/Image/ImageIO.hh"
38 #include "Base/ImageUtils/Bresenham.hh"
39 #include "Base/ImageUtils/BresenhamCircle.hh"
40 #include "Base/ImageUtils/BresenhamCircleEighth.hh"
41 #include "Base/ImageUtils/Scanline.hh"
42 #include "Base/Image/Image.hh"
43 
44 using namespace BIAS;
45 using namespace std;
46 
47 int main (int argc, char *argv[])
48 {
49  Image<unsigned char> im(200, 200, 1);
50  unsigned char **ida=im.GetImageDataArray();
51  int next[]={0,0}, start[]={10,30}, end[]={120,90}, center[]={100, 150};
52  int epsilon=4, radius=30;
53 
54  if (argc==5){
55  start[0]=atoi(argv[1]);
56  start[1]=atoi(argv[2]);
57  end[0]=atoi(argv[3]);
58  end[1]=atoi(argv[4]);
59  } else if (argc!=1){
60  cerr << endl << argv[0] << " [ startx starty endx endy ]" << endl << endl;
61  }
62 
63  im.FillImageWithConstValue((unsigned char)0);
64 
65  // draw circle with BresenhamCircle
66  BresenhamCircle bcirc(center, radius);
67 
68  while (bcirc.GetNext(next)){
69  ida[next[1]][next[0]]=255;
70  }
71 
72  // draw 1/8 circle with BresenhamCircleEighth
73  center[0]-=5;
74  center[1]-=5;
75  BresenhamCircleEighth bce(center, radius);
76 
77  while (bce.GetNext(next)){
78  ida[next[1]][next[0]]=255;
79  }
80 
81  // draw line with Scanline
82  Scanline sl(start, end, epsilon);
83 
84  while (sl.GetNext(next)){
85  ida[next[1]][next[0]]=255;
86  }
87 
88  // draw line with Bresenham
89  Bresenham bres(start, end);
90 
91  while (bres.GetNext(next)){
92  ida[next[1]][next[0]]=0;
93  }
94 
95  ImageIO::Save("bresenham", im);
96 
97  return 0;
98 }
Scans a circle using Bresenham&#39;s integer arithmetic algorithm.
Class for scanning a region given by a line and a distance ca.
Definition: Scanline.hh:44
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
Scans a line using Bresenhams integer arithmetic algorithm.
Definition: Bresenham.hh:42
Just like BresenhamCircle but only computes 1/8 of the circle.