@@ -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