OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimSubImageTileSource.cpp
Go to the documentation of this file.
1 //*****************************************************************************
2 // FILE: ossimSubImageTileSource.cc
3 //
4 // Copyright (C) 2001 ImageLinks, Inc.
5 //
6 // License: LGPL
7 //
8 // See LICENSE.txt file in the top level directory for more details.
9 //
10 // AUTHOR: Oscar Kramer
11 //
12 // DESCRIPTION: Contains implementation of class ossimSubImageTileSource.
13 // This tile source permits specifying an offset that is to be applied to the
14 // tile origin for all getTile() requests. It is intended for converting
15 // a full-image space coordinate to a sub-image coordinate.
16 //
17 // LIMITATIONS: None.
18 //
19 //*****************************************************************************
20 // $Id: ossimSubImageTileSource.cpp 17206 2010-04-25 23:20:40Z dburken $
21 
23 #include <ossim/base/ossimDrect.h>
26 
28  "ossimSubImageTileSource",
30 
31 static const char* SUBIMAGE_OFFSET_X = "offset_x";
32 static const char* SUBIMAGE_OFFSET_Y = "offset_y";
33 
36  theSubImageOffset(0, 0),
37  theTile(0)
38 {
39 }
40 
42  : ossimImageSourceFilter(inputSource), theSubImageOffset(0, 0),
43  theTile(0)
44 {
45 }
46 
48  const ossimIpt& offset)
49  : ossimImageSourceFilter(inputSource), theSubImageOffset(offset),
50  theTile(0)
51 {
52 }
53 
55 {
56 }
57 
58 //*****************************************************************************
59 // METHOD: ossimSubImageTileSource::getTile()
60 //
61 //*****************************************************************************
63  const ossimIrect& rect,
64  ossim_uint32 res_level)
65 {
66  ossimIpt offset = theSubImageOffset;
67 
68  if(res_level)
69  {
70  //***
71  // Determine the offset for the particular rr level requested:
72  //***
73  ossimDpt decimation_factor;
74  theInputConnection->getDecimationFactor(res_level, decimation_factor);
75 
76  if(!decimation_factor.hasNans())
77  {
78  offset = ossimIpt((int)(theSubImageOffset.x*decimation_factor.x + 0.5),
79  (int)(theSubImageOffset.y*decimation_factor.y + 0.5));
80  }
81  else
82  {
83  offset = theSubImageOffset;
84  }
85  }
86  //
87  // Apply the offset to the requested rect and fetch tile. The tile's origin
88  // needs to be adjusted to reflect the requested origin:
89  //
90  ossimIrect rect_prime (rect - offset);
91 
93  ossimImageSourceFilter::getTile(rect_prime, res_level);
94 
95  if(theTile.valid())
96  {
97  theTile->setImageRectangle(rect_prime);
98 
99  if(tile.valid())
100  {
101  theTile->loadTile(tile.get());
102  }
103  else
104  {
105  theTile->makeBlank();
106  }
107  }
108  else
109  {
110  if(tile.valid())
111  {
112  theTile = (ossimImageData*)tile->dup();
113  }
114  }
115  if(theTile.valid())
116  {
117  theTile->setOrigin(rect.ul());
118  theTile->validate();
119  }
120 
121  return theTile;
122 }
123 
124 //*****************************************************************************
125 // METHOD: ossimSubImageTileSource::getBoundingRect()
126 //
127 //*****************************************************************************
129 {
130  ossimDrect result;
131 
132  result.makeNan();
133  if(!theInputConnection)
134  return result;
135  ossimDpt offset = theSubImageOffset;
136 
138  if(resLevel)
139  {
140  ossimDpt decimation_factor;
141  theInputConnection->getDecimationFactor(resLevel, decimation_factor);
142 
143  if(!decimation_factor.hasNans())
144  {
145  rect*=decimation_factor;
146  offset= ossimDpt(theSubImageOffset.x*decimation_factor.x,
147  theSubImageOffset.y*decimation_factor.y);
148  }
149  }
150  ossimDrect rect_prime (rect + offset);
151 
152  return rect_prime;
153 }
154 
155 //*****************************************************************************
156 // METHOD: ossimSubImageTileSource::getValidImageVertices()
157 //
158 //*****************************************************************************
159 void ossimSubImageTileSource::getValidImageVertices(vector<ossimIpt>& vertices,
160  ossimVertexOrdering ordering,
161  ossim_uint32 /* resLevel */) const
162 {
163  if(!theInputConnection)
164  {
165  vertices.clear();
166  return;
167  }
168 
169  ossimDpt offset (theSubImageOffset);
170 
171  theInputConnection->getValidImageVertices(vertices, ordering);
172  vector<ossimIpt>::iterator vertex = vertices.begin();
173 
174  while (vertex != vertices.end())
175  {
176  (*vertex) += offset;
177  vertex++;
178  }
179 
180  return;
181 }
182 
184 {
186 
187  theTile = NULL;
188 }
189 
191  const char* prefix)
192 {
193  const char* offset_x = kwl.find(prefix, SUBIMAGE_OFFSET_X);
194  const char* offset_y = kwl.find(prefix, SUBIMAGE_OFFSET_Y);
195 
196  if(offset_x)
197  {
198  theSubImageOffset.x = ossimString(offset_x).toLong();
199 
200  }
201  if(offset_y)
202  {
203  theSubImageOffset.y = ossimString(offset_y).toLong();
204  }
205 
206  return ossimImageSourceFilter::loadState(kwl, prefix);
207 }
208 
210  const char* prefix)const
211 {
212  bool result = ossimImageSourceFilter::saveState(kwl, prefix);
213 
214  kwl.add(prefix,
215  SUBIMAGE_OFFSET_X,
217  true);
218 
219  kwl.add(prefix,
220  SUBIMAGE_OFFSET_Y,
222  true);
223 
224  return result;
225 }
void makeNan()
Definition: ossimDrect.h:388
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 rr_level=0)
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual void setImageRectangle(const ossimIrect &rect)
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
double y
Definition: ossimDpt.h:165
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimObject * dup() const
ossimRefPtr< ossimImageData > theTile
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
ossimVertexOrdering
virtual ossimDataObjectStatus validate() const
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.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) 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.
RTTI_DEF1(ossimSubImageTileSource, "ossimSubImageTileSource", ossimImageSourceFilter)
bool hasNans() const
Definition: ossimDpt.h:67
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 void setOrigin(const ossimIpt &origin)
virtual void makeBlank()
Initializes data to null pixel values.
long toLong() const
toLong&#39;s deprecated, please use the toInts...
virtual void getValidImageVertices(vector< ossimIpt > &validVertices, ossimVertexOrdering ordering=OSSIM_CLOCKWISE_ORDER, ossim_uint32 resLevel=0) const
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
double x
Definition: ossimDpt.h:164
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 ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)