//----------------------------------CONSTRUCTOR---------------------------------// /** * Constructs a Object3d object based on a solid file. * * @param solid solid used to construct the Object3d object */ public Object3D(Solid solid) { Vertex v1, v2, v3, vertex; Point3d[] verticesPoints = solid.getVertices(); int[] indices = solid.getIndices(); Color3f[] colors = solid.getColors(); var verticesTemp = new List <Vertex>(); Dictionary <int, int> revlookup = new Dictionary <int, int> (); for (int d = 0; d < indices.Length; d++) { revlookup [indices [d]] = d; } //create vertices vertices = new List <Vertex>(); for (int i = 0; i < verticesPoints.Length; i++) { Color3f col = new Color3f(1, 1, 1); if (colors.Length > 0) { col = colors[i]; } vertex = addVertex(verticesPoints[i], col, Vertex.UNKNOWN); verticesTemp.Add(vertex); } //create faces faces = new List <Face>(); for (int i = 0; i < indices.Length; i = i + 3) { v1 = verticesTemp[indices[i]]; v2 = verticesTemp[indices[i + 1]]; v3 = verticesTemp[indices[i + 2]]; addFace(v1, v2, v3); } //create bound bound = new Bound(verticesPoints); }
/// <summary> /// Constructs a Object3d object based on a solid file. /// </summary> /// <param name="solid">solid used to construct the Object3d object</param> public Object3D(Solid solid) { var verticesPoints = CollectionPool <Vector3Double> .ListCell.Create(); solid.GetVertices(verticesPoints); var indices = CollectionPool <int> .ListCell.Create(); solid.GetTriangles(indices); using (var vsCache = CollectionPool <Vertex> .ListCell.Create()) { //create vertices m_vertices = CollectionPool <Vertex> .ListCell.Create(); for (int i = 0; i < verticesPoints.Count; i++) { var vertex = AddVertex(verticesPoints[i], Status.UNKNOWN); vsCache.Add(vertex); } //create faces m_faces = CollectionPool <Face> .ListCell.Create(); for (int i = 0; i < indices.Count; i += 3) { var v1 = vsCache[indices[i]]; var v2 = vsCache[indices[i + 1]]; var v3 = vsCache[indices[i + 2]]; AddFace(v1, v2, v3); } } //create bound m_bound = new Bound(verticesPoints); indices.Dispose(); verticesPoints.Dispose(); }
//--------------------------------------OTHERS----------------------------------// /** * Checks if a bound overlaps other one * * @param bound other bound to make the comparison * @return true if they insersect, false otherwise */ public bool overlap(Bound bound) { if ((xMin > bound.xMax + TOL) || (xMax < bound.xMin - TOL) || (yMin > bound.yMax + TOL) || (yMax < bound.yMin - TOL) || (zMin > bound.zMax + TOL) || (zMax < bound.zMin - TOL)) { return false; } else { return true; } }
//--------------------------------------OTHERS----------------------------------// /// <summary> /// 判断包围盒是否重叠 /// </summary> /// <param name="bound"></param> /// <returns></returns> public bool Overlap(Bound bound) { return(!((xMin > bound.xMax + EqualityTolerance) || (xMax < bound.xMin - EqualityTolerance) || (yMin > bound.yMax + EqualityTolerance) || (yMax < bound.yMin - EqualityTolerance) || (zMin > bound.zMax + EqualityTolerance) || (zMax < bound.zMin - EqualityTolerance))); }
//----------------------------------CONSTRUCTOR---------------------------------// /** * Constructs a Object3d object based on a solid file. * * @param solid solid used to construct the Object3d object */ public Object3D(Solid solid) { Vertex v1, v2, v3, vertex; Point3d[] verticesPoints = solid.getVertices(); int[] indices = solid.getIndices(); Color3f[] colors = solid.getColors(); var verticesTemp = new List<Vertex>(); Dictionary<int,int> revlookup = new Dictionary<int, int> (); for (int d=0; d<indices.Length; d++) revlookup [indices [d]] = d; //create vertices vertices = new List<Vertex>(); for (int i = 0; i < verticesPoints.Length; i++) { Color3f col = new Color3f(1, 1, 1); if(colors.Length > 0) col = colors[i]; vertex = addVertex(verticesPoints[i], col, Vertex.UNKNOWN); verticesTemp.Add(vertex); } //create faces faces = new List<Face>(); for (int i = 0; i < indices.Length; i = i + 3) { v1 = verticesTemp[indices[i]]; v2 = verticesTemp[indices[i + 1]]; v3 = verticesTemp[indices[i + 2]]; addFace(v1, v2, v3); } //create bound bound = new Bound(verticesPoints); }