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
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkHyperTreeGridGeometry1DImpl.h"
#include "vtkCellArray.h"
#include "vtkDataSetAttributes.h"
#include "vtkHyperTreeGrid.h"
#include "vtkHyperTreeGridNonOrientedGeometryCursor.h"
#include "vtkPoints.h"
#include "vtkUnsignedCharArray.h"
VTK_ABI_NAMESPACE_BEGIN
//------------------------------------------------------------------------------
vtkHyperTreeGridGeometry1DImpl::vtkHyperTreeGridGeometry1DImpl(vtkHyperTreeGrid* input,
vtkPoints* outPoints, vtkCellArray* outCells, vtkDataSetAttributes* inCellDataAttributes,
vtkDataSetAttributes* outCellDataAttributes, bool passThroughCellIds,
const std::string& originalCellIdArrayName, bool fillMaterial)
: vtkHyperTreeGridGeometrySmallDimensionsImpl(input, outPoints, outCells, inCellDataAttributes,
outCellDataAttributes, passThroughCellIds, originalCellIdArrayName, fillMaterial)
{
// The orientation value indicates the axis on which the HTG 1D is oriented.
this->Axis = this->Input->GetOrientation();
// Cell size : 2 in 1D (segment)
this->CellPoints->SetNumberOfPoints(2);
}
//----------------------------------------------------------------------------------------------
void vtkHyperTreeGridGeometry1DImpl::ProcessLeafCellWithOneInterface(
vtkHyperTreeGridNonOrientedGeometryCursor* cursor, double sign,
const std::vector<double>& distancesToInterface)
{
// Create storage for endpoint IDs
std::vector<vtkIdType> outputIndexPoints;
double xyzCrt[3];
this->CellPoints->GetPoint(0, xyzCrt);
double valCrt = distancesToInterface[0];
double xyzNext[3];
this->CellPoints->GetPoint(1, xyzNext);
double valNext = distancesToInterface[1];
// Retrieve vertex coordinates
if (sign * valCrt >= 0.)
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(xyzCrt));
}
if (valCrt * valNext < 0)
{
double nxyz[3];
memcpy(nxyz, xyzCrt, 3 * sizeof(double));
unsigned int iDim = this->Axis;
nxyz[iDim] = (valNext * xyzCrt[iDim] - valCrt * xyzNext[iDim]) / (valNext - valCrt);
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(nxyz));
}
if (sign * valNext >= 0.)
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(xyzNext));
}
this->CreateNewCellAndCopyData(outputIndexPoints, cursor->GetGlobalNodeIndex());
}
//----------------------------------------------------------------------------------------------
void vtkHyperTreeGridGeometry1DImpl::ProcessLeafCellWithDoubleInterface(
vtkHyperTreeGridNonOrientedGeometryCursor* cursor,
const std::vector<double>& distancesToInterfaceA,
const std::vector<double>& distancesToInterfaceB)
{
// Create storage for endpoint IDs
std::vector<vtkIdType> outputIndexPoints;
double xyzCrt[3];
this->CellPoints->GetPoint(0, xyzCrt);
double valCrtA = distancesToInterfaceA[0];
double valCrtB = distancesToInterfaceB[0];
double xyzNext[3];
this->CellPoints->GetPoint(1, xyzNext);
double valNextA = distancesToInterfaceA[1];
double valNextB = distancesToInterfaceB[1];
// Retrieve vertex coordinates
if (valCrtA >= 0 && valCrtB <= 0)
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(xyzCrt));
}
bool inversionA = false;
double nxyzA[3];
if (valCrtA * valNextA < 0)
{
memcpy(nxyzA, xyzCrt, 3 * sizeof(double));
unsigned int iDim = this->Axis;
nxyzA[iDim] = (valNextA * xyzCrt[iDim] - valCrtA * xyzNext[iDim]) / (valNextA - valCrtA);
inversionA = true;
}
bool inversionB = false;
double nxyzB[3];
if (valCrtB * valNextB < 0)
{
memcpy(nxyzB, xyzCrt, 3 * sizeof(double));
unsigned int iDim = this->Axis;
nxyzB[iDim] = (valNextB * xyzCrt[iDim] - valCrtB * xyzNext[iDim]) / (valNextB - valCrtB);
inversionB = true;
}
if (inversionA)
{
if (inversionB)
{
if (nxyzA[this->Axis] > nxyzB[this->Axis])
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(nxyzB));
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(nxyzA));
}
else if (nxyzA[this->Axis] == nxyzB[this->Axis])
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(nxyzA));
}
else if (nxyzA[this->Axis] < nxyzB[this->Axis])
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(nxyzA));
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(nxyzB));
}
}
else
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(nxyzA));
}
}
else if (inversionB)
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(nxyzB));
}
if (valNextA >= 0 && valNextB <= 0)
{
outputIndexPoints.emplace_back(this->OutPoints->InsertNextPoint(xyzNext));
}
this->CreateNewCellAndCopyData(outputIndexPoints, cursor->GetGlobalNodeIndex());
}
//----------------------------------------------------------------------------------------------
void vtkHyperTreeGridGeometry1DImpl::BuildCellPoints(
vtkHyperTreeGridNonOrientedGeometryCursor* cursor)
{
// Case of a cell whose interface is not defined, we copy the entire surface
// First endpoint is at origin of cursor
double* cellOrigin = cursor->GetOrigin();
this->CellPoints->SetPoint(0, cellOrigin);
// Second endpoint is at origin of cursor plus its length
double* cellSize = cursor->GetSize();
double cellEnd[3];
memcpy(cellEnd, cellOrigin, 3 * sizeof(double));
cellEnd[this->Axis] += cellSize[this->Axis];
this->CellPoints->SetPoint(1, cellEnd);
}
VTK_ABI_NAMESPACE_END
|