Skip to content

Commit aa5de14

Browse files
authored
Merge pull request #2283 from RubioJr9/embb_size_fix
Sizing Fix for EditMeshBoundingBox
2 parents 93223a2 + f52dfa3 commit aa5de14

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

src/Modules/Fields/EditMeshBoundingBox.cc

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ void EditMeshBoundingBox::setOutputParameters()
120120
state->setValue(OutputCenterX, widgetTranslation_.x());
121121
state->setValue(OutputCenterY, widgetTranslation_.y());
122122
state->setValue(OutputCenterZ, widgetTranslation_.z());
123-
auto vecs = widgetScale_.get_transformation_vectors();
124-
state->setValue(OutputSizeX, vecs[0].norm());
125-
state->setValue(OutputSizeY, vecs[1].norm());
126-
state->setValue(OutputSizeZ, vecs[2].norm());
123+
state->setValue(OutputSizeX, size_[0]);
124+
state->setValue(OutputSizeY, size_[1]);
125+
state->setValue(OutputSizeZ, size_[2]);
127126
}
128127

129128
void EditMeshBoundingBox::clearVals()
@@ -241,10 +240,11 @@ void EditMeshBoundingBox::resetToInputField()
241240
computeWidgetBox(outputField_->vmesh()->get_bounding_box());
242241

243242
ogPos_ = pos_;
243+
ogSize_ = size_;
244244
widgetTranslation_ = pos_;
245-
auto trans = Transform(pos_, eigvecs_[0]*eigvals_[0], eigvecs_[1]*eigvals_[1], eigvecs_[2]*eigvals_[2]);
246-
ogScale_ = Vector(eigvals_[0], eigvals_[1], eigvals_[2]);
247-
widgetScale_.pre_scale(Vector(eigvals_[0], eigvals_[1], eigvals_[2]));
245+
auto eigvals = HALF_SCALE_ * size_;
246+
auto trans = Transform(pos_, eigvecs_[0]*eigvals[0], eigvecs_[1]*eigvals[1], eigvecs_[2]*eigvals[2]);
247+
widgetScale_.pre_scale(eigvals);
248248

249249
inputFieldInverse_ = Transform(trans);
250250
inputFieldInverse_.invert();
@@ -254,9 +254,9 @@ void EditMeshBoundingBox::resetToInputField()
254254
state->setValue(OutputCenterX, ogPos_.x());
255255
state->setValue(OutputCenterY, ogPos_.y());
256256
state->setValue(OutputCenterZ, ogPos_.z());
257-
state->setValue(OutputSizeX, ogScale_.x());
258-
state->setValue(OutputSizeY, ogScale_.y());
259-
state->setValue(OutputSizeZ, ogScale_.z());
257+
state->setValue(OutputSizeX, ogSize_.x());
258+
state->setValue(OutputSizeY, ogSize_.y());
259+
state->setValue(OutputSizeZ, ogSize_.z());
260260
}
261261

262262
// Sets the translation vector in the homogeneous matrices
@@ -266,8 +266,8 @@ void EditMeshBoundingBox::setOutputCenter()
266266
state->setTransientValue(SetOutputCenter, false);
267267

268268
widgetTranslation_ = Point(state->getValue(OutputCenterX).toDouble(),
269-
state->getValue(OutputCenterY).toDouble(),
270-
state->getValue(OutputCenterZ).toDouble());
269+
state->getValue(OutputCenterY).toDouble(),
270+
state->getValue(OutputCenterZ).toDouble());
271271

272272
}
273273

@@ -286,23 +286,27 @@ void EditMeshBoundingBox::setOutputSize()
286286
{
287287
auto state = get_state();
288288
state->setTransientValue(SetOutputSize, false);
289+
size_ = Vector(state->getValue(OutputSizeX).toDouble(),
290+
state->getValue(OutputSizeY).toDouble(),
291+
state->getValue(OutputSizeZ).toDouble());
292+
auto eigvals = HALF_SCALE_ * size_;
289293

290294
widgetScale_ = Transform();
291-
widgetScale_.post_scale(Vector(state->getValue(OutputSizeX).toDouble(),
292-
state->getValue(OutputSizeY).toDouble(),
293-
state->getValue(OutputSizeZ).toDouble()));
295+
widgetScale_.post_scale(eigvals);
294296
}
295297

