OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTileHash.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: David Burken Copied from TiledImageHash.
9 //
10 // Description: Hashing function for tiled rectangles. WIll hash a
11 // dpt or a to a single index value.
12 //
13 // NOTE: This works with rectangles that are positive in the line up
14 // (y) direction.
15 //
16 //*******************************************************************
17 // $Id: ossimTileHash.cpp 9094 2006-06-13 19:12:40Z dburken $
18 
19 #include <cfloat> // for FLT_EPSILON
20 
22 
24  double tileWidth,
25  double tileHeight)
26  :
28  theImageRect(imageRect)
29 {
30  // make sure that the width of the tile is not larger than
31  // the width of the image rectangle.
32  if(theImageRect.width() <= tileWidth)
33  {
36  }
37  else
38  {
39  theTileWidth = tileWidth;
40  double tempDiv = theImageRect.width()/theTileWidth;
41  double overFlow = tempDiv - static_cast<long>(tempDiv);
42  theNumberOfHorizTiles = static_cast<long>(tempDiv);
43 
44  if(fabs(overFlow) > FLT_EPSILON) // if the extent went beyond a tile
45  {
46  theNumberOfHorizTiles ++; // we must say it has another tile
47  }
48  }
49 
50  // make sure the height of the tile is not larger than the
51  // height of the image rectangle.
52  if(theImageRect.height() <= tileHeight)
53  {
56  }
57  else
58  {
59  theTileHeight = tileHeight;
60  double tempDiv = theImageRect.height()/theTileHeight;
61  double overFlow = tempDiv - static_cast<long>(tempDiv);
62  theNumberOfVertTiles = static_cast<long>(tempDiv);
63 
64  if(fabs(overFlow) > FLT_EPSILON) // if the extent went beyond a tile
65  {
66  theNumberOfVertTiles ++; // we must say it has another tile
67  }
68  }
69 }
70 
72 {
73 }
74 
76 {
77  if ( (aPoint.x >= theImageRect.ul().x) &&
78  (aPoint.x <= theImageRect.lr().x) &&
79  (aPoint.y <= theImageRect.ul().y) &&
80  (aPoint.y >= theImageRect.lr().y) )
81  {
82  // how far is the point horizontally from the upper left corner
83  double deltaWidth = aPoint.x - theImageRect.ul().x;
84 
85  // how far is the point vertically from the upper left point
86  double deltaHeight = theImageRect.ul().y - aPoint.y;
87 
88  // solve the horizontal and vertical index numbers
89  long indexWidth = static_cast<long>(deltaWidth / theTileWidth);
90  long indexHeight = static_cast<long>(deltaHeight / theTileHeight);
91 
92  // Map to a linear array.
93  // Just like you would index a 2-D array in memory
94  return static_cast<long>(theNumberOfHorizTiles*indexHeight + indexWidth);
95  }
96 
97  return -1;
98 }
99 
101 {
102  if ( (aPoint.x >= theImageRect.ul().x) &&
103  (aPoint.x <= theImageRect.lr().x) &&
104  (aPoint.y <= theImageRect.ul().y) &&
105  (aPoint.y >= theImageRect.lr().y) )
106  {
107  // how far is the point horizontally from the upper left corner
108  double deltaWidth = aPoint.x - theImageRect.ul().x;
109 
110  // how far is the point vertically from the upper left point
111  double deltaHeight = theImageRect.ul().y - aPoint.y;
112 
113  // solve the horizontal and vertical index numbers
114  long indexWidth = static_cast<long>(deltaWidth / theTileWidth);
115  long indexHeight = static_cast<long>(deltaHeight / theTileHeight);
116 
117  // Map to a linear array.
118  // Just like you would index a 2-D array in memory
119  return static_cast<long>(theNumberOfHorizTiles*indexHeight + indexWidth);
120  }
121 
122  return -1;
123 }
ossim_float64 width() const
Definition: ossimDrect.h:522
virtual long operator()(const ossimDpt &aPoint)
long theNumberOfHorizTiles
Definition: ossimTileHash.h:42
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
double theTileHeight
Definition: ossimTileHash.h:41
ossimTileHash(const ossimDrect &imageRect, double tileWidth, double tileHeight)
double theTileWidth
Definition: ossimTileHash.h:40
ossim_float32 x
Definition: ossimFpt.h:70
#define FLT_EPSILON
long theNumberOfVertTiles
Definition: ossimTileHash.h:43
ossimDrect theImageRect
Definition: ossimTileHash.h:39
ossim_float64 height() const
Definition: ossimDrect.h:517
virtual ~ossimTileHash()
double x
Definition: ossimDpt.h:164
ossim_float32 y
Definition: ossimFpt.h:71
const ossimDpt & lr() const
Definition: ossimDrect.h:341