Isis 3 Programmer Reference
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 
132  Displacement startX;
133 
134  if(m_startX)
135  startX = *m_startX;
136 
137  return startX;
138  }
139 
140 
147  Displacement startY;
148 
149  if(m_startY)
150  startY = *m_startY;
151 
152  return startY;
153  }
154 
155 
162  Displacement startZ;
163 
164  if(m_startZ)
165  startZ = *m_startZ;
166 
167  return startZ;
168  }
169 
170 
177  return Distance(
178  (getEndX() - getStartX()).meters(),
180  }
181 
182 
189  return Distance(
190  (getEndY() - getStartY()).meters(),
192  }
193 
194 
201  return Distance(
202  (getEndZ() - getStartZ()).meters(),
204  }
205 
206 
213  Displacement endX;
214 
215  if(m_endX)
216  endX = *m_endX;
217 
218  return endX;
219  }
220 
221 
228  Displacement endY;
229 
230  if(m_endY)
231  endY = *m_endY;
232 
233  return endY;
234  }
235 
236 
243  Displacement endZ;
244 
245  if(m_endZ)
246  endZ = *m_endZ;
247 
248  return endZ;
249  }
250 
251 
258  void Area3D::setStartX(const Displacement &startX) {
259  setArea(startX, getStartY(), getStartZ(),
260  getEndX(), getEndY(), getEndZ());
261  }
262 
263 
270  void Area3D::setStartY(const Displacement &startY) {
271  setArea(getStartX(), startY, getStartZ(),
272  getEndX(), getEndY(), getEndZ());
273  }
274 
275 
282  void Area3D::setStartZ(const Displacement &startZ) {
283  setArea(getStartX(), getStartY(), startZ,
284  getEndX(), getEndY(), getEndZ());
285  }
286 
287 
294  void Area3D::moveStartX(const Displacement &startX) {
295  setArea(startX, getStartY(), getStartZ(),
296  getEndX() + (startX - getStartX()), getEndY(), getEndZ());
297  }
298 
299 
306  void Area3D::moveStartY(const Displacement &startY) {
307  setArea(getStartX(), startY, getStartZ(),
308  getEndX(), getEndY() + (startY - getStartY()), getEndZ());
309  }
310 
311 
318  void Area3D::moveStartZ(const Displacement &startZ) {
319  setArea(getStartX(), getStartY(), startZ,
320  getEndX(), getEndY(), getEndZ() + (startZ - getStartZ()));
321  }
322 
323 
329  void Area3D::setWidth(const Distance &width) {
331  getStartX() + width, getEndY(), getEndZ());
332  }
333 
334 
340  void Area3D::setHeight(const Distance &height) {
342  getEndX(), getStartY() + height, getEndZ());
343  }
344 
345 
351  void Area3D::setDepth(const Distance &depth) {
353  getEndX(), getEndY(), getStartZ() + depth);
354  }
355 
356 
363  void Area3D::setEndX(const Displacement &endX) {
365  endX, getEndY(), getEndZ());
366  }
367 
368 
375  void Area3D::setEndY(const Displacement &endY) {
377  getEndX(), endY, getEndZ());
378  }
379 
380 
387  void Area3D::setEndZ(const Displacement &endZ) {
389  getEndX(), getEndY(), endZ);
390  }
391 
392 
399  void Area3D::moveEndX(const Displacement &endX) {
400  setArea(getStartX() + (endX - getEndX()), getStartY(), getStartZ(),
401  endX, getEndY(), getEndZ());
402  }
403 
404 
411  void Area3D::moveEndY(const Displacement &endY) {
412  setArea(getStartX(), getStartY() + (endY - getEndY()), getStartZ(),
413  getEndX(), endY, getEndZ());
414  }
415 
416 
423  void Area3D::moveEndZ(const Displacement &endZ) {
424  setArea(getStartX(), getStartY(), getStartZ() + (endZ - getEndZ()),
425  getEndX(), getEndY(), endZ);
426  }
427 
428 
437  const Distance &width) {
438  setArea(startX, getStartY(), getStartZ(),
439  startX + width, getEndY(), getEndZ());
440  }
441 
442 
451  const Distance &height) {
452  setArea(getStartX(), startY, getStartZ(),
453  getEndX(), startY + height, getEndZ());
454  }
455 
456 
465  const Distance &depth) {
466  setArea(getStartX(), getStartY(), startZ,
467  getEndX(), getEndY(), startZ + depth);
468  }
469 
470 
478  Area3D Area3D::intersect(const Area3D &otherArea) const {
479  Area3D result;
480 
481  // Check validity because of comparison operators.
482  if (isValid() && otherArea.isValid()) {
483  Displacement startX(std::max(getStartX(), otherArea.getStartX()));
484  Displacement startY(std::max(getStartY(), otherArea.getStartY()));
485  Displacement startZ(std::max(getStartZ(), otherArea.getStartZ()));
486  Displacement endX(std::min(getEndX(), otherArea.getEndX()));
487  Displacement endY(std::min(getEndY(), otherArea.getEndY()));
488  Displacement endZ(std::min(getEndZ(), otherArea.getEndZ()));
489 
490 
491  if (startX <= endX && startY <= endY && startZ <= endZ)
492  result = Area3D(startX, startY, startZ, endX, endY, endZ);
493  }
494 
495  return result;
496  }
497 
498 
505  bool Area3D::isValid() const {
506  bool valid = true;
507 
508  if(!m_startX)
509  valid = false;
510  else if(!m_startY)
511  valid = false;
512  else if(!m_startZ)
513  valid = false;
514  else if(!m_endX)
515  valid = false;
516  else if(!m_endY)
517  valid = false;
518  else if(!m_endZ)
519  valid = false;
520 
521  return valid;
522  }
523 
524 
533  bool Area3D::operator ==(const Area3D &otherArea) const {
534  return getStartX() == otherArea.getStartX() &&
535  getStartY() == otherArea.getStartY() &&
536  getStartZ() == otherArea.getStartZ() &&
537  getEndX() == otherArea.getEndX() &&
538  getEndY() == otherArea.getEndY() &&
539  getEndZ() == otherArea.getEndZ();
540  }
541 
542 
551  bool Area3D::operator !=(const Area3D &otherArea) const {
552  return !(*this == otherArea);
553  }
554 
555 
562  Area3D &Area3D::operator =(const Area3D &areaToCopy) {
563  deleteTheData();
564 
565  if(areaToCopy.m_startX) {
566  m_startX = new Displacement(*areaToCopy.m_startX);
567  }
568 
569  if(areaToCopy.m_startY) {
570  m_startY = new Displacement(*areaToCopy.m_startY);
571  }
572 
573  if(areaToCopy.m_startZ) {
574  m_startZ = new Displacement(*areaToCopy.m_startZ);
575  }
576 
577  if(areaToCopy.m_endX) {
578  m_endX = new Displacement(*areaToCopy.m_endX);
579  }
580 
581  if(areaToCopy.m_endY) {
582  m_endY = new Displacement(*areaToCopy.m_endY);
583  }
584 
585  if(areaToCopy.m_endZ) {
586  m_endZ = new Displacement(*areaToCopy.m_endZ);
587  }
588 
589  return *this;
590  }
591 
592 
609  void Area3D::setArea(const Displacement &startX,
610  const Displacement &startY, const Displacement &startZ,
611  const Displacement &endX, const Displacement &endY,
612  const Displacement &endZ) {
613  bool startXValid = startX.isValid();
614  bool endXValid = endX.isValid();
615  bool startYValid = startY.isValid();
616  bool endYValid = endY.isValid();
617  bool startZValid = startZ.isValid();
618  bool endZValid = endZ.isValid();
619 
620  deleteTheData();
621 
622  // Optimized for success.
623  if(startXValid && startYValid && startZValid && endXValid && endYValid &&
624  endZValid && startX <= endX && startY <= endY && startZ <= endZ) {
625  m_startX = new Displacement(startX);
626  m_startY = new Displacement(startY);
627  m_startZ = new Displacement(startZ);
628  m_endX = new Displacement(endX);
629  m_endY = new Displacement(endY);
630  m_endZ = new Displacement(endZ);
631  }
632  else {
633  if(startXValid && endXValid && startX > endX) {
634  QString msg = QObject::tr("Cannot have a 3D area with inverted X coordinates of "
635  "[%1 meters] to [%2 meters]")
636  .arg(startX.meters()).arg(endX.meters());
638  }
639 
640  if(startYValid && endYValid && startY > endY) {
641  QString msg = QObject::tr("Cannot have a 3D area with inverted Y coordinates of "
642  "[%1 meters] to [%2 meters]")
643  .arg(startY.meters()).arg(endY.meters());
645  }
646 
647  if(startZValid && endZValid && startZ > endZ) {
648  QString msg = QObject::tr("Cannot have a 3D area with inverted Z coordinates of "
649  "[%1 meters] to [%2 meters]")
650  .arg(startZ.meters()).arg(endZ.meters());
652  }
653 
654  if(startXValid)
655  m_startX = new Displacement(startX);
656 
657  if(startYValid)
658  m_startY = new Displacement(startY);
659 
660  if(startZValid)
661  m_startZ = new Displacement(startZ);
662 
663  if(endXValid)
664  m_endX = new Displacement(endX);
665 
666  if(endYValid)
667  m_endY = new Displacement(endY);
668 
669  if(endZValid)
670  m_endZ = new Displacement(endZ);
671  }
672  }
673 
674 
679  if(m_startX) {
680  delete m_startX;
681  m_startX = NULL;
682  }
683 
684  if(m_startY) {
685  delete m_startY;
686  m_startY = NULL;
687  }
688 
689  if(m_startZ) {
690  delete m_startZ;
691  m_startZ = NULL;
692  }
693 
694  if(m_endX) {
695  delete m_endX;
696  m_endX = NULL;
697  }
698 
699  if(m_endY) {
700  delete m_endY;
701  m_endY = NULL;
702  }
703 
704  if(m_endZ) {
705  delete m_endZ;
706  m_endZ = NULL;
707  }
708  }
709 
710 
715  m_startX = NULL;
716  m_startY = NULL;
717  m_startZ = NULL;
718  m_endX = NULL;
719  m_endY = NULL;
720  m_endZ = NULL;
721  }
722 }
723 
void setStartX(const Displacement &startX)
Sets the leftmost X position.
Definition: Area3D.cpp:258
void moveEndX(const Displacement &endX)
Moves the rightmost X position of the 3D area.
Definition: Area3D.cpp:399
Represents a 3D area (a 3D "cube")
Definition: Area3D.h:41
bool isValid() const
Returns true if all of the positions of the 3D area are valid (i.e.
Definition: Area3D.cpp:505
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
double meters() const
Get the displacement in meters.
bool isValid() const
Test if this displacement has been initialized or not.
void setDepth(const Distance &depth)
Changes the depth of the 3D area.
Definition: Area3D.cpp:351
void moveStartY(const Displacement &startY)
Moves the topmost Y position of the 3D area.
Definition: Area3D.cpp:306
void setHeight(const Distance &height)
Changes the height of the 3D area.
Definition: Area3D.cpp:340
Distance getDepth() const
Returns the depth (in the Z dimension) of the 3D area.
Definition: Area3D.cpp:200
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:162
Distance measurement, usually in meters.
Definition: Distance.h:47
Displacement getEndY() const
Returns the bottommost Y position of the 3D area.
Definition: Area3D.cpp:227
Displacement getStartX() const
Returns the leftmost X position of the 3D area.
Definition: Area3D.cpp:131
void moveStartX(const Displacement &startX)
Moves the leftmost X position of the 3D area.
Definition: Area3D.cpp:294
bool operator!=(const Area3D &otherArea) const
Compares two areas with the != operator.
Definition: Area3D.cpp:551
void setYDimension(const Displacement &startY, const Distance &height)
Sets the Y dimension of the 3D area.
Definition: Area3D.cpp:450
void deleteTheData()
Frees all allocated memory used by this 3D area.
Definition: Area3D.cpp:678
void setStartZ(const Displacement &startZ)
Sets the frontmost Z position.
Definition: Area3D.cpp:282
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
void setStartY(const Displacement &startY)
Sets the topmost Y position.
Definition: Area3D.cpp:270
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
void setZDimension(const Displacement &startZ, const Distance &depth)
Sets the Z dimension of the 3D area.
Definition: Area3D.cpp:464
Distance getWidth() const
Returns the width (in the X dimension) of the 3D area.
Definition: Area3D.cpp:176
Displacement getStartZ() const
Returns the frontmost Z position of the 3D area.
Definition: Area3D.cpp:161
void moveEndZ(const Displacement &endZ)
Moves the backmost Z position of the 3D area.
Definition: Area3D.cpp:423
Displacement * m_startZ
The frontmost Z position. Either NULL or a valid displacement.
Definition: Area3D.h:115
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:387
Displacement getEndZ() const
Returns the backmost Z position of the 3D area.
Definition: Area3D.cpp:242
Distance getHeight() const
Returns the height (in the Y dimension) of the 3D area.
Definition: Area3D.cpp:188
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:609
bool operator==(const Area3D &otherArea) const
Compares two areas with the == operator.
Definition: Area3D.cpp:533
void moveStartZ(const Displacement &startZ)
Moves the frontmost Z position of the 3D area.
Definition: Area3D.cpp:318
void setEndX(const Displacement &endX)
Sets the rightmost X position.
Definition: Area3D.cpp:363
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:411
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:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void setXDimension(const Displacement &startX, const Distance &width)
Sets the X dimension of the 3D area.
Definition: Area3D.cpp:436
Area3D intersect(const Area3D &otherArea) const
Returns the intersection of this 3D area with another 3D area.
Definition: Area3D.cpp:478
The distance is being specified in meters.
Definition: Distance.h:56
void setEndY(const Displacement &endY)
Sets the bottommost Y position.
Definition: Area3D.cpp:375
Area3D()
The empty constructor creates an invalid 3D area.
Definition: Area3D.cpp:40
Displacement getEndX() const
Returns the rightmost X position of the 3D area.
Definition: Area3D.cpp:212
void nullTheData()
Nulls all of the members used by this 3D area.
Definition: Area3D.cpp:714
void setWidth(const Distance &width)
Changes the width of the 3D area.
Definition: Area3D.cpp:329
Area3D & operator=(const Area3D &areaToCopy)
Assigns areaToCopy to this.
Definition: Area3D.cpp:562
Displacement getStartY() const
Returns the topmost Y position of the 3D area.
Definition: Area3D.cpp:146