Skip to content

Commit b11dd34

Browse files
committed
Working on streamline processing
1 parent 49e0b2c commit b11dd34

File tree

3 files changed

+98
-15
lines changed

3 files changed

+98
-15
lines changed

src/ExampleNets/regression/osprayStreamlines.srn5

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,7 +3508,7 @@
35083508
<name>ScaleBarFontSize</name>
35093509
<value>
35103510
<which>0</which>
3511-
<value>1</value>
3511+
<value>99</value>
35123512
</value>
35133513
</second>
35143514
</item>
@@ -3520,7 +3520,7 @@
35203520
<name>ScaleBarHeight</name>
35213521
<value>
35223522
<which>1</which>
3523-
<value>0.00000000000000000e+00</value>
3523+
<value>9.99899999999999949e+01</value>
35243524
</value>
35253525
</second>
35263526
</item>
@@ -3710,7 +3710,7 @@
37103710
</item>
37113711
</modules>
37123712
<connections class_id="13" tracking_level="0" version="0">
3713-
<count>24</count>
3713+
<count>25</count>
37143714
<item_version>0</item_version>
37153715
<item class_id="14" tracking_level="0" version="0">
37163716
<moduleId1_>CalculateGradients:0</moduleId1_>
@@ -3856,6 +3856,18 @@
38563856
<id>0</id>
38573857
</port2_>
38583858
</item>
3859+
<item>
3860+
<moduleId1_>GenerateStreamLines:0</moduleId1_>
3861+
<port1_>
3862+
<name>Streamlines</name>
3863+
<id>0</id>
3864+
</port1_>
3865+
<moduleId2_>InterfaceWithOspray:0</moduleId2_>
3866+
<port2_>
3867+
<name>Streamlines</name>
3868+
<id>0</id>
3869+
</port2_>
3870+
</item>
38593871
<item>
38603872
<moduleId1_>GenerateStreamLines:0</moduleId1_>
38613873
<port1_>

src/Interface/Modules/Visualization/InterfaceWithOspray.ui

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<item row="0" column="0">
3030
<widget class="QTabWidget" name="tabWidget">
3131
<property name="currentIndex">
32-
<number>1</number>
32+
<number>0</number>
3333
</property>
3434
<widget class="QWidget" name="tab">
3535
<attribute name="title">
@@ -635,6 +635,9 @@
635635
<layout class="QGridLayout" name="gridLayout_11">
636636
<item row="0" column="0">
637637
<widget class="QComboBox" name="lightTypeComboBox_">
638+
<property name="enabled">
639+
<bool>false</bool>
640+
</property>
638641
<property name="minimumSize">
639642
<size>
640643
<width>0</width>
@@ -646,11 +649,6 @@
646649
<string>ambient</string>
647650
</property>
648651
</item>
649-
<item>
650-
<property name="text">
651-
<string>none</string>
652-
</property>
653-
</item>
654652
<item>
655653
<property name="text">
656654
<string>spot</string>

src/Modules/Visualization/InterfaceWithOspray.cc

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ namespace detail
183183
ospCommit(world_);
184184
}
185185

186-
void addField(FieldHandle field, boost::optional<ColorMapHandle> colorMap)
186+
void adjustCameraPosition(FieldHandle field)
187187
{
188188
if (state_->getValue(Parameters::AutoCameraView).toBool())
189189
{
@@ -207,10 +207,12 @@ namespace detail
207207
ospSet3fv(camera_, "up", newUp);
208208
ospCommit(camera_);
209209
}
210+
}
210211

212+
void fillDataBuffers(FieldHandle field, ColorMapHandle colorMap)
213+
{
211214
auto facade(field->mesh()->getFacade());
212215

213-
auto map = colorMap.value_or(nullptr);
214216
fieldData_.push_back({});
215217
auto& fieldData = fieldData_.back();
216218
auto& vertex = fieldData.vertex;
@@ -232,9 +234,9 @@ namespace detail
232234
vertex.push_back(0);
233235

234236
vfield->get_value(value, node.index());
235-
if (map)
237+
if (colorMap)
236238
{
237-
nodeColor = map->valueToColor(value);
239+
nodeColor = colorMap->valueToColor(value);
238240
}
239241
color.push_back(static_cast<float>(nodeColor.r()));
240242
color.push_back(static_cast<float>(nodeColor.g()));
@@ -254,6 +256,19 @@ namespace detail
254256
}
255257
}
256258

