Skip to content

Commit 0f47d9a

Browse files
authored
Merge branch 'master' into clippingPlanes
2 parents fc77607 + acafeba commit 0f47d9a

File tree

9 files changed

+410
-27
lines changed

9 files changed

+410
-27
lines changed

src/Core/Algorithms/Visualization/OsprayDataAlgorithm.cc

Lines changed: 187 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ DEALINGS IN THE SOFTWARE.
3434
#include <Core/Datatypes/Legacy/Field/Field.h>
3535
#include <Core/Datatypes/Legacy/Field/FieldInformation.h>
3636
#include <Core/Datatypes/Legacy/Field/VMesh.h>
37+
#include <Core/Datatypes/Legacy/Field/LatVolMesh.h>
3738
#include <Core/Datatypes/Mesh/VirtualMeshFacade.h>
3839
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
3940
#include <Core/Algorithms/Base/AlgorithmPreconditions.h>
@@ -310,11 +311,160 @@ std::vector<int32_t> OsprayDataAlgorithm::sort_points(EdgeVector edges, std::vec
310311

311312
}
312313

313-
OsprayGeometryObjectHandle OsprayDataAlgorithm::addSurface(FieldHandle field, ColorMapHandle colorMap) const
314+
OsprayGeometryObjectHandle OsprayDataAlgorithm::addTriSurface(FieldHandle field, ColorMapHandle colorMap) const
314315
{
315316
auto obj = fillDataBuffers(field, colorMap);
316317
obj->isSurface = true;
317-
obj->GeomType="Surface";
318+
obj->GeomType="TriSurface";
319+
return obj;
320+
}
321+
322+
OsprayGeometryObjectHandle OsprayDataAlgorithm::addQuadSurface(FieldHandle field, ColorMapHandle colorMap) const
323+
{
324+
auto obj = fillDataBuffers(field, colorMap);
325+
obj->isSurface = true;
326+
obj->GeomType="QuadSurface";
327+
return obj;
328+
}
329+
330+
OsprayGeometryObjectHandle OsprayDataAlgorithm::addStructVol(FieldHandle field, ColorMapHandle colorMap) const
331+
{
332+
auto obj = makeObject(field);
333+
obj->isVolume = true;
334+
obj->GeomType="structVol";
335+
336+
auto& fieldData = obj->data;
337+
338+
std::vector<float> voxels;
339+
std::vector<float> vertex_new;
340+
341+
auto facade(field->mesh()->getFacade());
342+
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]);
352+
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];
362+
363+
double value;
364+
//std::cout << "mname:" << field->mesh()->type_name << std::endl;
365+
366+
for (const auto& node : facade->nodes())
367+
{
368+
auto point = node.point();
369+
if (vfield->num_values() > 0)
370+
{
371+
vfield->get_value(value, node.index());
372+
voxels.push_back(value);
373+
}
374+
vertex_new.push_back(static_cast<float>(point.x()));
375+
vertex_new.push_back(static_cast<float>(point.y()));
376+
vertex_new.push_back(static_cast<float>(point.z()));
377+
378+
}
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+
// alpha pushed twice for both upper and lower values
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+
412+
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 if(info.is_hexvol()) 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+
// OSPRay require an index array of size 8
442+
// for each unstructured mesh cell
443+
// a tetrahedral cell's first 4 vertices are set to -1
444+
// a wedge cell's first 2 vertices are set to -2
445+
VMesh::Cell::index_type elemID = *meshCellIter;
446+
VMesh::Node::array_type nodesFromCell(8);
447+
vmesh->get_nodes(nodesFromCell, elemID);
448+
for(int i=numVPerCell;i<8;i++)
449+
nodesFromCell[i] = -4/(8-numVPerCell);
450+
for(int i=numVPerCell;i<8+numVPerCell;i++){
451+
index_new.push_back(nodesFromCell[i%8]);
452+
}
453+
}
454+
if (colorMap)
455+
{
456+
ColorMap_OSP_helper cmp(colorMap->getColorMapName());
457+
obj->tfn.colors = cmp.colorList;
458+
459+
// set default opacity for now
460+
// alpha pushed twice for both upper and lower values
461+
auto alpha = static_cast<float>(get(Parameters::DefaultColorA).toDouble());
462+
obj->tfn.opacities.push_back(alpha);
463+
obj->tfn.opacities.push_back(alpha);
464+
}
465+
fieldData.color = voxels;
466+
fieldData.vertex = vertex_new;
467+
fieldData.index = index_new;
318468
return obj;
319469
}
320470

