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

#include <ossimAnnotationMultiPolyObject.h>

Inheritance diagram for ossimAnnotationMultiPolyObject:
ossimAnnotationObject ossimObject ossimReferenced

Public Member Functions

 ossimAnnotationMultiPolyObject ()
 
 ossimAnnotationMultiPolyObject (const vector< ossimPolygon > &multiPoly, bool enableFill, unsigned char r, unsigned char g, unsigned char b, long thickness)
 
 ossimAnnotationMultiPolyObject (const ossimAnnotationMultiPolyObject &rhs)
 
virtual 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 clear ()
 
virtual void addPolygon (ossim_uint32 polygonIndex, const ossimPolygon &poly)
 
virtual void addPoint (ossim_uint32 polygonIndex, const ossimDpt &pt)
 
virtual void setMultiPolygon (const vector< ossimPolygon > &multiPoly)
 
virtual void computeBoundingRect ()
 
virtual bool isPointWithin (const ossimDpt &imagePoint) const
 
const std::vector< ossimPolygon > & getMultiPolygon () const
 
std::vector< ossimPolygon > & getMultiPolygon ()
 
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 ~ossimAnnotationMultiPolyObject ()
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Protected Attributes

vector< ossimPolygontheMultiPolygon
 
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 16 of file ossimAnnotationMultiPolyObject.h.

Constructor & Destructor Documentation

◆ ossimAnnotationMultiPolyObject() [1/3]

ossimAnnotationMultiPolyObject::ossimAnnotationMultiPolyObject ( )

Definition at line 18 of file ossimAnnotationMultiPolyObject.cpp.

Referenced by getNewClippedObject().

20  theFillEnabled(false)
21 {
23 }
ossimAnnotationObject(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)

◆ ossimAnnotationMultiPolyObject() [2/3]

ossimAnnotationMultiPolyObject::ossimAnnotationMultiPolyObject ( const vector< ossimPolygon > &  multiPoly,
bool  enableFill,
unsigned char  r,
unsigned char  g,
unsigned char  b,
long  thickness 
)

Definition at line 25 of file ossimAnnotationMultiPolyObject.cpp.

References computeBoundingRect(), and theMultiPolygon.

31  :ossimAnnotationObject(r, g, b, thickness),
32  theFillEnabled(enableFill)
33 {
34  theMultiPolygon = multiPoly;
36 }
ossimAnnotationObject(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)

◆ ossimAnnotationMultiPolyObject() [3/3]

ossimAnnotationMultiPolyObject::ossimAnnotationMultiPolyObject ( const ossimAnnotationMultiPolyObject rhs)
inline

Definition at line 27 of file ossimAnnotationMultiPolyObject.h.

28  : ossimAnnotationObject(rhs),
32  {
33  }
ossimAnnotationObject(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)

◆ ~ossimAnnotationMultiPolyObject()

ossimAnnotationMultiPolyObject::~ossimAnnotationMultiPolyObject ( )
protectedvirtual

Definition at line 38 of file ossimAnnotationMultiPolyObject.cpp.

39 {
40 }

Member Function Documentation

◆ addPoint()

virtual void ossimAnnotationMultiPolyObject::addPoint ( ossim_uint32  polygonIndex,
const ossimDpt pt 
)
inlinevirtual

Definition at line 55 of file ossimAnnotationMultiPolyObject.h.

57  {
58  if(polygonIndex < theMultiPolygon.size())
59  {
60  theMultiPolygon[polygonIndex].addPoint(pt);
61  }
62  }

◆ addPolygon()

virtual void ossimAnnotationMultiPolyObject::addPolygon ( ossim_uint32  polygonIndex,
const ossimPolygon poly 
)
inlinevirtual

Definition at line 47 of file ossimAnnotationMultiPolyObject.h.

Referenced by ossimGeoAnnotationMultiPolyObject::transform().

49  {
50  if(polygonIndex < theMultiPolygon.size())
51  {
52  theMultiPolygon[polygonIndex] = poly;
53  }
54  }

◆ applyScale()

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

Implements ossimAnnotationObject.

Definition at line 42 of file ossimAnnotationMultiPolyObject.cpp.

References theBoundingRect, theMultiPolygon, x, and y.

