OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTiledImageHash.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 // Description: Hashing function for tiled rectangles. WIll hash a
11 // dpt to a single index value.
12 //
13 //*******************************************************************
14 // $Id: ossimTiledImageHash.cpp 9094 2006-06-13 19:12:40Z dburken $
15 
16 #include <cfloat> // for FLT_EPSILON
17 
19 
20 
22  double tileWidth,
23  double tileHeight)
24  :ossimPointHash(),
25  theImageRect(imageRect)
26 {
27  // make sure that the width of the tile is not larger than
28  // the width of the image rectangle.
29  if(theImageRect.width() < tileWidth)
30  {
33  }
34  else
35  {
36  theTileWidth = tileWidth;
37  double tempDiv = theImageRect.width()/theTileWidth;
38  double overFlow = tempDiv - static_cast<long>(tempDiv);
39  theNumberOfHorizTiles = static_cast<long>(tempDiv);
40 
41  if(fabs(overFlow) >= FLT_EPSILON) // if the extent went beyond a tile
42  {
43  theNumberOfHorizTiles ++; // we must say it has another tile
44  }
45  }
46 
47  // make sure the height of the tile is not larger than the
48  // height of the image rectangle.
49  if(theImageRect.height() < tileHeight)
50  {
53  }
54  else
55  {
56  theTileHeight = tileHeight;
57  double tempDiv = theImageRect.height()/theTileHeight;
58  double overFlow = tempDiv - static_cast<long>(tempDiv);
59  theNumberOfVertTiles = static_cast<long>(tempDiv);
60 
61  if(fabs(overFlow) >= FLT_EPSILON) // if the extent went beyond a tile
62  {
63  theNumberOfVertTiles ++; // we must say it has another tile
64  }
65  }
66 
67 }
68 
70 {
71 }
72 
74 {
75  if(aPoint.x >= theImageRect.ul().x && aPoint.y >= theImageRect.ul().y)
76  {
77  // how far is the point horizontally from the upper left corner
78  double deltaWidth = aPoint.x - theImageRect.ul().x;
79 
80  // how far is the point vertically from the upper left point
81  double deltaHeight = aPoint.y - theImageRect.ul().y;
82 
83  // if deltas are negative then we are outside the
84  // bounds
85  if((deltaWidth < 0) || (deltaHeight < 0))
86  {
87  return -1;
88  }
89 
90  // check if outside the rectangle
91  if( (deltaWidth > theNumberOfHorizTiles*theTileWidth)||
92  (deltaHeight > theNumberOfVertTiles*theTileHeight))
93  {
94  return -1;
95  }
96  // solve the horizontal and vertical index numbers
97  long indexWidth = static_cast<long>(deltaWidth / theTileWidth);
98  long indexHeight = static_cast<long>(deltaHeight / theTileHeight);
99 
100  // map to a linear array. Just like you would index a 2-D array in memory
101  return static_cast<long>(theNumberOfHorizTiles*indexHeight + indexWidth);
102  }
103 
104  return -1;
105 }
106 
108 {
109  if(aPoint.x >= theImageRect.ul().x && aPoint.y >= theImageRect.ul().y)
110  {
111  // how far is the point horizontally from the upper left corner
112  double deltaWidth = aPoint.x - theImageRect.ul().x;
113 
114  // how far is the point vertically from the upper left point
115  double deltaHeight = aPoint.y - theImageRect.ul().y;
116 
117  // if deltas are negative then we are outside the
118  // bounds
119  if((deltaWidth < 0) || (deltaHeight < 0))
120  {
121  return -1;
122  }
123 
124  // check if outside the rectangle
125  if( (deltaWidth > theNumberOfHorizTiles*theTileWidth)||
126  (deltaHeight > theNumberOfVertTiles*theTileHeight))
127  {
128  return -1;
129  }
130  // solve the horizontal and vertical index numbers
131  long indexWidth = static_cast<long>(deltaWidth / theTileWidth);
132  long indexHeight = static_cast<long>(deltaHeight / theTileHeight);
133 
134  // map to a linear array. Just like you would index a 2-D array in memory
135  return static_cast<long>(theNumberOfHorizTiles*indexHeight + indexWidth);
136  }
137 
138  return -1;
139 }
140 
ossimTiledImageHash(const ossimDrect &imageRect, double tileWidth, double tileHeight)
ossim_float64 width() const
Definition: ossimDrect.h:522
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
ossim_float32 x
Definition: ossimFpt.h:70
#define FLT_EPSILON
ossim_float64 height() const
Definition: ossimDrect.h:517
double x
Definition: ossimDpt.h:164
ossim_float32 y
Definition: ossimFpt.h:71
virtual long operator()(const ossimDpt &aPoint)