52 ,mainLayout(new QGridLayout(this))
53 ,showNodes(new QCheckBox(this))
54 ,sliderNodeRadius(new QSlider(this))
55 ,showNodeLabels(new QCheckBox(this))
56 ,showSpecificNodeLabel(new QCheckBox(this))
57 ,showSpecificNodeLabelEdit(new QLineEdit(
"0"))
58 ,showVelocities(new QCheckBox(this))
59 ,velocityScaleEdit(new QLineEdit(
"1"))
61 ,
nodeGlyphs(vtkSmartPointer<vtkGlyph3D>::New())
62 ,
nodeMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
63 ,
nodeActor(vtkSmartPointer<vtkActor>::New())
65 ,
labelMapper(vtkSmartPointer<vtkLabeledDataMapper>::New())
66 ,
labelActor(vtkSmartPointer<vtkActor2D>::New())
75 ,
nodeClr{{100,100,100},{0,255,255},{255,0,255},{1,1,1}}
78 const int initialRadius(12);
80 showNodes->setText(
"nodes");
81 showNodes->setChecked(
false);
82 nodeActor->SetVisibility(
false);
83 sliderNodeRadius->setEnabled(
false);
84 sliderNodeRadius->setMinimum(0);
85 sliderNodeRadius->setMaximum(30);
86 sliderNodeRadius->setValue(initialRadius);
87 sliderNodeRadius->setOrientation(Qt::Horizontal);
90 showSpecificNodeLabel->setText(
"selected nodes");
91 showSpecificNodeLabel->setChecked(
false);
92 specificNodeLabelActor->SetVisibility(
false);
94 showNodeLabels->setText(
"node labels");
95 showNodeLabels->setChecked(
false);
96 labelActor->SetVisibility(
false);
98 showVelocities->setText(
"velocities");
99 showVelocities->setChecked(
false);
100 velocityActor->SetVisibility(
false);
101 velocityScaleEdit->setEnabled(
false);
103 auto *nodesBox = controls::box(
"Nodes",
this,
"Show or hide network-node markers.", showNodes);
104 controls::field(controls::grid(nodesBox), 0,
"Radius", sliderNodeRadius,
105 "Marker radius in simulation length units b. Changes apply immediately.");
106 auto *labelsBox = controls::box(
"Node labels",
this,
"Show IDs for all network nodes.", showNodeLabels);
107 auto *selectedBox = controls::box(
"Selected node labels",
this,
"Show IDs only for the specified nodes.",
108 showSpecificNodeLabel);
109 controls::field(controls::grid(selectedBox), 0,
"Node IDs", showSpecificNodeLabelEdit,
110 "Enter space-separated node IDs. Press Enter to update the labels.");
112 controls::box(
"Velocities",
this,
"Show velocity arrows at network nodes.", showVelocities);
113 controls::field(controls::grid(velocityBox), 0,
"Scale", velocityScaleEdit,
114 "Multiply each velocity vector by this display scale. Press Enter to apply.");
115 mainLayout->addWidget(nodesBox, 0, 0);
116 mainLayout->addWidget(labelsBox, 1, 0);
117 mainLayout->addWidget(selectedBox, 2, 0);
118 mainLayout->addWidget(velocityBox, 3, 0);
119 mainLayout->setRowStretch(4, 1);
120 this->setLayout(mainLayout);
122 connect(showNodes,SIGNAL(stateChanged(
int)),
this, SLOT(modify()));
123 connect(showNodeLabels,SIGNAL(stateChanged(
int)),
this, SLOT(modify()));
124 connect(showVelocities,SIGNAL(stateChanged(
int)),
this, SLOT(modify()));
125 connect(velocityScaleEdit,SIGNAL(returnPressed()),
this, SLOT(modify()));
126 connect(showSpecificNodeLabel,SIGNAL(stateChanged(
int)),
this, SLOT(modify()));
127 connect(showSpecificNodeLabelEdit,SIGNAL(returnPressed()),
this, SLOT(modify()));
128 connect(sliderNodeRadius,SIGNAL(valueChanged(
int)),
this, SLOT(modify()));
131 nodeGlyphs->SetInputData(nodePolyData);
132 nodeGlyphs->SetSourceConnection(vtkSmartPointer<vtkSphereSource>::New()->GetOutputPort());
133 nodeGlyphs->ScalingOn();
134 nodeGlyphs->SetScaleModeToScaleByVector();
135 nodeGlyphs->SetScaleFactor(initialRadius);
136 nodeGlyphs->SetColorModeToColorByScalar();
137 nodeGlyphs->Update();
138 nodeMapper->SetInputConnection(nodeGlyphs->GetOutputPort());
139 nodeActor->SetMapper(nodeMapper);
142 labelMapper->SetInputData(labelPolyData);
143 labelMapper->SetLabelModeToLabelScalars();
144 labelMapper->SetLabelFormat(
"%1.0f");
145 labelMapper->GetLabelTextProperty()->SetFontSize(20);
146 labelActor->SetMapper(labelMapper);
147 labelActor->GetProperty()->SetColor(0.0, 0.0, 0.0);
150 velocityGlyphs->SetInputData(velocityPolyData);
151 velocityGlyphs->SetSourceConnection(vtkSmartPointer<vtkArrowSource>::New()->GetOutputPort());
152 velocityGlyphs->ScalingOn();
153 velocityGlyphs->SetScaleModeToScaleByVector();
154 velocityGlyphs->OrientOn();
155 velocityGlyphs->ClampingOff();
156 velocityGlyphs->SetVectorModeToUseVector();
157 velocityGlyphs->SetIndexModeToOff();
158 velocityMapper->SetInputConnection(velocityGlyphs->GetOutputPort());
159 velocityMapper->ScalarVisibilityOff();
160 velocityActor->SetMapper(velocityMapper);
161 velocityActor->GetProperty()->SetColor(1.0, 0.0, 1.0);
164 specificNodeLabelMapper->SetInputData(specificNodeLabelPolyData);
165 specificNodeLabelMapper->SetLabelModeToLabelScalars();
166 specificNodeLabelMapper->SetLabelFormat(
"%1.0f");
167 specificNodeLabelMapper->GetLabelTextProperty()->SetFontSize(20);
168 specificNodeLabelActor->SetMapper(specificNodeLabelMapper);
169 specificNodeLabelActor->GetProperty()->SetColor(1.0, 0.0, 0.0);
172 renderer->AddActor(nodeActor);
173 renderer->AddActor(velocityActor);
174 renderer->AddActor(labelActor);
175 renderer->AddActor(specificNodeLabelActor);
184 std::cout<<
"Updating nodes..."<<std::flush;
185 const auto t0= std::chrono::system_clock::now();
187 vtkSmartPointer<vtkPoints> nodePoints(vtkSmartPointer<vtkPoints>::New());
188 vtkSmartPointer<vtkUnsignedCharArray> nodeColors(vtkSmartPointer<vtkUnsignedCharArray>::New());
189 nodeColors->SetNumberOfComponents(3);
191 vtkSmartPointer<vtkDoubleArray> nodeLabels(vtkSmartPointer<vtkDoubleArray>::New());
192 nodeLabels->SetNumberOfComponents(1);
193 nodeLabels->SetName(
"node IDs");
195 vtkSmartPointer<vtkPoints> specificNodePoints(vtkSmartPointer<vtkPoints>::New());
196 vtkSmartPointer<vtkDoubleArray> specificNodeLabels(vtkSmartPointer<vtkDoubleArray>::New());
197 specificNodeLabels->SetNumberOfComponents(1);
200 vtkSmartPointer<vtkDoubleArray> velocityVectors(vtkSmartPointer<vtkDoubleArray>::New());
201 velocityVectors->SetNumberOfComponents(3);
202 velocityVectors->SetName(
"nodeVelocity");
204 std::set<size_t> singleNodes;
205 if(showSpecificNodeLabel->isChecked())
209 std::stringstream
ss(showSpecificNodeLabelEdit->text() .toStdString());
213 singleNodes.insert(val);
216 catch(std::exception&
e)
218 showSpecificNodeLabel->setText(QString::fromStdString(
e.what()));
229 for(
const auto& node : configIO.nodes())
231 if(singleNodes.find(node.sID)!=singleNodes.end())
233 specificNodePoints->InsertNextPoint(node.P.data());
234 specificNodeLabels->InsertNextTuple1(node.sID);
239 nodePoints->InsertNextPoint(node.P.data());
240 nodeLabels->InsertNextTuple1(node.sID);
241 velocityVectors->InsertNextTuple(node.V.data());
244 int location=node.meshLocation;
247 const auto found=network->
networkNodes().find(node.sID);
250 if(
const auto liveNode=found->second.lock())
252 location=liveNode->meshLocation();
256 const int colorIndex=location>=0 && location<=2?location:3;
257 nodeColors->InsertNextTypedTuple(this->
nodeClr[colorIndex]);