OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAnnotationMultiPolyLineObject.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 //*************************************************************************
8 // $Id: ossimAnnotationMultiPolyLineObject.cpp 17195 2010-04-23 17:32:18Z dburken $
12 #include <ossim/base/ossimIrect.h>
13 #include <ossim/base/ossimDrect.h>
14 #include <ossim/base/ossimLine.h>
15 
16 RTTI_DEF1(ossimAnnotationMultiPolyLineObject, "ossimAnnotationMultiPolyLineObject", ossimAnnotationObject)
17 
20 {
21  computeBoundingRect();
22 }
23 
25  unsigned char r,
26  unsigned char g,
27  unsigned char b,
28  long thickness)
29  :ossimAnnotationObject(r, g, b, thickness)
30 {
31  theMultiPolyLine = multiPoly;
33 }
34 
36 {
37 }
38 
40  double y)
41 {
42  for(ossim_uint32 i =0; i<theMultiPolyLine.size(); ++i)
43  {
44  theMultiPolyLine[i] *= ossimDpt(x, y);
45  }
47  // theBoundingRect *= ossimDpt(x,y);
48 }
49 
51 {
52  // do the quick checks first
53  //
54  if(rect.hasNans()) return false;
55  if(!rect.intersects(theBoundingRect)) return false;
56  if(theMultiPolyLine.size()<1) return false;
57 
58  for(ossim_uint32 i =0; i < theMultiPolyLine.size(); ++i)
59  {
60  vector<ossimPolyLine> result;
61 
62  if(theMultiPolyLine[i].clipToRect(result, rect))
63  {
64  return true;
65  }
66  }
67 
68  return false;
69 }
70 
72  const ossimDrect& /* rect */)const
73 {
75 
77  << "ossimAnnotationMultiPolyLineObject::getNewClippedObject\n"
78  << "Not implemented for " << getClassName() << endl;
79  return result;
80 }
81 
83 {
84  if(theMultiPolyLine.size()<1) return;
85  if(theBoundingRect.hasNans()) return;
86 
87 
89  anImage.setThickness(theThickness);
90  ossimDrect imageRect = anImage.getImageData()->getImageRectangle();
91 
92  if(theBoundingRect.intersects(imageRect))
93  {
94  // we need to extend it by a couple of pixels since
95  // if a pixel lies on the edge and then another pixel is just off
96  // the edge we will get a stair step and so for several pixels
97  // the line might be inside the image rectangle but the clip
98  // algorithm will only draw 1 pixel since it thinks the first
99  // point is inside and the second point is outside and will
100  // execute the clip algorithm keeping only the first
101  // point.
102  ossimDrect clipRect(imageRect.ul().x - 10,
103  imageRect.ul().y - 10,
104  imageRect.lr().x + 10,
105  imageRect.lr().y + 10);
106 
107  int j = 0;
108  for(ossim_uint32 i = 0; i < theMultiPolyLine.size(); ++i)
109  {
110  const ossimPolyLine& poly = theMultiPolyLine[i];
111  int vertexCount = poly.getNumberOfVertices();
112 
113  if(vertexCount > 1)
114  {
115 
116  ossimDpt start, end;
117  start = poly[0];
118  end = poly[1];
119  j = 1;
120  do
121  {
122  if(clipRect.clip(start, end))
123  {
124  anImage.drawLine(ossimIpt(start),
125  ossimIpt(end));
126  }
127  ++j;
128  start = poly[j-1];
129  end = poly[j];
130  }while(j < vertexCount);
131  }
132  else if(vertexCount == 1)
133  {
134  anImage.drawLine(ossimIpt(poly[0]),
135  ossimIpt(poly[0]));
136  }
137  }
138  }
139 }
140 
142 {
144  out << endl;
145  out << setw(15)<<setiosflags(ios::left)<<"type:"<<getClassName() << endl
146  << setw(15)<<setiosflags(ios::left)<<"polylines:"<<theMultiPolyLine.size()<<endl;
147 
148  for(ossim_uint32 i = 0; i < theMultiPolyLine.size(); ++i)
149  {
150  out << "____________________________________________________"<<endl
151  << theMultiPolyLine[i] << endl;
152  }
153  out << "____________________________________________________"<<endl;
154  return out;
155 }
156 
158 {
159  rect = theBoundingRect;
160 }
161 
163 {
164  if(theMultiPolyLine.size())
165  {
166  ossimDrect rect(theMultiPolyLine[0].getVertexList());
167 
168  for(ossim_uint32 i = 1; i < theMultiPolyLine.size(); ++i)
169  {
170  ossimDrect rect2(theMultiPolyLine[i].getVertexList());
171 
172  if(rect.hasNans())
173  {
174  rect = rect2;
175  }
176  else
177  {
178  if(!rect2.hasNans())
179  {
180  rect = rect.combine(rect2);
181  }
182  }
183  }
184 
185  theBoundingRect = rect;
186  }
187  else
188  {
190  }
191  if(!theBoundingRect.hasNans())
192  {
193  ossimIpt origin = theBoundingRect.ul();
195  origin.y - theThickness/2,
196  origin.x + (theBoundingRect.width()-1) + theThickness/2,
197  origin.y + (theBoundingRect.height()-1) + theThickness/2);
198  }
199 }
200 
202 {
203 // for(ossim_uint32 i = 0; i < theMultiPolyLine.size(); ++i)
204 // {
205 // if(theMultiPolyLine[i].isPointWithin(imagePoint))
206 // {
207 // return true;
208 // }
209 // }
210 
211  return theBoundingRect.pointWithin(imagePoint);
212 }
213 
215  : ossimAnnotationObject(rhs),
216  theMultiPolyLine(rhs.theMultiPolyLine),
217  theBoundingRect(rhs.theBoundingRect)
218 {
219 }
220 
222 {
223  return new ossimAnnotationMultiPolyLineObject(*this);
224 }
225 
227 {
228  theMultiPolyLine.push_back(poly);
229 }
230 
232  const ossimDpt& pt)
233 {
234  if(polygonIndex < theMultiPolyLine.size())
235  {
236  theMultiPolyLine[polygonIndex].addPoint(pt);
237  }
238 }
239 
240 void ossimAnnotationMultiPolyLineObject::setMultiPolyLine(const vector<ossimPolyLine>& multiPoly)
241 {
242  theMultiPolyLine = multiPoly;
244 }
245 
246 const std::vector<ossimPolyLine>& ossimAnnotationMultiPolyLineObject::getMultiPolyLine()const
247 {
248  return theMultiPolyLine;
249 }
250 
252 {
253  return theMultiPolyLine;
254 }
255 
void makeNan()
Definition: ossimDrect.h:388
ossim_uint32 x
virtual void setMultiPolyLine(const vector< ossimPolyLine > &multiPoly)
virtual void draw(ossimRgbImage &anImage) const
bool pointWithin(const ossimDpt &pt, double epsilon=0.0) const
Definition: ossimDrect.h:781
ossim_float64 width() const
Definition: ossimDrect.h:522
virtual std::ostream & print(std::ostream &out) const
Generic print method.
ossim_uint32 y
virtual void addPolyLine(const ossimPolyLine &poly)
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
ossimDrect combine(const ossimDrect &rect) const
Definition: ossimDrect.h:826
void setThickness(ossim_int32 thickness)
All the drawing algorithms have thickness.
ossim_uint32 getNumberOfVertices() const
Definition: ossimPolyLine.h:70
virtual std::ostream & print(std::ostream &out) const
Generic print method.
virtual bool isPointWithin(const ossimDpt &imagePoint) const
const std::vector< ossimPolyLine > & getMultiPolyLine() const
virtual ossimDrect getBoundingRect() const
virtual bool intersects(const ossimDrect &rect) const
ossimRefPtr< ossimImageData > getImageData()
Will return the image data.
unsigned int ossim_uint32
virtual ossimIrect getImageRectangle() const
bool hasNans() const
Definition: ossimDrect.h:396
virtual void addPoint(ossim_uint32 polygonIndex, const ossimDpt &pt)
bool intersects(const ossimDrect &rect) const
Definition: ossimDrect.cpp:289
ossim_float64 height() const
Definition: ossimDrect.h:517
void drawLine(double x1, double y1, double x2, double y2)
About all the draw routines will call draw line.
void setDrawColor(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255)
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) const
ossim_int32 y
Definition: ossimIpt.h:142
double x
Definition: ossimDpt.h:164
ossim_int32 x
Definition: ossimIpt.h:141
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
const ossimDpt & lr() const
Definition: ossimDrect.h:341
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23