44 {
45  for(ossim_uint32 i =0; i<theMultiPolygon.size(); ++i)
46  {
47  theMultiPolygon[i] *= ossimDpt(x, y);
48  }
49 
51 }
ossim_uint32 x
ossim_uint32 y
unsigned int ossim_uint32

◆ clear()

void ossimAnnotationMultiPolyObject::clear ( )
virtual

Definition at line 268 of file ossimAnnotationMultiPolyObject.cpp.

References theMultiPolygon.

269 {
270  theMultiPolygon.clear();
271 }

◆ computeBoundingRect()

void ossimAnnotationMultiPolyObject::computeBoundingRect ( )
virtual

Implements ossimAnnotationObject.

Definition at line 273 of file ossimAnnotationMultiPolyObject.cpp.

References ossimDrect::combine(), ossimDrect::hasNans(), ossimDrect::height(), ossimDrect::makeNan(), theBoundingRect, theMultiPolygon, ossimAnnotationObject::theThickness, ossimDrect::ul(), ossimDrect::width(), ossimIpt::x, and ossimIpt::y.

Referenced by ossimGeoAnnotationMultiPolyObject::computeBoundingRect(), ossimAnnotationMultiPolyObject(), and ossimGeoAnnotationMultiPolyObject::transform().

274 {
275  if(theMultiPolygon.size())
276  {
277  ossimDrect rect(theMultiPolygon[0]);
278 
279  for(ossim_uint32 i = 1; i < theMultiPolygon.size(); ++i)
280  {
281  ossimDrect rect2(theMultiPolygon[i]);
282 
283  if(rect.hasNans())
284  {
285  rect = rect2;
286  }
287  else
288  {
289  if(!rect2.hasNans())
290  {
291  rect = rect.combine(rect2);
292  }
293  }
294  }
295 
296  theBoundingRect = rect;
297  }
298  else
299  {
301  }
302  if(!theBoundingRect.hasNans())
303  {
304  ossimIpt origin = theBoundingRect.ul();
306  origin.y - theThickness/2,
307  origin.x + (theBoundingRect.width()-1) + theThickness/2,
308  origin.y + (theBoundingRect.height()-1) + theThickness/2);
309  }
310 }
void makeNan()
Definition: ossimDrect.h:388
ossim_float64 width() const
Definition: ossimDrect.h:522
const ossimDpt & ul() const
Definition: ossimDrect.h:339
unsigned int ossim_uint32
bool hasNans() const
Definition: ossimDrect.h:396
ossim_float64 height() const
Definition: ossimDrect.h:517
ossim_int32 y
Definition: ossimIpt.h:142
ossim_int32 x
Definition: ossimIpt.h:141

◆ draw()

void ossimAnnotationMultiPolyObject::draw ( ossimRgbImage anImage) const
virtual

Implements ossimAnnotationObject.

Definition at line 143 of file ossimAnnotationMultiPolyObject.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, theMultiPolygon, ossimAnnotationObject::theRed, ossimAnnotationObject::theThickness, ossimDrect::ul(), ossimDpt::x, and ossimDpt::y.

Referenced by ossimGeoAnnotationMultiPolyObject::draw().

