Isis 3.0 Programmer Reference
Back | Home
Area3D.cpp
Go to the documentation of this file.
1 
24 #include "Area3D.h"
25 
26 #include <algorithm>
27 
28 #include <QObject>
29 #include <QString>
30 
31 #include "Displacement.h"
32 #include "Distance.h"
33 #include "IException.h"
34 #include "IString.h"
35 
36 namespace Isis {
41  nullTheData();
42  }
43 
44 
55  Area3D::Area3D(const Displacement &startX, const Displacement &startY,
56  const Displacement &startZ,
57  const Distance &width, const Distance &height,
58  const Distance &depth) {
59  nullTheData();
60  setArea(startX, startY, startZ,
61  startX + width, startY + height, startZ + depth);
62  }
63 
64 
75  Area3D::Area3D(const Displacement &startX, const Displacement &startY,
76  const Displacement &startZ,
77  const Displacement &endX, const Displacement &endY,
78  const Displacement &endZ) {
79  nullTheData();
80  setArea(startX, startY, startZ, endX, endY, endZ);
81  }
82 
83 
89  Area3D::Area3D(const Area3D &areaToCopy) {
90  nullTheData();
91 
92  if(areaToCopy.m_startX) {
93  m_startX = new Displacement(*areaToCopy.m_startX);
94  }
95 
96  if(areaToCopy.m_startY) {
97  m_startY = new Displacement(*areaToCopy.m_startY);
98  }
99 
100  if(areaToCopy.m_startZ) {
101  m_startZ = new Displacement(*areaToCopy.m_startZ);
102  }
103 
104  if(areaToCopy.m_endX) {
105  m_endX = new Displacement(*areaToCopy.m_endX);
106  }
107 
108  if(areaToCopy.m_endY) {
109  m_endY = new Displacement(*areaToCopy.m_endY);
110  }
111 
112  if(areaToCopy.m_endZ) {
113  m_endZ = new Displacement(*areaToCopy.m_endZ);
114  }
115  }
116 
117 
122  deleteTheData();
123  }
124 
125 
130  Displacement startX;
131 
132  if(m_startX)
133  startX = *m_startX;
134 
135  return startX;
136  }
137 
138 
143  Displacement startY;
144 
145  if(m_startY)
146  startY = *m_startY;
147 
148  return startY;
149  }
150 
151 
156  Displacement startZ;
157 
158  if(m_startZ)
159  startZ = *m_startZ;
160 
161  return startZ;
162  }
163 
164 
169  return Distance(
170  (getEndX() - getStartX()).meters(),
172  }
173 
174 
179  return Distance(
180  (getEndY() - getStartY()).meters(),
182  }
183 
184 
189  return Distance(
190  (getEndZ() - getStartZ()).meters(),
192  }
193 
194 
199  Displacement endX;
200 
201  if(m_endX)
202  endX = *m_endX;
203 
204  return endX;
205  }
206 
207 
212  Displacement endY;
213 
214  if(m_endY)
215  endY = *m_endY;
216 
217  return endY;
218  }
219 
220 
225  Displacement endZ;
226 
227  if(m_endZ)
228  endZ = *m_endZ;
229 
230  return endZ;
231  }
232 
233 
240  void Area3D::setStartX(const Displacement &startX) {
241  setArea(startX, getStartY(), getStartZ(),
242  getEndX(), getEndY(), getEndZ());
243  }
244 
245 
252  void Area3D::setStartY(const Displacement &startY) {
253  setArea(getStartX(), startY, getStartZ(),
254  getEndX(), getEndY(), getEndZ());
255  }
256 
257 
264  void Area3D::setStartZ(const Displacement &startZ) {
265  setArea(getStartX(), getStartY(), startZ,
266  getEndX(), getEndY(), getEndZ());
267  }
268 
269 
276  void Area3D::moveStartX(const Displacement &startX) {
277  setArea(startX, getStartY(), getStartZ(),
278  getEndX() + (startX - getStartX()), getEndY(), getEndZ());
279  }
280 
281 
288  void Area3D::moveStartY(const Displacement &startY) {
289  setArea(getStartX(), startY, getStartZ(),
290  getEndX(), getEndY() + (startY - getStartY()), getEndZ());
291  }
292 
293 
300  void Area3D::moveStartZ(const Displacement &startZ) {
301  setArea(getStartX(), getStartY(), startZ,
302  getEndX(), getEndY(), getEndZ() + (startZ - getStartZ()));
303  }
304 
305 
311  void Area3D::setWidth(const Distance &width) {
313  getStartX() + width, getEndY(), getEndZ());
314  }
315 
316 
322  void Area3D::setHeight(const Distance &height) {
324  getEndX(), getStartY() + height, getEndZ());
325  }
326 
327 
333  void Area3D::setDepth(const Distance &depth) {
335  getEndX(), getEndY(), getStartZ() + depth);
336  }
337 
338 
345  void Area3D::setEndX(const Displacement &endX) {
347  endX, getEndY(), getEndZ());
348  }
349 
350 
357  void Area3D::setEndY(const Displacement &endY) {
359  getEndX(), endY, getEndZ());
360  }
361 
362 
369  void Area3D::setEndZ(const Displacement &endZ) {
371  getEndX(), getEndY(), endZ);
372  }
373 
374 
381  void Area3D::moveEndX(const Displacement &endX) {
382  setArea(getStartX() + (endX - getEndX()), getStartY(), getStartZ(),
383  endX, getEndY(), getEndZ());
384  }
385 
386 
393  void Area3D::moveEndY(const Displacement &endY) {
394  setArea(getStartX(), getStartY() + (endY - getEndY()), getStartZ(),
395  getEndX(), endY, getEndZ());
396  }
397 
398 
405  void Area3D::moveEndZ(const Displacement &endZ) {
406  setArea(getStartX(), getStartY(), getStartZ() + (endZ - getEndZ()),
407  getEndX(), getEndY(), endZ);
408  }
409 
410 
419  const Distance &width) {
420  setArea(startX, getStartY(), getStartZ(),
421  startX + width, getEndY(), getEndZ());
422  }
423 
424 
433  const Distance &height) {
434  setArea(getStartX(), startY, getStartZ(),
435  getEndX(), startY + height, getEndZ());
436  }
437 
438 
447  const Distance &depth) {
448  setArea(getStartX(), getStartY(), startZ,
449  getEndX(), getEndY(), startZ + depth);
450  }
451 
452 
460  Area3D Area3D::intersect(const Area3D &otherArea) const {
461  Area3D result;
462 
463  // Check validity because of comparison operators.
464  if (isValid() && otherArea.isValid()) {
465  Displacement startX(std::max(getStartX(), otherArea.getStartX()));
466  Displacement startY(std::max(getStartY(), otherArea.getStartY()));
467  Displacement startZ(std::max(getStartZ(), otherArea.getStartZ()));
468  Displacement endX(std::min(getEndX(), otherArea.getEndX()));
469  Displacement endY(std::min(getEndY(), otherArea.getEndY()));
470  Displacement endZ(std::min(getEndZ(), otherArea.getEndZ()));
471 
472 
473  if (startX <= endX && startY <= endY && startZ <= endZ)
474  result = Area3D(startX, startY, startZ, endX, endY, endZ);
475  }
476 
477  return result;
478  }
479 
480 
485  bool Area3D::isValid() const {
486  bool valid = true;
487 
488  if(!m_startX)
489  valid = false;
490  else if(!m_startY)
491  valid = false;
492  else if(!m_startZ)
493  valid = false;
494  else if(!m_endX)
495  valid = false;
496  else if(!m_endY)
497  valid = false;
498  else if(!m_endZ)
499  valid = false;
500 
501  return valid;
502  }
503 
504 
513  bool Area3D::operator ==(const Area3D &otherArea) const {
514  return getStartX() == otherArea.getStartX() &&
515  getStartY() == otherArea.getStartY() &&
516  getStartZ() == otherArea.getStartZ() &&
517  getEndX() == otherArea.getEndX() &&
518  getEndY() == otherArea.getEndY() &&
519  getEndZ() == otherArea.getEndZ();
520  }
521 
522 
531  bool Area3D::operator !=(const Area3D &otherArea) const {
532  return !(*this == otherArea);
533  }
534 
535 
542  Area3D &Area3D::operator =(const Area3D &areaToCopy) {
543  deleteTheData();
544 
545  if(areaToCopy.m_startX) {
546  m_startX = new Displacement(*areaToCopy.m_startX);
547  }
548 
549  if(areaToCopy.m_startY) {
550  m_startY = new Displacement(*areaToCopy.m_startY);
551  }
552 
553  if(areaToCopy.m_startZ) {
554  m_startZ = new Displacement(*areaToCopy.m_startZ);
555  }
556 
557  if(areaToCopy.m_endX) {
558  m_endX = new Displacement(*areaToCopy.m_endX);
559  }
560 
561  if(areaToCopy.m_endY) {
562  m_endY = new Displacement(*areaToCopy.m_endY);
563  }
564 
565  if(areaToCopy.m_endZ) {
566  m_endZ = new Displacement(*areaToCopy.m_endZ);
567  }
568 
569  return *this;
570  }
571 
572 
589  void Area3D::setArea(const Displacement &startX,
590  const Displacement &startY, const Displacement &startZ,
591  const Displacement &endX, const Displacement &endY,
592  const Displacement &endZ) {
593  bool startXValid = startX.isValid();
594  bool endXValid = endX.isValid();
595  bool startYValid = startY.isValid();
596  bool endYValid = endY.isValid();
597  bool startZValid = startZ.isValid();
598  bool endZValid = endZ.isValid();
599 
600  deleteTheData();
601 
602  // Optimized for success.
603  if(startXValid && startYValid && startZValid && endXValid && endYValid &&
604  endZValid && startX <= endX && startY <= endY && startZ <= endZ) {
605  m_startX = new Displacement(startX);
606  m_startY = new Displacement(startY);
607  m_startZ = new Displacement(startZ);
608  m_endX = new Displacement(endX);
609  m_endY = new Displacement(endY);
610  m_endZ = new Displacement(endZ);
611  }
612  else {
613  if(startXValid && endXValid && startX > endX) {
614  QString msg = QObject::tr("Cannot have a 3D area with inverted X coordinates of "
615  "[%1 meters] to [%2 meters]")
616  .arg(startX.meters()).arg(endX.meters());
618  }
619 
620  if(startYValid && endYValid && startY > endY) {
621  QString msg = QObject::tr("Cannot have a 3D area with inverted Y coordinates of "
622  "[%1 meters] to [%2 meters]")
623  .arg(startY.meters()).arg(endY.meters());
625  }
626 
627  if(startZValid && endZValid && startZ > endZ) {
628  QString msg = QObject::tr("Cannot have a 3D area with inverted Z coordinates of "
629  "[%1 meters] to [%2 meters]")
630  .arg(startZ.meters()).arg(endZ.meters());
632  }
633 
634  if(startXValid)
635  m_startX = new Displacement(startX);
636 
637  if(startYValid)
638  m_startY = new Displacement(startY);
639 
640  if(startZValid)
641  m_startZ = new Displacement(startZ);
642 
643  if(endXValid)
644  m_endX = new Displacement(endX);
645 
646  if(endYValid)
647  m_endY = new Displacement(endY);
648 
649  if(endZValid)
650  m_endZ = new Displacement(endZ);
651  }
652  }
653 
654 
659  if(m_startX) {
660  delete m_startX;
661  m_startX = NULL;
662  }
663 
664  if(m_startY) {
665  delete m_startY;
666  m_startY = NULL;
667  }
668 
669  if(m_startZ) {
670  delete m_startZ;
671  m_startZ = NULL;
672  }
673 
674  if(m_endX) {
675  delete m_endX;
676  m_endX = NULL;
677  }
678 
679  if(m_endY) {
680  delete m_endY;
681  m_endY = NULL;
682  }
683 
684  if(m_endZ) {
685  delete m_endZ;
686  m_endZ = NULL;
687  }
688  }
689 
690 
695  m_startX = NULL;
696  m_startY = NULL;
697  m_startZ = NULL;
698  m_endX = NULL;
699  m_endY = NULL;
700  m_endZ = NULL;
701  }
702 }
703 
bool isValid() const
Test if this displacement has been initialized or not.
void setStartX(const Displacement &startX)
Sets the leftmost X position.
Definition: Area3D.cpp:240
Displacement getStartZ() const
Returns the frontmost Z position of the 3D area.
Definition: Area3D.cpp:155
void moveEndX(const Displacement &endX)
Moves the rightmost X position of the 3D area.
Definition: Area3D.cpp:381
Represents a 3D area (a 3D &quot;cube&quot;)
Definition: Area3D.h:41
double meters() const
Get the displacement in meters.
Displacement * m_endY
The bottommost Y position. Either NULL or a valid displacement.
Definition: Area3D.h:119
Displacement * m_startX
The leftmost X position. Either NULL or a valid displacement.
Definition: Area3D.h:111
virtual ~Area3D()
The destructor frees allocated memory.
Definition: Area3D.cpp:121
void setDepth(const Distance &depth)
Changes the depth of the 3D area.
Definition: Area3D.cpp:333
void moveStartY(const Displacement &startY)
Moves the topmost Y position of the 3D area.
Definition: Area3D.cpp:288
void setHeight(const Distance &height)
Changes the height of the 3D area.
Definition: Area3D.cpp:322
Distance getWidth() const
Returns the width (in the X dimension) of the 3D area.
Definition: Area3D.cpp:168
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
Distance measurement, usually in meters.
Definition: Distance.h:47
void moveStartX(const Displacement &startX)
Moves the leftmost X position of the 3D area.
Definition: Area3D.cpp:276
Displacement getEndZ() const
Returns the backmost Z position of the 3D area.
Definition: Area3D.cpp:224
Displacement getEndY() const
Returns the bottommost Y position of the 3D area.
Definition: Area3D.cpp:211
void setYDimension(const Displacement &startY, const Distance &height)
Sets the Y dimension of the 3D area.
Definition: Area3D.cpp:432
Displacement getEndX() const
Returns the rightmost X position of the 3D area.
Definition: Area3D.cpp:198
void deleteTheData()
Frees all allocated memory used by this 3D area.
Definition: Area3D.cpp:658
void setStartZ(const Displacement &startZ)
Sets the frontmost Z position.
Definition: Area3D.cpp:264
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Area3D intersect(const Area3D &otherArea) const
Returns the intersection of this 3D area with another 3D area.
Definition: Area3D.cpp:460
void setStartY(const Displacement &startY)
Sets the topmost Y position.
Definition: Area3D.cpp:252
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
void setZDimension(const Displacement &startZ, const Distance &depth)
Sets the Z dimension of the 3D area.
Definition: Area3D.cpp:446
void moveEndZ(const Displacement &endZ)
Moves the backmost Z position of the 3D area.
Definition: Area3D.cpp:405
Displacement * m_startZ
The frontmost Z position. Either NULL or a valid displacement.
Definition: Area3D.h:115
bool operator==(const Area3D &otherArea) const
Compares two areas with the == operator.
Definition: Area3D.cpp:513
bool operator!=(const Area3D &otherArea) const
Compares two areas with the != operator.
Definition: Area3D.cpp:531
Displacement getStartX() const
Returns the leftmost X position of the 3D area.
Definition: Area3D.cpp:129
Displacement * m_endX
The rightmost X position. Either NULL or a valid displacement.
Definition: Area3D.h:117
void setEndZ(const Displacement &endZ)
Sets the backmost Z position.
Definition: Area3D.cpp:369
Distance getDepth() const
Returns the depth (in the Z dimension) of the 3D area.
Definition: Area3D.cpp:188
Distance getHeight() const
Returns the height (in the Y dimension) of the 3D area.
Definition: Area3D.cpp:178
bool isValid() const
Returns true if all of the positions of the 3D area are valid (i.e.
Definition: Area3D.cpp:485
virtual void setArea(const Displacement &startX, const Displacement &startY, const Displacement &startZ, const Displacement &endX, const Displacement &endY, const Displacement &endZ)
Sets the area.
Definition: Area3D.cpp:589
void moveStartZ(const Displacement &startZ)
Moves the frontmost Z position of the 3D area.
Definition: Area3D.cpp:300
void setEndX(const Displacement &endX)
Sets the rightmost X position.
Definition: Area3D.cpp:345
Displacement * m_endZ
The backmost Z position. Either NULL or a valid displacement.
Definition: Area3D.h:121
void moveEndY(const Displacement &endY)
Moves the bottommost Y position of the 3D area.
Definition: Area3D.cpp:393
Displacement * m_startY
The topmost Y position. Either NULL or a valid displacement.
Definition: Area3D.h:113
Displacement is a signed length, usually in meters.
Definition: Displacement.h:43
Isis exception class.
Definition: IException.h:99
void setXDimension(const Displacement &startX, const Distance &width)
Sets the X dimension of the 3D area.
Definition: Area3D.cpp:418
The distance is being specified in meters.
Definition: Distance.h:56
Displacement getStartY() const
Returns the topmost Y position of the 3D area.
Definition: Area3D.cpp:142
void setEndY(const Displacement &endY)
Sets the bottommost Y position.
Definition: Area3D.cpp:357
Area3D()
The empty constructor creates an invalid 3D area.
Definition: Area3D.cpp:40
void nullTheData()
Nulls all of the members used by this 3D area.
Definition: Area3D.cpp:694
void setWidth(const Distance &width)
Changes the width of the 3D area.
Definition: Area3D.cpp:311
Area3D & operator=(const Area3D &areaToCopy)
Assigns areaToCopy to this.
Definition: Area3D.cpp:542

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:14:27