private Topologic.Wire ByPolylineCurve(PolylineCurve ghPolylineCurve) { int numPoints = ghPolylineCurve.PointCount; if (numPoints < 1) { return(null); } List <Topologic.Vertex> vertices = new List <Topologic.Vertex>(); List <int> indices = new List <int>(); for (int i = 0; i < numPoints; ++i) { Point3d ghPoint = ghPolylineCurve.Point(i); Topologic.Vertex vertex = ByPoint(ghPoint); vertices.Add(vertex); indices.Add(i); } if (ghPolylineCurve.IsClosed) { //vertices.Add(vertices[0]); //indices.Add(0); List <List <int> > listOfIndices = new List <List <int> >(); listOfIndices.Add(indices); return(Topologic.Topology.ByVerticesIndices(vertices, listOfIndices)[0].Wires[0]); } else { List <List <int> > listOfIndices = new List <List <int> >(); listOfIndices.Add(indices); return(Topologic.Topology.ByVerticesIndices(vertices, listOfIndices)[0] as Topologic.Wire); } }
//private void ProcessFace( // Wire wire, ref Brep ghBrep, BrepFace ghBrepFace, BrepLoopType ghBrepLoopType, Rhino.Geometry.Surface ghSurface, // Dictionary<Edge, Tuple<int, int>> edge2DIndices, Dictionary<Edge, BrepEdge> edgeIndices) //{ // List<Edge> edges = wire.Edges; // BrepLoop ghBrepLoop = ghBrep.Loops.Add(ghBrepLoopType, ghBrepFace); // // 2f.For each loop, add a trim(2D edge) // List<BrepEdge> ghEdges = new List<BrepEdge>(); // List<Tuple<Curve, int, Curve, int>> gh2DCurves = new List<Tuple<Curve, int, Curve, int>>(); // original curve, index, reverse curve, reverse index // foreach (Edge edge in edges) // { // Tuple<int, int> thisEdge2DIndices = edge2DIndices. // Where(edgeIndexPair => edgeIndexPair.Key.IsSame(edge)). // Select(edgeIndexPair => edgeIndexPair.Value). // FirstOrDefault(); // int thisEdge2DIndex = thisEdge2DIndices.Item1; // int thisReverseEdge2DIndex = thisEdge2DIndices.Item2; // Curve ghCurve2D = ghBrep.Curves2D[thisEdge2DIndex]; // Curve ghReverseCurve2D = ghBrep.Curves2D[thisReverseEdge2DIndex]; // gh2DCurves.Add(Tuple.Create(ghCurve2D, thisEdge2DIndex, ghReverseCurve2D, thisReverseEdge2DIndex)); // BrepEdge ghBrepEdge = edgeIndices. // Where(edgeIndexPair => edgeIndexPair.Key.IsSame(edge)). // Select(edgeIndexPair => edgeIndexPair.Value). // FirstOrDefault(); // String ghBrepEdgeLog = ""; // if (!ghBrepEdge.IsValidWithLog(out ghBrepEdgeLog)) // { // throw new Exception("Fails to create a valid Brep with the following message: " + ghBrepEdgeLog); // } // ghEdges.Add(ghBrepEdge); // } // for (int currentEntryID = 0; currentEntryID < gh2DCurves.Count; ++currentEntryID) // { // int previousEntryID = currentEntryID - 1; // if (previousEntryID < 0) // { // previousEntryID = edges.Count - 1; // } // bool isCurrentStartEqualToPreviousStart = gh2DCurves[currentEntryID].Item1.PointAtStart.DistanceTo( // gh2DCurves[previousEntryID].Item1.PointAtStart) < tolerance; // bool isCurrentStartEqualToPreviousEnd = gh2DCurves[currentEntryID].Item1.PointAtStart.DistanceTo( // gh2DCurves[previousEntryID].Item1.PointAtEnd) < tolerance; // bool isTrimReversed = false; // if (!isCurrentStartEqualToPreviousStart && !isCurrentStartEqualToPreviousEnd) // { // // Reverse trim // isTrimReversed = true; // } // BrepTrim ghBrepTrim = ghBrep.Trims.Add( // ghEdges[currentEntryID], // 3D edge // isTrimReversed, // is reversed? // ghBrepLoop, // 2D loop // isTrimReversed ? gh2DCurves[currentEntryID].Item4 : gh2DCurves[currentEntryID].Item2); // 2D curve index, use the reversed one if reversed // ghBrepTrim.IsoStatus = ghSurface.IsIsoparametric(gh2DCurves[currentEntryID].Item1); // ghBrepTrim.TrimType = BrepTrimType.Boundary; // ghBrepTrim.SetTolerances(0.0, 0.0); // String ghBrepTrimLog = ""; // if (!ghBrepTrim.IsValidWithLog(out ghBrepTrimLog)) // { // throw new Exception("Fails to create a valid BrepTrim with the following message: " + ghBrepTrimLog); // } // } // String brepLoopLog = ""; // if (!ghBrepLoop.IsValidWithLog(out brepLoopLog)) // { // throw new Exception("Fails to create a valid outer BrepLoop with the following message: " + brepLoopLog); // } //} private Rhino.Geometry.NurbsSurface ToRhinoNurbsSurface(Topologic.NurbsSurface nurbsSurface) { int uDegree = nurbsSurface.UDegree; int vDegree = nurbsSurface.VDegree; bool isRational = nurbsSurface.IsURational && nurbsSurface.IsVRational; int uCount = nurbsSurface.NumOfUControlVertices; int vCount = nurbsSurface.NumOfVControlVertices; Rhino.Geometry.NurbsSurface ghNurbsSurface = Rhino.Geometry.NurbsSurface.Create( 3, isRational, uDegree + 1, vDegree + 1, uCount, vCount ); int i = 0; for (int u = 0; u < uCount; ++u) { for (int v = 0; v < vCount; ++v) { Topologic.Vertex controlVertex = nurbsSurface.ControlVertex(u, v); ghNurbsSurface.Points.SetPoint(u, v, ToPoint(controlVertex)); ++i; } } List <double> uKnots = nurbsSurface.UKnots; uKnots = uKnots.GetRange(1, uKnots.Count - 2); for (int u = 0; u < uKnots.Count; u++) { ghNurbsSurface.KnotsU[u] = uKnots[u]; } List <double> vKnots = nurbsSurface.VKnots; vKnots = vKnots.GetRange(1, vKnots.Count - 2); for (int v = 0; v < vKnots.Count; v++) { ghNurbsSurface.KnotsV[v] = vKnots[v]; } if (!ghNurbsSurface.IsValid) { throw new Exception("A valid surface cannot be created from this Face."); } return(ghNurbsSurface); }
private Topologic.Edge ByLine(Rhino.Geometry.Line ghLine) { Topologic.Vertex vertex1 = ByPoint(ghLine.From); Topologic.Vertex vertex2 = ByPoint(ghLine.To); return(Topologic.Edge.ByStartVertexEndVertex(vertex1, vertex2)); }