mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Adding color lines, view annotations, line color labels.
This commit is contained in:
parent
6eb38b4bde
commit
6b59b01e14
@ -51,11 +51,27 @@ struct Actor::InternalsType
|
||||
}
|
||||
};
|
||||
|
||||
Actor::Actor(const vtkm::cont::DynamicCellSet& cells,
|
||||
const vtkm::cont::CoordinateSystem& coordinates,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
const vtkm::rendering::Color& color)
|
||||
: Internals(
|
||||
new InternalsType(cells, coordinates, scalarField, vtkm::rendering::ColorTable(color)))
|
||||
{
|
||||
this->Init(coordinates, scalarField);
|
||||
}
|
||||
|
||||
Actor::Actor(const vtkm::cont::DynamicCellSet& cells,
|
||||
const vtkm::cont::CoordinateSystem& coordinates,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
const vtkm::rendering::ColorTable& colorTable)
|
||||
: Internals(new InternalsType(cells, coordinates, scalarField, colorTable))
|
||||
{
|
||||
this->Init(coordinates, scalarField);
|
||||
}
|
||||
|
||||
void Actor::Init(const vtkm::cont::CoordinateSystem& coordinates,
|
||||
const vtkm::cont::Field& scalarField)
|
||||
{
|
||||
VTKM_ASSERT(scalarField.GetData().GetNumberOfComponents() == 1);
|
||||
|
||||
|
@ -41,6 +41,11 @@ public:
|
||||
const vtkm::cont::Field& scalarField,
|
||||
const vtkm::rendering::ColorTable& colorTable = vtkm::rendering::ColorTable("default"));
|
||||
|
||||
Actor(const vtkm::cont::DynamicCellSet& cells,
|
||||
const vtkm::cont::CoordinateSystem& coordinates,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
const vtkm::rendering::Color& color);
|
||||
|
||||
void Render(vtkm::rendering::Mapper& mapper,
|
||||
vtkm::rendering::Canvas& canvas,
|
||||
const vtkm::rendering::Camera& camera) const;
|
||||
@ -64,6 +69,8 @@ private:
|
||||
std::shared_ptr<InternalsType> Internals;
|
||||
|
||||
struct RangeFunctor;
|
||||
|
||||
void Init(const vtkm::cont::CoordinateSystem& coordinates, const vtkm::cont::Field& scalarField);
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
@ -31,6 +31,7 @@ set(headers
|
||||
CanvasRayTracer.h
|
||||
Color.h
|
||||
ColorBarAnnotation.h
|
||||
ColorLegendAnnotation.h
|
||||
ColorTable.h
|
||||
ConnectivityProxy.h
|
||||
DecodePNG.h
|
||||
@ -64,6 +65,7 @@ set(sources
|
||||
CanvasRayTracer.cxx
|
||||
Color.cxx
|
||||
ColorBarAnnotation.cxx
|
||||
ColorLegendAnnotation.cxx
|
||||
ColorTable.cxx
|
||||
ConnectivityProxy.cxx
|
||||
DecodePNG.cxx
|
||||
@ -168,10 +170,12 @@ target_link_libraries(vtkm_rendering
|
||||
PUBLIC vtkm_cont
|
||||
PRIVATE ${VTKm_OPENGL_LIBRARIES}
|
||||
${VTKm_BACKEND_LIBRARIES}
|
||||
${EGL_LIBRARIES}
|
||||
)
|
||||
target_include_directories(vtkm_rendering
|
||||
PRIVATE ${VTKm_OPENGL_INCLUDE_DIRS}
|
||||
${VTKm_BACKEND_INCLUDE_DIRS}
|
||||
${EGL_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
|
@ -253,29 +253,44 @@ void Camera::TrackballRotate(vtkm::Float32 startX,
|
||||
this->Camera3D.ViewUp = vtkm::Transform3DVector(fullTransform, this->Camera3D.ViewUp);
|
||||
}
|
||||
|
||||
void Camera::ResetToBounds(const vtkm::Bounds& dataBounds)
|
||||
void Camera::ResetToBounds(const vtkm::Bounds& dataBounds,
|
||||
const vtkm::Float64 XDataViewPadding,
|
||||
const vtkm::Float64 YDataViewPadding,
|
||||
const vtkm::Float64 ZDataViewPadding)
|
||||
{
|
||||
// Save camera mode
|
||||
ModeEnum saveMode = this->GetMode();
|
||||
|
||||
// Pad view around data extents
|
||||
vtkm::Bounds db = dataBounds;
|
||||
vtkm::Float64 viewPadAmount = XDataViewPadding * (db.X.Max - db.X.Min);
|
||||
db.X.Max += viewPadAmount;
|
||||
db.X.Min -= viewPadAmount;
|
||||
viewPadAmount = YDataViewPadding * (db.Y.Max - db.Y.Min);
|
||||
db.Y.Max += viewPadAmount;
|
||||
db.Y.Min -= viewPadAmount;
|
||||
viewPadAmount = ZDataViewPadding * (db.Z.Max - db.Z.Min);
|
||||
db.Z.Max += viewPadAmount;
|
||||
db.Z.Min -= viewPadAmount;
|
||||
|
||||
// Reset for 3D camera
|
||||
vtkm::Vec<vtkm::Float32, 3> directionOfProjection = this->GetPosition() - this->GetLookAt();
|
||||
vtkm::Normalize(directionOfProjection);
|
||||
|
||||
vtkm::Vec<vtkm::Float32, 3> center = dataBounds.Center();
|
||||
vtkm::Vec<vtkm::Float32, 3> center = db.Center();
|
||||
this->SetLookAt(center);
|
||||
|
||||
vtkm::Vec<vtkm::Float32, 3> totalExtent;
|
||||
totalExtent[0] = vtkm::Float32(dataBounds.X.Length());
|
||||
totalExtent[1] = vtkm::Float32(dataBounds.Y.Length());
|
||||
totalExtent[2] = vtkm::Float32(dataBounds.Z.Length());
|
||||
totalExtent[0] = vtkm::Float32(db.X.Length());
|
||||
totalExtent[1] = vtkm::Float32(db.Y.Length());
|
||||
totalExtent[2] = vtkm::Float32(db.Z.Length());
|
||||
vtkm::Float32 diagonalLength = vtkm::Magnitude(totalExtent);
|
||||
this->SetPosition(center + directionOfProjection * diagonalLength * 1.0f);
|
||||
this->SetFieldOfView(60.0f);
|
||||
this->SetClippingRange(0.1f * diagonalLength, diagonalLength * 10.0f);
|
||||
|
||||
// Reset for 2D camera
|
||||
this->SetViewRange2D(dataBounds);
|
||||
this->SetViewRange2D(db);
|
||||
|
||||
// Reset pan and zoom
|
||||
this->Camera3D.XPan = 0;
|
||||
@ -289,6 +304,17 @@ void Camera::ResetToBounds(const vtkm::Bounds& dataBounds)
|
||||
this->SetMode(saveMode);
|
||||
}
|
||||
|
||||
// Enable the ability to pad the data extents in the final view
|
||||
void Camera::ResetToBounds(const vtkm::Bounds& dataBounds, const vtkm::Float64 dataViewPadding)
|
||||
{
|
||||
Camera::ResetToBounds(dataBounds, dataViewPadding, dataViewPadding, dataViewPadding);
|
||||
}
|
||||
|
||||
void Camera::ResetToBounds(const vtkm::Bounds& dataBounds)
|
||||
{
|
||||
Camera::ResetToBounds(dataBounds, 0);
|
||||
}
|
||||
|
||||
void Camera::Roll(vtkm::Float32 angleDegrees)
|
||||
{
|
||||
vtkm::Vec<vtkm::Float32, 3> directionOfProjection = this->GetLookAt() - this->GetPosition();
|
||||
|
@ -395,6 +395,20 @@ public:
|
||||
///
|
||||
void ResetToBounds(const vtkm::Bounds& dataBounds);
|
||||
|
||||
/// \brief Set up the camera to look at geometry with padding
|
||||
///
|
||||
/// \c ResetToBounds takes a \c Bounds structure containing the bounds in
|
||||
/// 3D space that contain the geometry being rendered and a \c Float64 value
|
||||
/// representing the percent that a view should be padded in x, y, and z.
|
||||
/// This method sets up the camera so that it is looking at this region in
|
||||
// space with the given padding percent. The view direction is preserved.
|
||||
///
|
||||
void ResetToBounds(const vtkm::Bounds& dataBounds, vtkm::Float64 dataViewPadding);
|
||||
void ResetToBounds(const vtkm::Bounds& dataBounds,
|
||||
vtkm::Float64 XDataViewPadding,
|
||||
vtkm::Float64 YDataViewPadding,
|
||||
vtkm::Float64 ZDataViewPadding);
|
||||
|
||||
/// \brief Roll the camera
|
||||
///
|
||||
/// Rotates the camera around the view direction by the given angle. The
|
||||
|
@ -108,6 +108,45 @@ public:
|
||||
|
||||
virtual void SaveAs(const std::string& fileName) const;
|
||||
|
||||
/// Creates a WorldAnnotator of a type that is paired with this Canvas. Other
|
||||
/// types of world annotators might work, but this provides a default.
|
||||
///
|
||||
/// The WorldAnnotator is created with the C++ new keyword (so it should be
|
||||
/// deleted with delete later). A pointer to the created WorldAnnotator is
|
||||
/// returned.
|
||||
///
|
||||
virtual vtkm::rendering::WorldAnnotator* CreateWorldAnnotator() const;
|
||||
|
||||
friend class AxisAnnotation2D;
|
||||
friend class ColorBarAnnotation;
|
||||
friend class ColorLegendAnnotation;
|
||||
friend class TextAnnotationScreen;
|
||||
|
||||
protected:
|
||||
virtual void AddColorSwatch(const vtkm::Vec<vtkm::Float64, 2>& point0,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point1,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point2,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point3,
|
||||
const vtkm::rendering::Color& color) const = 0;
|
||||
|
||||
VTKM_CONT
|
||||
void AddColorSwatch(const vtkm::Float64 x0,
|
||||
const vtkm::Float64 y0,
|
||||
const vtkm::Float64 x1,
|
||||
const vtkm::Float64 y1,
|
||||
const vtkm::Float64 x2,
|
||||
const vtkm::Float64 y2,
|
||||
const vtkm::Float64 x3,
|
||||
const vtkm::Float64 y3,
|
||||
const vtkm::rendering::Color& color) const
|
||||
{
|
||||
this->AddColorSwatch(vtkm::make_Vec(x0, y0),
|
||||
vtkm::make_Vec(x1, y1),
|
||||
vtkm::make_Vec(x2, y2),
|
||||
vtkm::make_Vec(x3, y3),
|
||||
color);
|
||||
}
|
||||
|
||||
virtual void AddLine(const vtkm::Vec<vtkm::Float64, 2>& point0,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point1,
|
||||
vtkm::Float32 linewidth,
|
||||
@ -170,14 +209,6 @@ public:
|
||||
text);
|
||||
}
|
||||
|
||||
/// Creates a WorldAnnotator of a type that is paired with this Canvas. Other
|
||||
/// types of world annotators might work, but this provides a default.
|
||||
///
|
||||
/// The WorldAnnotator is created with the C++ new keyword (so it should be
|
||||
/// deleted with delete later). A pointer to the created WorldAnnotator is
|
||||
/// returned.
|
||||
///
|
||||
virtual vtkm::rendering::WorldAnnotator* CreateWorldAnnotator() const;
|
||||
|
||||
private:
|
||||
vtkm::Id Width;
|
||||
|
@ -171,6 +171,27 @@ void CanvasGL::RefreshDepthBuffer() const
|
||||
const_cast<vtkm::Float32*>(this->GetDepthBuffer().GetStorage().GetArray()));
|
||||
}
|
||||
|
||||
void CanvasGL::AddColorSwatch(const vtkm::Vec<vtkm::Float64, 2>& point0,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point1,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point2,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point3,
|
||||
const vtkm::rendering::Color& color) const
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glTexCoord1f(0);
|
||||
glVertex3f(float(point0[0]), float(point0[1]), .99f);
|
||||
glVertex3f(float(point1[0]), float(point1[1]), .99f);
|
||||
|
||||
glTexCoord1f(1);
|
||||
glVertex3f(float(point2[0]), float(point2[1]), .99f);
|
||||
glVertex3f(float(point3[0]), float(point3[1]), .99f);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CanvasGL::AddLine(const vtkm::Vec<vtkm::Float64, 2>& point0,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point1,
|
||||
vtkm::Float32 linewidth,
|
||||
|
@ -58,6 +58,9 @@ public:
|
||||
|
||||
virtual void RefreshDepthBuffer() const VTKM_OVERRIDE;
|
||||
|
||||
vtkm::rendering::WorldAnnotator* CreateWorldAnnotator() const VTKM_OVERRIDE;
|
||||
|
||||
protected:
|
||||
void AddLine(const vtkm::Vec<vtkm::Float64, 2>& point0,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point1,
|
||||
vtkm::Float32 linewidth,
|
||||
@ -67,6 +70,12 @@ public:
|
||||
const vtkm::rendering::ColorTable& colorTable,
|
||||
bool horizontal) const VTKM_OVERRIDE;
|
||||
|
||||
void AddColorSwatch(const vtkm::Vec<vtkm::Float64, 2>& point0,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point1,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point2,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point3,
|
||||
const vtkm::rendering::Color& color) const VTKM_OVERRIDE;
|
||||
|
||||
void AddText(const vtkm::Vec<vtkm::Float32, 2>& position,
|
||||
vtkm::Float32 scale,
|
||||
vtkm::Float32 angle,
|
||||
@ -75,8 +84,6 @@ public:
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const VTKM_OVERRIDE;
|
||||
|
||||
vtkm::rendering::WorldAnnotator* CreateWorldAnnotator() const VTKM_OVERRIDE;
|
||||
|
||||
private:
|
||||
vtkm::rendering::BitmapFont Font;
|
||||
vtkm::rendering::TextureGL FontTexture;
|
||||
|
@ -251,6 +251,15 @@ void CanvasRayTracer::AddColorBar(const vtkm::Bounds&,
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
void CanvasRayTracer::AddColorSwatch(const vtkm::Vec<vtkm::Float64, 2>&,
|
||||
const vtkm::Vec<vtkm::Float64, 2>&,
|
||||
const vtkm::Vec<vtkm::Float64, 2>&,
|
||||
const vtkm::Vec<vtkm::Float64, 2>&,
|
||||
const vtkm::rendering::Color&) const
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
void CanvasRayTracer::AddText(const vtkm::Vec<vtkm::Float32, 2>&,
|
||||
vtkm::Float32,
|
||||
vtkm::Float32,
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float64>& colors,
|
||||
const vtkm::rendering::Camera& camera);
|
||||
|
||||
protected:
|
||||
void AddLine(const vtkm::Vec<vtkm::Float64, 2>& point0,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point1,
|
||||
vtkm::Float32 linewidth,
|
||||
@ -64,6 +65,11 @@ public:
|
||||
const vtkm::rendering::ColorTable& colorTable,
|
||||
bool horizontal) const VTKM_OVERRIDE;
|
||||
|
||||
void AddColorSwatch(const vtkm::Vec<vtkm::Float64, 2>& point0,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point1,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point2,
|
||||
const vtkm::Vec<vtkm::Float64, 2>& point3,
|
||||
const vtkm::rendering::Color& color) const VTKM_OVERRIDE;
|
||||
|
||||
void AddText(const vtkm::Vec<vtkm::Float32, 2>& position,
|
||||
vtkm::Float32 scale,
|
||||
|
88
vtkm/rendering/ColorLegendAnnotation.cxx
Normal file
88
vtkm/rendering/ColorLegendAnnotation.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//
|
||||
// Copyright 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/ColorLegendAnnotation.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
ColorLegendAnnotation::ColorLegendAnnotation()
|
||||
{
|
||||
this->FontScale = 0.05f;
|
||||
this->LabelColor = vtkm::rendering::Color::white;
|
||||
}
|
||||
|
||||
ColorLegendAnnotation::~ColorLegendAnnotation()
|
||||
{
|
||||
}
|
||||
|
||||
void ColorLegendAnnotation::Clear()
|
||||
{
|
||||
this->Labels.clear();
|
||||
this->ColorSwatchList.clear();
|
||||
}
|
||||
|
||||
void ColorLegendAnnotation::AddItem(const std::string& label, vtkm::rendering::Color color)
|
||||
{
|
||||
this->Labels.push_back(label);
|
||||
this->ColorSwatchList.push_back(color);
|
||||
}
|
||||
|
||||
void ColorLegendAnnotation::Render(const vtkm::rendering::Camera& camera,
|
||||
const vtkm::rendering::WorldAnnotator& annotator,
|
||||
vtkm::rendering::Canvas& canvas)
|
||||
{
|
||||
vtkm::Float32 l = -0.95f, r = -0.90f;
|
||||
vtkm::Float32 b = +0.90f, t = +0.95f;
|
||||
|
||||
for (unsigned int i = 0; i < this->ColorSwatchList.size(); ++i)
|
||||
{
|
||||
canvas.AddColorSwatch(l, b, l, t, r, t, r, b, this->ColorSwatchList[i]);
|
||||
b -= 0.07f;
|
||||
t -= 0.07f;
|
||||
}
|
||||
|
||||
// reset positions
|
||||
l = -0.95f;
|
||||
r = -0.90f;
|
||||
b = +0.90f;
|
||||
t = +0.95f;
|
||||
|
||||
while (this->Annot.size() < this->Labels.size())
|
||||
{
|
||||
this->Annot.push_back(new vtkm::rendering::TextAnnotationScreen(
|
||||
"test", this->LabelColor, this->FontScale, vtkm::Vec<vtkm::Float32, 2>(0, 0), 0));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < this->Annot.size(); ++i)
|
||||
{
|
||||
TextAnnotationScreen* txt = Annot[i];
|
||||
txt->SetText(Labels[i]);
|
||||
txt->SetPosition(r + .02f, (b + t) / 2.f);
|
||||
txt->SetAlignment(TextAnnotationScreen::Left, TextAnnotationScreen::VCenter);
|
||||
txt->Render(camera, annotator, canvas);
|
||||
b -= 0.07f;
|
||||
t -= 0.07f;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
68
vtkm/rendering/ColorLegendAnnotation.h
Normal file
68
vtkm/rendering/ColorLegendAnnotation.h
Normal file
@ -0,0 +1,68 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//
|
||||
// Copyright 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_rendering_ColorLegendAnnotation_h
|
||||
#define vtk_m_rendering_ColorLegendAnnotation_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/TextAnnotationScreen.h>
|
||||
#include <vtkm/rendering/WorldAnnotator.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
{
|
||||
|
||||
class VTKM_RENDERING_EXPORT ColorLegendAnnotation
|
||||
{
|
||||
private:
|
||||
vtkm::Float32 FontScale;
|
||||
vtkm::rendering::Color LabelColor;
|
||||
std::vector<std::string> Labels;
|
||||
std::vector<TextAnnotationScreen*> Annot;
|
||||
std::vector<vtkm::rendering::Color> ColorSwatchList;
|
||||
|
||||
public:
|
||||
ColorLegendAnnotation();
|
||||
~ColorLegendAnnotation();
|
||||
|
||||
void Clear();
|
||||
void AddItem(const std::string& label, vtkm::rendering::Color color);
|
||||
|
||||
void SetLabelColor(vtkm::rendering::Color c) { this->LabelColor = c; }
|
||||
|
||||
void SetLabelFontScale(vtkm::Float32 s)
|
||||
{
|
||||
this->FontScale = s;
|
||||
for (unsigned int i = 0; i < this->Annot.size(); i++)
|
||||
this->Annot[i]->SetScale(s);
|
||||
}
|
||||
|
||||
virtual void Render(const vtkm::rendering::Camera&,
|
||||
const vtkm::rendering::WorldAnnotator& annotator,
|
||||
vtkm::rendering::Canvas& canvas);
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif // vtk_m_rendering_ColorLegendAnnotation_h
|
@ -1218,6 +1218,7 @@ ColorTable::ColorTable(const std::string& name_)
|
||||
}
|
||||
|
||||
ColorTable::ColorTable(const vtkm::rendering::Color& color)
|
||||
: Internals(new detail::ColorTableInternals)
|
||||
{
|
||||
this->Internals->UniqueName = "";
|
||||
this->Internals->Smooth = false;
|
||||
|
@ -178,13 +178,16 @@ struct MapColorAndVerticesInvokeFunctor
|
||||
template <typename PtType>
|
||||
VTKM_CONT void RenderStructuredLineSegments(vtkm::Id numVerts,
|
||||
const PtType& verts,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar)
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar,
|
||||
vtkm::rendering::ColorTable ct)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(1);
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
vtkm::UInt8 r, g, b, a;
|
||||
ct.MapRGB(0).GetRGBA(r, g, b, a);
|
||||
|
||||
glColor4ub(r, g, b, a);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (int i = 0; i < numVerts; i++)
|
||||
{
|
||||
@ -198,13 +201,16 @@ VTKM_CONT void RenderStructuredLineSegments(vtkm::Id numVerts,
|
||||
template <typename PtType>
|
||||
VTKM_CONT void RenderExplicitLineSegments(vtkm::Id numVerts,
|
||||
const PtType& verts,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar)
|
||||
const vtkm::cont::ArrayHandle<vtkm::Float32>& scalar,
|
||||
vtkm::rendering::ColorTable ct)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(1);
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
vtkm::UInt8 r, g, b, a;
|
||||
ct.MapRGB(0).GetRGBA(r, g, b, a);
|
||||
|
||||
glColor4ub(r, g, b, a);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (int i = 0; i < numVerts; i++)
|
||||
{
|
||||
@ -412,7 +418,7 @@ void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
|
||||
{
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates verts;
|
||||
verts = dcoords.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
|
||||
RenderStructuredLineSegments(numVerts, verts, sf);
|
||||
RenderStructuredLineSegments(numVerts, verts, sf, colorTable);
|
||||
}
|
||||
else if (cellset.IsSameType(vtkm::cont::CellSetSingleType<>()) &&
|
||||
cellset.Cast<vtkm::cont::CellSetSingleType<>>().GetCellShapeAsId() ==
|
||||
@ -420,7 +426,7 @@ void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 3>> verts;
|
||||
verts = dcoords.Cast<vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 3>>>();
|
||||
RenderExplicitLineSegments(numVerts, verts, sf);
|
||||
RenderExplicitLineSegments(numVerts, verts, sf, colorTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -76,6 +76,12 @@ void View::SaveAs(const std::string& fileName) const
|
||||
this->GetCanvas().SaveAs(fileName);
|
||||
}
|
||||
|
||||
void View::RenderAnnotations()
|
||||
{
|
||||
for (unsigned int i = 0; i < annotations.size(); ++i)
|
||||
annotations[i]->Render(this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
|
||||
void View::SetupForWorldSpace(bool viewportClip)
|
||||
{
|
||||
//this->Camera.SetupMatrices();
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/TextAnnotation.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -101,16 +102,25 @@ public:
|
||||
|
||||
void SaveAs(const std::string& fileName) const;
|
||||
|
||||
VTKM_CONT
|
||||
void ClearAnnotations() { annotations.clear(); }
|
||||
|
||||
VTKM_CONT
|
||||
void AddAnnotation(vtkm::rendering::TextAnnotation* ann) { annotations.push_back(ann); }
|
||||
|
||||
protected:
|
||||
void SetupForWorldSpace(bool viewportClip = true);
|
||||
|
||||
void SetupForScreenSpace(bool viewportClip = false);
|
||||
|
||||
void RenderAnnotations();
|
||||
|
||||
private:
|
||||
vtkm::rendering::Scene Scene;
|
||||
std::shared_ptr<vtkm::rendering::Mapper> MapperPointer;
|
||||
std::shared_ptr<vtkm::rendering::Canvas> CanvasPointer;
|
||||
std::shared_ptr<vtkm::rendering::WorldAnnotator> WorldAnnotatorPointer;
|
||||
std::vector<vtkm::rendering::TextAnnotation*> annotations;
|
||||
vtkm::rendering::Camera Camera;
|
||||
};
|
||||
}
|
||||
|
@ -68,6 +68,8 @@ void View1D::Paint()
|
||||
this->RenderWorldAnnotations();
|
||||
this->SetupForScreenSpace();
|
||||
this->RenderScreenAnnotations();
|
||||
this->RenderColorLegendAnnotations();
|
||||
this->RenderAnnotations();
|
||||
this->GetCanvas().Finish();
|
||||
}
|
||||
|
||||
@ -112,9 +114,33 @@ void View1D::RenderScreenAnnotations()
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
|
||||
void View1D::RenderColorLegendAnnotations()
|
||||
{
|
||||
if (LegendEnabled)
|
||||
{
|
||||
this->Legend.Clear();
|
||||
for (int i = 0; i < this->GetScene().GetNumberOfActors(); ++i)
|
||||
{
|
||||
vtkm::rendering::Actor act = this->GetScene().GetActor(i);
|
||||
this->Legend.AddItem(act.GetScalarField().GetName(), act.GetColorTable().MapRGB(0));
|
||||
}
|
||||
this->Legend.Render(this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
}
|
||||
|
||||
void View1D::RenderWorldAnnotations()
|
||||
{
|
||||
// 1D views don't have world annotations.
|
||||
}
|
||||
|
||||
void View1D::EnableLegend()
|
||||
{
|
||||
LegendEnabled = true;
|
||||
}
|
||||
|
||||
void View1D::DisableLegend()
|
||||
{
|
||||
LegendEnabled = false;
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define vtk_m_rendering_View1D_h
|
||||
|
||||
#include <vtkm/rendering/AxisAnnotation2D.h>
|
||||
#include <vtkm/rendering/ColorLegendAnnotation.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
|
||||
namespace vtkm
|
||||
@ -47,11 +48,16 @@ public:
|
||||
void Paint() VTKM_OVERRIDE;
|
||||
void RenderScreenAnnotations() VTKM_OVERRIDE;
|
||||
void RenderWorldAnnotations() VTKM_OVERRIDE;
|
||||
void RenderColorLegendAnnotations();
|
||||
void EnableLegend();
|
||||
void DisableLegend();
|
||||
|
||||
private:
|
||||
// 1D-specific annotations
|
||||
vtkm::rendering::AxisAnnotation2D HorizontalAxisAnnotation;
|
||||
vtkm::rendering::AxisAnnotation2D VerticalAxisAnnotation;
|
||||
vtkm::rendering::ColorLegendAnnotation Legend;
|
||||
bool LegendEnabled = true;
|
||||
};
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
Loading…
Reference in New Issue
Block a user