@@ -421,19 +571,29 @@ OsprayGeometryObjectHandle OsprayDataAlgorithm::fillDataBuffers(FieldHandle fiel
421571
}
422572
}
423573

574+
FieldInformation info(field);
575+
576+
424577
auto& index = fieldData.index;
425578
{
426579
for (const auto& face : facade->faces())
427580
{
428581
auto nodes = face.nodeIndices();
429-
index.push_back(static_cast<int32_t>(nodes[0]));
430-
index.push_back(static_cast<int32_t>(nodes[1]));
431-
index.push_back(static_cast<int32_t>(nodes[2]));
582+
if(info.is_quadsurfmesh()){
583+
// quad face added in reverse order for correct normal in OSPRay viewer
584+
index.push_back(static_cast<int32_t>(nodes[3]));
585+
index.push_back(static_cast<int32_t>(nodes[2]));
586+
index.push_back(static_cast<int32_t>(nodes[1]));
587+
index.push_back(static_cast<int32_t>(nodes[0]));
588+
}else{
589+
index.push_back(static_cast<int32_t>(nodes[0]));
590+
index.push_back(static_cast<int32_t>(nodes[1]));
591+
index.push_back(static_cast<int32_t>(nodes[2]));
592+
}
432593
}
433594
}
434595

435-
FieldInformation info(field);
436-
if (get(Parameters::UseNormals).toBool() && info.is_trisurfmesh())
596+
if (get(Parameters::UseNormals).toBool() && info.is_surface())
437597
{
438598
auto mesh = field->vmesh();
439599
mesh->synchronize(Mesh::NORMALS_E);
@@ -471,7 +631,6 @@ AlgorithmOutput OsprayDataAlgorithm::run(const AlgorithmInput& input) const
471631
OsprayGeometryObjectHandle renderable;
472632

473633
FieldInformation info(field);
474-
475634
if (info.is_trisurfmesh())
476635
{
477636
// currently only supports one output, so no point in doing both
@@ -481,7 +640,26 @@ AlgorithmOutput OsprayDataAlgorithm::run(const AlgorithmInput& input) const
481640
}
482641
else
483642
{
484-
renderable = addSurface(field, colorMap);
643+
renderable = addTriSurface(field, colorMap);
644+
}
645+
}
646+
else if (info.is_quadsurfmesh()){
647+
renderable = addQuadSurface(field, colorMap);
648+
//THROW_ALGORITHM_INPUT_ERROR("field type quad.");
649+
}
650+
else if (info.is_volume())
651+
{
652+
if(info.is_hexvol()){
653+
renderable = addUnstructVol(field, colorMap);
654+
//THROW_ALGORITHM_INPUT_ERROR("Hex vol not supported. LatVol only at this point");
655+
}else if(info.is_latvol()){
656+
renderable = addStructVol(field, colorMap);
657+
//renderable = addStructVol(field, colorMap);
658+
}else if(info.is_tetvol()){
659+
renderable = addUnstructVol(field, colorMap);
660+
//THROW_ALGORITHM_INPUT_ERROR("Tet vol not supported. LatVol only at this point");
661+
}else {
662+
THROW_ALGORITHM_INPUT_ERROR("Unknown vol type. LatVol only at this point");
485663
}
486664
}
487665
else if (info.is_pointcloudmesh())

