OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTiledImagePatch.cpp
Go to the documentation of this file.
1 //---
2 // License: MIT
3 //
4 // Author: David Burken
5 //
6 // Description:
7 //
8 // Class to fill a patch from input tiles requested on even tile boundaries with
9 // a tile size typically matching the input, with some output tile size
10 // different from the input.
11 //
12 //---
13 // $Id$
14 
16 #include <ossim/base/ossimIrect.h>
18 
20 
22  :
23  ossimImageSourceFilter(), // base class
24  m_tile(0),
25  m_inputTileSize()
26 {
27  m_inputTileSize.makeNan();
28 }
29 
31 {
32 }
33 
35 {
36  //---
37  // Call the base class initialize.
38  // Note: This will reset "theInputConnection" if it changed...
39  //---
41 
42  // Clear everything. The tile will be allocated on first getTile call.
43  m_tile = 0;
44 
45  // Get the input tile sizes:
46  if ( theInputConnection )
47  {
48  if ( m_inputTileSize.hasNans() )
49  {
52  }
53  }
54 }
55 
57  const ossimIrect& tileRect, ossim_uint32 resLevel)
58 {
59  if ( m_tile.valid() == false )
60  {
61  allocateTile(); // First time through...
62  }
63 
64  if ( m_tile.valid() )
65  {
66  // Image rectangle must be set prior to calling getTile.
67  m_tile->setImageRectangle(tileRect);
68 
69  if ( getTile( m_tile.get(), resLevel ) == false )
70  {
72  {
73  m_tile->makeBlank();
74  }
75  }
76  }
77 
78  return m_tile;
79 }
80 
82 {
83  bool status = false;
84 
85  if ( isSourceEnabled() && theInputConnection && isValidRLevel(resLevel) &&
86  result && (m_inputTileSize.hasNans() == false) )
87  {
88  status = true;
89 
90  // See if any point of the requested tile is in the image.
91  ossimIrect tile_rect = result->getImageRectangle();
92 
93  ossimIrect input_rect;
94  theInputConnection->getBoundingRect( input_rect, resLevel );
95 
96  if ( tile_rect.intersects( input_rect ) )
97  {
98  // Initialize the tile if needed as we're going to stuff it.
99  if (result->getDataObjectStatus() == OSSIM_NULL)
100  {
101  result->initialize();
102  }
103 
104  // If empty imput tiles are pulled the entire output tile might not be filled.
105  result->makeBlank();
106 
107  // Clip rect:
108  ossimIrect clip_rect = tile_rect.clipToRect( input_rect );
109 
110  // Zero based start point.
111  ossimIpt inputOrigin = clip_rect.ul() - input_rect.ul();
112 
113  // Zero based point on input tile boundary.
114  inputOrigin.x = (inputOrigin.x / m_inputTileSize.x) * m_inputTileSize.x;
115  inputOrigin.y = (inputOrigin.y / m_inputTileSize.y) * m_inputTileSize.y;
116 
117  // Shift back to original space:
118  inputOrigin += input_rect.ul();
119 
120  // Line loop:
121  for ( ossim_int32 y = inputOrigin.y; y < clip_rect.lr().y; y += m_inputTileSize.y )
122  {
123  // Sample loop:
124  for ( ossim_int32 x = inputOrigin.x; x < clip_rect.lr().x; x += m_inputTileSize.x )
125  {
126  ossimIrect rect( x, y, x + m_inputTileSize.x - 1, y + m_inputTileSize.y - 1 );
127 
128  ossimRefPtr<ossimImageData> tile = theInputConnection->getTile( rect, resLevel );
129  if ( tile.valid() )
130  {
131  if ( (tile->getDataObjectStatus() != OSSIM_NULL) &&
132  (tile->getDataObjectStatus() != OSSIM_EMPTY) )
133  {
134  result->loadTile( tile.get() );
135  }
136  }
137  }
138  }
139 
140  result->validate();
141 
142  }
143  else
144  {
145  // No part of requested tile within the image rectangle.
146  result->makeBlank();
147  }
148 
149  } // matches: if( isOpen() && isSourceEnabled() && isValidRLevel(level) )
150 
151  return status;
152 }
153 
155 {
156  return ossimString("ossimTiledImagePatch");
157 }
158 
160 {
161  return ossimString("OSSIM tiled image patch");
162 }
163 
165 {
166  return ossimString("tiled_image_patch");
167 }
168 
170 {
171  return m_inputTileSize;
172 }
173 
175 {
176  bool status = true;
177  if ( ( tileSize.hasNans() == false ) && (tileSize.x > 0) && (tileSize.y > 0) )
178  {
179  m_inputTileSize = tileSize;
180  }
181  else
182  {
184  status = false;
185  }
186  return status;
187 }
188 
189 bool ossimTiledImagePatch::loadState(const ossimKeywordlist& kwl, const char* prefix)
190 {
191  std::string myPrefix = (prefix ? prefix : "" );
192  std::string key = "tile_size";
193  std::string value = kwl.findKey( myPrefix, key );
194  if ( value.size() )
195  {
196  m_inputTileSize.toPoint( value );
197  }
198  return ossimImageSourceFilter::loadState(kwl, prefix);
199 }
200 
201 bool ossimTiledImagePatch::saveState(ossimKeywordlist& kwl, const char* prefix)const
202 {
203  std::string myPrefix = (prefix ? prefix : "" );
204  std::string key = "tile_size";
205  kwl.addPair( myPrefix, key, m_inputTileSize.toString().string() );
206  return ossimImageSourceFilter::saveState(kwl, prefix);
207 }
208 
210 {
212  m_tile->initialize();
213 }
214 
216 {
217  // return (resLevel < m_inputBoundingRect.size());
218  return (resLevel < theInputConnection->getNumberOfDecimationLevels());
219 }
220 
221 // Private to disallow use...
223  : m_tile(0),
224  m_inputTileSize()
225 {
226 }
227 
228 // Private to disallow use...
230 {
231  return *this;
232 }
233 
234 
ossimString toString() const
Definition: ossimIpt.cpp:139
ossim_uint32 x
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ~ossimTiledImagePatch()
virtual protected destructor
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
void makeNan()
Definition: ossimIpt.h:56
ossimTiledImagePatch()
default constructor
virtual void setImageRectangle(const ossimIrect &rect)
Represents serializable keyword/value map.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
virtual ossimString getClassName() const
Class to fill a patch from input tiles requested on even tile boundaries with a tile size typically m...
const ossimIpt & getInputTileSize() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
Returns a pointer to a tile given an origin representing the upper left corner of the tile to grab fr...
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
virtual void initialize()
Initializes bounding rects and tile size(if not set) from input.
virtual ossim_uint32 getNumberOfDecimationLevels() const
Will return the number of resolution levels.
virtual ossimString getLongName() const
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
virtual void initialize()
Initialize the data buffer.
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
bool isValidRLevel(ossim_uint32 resLevel) const
Test the bounds of resLevel.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
void allocateTile()
Allocates the tile.
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
static ossimImageDataFactory * instance()
ossimTiledImagePatch & operator=(const ossimTiledImagePatch &)
Private to disallow use...
virtual ossimDataObjectStatus validate() const
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual ossimIrect getImageRectangle() const
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
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load the class state from a keyword list.
void toPoint(const std::string &s)
Initializes this point from string.
Definition: ossimIpt.cpp:170
return status
virtual void makeBlank()
Initializes data to null pixel values.
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
ossimRefPtr< ossimImageData > m_tile
ossim_int32 x
Definition: ossimIpt.h:141
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
bool setInputTileSize(const ossimIpt &tileSize)
Sets the input tile size.
bool hasNans() const
Definition: ossimIpt.h:58
virtual ossimString getShortName() const
int ossim_int32
const std::string & string() const
Definition: ossimString.h:414
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)