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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkObject.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm 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.
=========================================================================*/
#include "vtkCellQuality.h"
#include "verdict.h"
#include "vtkCellData.h"
#include "vtkCell.h"
#include "vtkCellTypes.h"
#include "vtkDataArray.h"
#include "vtkDataSet.h"
#include "vtkDoubleArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkMeshQuality.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkSmartPointer.h"
#include "vtkTetra.h"
#include "vtkTriangle.h"
#include "vtkstd/utility"
vtkStandardNewMacro(vtkCellQuality);
double vtkCellQuality::CurrentTriNormal [3];
vtkCellQuality::~vtkCellQuality ()
{
this->PointIds->Delete();
this->Points->Delete();
}
vtkCellQuality::vtkCellQuality ()
{
this->QualityMeasure = NONE;
this->UnsupportedGeometry = -1;
this->UndefinedQuality = -1;
this->PointIds = vtkIdList::New();
this->Points = vtkPoints::New();
}
void vtkCellQuality::PrintSelf (ostream& os, vtkIndent indent)
{
static const char* CellQualityMeasureNames [] =
{
"None",
"Area",
"AspectBeta"
"AspectFrobenius",
"AspectGamma",
"AspectRatio",
"CollapseRatio",
"Condition",
"Diagonal",
"Dimension",
"Distortion",
"EdgeRatio",
"Jacobian",
"MaxAngle",
"MaxAspectFrobenius",
"MaxEdgeRatio",
"MedAspectFrobenius",
"MinAngle",
"Oddy",
"RadiusRatio",
"RelativeSizeSquared",
"ScaledJacobian",
"Shape",
"ShapeAndSize",
"Shear",
"ShearAndSize",
"Skew",
"Stretch",
"Taper",
"Volume",
"Warpage",
};
const char* name = CellQualityMeasureNames[this->QualityMeasure];
this->Superclass::PrintSelf(os, indent);
os << indent << "TriangleQualityMeasure : " << name << endl;
os << indent << "QuadQualityMeasure : " << name << endl;
os << indent << "TetQualityMeasure : " << name << endl;
os << indent << "HexQualityMeasure : " << name << endl;
os << indent << "TriangleStripQualityMeasure : " << name << endl;
os << indent << "PixelQualityMeasure : " << name << endl;
os << indent << "UnsupportedGeometry : " << this->UnsupportedGeometry << endl;
os << indent << "UndefinedQuality : " << this->UndefinedQuality << endl;
}
int vtkCellQuality::RequestData
(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// get the info objects
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation* outInfo = outputVector->GetInformationObject(0);
// get the input and output
vtkDataSet* in = vtkDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkDataSet* out = vtkDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
// Copy input to get a start point
out->ShallowCopy(in);
// Allocate storage for cell quality
vtkIdType const nCells = in->GetNumberOfCells();
vtkSmartPointer<vtkDoubleArray> quality =
vtkSmartPointer<vtkDoubleArray>::New();
quality->SetName("CellQuality");
quality->SetNumberOfValues(nCells);
vtkDataArray* CellNormals = in->GetCellData()->GetNormals();
if (CellNormals)
{
v_set_tri_normal_func(reinterpret_cast<ComputeNormal>
(vtkCellQuality::GetCurrentTriangleNormal));
}
else
{
v_set_tri_normal_func(0);
}
// Support progress and abort.
vtkIdType const tenth = (nCells >= 10 ? nCells/10 : 1);
double const nCellInv = 1./nCells;
// Actual computation of the selected quality
for (vtkIdType cid = 0; cid < nCells; ++cid)
{
// Periodically update progress and check for an abort request.
if (0 == cid % tenth)
{
this->UpdateProgress((cid+1)*nCellInv);
if (this->GetAbortExecute())
{
break;
}
}
vtkCell* cell = out->GetCell(cid);
double q = 0;
switch (cell->GetCellType())
{
default:
q = this->GetUnsupportedGeometry();
break;
// Below are supported types. Please be noted that not every quality is
// defined for all supported geometries. For those quality that is not
// defined with respective to a particular cell type,
// this->GetUndefinedQuality() is returned.
case VTK_TRIANGLE:
if (CellNormals)
CellNormals->GetTuple(cid, vtkCellQuality::CurrentTriNormal);
q = this->ComputeTriangleQuality(cell);
break;
case VTK_TRIANGLE_STRIP:
q = this->ComputeTriangleStripQuality(cell);
break;
case VTK_PIXEL:
q = this->ComputePixelQuality(cell);
break;
case VTK_QUAD:
q = this->ComputeQuadQuality(cell);
break;
case VTK_TETRA:
q = this->ComputeTetQuality(cell);
break;
case VTK_HEXAHEDRON:
q = this->ComputeHexQuality(cell);
break;
}
quality->SetValue(cid, q);
}
out->GetCellData()->AddArray(quality);
out->GetCellData()->SetActiveAttribute("CellQuality", vtkDataSetAttributes::SCALARS);
return 1;
}
double vtkCellQuality::ComputeTriangleQuality (vtkCell* cell)
{
switch (this->GetQualityMeasure())
{
case AREA: return vtkMeshQuality::TriangleArea(cell);
case ASPECT_FROBENIUS: return vtkMeshQuality::TriangleAspectFrobenius(cell);
case ASPECT_RATIO: return vtkMeshQuality::TriangleAspectRatio(cell);
case CONDITION: return vtkMeshQuality::TriangleCondition(cell);
case DISTORTION: return vtkMeshQuality::TriangleDistortion(cell);
case EDGE_RATIO: return vtkMeshQuality::TriangleEdgeRatio(cell);
case MAX_ANGLE: return vtkMeshQuality::TriangleMaxAngle(cell);
case MIN_ANGLE: return vtkMeshQuality::TriangleMinAngle(cell);
case RADIUS_RATIO: return vtkMeshQuality::TriangleRadiusRatio(cell);
case RELATIVE_SIZE_SQUARED:
return vtkMeshQuality::TriangleRelativeSizeSquared(cell);
case SCALED_JACOBIAN: return vtkMeshQuality::TriangleScaledJacobian(cell);
case SHAPE_AND_SIZE: return vtkMeshQuality::TriangleShapeAndSize(cell);
case SHAPE: return vtkMeshQuality::TriangleShape(cell);
default: return this->GetUndefinedQuality();
}
}
double vtkCellQuality::ComputeQuadQuality (vtkCell* cell)
{
switch (this->GetQualityMeasure())
{
case AREA: return vtkMeshQuality::QuadArea(cell);
case ASPECT_RATIO: return vtkMeshQuality::QuadAspectRatio(cell);
case CONDITION: return vtkMeshQuality::QuadCondition(cell);
case DISTORTION: return vtkMeshQuality::QuadDistortion(cell);
case EDGE_RATIO: return vtkMeshQuality::QuadEdgeRatio(cell);
case JACOBIAN: return vtkMeshQuality::QuadJacobian(cell);
case MAX_ANGLE: return vtkMeshQuality::QuadMaxAngle(cell);
case MAX_ASPECT_FROBENIUS:
return vtkMeshQuality::QuadMaxAspectFrobenius(cell);
case MAX_EDGE_RATIO: return vtkMeshQuality::QuadMaxEdgeRatios(cell);
case MED_ASPECT_FROBENIUS:
return vtkMeshQuality::QuadMedAspectFrobenius(cell);
case MIN_ANGLE: return vtkMeshQuality::QuadMinAngle(cell);
case ODDY: return vtkMeshQuality::QuadOddy(cell);
case RADIUS_RATIO: return vtkMeshQuality::QuadRadiusRatio(cell);
case RELATIVE_SIZE_SQUARED:
return vtkMeshQuality::QuadRelativeSizeSquared(cell);
case SCALED_JACOBIAN:return vtkMeshQuality::QuadScaledJacobian(cell);
case SHAPE_AND_SIZE: return vtkMeshQuality::QuadShapeAndSize(cell);
case SHAPE: return vtkMeshQuality::QuadShape(cell);
case SHEAR_AND_SIZE: return vtkMeshQuality::QuadShearAndSize(cell);
case SHEAR: return vtkMeshQuality::QuadShear(cell);
case SKEW: return vtkMeshQuality::QuadSkew(cell);
case STRETCH: return vtkMeshQuality::QuadStretch(cell);
case TAPER: return vtkMeshQuality::QuadTaper(cell);
case WARPAGE: return vtkMeshQuality::QuadWarpage(cell);
default: return this->GetUndefinedQuality();
}
}
double vtkCellQuality::ComputeTetQuality (vtkCell* cell)
{
switch (this->GetQualityMeasure())
{
case ASPECT_BETA: return vtkMeshQuality::TetAspectBeta(cell);
case ASPECT_FROBENIUS: return vtkMeshQuality::TetAspectFrobenius(cell);
case ASPECT_GAMMA: return vtkMeshQuality::TetAspectGamma(cell);
case ASPECT_RATIO: return vtkMeshQuality::TetAspectRatio(cell);
case COLLAPSE_RATIO: return vtkMeshQuality::TetCollapseRatio(cell);
case CONDITION: return vtkMeshQuality::TetCondition(cell);
case DISTORTION: return vtkMeshQuality::TetDistortion(cell);
case EDGE_RATIO: return vtkMeshQuality::TetEdgeRatio(cell);
case JACOBIAN: return vtkMeshQuality::TetJacobian(cell);
case MIN_ANGLE: return vtkMeshQuality::TetMinAngle(cell);
case RADIUS_RATIO: return vtkMeshQuality::TetRadiusRatio(cell);
case RELATIVE_SIZE_SQUARED:
return vtkMeshQuality::TetRelativeSizeSquared(cell);
case SCALED_JACOBIAN: return vtkMeshQuality::TetScaledJacobian(cell);
case SHAPE_AND_SIZE: return vtkMeshQuality::TetShapeandSize(cell);
case SHAPE: return vtkMeshQuality::TetShape(cell);
case VOLUME: return vtkMeshQuality::TetVolume(cell);
default: return this->GetUndefinedQuality();
}
}
double vtkCellQuality::ComputeHexQuality (vtkCell* cell)
{
switch (this->GetQualityMeasure())
{
case CONDITION: return vtkMeshQuality::HexCondition(cell);
case DIAGONAL: return vtkMeshQuality::HexDiagonal(cell);
case DIMENSION: return vtkMeshQuality::HexDimension(cell);
case DISTORTION: return vtkMeshQuality::HexDistortion(cell);
case EDGE_RATIO: return vtkMeshQuality::HexEdgeRatio(cell);
case JACOBIAN: return vtkMeshQuality::HexJacobian(cell);
case MAX_ASPECT_FROBENIUS:
return vtkMeshQuality::HexMaxAspectFrobenius(cell);
case MAX_EDGE_RATIO: return vtkMeshQuality::HexMaxEdgeRatio(cell);
case MED_ASPECT_FROBENIUS:
return vtkMeshQuality::HexMedAspectFrobenius(cell);
case ODDY: return vtkMeshQuality::HexOddy(cell);
case RELATIVE_SIZE_SQUARED:
return vtkMeshQuality::HexRelativeSizeSquared(cell);
case SCALED_JACOBIAN:return vtkMeshQuality::HexScaledJacobian(cell);
case SHAPE_AND_SIZE: return vtkMeshQuality::HexShapeAndSize(cell);
case SHAPE: return vtkMeshQuality::HexShape(cell);
case SHEAR_AND_SIZE: return vtkMeshQuality::HexShearAndSize(cell);
case SHEAR: return vtkMeshQuality::HexShear(cell);
case SKEW: return vtkMeshQuality::HexSkew(cell);
case STRETCH: return vtkMeshQuality::HexStretch(cell);
case TAPER: return vtkMeshQuality::HexTaper(cell);
case VOLUME: return vtkMeshQuality::HexVolume(cell);
default: return this->GetUndefinedQuality();
}
}
double vtkCellQuality::ComputeTriangleStripQuality (vtkCell* cell)
{
switch (this->GetQualityMeasure())
{
case AREA: return vtkCellQuality::TriangleStripArea(cell);
default: return this->GetUndefinedQuality();
}
}
double vtkCellQuality::ComputePixelQuality (vtkCell* cell)
{
switch (this->GetQualityMeasure())
{
case AREA: return vtkCellQuality::PixelArea(cell);
default: return this->GetUndefinedQuality();
}
}
int vtkCellQuality::GetCurrentTriangleNormal (double [3], double normal [3])
{
// copy the cell normal
normal[0] = vtkCellQuality::CurrentTriNormal[0];
normal[1] = vtkCellQuality::CurrentTriNormal[1];
normal[2] = vtkCellQuality::CurrentTriNormal[2];
return 1;
}
// Triangle strip quality metrics
double vtkCellQuality::TriangleStripArea (vtkCell* cell)
{
return this->PolygonArea(cell);
}
// Pixel quality metrics
double vtkCellQuality::PixelArea (vtkCell* cell)
{
return this->PolygonArea(cell);
}
// Polygon quality metrics
double vtkCellQuality::PolygonArea (vtkCell* cell)
{
cell->Triangulate(0, this->PointIds, this->Points);
double abc [3][3], quality = 0;
for (vtkIdType i = 0, n = this->Points->GetNumberOfPoints(); i < n; i += 3)
{
this->Points->GetPoint(i+0, abc[0]);
this->Points->GetPoint(i+1, abc[1]);
this->Points->GetPoint(i+2, abc[2]);
quality += vtkTriangle::TriangleArea(abc[0], abc[1], abc[2]);
}
return quality;
}
|