src/Core/Algorithms/Visualization/OsprayDataAlgorithm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ namespace SCIRun
6666
private:
6767
Core::Datatypes::OsprayGeometryObjectHandle addStreamline(FieldHandle field, Core::Datatypes::ColorMapHandle colorMap) const;
6868
Core::Datatypes::OsprayGeometryObjectHandle addSphere(FieldHandle field, Core::Datatypes::ColorMapHandle colorMap) const;
69-
Core::Datatypes::OsprayGeometryObjectHandle addSurface(FieldHandle field, Core::Datatypes::ColorMapHandle colorMap) const;
69+
Core::Datatypes::OsprayGeometryObjectHandle addTriSurface(FieldHandle field, Core::Datatypes::ColorMapHandle colorMap) const;
70+
Core::Datatypes::OsprayGeometryObjectHandle addQuadSurface(FieldHandle field, Core::Datatypes::ColorMapHandle colorMap) const;
71+
Core::Datatypes::OsprayGeometryObjectHandle addStructVol(FieldHandle field, Core::Datatypes::ColorMapHandle colorMap) const;
72+
Core::Datatypes::OsprayGeometryObjectHandle addUnstructVol(FieldHandle field, Core::Datatypes::ColorMapHandle colorMap) const;
7073
Core::Datatypes::OsprayGeometryObjectHandle addCylinder(FieldHandle field, Core::Datatypes::ColorMapHandle colorMap) const;
7174
void connected_component_edges(EdgeVector all_edges, std::vector<EdgeVector>& subsets, std::vector<int>& size_regions)const;
7275
void ReorderNodes(std::vector<int32_t> index, std::vector<int32_t> cc_index, std::vector<float> vertex, std::vector<float> color, std::vector<int32_t>& index_new, std::vector<float>& vertex_new,std::vector<float>& color_new) const;

src/Core/Datatypes/ColorMap.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ ColorMap* ColorMap::clone() const
5454
return new ColorMap(*this);
5555
}
5656

57+
58+
5759
namespace detail
5860
{
61+
5962
class Rainbow : public ColorMapStrategy
6063
{
6164
public:
@@ -340,3 +343,45 @@ double ColorMap::getColorMapShift() const { return shift_; }
340343
bool ColorMap::getColorMapInvert() const { return invert_; }
341344
double ColorMap::getColorMapRescaleScale() const { return rescale_scale_; }
342345
double ColorMap::getColorMapRescaleShift() const { return rescale_shift_; }
346+
347+
348+
349+
ColorMap_OSP_helper::ColorMap_OSP_helper(const std::string name){
350+
opacityList.push_back(0.5);
351+
opacityList.push_back(0.5);
352+
if(name.compare("Rainbow") == 0){
353+
colorList.push_back(0); colorList.push_back(0); colorList.push_back(1);
354+
colorList.push_back(0); colorList.push_back(0.75); colorList.push_back(0.75);
355+
colorList.push_back(0); colorList.push_back(1); colorList.push_back(0);
356+
colorList.push_back(1); colorList.push_back(0.5); colorList.push_back(0);
357+
colorList.push_back(1); colorList.push_back(0); colorList.push_back(0);
358+
}else if(name.compare("Old Rainbow") == 0){
359+
colorList.push_back(0); colorList.push_back(0); colorList.push_back(1);
360+
colorList.push_back(0); colorList.push_back(1); colorList.push_back(1);
361+
colorList.push_back(0); colorList.push_back(1); colorList.push_back(0);
362+
colorList.push_back(1); colorList.push_back(1); colorList.push_back(0);
363+
colorList.push_back(1); colorList.push_back(0); colorList.push_back(0);
364+
}else if(name.compare("Blackbody") == 0){
365+
colorList.push_back(0); colorList.push_back(0); colorList.push_back(0);
366+
colorList.push_back(1); colorList.push_back(0); colorList.push_back(0);
367+
colorList.push_back(1); colorList.push_back(1); colorList.push_back(0);
368+
colorList.push_back(1); colorList.push_back(1); colorList.push_back(1);
369+
}else if(name.compare("Grayscale") == 0){
370+
colorList.push_back(0); colorList.push_back(0); colorList.push_back(0);
371+
colorList.push_back(1); colorList.push_back(1); colorList.push_back(1);
372+
}else if(name.compare("Orange,Black,Lime") == 0){
373+
colorList.push_back(1); colorList.push_back(0.5); colorList.push_back(0);
374+
colorList.push_back(0); colorList.push_back(0); colorList.push_back(0);
375+
colorList.push_back(0); colorList.push_back(1); colorList.push_back(0);
376+
}else if(name.compare("Darkhue") == 0){
377+
colorList.push_back(0); colorList.push_back(0); colorList.push_back(0);
378+
colorList.push_back(0); colorList.push_back(0); colorList.push_back(0.333333);
379+
colorList.push_back(0.5); colorList.push_back(0); colorList.push_back(0.5);
380+
colorList.push_back(1); colorList.push_back(0); colorList.push_back(0);
381+
colorList.push_back(1); colorList.push_back(0); colorList.push_back(0.25*2.6666666);
382+
}else if(name.compare("BP Seismic") == 0){
383+
colorList.push_back(0); colorList.push_back(0); colorList.push_back(1);
384+
colorList.push_back(1); colorList.push_back(1); colorList.push_back(1);
385+
colorList.push_back(1); colorList.push_back(0); colorList.push_back(0);
386+
}
387+
}

src/Core/Datatypes/ColorMap.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ namespace Datatypes {
118118
private:
119119
StandardColorMapFactory() = delete;
120120
};
121+
122+
// colormap helper for ospray transfer function
123+
class ColorMap_OSP_helper
124+
{
125+
public:
126+
std::vector<float> colorList;
127+
std::vector<float> opacityList;
128+
ColorMap_OSP_helper(const std::string name);
129+
};
121130

122131
}}}
123132

