1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10
11 #include <vtkm/rendering/LineRenderer.h>
12 #include <vtkm/rendering/TextRenderer.h>
13 #include <vtkm/rendering/WorldAnnotator.h>
14
15 namespace vtkm
16 {
17 namespace rendering
18 {
19
WorldAnnotator(const vtkm::rendering::Canvas * canvas)20 WorldAnnotator::WorldAnnotator(const vtkm::rendering::Canvas* canvas)
21 : Canvas(canvas)
22 {
23 }
24
~WorldAnnotator()25 WorldAnnotator::~WorldAnnotator() {}
26
AddLine(const vtkm::Vec3f_64 & point0,const vtkm::Vec3f_64 & point1,vtkm::Float32 lineWidth,const vtkm::rendering::Color & color,bool vtkmNotUsed (inFront)) const27 void WorldAnnotator::AddLine(const vtkm::Vec3f_64& point0,
28 const vtkm::Vec3f_64& point1,
29 vtkm::Float32 lineWidth,
30 const vtkm::rendering::Color& color,
31 bool vtkmNotUsed(inFront)) const
32 {
33 vtkm::Matrix<vtkm::Float32, 4, 4> transform =
34 vtkm::MatrixMultiply(Canvas->GetProjection(), Canvas->GetModelView());
35 LineRenderer renderer(Canvas, transform);
36 renderer.RenderLine(point0, point1, lineWidth, color);
37 }
38
AddText(const vtkm::Vec3f_32 & origin,const vtkm::Vec3f_32 & right,const vtkm::Vec3f_32 & up,vtkm::Float32 scale,const vtkm::Vec2f_32 & anchor,const vtkm::rendering::Color & color,const std::string & text,const vtkm::Float32 depth) const39 void WorldAnnotator::AddText(const vtkm::Vec3f_32& origin,
40 const vtkm::Vec3f_32& right,
41 const vtkm::Vec3f_32& up,
42 vtkm::Float32 scale,
43 const vtkm::Vec2f_32& anchor,
44 const vtkm::rendering::Color& color,
45 const std::string& text,
46 const vtkm::Float32 depth) const
47 {
48 vtkm::Vec3f_32 n = vtkm::Cross(right, up);
49 vtkm::Normalize(n);
50
51 vtkm::Matrix<vtkm::Float32, 4, 4> transform = MatrixHelpers::WorldMatrix(origin, right, up, n);
52 transform = vtkm::MatrixMultiply(Canvas->GetModelView(), transform);
53 transform = vtkm::MatrixMultiply(Canvas->GetProjection(), transform);
54 Canvas->AddText(transform, scale, anchor, color, text, depth);
55 }
56 }
57 } // namespace vtkm::rendering
58