Skip to content

Commit 375c641

Browse files
author
tpat
committed
Fixed flipped triangles and normals on disks. Added widget scaling to show and
edit dipoles
1 parent bd3574a commit 375c641

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

src/Graphics/Glyphs/GlyphGeom.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ void GlyphGeom::generateDisk(const Point& p1, const Point& p2, double radius1,
418418
numVBOElements_++;
419419
int p2_index = numVBOElements_;
420420
colors_.push_back(color2);
421-
normals_.push_back(n);
421+
normals_.push_back(-n);
422422
numVBOElements_++;
423423

424424
// Precalculate
@@ -446,7 +446,7 @@ void GlyphGeom::generateDisk(const Point& p1, const Point& p2, double radius1,
446446
normals_.push_back(n);
447447
points_.push_back(radius2 * p + Vector(p2));
448448
colors_.push_back(color2);
449-
normals_.push_back(n);
449+
normals_.push_back(-n);
450450
}
451451

452452
uint32_t offset = static_cast<uint32_t>(numVBOElements_);
@@ -458,16 +458,16 @@ void GlyphGeom::generateDisk(const Point& p1, const Point& p2, double radius1,
458458
indices_.push_back(strips);
459459
indices_.push_back(strips + 1);
460460
indices_.push_back(strips + points_per_loop);
461-
indices_.push_back(strips + 1);
462461
indices_.push_back(strips + points_per_loop);
462+
indices_.push_back(strips + 1);
463463
indices_.push_back(strips + points_per_loop + 1);
464464

465465
// Render base
466466
indices_.push_back(p1_index);
467467
indices_.push_back(strips + 2);
468468
indices_.push_back(strips + points_per_loop + 2);
469-
indices_.push_back(p2_index);
470469
indices_.push_back(strips + 3);
470+
indices_.push_back(p2_index);
471471
indices_.push_back(strips + points_per_loop + 3);
472472
}
473473
}

