From 2d9357d2ba55469f8b13d37b3eab33bfc48283da Mon Sep 17 00:00:00 2001 From: Haocheng LIU Date: Tue, 30 Jul 2019 14:13:09 -0400 Subject: [PATCH] Add new features for instance glyphing support This commit add custom orientation, mask, scale and per point color support for glpyhing smtk entities. --- doc/release/notes/extend-instance-features.md | 4 ++ .../server/vtkSMTKResourceRepresentation.cxx | 1 + .../vtk/source/vtkModelMultiBlockSource.cxx | 60 +++++++++++++++---- smtk/model/Instance.h | 14 +++++ 4 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 doc/release/notes/extend-instance-features.md diff --git a/doc/release/notes/extend-instance-features.md b/doc/release/notes/extend-instance-features.md new file mode 100644 index 0000000000..cf22d04f78 --- /dev/null +++ b/doc/release/notes/extend-instance-features.md @@ -0,0 +1,4 @@ +## Add new features for instance glyphing support + +This commit add custom orientation, mask, scale and per point color +support for glpyhing smtk entities. diff --git a/smtk/extension/paraview/server/vtkSMTKResourceRepresentation.cxx b/smtk/extension/paraview/server/vtkSMTKResourceRepresentation.cxx index 67c499587d..a269d4597b 100644 --- a/smtk/extension/paraview/server/vtkSMTKResourceRepresentation.cxx +++ b/smtk/extension/paraview/server/vtkSMTKResourceRepresentation.cxx @@ -651,6 +651,7 @@ void vtkSMTKResourceRepresentation::ConfigureGlyphMapper(vtkGlyph3DMapper* mappe mapper->SetScaleArray(VTK_INSTANCE_SCALE); mapper->SetScaling(true); + mapper->SetScaleModeToScaleByVectorComponents(); mapper->SetOrientationArray(VTK_INSTANCE_ORIENTATION); mapper->SetOrientationMode(vtkGlyph3DMapper::ROTATION); diff --git a/smtk/extension/vtk/source/vtkModelMultiBlockSource.cxx b/smtk/extension/vtk/source/vtkModelMultiBlockSource.cxx index 44605e7b20..a1c401f89c 100644 --- a/smtk/extension/vtk/source/vtkModelMultiBlockSource.cxx +++ b/smtk/extension/vtk/source/vtkModelMultiBlockSource.cxx @@ -718,22 +718,58 @@ void vtkModelMultiBlockSource::AddInstancePoints(vtkPolyData* instancePoly, vtkPoints* pts = instancePoly->GetPoints(); auto pd = instancePoly->GetPointData(); // WARNING: Array indices are hardcoded here for speed. See PrepareInstanceOutput above. - auto orient = vtkDoubleArray::SafeDownCast(pd->GetArray(0)); - auto scale = vtkDoubleArray::SafeDownCast(pd->GetArray(1)); - auto prototype = vtkIdTypeArray::SafeDownCast(pd->GetArray(2)); - auto mask = vtkUnsignedCharArray::SafeDownCast(pd->GetArray(3)); + auto orientArray = vtkDoubleArray::SafeDownCast(pd->GetArray(0)); + auto scaleArray = vtkDoubleArray::SafeDownCast(pd->GetArray(1)); + auto prototypeArray = vtkIdTypeArray::SafeDownCast(pd->GetArray(2)); + auto maskArray = vtkUnsignedCharArray::SafeDownCast(pd->GetArray(3)); std::vector::const_iterator pit = tess->coords().begin(); - vtkIdType nptsThisInst = static_cast(tess->coords().size() / 3); - double ptOrient[3] = { 0, 0, 0 }; - double ptScale[3] = { 1, 1, 1 }; - for (vtkIdType ii = 0; ii < nptsThisInst; ++ii, pit += 3) + size_t nptsThisInst = static_cast(tess->coords().size() / 3); + + // First check if orient, scale, mask and color has been provided in the instance + const smtk::model::FloatList& orientations = inst.floatProperty(Instance::orientations); + bool hasOrientations = + (orientations.size() == nptsThisInst * 3 && inst.rule() == "tabular") ? true : false; + + const smtk::model::FloatList& scales = inst.floatProperty(Instance::scales); + bool hasScales = (scales.size() == nptsThisInst * 3 && inst.rule() == "tabular") ? true : false; + + const smtk::model::IntegerList& masks = inst.integerProperty(Instance::masks); + bool hasMasks = (masks.size() == nptsThisInst && inst.rule() == "tabular") ? true : false; + + const smtk::model::IntegerList& colors = inst.integerProperty(Instance::colors); + bool hasColors = (colors.size() == nptsThisInst * 3 && inst.rule() == "tabular") ? true : false; + + double ptOrientDefault[3] = { 0, 0, 0 }; + double ptScaleDefault[3] = { 1, 1, 1 }; + vtkNew colorArray; + if (hasColors) + { + colorArray->SetName("colors"); + colorArray->SetNumberOfComponents(3); + colorArray->Allocate(static_cast(nptsThisInst)); + } + for (size_t ii = 0; ii < nptsThisInst; ++ii, pit += 3) { pts->InsertNextPoint(*pit, *(pit + 1), *(pit + 2)); - prototype->InsertNextValue(it->second); // block ID - orient->InsertNextTuple(ptOrient); - scale->InsertNextTuple(ptScale); - mask->InsertNextValue(1); + prototypeArray->InsertNextValue(it->second); // block ID + + orientArray->InsertNextTuple(hasOrientations ? &orientations[3 * ii] : ptOrientDefault); + + scaleArray->InsertNextTuple(hasScales ? &scales[3 * ii] : ptScaleDefault); + + maskArray->InsertNextValue(hasMasks ? static_cast(masks[ii]) : 1); + + if (hasColors) + { + colorArray->InsertNextTuple3(static_cast(colors[3 * ii]), + static_cast(colors[3 * ii] + 1), + static_cast(colors[3 * ii] + 2)); + } + } + if (hasColors) + { + pd->SetScalars(colorArray); } } diff --git a/smtk/model/Instance.h b/smtk/model/Instance.h index 4c9ca42da4..6338a659e0 100644 --- a/smtk/model/Instance.h +++ b/smtk/model/Instance.h @@ -24,6 +24,20 @@ class SMTKCORE_EXPORT Instance : public EntityRef { public: SMTK_ENTITYREF_CLASS(Instance, EntityRef, isInstance); + /// a string used to store/fetch placements. + static constexpr const char* const placements = "placements"; + /// a string used to store/fetch orientation as float property + /// It will be retranscribed as vtkDoubleArray when passing into vtkGlyph3DMapper if specified. + static constexpr const char* const orientations = "orientations"; + /// a string used to store/fetch scales as float property + /// It will be retranscribed as vtkDoubleArray when passing into vtkGlyph3DMapper if specified. + static constexpr const char* const scales = "scales"; + /// a string used to store/fetch masks(AKA visibility) as int property + /// It will be retranscribed as vtkUnsignedCharArray when passing into vtkGlyph3DMapper if specified. + static constexpr const char* const masks = "masks"; + /// a string used to store/fetch colors in rgb 0~255 as int property + /// It will be retranscribed as vtkUnsignedCharArray when passing into vtkGlyph3DMapper if specified. + static constexpr const char* const colors = "colors"; EntityRef prototype() const; -- GitLab