mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 01:49:02 +00:00
Merge topic 'document-glyph-mappers'
3fe5b0185 Document glyph mapper classes Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Manish Mathai <mmathai@uoregon.edu> Merge-request: !3138
This commit is contained in:
commit
c1885116b3
@ -15,6 +15,7 @@ namespace vtkm
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
/// @brief Glyph shapes supported by glyphing mappers.
|
||||
enum struct GlyphType
|
||||
{
|
||||
Arrow,
|
||||
|
@ -18,17 +18,7 @@ namespace vtkm
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
MapperGlyphBase::MapperGlyphBase()
|
||||
: Canvas(nullptr)
|
||||
, CompositeBackground(true)
|
||||
, UseNodes(true)
|
||||
, UseStride(false)
|
||||
, Stride(1)
|
||||
, ScaleByValue(false)
|
||||
, BaseSize(-1.f)
|
||||
, ScaleDelta(0.5f)
|
||||
{
|
||||
}
|
||||
MapperGlyphBase::MapperGlyphBase() {}
|
||||
|
||||
MapperGlyphBase::~MapperGlyphBase() {}
|
||||
|
||||
@ -49,24 +39,52 @@ vtkm::rendering::Canvas* MapperGlyphBase::GetCanvas() const
|
||||
return this->Canvas;
|
||||
}
|
||||
|
||||
vtkm::cont::Field::Association MapperGlyphBase::GetGlyphAssociation() const
|
||||
{
|
||||
return this->GlyphAssociation;
|
||||
}
|
||||
|
||||
void MapperGlyphBase::SetGlyphAssociation(vtkm::cont::Field::Association association)
|
||||
{
|
||||
switch (association)
|
||||
{
|
||||
case vtkm::cont::Field::Association::Cells:
|
||||
case vtkm::cont::Field::Association::Points:
|
||||
this->GlyphAssociation = association;
|
||||
break;
|
||||
default:
|
||||
throw vtkm::cont::ErrorBadValue("Invalid glyph association.");
|
||||
}
|
||||
}
|
||||
|
||||
bool MapperGlyphBase::GetUseCells() const
|
||||
{
|
||||
return !this->UseNodes;
|
||||
return this->GlyphAssociation == vtkm::cont::Field::Association::Cells;
|
||||
}
|
||||
|
||||
void MapperGlyphBase::SetUseCells()
|
||||
{
|
||||
this->UseNodes = false;
|
||||
this->SetGlyphAssociation(vtkm::cont::Field::Association::Cells);
|
||||
}
|
||||
|
||||
bool MapperGlyphBase::GetUsePoints() const
|
||||
{
|
||||
return this->GlyphAssociation == vtkm::cont::Field::Association::Points;
|
||||
}
|
||||
|
||||
void MapperGlyphBase::SetUsePoints()
|
||||
{
|
||||
this->SetGlyphAssociation(vtkm::cont::Field::Association::Points);
|
||||
}
|
||||
|
||||
bool MapperGlyphBase::GetUseNodes() const
|
||||
{
|
||||
return this->UseNodes;
|
||||
return this->GetUsePoints();
|
||||
}
|
||||
|
||||
void MapperGlyphBase::SetUseNodes()
|
||||
{
|
||||
this->UseNodes = true;
|
||||
this->SetUsePoints();
|
||||
}
|
||||
|
||||
vtkm::Float32 MapperGlyphBase::GetBaseSize() const
|
||||
|
@ -10,6 +10,7 @@
|
||||
#ifndef vtk_m_rendering_MapperGlyphBase_h
|
||||
#define vtk_m_rendering_MapperGlyphBase_h
|
||||
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
@ -23,6 +24,10 @@ namespace rendering
|
||||
|
||||
class CanvasRayTracer;
|
||||
|
||||
/// @brief Base class for glyph mappers.
|
||||
///
|
||||
/// Glyph mappers place 3D icons at various places in the mesh. The icons are
|
||||
/// placed based on the location of points or cells in the mesh.
|
||||
class VTKM_RENDERING_EXPORT MapperGlyphBase : public Mapper
|
||||
{
|
||||
public:
|
||||
@ -33,21 +38,57 @@ public:
|
||||
void SetCanvas(vtkm::rendering::Canvas* canvas) override;
|
||||
virtual vtkm::rendering::Canvas* GetCanvas() const override;
|
||||
|
||||
/// @brief Specify the elements the glyphs will be associated with.
|
||||
///
|
||||
/// The glyph mapper will place glyphs over locations specified by either the points
|
||||
/// or the cells of a mesh. The glyph may also be oriented by a scalar field with the
|
||||
/// same association.
|
||||
virtual vtkm::cont::Field::Association GetGlyphAssociation() const;
|
||||
/// @copydoc GetGlyphAssociation
|
||||
virtual void SetGlyphAssociation(vtkm::cont::Field::Association association);
|
||||
/// @copydoc GetGlyphAssociation
|
||||
virtual bool GetUseCells() const;
|
||||
/// @copydoc GetGlyphAssociation
|
||||
virtual void SetUseCells();
|
||||
/// @copydoc GetGlyphAssociation
|
||||
virtual bool GetUsePoints() const;
|
||||
/// @copydoc GetGlyphAssociation
|
||||
virtual void SetUsePoints();
|
||||
VTKM_DEPRECATED(2.2, "Use GetUsePoints() or GetGlyphAssociation().")
|
||||
virtual bool GetUseNodes() const;
|
||||
VTKM_DEPRECATED(2.2, "Use SetUsePoints() or SetGlyphAssociation().")
|
||||
virtual void SetUseNodes();
|
||||
|
||||
// These options do not seem to be supported yet.
|
||||
// I'm not sure why you would need UseStride. Just use Stride = 1.
|
||||
virtual bool GetUseStride() const;
|
||||
virtual void SetUseStride(bool on);
|
||||
virtual vtkm::Id GetStride() const;
|
||||
virtual void SetStride(vtkm::Id stride);
|
||||
|
||||
/// @brief Specify the size of each glyph (before scaling).
|
||||
///
|
||||
/// If the base size is not set to a positive value, it is automatically sized with a heuristic
|
||||
/// based off the bounds of the geometry.
|
||||
virtual vtkm::Float32 GetBaseSize() const;
|
||||
/// @copydoc GetBaseSize
|
||||
virtual void SetBaseSize(vtkm::Float32 size);
|
||||
|
||||
/// @brief Specify whether to scale the glyphs by a field.
|
||||
virtual bool GetScaleByValue() const;
|
||||
/// @copydoc GetScaleByValue
|
||||
virtual void SetScaleByValue(bool on);
|
||||
|
||||
/// @brief Specify the range of values to scale the glyphs.
|
||||
///
|
||||
/// When `ScaleByValue` is on, the glyphs will be scaled proportionally to the field
|
||||
/// magnitude. The `ScaleDelta` determines how big and small they get. For a `ScaleDelta`
|
||||
/// of one, the smallest field values will have glyphs of zero size and the maximum field
|
||||
/// values will be twice the base size. A `ScaleDelta` of 0.5 will result in glyphs sized
|
||||
/// in the range of 0.5 times the base size to 1.5 times the base size. `ScaleDelta` outside
|
||||
/// the range [0, 1] is undefined.
|
||||
virtual vtkm::Float32 GetScaleDelta() const;
|
||||
/// @copydoc GetScaleDelta
|
||||
virtual void SetScaleDelta(vtkm::Float32 delta);
|
||||
|
||||
virtual void SetCompositeBackground(bool on);
|
||||
@ -58,17 +99,17 @@ protected:
|
||||
const vtkm::cont::Field& scalarField) const;
|
||||
|
||||
|
||||
vtkm::rendering::CanvasRayTracer* Canvas;
|
||||
bool CompositeBackground;
|
||||
vtkm::rendering::CanvasRayTracer* Canvas = nullptr;
|
||||
bool CompositeBackground = true;
|
||||
|
||||
bool UseNodes;
|
||||
vtkm::cont::Field::Association GlyphAssociation = vtkm::cont::Field::Association::Points;
|
||||
|
||||
bool UseStride;
|
||||
vtkm::Id Stride;
|
||||
bool UseStride = false;
|
||||
vtkm::Id Stride = 1;
|
||||
|
||||
bool ScaleByValue;
|
||||
vtkm::Float32 BaseSize;
|
||||
vtkm::Float32 ScaleDelta;
|
||||
bool ScaleByValue = false;
|
||||
vtkm::Float32 BaseSize = -1.f;
|
||||
vtkm::Float32 ScaleDelta = 0.5f;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
@ -339,7 +339,8 @@ void MapperGlyphScalar::RenderCells(const vtkm::cont::UnknownCellSet& cellset,
|
||||
|
||||
vtkm::Bounds coordBounds = coords.GetBounds();
|
||||
vtkm::Float32 baseSize = this->BaseSize;
|
||||
if (baseSize == -1.f)
|
||||
// The weird formulation of this condition is to handle NaN correctly.
|
||||
if (!(baseSize > 0))
|
||||
{
|
||||
// set a default size
|
||||
vtkm::Float64 lx = coordBounds.X.Length();
|
||||
@ -369,22 +370,22 @@ void MapperGlyphScalar::RenderCells(const vtkm::cont::UnknownCellSet& cellset,
|
||||
{
|
||||
vtkm::Float32 minSize = baseSize - baseSize * this->ScaleDelta;
|
||||
vtkm::Float32 maxSize = baseSize + baseSize * this->ScaleDelta;
|
||||
if (this->UseNodes)
|
||||
if (this->GlyphAssociation == vtkm::cont::Field::Association::Points)
|
||||
{
|
||||
glyphExtractor.ExtractCoordinates(processedCoords, processedField, minSize, maxSize);
|
||||
}
|
||||
else
|
||||
else // this->GlyphAssociation == vtkm::cont::Field::Association::Cells
|
||||
{
|
||||
glyphExtractor.ExtractCells(processedCellSet, processedField, minSize, maxSize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->UseNodes)
|
||||
if (this->GlyphAssociation == vtkm::cont::Field::Association::Points)
|
||||
{
|
||||
glyphExtractor.ExtractCoordinates(processedCoords, baseSize);
|
||||
}
|
||||
else
|
||||
else // this->GlyphAssociation == vtkm::cont::Field::Association::Cells
|
||||
{
|
||||
glyphExtractor.ExtractCells(processedCellSet, baseSize);
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ namespace vtkm
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
/// @brief A mapper that produces unoriented glyphs.
|
||||
///
|
||||
/// This mapper is meant to be used with scalar fields. The glyphs can be optionally
|
||||
/// sized based on the field.
|
||||
class VTKM_RENDERING_EXPORT MapperGlyphScalar : public vtkm::rendering::MapperGlyphBase
|
||||
{
|
||||
public:
|
||||
@ -25,7 +29,9 @@ public:
|
||||
|
||||
~MapperGlyphScalar();
|
||||
|
||||
/// @brief Specify the shape of the glyphs.
|
||||
vtkm::rendering::GlyphType GetGlyphType() const;
|
||||
/// @copydoc GetGlyphType
|
||||
void SetGlyphType(vtkm::rendering::GlyphType glyphType);
|
||||
|
||||
void RenderCells(const vtkm::cont::UnknownCellSet& cellset,
|
||||
|
@ -69,7 +69,8 @@ void MapperGlyphVector::RenderCells(const vtkm::cont::UnknownCellSet& cellset,
|
||||
|
||||
vtkm::Bounds coordBounds = coords.GetBounds();
|
||||
vtkm::Float32 baseSize = this->BaseSize;
|
||||
if (baseSize == -1.f)
|
||||
// The weird formulation of this condition is to handle NaN correctly.
|
||||
if (!(baseSize > 0))
|
||||
{
|
||||
// set a default size
|
||||
vtkm::Float64 lx = coordBounds.X.Length();
|
||||
@ -92,22 +93,22 @@ void MapperGlyphVector::RenderCells(const vtkm::cont::UnknownCellSet& cellset,
|
||||
{
|
||||
vtkm::Float32 minSize = baseSize - baseSize * this->ScaleDelta;
|
||||
vtkm::Float32 maxSize = baseSize + baseSize * this->ScaleDelta;
|
||||
if (this->UseNodes)
|
||||
if (this->GlyphAssociation == vtkm::cont::Field::Association::Points)
|
||||
{
|
||||
glyphExtractor.ExtractCoordinates(processedCoords, processedField, minSize, maxSize);
|
||||
}
|
||||
else
|
||||
else // this->GlyphAssociation == vtkm::cont::Field::Association::Cells
|
||||
{
|
||||
glyphExtractor.ExtractCells(processedCellSet, processedField, minSize, maxSize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->UseNodes)
|
||||
if (this->GlyphAssociation == vtkm::cont::Field::Association::Points)
|
||||
{
|
||||
glyphExtractor.ExtractCoordinates(processedCoords, processedField, baseSize);
|
||||
}
|
||||
else
|
||||
else // this->GlyphAssociation == vtkm::cont::Field::Association::Cells
|
||||
{
|
||||
glyphExtractor.ExtractCells(processedCellSet, processedField, baseSize);
|
||||
}
|
||||
|
@ -18,6 +18,11 @@ namespace vtkm
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
/// @brief A mapper that produces oriented glyphs.
|
||||
///
|
||||
/// This mapper is meant to be used with 3D vector fields. The glyphs are oriented in
|
||||
/// the direction of the vector field. The glyphs can be optionally sized based on the
|
||||
/// magnitude of the field.
|
||||
class VTKM_RENDERING_EXPORT MapperGlyphVector : public vtkm::rendering::MapperGlyphBase
|
||||
{
|
||||
public:
|
||||
@ -25,7 +30,9 @@ public:
|
||||
|
||||
~MapperGlyphVector();
|
||||
|
||||
/// @brief Specify the shape of the glyphs.
|
||||
vtkm::rendering::GlyphType GetGlyphType() const;
|
||||
/// @copydoc GetGlyphType
|
||||
void SetGlyphType(vtkm::rendering::GlyphType glyphType);
|
||||
|
||||
void RenderCells(const vtkm::cont::UnknownCellSet& cellset,
|
||||
|
Loading…
Reference in New Issue
Block a user