Developer Documentation
QtPrincipalAxisDialog.cc
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2016, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42//=============================================================================
43//
44// CLASS QtPrincipalAxisDialog - IMPLEMENTATION
45//
46//=============================================================================
47
48//== INCLUDES =================================================================
49
50#include "QtPrincipalAxisDialog.hh"
51
52#include <QtGui>
53#include <limits>
54
55//== NAMESPACES ===============================================================
56
57namespace ACG {
58
59//== IMPLEMENTATION ==========================================================
60
61
62//-----------------------------------------------------------------------------
63
64static Vec4f byte2float(unsigned char r, unsigned char g, unsigned char b) {
65 return Vec4f(r/255.0, g/255.0, b/255.0, 1.0);
66}
67
68static float colorSchemeDistance(const QtPrincipalAxisDialog::ColorScheme a,
69 const QtPrincipalAxisDialog::ColorScheme b) {
70
71 float result = 0;
72 for (int i = 0; i < 3; ++i) {
73 result += (a[i] - b[i]).norm();
74 }
75
76 return result;
77}
78
79const QtPrincipalAxisDialog::ColorScheme QtPrincipalAxisDialog::color_schemes_[3] = {
80 { byte2float(232, 28, 23), byte2float(0, 110, 225), byte2float(0, 179, 0) },
81 { byte2float(26, 178, 0), byte2float(17, 0, 255), byte2float(204, 77, 0) },
82 { byte2float(255, 53, 139), byte2float(1, 176, 240), byte2float(174, 238, 0) },
83};
84static const size_t N_COLOR_SCHEMES = 3;
85
86void
87QtPrincipalAxisDialog::
88get_parameters()
89{
90// QRadioButton* drawStyle3D;
91// QRadioButton* drawStyle2D;
92// QRadioButton* colorModeAxis;
93// QRadioButton* colorModeSign;
94// QCheckBox* showTensor1;
95// QCheckBox* showTensor2;
96// QCheckBox* showTensor3;
97// QLineEdit* maxDrawRadius;
98// QLineEdit* minDrawRadius;
99// QLineEdit* radiusScale;
100// QPushButton* OkButton;
101// QPushButton* CancelButton;
102
103 if( pnode_.draw_style_ == PrincipalAxisNode::DS_3D)
104 drawStyle3D->setChecked(true);
105 else
106 drawStyle2D->setChecked(true);
107
108 if( pnode_.color_mode_ == PrincipalAxisNode::CM_Axis)
109 colorModeAxis->setChecked(true);
110 else
111 colorModeSign->setChecked(true);
112
113 showTensor1->setChecked( pnode_.show_tensor_component_[0] > 0);
114 showTensor2->setChecked( pnode_.show_tensor_component_[1] > 0);
115 showTensor3->setChecked( pnode_.show_tensor_component_[2] > 0);
116
117 showTensor1B->setChecked( pnode_.show_tensor_component_[0] > 1);
118 showTensor2B->setChecked( pnode_.show_tensor_component_[1] > 1);
119 showTensor3B->setChecked( pnode_.show_tensor_component_[2] > 1);
120
121 QString d;
122
123 maxDrawRadius->setText(d.setNum(pnode_.max_draw_radius_));
124 minDrawRadius->setText(d.setNum(pnode_.min_draw_radius_));
125 radiusScale->setText (d.setNum(pnode_.cylinder_radius_scale_));
126 minSpacing->setText (d.setNum(pnode_.min_spacing_));
127
128 ColorScheme cs;
129 pnode_.get_axes_colors(cs);
130 setColorScheme(cs);
131}
132
133
134//-----------------------------------------------------------------------------
135
136
137void
138QtPrincipalAxisDialog::
139set_parameters()
140{
141 // set drawstyle
142 if( drawStyle3D->isChecked() )
143 pnode_.draw_style_ = PrincipalAxisNode::DS_3D;
144 else
145 pnode_.draw_style_ = PrincipalAxisNode::DS_2D;
146
147 // set colormode
148 if( colorModeAxis->isChecked())
149 pnode_.color_mode_ = PrincipalAxisNode::CM_Axis;
150 else
151 pnode_.color_mode_ = PrincipalAxisNode::CM_Sign;
152
153
154 // set drawTensorComponents
155 pnode_.show_tensor_component_[0] = showTensor1->isChecked();
156 pnode_.show_tensor_component_[1] = showTensor2->isChecked();
157 pnode_.show_tensor_component_[2] = showTensor3->isChecked();
158
159 // Both tensor directions?
160 if( showTensor1B->isChecked())
161 pnode_.show_tensor_component_[0] = 2;
162 if( showTensor2B->isChecked())
163 pnode_.show_tensor_component_[1] = 2;
164 if( showTensor3B->isChecked())
165 pnode_.show_tensor_component_[2] = 2;
166
167
168 pnode_.max_draw_radius_ = maxDrawRadius->text().toDouble();
169 pnode_.min_draw_radius_ = minDrawRadius->text().toDouble();
170 pnode_.cylinder_radius_scale_ = radiusScale->text().toDouble();
171 pnode_.min_spacing_ = minSpacing->text().toDouble();
172
173 pnode_.set_axes_colors(getSelectedColorScheme());
174
175 pnode_.auto_update_range();
176}
177
178
179//-----------------------------------------------------------------------------
180
181
182void
183QtPrincipalAxisDialog::
184slotOkButton()
185{
186 set_parameters();
187 close();
188}
189
190
191//-----------------------------------------------------------------------------
192
193
194void
195QtPrincipalAxisDialog::
196slotCancelButton()
197{
198 close();
199}
200
201const QtPrincipalAxisDialog::ColorScheme &QtPrincipalAxisDialog::getSelectedColorScheme() {
202 if (colorscheme_1_rb->isChecked()) {
203 return color_schemes_[0];
204 } else if (colorscheme_2_rb->isChecked()) {
205 return color_schemes_[1];
206 } else if (colorscheme_3_rb->isChecked()) {
207 return color_schemes_[2];
208 } else {
209 // Fallback.
210 return color_schemes_[0];
211 }
212}
213
214void QtPrincipalAxisDialog::setColorScheme(ColorScheme cs) {
215 float best_match = std::numeric_limits<float>::infinity();
216 size_t best_match_i = std::numeric_limits<size_t>::max();
217
218 for (size_t i = 0; i < N_COLOR_SCHEMES; ++i) {
219 float match = colorSchemeDistance(cs, color_schemes_[i]);
220 if (match < best_match) {
221 best_match = match;
222 best_match_i = i;
223 }
224 }
225
226 switch (best_match_i) {
227 case 0:
228 colorscheme_1_rb->setChecked(true);
229 break;
230 case 1:
231 colorscheme_2_rb->setChecked(true);
232 break;
233 case 2:
234 colorscheme_3_rb->setChecked(true);
235 break;
236 default:
237 break;
238 }
239}
240
241
242//=============================================================================
243} // namespace ACG
244//=============================================================================
Namespace providing different geometric functions concerning angles.
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:138