OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTrimFilter.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: ossimTrimFilter.cpp 9094 2006-06-13 19:12:40Z dburken $
14 #include <ossim/base/ossimTrace.h>
17 #include <ossim/base/ossimDpt.h>
18 
19 static ossimTrace traceDebug("ossimTrimFilter:debug");
20 
22  "ossimTrimFilter",
24 
27  theLeftPercent(0.0),
28  theRightPercent(0.0),
29  theTopPercent(0.0),
30  theBottomPercent(0.0)
31 {
33 }
34 
36 {
37  theCutter = 0;
38 }
39 
41  const ossimIrect& rect,
42  ossim_uint32 resLevel)
43 {
45  {
46  return NULL;
47  }
48 
49  if(!theValidVertices.size())
50  {
51  return ossimImageSourceFilter::getTile(rect, resLevel);
52  }
53 
55  theCutter->getTile(rect, resLevel);
56 
57  if(!isSourceEnabled()||!tile.valid())
58  {
59  return tile;
60  }
61  if(tile->getDataObjectStatus() == OSSIM_NULL ||
63  {
64  return tile;
65  }
66 
67  return theCutter->getTile(rect, resLevel);
68 // theTile->setImageRectangle(rect);
69 // theTile->setDataObjectStatus(OSSIM_FULL);
70 
71 // theTile->makeBlank();
72 // ossimIrect boundingRect = getBoundingRect(resLevel);
73 // ossimIrect tileRect = tile->getImageRectangle();
74 // ossimIrect clipRect = boundingRect.clipToRect(tileRect);
75 
76 // theTile->loadTile(tile->getBuf(),
77 // tile->getImageRectangle(),
78 // clipRect,
79 // OSSIM_BSQ);
80 
81 // theTile->validate();
82 
83 }
84 
86  vector<ossimIpt>& validVertices,
87  ossimVertexOrdering ordering,
88  ossim_uint32 resLevel)const
89 {
91  ordering,
92  resLevel);
93  if(validVertices.size()==4)
94  {
95  ossimDpt averagePt((ossimDpt(validVertices[0])+
96  ossimDpt(validVertices[1])+
97  ossimDpt(validVertices[2])+
98  ossimDpt(validVertices[3]))*.25);
99  ossimDpt averageTop( ( ossimDpt(validVertices[0]+
100  validVertices[1])*.5) );
101  ossimDpt averageBottom( ( ossimDpt(validVertices[2]+
102  validVertices[3])*.5 ) );
103  ossimDpt averageLeft( (ossimDpt(validVertices[0]+
104  validVertices[3])*.5) );
105  ossimDpt averageRight( (ossimDpt(validVertices[1]+
106  validVertices[2])*.5) );
107 
108  ossimDpt topAxis = (averageTop-averagePt);
109  ossimDpt rightAxis = (averageRight-averagePt);
110  ossimDpt leftAxis = (averageLeft-averagePt);
111  ossimDpt bottomAxis = (averageBottom-averagePt);
112 
113  double topLen = topAxis.length();
114  double bottomLen = bottomAxis.length();
115  double rightLen = rightAxis.length();
116  double leftLen = leftAxis.length();
117 
118  if((topLen > FLT_EPSILON)&&
119  (bottomLen > FLT_EPSILON)&&
120  (leftLen > FLT_EPSILON)&&
121  (rightLen > FLT_EPSILON))
122  {
123  topAxis = topAxis*(1.0/topLen);
124  bottomAxis = bottomAxis*(1.0/bottomLen);
125  leftAxis = leftAxis*(1.0/leftLen);
126  rightAxis = rightAxis*(1.0/rightLen);
127 
128  ossim_uint32 idx = 0;
129  ossim_uint32 count = 0;
130  for(idx = 0; idx < validVertices.size(); ++idx)
131  {
132  ossimDpt axis[2];
133  double axisLen[2];
134  ossimDpt diff = validVertices[idx]-averagePt;
135  double testLen = (topAxis.x*diff.x+
136  topAxis.y*diff.y);
137  count = 0;
138  if(testLen >= -FLT_EPSILON)
139  {
140  axis[count] = topAxis;
141  axisLen[count] = testLen*(1.0-theTopPercent);
142  ++count;
143  }
144 
145  if(count < 2)
146  {
147  testLen = (bottomAxis.x*diff.x+
148  bottomAxis.y*diff.y);
149  if(testLen >= -FLT_EPSILON)
150  {
151  axis[count] = bottomAxis;
152  axisLen[count] = testLen*(1.0-theBottomPercent);
153  ++count;
154  }
155  }
156  if(count < 2)
157  {
158  testLen = (leftAxis.x*diff.x+
159  leftAxis.y*diff.y);
160  if(testLen >= -FLT_EPSILON)
161  {
162  axis[count] = leftAxis;
163  axisLen[count] = testLen*(1.0-theLeftPercent);
164  ++count;
165  }
166  }
167  if(count < 2)
168  {
169  testLen = (rightAxis.x*diff.x+
170  rightAxis.y*diff.y);
171  if(testLen >= -FLT_EPSILON)
172  {
173  axis[count] = rightAxis;
174  axisLen[count] = testLen*(1.0-theRightPercent);
175  ++count;
176  }
177  }
178  if(count == 2)
179  {
180  validVertices[idx] = (averagePt + (axis[0]*axisLen[0] +
181  axis[1]*axisLen[1]));
182  }
183  }
184  }
185  }
186 // ossimIrect rect = getBoundingRect();
187 
188 // if(ordering == OSSIM_CLOCKWISE_ORDER)
189 // {
190 // validVertices.push_back(rect.ul());
191 // validVertices.push_back(rect.ur());
192 // validVertices.push_back(rect.lr());
193 // validVertices.push_back(rect.ll());
194 // }
195 // else
196 // {
197 // validVertices.push_back(rect.ul());
198 // validVertices.push_back(rect.ll());
199 // validVertices.push_back(rect.lr());
200 // validVertices.push_back(rect.ur());
201 // }
202 }
203 
205 {
206 
207  vector<ossimIpt> validVertices;
208  ossimIrect result;
209  result.makeNan();
210  getValidImageVertices(validVertices, OSSIM_CLOCKWISE_ORDER, resLevel);
211 
212  if(validVertices.size())
213  {
214  result = ossimIrect(validVertices);
215  }
216 
217  return result;
218 }
219 
221 {
223  {
224  theCutter->disconnectMyInput(0, false, false);
225  if(getInput())
226  {
228  }
233  }
234 }
235 
237  const char* prefix)const
238 {
239  kwl.add(prefix,
240  "left_percent",
242  true);
243  kwl.add(prefix,
244  "right_percent",
246  true);
247  kwl.add(prefix,
248  "top_percent",
250  true);
251  kwl.add(prefix,
252  "bottom_percent",
254  true);
255 
256  return ossimImageSourceFilter::saveState(kwl, prefix);
257 }
258 
260  const char* prefix)
261 {
262  const char* leftPerc = kwl.find(prefix, "left_percent");
263  const char* rightPerc = kwl.find(prefix, "right_percent");
264  const char* topPerc = kwl.find(prefix, "top_percent");
265  const char* bottomPerc = kwl.find(prefix, "bottom_percent");
266 
267  if(leftPerc)
268  {
269  theLeftPercent = ossimString(leftPerc).toDouble();
270  }
271  if(rightPerc)
272  {
273  theRightPercent = ossimString(rightPerc).toDouble();
274  }
275  if(topPerc)
276  {
277  theTopPercent = ossimString(topPerc).toDouble();
278  }
279  if(bottomPerc)
280  {
281  theBottomPercent = ossimString(bottomPerc).toDouble();
282  }
283 
284  return ossimImageSourceFilter::loadState(kwl, prefix);
285 }
286 
288 {
289  ossimProperty* prop = 0;
290  if(name == "left_percent")
291  {
292  prop = new ossimNumericProperty(name,
294  0.0, 1.0);
295  prop->setFullRefreshBit();
296  }
297  else if(name == "right_percent")
298  {
299  prop = new ossimNumericProperty(name,
301  0.0, 1.0);
302  prop->setFullRefreshBit();
303  }
304  else if(name == "top_percent")
305  {
306  prop = new ossimNumericProperty(name,
308  0.0, 1.0);
309  prop->setFullRefreshBit();
310  }
311  else if(name == "bottom_percent")
312  {
313  prop = new ossimNumericProperty(name,
315  0.0, 1.0);
316  prop->setFullRefreshBit();
317  }
318 
319  if(prop) return prop;
320 
322 }
323 
325 {
326  if(!property.valid())return;
327  ossimString name = property->getName();
328 
329  if(name == "left_percent")
330  {
331  theLeftPercent = property->valueToString().toDouble();
332  }
333  else if(name == "right_percent")
334  {
335  theRightPercent = property->valueToString().toDouble();
336  }
337  else if(name == "top_percent")
338  {
339  theTopPercent = property->valueToString().toDouble();
340  }
341  else if(name == "bottom_percent")
342  {
343  theBottomPercent = property->valueToString().toDouble();
344  }
345  else
346  {
347  return ossimImageSourceFilter::setProperty(property);
348  }
349 }
350 
351 void ossimTrimFilter::getPropertyNames(std::vector<ossimString>& propertyNames)const
352 {
353  propertyNames.push_back("left_percent");
354  propertyNames.push_back("right_percent");
355  propertyNames.push_back("top_percent");
356  propertyNames.push_back("bottom_percent");
357 }
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossimRefPtr< ossimConnectableObject > disconnectMyInput(ossim_int32 inputIndex, bool disconnectOutputFlag=true, bool createEventFlag=true)
Will disconnect the object at the given input index and generate a connection event.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Set property.
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
double y
Definition: ossimDpt.h:165
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ~ossimTrimFilter()
double length() const
Definition: ossimDpt.h:81
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
Method to save the state of an object to a keyword list.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Adds this objects properties to the list.
void setFullRefreshBit()
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimVertexOrdering
#define FLT_EPSILON
std::vector< ossimIpt > theValidVertices
virtual void getValidImageVertices(std::vector< ossimIpt > &validVertices, ossimVertexOrdering ordering=OSSIM_CLOCKWISE_ORDER, ossim_uint32 resLevel=0) const
ordering specifies how the vertices should be arranged.
virtual void setPolygon(const vector< ossimDpt > &polygon, ossim_uint32 i=0)
ossimImageSource * theInputConnection
unsigned int ossim_uint32
ossimRefPtr< ossimPolyCutter > theCutter
virtual void getValidImageVertices(vector< ossimIpt > &validVertices, ossimVertexOrdering ordering=OSSIM_CLOCKWISE_ORDER, ossim_uint32 resLevel=0) const
double toDouble() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual void initialize()
RTTI_DEF1(ossimTrimFilter, "ossimTrimFilter", ossimImageSourceFilter)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
void makeNan()
Definition: ossimIrect.h:329
virtual void initialize()
double x
Definition: ossimDpt.h:164
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual void setNumberOfPolygons(ossim_uint32 count)
ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)