| 99 | } |
| 100 | |
| 101 | int vtkDataSetGradientPrecompute::GradientPrecompute(vtkDataSet* ds, vtkDataSetAlgorithm* self) |
| 102 | { |
| 103 | vtkIdType nCells = ds->GetNumberOfCells(); |
| 104 | vtkIdType nCellNodes = 0; |
| 105 | for (vtkIdType i = 0; i < nCells; i++) |
| 106 | { |
| 107 | nCellNodes += ds->GetCell(i)->GetNumberOfPoints(); |
| 108 | } |
| 109 | |
| 110 | vtkDoubleArray* cqs = vtkDoubleArray::New(); |
| 111 | cqs->SetName("GradientPrecomputation"); |
| 112 | cqs->SetNumberOfComponents(3); |
| 113 | cqs->SetNumberOfTuples(nCellNodes); |
| 114 | cqs->FillComponent(0, 0.0); |
| 115 | cqs->FillComponent(1, 0.0); |
| 116 | cqs->FillComponent(2, 0.0); |
| 117 | |
| 118 | // The cell size determines the amount of space the cell takes up. For 3D |
| 119 | // cells this is the volume. For 2D cells this is the area. For 1D cells |
| 120 | // this is the length. For 0D cells this is undefined, but we set it to 1 so |
| 121 | // as not to get invalid results when normalizing something by the cell size. |
| 122 | vtkDoubleArray* cellSize = vtkDoubleArray::New(); |
| 123 | cellSize->SetName("CellSize"); |
| 124 | cellSize->SetNumberOfTuples(nCells); |
| 125 | |
| 126 | vtkIdType curPoint = 0; |
| 127 | for (vtkIdType c = 0; c < nCells; c++) |
| 128 | { |
| 129 | if (self && self->CheckAbort()) |
| 130 | { |
| 131 | break; |
| 132 | } |
| 133 | vtkCell* cell = ds->GetCell(c); |
| 134 | int np = cell->GetNumberOfPoints(); |
| 135 | |
| 136 | double cellCenter[3] = { 0, 0, 0 }; |
| 137 | double cellPoints[MAX_CELL_POINTS][3]; |
| 138 | double cellVectors[MAX_CELL_POINTS][3]; |
| 139 | double tmp[3]; |
| 140 | double size = 0.0; |
| 141 | |
| 142 | for (int p = 0; p < np; p++) |
| 143 | { |
| 144 | ds->GetPoint(cell->GetPointId(p), cellPoints[p]); |
| 145 | ADD_VEC(cellCenter, cellPoints[p]); |
| 146 | ZERO_VEC(cellVectors[p]); |
| 147 | } |
| 148 | SCALE_VEC(cellCenter, 1.0 / np); |
| 149 | |
| 150 | // -= 3 D =- |
| 151 | if (cell->GetCellDimension() == 3) |
| 152 | { |
| 153 | #ifdef VTK_DATASET_GRADIENT_TETRA_OPTIMIZATION |
| 154 | if (np == 4) // cell is a tetrahedra |
| 155 | { |
| 156 | // vtkWarningMacro(<<"Tetra detected\n"); |
| 157 | size = fabs(vtkTetra::ComputeVolume( |
| 158 | cellPoints[0], cellPoints[1], cellPoints[2], cellPoints[3])) * |
nothing calls this directly
no test coverage detected