144 {
145  if(theMultiPolygon.size()<1) return;
146  if(theBoundingRect.hasNans()) return;
147 
148 
149  anImage.setDrawColor(theRed, theGreen, theBlue);
150  anImage.setThickness(theThickness);
151  ossimDrect imageRect = anImage.getImageData()->getImageRectangle();
152 
153  if(theBoundingRect.intersects(imageRect))
154  {
155  // we need to extend it by a couple of pixels since
156  // if a pixel lies on the edge and then another pixel is just off
157  // the edge we will get a stair step and so for several pixels
158  // the line might be inside the image rectangle but the clip
159  // algorithm will only draw 1 pixel since it thinks the first
160  // point is inside and the second point is outside and will
161  // execute the clip algorithm keeping only the first
162  // point.
163  ossimDrect clipRect(imageRect.ul().x - 10,
164  imageRect.ul().y - 10,
165  imageRect.lr().x + 10,
166  imageRect.lr().y + 10);
167 
168  int j = 0;
169  for(ossim_uint32 i = 0; i < theMultiPolygon.size(); ++i)
170  {
171  const ossimPolygon& poly = theMultiPolygon[i];
172  int vertexCount = poly.getVertexCount();
173  if(!theFillEnabled)
174  {
175  if(poly.getNumberOfVertices() == 1)
176  {
177  ossimDpt start, end;
178  start = poly[0];
179  end = poly[0];
180  if(clipRect.clip(start, end))
181  {
182  anImage.drawLine(ossimIpt(start),
183  ossimIpt(end));
184  }
185  }
186  else if(poly.getNumberOfVertices() == 2)
187  {
188  ossimDpt start, end;
189  start = poly[0];
190  end = poly[1];
191  if(clipRect.clip(start, end))
192  {
193  anImage.drawLine(ossimIpt(start),
194  ossimIpt(end));
195  }
196  }
197  else if(vertexCount > 2)
198  {
199  ossimDpt start, end;
200  j = 0;
201  while(j<vertexCount)
202  {
203  start = poly[j];
204  end = poly[(j+1)%vertexCount];
205  if(clipRect.clip(start, end))
206  {
207  anImage.drawLine(ossimIpt(start),
208  ossimIpt(end));
209  }
210  ++j;
211  }
212 #if 0
213  ossimDpt start, end;
214  start = poly[vertexCount-1];
215  end = poly[0];
216  j = 0;
217  do
218  {
219  if(clipRect.clip(start, end))
220  {
221  anImage.drawLine(ossimIpt(start),
222  ossimIpt(end));
223  }
224  ++j;
225  start = poly[j-1];
226  end = poly[j];
227  }while(j < vertexCount);
228 #endif
229  }
230  }
231  else
232  {
233  vector<ossimPolygon> result;
234  if(poly.clipToRect(result, imageRect))
235  {
236  for(j = 0; j < (int)result.size();++j)
237  {
238  anImage.drawFilledPolygon(result[j].getVertexList());
239  }
240  }
241  }
242  }
243  }
244 }
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
unsigned int ossim_uint32
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()

virtual ossimObject* ossimAnnotationMultiPolyObject::dup ( ) const
inlinevirtual

Reimplemented from ossimObject.

Definition at line 34 of file ossimAnnotationMultiPolyObject.h.

◆ getBoundingRect()

void ossimAnnotationMultiPolyObject::getBoundingRect ( ossimDrect rect) const
virtual

◆ getMultiPolygon() [1/2]

const std::vector<ossimPolygon>& ossimAnnotationMultiPolyObject::getMultiPolygon ( ) const
inline

Definition at line 72 of file ossimAnnotationMultiPolyObject.h.

72 {return theMultiPolygon;}

◆ getMultiPolygon() [2/2]

std::vector<ossimPolygon>& ossimAnnotationMultiPolyObject::getMultiPolygon ( )
inline

Definition at line 73 of file ossimAnnotationMultiPolyObject.h.

73 {return theMultiPolygon;}

◆ getNewClippedObject()

ossimAnnotationObject * ossimAnnotationMultiPolyObject::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 74 of file ossimAnnotationMultiPolyObject.cpp.

References ossimPolyLine::clipToRect(), ossimDrect::intersects(), ossimDrect::lr(), ossimAnnotationMultiPolyObject(), ossimAnnotationObject::theBlue, theBoundingRect, theFillEnabled, ossimAnnotationObject::theGreen, theMultiPolygon, ossimAnnotationObject::theRed, ossimAnnotationObject::theThickness, ossimDrect::ul(), ossimDpt::x, and ossimDpt::y.

75 {
77 
78  if(theBoundingRect.intersects(rect))
79  {
80  ossimDrect clipRect(rect.ul().x - 10,
81  rect.ul().y - 10,
82  rect.lr().x + 10,
83  rect.lr().y + 10);
84 
85  if(theFillEnabled)
86  {
87  vector<ossimPolygon> polyListResult;
88 
89  for(ossim_uint32 i = 0; i < theMultiPolygon.size(); ++i)
90  {
91  vector<ossimPolygon> tempList;
92 
93  if(theMultiPolygon[i].clipToRect(tempList, rect))
94  {
95  polyListResult.insert(polyListResult.end(),
96  tempList.begin(),
97  tempList.end());
98  }
99  }
100 
101  if(polyListResult.size())
102  {
103  result = new ossimAnnotationMultiPolyObject(polyListResult,
105  theRed,
106  theGreen,
107  theBlue,
108  theThickness);
109  }
110  }
111  else
112  {
113  vector<ossimPolyLine> lineListResult;
114  vector<ossimPolyLine> tempResult;
115 
116  for(ossim_uint32 i = 0; i< theMultiPolygon.size();++i)
117  {
118  ossimPolyLine polyLine = theMultiPolygon[i];
119 
120  if(polyLine.clipToRect(tempResult,
121  clipRect))
122  {
123  lineListResult.insert(lineListResult.end(),
124  tempResult.begin(),
125  tempResult.end());
126  }
127  }
128 
129  if(lineListResult.size())
130  {
131  result = new ossimAnnotationMultiLineObject(lineListResult,
132  theRed,
133  theGreen,
134  theBlue,
135  theThickness);
136  }
137  }
138  }
139 
140  return result;
141 }
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
unsigned int ossim_uint32
bool intersects(const ossimDrect &rect) const
Definition: ossimDrect.cpp:289
bool clipToRect(vector< ossimPolyLine > &result, const ossimDrect &rect) const
double x
Definition: ossimDpt.h:164
const ossimDpt & lr() const
Definition: ossimDrect.h:341

