Evita  0.16
evBoundingBox.h
Go to the documentation of this file.
1 /*
2  *
3  * EVITA: Efficient Visualization of Terascale Datasets
4  * Copyright (C) 2000-2016 Team Evita
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
19  * MA 02139, USA.
20  *
21  */
22 
23 
24 #ifndef __evBoundingBox_h
25 #define __evBoundingBox_h
26 
27 
28 #include "evField.h"
29 #include "evAddress.h"
30 
31 
33 {
34 public:
35  evBoundingBox(void);
36  evBoundingBox(const unsigned int num_dimensions);
37  evBoundingBox(const evBoundingBox &bounding_box);
38  virtual ~evBoundingBox(void);
39 
40  virtual const evString GetClassName(void) const
41  {
42  return(evString("evBoundingBox"));
43  }
44 
45  void SetLowerBound(const evVector &lower_bound);
46  evVector GetLowerBound(void) const;
47 
48  void SetUpperBound(const evVector &upper_bound);
49  evVector GetUpperBound(void) const;
50 
51  void SetBounds(const evVector &lower_bound,
52  const evVector &upper_bound);
53 
54  evBoundingBox operator = (const evBoundingBox &bounding_box);
55 
56  evVector CalcUniformGrid(const evAddress &grid_coordinates,
57  const evAddress &size) const;
58 
59  double CalcPixelSize(const evAddress &size) const;
60 
61  int InsideViewFrustum(const evVector &frustum) const;
62 
63  void PrintSelf(const int tabbing) const;
64 
65 protected:
66 
67 private:
70 };
71 
72 
74 {
75 }
76 
77 
78 inline evBoundingBox::evBoundingBox(const unsigned int num_dimensions) :
79  LowerBound(num_dimensions), UpperBound(num_dimensions)
80 {
81 }
82 
83 
84 inline evBoundingBox::evBoundingBox(const evBoundingBox &bounding_box)
85 {
86  this->LowerBound = bounding_box.LowerBound;
87  this->UpperBound = bounding_box.UpperBound;
88 }
89 
90 
92 {
93 }
94 
95 
96 inline void evBoundingBox::SetLowerBound(const evVector &lower_bound)
97 {
98  this->LowerBound = lower_bound;
99 }
100 
101 
103 {
104  return(this->LowerBound);
105 }
106 
107 
108 inline void evBoundingBox::SetUpperBound(const evVector &upper_bound)
109 {
110  this->UpperBound = upper_bound;
111 }
112 
113 
115 {
116  return(this->UpperBound);
117 }
118 
119 
120 inline void evBoundingBox::SetBounds(const evVector &lower_bound,
121  const evVector &upper_bound)
122 {
123  this->SetLowerBound(lower_bound);
124  this->SetUpperBound(upper_bound);
125 }
126 
127 
129  &bounding_box)
130 {
131  this->LowerBound = bounding_box.LowerBound;
132  this->UpperBound = bounding_box.UpperBound;
133 
134  return(*this);
135 }
136 
137 
139  &grid_coordinates,
140  const evAddress &size) const
141 {
142  unsigned int num_dimensions = this->LowerBound.Dimension();
143 
144  evVector uniform_grid(num_dimensions);
145 
146  for (unsigned int component = 0; component < num_dimensions;
147  component++)
148  uniform_grid[component] =
149  (this->UpperBound[component] - this->LowerBound[component]) *
150  ((double)grid_coordinates[component] / (size[component] - 1)) +
151  this->LowerBound[component];
152  return(uniform_grid);
153 }
154 
155 
156 inline double evBoundingBox::CalcPixelSize(const evAddress &size) const
157 {
158  double pixel_size = -MAXDOUBLE;
159 
160  unsigned int num_dimensions = this->LowerBound.Dimension();
161 
162  for (unsigned int component = 0; component < num_dimensions;
163  component++)
164  if (size[component] > 1)
165  pixel_size = std::max(pixel_size,
166  std::fabs(this->UpperBound[component] -
167  this->LowerBound[component]) /
168  (size[component] - 1));
169 
170  return(pixel_size);
171 }
172 
173 
174 inline void evBoundingBox::PrintSelf(const int tabbing) const
175 {
176  evPrintWithTab(tabbing, "Lower Bound: ");
178  printf("\n");
179  evPrintWithTab(tabbing, "Upper Bound: ");
181  printf("\n");
182 }
183 
184 
185 inline int evBoundingBox::InsideViewFrustum(const evVector &frustum)
186  const
187 {
188  evVector diagonal = this->UpperBound - this->LowerBound;
189  evVector center = (diagonal / 2.0) + this->LowerBound;
190  double radius = diagonal.Norm() / 2;
191 
192  if (center.Dimension() >= 3)
193  for (unsigned int plane = 0; plane < 6; plane++)
194  {
195  double distance =
196  frustum[plane * 4 + 0] * center[0] +
197  frustum[plane * 4 + 1] * center[1] +
198  frustum[plane * 4 + 2] * center[2] +
199  frustum[plane * 4 + 3];
200  if (distance < -radius)
201  return(0);
202  }
203  else
204  for (unsigned int plane = 0; plane < 4; plane++)
205  {
206  double distance =
207  frustum[plane * 4 + 0] * center[0] +
208  frustum[plane * 4 + 1] * center[1] +
209  frustum[plane * 4 + 3];
210  if (distance < -radius)
211  return(0);
212  }
213 
214  return(1);
215 }
216 
217 
218 #endif
evVector LowerBound
Definition: evBoundingBox.h:68
void evPrintWithTab(const int tabbing, const char *format,...)
unsigned int Dimension(void) const
Definition: evVector.h:149
evVector GetLowerBound(void) const
Definition: evBoundingBox.h:102
double CalcPixelSize(const evAddress &size) const
Definition: evBoundingBox.h:156
void PrintSelf(const int tabbing) const
Definition: evBoundingBox.h:174
evBoundingBox(void)
Definition: evBoundingBox.h:73
evBoundingBox operator=(const evBoundingBox &bounding_box)
Definition: evBoundingBox.h:128
virtual void PrintSelf(const int tabbing) const
Definition: evVector.h:36
Definition: evAddress.h:37
void SetBounds(const evVector &lower_bound, const evVector &upper_bound)
Definition: evBoundingBox.h:120
Definition: evBoundingBox.h:32
void SetUpperBound(const evVector &upper_bound)
Definition: evBoundingBox.h:108
void SetLowerBound(const evVector &lower_bound)
Definition: evBoundingBox.h:96
Definition: evDataObject.h:31
virtual const evString GetClassName(void) const
Definition: evBoundingBox.h:40
evVector GetUpperBound(void) const
Definition: evBoundingBox.h:114
evVector CalcUniformGrid(const evAddress &grid_coordinates, const evAddress &size) const
Definition: evBoundingBox.h:138
#define EVPRINT_NOFORMAT
Definition: evMiscRoutines.h:34
double Norm(void) const
Definition: evVector.h:395
evVector UpperBound
Definition: evBoundingBox.h:69
int InsideViewFrustum(const evVector &frustum) const
Definition: evBoundingBox.h:185
virtual ~evBoundingBox(void)
Definition: evBoundingBox.h:91
Definition: evString.h:30