OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAnnotationLineObject.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimAnnotationLineObject.cpp 13964 2009-01-14 16:30:07Z gpotts $
12 
15 
17  "ossimAnnotationLineObject",
19 
22  theStart(0,0),
23  theEnd(0,0),
24  theBoundingRect(0,0,0,0)
25 {
26 }
27 
29  const ossimIpt& end,
30  unsigned char r,
31  unsigned char g,
32  unsigned char b,
33  long thickness)
34  :ossimAnnotationObject(r, g, b, thickness),
35  theStart(start),
36  theEnd(end)
37 {
39 }
40 
42  long y1,
43  long x2,
44  long y2,
45  unsigned char r,
46  unsigned char g,
47  unsigned char b,
48  long thickness)
49  :ossimAnnotationObject(r, g, b, thickness),
50  theStart(x1, y1),
51  theEnd(x2, y2)
52 {
54 }
55 
58  theStart(rhs.theStart),
59  theEnd(rhs.theEnd),
60  theBoundingRect(rhs.theBoundingRect)
61 {
62 }
63 
65 {
66  return new ossimAnnotationLineObject(*this);
67 }
68 
70 {
71  theStart.x = ossim::round<int>(theStart.x*x);
72  theStart.y = ossim::round<int>(theStart.y*y);
73  theEnd.x = ossim::round<int>(theEnd.x*x);
74  theEnd.y = ossim::round<int>(theEnd.y*y);
76 }
77 
79 {
81  ossimDpt start = theStart;
82  ossimDpt end = theEnd;
83 
84  if(rect.clip(start, end))
85  {
86  result = (ossimAnnotationLineObject*)dup();
87  result->setLine(start, end);
88  }
89 
90  return result;
91 }
92 
94 {
95  ossimDpt start = theStart;
96  ossimDpt end = theEnd;
97 
98  return rect.clip(start, end);
99 }
100 
102 {
103  if(anImage.getImageData().valid())
104  {
105  anImage.setDrawColor(theRed, theGreen, theBlue);
106  anImage.setThickness(theThickness);
107  ossimDrect imageRect = anImage.getImageData()->getImageRectangle();
108  ossimDpt start = theStart;
109  ossimDpt end = theEnd;
110 
111  if(anImage.getImageData().valid())
112  {
113  // we need to extend it by a couple of pixels since
114  // if a pixel lies on the edge and then another pixel is just off
115  // the edge we will get a stair step and so for several pixels
116  // the line might be inside the image rectangle but the clip
117  // algorithm will only draw 1 pixel since it thinks the first
118  // point is inside and the second point is outside and will
119  // execute the clip algorithm keeping only the first
120  // point.
121  ossimDrect clipRect(imageRect.ul().x - 10,
122  imageRect.ul().y - 10,
123  imageRect.lr().x + 10,
124  imageRect.lr().y + 10);
125  // now we can draw.
126  if(clipRect.clip(start, end))
127  {
128  anImage.drawLine(ossimIpt((int)start.x,
129  (int)start.y),
130  ossimIpt((int)end.x,
131  (int)end.y));
132  }
133  }
134  }
135 }
136 
138 {
139  out << "line_start: " << theStart << endl
140  << "line_end: " << theEnd << endl
141  << "bounding_rect: " << theBoundingRect << endl;
142  return out;
143 }
144 
146 {
147  rect = theBoundingRect;
148 }
149 
151 {
152  vector<ossimDpt> pts(2);
153 
154  pts[0] = theStart;
155  pts[1] = theEnd;
156 
158 }
159 
161  const ossimDpt& end)
162 {
163  theStart = start;
164  theEnd = end;
166 }
168 {
169  start = theStart;
170  end = theEnd;
171 }
172 
174 {
175  if(theBoundingRect.pointWithin(point))
176  {
177  // we will use the implicit form of a line to determine if the point is
178  // on the line. For now we will just return true if it is within the
179  // bounding rect.
180  return true;
181  }
182 
183  return false;
184 }
ossim_uint32 x
bool pointWithin(const ossimDpt &pt, double epsilon=0.0) const
Definition: ossimDrect.h:781
virtual void applyScale(double x, double y)
virtual bool isPointWithin(const ossimDpt &imagePoint) const
virtual std::ostream & print(std::ostream &out) const
Generic print method.
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
RTTI_DEF1(ossimAnnotationLineObject, "ossimAnnotationLineObject", ossimAnnotationObject) ossimAnnotationLineObject
void getLine(ossimDpt &start, ossimDpt &end)
void setThickness(ossim_int32 thickness)
All the drawing algorithms have thickness.
virtual void draw(ossimRgbImage &anImage) const
virtual ossimDrect getBoundingRect() const
ossimRefPtr< ossimImageData > getImageData()
Will return the image data.
void setLine(const ossimDpt &start, const ossimDpt &end)
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) const
virtual ossimIrect getImageRectangle() const
virtual bool intersects(const ossimDrect &rect) const
void drawLine(double x1, double y1, double x2, double y2)
About all the draw routines will call draw line.
bool clip(ossimDpt &p1, ossimDpt &p2) const
Definition: ossimDrect.cpp:653
void setDrawColor(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255)
virtual ossimObject * dup() const
ossim_int32 y
Definition: ossimIpt.h:142
double x
Definition: ossimDpt.h:164
ossim_int32 x
Definition: ossimIpt.h:141
const ossimDpt & lr() const
Definition: ossimDrect.h:341
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23