296298
void EditMeshBoundingBox::resetOutputSize()
297299
{
298300
auto state = get_state();
299301
state->setTransientValue(ResetSize, false);
302+
size_ = ogSize_;
303+
auto eigvals = HALF_SCALE_ * size_;
300304

301305
widgetScale_ = Transform();
302-
widgetScale_.pre_scale(ogScale_);
303-
state->setValue(OutputSizeX, ogScale_.x());
304-
state->setValue(OutputSizeY, ogScale_.y());
305-
state->setValue(OutputSizeZ, ogScale_.z());
306+
widgetScale_.pre_scale(eigvals);
307+
state->setValue(OutputSizeX, size_.x());
308+
state->setValue(OutputSizeY, size_.y());
309+
state->setValue(OutputSizeZ, size_.z());
306310
}
307311

308312
std::string EditMeshBoundingBox::convertForLabel(double coord)
@@ -322,32 +326,28 @@ void EditMeshBoundingBox::computeWidgetBox(const BBox& box)
322326
}
323327

324328
// build a widget identical to the BBox
325-
auto diag = bbox_.diagonal();
329+
pos_ = bbox_.center();
330+
size_ = bbox_.diagonal();
326331
const auto SMALL = 1e-4;
327-
if (fabs(diag.x())<SMALL)
332+
const auto SMALL2 = 2*SMALL;
333+
if (fabs(size_.x())<SMALL)
328334
{
329-
diag.x(2 * SMALL);
335+
size_.x(SMALL2);
330336
bbox_.extend(bbox_.get_min() - Vector(SMALL, 0.0, 0.0));
331337
bbox_.extend(bbox_.get_max() + Vector(SMALL, 0.0, 0.0));
332338
}
333-
if (fabs(diag.y())<SMALL)
339+
if (fabs(size_.y())<SMALL)
334340
{
335-
diag.y(2 * SMALL);
341+
size_.y(SMALL2);
336342
bbox_.extend(bbox_.get_min() - Vector(0.0, SMALL, 0.0));
337343
bbox_.extend(bbox_.get_max() + Vector(0.0, SMALL, 0.0));
338344
}
339-
if (fabs(diag.z())<SMALL)
345+
if (fabs(size_.z())<SMALL)
340346
{
341-
diag.z(2 * SMALL);
347+
size_.z(SMALL2);
342348
bbox_.extend(bbox_.get_min() - Vector(0.0, 0.0, SMALL));
343349
bbox_.extend(bbox_.get_max() + Vector(0.0, 0.0, SMALL));
344350
}
345-
346-
eigvals_.resize(mDIMENSIONS);
347-
pos_ = bbox_.center();
348-
eigvals_[0] = diag.x() * 0.5;
349-
eigvals_[1] = diag.y() * 0.5;
350-
eigvals_[2] = diag.z() * 0.5;
351351
}
352352

353353
void EditMeshBoundingBox::generateGeomsList()
@@ -377,9 +377,9 @@ void EditMeshBoundingBox::updateInputFieldAttributes()
377377
state->setValue(InputCenterX, convertForLabel(ogPos_[0]));
378378
state->setValue(InputCenterY, convertForLabel(ogPos_[1]));
379379
state->setValue(InputCenterZ, convertForLabel(ogPos_[2]));
380-
state->setValue(InputSizeX, convertForLabel(ogScale_[0]));
381-
state->setValue(InputSizeY, convertForLabel(ogScale_[1]));
382-
state->setValue(InputSizeZ, convertForLabel(ogScale_[2]));
380+
state->setValue(InputSizeX, convertForLabel(ogSize_[0]));
381+
state->setValue(InputSizeY, convertForLabel(ogSize_[1]));
382+
state->setValue(InputSizeZ, convertForLabel(ogSize_[2]));
383383
}
384384

385385
void EditMeshBoundingBox::saveToParameters()

src/Modules/Fields/EditMeshBoundingBox.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ namespace SCIRun {
103103
MODULE_TRAITS_AND_INFO(ModuleHasUI)
104104

105105
private:
106+
const double HALF_SCALE_ = 0.5;
107+
106108
void clearVals();
107109
void computeWidgetBox(const Core::Geometry::BBox& box);
108110
void buildGeometryObject();
@@ -127,14 +129,14 @@ namespace SCIRun {
127129
Core::Geometry::BBox bbox_;
128130
Core::Geometry::Point pos_;
129131
std::vector<Core::Geometry::Vector> eigvecs_;
130-
std::vector<double> eigvals_;
132+
Core::Geometry::Vector size_;
131133
FieldHandle outputField_;
132134
int widgetNum_{0};
133135
int resolution_ = 20;
134136

135137
std::vector<Graphics::Datatypes::GeometryHandle> geoms_;
136138
Core::Geometry::Point ogPos_;
137-
Core::Geometry::Vector ogScale_;
139+
Core::Geometry::Vector ogSize_;
138140
Core::Geometry::Transform inputFieldInverse_;
139141
Core::Geometry::Transform widgetScale_;
140142
Core::Geometry::Transform widgetRotation_;

0 commit comments

Comments
 (0)