◆ intersects()

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

Implements ossimAnnotationObject.

Definition at line 53 of file ossimAnnotationMultiPolyObject.cpp.

References ossimDrect::hasNans(), ossimDrect::intersects(), theBoundingRect, and theMultiPolygon.

54 {
55  // do the quick checks first
56  //
57  if(rect.hasNans()) return false;
58  if(!rect.intersects(theBoundingRect)) return false;
59  if(theMultiPolygon.size()<1) return false;
60 
61  for(ossim_uint32 i =0; i < theMultiPolygon.size(); ++i)
62  {
63  vector<ossimPolygon> result;
64 
65  if(theMultiPolygon[i].clipToRect(result, rect))
66  {
67  return true;
68  }
69  }
70 
71  return false;
72 }
unsigned int ossim_uint32
bool hasNans() const
Definition: ossimDrect.h:396
bool intersects(const ossimDrect &rect) const
Definition: ossimDrect.cpp:289

◆ isPointWithin()

bool ossimAnnotationMultiPolyObject::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 312 of file ossimAnnotationMultiPolyObject.cpp.

References theMultiPolygon.

Referenced by ossimGeoAnnotationMultiPolyObject::isPointWithin().

313 {
314  for(ossim_uint32 i = 0; i < theMultiPolygon.size(); ++i)
315  {
316  if(theMultiPolygon[i].isPointWithin(imagePoint))
317  {
318  return true;
319  }
320  }
321 
322  return false;
323 }
virtual bool isPointWithin(const ossimDpt &imagePoint) const
unsigned int ossim_uint32

◆ print()

std::ostream & ossimAnnotationMultiPolyObject::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 246 of file ossimAnnotationMultiPolyObject.cpp.

References ossimObject::getClassName(), ossimAnnotationObject::print(), theFillEnabled, and theMultiPolygon.

247 {
249  out << endl;
250  out << setw(15)<<setiosflags(ios::left)<<"type:"<<getClassName() << endl
251  << setw(15)<<setiosflags(ios::left)<<"polygons:"<<theMultiPolygon.size()<<endl
252  << setw(15)<<setiosflags(ios::left)<<"fill enable: " << theFillEnabled << endl;
253 
254  for(ossim_uint32 i = 0; i < theMultiPolygon.size(); ++i)
255  {
256  out << "____________________________________________________"<<endl
257  << theMultiPolygon[i] << endl;
258  }
259  out << "____________________________________________________"<<endl;
260  return out;
261 }
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
virtual std::ostream & print(std::ostream &out) const
Generic print method.
unsigned int ossim_uint32

◆ setFillFlag()

void ossimAnnotationMultiPolyObject::setFillFlag ( bool  flag)
inline

◆ setMultiPolygon()

virtual void ossimAnnotationMultiPolyObject::setMultiPolygon ( const vector< ossimPolygon > &  multiPoly)
inlinevirtual

Member Data Documentation

◆ theBoundingRect

ossimDrect ossimAnnotationMultiPolyObject::theBoundingRect
protected

◆ theFillEnabled

bool ossimAnnotationMultiPolyObject::theFillEnabled
protected

Definition at line 82 of file ossimAnnotationMultiPolyObject.h.

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

◆ theMultiPolygon

vector<ossimPolygon> ossimAnnotationMultiPolyObject::theMultiPolygon
protected

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