From eb91a926506671aca2d743313acc328d75a9a0d5 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 30 Oct 2018 07:51:39 -0400 Subject: [PATCH 1/3] Representation fixes. + Fix so that colors are recomputed when input multiblock changes. + Fix translucent geometry handling to account for all actors. + Note a potential issue with glyph coloring until we have data and a test case to investigate. --- .../paraview/server/vtkSMTKModelRepresentation.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx index 639e9f194e..0cc606ddcc 100644 --- a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx +++ b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx @@ -224,6 +224,9 @@ int vtkSMTKModelRepresentation::RequestData( this->GlyphMapper->Modified(); this->GetModelBounds(); + + // New input data requires updated block colors: + this->UpdateColorBy = true; return Superclass::RequestData(request, inVec, outVec); } @@ -255,7 +258,9 @@ int vtkSMTKModelRepresentation::ProcessViewRequest( // ordered compositing when rendering translucent geometry. We need to extend // this condition to consider translucent LUTs once we start supporting them. if (this->Entities->HasTranslucentPolygonalGeometry() || - this->GlyphEntities->HasTranslucentPolygonalGeometry()) + this->GlyphEntities->HasTranslucentPolygonalGeometry() || + this->SelectedEntities->HasTranslucentPolygonalGeometry() || + this->SelectedGlyphEntities->HasTranslucentPolygonalGeometry()) { outInfo->Set(vtkPVRenderView::NEED_ORDERED_COMPOSITING(), 1); } @@ -1131,6 +1136,8 @@ void vtkSMTKModelRepresentation::ColorByEntity(vtkMultiBlockDataSet* data) auto uuid = data->GetMetaData(it)->Get(vtkModelMultiBlockSource::ENTITYID()); if (uuid) { + // FIXME? Check whether UUID corresponds to an instance or not. + // Instances should use the GlyphMapper rather than the EntityMapper. ColorBlockAsEntity(this->EntityMapper, dataObj, uuid, this->Resource); } } -- GitLab From e798cbb96eb6dffc8c288511068be4b0bd79d1e8 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 30 Oct 2018 08:59:23 -0400 Subject: [PATCH 2/3] Attribute selections highlight associations. --- .../server/vtkSMTKModelRepresentation.cxx | 79 +++++++++++++------ .../server/vtkSMTKModelRepresentation.h | 4 + 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx index 0cc606ddcc..f765ff9c84 100644 --- a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx +++ b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx @@ -37,10 +37,16 @@ #include "smtk/extension/paraview/server/vtkSMTKModelRepresentation.h" #include "smtk/extension/paraview/server/vtkSMTKWrapper.h" #include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h" + +#include "smtk/attribute/Attribute.h" +#include "smtk/attribute/ReferenceItem.h" + #include "smtk/model/Entity.h" #include "smtk/model/Resource.h" + #include "smtk/resource/Component.h" #include "smtk/resource/Manager.h" + #include "smtk/view/Selection.h" namespace @@ -446,6 +452,7 @@ bool vtkSMTKModelRepresentation::ApplyDefaultStyle( smtk::view::SelectionPtr seln, RenderableDataMap& renderables, vtkSMTKModelRepresentation* self) { bool atLeastOneSelected = false; + smtk::attribute::Attribute::Ptr attr; for (auto& item : seln->currentSelection()) { if (item.second <= 0) @@ -454,36 +461,62 @@ bool vtkSMTKModelRepresentation::ApplyDefaultStyle( continue; } - // Determine the actor-pair we are dealing with (normal or instanced): - auto entity = item.first->as(); - bool isGlyphed = entity && entity->isInstance(); - - // Determine if the user has hidden the entity - auto& smap = self->GetComponentState(); - auto cstate = smap.find(item.first->id()); - bool hidden = (cstate != smap.end() && !cstate->second.m_visibility); - - // TODO: A single persistent object may have a "footprint" - // (i.e., a set) that represents it. - // In this case, we should set the selected state for all - // of the footprint. However, this is complicated by the fact - // that some of the footprint entries might correspond to - // children (boundary) objects that might be controlled - // independently. - // - // For now, assume each persistent object has at most 1 - // vtkDataObject associated with it. - auto dataIt = renderables.find(item.first->id()); - if (dataIt != renderables.end()) + // If the item is an attribute, it will not be directly renderable, + // so preview its associated entities. + attr = item.first->as(); + if (attr) { - self->SetSelectedState(dataIt->second, hidden ? -1 : item.second, isGlyphed); - atLeastOneSelected = true; + for (auto obj : *attr->associations()) + { + atLeastOneSelected |= self->SelectComponentFootprint(obj, /*selnBit TODO*/ 1, renderables); + } + } + else + { + atLeastOneSelected |= self->SelectComponentFootprint(item.first, item.second, renderables); } } return atLeastOneSelected; } +bool vtkSMTKModelRepresentation::SelectComponentFootprint( + smtk::resource::PersistentObjectPtr item, int selnBits, RenderableDataMap& renderables) +{ + bool atLeastOneSelected = false; + if (!item) + { + return atLeastOneSelected; + } + + // Determine the actor-pair we are dealing with (normal or instanced): + auto entity = item->as(); + bool isGlyphed = entity && entity->isInstance(); + + // Determine if the user has hidden the entity + auto& smap = this->GetComponentState(); + auto cstate = smap.find(item->id()); + bool hidden = (cstate != smap.end() && !cstate->second.m_visibility); + + // TODO: A single persistent object may have a "footprint" + // (i.e., a set) that represents it. + // In this case, we should set the selected state for all + // of the footprint. However, this is complicated by the fact + // that some of the footprint entries might correspond to + // children (boundary) objects that might be controlled + // independently. + // + // For now, assume each persistent object has at most 1 + // vtkDataObject associated with it. + auto dataIt = renderables.find(item->id()); + if (dataIt != renderables.end()) + { + this->SetSelectedState(dataIt->second, hidden ? -1 : selnBits, isGlyphed); + atLeastOneSelected = true; + } + return atLeastOneSelected; +} + int vtkSMTKModelRepresentation::FillInputPortInformation(int port, vtkInformation* info) { // Saying INPUT_IS_OPTIONAL() is essential, since representations don't have diff --git a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.h b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.h index ab643d2421..b2430619ae 100644 --- a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.h +++ b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.h @@ -290,6 +290,10 @@ public: static bool ApplyDefaultStyle( smtk::view::SelectionPtr seln, RenderableDataMap& renderables, vtkSMTKModelRepresentation* rep); + /// A helper used by ApplyDefaultStyle to handle a single component. + bool SelectComponentFootprint( + smtk::resource::PersistentObjectPtr item, int selnBits, RenderableDataMap& renderables); + /// Return the map from persistent-object UUID to user-specified state. /// /// This is read only. If you want to modify component state, -- GitLab From 32f32b8a717fee2df7424b36bddf9d00c33a5cb3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 30 Oct 2018 20:36:51 -0400 Subject: [PATCH 3/3] Better rendering of unrenderable selections. Render the footprint of selected items without renderable geometry instead of doing nothing. --- .../server/vtkSMTKModelRepresentation.cxx | 77 ++++++++++++++++++- .../server/vtkSMTKModelRepresentation.h | 4 + 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx index f765ff9c84..ac7f9e7f81 100644 --- a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx +++ b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.cxx @@ -41,7 +41,11 @@ #include "smtk/attribute/Attribute.h" #include "smtk/attribute/ReferenceItem.h" +#include "smtk/model/AuxiliaryGeometry.h" +#include "smtk/model/CellEntity.h" #include "smtk/model/Entity.h" +#include "smtk/model/Group.h" +#include "smtk/model/Model.h" #include "smtk/model/Resource.h" #include "smtk/resource/Component.h" @@ -512,7 +516,78 @@ bool vtkSMTKModelRepresentation::SelectComponentFootprint( if (dataIt != renderables.end()) { this->SetSelectedState(dataIt->second, hidden ? -1 : selnBits, isGlyphed); - atLeastOneSelected = true; + atLeastOneSelected |= !hidden; + } + else + { + // The component does not have any geometry of its own... but perhaps + // we can render its children highlighted instead. + auto ent = item->as(); + if (ent) + { + if (ent->isGroup()) + { + auto members = smtk::model::Group(ent).members(); + atLeastOneSelected |= this->SelectComponentFootprint(members, selnBits, renderables); + } + else if (ent->isModel()) + { + auto model = smtk::model::Model(ent); + auto cells = model.cellsAs(); + for (auto cell : cells) + { + // If the cell has no geometry, then add its boundary cells. + if (renderables.find(cell.entity()) == renderables.end()) + { + auto bdys = smtk::model::CellEntity(cell).boundingCellsAs(); + cells.insert(bdys.begin(), bdys.end()); + } + } + atLeastOneSelected |= this->SelectComponentFootprint(cells, selnBits, renderables); + + auto groups = model.groups(); + for (auto group : groups) + { + auto members = group.members(); + atLeastOneSelected |= this->SelectComponentFootprint(members, selnBits, renderables); + } + + // TODO: Auxiliary geometry may also be handled by a separate representation. + // Need to ensure that representation also renders selection properly. + auto auxGeoms = model.auxiliaryGeometry(); + // Convert auxGeoms to EntityRefs to match SelectComponentFootprint() API: + smtk::model::EntityRefs auxEnts; + for (auto auxGeom : auxGeoms) + { + auxEnts.insert(auxGeom); + } + atLeastOneSelected |= this->SelectComponentFootprint(auxEnts, selnBits, renderables); + } + else if (ent->isCellEntity()) + { + auto bdys = smtk::model::CellEntity(ent).boundingCellsAs(); + atLeastOneSelected |= this->SelectComponentFootprint(bdys, selnBits, renderables); + } + } + } + return atLeastOneSelected; +} + +bool vtkSMTKModelRepresentation::SelectComponentFootprint( + const smtk::model::EntityRefs& items, int selnBits, RenderableDataMap& renderables) +{ + bool atLeastOneSelected = false; + auto& smap = this->GetComponentState(); + for (auto item : items) + { + auto dataIt = renderables.find(item.entity()); + auto cstate = smap.find(item.entity()); + bool hidden = (cstate != smap.end() && !cstate->second.m_visibility); + if (dataIt != renderables.end()) + { + this->SetSelectedState(dataIt->second, hidden ? -1 : selnBits, item.isInstance()); + atLeastOneSelected |= !hidden; + } } return atLeastOneSelected; } diff --git a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.h b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.h index b2430619ae..4f1b254aa7 100644 --- a/smtk/extension/paraview/server/vtkSMTKModelRepresentation.h +++ b/smtk/extension/paraview/server/vtkSMTKModelRepresentation.h @@ -294,6 +294,10 @@ public: bool SelectComponentFootprint( smtk::resource::PersistentObjectPtr item, int selnBits, RenderableDataMap& renderables); + /// A helper used by ApplyDefaultStyle to handle model entity components. + bool SelectComponentFootprint( + const smtk::model::EntityRefs& items, int selnBits, RenderableDataMap& renderables); + /// Return the map from persistent-object UUID to user-specified state. /// /// This is read only. If you want to modify component state, -- GitLab