Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxBoundingBox3D.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXBOUNDINGBOX3D_H_
34 #define CXBOUNDINGBOX3D_H_
35 
36 #include "cxResourceExport.h"
37 #include "cxPrecompiledHeader.h"
38 
39 #include "boost/array.hpp"
40 #include "cxVector3D.h"
41 #include <vector>
42 
43 // --------------------------------------------------------
44 namespace cx
45 {
46 //namespace utils
47 //{
48 // --------------------------------------------------------
49 
59 class cxResource_EXPORT IntBoundingBox3D: public boost::array<int, 6>
60 {
61 public:
63  explicit IntBoundingBox3D(int x0, int x1, int y0, int y1, int z0 = 0, int z1 = 0);
64  explicit IntBoundingBox3D(const Vector3D& a, const Vector3D& b);
65  explicit IntBoundingBox3D(const Eigen::Vector3i& a, const Eigen::Vector3i& b);
66  explicit IntBoundingBox3D(const double* data);
67  explicit IntBoundingBox3D(const int* data);
68 
69  Eigen::Vector3i bottomLeft() const;
70  Eigen::Vector3i topRight() const;
71  Eigen::Vector3i center() const;
72  Eigen::Vector3i range() const;
73  Eigen::Vector3i corner(int x, int y, int z) const;
74  bool contains(const Eigen::Vector3i& p) const;
75 };
76 // --------------------------------------------------------
77 
78 cxResource_EXPORT std::ostream& operator<<(std::ostream& s, const IntBoundingBox3D& data);
79 
84 class cxResource_EXPORT DoubleBoundingBox3D: public boost::array<double, 6>
85 {
86 public:
88  explicit DoubleBoundingBox3D(double x0, double x1, double y0, double y1, double z0 = 0.0, double z1 = 0.0);
89  explicit DoubleBoundingBox3D(const Vector3D& a, const Vector3D& b);
90  explicit DoubleBoundingBox3D(const double* data);
91  explicit DoubleBoundingBox3D(const IntBoundingBox3D& bb);
92  explicit DoubleBoundingBox3D(const int* data);
93  static DoubleBoundingBox3D fromViewport(const double* data);
94  static DoubleBoundingBox3D fromCloud(std::vector<Vector3D> cloud);
95  static DoubleBoundingBox3D fromString(const QString& text);
96  static DoubleBoundingBox3D zero() { return DoubleBoundingBox3D(0,0,0,0,0,0); }
97 
98  Vector3D bottomLeft() const;
99  Vector3D topRight() const;
100  Vector3D center() const;
101  Vector3D range() const;
102  Vector3D corner(int x, int y, int z) const;
103  bool contains(const Vector3D& p) const;
104  DoubleBoundingBox3D unionWith(const DoubleBoundingBox3D& other) const;
105 };
106 // --------------------------------------------------------
107 
108 cxResource_EXPORT bool similar(const DoubleBoundingBox3D& a, const DoubleBoundingBox3D& b, double tol = 1.0E-6);
109 
110 cxResource_EXPORT std::ostream& operator<<(std::ostream& s, const DoubleBoundingBox3D& data);
111 
116 // --------------------------------------------------------
117 //} // namespace utils
118 //using namespace utils;
119 } // namespace cx
120 // --------------------------------------------------------
121 
122 #endif /*CXBOUNDINGBOX3D_H_*/
Eigen::Vector2d fromString(const QString &text)
Definition: cxVector3D.cpp:127
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
static DoubleBoundingBox3D zero()
Representation of an integer bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
std::ostream & operator<<(std::ostream &s, const IntBoundingBox3D &data)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63