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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkQuadraticEdge.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 "vtkQuadraticEdge.h"
#include "vtkObjectFactory.h"
#include "vtkMath.h"
#include "vtkLine.h"
#include "vtkDoubleArray.h"
#include "vtkPoints.h"
vtkStandardNewMacro(vtkQuadraticEdge);
//----------------------------------------------------------------------------
// Construct the line with two points.
vtkQuadraticEdge::vtkQuadraticEdge()
{
this->Scalars = vtkDoubleArray::New();
this->Scalars->SetNumberOfTuples(2);
this->Points->SetNumberOfPoints(3);
this->PointIds->SetNumberOfIds(3);
for (int i = 0; i < 3; i++)
{
this->Points->SetPoint(i, 0.0, 0.0, 0.0);
this->PointIds->SetId(i,0);
}
this->Line = vtkLine::New();
}
//----------------------------------------------------------------------------
vtkQuadraticEdge::~vtkQuadraticEdge()
{
this->Line->Delete();
this->Scalars->Delete();
}
//----------------------------------------------------------------------------
int vtkQuadraticEdge::EvaluatePosition(double* x, double* closestPoint,
int& subId, double pcoords[3],
double& minDist2, double *weights)
{
double closest[3];
double pc[3], dist2;
int ignoreId, i, returnStatus, status;
double lineWeights[2];
pcoords[1] = pcoords[2] = 0.0;
returnStatus = -1;
weights[0] = 0.0;
for (minDist2=VTK_DOUBLE_MAX,i=0; i < 2; i++)
{
if ( i == 0)
{
this->Line->Points->SetPoint(0,this->Points->GetPoint(0));
this->Line->Points->SetPoint(1,this->Points->GetPoint(2));
}
else
{
this->Line->Points->SetPoint(0,this->Points->GetPoint(2));
this->Line->Points->SetPoint(1,this->Points->GetPoint(1));
}
status = this->Line->EvaluatePosition(x,closest,ignoreId,pc,
dist2,lineWeights);
if ( status != -1 && dist2 < minDist2 )
{
returnStatus = status;
minDist2 = dist2;
subId = i;
pcoords[0] = pc[0];
}
}
// adjust parametric coordinate
if ( returnStatus != -1 )
{
if ( subId == 0 ) //first part
{
pcoords[0] = pcoords[0]/2.0;
}
else
{
pcoords[0] = 0.5 + pcoords[0]/2.0;
}
if(closestPoint!=0)
{
// Compute both closestPoint and weights
this->EvaluateLocation(subId,pcoords,closestPoint,weights);
}
else
{
// Compute weights only
this->InterpolationFunctions(pcoords,weights);
}
}
return returnStatus;
}
//----------------------------------------------------------------------------
void vtkQuadraticEdge::EvaluateLocation(int& vtkNotUsed(subId),
double pcoords[3],
double x[3], double *weights)
{
int i;
double a0[3], a1[3], a2[3];
this->Points->GetPoint(0, a0);
this->Points->GetPoint(1, a1);
this->Points->GetPoint(2, a2); //midside node
this->InterpolationFunctions(pcoords,weights);
for (i=0; i<3; i++)
{
x[i] = a0[i]*weights[0] + a1[i]*weights[1] + a2[i]*weights[2];
}
}
//----------------------------------------------------------------------------
int vtkQuadraticEdge::CellBoundary(int subId, double pcoords[3],
vtkIdList *pts)
{
return this->Line->CellBoundary(subId, pcoords, pts);
}
//----------------------------------------------------------------------------
static int LinearLines[2][2] = { {0,2}, {2,1} };
void vtkQuadraticEdge::Contour(double value, vtkDataArray *cellScalars,
vtkIncrementalPointLocator *locator, vtkCellArray *verts,
vtkCellArray *lines, vtkCellArray *polys,
vtkPointData *inPd, vtkPointData *outPd,
vtkCellData *inCd, vtkIdType cellId,
vtkCellData *outCd)
{
for (int i=0; i < 2; i++) //for each subdivided line
{
for ( int j=0; j<2; j++) //for each of the four vertices of the line
{
this->Line->Points->SetPoint(j,this->Points->GetPoint(LinearLines[i][j]));
this->Line->PointIds->SetId(j,this->PointIds->GetId(LinearLines[i][j]));
this->Scalars->SetValue(j,cellScalars->GetTuple1(LinearLines[i][j]));
}
this->Line->Contour(value, this->Scalars, locator, verts,
lines, polys, inPd, outPd, inCd, cellId, outCd);
}
}
//----------------------------------------------------------------------------
// Line-line intersection. Intersection has to occur within [0,1] parametric
// coordinates and with specified tolerance.
// The following arguments were modified to avoid warnings:
// double p1[3], double p2[3], double x[3], double pcoords[3],
int vtkQuadraticEdge::IntersectWithLine(double p1[3], double p2[3],
double tol, double& t,
double x[3], double pcoords[3],
int& subId)
{
int subTest, numLines=2;
for (subId=0; subId < numLines; subId++)
{
if ( subId == 0)
{
this->Line->Points->SetPoint(0,this->Points->GetPoint(0));
this->Line->Points->SetPoint(1,this->Points->GetPoint(2));
}
else
{
this->Line->Points->SetPoint(0,this->Points->GetPoint(2));
this->Line->Points->SetPoint(1,this->Points->GetPoint(1));
}
if ( this->Line->IntersectWithLine(p1, p2, tol, t, x, pcoords, subTest) )
{
return 1;
}
}
return 0;
}
//----------------------------------------------------------------------------
int vtkQuadraticEdge::Triangulate(int vtkNotUsed(index), vtkIdList *ptIds,
vtkPoints *pts)
{
pts->Reset();
ptIds->Reset();
// The first line
ptIds->InsertId(0,this->PointIds->GetId(0));
pts->InsertPoint(0,this->Points->GetPoint(0));
ptIds->InsertId(1,this->PointIds->GetId(2));
pts->InsertPoint(1,this->Points->GetPoint(2));
// The second line
ptIds->InsertId(2,this->PointIds->GetId(2));
pts->InsertPoint(2,this->Points->GetPoint(2));
ptIds->InsertId(3,this->PointIds->GetId(1));
pts->InsertPoint(3,this->Points->GetPoint(1));
return 1;
}
//----------------------------------------------------------------------------
void vtkQuadraticEdge::Derivatives(int vtkNotUsed(subId),
double vtkNotUsed(pcoords)[3],
double *vtkNotUsed(values),
int vtkNotUsed(dim),
double *vtkNotUsed(derivs))
{
// TODO - if the effort is justified, someone should implement a correct
// version of this method
vtkErrorMacro( "Derivatives() is not implemented for this cell.");
}
//----------------------------------------------------------------------------
// Clip this quadratic edge using scalar value provided. Like contouring,
// except that it cuts the edge to produce linear line segments.
void vtkQuadraticEdge::Clip(double value, vtkDataArray *cellScalars,
vtkIncrementalPointLocator *locator, vtkCellArray *lines,
vtkPointData *inPd, vtkPointData *outPd,
vtkCellData *inCd, vtkIdType cellId,
vtkCellData *outCd, int insideOut)
{
for (int i=0; i < 2; i++) //for each subdivided line
{
for ( int j=0; j<2; j++) //for each of the four vertices of the line
{
this->Line->Points->SetPoint(j,this->Points->GetPoint(LinearLines[i][j]));
this->Line->PointIds->SetId(j,this->PointIds->GetId(LinearLines[i][j]));
this->Scalars->SetValue(j,cellScalars->GetTuple1(LinearLines[i][j]));
}
this->Line->Clip(value, this->Scalars, locator, lines, inPd, outPd,
inCd, cellId, outCd, insideOut);
}
}
//----------------------------------------------------------------------------
// Compute interpolation functions. Node [2] is the mid-edge node.
void vtkQuadraticEdge::InterpolationFunctions(double pcoords[3],
double weights[3])
{
double r = pcoords[0];
weights[0] = 2.0 * (r - 0.5) * (r - 1.0);
weights[1] = 2.0 * r * (r - 0.5);
weights[2] = 4.0 * r * (1.0 - r);
}
//----------------------------------------------------------------------------
// Derivatives in parametric space.
void vtkQuadraticEdge::InterpolationDerivs(double pcoords[3], double derivs[3])
{
double r = pcoords[0];
derivs[0] = 4.0 * r - 3.0;
derivs[1] = 4.0 * r - 1.0;
derivs[2] = 4.0 - r * 8.0;
}
//----------------------------------------------------------------------------
static double vtkQEdgeCellPCoords[9] = {0.0,0.0,0.0, 1.0,0.0,0.0, 0.5,0.0,0.0};
double *vtkQuadraticEdge::GetParametricCoords()
{
return vtkQEdgeCellPCoords;
}
//----------------------------------------------------------------------------
void vtkQuadraticEdge::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Line:\n";
this->Line->PrintSelf(os,indent.GetNextIndent());
}
|