forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ossimAnnotationMultiEllipseObject.cpp
224 lines (200 loc) · 6.24 KB
/
ossimAnnotationMultiEllipseObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//*******************************************************************
//
// License: See top level LICENSE.txt file.
//
// Author: Garrett Potts
//
//*************************************************************************
// $Id: ossimAnnotationMultiEllipseObject.cpp 17195 2010-04-23 17:32:18Z dburken $
#include <ossim/imaging/ossimAnnotationMultiEllipseObject.h>
ossimAnnotationMultiEllipseObject::ossimAnnotationMultiEllipseObject
(const std::vector<ossimDpt>& pointList,
const ossimDpt& widthHeight,
bool enableFill,
unsigned char r,
unsigned char g,
unsigned char b,
long thickness)
:
ossimAnnotationObject(r, g, b, thickness),
thePointList(pointList),
theWidthHeight(widthHeight),
theFillFlag(enableFill)
{
computeBoundingRect();
}
ossimAnnotationMultiEllipseObject::ossimAnnotationMultiEllipseObject
(const ossimDpt& widthHeight,
bool enableFill,
unsigned char r,
unsigned char g,
unsigned char b,
long thickness)
:
ossimAnnotationObject(r, g, b, thickness),
theWidthHeight(widthHeight),
theFillFlag(enableFill)
{
theBoundingRect.makeNan();
}
ossimAnnotationMultiEllipseObject::ossimAnnotationMultiEllipseObject(const ossimAnnotationMultiEllipseObject& rhs)
:thePointList(rhs.thePointList),
theWidthHeight(rhs.theWidthHeight),
theFillFlag(rhs.theFillFlag),
theBoundingRect(rhs.theBoundingRect)
{
}
ossimObject* ossimAnnotationMultiEllipseObject::dup()const
{
return new ossimAnnotationMultiEllipseObject(*this);
}
ossimAnnotationMultiEllipseObject::~ossimAnnotationMultiEllipseObject()
{}
ossimAnnotationObject* ossimAnnotationMultiEllipseObject::getNewClippedObject(
const ossimDrect& /* rect */)const
{
ossimNotify(ossimNotifyLevel_WARN)
<< "ossimAnnotationMultiEllipseObject::getNewClippedObject WARNING: Not implemented"
<< std::endl;
return NULL;
}
void ossimAnnotationMultiEllipseObject::applyScale(double x, double y)
{
int i;
int upper = (int)thePointList.size();
for(i = 0; i < upper; ++i)
{
thePointList[i].x *= x;
thePointList[i].y *= y;
}
theWidthHeight.x *= x;
theWidthHeight.y *= y;
computeBoundingRect();
}
void ossimAnnotationMultiEllipseObject::draw(ossimRgbImage& anImage)const
{
anImage.setDrawColor(theRed, theGreen, theBlue);
anImage.setThickness(theThickness);
ossimDrect imageRect = anImage.getImageData()->getImageRectangle();
if(theBoundingRect.intersects(imageRect))
{
int i;
int upper = (int)thePointList.size();
if(theFillFlag)
{
for(i = 0; i < upper; ++i)
{
ossimDpt tempPoint = thePointList[i];
ossimDrect tempRect(ossimDpt(tempPoint.x - theWidthHeight.x,
tempPoint.y - theWidthHeight.y),
ossimDpt(tempPoint.x + theWidthHeight.x,
tempPoint.y + theWidthHeight.y));
if(tempRect.intersects(imageRect))
{
anImage.drawFilledArc(ossim::round<int>(tempPoint.x),
ossim::round<int>(tempPoint.y),
ossim::round<int>(theWidthHeight.x),
ossim::round<int>(theWidthHeight.y),
0,
360);
}
}
}
else
{
for(i = 0; i < upper; ++i)
{
ossimDpt tempPoint = thePointList[i];
ossimDrect tempRect(ossimDpt(tempPoint.x - theWidthHeight.x,
tempPoint.y - theWidthHeight.y),
ossimDpt(tempPoint.x + theWidthHeight.x,
tempPoint.y + theWidthHeight.y));
if(tempRect.intersects(imageRect))
{
anImage.drawArc(ossim::round<int>(tempPoint.x),
ossim::round<int>(tempPoint.y),
ossim::round<int>(theWidthHeight.x),
ossim::round<int>(theWidthHeight.y),
0,
360);
}
}
}
}
}
bool ossimAnnotationMultiEllipseObject::intersects(const ossimDrect& rect)const
{
return rect.intersects(theBoundingRect);
}
std::ostream& ossimAnnotationMultiEllipseObject::print(std::ostream& out)const
{
ossimNotify(ossimNotifyLevel_NOTICE)
<< "ossimAnnotionMultiEllipseObject::print NOT IMPLEMENTED"
<< endl;
return out;
}
void ossimAnnotationMultiEllipseObject::getBoundingRect(ossimDrect& rect)const
{
rect = theBoundingRect;
}
void ossimAnnotationMultiEllipseObject::computeBoundingRect()
{
theBoundingRect.makeNan();
int i;
int upper = (int)thePointList.size();
for(i = 0; i < upper; ++i)
{
ossimDpt tempPoint = thePointList[i];
if(!tempPoint.hasNans())
{
ossimDrect tempRect(ossimDpt(tempPoint.x - theWidthHeight.x,
tempPoint.y - theWidthHeight.y),
ossimDpt(tempPoint.x + theWidthHeight.x,
tempPoint.y + theWidthHeight.y));
if(!theBoundingRect.hasNans())
{
theBoundingRect.combine(tempRect);
}
else
{
theBoundingRect = tempRect;
}
}
}
}
bool ossimAnnotationMultiEllipseObject::isPointWithin(const ossimDpt& imagePoint)const
{
if(!theBoundingRect.hasNans())
{
return theBoundingRect.pointWithin(imagePoint);
}
return false;
}
void ossimAnnotationMultiEllipseObject::setFillFlag(bool flag)
{
theFillFlag = flag;
}
void ossimAnnotationMultiEllipseObject::resize(ossim_uint32 size)
{
if(size)
{
thePointList.resize(size);
}
else
{
thePointList.clear();
}
}
void ossimAnnotationMultiEllipseObject::setWidthHeight(const ossimDpt& widthHeight)
{
theWidthHeight = widthHeight;
computeBoundingRect();
}
ossimDpt& ossimAnnotationMultiEllipseObject::operator[](int i)
{
return thePointList[i];
}
const ossimDpt& ossimAnnotationMultiEllipseObject::operator[](int i)const
{
return thePointList[i];
}