public bool ClosestPoint( int[] objectIndexArray, int firstIndex, int indexCount, V3d query, Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter, Func <IIntersectableObjectSet, int, int, ObjectClosestPoint, bool> ios_index_part_ocp_pointFilter, ref ObjectClosestPoint closest) { int kdTreeIndex = -1; for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++) { int index = objectIndexArray[i]; var x = ConcreteKdTreeList[index]; var trafo = x.Trafo; if (x.KdIntersectionTree.ClosestPoint(trafo.Backward.TransformPos(query), ref closest)) { kdTreeIndex = index; closest.Point = trafo.Forward.TransformPos(closest.Point); } } if (kdTreeIndex < 0) { return(false); } if (closest.ObjectStack == null) { closest.ObjectStack = new List <SetObject>(); } closest.ObjectStack.Add(new SetObject(this, kdTreeIndex)); return(true); }
public bool ClosestPoint( int[] objectIndexArray, int firstIndex, int indexCount, V3d queryPoint, Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter, Func <IIntersectableObjectSet, int, int, ObjectClosestPoint, bool> ios_index_part_ocp_pointFilter, ref ObjectClosestPoint closestPoint) { return(false); }
public bool ClosestPoint(int[] objectIndexArray, int firstIndex, int indexCount, V3d queryPoint, Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter, Func <IIntersectableObjectSet, int, int, ObjectClosestPoint, bool> ios_index_part_ocp_pointFilter, ref ObjectClosestPoint closestPoint) { var minDist2 = closestPoint.DistanceSquared; var minIndex = -1; var minPos = V3d.NaN; for (int i = 0; i < indexCount; i++) { var id = objectIndexArray[firstIndex + i]; if (ios_index_objectFilter(this, id)) { GetTriangle(id, out V3d p0, out V3d p1, out V3d p2); var p = queryPoint.GetClosestPointOnTriangle(p0, p1, p2); var d = V3d.DistanceSquared(p, queryPoint); if (d < minDist2) { d = minDist2; minIndex = id; minPos = p; } } } if (minIndex >= 0) { closestPoint = new ObjectClosestPoint() { Distance = Fun.Sqrt(minDist2), DistanceSquared = minDist2, Point = minPos, SetObject = new SetObject(this, minIndex), ObjectStack = new List <SetObject>(), // TODO Coord = V2d.Zero // TODO }; return(true); } else { return(false); } }
/// <summary> /// /// </summary> /// <param name="objectIndexArray"></param> /// <param name="firstIndex"></param> /// <param name="indexCount"></param> /// <param name="query"></param> /// <param name="ios_index_objectFilter">not implemented</param> /// <param name="ios_index_part_ocp_pointFilter">not implemented</param> /// <param name="closest"></param> /// <returns></returns> public bool ClosestPoint( int[] objectIndexArray, int firstIndex, int indexCount, V3d query, Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter, Func <IIntersectableObjectSet, int, int, ObjectClosestPoint, bool> ios_index_part_ocp_pointFilter, ref ObjectClosestPoint closest) { bool result = false; for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++) { int index = objectIndexArray[i]; V3d p = query.GetClosestPointOn(Sphere3ds[index]); double d2 = V3d.DistanceSquared(query, p); if (d2 < closest.DistanceSquared) { result = closest.Set(d2, p, this, index); } } return(result); }
public bool ClosestPoint( int[] objectIndexArray, int firstIndex, int indexCount, V3d queryPoint, Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter, Func <IIntersectableObjectSet, int, int, ObjectClosestPoint, bool> ios_index_part_ocp_pointFilter, ref ObjectClosestPoint closestPoint) { bool result = false; var pa = m_positionArray; for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++) { int li = objectIndexArray[i]; V3d p = queryPoint.GetClosestPointOnLine(pa[li], pa[li + 1]); double d2 = V3d.DistanceSquared(queryPoint, p); if (d2 < closestPoint.DistanceSquared) { result = closestPoint.Set(d2, p, this, li); } } return(result); }
public bool ClosestPoint( int[] objectIndexArray, int firstIndex, int indexCount, V3d query, Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter, Func <IIntersectableObjectSet, int, int, ObjectClosestPoint, bool> ios_index_part_ocp_pointFilter, ref ObjectClosestPoint closest) { var plist = Position3dList; bool result = false; for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++) { int index = objectIndexArray[i]; int pi = index * 3; V3d p = query.GetClosestPointOnTriangle( plist[pi], plist[pi + 1], plist[pi + 2]); double d2 = V3d.DistanceSquared(query, p); if (d2 < closest.DistanceSquared) { result = closest.Set(d2, p, this, index); } } return(result); }
public bool ClosestPoint( int[] objectIndexArray, int firstIndex, int indexCount, V3d queryPoint, Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter, Func <IIntersectableObjectSet, int, int, ObjectClosestPoint, bool> ios_index_part_ocp_pointFilter, ref ObjectClosestPoint closestPoint) { bool result = false; int[] fia = FirstIndexArray, via = VertexIndexArray; var pa = PositionArray; for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++) { int oi = objectIndexArray[i]; if (ios_index_objectFilter != null && !ios_index_objectFilter(this, oi)) { continue; } int fvi = fia[oi], fve = fia[oi + 1]; V3d p0 = pa[via[fvi++]], p1 = pa[via[fvi++]]; while (fvi < fve) { var p2 = pa[via[fvi++]]; V3d p = queryPoint.GetClosestPointOnTriangle(p0, p1, p2); double d2 = V3d.DistanceSquared(queryPoint, p); if (d2 < closestPoint.DistanceSquared) { result = closestPoint.Set(d2, p, this, oi); } p1 = p2; } } return(result); }