1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkSmoothErrorMetric.h"
#include "vtkGenericAdaptorCell.h"
#include "vtkGenericAttribute.h"
#include "vtkGenericAttributeCollection.h"
#include "vtkGenericDataSet.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include <cassert>
VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkSmoothErrorMetric);
//------------------------------------------------------------------------------
vtkSmoothErrorMetric::vtkSmoothErrorMetric()
{
this->AngleTolerance = 90.1; // in degrees
this->CosTolerance = cos(vtkMath::RadiansFromDegrees(this->AngleTolerance));
}
//------------------------------------------------------------------------------
vtkSmoothErrorMetric::~vtkSmoothErrorMetric() = default;
//------------------------------------------------------------------------------
double vtkSmoothErrorMetric::GetAngleTolerance()
{
return this->AngleTolerance;
}
//------------------------------------------------------------------------------
void vtkSmoothErrorMetric::SetAngleTolerance(double value)
{
// assert("pre: positive_value" && value>90 && value<180);
if (this->AngleTolerance != value)
{
// Clamp the value
if (value <= 90)
{
vtkWarningMacro(<< "value " << value << " out of range ]90,180[, clamped to 90.1");
this->AngleTolerance = 90.1;
}
else
{
if (value >= 180)
{
vtkWarningMacro(<< "value " << value << " out of range ]90,180[, clamped to 179.9");
this->AngleTolerance = 179.9;
}
else
{
this->AngleTolerance = value;
}
}
this->CosTolerance = cos(vtkMath::RadiansFromDegrees(this->AngleTolerance));
this->Modified();
}
}
//------------------------------------------------------------------------------
int vtkSmoothErrorMetric::RequiresEdgeSubdivision(
double* leftPoint, double* midPoint, double* rightPoint, double vtkNotUsed(alpha))
{
assert("pre: leftPoint_exists" && leftPoint != nullptr);
assert("pre: midPoint_exists" && midPoint != nullptr);
assert("pre: rightPoint_exists" && rightPoint != nullptr);
// assert( "pre: clamped_alpha" && alpha>0 && alpha < 1. ); // or else true
if (this->GenericCell->IsGeometryLinear())
{
// don't need to do anything:
return 0;
}
double a[3];
double b[3];
a[0] = leftPoint[0] - midPoint[0];
a[1] = leftPoint[1] - midPoint[1];
a[2] = leftPoint[2] - midPoint[2];
b[0] = rightPoint[0] - midPoint[0];
b[1] = rightPoint[1] - midPoint[1];
b[2] = rightPoint[2] - midPoint[2];
double dota = vtkMath::Dot(a, a);
double dotb = vtkMath::Dot(b, b);
double cosa;
if (dota == 0 || dotb == 0)
{
cosa = -1.;
}
else
{
cosa = vtkMath::Dot(a, b) / sqrt(dota * dotb);
}
int result = (cosa > this->CosTolerance);
return result;
}
//------------------------------------------------------------------------------
// Description:
// Return the error at the mid-point. The type of error depends on the state
// of the concrete error metric. For instance, it can return an absolute
// or relative error metric.
// See RequiresEdgeSubdivision() for a description of the arguments.
// \post positive_result: result>=0
double vtkSmoothErrorMetric::GetError(
double* leftPoint, double* midPoint, double* rightPoint, double vtkNotUsed(alpha))
{
assert("pre: leftPoint_exists" && leftPoint != nullptr);
assert("pre: midPoint_exists" && midPoint != nullptr);
assert("pre: rightPoint_exists" && rightPoint != nullptr);
// assert( "pre: clamped_alpha" && alpha > 0. && alpha < 1. );
if (this->GenericCell->IsGeometryLinear())
{
// don't need to do anything:
return 0.;
}
double a[3];
double b[3];
a[0] = leftPoint[0] - midPoint[0];
a[1] = leftPoint[1] - midPoint[1];
a[2] = leftPoint[2] - midPoint[2];
b[0] = rightPoint[0] - midPoint[0];
b[1] = rightPoint[1] - midPoint[1];
b[2] = rightPoint[2] - midPoint[2];
double dota = vtkMath::Dot(a, a);
double dotb = vtkMath::Dot(b, b);
double cosa;
if (dota == 0. || dotb == 0.)
{
cosa = -1.;
}
else
{
cosa = vtkMath::Dot(a, b) / sqrt(dota * dotb);
}
if (cosa > 1.)
{
cosa = 1.;
}
else if (cosa < -1.)
{
cosa = -1.;
}
double result = 180. - vtkMath::RadiansFromDegrees(acos(cosa));
assert("post: positive_result" && result >= 0.);
return result;
}
//------------------------------------------------------------------------------
void vtkSmoothErrorMetric::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "AngleTolerance: " << this->AngleTolerance << endl;
os << indent << "CosTolerance: " << this->CosTolerance << endl;
}
VTK_ABI_NAMESPACE_END
|