NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxBoundingBoxWidget.cpp
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 #include <cxBoundingBoxWidget.h>
34 #include "cxBoundingBox3D.h"
35 #include "cxDoubleSpanSlider.h"
36 #include "cxDoublePairProperty.h"
37 
38 namespace cx
39 {
40 
41 BoundingBoxWidget::BoundingBoxWidget(QWidget* parent, QStringList captions) :
42  QWidget(parent)
43 {
44  QVBoxLayout* layout = new QVBoxLayout(this);
45  layout->setMargin(0);
46 
47  if(captions.isEmpty())
48  captions = QStringList() << "X (mm)" << "Y (mm)" << "Z (mm)";
49 
50  for (int i=0; i<captions.size(); ++i)
51  {
52  DoublePairPropertyPtr property = DoublePairProperty::initialize(captions[i], captions[i], captions[i], DoubleRange(-2000, 2000, 1), 0);
53  mRange.push_back(new SliderRangeGroupWidget(this, property));
55  layout->addWidget(mRange[i]);
56  if(i >= captions.size())
57  mRange[i]->setVisible(false);
58  }
59 }
60 
61 void BoundingBoxWidget::showDim(int dim, bool visible)
62 {
63  mRange[dim]->setVisible(visible);
64 }
65 
67 {
68  for (int i=0; i<mRange.size(); ++i)
69  {
70  mRange[i]->blockSignals(true);
71  mRange[i]->setRange(DoubleRange(range.begin()[2*i], range.begin()[2*i+1], 1));
72  mRange[i]->setValue(value.begin()[2*i], value.begin()[2*i+1]);
73  mRange[i]->blockSignals(false);
74  }
75 }
76 
78 {
79  //Init with zeroes
80  std::vector< std::pair<double, double> > values;
81  for(unsigned i = 0; i < 3; ++i)
82  values.push_back(std::make_pair(0, 0));
83 
84  //Overwrite the zeroes with values (depends on the dim we are using)
85  for(unsigned i = 0; i < mRange.size(); ++i)
86  values[i] = mRange[i]->getValue();
87 
89  values[0].first, values[0].second,
90  values[1].first, values[1].second,
91  values[2].first, values[2].second);
92 
93 // std::pair<double, double> x = mRange[0]->getValue();
94 // std::pair<double, double> y = mRange[1]->getValue();
95 // std::pair<double, double> z = mRange[2]->getValue();
96 // DoubleBoundingBox3D box(x.first, x.second, y.first, y.second, z.first, z.second);
97 
98  return box;
99 }
100 
101 }
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
DoubleBoundingBox3D getValue() const
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.
boost::shared_ptr< class DoublePairProperty > DoublePairPropertyPtr
void valueChanged(double lower, double upper)
void setValue(const DoubleBoundingBox3D &value, const DoubleBoundingBox3D &range)
void showDim(int dim, bool visible)
static DoublePairPropertyPtr initialize(const QString &uid, QString name, QString help, DoubleRange range, int decimals, QDomNode root=QDomNode())
BoundingBoxWidget(QWidget *parent=NULL, QStringList inCaptions=QStringList())