public Polygon MakePolygon(List <int> pointIndices) { Polygon polygon = MakePolygon(); /* Sanity check */ for (int i = 0; i < pointIndices.Count; ++i) { for (int j = 0; j < pointIndices.Count; ++j) { if (i == j) { continue; } if (pointIndices[i] == pointIndices[j]) { throw new System.Exception("duplicate polygon corner point indices"); } } } foreach (int pointIndex in pointIndices) { Point point = Points[pointIndex]; polygon.MakeCorner(point); } #if DEBUG_CHECK var pointLocations = PointAttributes.Find <Vector3>("point_locations"); if (polygon.DebugCheck(pointLocations) == false) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = pointIndices.Length - 1; i >= 0; --i) { sb.Append(pointIndices[i].ToString()); if (i > 0) { sb.Append(", "); } } Logger.Log(sb.ToString() + ");"); } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < pointIndices.Length; i++) { sb.Append(pointIndices[i].ToString()); if (i < pointIndices.Length - 1) { sb.Append(", "); } } Logger.Log(sb.ToString() + ");"); } #endif return(polygon); }
/// Compute polygon centroids based on point position attributes /// Results are stored in internally stored attribute map named "polygon_centroids". public void ComputePolygonCentroids() { var polygonCentroids = PolygonAttributes.FindOrCreate <Vector3>("polygon_centroids"); var pointLocations = PointAttributes.Find <Vector3>("point_locations"); polygonCentroids.Clear(); foreach (Polygon polygon in Polygons) { polygon.ComputeCentroid(polygonCentroids, pointLocations); } }
/// Compute polygon normals based on point position attributes. /// Results are stored in internally stored attribute map named "polygon_normals". public void ComputePolygonNormals() { var polygonNormals = PolygonAttributes.FindOrCreate <Vector3>("polygon_normals"); var pointLocations = PointAttributes.Find <Vector3>("point_locations"); polygonNormals.Clear(); foreach (Polygon polygon in Polygons) { polygon.ComputeNormal(polygonNormals, pointLocations); } }
public Corner ClosestPolygonCorner(Polygon polygon, Vector3 position) { Corner closestCorner = null; float closestDistanceSquared = float.MaxValue; var pointLocations = PointAttributes.Find <Vector3>("point_locations"); foreach (Corner corner in polygon.Corners) { Vector3 cornerLocation = pointLocations[corner.Point]; float distanceSquared = cornerLocation.DistanceSquared(position); if (distanceSquared < closestDistanceSquared) { closestDistanceSquared = distanceSquared; closestCorner = corner; } } return(closestCorner); }
/// \brief Construct a new Polygon from a given set of Point indices /// \param pointIndices Indices to Points that are connected to the new Polygon</param> /// \return Newly created Polygon public Polygon MakePolygon(params int[] pointIndices) { Polygon polygon = MakePolygon(); foreach (int pointIndex in pointIndices) { Point point = Points[pointIndex]; polygon.MakeCorner(point); } #if DEBUG_CHECK var pointLocations = PointAttributes.Find <Vector3>("point_locations"); if (polygon.DebugCheck(pointLocations) == false) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = pointIndices.Length - 1; i >= 0; --i) { sb.Append(pointIndices[i].ToString()); if (i > 0) { sb.Append(", "); } } Logger.Log(sb.ToString() + ");"); } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < pointIndices.Length; i++) { sb.Append(pointIndices[i].ToString()); if (i < pointIndices.Length - 1) { sb.Append(", "); } } Logger.Log(sb.ToString() + ");"); } #endif return(polygon); }
public void SmoothAverage( string cornerAttribute, string pointNormalName ) { var cornerAttributes = CornerAttributes.FindOrCreate <Vector4>(cornerAttribute); var cornerNormals = CornerAttributes.FindOrCreate <Vector3>("corner_normals"); var pointNormals = PointAttributes.Find <Vector3>(pointNormalName); var newCornerAttributes = CornerAttributes.FindOrCreate <Vector4>("temp"); foreach (Polygon polygon in Polygons) { polygon.SmoothAverage( newCornerAttributes, cornerAttributes, cornerNormals, pointNormals ); } CornerAttributes.Replace(cornerAttribute, "temp"); }