OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRectangleCutFilter.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: ossimRectangleCutFilter.cpp 22953 2014-11-05 19:19:28Z dburken $
13 #include <ossim/base/ossimTrace.h>
15 #include <ossim/base/ossimCommon.h>
18 
19 static ossimTrace traceDebug("ossimRectangleCutFilter:debug");
20 
22  "ossimRectangleCutFilter",
24 
26  ossimImageSource* inputSource)
27  :ossimImageSourceFilter(owner, inputSource),
28  theCutType(OSSIM_RECTANGLE_NULL_OUTSIDE)
29 {
31 }
32 
34  :ossimImageSourceFilter(NULL, inputSource),
35  theCutType(OSSIM_RECTANGLE_NULL_OUTSIDE)
36 {
38 }
39 
40 
42  const ossimIrect& rect,
43  ossim_uint32 resLevel)
44 {
46 
47  if ( theInputConnection && isSourceEnabled() && ( theRectangle.hasNans() == false ) )
48  {
49  ossim_int32 decimationIndex = min((ossim_int32)resLevel,
50  (ossim_int32)theDecimationList.size()-1);
51 
52  // Compute cut rect for resLevel:
53  ossimIrect cutRect = theRectangle*theDecimationList[decimationIndex];
54 
55  // Check intersection of our cut rect:
56  bool requestIntersects = rect.intersects( cutRect );
57  bool requestCompletelyWithin = rect.completely_within(cutRect);
58 
59  if ( ( ( theCutType == OSSIM_RECTANGLE_NULL_OUTSIDE ) && requestIntersects ) ||
60  ( ( theCutType == OSSIM_RECTANGLE_NULL_INSIDE ) && !requestCompletelyWithin ) )
61  {
62  // Grab tile from the input.
63  tile = theInputConnection->getTile(rect, resLevel);
64 
65  if ( tile.valid() )
66  {
67  if ( tile->getDataObjectStatus() != OSSIM_NULL &&
68  tile->getDataObjectStatus() != OSSIM_EMPTY )
69  {
70  ossimIrect inputRectangle = tile->getImageRectangle();
71 
72  if( theCutType == OSSIM_RECTANGLE_NULL_OUTSIDE ) // Typical case...
73  {
74  if ( !requestCompletelyWithin )
75  {
76  // Clip the tile:
77  ossim_int32 ulx = inputRectangle.ul().x;
78  ossim_int32 uly = inputRectangle.ul().y;
79  ossim_int32 w = tile->getWidth();
80  ossim_int32 h = tile->getHeight();
81  ossim_int32 offset = 0;
82  ossimIpt tempPoint(ulx, uly);
83 
84  for(ossim_int32 y = 0; y < h; ++tempPoint.y,++y)
85  {
86  tempPoint.x = ulx;
87  for(ossim_int32 x = 0; x < w; ++tempPoint.x,++x)
88  {
89  if(!cutRect.pointWithin(tempPoint))
90  {
91  tile->setNull(offset);
92  }
93  ++offset;
94  }
95  }
96  tile->validate();
97  }
98  }
99  else // Null inside...
100  {
101  // Note if complete within requested rect this block was bypassed entirely.
102  ossim_int32 ulx = inputRectangle.ul().x;
103  ossim_int32 uly = inputRectangle.ul().y;
104  ossim_int32 w = tile->getWidth();
105  ossim_int32 h = tile->getHeight();
106  ossim_int32 offset = 0;
107  ossimIpt tempPoint(ulx, uly);
108 
109  for(ossim_int32 y = 0; y < h; ++tempPoint.y,++y)
110  {
111  tempPoint.x = ulx;
112  for(ossim_int32 x = 0; x < w; ++tempPoint.x,++x)
113  {
114  if(cutRect.pointWithin(tempPoint))
115  {
116  tile->setNull(offset);
117  }
118  ++offset;
119  }
120  }
121  tile->validate();
122  }
123 
124  } // Matches: if ( tile->getDataObjectStatus() ...
125 
126  } // Matches: if ( tile.valid() )
127 
128  } // Matches: if ( ( ( theCutType == OSSI ...
129 
130  } // Matches: if ( theInputConnection && enabled && ...
131 
132  return tile;
133 } // End: ossimRectangleCutFilter::getTile( ... )
134 
136 {
137  theRectangle = rect;
138 
139  if(theRectangle.hasNans())
140  {
142  {
144  }
145  }
146 }
147 
149  vector<ossimIpt>& validVertices,
150  ossimVertexOrdering ordering,
151  ossim_uint32 /* resLevel */)const
152 {
153  ossimIrect rect = getBoundingRect();
154 
155  if(ordering == OSSIM_CLOCKWISE_ORDER)
156  {
157  validVertices.push_back(rect.ul());
158  validVertices.push_back(rect.ur());
159  validVertices.push_back(rect.lr());
160  validVertices.push_back(rect.ll());
161  }
162  else
163  {
164  validVertices.push_back(rect.ul());
165  validVertices.push_back(rect.ll());
166  validVertices.push_back(rect.lr());
167  validVertices.push_back(rect.ur());
168  }
169 }
170 
172 {
173  if(traceDebug())
174  {
175  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimRectangleCutFilter::getBoundingRect DEBUG: entered..." << std::endl;
176  }
177  ossimIrect result;
178 
179  result.makeNan();
180  if(!theInputConnection)
181  {
182  if(traceDebug())
183  {
184  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimRectangleCutFilter::getBoundingRect DEBUG: Input connection was not valid so leaving" << std::endl;
185  }
186  return result;
187  }
188 
189  result = theInputConnection->getBoundingRect(resLevel);
190  if(isSourceEnabled())
191  {
193  {
194  ossimDpt decimation;
195  getDecimationFactor(resLevel, decimation);
196  ossimIrect cutRect = theRectangle;
197  if(!decimation.hasNans())
198  {
199  cutRect = theRectangle*decimation;
200  }
201  result = cutRect;
202  }
203  }
204 
205  if(traceDebug())
206  {
207  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimRectangleCutFilter::getBoundingRect DEBUG: cut rect = " << result << std::endl;
208  }
209  return result;
210 }
211 
213 {
214  theDecimationList.clear();
216  {
218  }
219  if(theDecimationList.empty())
220  {
221  theDecimationList.push_back(ossimDpt(1,1));
222  }
223  if(theRectangle.hasNans())
224  {
226  }
227 }
228 
230  const char* prefix)const
231 {
232  ossimString newPrefix = prefix;
233  newPrefix+="clip_rect.";
234 
235  theRectangle.saveState(kwl, newPrefix);
236 
238  {
239  kwl.add(prefix,
240  "cut_type",
241  "null_inside",
242  true);
243  }
245  {
246  kwl.add(prefix,
247  "cut_type",
248  "null_outside",
249  true);
250  }
251 
252  return ossimImageSourceFilter::saveState(kwl, prefix);
253 }
254 
256  const char* prefix)
257 {
258  ossimString newPrefix = prefix;
259 
260  ossimString rect = kwl.find(prefix, "rect");
261  if(!rect.empty())
262  {
263  theRectangle.toRect(rect);
264  }
265  else
266  {
267  newPrefix+="clip_rect.";
268 
269  theRectangle.loadState(kwl, newPrefix.c_str());
270  }
271 
272  const char* cutType = kwl.find(prefix, "cut_type");
273  if(cutType)
274  {
275  ossimString c = cutType;
276  if(c == "null_inside")
277  {
279  }
280  else if(c == "null_outside")
281  {
283  }
284  else
285  {
286  theCutType = static_cast<ossimRectangleCutType>(ossimString(cutType).toLong());
287  }
288  }
289 
290  return ossimImageSourceFilter::loadState(kwl, prefix);
291 }
292 
294 {
295  return theRectangle;
296 }
297 
299 {
300  return theCutType;
301 }
302 
304 {
305  theCutType = cutType;
306 }
void setRectangle(const ossimIrect &rect)
ossimRectangleCutType theCutType
vector< ossimDpt > theDecimationList
virtual ossim_uint32 getWidth() const
ossim_uint32 x
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Definition: ossimIrect.cpp:589
Represents serializable keyword/value map.
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
const ossimIpt & ll() const
Definition: ossimIrect.h:277
bool completely_within(const ossimIrect &rect) const
Definition: ossimIrect.cpp:425
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
void setCutType(ossimRectangleCutType cutType)
ossimVertexOrdering
virtual ossimDataObjectStatus validate() const
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Definition: ossimIrect.cpp:641
ossimImageSource * theInputConnection
unsigned int ossim_uint32
ossimRectangleCutFilter(ossimObject *owner, ossimImageSource *inputSource=NULL)
virtual ossimIrect getImageRectangle() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
Method to save the state of an object to 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.
const ossimIpt & lr() const
Definition: ossimIrect.h:276
bool hasNans() const
Definition: ossimDpt.h:67
ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
void setNull(ossim_uint32 offset)
const ossimIpt & ur() const
Definition: ossimIrect.h:275
const ossimIrect & getRectangle() const
long toLong() const
toLong&#39;s deprecated, please use the toInts...
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossim_int32 y
Definition: ossimIpt.h:142
void makeNan()
Definition: ossimIrect.h:329
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
bool toRect(const ossimString &rectString)
expected Format: form 1: ( 30, -90, 512, 512, [LH|RH] ) -x- -y- -w- -h- -Right or left handed- ...
Definition: ossimIrect.cpp:359
bool hasNans() const
Definition: ossimIrect.h:337
ossim_int32 x
Definition: ossimIpt.h:141
virtual void getDecimationFactor(ossim_uint32 resLevel, ossimDpt &result) const
Will return the decimation factor for the given resolution level.
virtual void getValidImageVertices(vector< ossimIpt > &validVertices, ossimVertexOrdering ordering=OSSIM_CLOCKWISE_ORDER, ossim_uint32 resLevel=0) const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual void getDecimationFactors(std::vector< ossimDpt > &decimations) const
Will return an array of all decimations for each resolution level.
#define min(a, b)
Definition: auxiliary.h:75
ossimRectangleCutType getCutType() const
int ossim_int32
RTTI_DEF1(ossimRectangleCutFilter, "ossimRectangleCutFilter", ossimImageSourceFilter)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)