@@ -327,11 +327,11 @@ OsprayGeometryObjectHandle OsprayDataAlgorithm::addQuadSurface(FieldHandle field
327327 return obj;
328328}
329329
330- OsprayGeometryObjectHandle OsprayDataAlgorithm::addVol (FieldHandle field, ColorMapHandle colorMap) const
330+ OsprayGeometryObjectHandle OsprayDataAlgorithm::addStructVol (FieldHandle field, ColorMapHandle colorMap) const
331331{
332332 auto obj = makeObject (field);
333333 obj->isVolume = true ;
334- obj->GeomType =" Volume " ;
334+ obj->GeomType =" structVol " ;
335335
336336 auto & fieldData = obj->data ;
337337
@@ -340,21 +340,25 @@ OsprayGeometryObjectHandle OsprayDataAlgorithm::addVol(FieldHandle field, ColorM
340340
341341 auto facade (field->mesh ()->getFacade ());
342342 auto vfield = field->vfield ();
343+ auto vmesh = field->vmesh ();
344+
345+ const BBox bbox = vmesh->get_bounding_box ();
346+ Vector size = bbox.diagonal ();
347+ Point center = bbox.center ();
348+ VMesh::dimension_type dim;
349+ vmesh->get_dimensions (dim);
350+ Vector dimensions_ = Vector (1.0 ,1.0 ,1.0 );
351+ for (size_t p=0 ;p<dim.size ();p++) dimensions_[p] = static_cast <double >(dim[p]);
343352
344- // //cast mesh to latvol and fill dim, space, origin
345- // auto latVolM = (boost::shared_ptr<LatVolMesh<Core::Basis::HexTrilinearLgn<Core::Geometry::Point> > >) field->mesh();
346- // std::vector<int> dim; latVolM->get_dim(dim);
347- // std::vector<float> min; latVolM.get_min(min);
348- /* fieldData.origin_x = latVolM->get_min_i();
349- fieldData.origin_y = latVolM->get_min_j();
350- fieldData.origin_z = latVolM->get_min_k();
351- fieldData.dim_x = latVolM->get_ni();
352- fieldData.dim_y = latVolM->get_nj();
353- fieldData.dim_z = latVolM->get_nk();*/
354- // get_ni
355- fieldData.dim_x = 100 ; fieldData.dim_y = 100 ; fieldData.dim_z = 100 ;
356- fieldData.origin_x = -1 ; fieldData.origin_y = -1 ; fieldData.origin_z = -1 ;
357- fieldData.spacing_x = 0.02 ; fieldData.spacing_y = 0.02 ; fieldData.spacing_z = 0.02 ;
353+ fieldData.dim_x = dimensions_[0 ];
354+ fieldData.dim_y = dimensions_[1 ];
355+ fieldData.dim_z = dimensions_[2 ];
356+ fieldData.origin_x = center.x () - size.x ()/2.0 ;
357+ fieldData.origin_y = center.y () - size.y ()/2.0 ;
358+ fieldData.origin_z = center.z () - size.z ()/2.0 ;
359+ fieldData.spacing_x = size.x ()/dimensions_[0 ];
360+ fieldData.spacing_y = size.y ()/dimensions_[1 ];
361+ fieldData.spacing_z = size.z ()/dimensions_[2 ];
358362
359363 double value;
360364 // std::cout << "mname:" << field->mesh()->type_name << std::endl;
@@ -372,15 +376,91 @@ OsprayGeometryObjectHandle OsprayDataAlgorithm::addVol(FieldHandle field, ColorM
372376 vertex_new.push_back (static_cast <float >(point.z ()));
373377
374378 }
379+ // auto alpha = static_cast<float>(get(Parameters::DefaultColorA).toDouble());
380+ if (colorMap)
381+ {
382+ ColorMap_OSP_helper cmp (colorMap->getColorMapName ());
383+ obj->tfn .colors = cmp.colorList ;
384+
385+ // set default opacity for now
386+ // obj->tfn.opacities = cmp.opacityList;
387+ auto alpha = static_cast <float >(get (Parameters::DefaultColorA).toDouble ());
388+ obj->tfn .opacities .push_back (alpha);
389+ obj->tfn .opacities .push_back (alpha);
390+ }
391+ fieldData.color = voxels;
392+ fieldData.vertex = vertex_new;
393+ return obj;
394+ }
395+
396+ OsprayGeometryObjectHandle OsprayDataAlgorithm::addUnstructVol (FieldHandle field, ColorMapHandle colorMap) const
397+ {
398+ auto obj = makeObject (field);
399+ obj->isVolume = true ;
400+ obj->GeomType =" unstructVol" ;
401+
402+ auto & fieldData = obj->data ;
403+
404+ std::vector<float > voxels;
405+ std::vector<float > vertex_new;
406+ std::vector<int32_t > index_new;
407+
408+ auto facade (field->mesh ()->getFacade ());
409+ auto vfield = field->vfield ();
410+ auto vmesh = field->vmesh ();
411+
375412
413+ double value;
414+ // std::cout << "mname:" << field->mesh()->type_name << std::endl;
415+ for (const auto & node : facade->nodes ())
416+ {
417+ auto point = node.point ();
418+ if (vfield->num_values () > 0 )
419+ {
420+ vfield->get_value (value, node.index ());
421+ voxels.push_back (value);
422+ }
423+ vertex_new.push_back (static_cast <float >(point.x ()));
424+ vertex_new.push_back (static_cast <float >(point.y ()));
425+ vertex_new.push_back (static_cast <float >(point.z ()));
426+ }
427+
428+ VMesh::Cell::iterator meshCellIter;
429+ VMesh::Cell::iterator meshCellEnd;
430+ vmesh->end (meshCellEnd);
431+
432+ int numVPerCell = -1 ;
433+ FieldInformation info (field);
434+
435+ if (info.is_tetvol ()) numVPerCell =4 ;
436+ else numVPerCell =8 ;
437+ // else THROW_ALGORITHM_INPUT_ERROR("hex or tet only for unstructured volume!");
438+
439+ for (vmesh->begin (meshCellIter); meshCellIter != meshCellEnd; ++meshCellIter)
440+ {
441+ VMesh::Cell::index_type elemID = *meshCellIter;
442+ VMesh::Node::array_type nodesFromCell (8 );
443+ vmesh->get_nodes (nodesFromCell, elemID);
444+ for (int i=numVPerCell;i<8 ;i++)
445+ nodesFromCell[i] = -4 /(8 -numVPerCell);
446+ for (int i=numVPerCell;i<16 -numVPerCell;i++){
447+ index_new.push_back (nodesFromCell[i%8 ]);
448+ }
449+ }
376450 if (colorMap)
377451 {
378452 ColorMap_OSP_helper cmp (colorMap->getColorMapName ());
379453 obj->tfn .colors = cmp.colorList ;
380- obj->tfn .opacities = cmp.opacityList ;
454+
455+ // set default opacity for now
456+ // obj->tfn.opacities = cmp.opacityList;
457+ auto alpha = static_cast <float >(get (Parameters::DefaultColorA).toDouble ());
458+ obj->tfn .opacities .push_back (alpha);
459+ obj->tfn .opacities .push_back (alpha);
381460 }
382461 fieldData.color = voxels;
383462 fieldData.vertex = vertex_new;
463+ fieldData.index = index_new;
384464 return obj;
385465}
386466
@@ -546,7 +626,6 @@ AlgorithmOutput OsprayDataAlgorithm::run(const AlgorithmInput& input) const
546626 OsprayGeometryObjectHandle renderable;
547627
548628 FieldInformation info (field);
549-
550629 if (info.is_trisurfmesh ())
551630 {
552631 // currently only supports one output, so no point in doing both
@@ -565,13 +644,16 @@ AlgorithmOutput OsprayDataAlgorithm::run(const AlgorithmInput& input) const
565644 }
566645 else if (info.is_volume ())
567646 {
568- if (info.is_latvol ()){
569- renderable = addVol (field, colorMap);
570- }else if (info.is_tetvol ()){
571- THROW_ALGORITHM_INPUT_ERROR (" Tet vol not supported. LatVol only at this point" );
572- }else if (info.is_hexvol ()){
647+ if (info.is_hexvol ()){
648+ // renderable = addUnstructVol(field, colorMap);
573649 THROW_ALGORITHM_INPUT_ERROR (" Hex vol not supported. LatVol only at this point" );
574- }else {
650+ }else if (info.is_latvol ()){
651+ renderable = addStructVol (field, colorMap);
652+ // renderable = addStructVol(field, colorMap);
653+ }else if (info.is_tetvol ()){
654+ renderable = addUnstructVol (field, colorMap);
655+ // THROW_ALGORITHM_INPUT_ERROR("Tet vol not supported. LatVol only at this point");
656+ }else {
575657 THROW_ALGORITHM_INPUT_ERROR (" Unknown vol type. LatVol only at this point" );
576658 }
577659 }
0 commit comments