OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ossimAnnotationPolyObject Class Reference

#include <ossimAnnotationPolyObject.h>

Inheritance diagram for ossimAnnotationPolyObject:
ossimAnnotationObject ossimObject ossimReferenced

Public Member Functions

 ossimAnnotationPolyObject (bool enableFill=false, ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)
 
 ossimAnnotationPolyObject (const vector< ossimDpt > &imagePts, bool enableFill=false, ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)
 
 ossimAnnotationPolyObject (const ossimAnnotationPolyObject &rhs)
 
ossimObjectdup () const
 
virtual void applyScale (double x, double y)
 
virtual void draw (ossimRgbImage &anImage) const
 
virtual bool intersects (const ossimDrect &rect) const
 
virtual ossimAnnotationObjectgetNewClippedObject (const ossimDrect &rect) const
 
virtual std::ostream & print (std::ostream &out) const
 Generic print method. More...
 
virtual void getBoundingRect (ossimDrect &rect) const
 
virtual void addPoint (const ossimDpt &pt)
 
virtual void setPolygon (const vector< ossimDpt > &imagePoints)
 
virtual void setPolygon (const ossimPolygon &polygon)
 
virtual void setPolygon (const ossimIrect &rect)
 
virtual void setPolygon (const ossimDrect &rect)
 
virtual void computeBoundingRect ()
 
virtual bool isPointWithin (const ossimDpt &imagePoint) const
 
const ossimPolygongetPolygon () const
 
ossimPolygongetPolygon ()
 
virtual void setFillFlag (bool flag)
 
- Public Member Functions inherited from ossimAnnotationObject
virtual ~ossimAnnotationObject ()
 
 ossimAnnotationObject (ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)
 
virtual void applyScale (const ossimDpt &scale)
 
virtual ossimDrect getBoundingRect () const
 
