MCPcopy Create free account
hub / github.com/Kitware/VTK / IntersectWithLine

Method IntersectWithLine

Common/DataModel/vtkHyperTreeGridGeometricLocator.cxx:184–303  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

182
183//------------------------------------------------------------------------------
184int vtkHyperTreeGridGeometricLocator::IntersectWithLine(const double p0[3], const double p1[3],
185 double tol, double& t, double x[3], double pcoords[3], int& subId, vtkIdType& cellId,
186 vtkGenericCell* cell)
187{
188 // initialize outputs
189 cellId = -1;
190 t = -1.0;
191 subId = 0;
192 std::fill(x, x + 3, 0.0);
193 std::fill(pcoords, pcoords + 3, 0.0);
194
195 // setup calculation
196 unsigned int dim = this->HTG->GetDimension();
197 std::vector<double> sizes(dim, 0.0);
198 std::vector<double> origin(dim, 0.0);
199 this->GetZeroLevelOriginAndSize(origin.data(), sizes.data());
200
201 // find intersection point with entire grid
202 bool p0InCell = true;
203 for (unsigned int d = 0; d < dim; d++)
204 {
205 p0InCell &= ((p0[d] - origin[d]) < (sizes[d] + tol));
206 }
207
208 if (!p0InCell)
209 {
210 if (!this->ConstructCell(origin.data(), sizes.data(), cell))
211 {
212 vtkErrorMacro("Could not construct cell");
213 return -1;
214 }
215 // line does not intersect grid at all
216 if (cell->IntersectWithLine(p0, p1, tol, t, x, pcoords, subId) == 0)
217 {
218 return 0;
219 }
220 // run FindCell on the intersection point + epsilon so we're sure we're in the cell
221 std::vector<double> tangent(3, 0.0);
222 vtkMath::Subtract(p1, p0, tangent.data());
223 vtkMath::Normalize(tangent.data());
224 double epsilon = 0.01 *
225 (vtkMath::Norm(sizes.data()) /
226 std::pow(this->HTG->GetBranchFactor(), this->HTG->GetNumberOfLevels()));
227 epsilon = std::max(epsilon, tol * 2.0);
228 vtkMath::MultiplyScalar(tangent.data(), epsilon);
229 vtkMath::Add(x, tangent.data(), x);
230 }
231 else
232 {
233 std::copy(p0, p0 + dim, x);
234 }
235 {
236 std::vector<double> locWeights(std::pow(2, dim), 0.0);
237 std::vector<double> locPCoords(3, 0.0);
238 // potential speed-up here by automatically looking for the cell but also could be loss
239 cellId = this->FindCell(x, tol, cell, subId, locPCoords.data(), locWeights.data());
240 }
241 if (cellId >= 0)

Calls 15

ConstructCellMethod · 0.95
FindCellMethod · 0.95
GetSortingMapMethod · 0.95
SetNumberOfIdsMethod · 0.80
NormalizeFunction · 0.70
NormFunction · 0.70
fillFunction · 0.50
SubtractFunction · 0.50

Tested by

no test coverage detected