mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add TextAnnotation to rendering library
Also made the TextAnnotation classes conform better to VTK-m coding style. Specifically, changed the order of words in subclass names (e.g. TextAnnotationBillboard instead of BillboardTextAnnotation) and broke out each subclass into its own header/source files.
This commit is contained in:
parent
d4afc12add
commit
c446f1bc7a
@ -53,11 +53,34 @@ vtkm::Vec<T,3> Transform3DPoint(const vtkm::Matrix<T,4,4> &matrix,
|
||||
vtkm::dot(vtkm::MatrixGetRow(matrix,2), homogeneousPoint));
|
||||
}
|
||||
|
||||
/// \brief Transform a 3D point by a transformation matrix.
|
||||
/// \brief Transform a 3D point by a transformation matrix with perspective.
|
||||
///
|
||||
/// Given a 4x4 transformation matrix and a 3D point, returns the point
|
||||
/// transformed by the given matrix in homogeneous coordinates.
|
||||
///
|
||||
/// Unlike Transform3DPoint, this method honors the fourth component of the
|
||||
/// transformed homogeneous coordiante. This makes it applicable for perspective
|
||||
/// transformations, but requires some more computations.
|
||||
///
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,3> Transform3DPointPerspective(const vtkm::Matrix<T,4,4> &matrix,
|
||||
const vtkm::Vec<T,3> &point)
|
||||
{
|
||||
vtkm::Vec<T,4> homogeneousPoint(point[0], point[1], point[2], T(1));
|
||||
T inverseW = 1/vtkm::dot(vtkm::MatrixGetRow(matrix,3), homogeneousPoint);
|
||||
return vtkm::Vec<T,3>(
|
||||
vtkm::dot(vtkm::MatrixGetRow(matrix,0), homogeneousPoint)*inverseW,
|
||||
vtkm::dot(vtkm::MatrixGetRow(matrix,1), homogeneousPoint)*inverseW,
|
||||
vtkm::dot(vtkm::MatrixGetRow(matrix,2), homogeneousPoint)*inverseW);
|
||||
}
|
||||
|
||||
/// \brief Transform a 3D vector by a transformation matrix.
|
||||
///
|
||||
/// Given a 4x4 transformation matrix and a 3D vector, returns the vector
|
||||
/// transformed by the given matrix in homogeneous coordinates. Unlike points,
|
||||
/// vectors do not get translated.
|
||||
///
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,3> Transform3DVector(const vtkm::Matrix<T,4,4> &matrix,
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include <vtkm/rendering/AxisAnnotation2D.h>
|
||||
|
||||
#include <vtkm/rendering/TextAnnotationScreen.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace vtkm {
|
||||
@ -113,10 +115,12 @@ void AxisAnnotation2D::Render(
|
||||
unsigned int nmajor = (unsigned int)this->ProportionsMajor.size();
|
||||
while (this->Labels.size() < nmajor)
|
||||
{
|
||||
this->Labels.push_back(new ScreenTextAnnotation("test",
|
||||
this->Color,
|
||||
this->FontScale,
|
||||
0,0, 0));
|
||||
this->Labels.push_back(new vtkm::rendering::TextAnnotationScreen(
|
||||
"test",
|
||||
this->Color,
|
||||
this->FontScale,
|
||||
vtkm::Vec<vtkm::Float32,2>(0,0),
|
||||
0));
|
||||
}
|
||||
|
||||
std::stringstream numberToString;
|
||||
@ -143,8 +147,8 @@ void AxisAnnotation2D::Render(
|
||||
this->Labels[i]->SetText(numberToString.str());
|
||||
//if (fabs(this->PositionsMajor[i]) < 1e-10)
|
||||
// this->Labels[i]->SetText("0");
|
||||
((ScreenTextAnnotation*)(this->Labels[i]))->SetPosition(vtkm::Float32(xs),
|
||||
vtkm::Float32(ys));
|
||||
((TextAnnotationScreen*)(this->Labels[i]))->SetPosition(vtkm::Float32(xs),
|
||||
vtkm::Float32(ys));
|
||||
|
||||
this->Labels[i]->SetAlignment(this->AlignH,this->AlignV);
|
||||
}
|
||||
|
@ -74,11 +74,12 @@ void AxisAnnotation3D::Render(const Camera &camera,
|
||||
unsigned int nmajor = (unsigned int)proportions.size();
|
||||
while (this->Labels.size() < nmajor)
|
||||
{
|
||||
this->Labels.push_back(new BillboardTextAnnotation("test",
|
||||
this->Color,
|
||||
vtkm::Float32(this->FontScale),
|
||||
0,0,0,
|
||||
0));
|
||||
this->Labels.push_back(new TextAnnotationBillboard(
|
||||
"test",
|
||||
this->Color,
|
||||
vtkm::Float32(this->FontScale),
|
||||
vtkm::Vec<vtkm::Float32,3>(0,0,0),
|
||||
0));
|
||||
}
|
||||
|
||||
std::stringstream numberToString;
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/WorldAnnotator.h>
|
||||
#include <vtkm/rendering/AxisAnnotation.h>
|
||||
#include <vtkm/rendering/TextAnnotation.h>
|
||||
#include <vtkm/rendering/TextAnnotationBillboard.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -50,7 +50,7 @@ protected:
|
||||
vtkm::Float32 FontOffset;
|
||||
vtkm::Float32 LineWidth;
|
||||
vtkm::rendering::Color Color;
|
||||
std::vector<BillboardTextAnnotation*> Labels;
|
||||
std::vector<TextAnnotationBillboard*> Labels;
|
||||
int MoreOrLessTickAdjustment;
|
||||
public:
|
||||
|
||||
|
@ -39,6 +39,8 @@ set(headers
|
||||
MapperRayTracer.h
|
||||
MapperVolume.h
|
||||
TextAnnotation.h
|
||||
TextAnnotationBillboard.h
|
||||
TextAnnotationScreen.h
|
||||
Triangulator.h
|
||||
View.h
|
||||
WorldAnnotator.h
|
||||
@ -61,6 +63,9 @@ set(sources
|
||||
MapperRayTracer.cxx
|
||||
MapperVolume.cxx
|
||||
Scene.cxx
|
||||
TextAnnotation.cxx
|
||||
TextAnnotationBillboard.cxx
|
||||
TextAnnotationScreen.cxx
|
||||
|
||||
internal/RunTriangulator.cxx
|
||||
)
|
||||
|
89
vtkm/rendering/TextAnnotation.cxx
Normal file
89
vtkm/rendering/TextAnnotation.cxx
Normal file
@ -0,0 +1,89 @@
|
||||
//============================================================================
|
||||
// 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/TextAnnotation.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
TextAnnotation::TextAnnotation(const std::string &text,
|
||||
const vtkm::rendering::Color &color,
|
||||
vtkm::Float32 scale)
|
||||
: Text(text), TextColor(color), Scale(scale), Anchor(-1,-1)
|
||||
{
|
||||
}
|
||||
|
||||
TextAnnotation::~TextAnnotation()
|
||||
{
|
||||
}
|
||||
|
||||
void TextAnnotation::SetText(const std::string &text)
|
||||
{
|
||||
this->Text = text;
|
||||
}
|
||||
|
||||
const std::string &TextAnnotation::GetText() const
|
||||
{
|
||||
return this->Text;
|
||||
}
|
||||
|
||||
void TextAnnotation::SetRawAnchor(const vtkm::Vec<vtkm::Float32,2> &anchor)
|
||||
{
|
||||
this->Anchor = anchor;
|
||||
}
|
||||
|
||||
void TextAnnotation::SetRawAnchor(vtkm::Float32 h, vtkm::Float32 v)
|
||||
{
|
||||
this->SetRawAnchor(vtkm::make_Vec(h,v));
|
||||
}
|
||||
|
||||
void TextAnnotation::SetAlignment(HorizontalAlignment h, VerticalAlignment v)
|
||||
{
|
||||
switch (h)
|
||||
{
|
||||
case Left: this->Anchor[0] = -1.0f; break;
|
||||
case HCenter: this->Anchor[0] = 0.0f; break;
|
||||
case Right: this->Anchor[0] = +1.0f; break;
|
||||
}
|
||||
|
||||
// For vertical alignment, "center" is generally the center
|
||||
// of only the above-baseline contents of the font, so we
|
||||
// use a value slightly off of zero for VCenter.
|
||||
// (We don't use an offset value instead of -1.0 for the
|
||||
// bottom value, because generally we want a true minimum
|
||||
// extent, e.g. to have text sitting at the bottom of a
|
||||
// window, and in that case, we need to keep all the text,
|
||||
// including parts that descend below the baseline, above
|
||||
// the bottom of the window.
|
||||
switch (v)
|
||||
{
|
||||
case Bottom: this->Anchor[1] = -1.0f; break;
|
||||
case VCenter: this->Anchor[1] = -0.06f; break;
|
||||
case Top: this->Anchor[1] = +1.0f; break;
|
||||
}
|
||||
}
|
||||
|
||||
void TextAnnotation::SetScale(vtkm::Float32 scale)
|
||||
{
|
||||
this->Scale = scale;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -20,11 +20,12 @@
|
||||
#ifndef vtk_m_rendering_TextAnnotation_h
|
||||
#define vtk_m_rendering_TextAnnotation_h
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/ColorTable.h>
|
||||
#include <vtkm/rendering/WorldAnnotator.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
@ -45,205 +46,50 @@ public:
|
||||
};
|
||||
|
||||
protected:
|
||||
std::string Text;
|
||||
Color TextColor;
|
||||
vtkm::Float32 Scale;
|
||||
vtkm::Float32 AnchorX, AnchorY;
|
||||
std::string Text;
|
||||
Color TextColor;
|
||||
vtkm::Float32 Scale;
|
||||
vtkm::Vec<vtkm::Float32,2> Anchor;
|
||||
|
||||
public:
|
||||
TextAnnotation(const std::string &txt, Color c, vtkm::Float32 s)
|
||||
: Text(txt), TextColor(c), Scale(s)
|
||||
{
|
||||
// default anchor: bottom-left
|
||||
AnchorX = -1;
|
||||
AnchorY = -1;
|
||||
}
|
||||
virtual ~TextAnnotation()
|
||||
{
|
||||
}
|
||||
void SetText(const std::string &txt)
|
||||
{
|
||||
Text = txt;
|
||||
}
|
||||
void SetRawAnchor(vtkm::Float32 h, vtkm::Float32 v)
|
||||
{
|
||||
AnchorX = h;
|
||||
AnchorY = v;
|
||||
}
|
||||
void SetAlignment(HorizontalAlignment h, VerticalAlignment v)
|
||||
{
|
||||
switch (h)
|
||||
{
|
||||
case Left: AnchorX = -1.0f; break;
|
||||
case HCenter: AnchorX = 0.0f; break;
|
||||
case Right: AnchorX = +1.0f; break;
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
TextAnnotation(const std::string &text,
|
||||
const vtkm::rendering::Color &color,
|
||||
vtkm::Float32 scalar);
|
||||
|
||||
// For vertical alignment, "center" is generally the center
|
||||
// of only the above-baseline contents of the font, so we
|
||||
// use a value slightly off of zero for VCenter.
|
||||
// (We don't use an offset value instead of -1.0 for the
|
||||
// bottom value, because generally we want a true minimum
|
||||
// extent, e.g. to have text sitting at the bottom of a
|
||||
// window, and in that case, we need to keep all the text,
|
||||
// including parts that descend below the baseline, above
|
||||
// the bottom of the window.
|
||||
switch (v)
|
||||
{
|
||||
case Bottom: AnchorY = -1.0f; break;
|
||||
case VCenter: AnchorY = -0.06f; break;
|
||||
case Top: AnchorY = +1.0f; break;
|
||||
}
|
||||
}
|
||||
void SetScale(vtkm::Float32 s)
|
||||
{
|
||||
Scale = s;
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual ~TextAnnotation();
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetText(const std::string &text);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
const std::string &GetText() const;
|
||||
|
||||
/// Set the anchor point relative to the box containing the text. The anchor
|
||||
/// is scaled in both directions to the range [-1,1] with -1 at the lower
|
||||
/// left and 1 at the upper right.
|
||||
///
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetRawAnchor(const vtkm::Vec<vtkm::Float32,2> &anchor);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetRawAnchor(vtkm::Float32 h, vtkm::Float32 v);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetAlignment(HorizontalAlignment h, VerticalAlignment v);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetScale(vtkm::Float32 scale);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void Render(const vtkm::rendering::Camera &camera,
|
||||
const vtkm::rendering::WorldAnnotator &worldAnnotator,
|
||||
vtkm::rendering::Canvas &canvas) = 0;
|
||||
};
|
||||
|
||||
class ScreenTextAnnotation : public TextAnnotation
|
||||
{
|
||||
protected:
|
||||
vtkm::Float32 XPos,YPos;
|
||||
vtkm::Float32 Angle;
|
||||
public:
|
||||
ScreenTextAnnotation(const std::string &txt, Color c, vtkm::Float32 s,
|
||||
vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 angleDeg = 0.)
|
||||
: TextAnnotation(txt,c,s)
|
||||
{
|
||||
XPos = ox;
|
||||
YPos = oy;
|
||||
Angle = angleDeg;
|
||||
}
|
||||
void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy)
|
||||
{
|
||||
XPos = ox;
|
||||
YPos = oy;
|
||||
}
|
||||
virtual void Render(const vtkm::rendering::Camera &vtkmNotUsed(camera),
|
||||
const vtkm::rendering::WorldAnnotator &,
|
||||
vtkm::rendering::Canvas &canvas)
|
||||
{
|
||||
vtkm::Float32 WindowAspect = vtkm::Float32(canvas.GetWidth()) /
|
||||
vtkm::Float32(canvas.GetHeight());
|
||||
|
||||
canvas.AddText(XPos,YPos,
|
||||
Scale,
|
||||
Angle,
|
||||
WindowAspect,
|
||||
AnchorX, AnchorY,
|
||||
TextColor, Text);
|
||||
}
|
||||
};
|
||||
|
||||
class BillboardTextAnnotation : public TextAnnotation
|
||||
{
|
||||
protected:
|
||||
vtkm::Float32 XPos,YPos,ZPos;
|
||||
vtkm::Float32 Angle;
|
||||
public:
|
||||
BillboardTextAnnotation(const std::string &txt, Color c, vtkm::Float32 s,
|
||||
vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz,
|
||||
vtkm::Float32 angleDeg = 0.)
|
||||
: TextAnnotation(txt,c,s)
|
||||
{
|
||||
XPos = ox;
|
||||
YPos = oy;
|
||||
ZPos = oz;
|
||||
Angle = angleDeg;
|
||||
}
|
||||
void SetPosition(vtkm::Float32 ox, vtkm::Float32 oy, vtkm::Float32 oz)
|
||||
{
|
||||
XPos = ox;
|
||||
YPos = oy;
|
||||
ZPos = oz;
|
||||
}
|
||||
|
||||
virtual void Render(const vtkm::rendering::Camera &camera,
|
||||
const vtkm::rendering::WorldAnnotator &worldAnnotator,
|
||||
vtkm::rendering::Canvas &canvas)
|
||||
{
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> V, P;
|
||||
V = camera.CreateViewMatrix();
|
||||
P = camera.CreateProjectionMatrix(canvas.GetWidth(), canvas.GetHeight());
|
||||
|
||||
vtkm::Vec<vtkm::Float32,4> p4w(XPos,YPos,ZPos,1);
|
||||
vtkm::Vec<vtkm::Float32,4> p4s =
|
||||
vtkm::MatrixMultiply(vtkm::MatrixMultiply(P,V), p4w);
|
||||
|
||||
canvas.SetViewToScreenSpace(camera,true);
|
||||
|
||||
vtkm::Float32 psx = p4s[0] / p4s[3];
|
||||
vtkm::Float32 psy = p4s[1] / p4s[3];
|
||||
vtkm::Float32 psz = p4s[2] / p4s[3];
|
||||
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> T;
|
||||
T = vtkm::Transform3DTranslate(psx,psy,-psz);
|
||||
|
||||
vtkm::Float32 WindowAspect =
|
||||
vtkm::Float32(canvas.GetWidth()) / vtkm::Float32(canvas.GetHeight());
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> SW;
|
||||
SW = vtkm::Transform3DScale(1.f/WindowAspect, 1.f, 1.f);
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> SV;
|
||||
vtkm::MatrixIdentity(SV);
|
||||
//if view type == 2D?
|
||||
{
|
||||
vtkm::Float32 vl, vr, vb, vt;
|
||||
camera.GetRealViewport(canvas.GetWidth(),canvas.GetHeight(),vl,vr,vb,vt);
|
||||
vtkm::Float32 xs = (vr-vl);
|
||||
vtkm::Float32 ys = (vt-vb);
|
||||
SV = vtkm::Transform3DScale(2.f/xs, 2.f/ys, 1.f);
|
||||
}
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> R;
|
||||
R = vtkm::Transform3DRotateZ(Angle * 3.14159265f / 180.f);
|
||||
|
||||
vtkm::Vec<vtkm::Float32,4> origin4(0,0,0,1);
|
||||
vtkm::Vec<vtkm::Float32,4> right4(1,0,0,0);
|
||||
vtkm::Vec<vtkm::Float32,4> up4(0,1,0,0);
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> M =
|
||||
vtkm::MatrixMultiply(T,
|
||||
vtkm::MatrixMultiply(SW,
|
||||
vtkm::MatrixMultiply(SV,
|
||||
R)));
|
||||
|
||||
vtkm::Vec<vtkm::Float32,4> new_origin4 =
|
||||
vtkm::MatrixMultiply(M, origin4);
|
||||
vtkm::Vec<vtkm::Float32,4> new_right4 =
|
||||
vtkm::MatrixMultiply(M, right4);
|
||||
vtkm::Vec<vtkm::Float32,4> new_up4 =
|
||||
vtkm::MatrixMultiply(M, up4);
|
||||
|
||||
vtkm::Float32 px = new_origin4[0] / new_origin4[3];
|
||||
vtkm::Float32 py = new_origin4[1] / new_origin4[3];
|
||||
vtkm::Float32 pz = new_origin4[2] / new_origin4[3];
|
||||
|
||||
vtkm::Float32 rx = new_right4[0];
|
||||
vtkm::Float32 ry = new_right4[1];
|
||||
vtkm::Float32 rz = new_right4[2];
|
||||
|
||||
vtkm::Float32 ux = new_up4[0];
|
||||
vtkm::Float32 uy = new_up4[1];
|
||||
vtkm::Float32 uz = new_up4[2];
|
||||
|
||||
worldAnnotator.AddText(px,py,pz,
|
||||
rx,ry,rz,
|
||||
ux,uy,uz,
|
||||
Scale,
|
||||
AnchorX, AnchorY,
|
||||
TextColor, Text);
|
||||
|
||||
canvas.SetViewToWorldSpace(camera,true);
|
||||
}
|
||||
vtkm::rendering::Canvas &canvas) const = 0;
|
||||
};
|
||||
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_TextAnnotation_h
|
||||
|
121
vtkm/rendering/TextAnnotationBillboard.cxx
Normal file
121
vtkm/rendering/TextAnnotationBillboard.cxx
Normal file
@ -0,0 +1,121 @@
|
||||
//============================================================================
|
||||
// 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/TextAnnotationBillboard.h>
|
||||
|
||||
#include <vtkm/Matrix.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
TextAnnotationBillboard::TextAnnotationBillboard(
|
||||
const std::string &text,
|
||||
const vtkm::rendering::Color &color,
|
||||
vtkm::Float32 scalar,
|
||||
const vtkm::Vec<vtkm::Float32,3> &position,
|
||||
vtkm::Float32 angleDegrees)
|
||||
: TextAnnotation(text, color, scalar),
|
||||
Position(position),
|
||||
Angle(angleDegrees)
|
||||
{ }
|
||||
|
||||
TextAnnotationBillboard::~TextAnnotationBillboard()
|
||||
{ }
|
||||
|
||||
void TextAnnotationBillboard::SetPosition(
|
||||
const vtkm::Vec<vtkm::Float32,3> &position)
|
||||
{
|
||||
this->Position = position;
|
||||
}
|
||||
|
||||
void TextAnnotationBillboard::SetPosition(
|
||||
vtkm::Float32 xpos, vtkm::Float32 ypos, vtkm::Float32 zpos)
|
||||
{
|
||||
this->SetPosition(vtkm::make_Vec(xpos, ypos, zpos));
|
||||
}
|
||||
|
||||
void TextAnnotationBillboard::Render(
|
||||
const vtkm::rendering::Camera &camera,
|
||||
const vtkm::rendering::WorldAnnotator &worldAnnotator,
|
||||
vtkm::rendering::Canvas &canvas) const
|
||||
{
|
||||
using MatrixType = vtkm::Matrix<vtkm::Float32,4,4>;
|
||||
using VectorType = vtkm::Vec<vtkm::Float32,3>;
|
||||
|
||||
MatrixType viewMatrix = camera.CreateViewMatrix();
|
||||
MatrixType projectionMatrix
|
||||
= camera.CreateProjectionMatrix(canvas.GetWidth(), canvas.GetHeight());
|
||||
|
||||
VectorType screenPos =
|
||||
vtkm::Transform3DPointPerspective(
|
||||
vtkm::MatrixMultiply(projectionMatrix,viewMatrix),
|
||||
this->Position);
|
||||
|
||||
canvas.SetViewToScreenSpace(camera,true);
|
||||
|
||||
|
||||
MatrixType translateMatrix =
|
||||
vtkm::Transform3DTranslate(screenPos[0], screenPos[1], -screenPos[2]);
|
||||
|
||||
vtkm::Float32 windowAspect =
|
||||
vtkm::Float32(canvas.GetWidth()) / vtkm::Float32(canvas.GetHeight());
|
||||
|
||||
MatrixType scaleMatrix = vtkm::Transform3DScale(1.f/windowAspect, 1.f, 1.f);
|
||||
|
||||
MatrixType viewportMatrix;
|
||||
vtkm::MatrixIdentity(viewportMatrix);
|
||||
//if view type == 2D?
|
||||
{
|
||||
vtkm::Float32 vl, vr, vb, vt;
|
||||
camera.GetRealViewport(canvas.GetWidth(),canvas.GetHeight(),vl,vr,vb,vt);
|
||||
vtkm::Float32 xs = (vr-vl);
|
||||
vtkm::Float32 ys = (vt-vb);
|
||||
viewportMatrix = vtkm::Transform3DScale(2.f/xs, 2.f/ys, 1.f);
|
||||
}
|
||||
|
||||
MatrixType rotateMatrix =
|
||||
vtkm::Transform3DRotateZ(this->Angle * 3.14159265f / 180.f);
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> fullTransformMatrix =
|
||||
vtkm::MatrixMultiply(translateMatrix,
|
||||
vtkm::MatrixMultiply(scaleMatrix,
|
||||
vtkm::MatrixMultiply(viewportMatrix,
|
||||
rotateMatrix)));
|
||||
|
||||
VectorType origin =
|
||||
vtkm::Transform3DPointPerspective(fullTransformMatrix, VectorType(0,0,0));
|
||||
VectorType right =
|
||||
vtkm::Transform3DVector(fullTransformMatrix, VectorType(1,0,0));
|
||||
VectorType up =
|
||||
vtkm::Transform3DVector(fullTransformMatrix, VectorType(0,1,0));
|
||||
|
||||
worldAnnotator.AddText(origin,
|
||||
right,
|
||||
up,
|
||||
this->Scale,
|
||||
this->Anchor,
|
||||
this->TextColor,
|
||||
this->Text);
|
||||
|
||||
canvas.SetViewToWorldSpace(camera,true);
|
||||
}
|
||||
|
||||
}
|
||||
} // vtkm::rendering
|
60
vtkm/rendering/TextAnnotationBillboard.h
Normal file
60
vtkm/rendering/TextAnnotationBillboard.h
Normal file
@ -0,0 +1,60 @@
|
||||
//============================================================================
|
||||
// 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 vtkm_rendering_TextAnnotationBillboard_h
|
||||
#define vtkm_rendering_TextAnnotationBillboard_h
|
||||
|
||||
#include <vtkm/rendering/TextAnnotation.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
class TextAnnotationBillboard : public TextAnnotation
|
||||
{
|
||||
protected:
|
||||
vtkm::Vec<vtkm::Float32,3> Position;
|
||||
vtkm::Float32 Angle;
|
||||
|
||||
public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
TextAnnotationBillboard(const std::string &text,
|
||||
const vtkm::rendering::Color &color,
|
||||
vtkm::Float32 scalar,
|
||||
const vtkm::Vec<vtkm::Float32,3> &position,
|
||||
vtkm::Float32 angleDegrees = 0);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
~TextAnnotationBillboard();
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetPosition(const vtkm::Vec<vtkm::Float32,3> &position);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetPosition(vtkm::Float32 posx, vtkm::Float32 posy, vtkm::Float32 posz);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void Render(const vtkm::rendering::Camera &camera,
|
||||
const vtkm::rendering::WorldAnnotator &worldAnnotator,
|
||||
vtkm::rendering::Canvas &canvas) const VTKM_OVERRIDE;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
||||
#endif //vtkm_rendering_TextAnnotationBillboard_h
|
69
vtkm/rendering/TextAnnotationScreen.cxx
Normal file
69
vtkm/rendering/TextAnnotationScreen.cxx
Normal file
@ -0,0 +1,69 @@
|
||||
//============================================================================
|
||||
// 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/TextAnnotationScreen.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
TextAnnotationScreen::TextAnnotationScreen(
|
||||
const std::string &text,
|
||||
const vtkm::rendering::Color &color,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32,2> &position,
|
||||
vtkm::Float32 angleDegrees)
|
||||
: TextAnnotation(text,color,scale),
|
||||
Position(position),
|
||||
Angle(angleDegrees)
|
||||
{ }
|
||||
|
||||
TextAnnotationScreen::~TextAnnotationScreen()
|
||||
{ }
|
||||
|
||||
void TextAnnotationScreen::SetPosition(
|
||||
const vtkm::Vec<vtkm::Float32,2> &position)
|
||||
{
|
||||
this->Position = position;
|
||||
}
|
||||
|
||||
void TextAnnotationScreen::SetPosition(vtkm::Float32 xpos, vtkm::Float32 ypos)
|
||||
{
|
||||
this->SetPosition(vtkm::make_Vec(xpos, ypos));
|
||||
}
|
||||
|
||||
void TextAnnotationScreen::Render(
|
||||
const vtkm::rendering::Camera &vtkmNotUsed(camera),
|
||||
const vtkm::rendering::WorldAnnotator &vtkmNotUsed(annotator),
|
||||
vtkm::rendering::Canvas &canvas) const
|
||||
{
|
||||
vtkm::Float32 windowAspect = vtkm::Float32(canvas.GetWidth()) /
|
||||
vtkm::Float32(canvas.GetHeight());
|
||||
|
||||
canvas.AddText(this->Position,
|
||||
this->Scale,
|
||||
this->Angle,
|
||||
windowAspect,
|
||||
this->Anchor,
|
||||
this->TextColor,
|
||||
this->Text);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
60
vtkm/rendering/TextAnnotationScreen.h
Normal file
60
vtkm/rendering/TextAnnotationScreen.h
Normal file
@ -0,0 +1,60 @@
|
||||
//============================================================================
|
||||
// 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_TextAnnotationScreen_h
|
||||
#define vtk_m_rendering_TextAnnotationScreen_h
|
||||
|
||||
#include <vtkm/rendering/TextAnnotation.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
class TextAnnotationScreen : public TextAnnotation
|
||||
{
|
||||
protected:
|
||||
vtkm::Vec<vtkm::Float32,2> Position;
|
||||
vtkm::Float32 Angle;
|
||||
|
||||
public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
TextAnnotationScreen(const std::string &text,
|
||||
const vtkm::rendering::Color &color,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32,2> &position,
|
||||
vtkm::Float32 angleDegrees = 0);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
~TextAnnotationScreen();
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetPosition(const vtkm::Vec<vtkm::Float32,2> &position);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetPosition(vtkm::Float32 posx, vtkm::Float32 posy);
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void Render(const vtkm::rendering::Camera &camera,
|
||||
const vtkm::rendering::WorldAnnotator &annotator,
|
||||
vtkm::rendering::Canvas &canvas) const VTKM_OVERRIDE;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_TextAnnotationScreen_h
|
@ -185,6 +185,26 @@ struct TransformTests
|
||||
test_equal(rotated1, Vec(-startPoint[1],startPoint[0],startPoint[2])),
|
||||
"Bad rotate.");
|
||||
}
|
||||
|
||||
void CheckPerspective()
|
||||
{
|
||||
std::cout << "--- Checking Perspective" << std::endl;
|
||||
|
||||
Vec startPoint = this->RandomVector();
|
||||
std::cout << " Starting point: " << startPoint << std::endl;
|
||||
|
||||
Transform perspective(0);
|
||||
perspective(0, 0) = 1;
|
||||
perspective(1, 1) = 1;
|
||||
perspective(2, 2) = 1;
|
||||
perspective(3, 2) = 1;
|
||||
|
||||
Vec projected = vtkm::Transform3DPointPerspective(perspective, startPoint);
|
||||
std::cout << " Projected: " << projected << std::endl;
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(projected, startPoint/startPoint[2]),
|
||||
"Bad perspective.");
|
||||
}
|
||||
};
|
||||
|
||||
struct TryTransformsFunctor
|
||||
|
Loading…
Reference in New Issue
Block a user