259+
}
260+
261+
void addField(FieldHandle field, ColorMapHandle colorMap)
262+
{
263+
adjustCameraPosition(field);
264+
265+
fillDataBuffers(field, colorMap);
266+
267+
const auto& fieldData = fieldData_.back();
268+
const auto& vertex = fieldData.vertex;
269+
const auto& color = fieldData.color;
270+
const auto& index = fieldData.index;
271+
257272
// create and setup model and mesh
258273
OSPGeometry mesh = ospNewGeometry("triangles");
259274
OSPData data = ospNewData(vertex.size() / 4, OSP_FLOAT3A, &vertex[0]); // OSP_FLOAT3 format is also supported for vertex positions
@@ -272,9 +287,55 @@ namespace detail
272287
ospCommit(world_);
273288
}
274289

290+
void addStreamline(FieldHandle field)
291+
{
292+
auto vfield = field->vfield();
293+
auto vmesh = field->vmesh();
294+
auto td = field->get_type_description();
295+
if (td)
296+
{
297+
const auto& tname = td->get_name();
298+
std::cout << __FUNCTION__ << " " << tname << std::endl;
299+
}
300+
301+
adjustCameraPosition(field);
302+
303+
fillDataBuffers(field, nullptr);
304+
305+
const auto& fieldData = fieldData_.back();
306+
const auto& vertex = fieldData.vertex;
307+
const auto& color = fieldData.color;
308+
309+
auto& index = fieldData.index;
310+
{
311+
for (const auto& edge : facade->edges())
312+
{
313+
auto nodesFromEdge = edge.nodeIndices();
314+
//auto nodePoints = edge.nodePoints();
315+
std::cout << "Edge " << edge.index() << " nodes=[" << nodesFromEdge[0] << ", " << nodesFromEdge[1] << "]" << std::endl;
316+
}
317+
}
318+
319+
// create and setup model and mesh
320+
OSPGeometry streamlines = ospNewGeometry("streamlines");
321+
OSPData data = ospNewData(vertex.size() / 4, OSP_FLOAT3A, &vertex[0]);
322+
ospCommit(data);
323+
ospSetData(streamlines, "vertex", data);
324+
data = ospNewData(vertex.size() / 4, OSP_FLOAT4, &color[0]);
325+
ospCommit(data);
326+
ospSetData(streamlines, "vertex.color", data);
327+
// data = ospNewData(index.size() / 3, OSP_INT3, &index[0]);
328+
// ospCommit(data);
329+
// ospSetData(streamlines, "index", data);
330+
ospCommit(mesh);
331+
332+
meshes_.push_back(mesh);
333+
ospAddGeometry(world_, mesh);
334+
ospCommit(world_);
335+
}
336+
275337
void render()
276338
{
277-
// create renderer
278339
renderer_ = ospNewRenderer("scivis"); // choose Scientific Visualization renderer
279340

280341
// create and setup light for Ambient Occlusion
@@ -373,6 +434,7 @@ void InterfaceWithOspray::execute()
373434
#ifdef WITH_OSPRAY
374435
auto fields = getRequiredDynamicInputs(Field);
375436
auto colorMaps = getOptionalDynamicInputs(ColorMapObject);
437+
auto streamlines = getOptionalDynamicInputs(Streamlines);
376438

377439
if (needToExecute())
378440
{
@@ -385,7 +447,7 @@ void InterfaceWithOspray::execute()
385447
for (auto&& fieldColor : zip(fields, colorMaps))
386448
{
387449
FieldHandle field;
388-
boost::optional<ColorMapHandle> color;
450+
ColorMapHandle color;
389451
boost::tie(field, color) = fieldColor;
390452

391453
FieldInformation info(field);
@@ -395,6 +457,17 @@ void InterfaceWithOspray::execute()
395457

396458
ospray.addField(field, color);
397459
}
460+
461+
for (auto& streamline : streamlines)
462+
{
463+
FieldInformation info(streamline);
464+
465+
if (!info.is_curvemesh())
466+
THROW_INVALID_ARGUMENT("Module currently only works with curvemesh streamlines.");
467+
468+
ospray.addStreamline(streamline);
469+
}
470+
398471
ospray.render();
399472

400473
auto isoString = boost::posix_time::to_iso_string(boost::posix_time::microsec_clock::universal_time());

0 commit comments

Comments
 (0)