src/Core/Datatypes/Geometry.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,18 @@ namespace Datatypes
8989
{
9090
std::vector<float> vertex, color, vertex_normal;
9191
std::vector<int32_t> index;
92+
int dim_x, dim_y,dim_z;
93+
float origin_x,origin_y,origin_z;
94+
float spacing_x, spacing_y, spacing_z;
9295
};
9396

9497
FieldData data;
98+
struct transferFunc
99+
{
100+
std::vector<float> colors;
101+
std::vector<float> opacities;
102+
};
103+
transferFunc tfn;
95104

96105
double radius;
97106

src/Interface/Modules/Render/Ospray/VolumeViewer.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -762,22 +762,19 @@ void VolumeViewer::loadGeometry(OSPGeometry geom)
762762

763763
void VolumeViewer::loadVolume(OSPVolume vol, const vec2f& voxelRange, const box3f& bounds)
764764
{
765-
if (ownModelPerObject_)
766-
modelStates_.push_back(ModelState(ospNewModel()));
765+
//if (ownModelPerObject_)
766+
// modelStates_.push_back(ModelState(ospNewModel()));
767767

768768
assert(vol);
769-
// For now we set the same transfer function on all volumes.
770-
ospSetObject(vol, "transferFunction", transferFunction);
769+
771770
ospCommit(vol);
772-
773771
// Add the loaded volume(s) to the model.
774772
ospAddVolume(modelStates_.back().model, vol);
775-
776773
assert(!bounds.empty());
777774
// Add to volumes vector for the current model.
778775
modelStates_.back().volumes.push_back(std::make_shared<ModelState::Volume>(vol, bounds, voxelRange));
779776

780-
if (ownModelPerObject_)
777+
//if (ownModelPerObject_)
781778
ospCommit(modelStates_.back().model);
782779
}
783780

@@ -838,7 +835,7 @@ void VolumeViewer::globalInit(const std::string &renderer_type)
838835
// Create an OSPRay transfer function.
839836
transferFunction = ospNewTransferFunction("piecewise_linear");
840837
exitOnCondition(transferFunction == NULL, "could not create OSPRay transfer function object");
841-
ospCommit(transferFunction);
838+
//ospCommit(transferFunction);
842839
}
843840

844841
const float b = -3;

src/Interface/Modules/Render/Ospray/VolumeViewer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public Q_SLOTS:
242242
void setDirectionalLightColor(float r, float g, float b);
243243
void setBackgroundColor(float r, float g, float b);
244244

245+
245246

246247
protected:
247248

0 commit comments

Comments
 (0)