virtual void setColor (ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
 
void getColor (ossim_uint8 &r, ossim_uint8 &g, ossim_uint8 &b) const
 
ossim_uint8 getThickness () const
 
virtual void setThickness (ossim_uint8 thickness)
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 Saves the current state of this object. More...
 
virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 Method to the load (recreate) the state of an object from a keyword list. More...
 
virtual ossimString getName () const
 
virtual void setName (const ossimString &name)
 
ossim_uint32 getId () const
 
virtual ossim_uint32 setId ()
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimString getShortName () const
 
virtual ossimString getLongName () const
 
virtual ossimString getDescription () const
 
virtual ossimString getClassName () const
 
virtual RTTItypeid getType () const
 
virtual bool canCastTo (ossimObject *obj) const
 
virtual bool canCastTo (const RTTItypeid &id) const
 
virtual bool canCastTo (const ossimString &parentClassName) const
 
virtual bool isEqualTo (const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 
virtual void accept (ossimVisitor &visitor)
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Protected Member Functions

virtual ~ossimAnnotationPolyObject ()
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Protected Attributes

ossimPolygon thePolygon
 
ossimDrect theBoundingRect
 
bool theFillEnabled
 
- Protected Attributes inherited from ossimAnnotationObject
ossim_uint8 theRed
 
ossim_uint8 theGreen
 
ossim_uint8 theBlue
 
ossim_uint8 theThickness
 
ossimString theName
 
ossim_uint32 theId
 

Additional Inherited Members

- Static Public Member Functions inherited from ossimAnnotationObject
static ossim_uint32 getNextId ()
 
static void restIdCounter ()
 
- Static Protected Attributes inherited from ossimAnnotationObject
static ossim_uint32 theIdCounter = 0
 

Detailed Description

Definition at line 17 of file ossimAnnotationPolyObject.h.

Constructor & Destructor Documentation

◆ ossimAnnotationPolyObject() [1/3]

ossimAnnotationPolyObject::ossimAnnotationPolyObject ( bool  enableFill = false,
ossim_uint8  r = 255,
ossim_uint8  g = 255,
ossim_uint8  b = 255,
ossim_uint8  thickness = 1 
)

Referenced by dup(), and getNewClippedObject().

◆ ossimAnnotationPolyObject() [2/3]

ossimAnnotationPolyObject::ossimAnnotationPolyObject ( const vector< ossimDpt > &  imagePts,
bool  enableFill = false,
ossim_uint8  r = 255,
ossim_uint8  g = 255,
ossim_uint8  b = 255,
ossim_uint8  thickness = 1 
)

Definition at line 32 of file ossimAnnotationPolyObject.cpp.

References computeBoundingRect(), and thePolygon.

39  :ossimAnnotationObject(r, g, b, thickness),
40  theFillEnabled(enableFill)
41 {
42  thePolygon = imagePts;
44 }
ossimAnnotationObject(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)

◆ ossimAnnotationPolyObject() [3/3]

ossimAnnotationPolyObject::ossimAnnotationPolyObject ( const ossimAnnotationPolyObject rhs)

Definition at line 46 of file ossimAnnotationPolyObject.cpp.

48  : ossimAnnotationObject(rhs),
52 {
53 }
ossimAnnotationObject(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)

◆ ~ossimAnnotationPolyObject()

ossimAnnotationPolyObject::~ossimAnnotationPolyObject ( )
protectedvirtual

Definition at line 60 of file ossimAnnotationPolyObject.cpp.

61 {
62 }

Member Function Documentation

◆ addPoint()

void ossimAnnotationPolyObject::addPoint ( const ossimDpt pt)
virtual

Definition at line 283 of file ossimAnnotationPolyObject.cpp.

References ossimPolygon::addPoint(), and thePolygon.

284 {
285  thePolygon.addPoint(pt);
286 }
void addPoint(const ossimDpt &pt)

◆ applyScale()

void ossimAnnotationPolyObject::applyScale ( double  x,
double  y 
)
virtual

Implements ossimAnnotationObject.

Definition at line 64 of file ossimAnnotationPolyObject.cpp.

References computeBoundingRect(), thePolygon, x, and y.

Referenced by ossimGeoAnnotationPolyObject::applyScale().

65 {
66  thePolygon *= ossimDpt(x, y);
68 }
ossim_uint32 x
ossim_uint32 y

◆ computeBoundingRect()

void ossimAnnotationPolyObject::computeBoundingRect ( )
virtual

◆ draw()

void ossimAnnotationPolyObject::draw ( ossimRgbImage anImage) const
virtual

Implements ossimAnnotationObject.

Definition at line 167 of file ossimAnnotationPolyObject.cpp.

References ossimPolygon::clipToRect(), ossimRgbImage::drawFilledPolygon(), ossimRgbImage::drawLine(), ossimRgbImage::getImageData(), ossimImageData::getImageRectangle(), ossimPolygon::getNumberOfVertices(), ossimPolygon::getVertexCount(), ossimDrect::hasNans(), ossimDrect::intersects(), ossimDrect::lr(), ossimRgbImage::setDrawColor(), ossimRgbImage::setThickness(), ossimAnnotationObject::theBlue, theBoundingRect, theFillEnabled, ossimAnnotationObject::theGreen, thePolygon, ossimAnnotationObject::theRed, ossimAnnotationObject::theThickness, ossimDrect::ul(), ossimDpt::x, and ossimDpt::y.

Referenced by ossimGeoAnnotationPolyObject::draw().

168 {
169  if(thePolygon.getVertexCount() < 2) return;
170  if(theBoundingRect.hasNans()) return;
171  int vertexCount = thePolygon.getVertexCount();
172 
173  anImage.setDrawColor(theRed, theGreen, theBlue);
174  anImage.setThickness(theThickness);
175  ossimDrect imageRect = anImage.getImageData()->getImageRectangle();
176  if(theBoundingRect.intersects(imageRect))
177  {
178  // we need to extend it by a couple of pixels since
179  // if a pixel lies on the edge and then another pixel is just off
180  // the edge we will get a stair step and so for several pixels
181  // the line might be inside the image rectangle but the clip
182  // algorithm will only draw 1 pixel since it thinks the first
183  // point is inside and the second point is outside and will
184  // execute the clip algorithm keeping only the first
185  // point.
186  ossimDrect clipRect(imageRect.ul().x - 10,
187  imageRect.ul().y - 10,
188  imageRect.lr().x + 10,
189  imageRect.lr().y + 10);
190 
191  if(!theFillEnabled)
192  {
193  ossimDpt start, end;
195  {
196  start = thePolygon[0];
197  end = thePolygon[0];
198  if(clipRect.clip(start, end))
199  {
200  anImage.drawLine(ossimIpt(start),
201  ossimIpt(end));
202  }
203  }
204  else if(thePolygon.getNumberOfVertices() == 2)
205  {
206  start = thePolygon[0];
207  end = thePolygon[1];
208  if(clipRect.clip(start, end))
209  {
210  anImage.drawLine(ossimIpt(start),
211  ossimIpt(end));
212  }
213  }
214  else
215  {
216  int j = 0;
217  while(j<vertexCount)
218  {
219  start = thePolygon[j];
220  end = thePolygon[(j+1)%vertexCount];
221  if(clipRect.clip(start, end))
222  {
223  anImage.drawLine(ossimIpt(start),
224  ossimIpt(end));
225  }
226  ++j;
227  }
228  }
229 #if 0
230  ossimDpt start, end;
231  start = thePolygon[vertexCount-1];
232  end = thePolygon[0];
233  int i = 0;
234  do
235  {
236  if(clipRect.clip(start, end))
237  {
238  anImage.drawLine(ossimIpt((int)start.x, (int)start.y),
239  ossimIpt((int)end.x, (int)end.y));
240  }
241  ++i;
242  start = thePolygon[i];
243  end = thePolygon[i-1];
244  }while(i < vertexCount);
245 #endif
246  }
247  else
248  {
249  vector<ossimPolygon> result;
250  if(thePolygon.clipToRect(result, imageRect))
251  {
252  for(int i = 0; i < (int)result.size();++i)
253  {
254  anImage.drawFilledPolygon(result[i].getVertexList());
255  }
256  }
257  }
258  }
259 }
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
void setThickness(ossim_int32 thickness)
All the drawing algorithms have thickness.
ossimRefPtr< ossimImageData > getImageData()
Will return the image data.
ossim_uint32 getVertexCount() const
virtual ossimIrect getImageRectangle() const
bool hasNans() const
Definition: ossimDrect.h:396
bool intersects(const ossimDrect &rect) const
Definition: ossimDrect.cpp:289
void drawLine(double x1, double y1, double x2, double y2)
About all the draw routines will call draw line.
bool clipToRect(vector< ossimPolygon > &result, const ossimDrect &rect) const
Uses the ossimPolyArea2d class for the intersection.
ossim_uint32 getNumberOfVertices() const
void setDrawColor(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255)
void drawFilledPolygon(const std::vector< ossimDpt > &p)
We will cut and paste the code from drawFilledPolygon(ossimIpt *p, int n).
double x
Definition: ossimDpt.h:164
const ossimDpt & lr() const
Definition: ossimDrect.h:341

◆ dup()

ossimObject * ossimAnnotationPolyObject::dup ( ) const
virtual

Reimplemented from ossimObject.

Definition at line 55 of file ossimAnnotationPolyObject.cpp.

References ossimAnnotationPolyObject().

56 {
57  return new ossimAnnotationPolyObject(*this);
58 }
ossimAnnotationPolyObject(bool enableFill=false, ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)

◆ getBoundingRect()

void ossimAnnotationPolyObject::getBoundingRect ( ossimDrect rect) const
virtual

Implements ossimAnnotationObject.

Definition at line 278 of file ossimAnnotationPolyObject.cpp.

References theBoundingRect.

Referenced by ossimGeoAnnotationPolyObject::getBoundingRect().

279 {
280  rect = theBoundingRect;
281 }

◆ getNewClippedObject()

ossimAnnotationObject * ossimAnnotationPolyObject::getNewClippedObject ( const ossimDrect rect) const
virtual

Will allocate a new object that is clipped to the passed. in rect. Look at derived classes to see if the object is actually clipped or not. A new object is returned if it clips to the rect else NULL should be returned it doesn't clip.

Implements ossimAnnotationObject.

Definition at line 115 of file ossimAnnotationPolyObject.cpp.

References ossimPolygon::clipToRect(), ossimPolyLine::clipToRect(), ossimDrect::intersects(), ossimAnnotationPolyObject(), ossimAnnotationObject::theBlue, theBoundingRect, theFillEnabled, ossimAnnotationObject::theGreen, thePolygon, ossimAnnotationObject::theRed, and ossimAnnotationObject::theThickness.

Referenced by ossimGeoAnnotationPolyObject::getNewClippedObject().

116 {
118 
119  if(theBoundingRect.intersects(rect))
120  {
121  if(theFillEnabled)
122  {
123  vector<ossimPolygon> resultPoly;
124 
125  if(thePolygon.clipToRect(resultPoly, rect))
126  {
127  if(resultPoly.size() == 1)
128  {
129  result = new ossimAnnotationPolyObject(resultPoly[0].getVertexList(),
131  theRed,
132  theGreen,
133  theBlue,
134  theThickness);
135  }
136  else
137  {
138  result = new ossimAnnotationMultiPolyObject(resultPoly,
140  theRed,
141  theGreen,
142  theBlue,
143  theThickness);
144  }
145  }
146  }
147  else
148  {
149  vector<ossimPolyLine> lineListResult;
150  ossimPolyLine polyLine = thePolygon;
151 
152  if(polyLine.clipToRect(lineListResult,
153  rect))
154  {
155  result = new ossimAnnotationMultiLineObject(lineListResult,
156  theRed,
157  theGreen,
158  theBlue,
159  theThickness);
160  }
161  }
162  }
163 
164  return result;
165 }
ossimAnnotationPolyObject(bool enableFill=false, ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)
bool intersects(const ossimDrect &rect) const
Definition: ossimDrect.cpp:289
bool clipToRect(vector< ossimPolygon > &result, const ossimDrect &rect) const
Uses the ossimPolyArea2d class for the intersection.
bool clipToRect(vector< ossimPolyLine > &result, const ossimDrect &rect) const

◆ getPolygon() [1/2]

const ossimPolygon & ossimAnnotationPolyObject::getPolygon ( ) const

Definition at line 318 of file ossimAnnotationPolyObject.cpp.

References thePolygon.

Referenced by ossimGeoAnnotationPolyObject::transform().

319 {
320  return thePolygon;
321 }

◆ getPolygon() [2/2]

ossimPolygon & ossimAnnotationPolyObject::getPolygon ( )

Definition at line 323 of file ossimAnnotationPolyObject.cpp.

References thePolygon.

324 {
325  return thePolygon;
326 }

◆ intersects()

bool ossimAnnotationPolyObject::intersects ( const ossimDrect rect) const
virtual

Implements ossimAnnotationObject.

Definition at line 70 of file ossimAnnotationPolyObject.cpp.

References ossimDrect::clip(), ossimPolygon::clipToRect(), ossimPolygon::getVertexCount(), ossimDrect::hasNans(), ossimDrect::intersects(), theBoundingRect, theFillEnabled, and thePolygon.

Referenced by ossimGeoAnnotationPolyObject::intersects().

71 {
72  // do the quick checks first
73  //
74  if(rect.hasNans()) return false;
75  if(!rect.intersects(theBoundingRect)) return false;
76 
77  if(!theFillEnabled)
78  {
79  int vertexCount = thePolygon.getVertexCount();
80  ossimDpt start, end;
81  int j = 0;
82  while(j<vertexCount)
83  {
84  start = thePolygon[j];
85  end = thePolygon[(j+1)%vertexCount];
86  if(rect.clip(start, end))
87  {
88  return true;
89  }
90  ++j;
91  }
92 // start = thePolygon[vertexCount-1];
93 // end = thePolygon[0];
94 // int i = 0;
95 // do
96 // {
97 // if(rect.clip(start, end))
98 // {
99 // return true;
100 // }
101 // ++i;
102 // start = thePolygon[i];
103 // end = thePolygon[i-1];
104 // }while(i < vertexCount);
105  }
106  else
107  {
108  vector<ossimPolygon> result;
109  return thePolygon.clipToRect(result, rect);
110  }
111 
112  return false;
113 }
ossim_uint32 getVertexCount() const
bool hasNans() const
Definition: ossimDrect.h:396
bool intersects(const ossimDrect &rect) const
Definition: ossimDrect.cpp:289
bool clip(ossimDpt &p1, ossimDpt &p2) const
Definition: ossimDrect.cpp:653
bool clipToRect(vector< ossimPolygon > &result, const ossimDrect &rect) const
Uses the ossimPolyArea2d class for the intersection.

◆ isPointWithin()

bool ossimAnnotationPolyObject::isPointWithin ( const ossimDpt imagePoint) const
virtual

This method allows you to pick an object. It will return true or false if the point falls somewhere on an object. Look at derived classes for further information.

Reimplemented from ossimAnnotationObject.

Definition at line 313 of file ossimAnnotationPolyObject.cpp.

References ossimDrect::pointWithin(), and theBoundingRect.

314 {
315  return theBoundingRect.pointWithin(imagePoint);
316 }
bool pointWithin(const ossimDpt &pt, double epsilon=0.0) const
Definition: ossimDrect.h:781

◆ print()

std::ostream & ossimAnnotationPolyObject::print ( std::ostream &  out) const
virtual

Generic print method.

Derived classes should re-implement as they see fit.

Returns
std::ostream&

Reimplemented from ossimAnnotationObject.

Definition at line 261 of file ossimAnnotationPolyObject.cpp.

References ossimPolygon::getVertexCount(), theBoundingRect, theFillEnabled, and thePolygon.

Referenced by ossimGeoAnnotationPolyObject::print().

262 {
263  out << "number_of_points: " << thePolygon.getVertexCount();
264  if(thePolygon.getVertexCount() > 0)
265  {
266  for(long index =0; index < (long)(thePolygon.getVertexCount()-1); ++index)
267  {
268  out << thePolygon[index] << endl;
269 
270  }
271  out << thePolygon[thePolygon.getVertexCount()-1] << endl;
272  }
273  out << "fill_enabled: " << theFillEnabled << endl
274  << "bounding_rect: " << theBoundingRect << endl;
275  return out;
276 }
ossim_uint32 getVertexCount() const

◆ setFillFlag()

void ossimAnnotationPolyObject::setFillFlag ( bool  flag)
virtual

Definition at line 328 of file ossimAnnotationPolyObject.cpp.

References theFillEnabled.

Referenced by ossimGeoAnnotationPolyObject::setFillFlag().

329 {
330  theFillEnabled = flag;
331 }

◆ setPolygon() [1/4]

void ossimAnnotationPolyObject::setPolygon ( const vector< ossimDpt > &  imagePoints)
virtual

Definition at line 288 of file ossimAnnotationPolyObject.cpp.

References thePolygon.

Referenced by ossimGeoAnnotationPolyObject::loadState(), and ossimGeoAnnotationPolyObject::setPolygon().

289 {
290  thePolygon = imagePoints;
291 }

◆ setPolygon() [2/4]

void ossimAnnotationPolyObject::setPolygon ( const ossimPolygon polygon)
virtual

Definition at line 293 of file ossimAnnotationPolyObject.cpp.

References thePolygon.

294 {
295  thePolygon = polygon;
296 }

◆ setPolygon() [3/4]

void ossimAnnotationPolyObject::setPolygon ( const ossimIrect rect)
virtual

Definition at line 298 of file ossimAnnotationPolyObject.cpp.

References thePolygon.

299 {
300  thePolygon = rect;
301 }

◆ setPolygon() [4/4]

void ossimAnnotationPolyObject::setPolygon ( const ossimDrect rect)
virtual

Definition at line 303 of file ossimAnnotationPolyObject.cpp.

References thePolygon.

304 {
305  thePolygon = rect;
306 }

Member Data Documentation

◆ theBoundingRect

ossimDrect ossimAnnotationPolyObject::theBoundingRect
protected

◆ theFillEnabled

bool ossimAnnotationPolyObject::theFillEnabled
protected

Definition at line 75 of file ossimAnnotationPolyObject.h.

Referenced by draw(), getNewClippedObject(), intersects(), print(), and setFillFlag().

◆ thePolygon

ossimPolygon ossimAnnotationPolyObject::thePolygon
protected

The documentation for this class was generated from the following files: