4545#include < Core/Datatypes/Legacy/Field/VField.h>
4646#include < Core/Datatypes/Geometry.h>
4747#include < Core/Datatypes/Mesh/MeshFacade.h>
48- #include < Core/GeometryPrimitives/BBox.h>
4948#include < Core/GeometryPrimitives/Point.h>
5049#include < Core/Logging/Log.h>
51- #include < Graphics/Datatypes/GeometryImpl.h>
5250#include < Graphics/Glyphs/GlyphGeom.h>
5351#include < Graphics/Widgets/SphereWidget.h>
5452#include < Graphics/Widgets/ConeWidget.h>
@@ -69,44 +67,6 @@ using namespace Graphics::Datatypes;
6967
7068MODULE_INFO_DEF (ShowAndEditDipoles, Visualization, SCIRun)
7169
72-
73- namespace SCIRun
74- {
75- namespace Modules
76- {
77- namespace Visualization
78- {
79- class ShowAndEditDipolesImpl
80- {
81- public:
82- BBox last_bounds_;
83- std::vector<std::vector<WidgetHandle>* > pointWidgets_;
84- std::vector<GeometryHandle> geoms_;
85- std::vector<Transform> previousTransforms_;
86- double l2norm_;
87-
88- FieldHandle makePointCloud ()
89- {
90- FieldInformation fi (" PointCloudMesh" , 1 , " double" );
91- auto ofield = CreateField (fi);
92- auto mesh = ofield->vmesh ();
93- auto field = ofield->vfield ();
94-
95- for (int i = 0 ; i < pointWidgets_.size (); i++)
96- {
97- const Point location = (*pointWidgets_[i])[0 ]->position ();
98-
99- VMesh::Node::index_type pcindex = mesh->add_point (location);
100- field->resize_fdata ();
101- field->set_value (static_cast <double >(i), pcindex);
102- }
103- return ofield;
104- }
105- };
106- }
107- }
108- }
109-
11070enum WidgetSection {
11171 SPHERE,
11272 CYLINDER,
@@ -116,8 +76,7 @@ enum WidgetSection {
11676};
11777
11878ShowAndEditDipoles::ShowAndEditDipoles ()
119- : GeometryGeneratingModule(staticInfo_),
120- impl_(new ShowAndEditDipolesImpl)
79+ : GeometryGeneratingModule(staticInfo_)
12180{
12281 INITIALIZE_PORT (DipoleInputField);
12382 INITIALIZE_PORT (DipoleOutputField);
@@ -130,6 +89,7 @@ ShowAndEditDipoles::ShowAndEditDipoles()
13089 deflCol_ = ColorRGB (0.5 , 0.5 , 0.5 );
13190 greenCol_ = ColorRGB (0.2 , 0.8 , 0.2 );
13291 resizeCol_ = ColorRGB (0.54 , 1.0 , 0.60 );
92+ lineCol_ = ColorRGB (0.8 , 0.8 , 0.2 );
13393
13494 sphereRadius_ = 0.25 ;
13595 cylinderRadius_ = 0.12 ;
@@ -169,11 +129,11 @@ void ShowAndEditDipoles::execute()
169129 if (inputsChanged ())
170130 {
171131 // Garbage collect
172- for (auto dip : impl_-> pointWidgets_ )
132+ for (auto dip : pointWidgets_)
173133 {
174134 dip->erase (dip->begin (), dip->end ());
175135 }
176- impl_-> pointWidgets_ .erase (impl_-> pointWidgets_ .begin (), impl_-> pointWidgets_ .end ());
136+ pointWidgets_.erase (pointWidgets_.begin (), pointWidgets_.end ());
177137
178138 ReceiveInputField ();
179139 GenerateOutputGeom ();
@@ -185,32 +145,32 @@ void ShowAndEditDipoles::execute()
185145 auto bbox = fh->vmesh ()->get_bounding_box ();
186146 int last_id = pos_.size () - 1 ;
187147 // Destroy last dipole
188- impl_-> pointWidgets_ [last_id]->erase (impl_-> pointWidgets_ [last_id]->begin (), impl_-> pointWidgets_ [last_id]->end ());
148+ pointWidgets_[last_id]->erase (pointWidgets_[last_id]->begin (), pointWidgets_[last_id]->end ());
189149 createDipoleWidget (bbox, pos_[last_id], direction_[last_id] * state->getValue (WidgetSize).toDouble (), last_id, state->getValue (ShowLastAsVector).toBool ());
190150 lastVectorShown_ = state->getValue (ShowLastAsVector).toBool ();
191151 }
192152
193153 // Recreate geom list
194- impl_-> geoms_ .resize (0 );
154+ geoms_.resize (0 );
195155
196156 // Rewrite all existing geom
197- for (int d = 0 ; d < impl_-> pointWidgets_ .size (); d++)
157+ for (int d = 0 ; d < pointWidgets_.size (); d++)
198158 {
199- for (int w = 0 ; w < impl_-> pointWidgets_ [d]->size (); w++)
200- impl_-> geoms_ .push_back ((*impl_-> pointWidgets_ [d])[w]);
159+ for (int w = 0 ; w < pointWidgets_[d]->size (); w++)
160+ geoms_.push_back ((*pointWidgets_[d])[w]);
201161 }
202162 if (state->getValue (ShowLines).toBool ())
203- impl_-> geoms_ .push_back (addLines ());
163+ geoms_.push_back (addLines ());
204164
205- sendOutput (DipoleOutputField, impl_-> makePointCloud ());
165+ sendOutput (DipoleOutputField, makePointCloud ());
206166
207167 std::string idName = " SAEDField" ;
208168 idName += GeometryObject::delimiter +
209169 state->getValue (ShowAndEditDipoles::FieldName).toString () +
210170 " (from " + id ().id_ +" )" +
211171 " (" + std::to_string (widgetIter_) + " )" ;
212172
213- auto comp_geo = createGeomComposite (*this , " dipoles" , impl_-> geoms_ .begin (), impl_-> geoms_ .end ());
173+ auto comp_geo = createGeomComposite (*this , " dipoles" , geoms_.begin (), geoms_.end ());
214174 sendOutput (DipoleWidget, comp_geo);
215175 widgetIter_++;
216176}
@@ -271,7 +231,7 @@ void ShowAndEditDipoles::adjustPositionFromTransform(const Transform& transformM
271231{
272232 DenseMatrix center (4 , 1 );
273233
274- auto currLoc = (*impl_-> pointWidgets_ [id])[type]->position ();
234+ auto currLoc = (*pointWidgets_[id])[type]->position ();
275235 center << currLoc.x (), currLoc.y (), currLoc.z (), 1.0 ;
276236 DenseMatrix newTransform (DenseMatrix (transformMatrix) * center);
277237
@@ -311,7 +271,7 @@ void ShowAndEditDipoles::adjustPositionFromTransform(const Transform& transformM
311271 FieldHandle fh = getRequiredInput (DipoleInputField);
312272 auto state = get_state ();
313273 auto bbox = fh->vmesh ()->get_bounding_box ();
314- bool is_vector = (impl_-> pointWidgets_ [id]->size () == 4 );
274+ bool is_vector = (pointWidgets_[id]->size () == 4 );
315275 createDipoleWidget (bbox, pos_[id], direction_[id] * state->getValue (WidgetSize).toDouble (), id, is_vector);
316276}
317277
@@ -340,8 +300,8 @@ void ShowAndEditDipoles::GenerateOutputGeom()
340300 auto state = get_state ();
341301 auto bbox = fh->vmesh ()->get_bounding_box ();
342302
343- impl_-> last_bounds_ = bbox;
344- impl_-> pointWidgets_ .resize (pos_.size ());
303+ last_bounds_ = bbox;
304+ pointWidgets_.resize (pos_.size ());
345305
346306 // Create all but last dipole as vector
347307 for (int i = 0 ; i < pos_.size () - 1 ; i++)
@@ -385,15 +345,17 @@ void ShowAndEditDipoles::createDipoleWidget(BBox& bbox, Point& pos, Vector scale
385345
386346 Point center = bmin + scaled_dir/2.0 ;
387347
388- impl_->pointWidgets_ [widget_num] = new std::vector<WidgetHandle>(1 + show_as_vector * 3 );
348+ pointWidgets_[widget_num] = new std::vector<WidgetHandle>(1 + show_as_vector * 3 );
349+
350+ ColorRGB sphereCol = (show_as_vector) ? deflPointCol_ : resizeCol_;
389351
390352 // Create glyphs
391- (*impl_-> pointWidgets_ [widget_num])[0 ] = (boost::dynamic_pointer_cast<WidgetBase>
353+ (*pointWidgets_[widget_num])[0 ] = (boost::dynamic_pointer_cast<WidgetBase>
392354 (WidgetFactory::createSphere (
393355 *this ,
394356 widgetName (WidgetSection::SPHERE, widget_num, widgetIter_),
395357 sphereRadius_ * scaled_dir.length (),
396- deflPointCol_ .toString (),
358+ sphereCol .toString (),
397359 bmin,
398360 bbox)));
399361
@@ -402,7 +364,7 @@ void ShowAndEditDipoles::createDipoleWidget(BBox& bbox, Point& pos, Vector scale
402364 // Starts the cylinder position closer to the surface of the sphere
403365 Point cylinderStart = bmin + 0.75 * (scaled_dir * sphereRadius_);
404366
405- (*impl_-> pointWidgets_ [widget_num])[1 ] = (boost::dynamic_pointer_cast<WidgetBase>
367+ (*pointWidgets_[widget_num])[1 ] = (boost::dynamic_pointer_cast<WidgetBase>
406368 (WidgetFactory::createCylinder (
407369 *this ,
408370 widgetName (WidgetSection::CYLINDER, widget_num, widgetIter_),
@@ -411,7 +373,7 @@ void ShowAndEditDipoles::createDipoleWidget(BBox& bbox, Point& pos, Vector scale
411373 cylinderStart,
412374 center,
413375 bbox)));
414- (*impl_-> pointWidgets_ [widget_num])[2 ] = (boost::dynamic_pointer_cast<WidgetBase>
376+ (*pointWidgets_[widget_num])[2 ] = (boost::dynamic_pointer_cast<WidgetBase>
415377 (WidgetFactory::createCone (
416378 *this ,
417379 widgetName (WidgetSection::CONE, widget_num, widgetIter_),
@@ -426,7 +388,7 @@ void ShowAndEditDipoles::createDipoleWidget(BBox& bbox, Point& pos, Vector scale
426388 Point dp1 = diskPos - diskWidth_ * scaled_dir;
427389 Point dp2 = diskPos + diskWidth_ * scaled_dir;
428390
429- (*impl_-> pointWidgets_ [widget_num])[3 ] = (boost::dynamic_pointer_cast<WidgetBase>
391+ (*pointWidgets_[widget_num])[3 ] = (boost::dynamic_pointer_cast<WidgetBase>
430392 (WidgetFactory::createDisk (
431393 *this ,
432394 widgetName (WidgetSection::DISK, widget_num, widgetIter_),
@@ -459,22 +421,38 @@ GeometryHandle ShowAndEditDipoles::addLines()
459421 renState.set (RenderState::IS_ON, true );
460422 renState.set (RenderState::USE_TRANSPARENT_EDGES, false );
461423 renState.mGlyphType = RenderState::GlyphType::LINE_GLYPH;
462- renState.defaultColor = resizeCol_ ;
424+ renState.defaultColor = lineCol_ ;
463425 renState.set (RenderState::USE_DEFAULT_COLOR, true );
464426
465427 // Create lines between every point
466428 for (int a = 0 ; a < pos_.size (); a++)
467429 {
468430 for (int b = 0 ; b < pos_.size (); b++)
469431 {
470- glyphs.addLine (pos_[a], pos_[b], resizeCol_, resizeCol_ );
432+ glyphs.addLine (pos_[a], pos_[b], lineCol_, lineCol_ );
471433 }
472434 }
473435
474436 glyphs.buildObject (*geom, idName, false , 0.5 , ColorScheme::COLOR_UNIFORM, renState, primIn, bbox);
475437 return geom;
476438}
477439
440+ FieldHandle ShowAndEditDipoles::makePointCloud ()
441+ {
442+ FieldInformation fi (" PointCloudMesh" , 0 , " Vector" );
443+ auto ofield = CreateField (fi);
444+ auto mesh = ofield->vmesh ();
445+ auto field = ofield->vfield ();
446+
447+ for (int i = 0 ; i < pointWidgets_.size (); i++)
448+ {
449+ VMesh::Node::index_type pcindex = mesh->add_point (pos_[i]);
450+ field->resize_fdata ();
451+ field->set_value (static_cast <Vector>(direction_[i]), pcindex);
452+ }
453+ return ofield;
454+ }
455+
478456const AlgorithmParameterName ShowAndEditDipoles::FieldName (" FieldName" );
479457const AlgorithmParameterName ShowAndEditDipoles::WidgetSize (" WidgetSize" );
480458const AlgorithmParameterName ShowAndEditDipoles::Sizing (" Sizing" );
@@ -1099,6 +1077,5 @@ ShowAndEditDipoles::tcl_command(GuiArgs& args, void* userdata)
10991077}
11001078
11011079
1102-
11031080} // End namespace BioPSE
11041081#endif
0 commit comments