2016-08-26 18:58:28 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-08-26 18:58:28 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/rendering/AxisAnnotation3D.h>
|
|
|
|
|
2023-06-12 20:02:47 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace rendering
|
|
|
|
{
|
2016-08-26 18:58:28 +00:00
|
|
|
|
|
|
|
AxisAnnotation3D::AxisAnnotation3D()
|
2017-05-18 14:29:41 +00:00
|
|
|
: AxisAnnotation()
|
|
|
|
, TickMajorSize(1.0)
|
|
|
|
, TickMajorOffset(1.0)
|
|
|
|
, TickMinorSize(0.1)
|
|
|
|
, TickMinorOffset(1.0)
|
|
|
|
, Axis(0)
|
|
|
|
, Invert(1, 1, 1)
|
|
|
|
, Point0(0, 0, 0)
|
|
|
|
, Point1(1, 0, 0)
|
|
|
|
, Range(0, 1)
|
|
|
|
, FontScale(0.05f)
|
|
|
|
, // screen space font size
|
|
|
|
FontOffset(0.1f)
|
|
|
|
, // world space offset from axis
|
|
|
|
LineWidth(1.0)
|
|
|
|
, Color(1, 1, 1)
|
|
|
|
, MoreOrLessTickAdjustment(0)
|
|
|
|
{
|
|
|
|
}
|
2016-08-26 18:58:28 +00:00
|
|
|
|
|
|
|
void AxisAnnotation3D::SetTickInvert(bool x, bool y, bool z)
|
|
|
|
{
|
|
|
|
this->Invert[0] = x ? +1.0f : -1.0f;
|
|
|
|
this->Invert[1] = y ? +1.0f : -1.0f;
|
|
|
|
this->Invert[2] = z ? +1.0f : -1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AxisAnnotation3D::SetLabelFontScale(Float64 s)
|
|
|
|
{
|
|
|
|
this->FontScale = s;
|
2023-06-12 20:02:47 +00:00
|
|
|
for (auto& label : this->Labels)
|
2016-08-26 18:58:28 +00:00
|
|
|
{
|
2023-06-12 20:02:47 +00:00
|
|
|
label->SetScale(vtkm::Float32(s));
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
void AxisAnnotation3D::Render(const Camera& camera,
|
|
|
|
const WorldAnnotator& worldAnnotator,
|
2017-05-18 14:29:41 +00:00
|
|
|
Canvas& canvas)
|
2016-08-26 18:58:28 +00:00
|
|
|
{
|
|
|
|
bool infront = true;
|
2017-05-18 14:29:41 +00:00
|
|
|
worldAnnotator.AddLine(this->Point0, this->Point1, this->LineWidth, this->Color, infront);
|
2016-08-26 18:58:28 +00:00
|
|
|
|
|
|
|
std::vector<vtkm::Float64> positions;
|
|
|
|
std::vector<vtkm::Float64> proportions;
|
|
|
|
// major ticks
|
|
|
|
CalculateTicks(this->Range, false, positions, proportions, this->MoreOrLessTickAdjustment);
|
2023-06-12 20:02:47 +00:00
|
|
|
auto nmajor = (unsigned int)proportions.size();
|
2016-08-26 18:58:28 +00:00
|
|
|
while (this->Labels.size() < nmajor)
|
|
|
|
{
|
2023-06-12 20:02:47 +00:00
|
|
|
this->Labels.push_back(std::make_unique<TextAnnotationBillboard>(
|
2023-06-14 16:04:43 +00:00
|
|
|
"test", this->Color, vtkm::Float32(this->FontScale), vtkm::Vec3f_32(0, 0, 0)));
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream numberToString;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (unsigned int i = 0; i < nmajor; ++i)
|
2016-08-26 18:58:28 +00:00
|
|
|
{
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f_64 tickPos = proportions[i] * (this->Point1 - this->Point0) + this->Point0;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (int pass = 0; pass <= 1; pass++)
|
2016-08-26 18:58:28 +00:00
|
|
|
{
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f_64 tickSize(0);
|
2016-08-26 18:58:28 +00:00
|
|
|
if (pass == 0)
|
|
|
|
{
|
|
|
|
switch (this->Axis)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
case 0:
|
|
|
|
tickSize[1] = this->TickMajorSize;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
tickSize[0] = this->TickMajorSize;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
tickSize[0] = this->TickMajorSize;
|
|
|
|
break;
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // pass == 1
|
|
|
|
{
|
|
|
|
switch (this->Axis)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
case 0:
|
|
|
|
tickSize[2] = this->TickMajorSize;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
tickSize[2] = this->TickMajorSize;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
tickSize[1] = this->TickMajorSize;
|
|
|
|
break;
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tickSize = tickSize * this->Invert;
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f_64 start = tickPos - tickSize * this->TickMajorOffset;
|
|
|
|
vtkm::Vec3f_64 end = tickPos - tickSize * (1.0 - this->TickMajorOffset);
|
2016-08-26 18:58:28 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
worldAnnotator.AddLine(start, end, this->LineWidth, this->Color, infront);
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f_32 tickSize(0);
|
2016-08-26 18:58:28 +00:00
|
|
|
vtkm::Float32 s = 0.4f * this->FontOffset;
|
|
|
|
switch (this->Axis)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
case 0:
|
|
|
|
tickSize[1] = s;
|
|
|
|
tickSize[2] = s;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
tickSize[0] = s;
|
|
|
|
tickSize[2] = s;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
tickSize[0] = s;
|
|
|
|
tickSize[1] = s;
|
|
|
|
break;
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
tickSize = tickSize * this->Invert;
|
|
|
|
|
|
|
|
numberToString.str("");
|
|
|
|
numberToString << positions[i];
|
|
|
|
this->Labels[i]->SetText(numberToString.str());
|
|
|
|
//if (fabs(positions[i]) < 1e-10)
|
|
|
|
// this->Labels[i]->SetText("0");
|
|
|
|
this->Labels[i]->SetPosition(vtkm::Float32(tickPos[0] - tickSize[0]),
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Float32(tickPos[1] - tickSize[1]),
|
|
|
|
vtkm::Float32(tickPos[2] - tickSize[2]));
|
|
|
|
this->Labels[i]->SetAlignment(TextAnnotation::HCenter, TextAnnotation::VCenter);
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// minor ticks
|
|
|
|
CalculateTicks(this->Range, true, positions, proportions, this->MoreOrLessTickAdjustment);
|
2023-06-12 20:02:47 +00:00
|
|
|
auto nminor = (unsigned int)proportions.size();
|
2017-05-18 14:29:41 +00:00
|
|
|
for (unsigned int i = 0; i < nminor; ++i)
|
2016-08-26 18:58:28 +00:00
|
|
|
{
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f_64 tickPos = proportions[i] * (this->Point1 - this->Point0) + this->Point0;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (int pass = 0; pass <= 1; pass++)
|
2016-08-26 18:58:28 +00:00
|
|
|
{
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f_64 tickSize(0);
|
2016-08-26 18:58:28 +00:00
|
|
|
if (pass == 0)
|
|
|
|
{
|
|
|
|
switch (this->Axis)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
case 0:
|
2017-11-13 16:34:05 +00:00
|
|
|
tickSize[1] = this->TickMinorSize;
|
2017-05-18 14:29:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2017-11-13 16:34:05 +00:00
|
|
|
tickSize[0] = this->TickMinorSize;
|
2017-05-18 14:29:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-11-13 16:34:05 +00:00
|
|
|
tickSize[0] = this->TickMinorSize;
|
2017-05-18 14:29:41 +00:00
|
|
|
break;
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // pass == 1
|
|
|
|
{
|
|
|
|
switch (this->Axis)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
case 0:
|
2017-11-13 16:34:05 +00:00
|
|
|
tickSize[2] = this->TickMinorSize;
|
2017-05-18 14:29:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2017-11-13 16:34:05 +00:00
|
|
|
tickSize[2] = this->TickMinorSize;
|
2017-05-18 14:29:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-11-13 16:34:05 +00:00
|
|
|
tickSize[1] = this->TickMinorSize;
|
2017-05-18 14:29:41 +00:00
|
|
|
break;
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tickSize = tickSize * this->Invert;
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f_64 start = tickPos - tickSize * this->TickMinorOffset;
|
|
|
|
vtkm::Vec3f_64 end = tickPos - tickSize * (1.0 - this->TickMinorOffset);
|
2016-08-26 18:58:28 +00:00
|
|
|
|
|
|
|
worldAnnotator.AddLine(start, end, this->LineWidth, this->Color, infront);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-12 20:02:47 +00:00
|
|
|
for (auto& label : this->Labels)
|
2016-08-26 18:58:28 +00:00
|
|
|
{
|
2023-06-12 20:02:47 +00:00
|
|
|
label->Render(camera, worldAnnotator, canvas);
|
2016-08-26 18:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::rendering
|