src/Interface/Modules/Visualization/ShowAndEditDipolesDialog.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ShowAndEditDipolesDialog::ShowAndEditDipolesDialog(const std::string& name, Modu
4545
setWindowTitle(QString::fromStdString(name));
4646
fixSize();
4747

48-
std::cout << "dialog managers\n";
48+
addDoubleSpinBoxManager(widgetSizeSpinBox, SAED::WidgetSize);
4949
addCheckBoxManager(showLastAsVectorCheckBox, SAED::ShowLastAsVector);
5050
addRadioButtonGroupManager({fixedSizeRButton, normalizeLargestRButton, scaleSizeRButton}, SAED::Sizing);
5151
addCheckBoxManager(showLinesCheckBox, SAED::ShowLines);

src/Modules/Legacy/Visualization/ShowAndEditDipoles.cc

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ ShowAndEditDipoles::ShowAndEditDipoles()
122122
greenCol_ = ColorRGB(0.2, 0.8, 0.2);
123123
resizeCol_ = ColorRGB(0.54, 1.0, 0.60);
124124

125-
sphereRadius_ = 1.0;
126-
cylinderRadius_ = 0.5;
127-
coneRadius_ = 1.0;
128-
diskRadius_ = 1.0;
125+
sphereRadius_ = 0.25;
126+
cylinderRadius_ = 0.12;
127+
coneRadius_ = 0.25;
128+
diskRadius_ = 0.25;
129129
diskDistFromCenter_ = 0.85;
130130
diskWidth_ = 0.05;
131131
widgetID_ = 0;
@@ -134,9 +134,10 @@ ShowAndEditDipoles::ShowAndEditDipoles()
134134
void ShowAndEditDipoles::setStateDefaults()
135135
{
136136
auto state = get_state();
137-
state->setValue(NumSeeds, 1);
137+
state->setValue(WidgetSize, 0.23);
138+
state->setValue(Sizing, 0);
138139
state->setValue(ShowLastAsVector, false);
139-
state->setValue(ProbeScale, 0.23);
140+
state->setValue(ShowLines, false);
140141
state->setValue(PointPositions, VariableList());
141142

142143
getOutputPort(DipoleWidget)->connectConnectionFeedbackListener([this](const ModuleFeedback& var) { processWidgetFeedback(var); });
@@ -211,9 +212,15 @@ void ShowAndEditDipoles::adjustPositionFromTransform(const Transform& transformM
211212
{
212213
// Sphere and Cylinder reposition dipole
213214
case WidgetSection::SPHERE:
214-
case WidgetSection::CYLINDER:
215215
pos_ = newPoint;
216216
break;
217+
case WidgetSection::CYLINDER:
218+
{
219+
double scale = get_state()->getValue(WidgetSize).toDouble();
220+
// Shift direction back because newPos is the center of the cylinder
221+
pos_ = newPoint - 1.375 * direction_ * scale * sphereRadius_;
222+
break;
223+
}
217224
// Cone rotates dipole
218225
case WidgetSection::CONE:
219226
direction_ = (newPoint - pos_).normal() * direction_.length();
@@ -224,6 +231,9 @@ void ShowAndEditDipoles::adjustPositionFromTransform(const Transform& transformM
224231
Vector newVec(newPoint-pos_);
225232
newVec /= diskDistFromCenter_;
226233
direction_ = Dot(newVec, direction_.normal()) * direction_.normal();
234+
235+
double scale = get_state()->getValue(WidgetSize).toDouble();
236+
direction_ /= scale;
227237
break;
228238
}
229239
}
@@ -234,9 +244,12 @@ FieldHandle ShowAndEditDipoles::GenerateOutputField()
234244
auto ifieldhandle = getRequiredInput(DipoleInputField);
235245
auto bbox = ifieldhandle->vmesh()->get_bounding_box();
236246

247+
auto state = get_state();
248+
double scale = state->getValue(WidgetSize).toDouble();
249+
Vector scaled_dir = direction_ * scale;
237250
Point center;
238251
Point bmin = pos_;
239-
Point bmax = pos_ + direction_;
252+
Point bmax = pos_ + scaled_dir;
240253

241254
// Fix degenerate boxes.
242255
const double size_estimate = std::max((bmax - bmin).length() * 0.01, 1.0e-5);
@@ -256,13 +269,11 @@ FieldHandle ShowAndEditDipoles::GenerateOutputField()
256269
bmax.z(bmax.z() + size_estimate);
257270
}
258271

259-
center = pos_ + direction_/2.0;
272+
center = pos_ + scaled_dir/2.0;
260273

261274
impl_->l2norm_ = (bmax - bmin).length();
262275
impl_->last_bounds_ = bbox;
263276

264-
auto state = get_state();
265-
auto scale = state->getValue(ProbeScale).toDouble();
266277
auto widgetName = [](int i, int id) { return "SAED(" + std::to_string(i) + ")" + std::to_string(id); };
267278
impl_->pointWidgets_.resize(0);
268279

@@ -271,42 +282,45 @@ FieldHandle ShowAndEditDipoles::GenerateOutputField()
271282
(WidgetFactory::createSphere(
272283
*this,
273284
widgetName(WidgetSection::SPHERE, widgetID_),
274-
sphereRadius_ * direction_.length() * scale,
285+
sphereRadius_ * scaled_dir.length(),
275286
deflPointCol_.toString(),
276287
pos_,
277288
bbox)));
278289

279290
if(state->getValue(ShowLastAsVector).toBool())
280291
{
292+
// Starts the cylinder position closer to the surface of the sphere
293+
Point cylinderStart = pos_ + 0.75 * (scaled_dir * sphereRadius_);
294+
281295
impl_->pointWidgets_.push_back(boost::dynamic_pointer_cast<WidgetBase>
282296
(WidgetFactory::createCylinder(
283297
*this,
284298
widgetName(WidgetSection::CYLINDER, widgetID_),
285-
cylinderRadius_ * direction_.length() * scale,
299+
cylinderRadius_ * scaled_dir.length(),
286300
deflCol_.toString(),
287-
pos_,
301+
cylinderStart,
288302
center,
289303
bbox)));
290304
impl_->pointWidgets_.push_back(boost::dynamic_pointer_cast<WidgetBase>
291305
(WidgetFactory::createCone(
292306
*this,
293307
widgetName(WidgetSection::CONE, widgetID_),
294-
coneRadius_ * direction_.length() * scale,
308+
coneRadius_ * scaled_dir.length(),
295309
deflCol_.toString(),
296310
center,
297311
bmax,
298312
bbox,
299313
true)));
300314

301-
Point diskPos = pos_ + direction_ * diskDistFromCenter_;
302-
Point dp1 = diskPos - diskWidth_ * direction_;
303-
Point dp2 = diskPos + diskWidth_ * direction_;
315+
Point diskPos = pos_ + scaled_dir * diskDistFromCenter_;
316+
Point dp1 = diskPos - diskWidth_ * scaled_dir;
317+
Point dp2 = diskPos + diskWidth_ * scaled_dir;
304318

305319
impl_->pointWidgets_.push_back(boost::dynamic_pointer_cast<WidgetBase>
306320
(WidgetFactory::createDisk(
307321
*this,
308322
widgetName(WidgetSection::DISK, widgetID_),
309-
diskRadius_ * direction_.length() * scale,
323+
diskRadius_ * scaled_dir.length(),
310324
resizeCol_.toString(),
311325
dp1,
312326
dp2,
@@ -328,12 +342,11 @@ FieldHandle ShowAndEditDipoles::GenerateOutputField()
328342
}
329343

330344

345+
const AlgorithmParameterName ShowAndEditDipoles::WidgetSize("WidgetSize");
331346
const AlgorithmParameterName ShowAndEditDipoles::Sizing("Sizing");
332347
const AlgorithmParameterName ShowAndEditDipoles::ShowLastAsVector("ShowLastAsVector");
333348
const AlgorithmParameterName ShowAndEditDipoles::ShowLines("ShowLines");
334-
const AlgorithmParameterName ShowAndEditDipoles::ProbeScale("ProbeScale");
335349
const AlgorithmParameterName ShowAndEditDipoles::PointPositions("PointPositions");
336-
const AlgorithmParameterName ShowAndEditDipoles::NumSeeds("NumSeeds");
337350

338351

339352

src/Modules/Legacy/Visualization/ShowAndEditDipoles.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ namespace SCIRun {
4747
virtual void execute() override;
4848
virtual void setStateDefaults() override;
4949

50+
static const Core::Algorithms::AlgorithmParameterName WidgetSize;
5051
static const Core::Algorithms::AlgorithmParameterName Sizing;
5152
static const Core::Algorithms::AlgorithmParameterName ShowLastAsVector;
5253
static const Core::Algorithms::AlgorithmParameterName ShowLines;
53-
static const Core::Algorithms::AlgorithmParameterName NumSeeds;
54-
static const Core::Algorithms::AlgorithmParameterName ProbeScale;
5554
static const Core::Algorithms::AlgorithmParameterName PointPositions;
5655

5756
INPUT_PORT(0, DipoleInputField, Field);

0 commit comments

Comments
 (0)