KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
corner.h
Go to the documentation of this file.
1 /* $Id $ */
2 
15 #ifndef EDGE_CORNER_H
16 #define EDGE_CORNER_H
17 
18 #include "l_cpp/l_exception.h"
19 #include <l_cpp/l_readable.h>
20 #include <l_cpp/l_writeable.h>
21 #include "i_cpp/i_image.h"
22 #include "m_cpp/m_vector.h"
23 #include "edge_cpp/line_segment.h"
24 #include <limits>
25 
26 namespace kjb {
27 
37 class Corner : public Readable, public Writeable
38 {
39  public:
40 
42  Corner() : Readable(), Writeable(), position(3,0.0) {}
43 
45  Corner(const kjb::Vector & iposition) : Readable(), Writeable(), position(3,0.0)
46  {
47  set_position(iposition);
48  }
49 
51  {
52 
53  }
54 
55  Corner (const char * filename)
56  {
57  Readable::read(filename);
58  }
59 
60  Corner (std::istream & in)
61  {
62  read(in);
63  }
64 
65  Corner & operator=(const Corner & src)
66  {
67  position = src.position;
68  segments = src.segments;
69  return (*this);
70  }
71 
72  inline const kjb::Vector & get_position() const
73  {
74  return position;
75  }
76 
77  inline const std::vector<kjb::Line_segment> & get_segments() const
78  {
79  return segments;
80  }
81 
82  inline void set_position(const kjb::Vector & iposition)
83  {
84  if(iposition.size() == 2)
85  {
86  position(0) = iposition(0);
87  position(1) = iposition(1);
88  }
89  else if(iposition.size() == 3)
90  {
91  position = iposition;
92  }
93  else
94  {
95  KJB_THROW_2(Illegal_argument, "Invalid size of vector containing corner position");
96  }
97  }
98 
99  inline void add_segment(const kjb::Line_segment & isegment)
100  {
101  segments.push_back(isegment);
102  }
103 
104  inline const kjb::Line_segment & get_segment(unsigned int i) const
105  {
106  if(i >= segments.size())
107  {
108  KJB_THROW_2(Illegal_argument, "Corner: requested segment index out of bounds");
109  }
110  return segments[i];
111  }
112 
113 
114  inline void set_segment(unsigned int i, const kjb::Line_segment isegment)
115  {
116  if(i >= segments.size())
117  {
118  KJB_THROW_2(Illegal_argument, "Corner: requested segment index out of bounds");
119  }
120  segments[i] = isegment;
121  }
122 
123  inline unsigned int get_num_segments() const
124  {
125  return segments.size();
126  }
127 
129  void read(std::istream& in);
130 
132  void write(std::ostream& out) const;
133 
135  virtual void draw( kjb::Image & img, double ir, double ig, double ib, double width = 1.0) const;
136 
138  virtual void randomly_color(kjb::Image & img, double width = 1.0) const;
139 
140  protected:
141 
144 
146  std::vector<kjb::Line_segment> segments;
147 
148 };
149 
150 
151 }
152 
153 #endif
Corner(std::istream &in)
Definition: corner.h:60
virtual void randomly_color(kjb::Image &img, double width=1.0) const
Randomly colors this line segment on an image.
Definition: corner.cpp:84
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
Corner(const kjb::Vector &iposition)
Constructor without initializations.
Definition: corner.h:45
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
void read(std::istream &in)
Reads this Line segment from an input stream.
Definition: corner.cpp:22
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
Corner(const Corner &src)
Definition: corner.h:50
Corner()
Constructor without initializations.
Definition: corner.h:42
kjb::Vector position
position of this 2D corner
Definition: corner.h:143
void set_position(const kjb::Vector &iposition)
Definition: corner.h:82
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
const kjb::Vector & get_position() const
Definition: corner.h:72
const kjb::Line_segment & get_segment(unsigned int i) const
Definition: corner.h:104
void set_segment(unsigned int i, const kjb::Line_segment isegment)
Definition: corner.h:114
std::vector< kjb::Line_segment > segments
Definition: corner.h:146
Corner & operator=(const Corner &src)
Definition: corner.h:65
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
Class to manipulate a 2D corner. The corener is defined in terms of a set of line segments all inters...
Definition: corner.h:37
void add_segment(const kjb::Line_segment &isegment)
Definition: corner.h:99
virtual void read(std::istream &in)=0
Reads this Readable from an input stream.
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Code for a wrapper class around the C struct KJB_Image.
Support for error handling exception classes in libKJB.
void write(std::ostream &out) const
Writes this Line segment to an output stream.
Definition: corner.cpp:64
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
unsigned int get_num_segments() const
Definition: corner.h:123
Corner(const char *filename)
Definition: corner.h:55
const std::vector< kjb::Line_segment > & get_segments() const
Definition: corner.h:77
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
Class to manipulate a line segment The class is parametrized in terms the position of the centre...
Definition: gr_line_segment.h:62
virtual void draw(kjb::Image &img, double ir, double ig, double ib, double width=1.0) const
Draws this line segment.
Definition: corner.cpp:75