コード例 #1
0
ファイル: TopoVertex.cs プロジェクト: JackTing/Repetier-Host
 public void LaplaceRelaxation(TopoModel model)
 {
     double n = 2;
     RHVector3 newPos = new RHVector3(pos);
     newPos.AddInternal(pos);
     foreach (TopoTriangle t in connectedFacesList)
     {
         int idx = t.VertexIndexFor(this);
         n += 2;
         newPos.AddInternal(t.vertices[(idx + 1) % 3].pos);
         newPos.AddInternal(t.vertices[(idx + 2) % 3].pos);
     }
     newPos.Scale(1.0 / n);
     // validate newPos does not create intersecting triangles or bad shapes
     foreach (TopoTriangle t in connectedFacesList)
     {
         int idx = t.VertexIndexFor(this);
         RHVector3 d1 = t.vertices[(idx+1)%3].pos.Subtract(newPos);
         RHVector3 d2 = t.vertices[(idx+2)%3].pos.Subtract(t.vertices[(idx+1)%3].pos);
         RHVector3 normal = d1.CrossProduct(d2);
         if (normal.ScalarProduct(t.normal) < 0)
             return;
         double angle = t.AngleEdgePoint((idx + 1) % 3, newPos);
         if(angle < 0.088 || angle > 2.96)
             return; // Angle gets to small
     }
     model.vertices.ChangeCoordinates(this, newPos);
 }
コード例 #2
0
ファイル: RHVector3.cs プロジェクト: JackTing/Repetier-Host
 public double Distance(RHVector3 point)
 {
     double dx = point.x - x;
     double dy = point.y - y;
     double dz = point.z - z;
     return Math.Sqrt(dx * dx + dy * dy + dz * dz);
 }
コード例 #3
0
ファイル: BedHeightMap.cs プロジェクト: rlinus/Repetier-Host
 private void buttonMeasureHeights_Click(object sender, EventArgs e)
 {
     minx = double.Parse(textXMin.Text,GCode.format);
     maxx = double.Parse(textXMax.Text, GCode.format);
     miny = double.Parse(textYMin.Text, GCode.format);
     maxy = double.Parse(textYMax.Text, GCode.format);
     nx = int.Parse(textXPoints.Text);
     ny = int.Parse(textYPoints.Text);
     dx = (maxx-minx)/(double)(nx-1);
     dy = (maxy-miny)/(double)(ny-1);
     n = nx * ny;
     points = new RHVector3[n];
     int x, y;
     for (y = 0; y < ny; y++)
     {
         for (x = 0; x < nx; x++)
         {
             points[y * nx + x] = new RHVector3(minx + x * dx, miny + y * dy, 0);
         }
     }
     missing = n;
     Main.conn.eventResponse += Answer;
     buttonResultToClipboard.Enabled = false;
     for (int i = 0; i < n; i++)
     {
         RHVector3 act = points[i];
         Main.conn.injectManualCommand("G1 X" + act.x.ToString("0.00", GCode.format) + " Y" + act.y.ToString("0.00", GCode.format) + " F" + Main.conn.travelFeedRate.ToString(GCode.format));
         Main.conn.injectManualCommand("G30");
     }
 }
コード例 #4
0
 private int vertextHash(RHVector3 v)
 {
     int a = (int)(v.x*4.0);
     int b = (int)v.y;
     int c = (int)v.z;
     return a ^ (b << 16) ^ (c << 8) ^ c ^ (b<<8);
 }
コード例 #5
0
 public bool ContainsPoint(RHVector3 point)
 {
     if (minPoint == null) return false;
     return point.x >= minPoint.x && point.x <= maxPoint.x &&
         point.y >= minPoint.y && point.y <= maxPoint.y &&
         point.z >= minPoint.z && point.z <= maxPoint.z;
 }
コード例 #6
0
ファイル: Submesh.cs プロジェクト: rajeshputtur/Repetier-Host
 public void AddTriangle(RHVector3 v1, RHVector3 v2, RHVector3 v3, int color)
 {
     if(color == MESHCOLOR_ERRORFACE)
         trianglesError.Add(new SubmeshTriangle(VertexId(v1), VertexId(v2), VertexId(v3), color));
     else
         triangles.Add(new SubmeshTriangle(VertexId(v1), VertexId(v2), VertexId(v3), color));
 }
コード例 #7
0
ファイル: TopoModel.cs プロジェクト: sean-cc/Repetier-Host
 public TopoTriangle addTriangle(RHVector3 p1,RHVector3 p2,RHVector3 p3,RHVector3 normal)
 {
     TopoVertex v1 = addVertex(p1);
     TopoVertex v2 = addVertex(p2);
     TopoVertex v3 = addVertex(p3);
     TopoTriangle triangle = new TopoTriangle(this, v1, v2, v3, normal.x, normal.y, normal.z);
     return AddTriangle(triangle);
 }
コード例 #8
0
ファイル: TopoVertex.cs プロジェクト: JackTing/Repetier-Host
 public TopoVertex(int _id,RHVector3 _pos,Matrix4 trans)
 {
     id = _id;
     pos = new RHVector3(
         _pos.x*trans.Column0.X+_pos.y*trans.Column0.Y+_pos.z*trans.Column0.Z+trans.Column0.W,
         _pos.x*trans.Column1.X+_pos.y*trans.Column1.Y+_pos.z*trans.Column1.Z+trans.Column1.W,
         _pos.x*trans.Column2.X+_pos.y*trans.Column2.Y+_pos.z*trans.Column2.Z+trans.Column2.W
     );
 } 
コード例 #9
0
 public TopoVertex(int _id, RHVector3 _pos, Matrix4 trans)
 {
     id  = _id;
     pos = new RHVector3(
         _pos.x * trans.Column0.X + _pos.y * trans.Column0.Y + _pos.z * trans.Column0.Z + trans.Column0.W,
         _pos.x * trans.Column1.X + _pos.y * trans.Column1.Y + _pos.z * trans.Column1.Z + trans.Column1.W,
         _pos.x * trans.Column2.X + _pos.y * trans.Column2.Y + _pos.z * trans.Column2.Z + trans.Column2.W
         );
 }
コード例 #10
0
ファイル: TopoEdge.cs プロジェクト: rdacomp/Repetier-Host2
        public bool ProjectPoint(RHVector3 p, out double lambda, RHVector3 pProjected)
        {
            RHVector3 u = v2.pos.Subtract(v1.pos);

            lambda       = p.Subtract(v1.pos).ScalarProduct(u) / u.ScalarProduct(u);
            pProjected.x = v1.pos.x + lambda * u.x;
            pProjected.y = v1.pos.y + lambda * u.y;
            pProjected.z = v1.pos.z + lambda * u.z;
            return(lambda >= 0 && lambda <= 1);
        }
コード例 #11
0
ファイル: Submesh.cs プロジェクト: tojoshua/Repetier-Host
        public int VertexId(RHVector3 v)
        {
            //if (rhvertextMap.ContainsKey(v))
            //    return rhvertextMap[v];
            int pos = vertices.Count;

            vertices.Add(new Vector3((float)v.x, (float)v.y, (float)v.z));
            //rhvertextMap.Add(v, pos);
            return(pos);
        }
コード例 #12
0
 public bool ContainsPoint(RHVector3 point)
 {
     if (minPoint == null)
     {
         return(false);
     }
     return(point.x >= minPoint.x && point.x <= maxPoint.x &&
            point.y >= minPoint.y && point.y <= maxPoint.y &&
            point.z >= minPoint.z && point.z <= maxPoint.z);
 }
コード例 #13
0
        static public double TriangleQualityFromPositions(RHVector3 p1, RHVector3 p2, RHVector3 p3)
        {
            double a        = p1.Distance(p2);
            double b        = p1.Distance(p3);
            double c        = p2.Distance(p3);
            double bc2      = 2 * b * c;
            double sinalpha = Math.Sin(Math.Acos((b * b + c * c - a * a) / (bc2)));

            return(a * (a + b + c) / (bc2 * sinalpha * sinalpha));
        }
コード例 #14
0
ファイル: Submesh.cs プロジェクト: tojoshua/Repetier-Host
 public void AddTriangle(RHVector3 v1, RHVector3 v2, RHVector3 v3, int color)
 {
     if (color == MESHCOLOR_ERRORFACE)
     {
         trianglesError.Add(new SubmeshTriangle(VertexId(v1), VertexId(v2), VertexId(v3), color));
     }
     else
     {
         triangles.Add(new SubmeshTriangle(VertexId(v1), VertexId(v2), VertexId(v3), color));
     }
 }
コード例 #15
0
 public TopoVertex SearchPoint(RHVector3 vertex)
 {
     foreach (TopoVertex v in vertices)
     {
         if (vertex.Distance(v.pos) < TopoModel.epsilon)
         {
             return(v);
         }
     }
     return(null);
 }
コード例 #16
0
 public TopoVertex SearchPoint(RHVector3 vertex)
 {
     int hash = vertextHash(vertex);
     if (!list.ContainsKey(hash)) return null;
     foreach (TopoVertex v in list[hash])
     {
         if (vertex.Distance(v.pos) < TopoModel.epsilon)
             return v;
     }
     return null;
 }
コード例 #17
0
        /// <summary>
        /// Checks if all vertices are colinear preventing a normal computation. If point are coliniear the center vertex is
        /// moved in the direction of the edge to allow normal computations.
        /// </summary>
        /// <returns></returns>
        public bool CheckIfColinear()
        {
            RHVector3 d1    = vertices[1].pos.Subtract(vertices[0].pos);
            RHVector3 d2    = vertices[2].pos.Subtract(vertices[1].pos);
            double    angle = d1.Angle(d2);

            if (angle > 0.001 && angle < Math.PI - 0.001)
            {
                return(false);
            }
            return(true);
        }
コード例 #18
0
 public void Add(RHVector3 point)
 {
     if (minPoint == null)
     {
         minPoint = new RHVector3(point);
         maxPoint = new RHVector3(point);
     }
     else
     {
         minPoint.StoreMinimum(point);
         maxPoint.StoreMaximum(point);
     }
 }
コード例 #19
0
 public void Add(RHVector3 point)
 {
     if (minPoint == null)
     {
         minPoint = new RHVector3(point);
         maxPoint = new RHVector3(point);
     }
     else
     {
         minPoint.StoreMinimum(point);
         maxPoint.StoreMaximum(point);
     }
 }
コード例 #20
0
        public int LargestDimension()
        {
            RHVector3 size = box.Size;

            if (size.x > size.y && size.x > size.z)
            {
                return(0);
            }
            if (size.y > size.z)
            {
                return(1);
            }
            return(2);
        }
コード例 #21
0
ファイル: BedHeightMap.cs プロジェクト: rlinus/Repetier-Host
 public RHVector3 findNearest(double x, double y)
 {
     RHVector3 best = null;
     RHVector3 pos = new RHVector3(x,y,0);
     double bestdist = 1e20;
     for(int i=0;i<n;i++) {
         RHVector3 act = points[i];
         double dist = act.Distance(pos);
         if (dist < bestdist)
         {
             best = act;
             bestdist = dist;
         }
     }
     return best;
 }
コード例 #22
0
        public TopoVertex SearchPoint(RHVector3 vertex)
        {
            int hash = vertextHash(vertex);

            if (!list.ContainsKey(hash))
            {
                return(null);
            }
            foreach (TopoVertex v in list[hash])
            {
                if (vertex.Distance(v.pos) < TopoModel.epsilon)
                {
                    return(v);
                }
            }
            return(null);
        }
コード例 #23
0
 public TopoVertex SearchPoint(RHVector3 vertex)
 {
     if (IsLeaf)
     {
         return(leaf.SearchPoint(vertex));
     }
     if (left == null)
     {
         return(null);
     }
     if (vertex[splitDimension] < splitPosition)
     {
         return(left.SearchPoint(vertex));
     }
     else
     {
         return(right.SearchPoint(vertex));
     }
 }
コード例 #24
0
ファイル: TopoEdge.cs プロジェクト: rdacomp/Repetier-Host2
        public double alphaBeta; // Sum of dihedral angles to a virtual shared triangle

        public TopoEdgePair(TopoEdge _edgeA, TopoEdge _edgeB)
        {
            edgeA = _edgeA;
            edgeB = _edgeB;
            RHVector3 sharedPoint = null;
            RHVector3 p1 = null, p2 = null;

            if (edgeA.v1 == edgeB.v1)
            {
                sharedPoint = edgeA.v1.pos;
                p1          = edgeA.v2.pos;
                p2          = edgeB.v2.pos;
            }
            else if (edgeA.v1 == edgeB.v2)
            {
                sharedPoint = edgeA.v1.pos;
                p1          = edgeA.v2.pos;
                p2          = edgeB.v1.pos;
            }
            else if (edgeA.v2 == edgeB.v1)
            {
                sharedPoint = edgeA.v1.pos;
                p1          = edgeA.v1.pos;
                p2          = edgeB.v2.pos;
            }
            else if (edgeA.v2 == edgeB.v2)
            {
                sharedPoint = edgeA.v2.pos;
                p1          = edgeA.v1.pos;
                p2          = edgeB.v1.pos;
            }
            RHVector3 d1     = p1.Subtract(sharedPoint);
            RHVector3 d2     = p2.Subtract(sharedPoint);
            RHVector3 normal = d1.CrossProduct(d2);

            normal.NormalizeSafe();
            alphaBeta = normal.AngleForNormalizedVectors(edgeA.faces.First.Value.normal) + normal.AngleForNormalizedVectors(edgeB.faces.First.Value.normal);
            if (alphaBeta > Math.PI) // normal was wrong direction
            {
                alphaBeta = 2 * Math.PI - alphaBeta;
            }
        }
コード例 #25
0
        public bool SmoothAspectRatio(TopoModel model, double maxRatio)
        {
            double maxLen, minLen;
            int    maxIdx, minIdx;

            LongestShortestEdgeLength(out maxIdx, out maxLen, out minIdx, out minLen);
            if (minLen == 0)
            {
                return(false);
            }
            if (maxLen > 1 && maxLen / minLen > maxRatio)
            {
                RHVector3 center = edges[maxIdx].v1.pos.Add(edges[maxIdx].v2.pos);
                center.Scale(0.5);
                TopoVertex newVertex = new TopoVertex(0, center);
                model.addVertex(newVertex);
                edges[maxIdx].InsertVertex(model, newVertex);
                return(true);
            }
            return(false);
        }
コード例 #26
0
        private bool InPlanePointInside(int d1, int d2, RHVector3 p)
        {
            RHVector3 A   = vertices[0].pos;
            double    ax  = vertices[1].pos[d1] - vertices[0].pos[d1];
            double    ay  = vertices[1].pos[d2] - vertices[0].pos[d2];
            double    bx  = vertices[2].pos[d1] - vertices[0].pos[d1];
            double    by  = vertices[2].pos[d2] - vertices[0].pos[d2];
            double    det = ax * by - ay * bx;

            if (det == 0)
            {
                return(false);
            }
            double alpha     = -(bx * p[d2] - by * p[d1] + A[d1] * by - A[d2] * bx) / det;
            double beta      = (ax * p[d2] - ay * p[d1] - ax * A[d2] + ay * A[d1]) / det;
            bool   intersect = alpha >= epsilonZeroMinus && beta >= epsilonZeroMinus && alpha + beta <= epsilonOnePlus;

            if (intersect && debugIntersections)
            {
                Console.WriteLine("InPlanePointInside alpha=" + alpha + ", beta = " + beta);
            }
            return(intersect);
        }
コード例 #27
0
ファイル: Submesh.cs プロジェクト: tojoshua/Repetier-Host
 public void AddEdge(RHVector3 v1, RHVector3 v2, int color)
 {
     edges.Add(new SubmeshEdge(VertexId(v1), VertexId(v2), color));
 }
コード例 #28
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public void StoreMinimum(RHVector3 vec)
 {
     x = Math.Min(x, vec.x);
     y = Math.Min(y, vec.y);
     z = Math.Min(z, vec.z);
 }
コード例 #29
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public double ScalarProduct(RHVector3 vector)
 {
     return(x * vector.x + y * vector.y + z * vector.z);
 }
コード例 #30
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public void SubtractInternal(RHVector3 vector)
 {
     x -= vector.x;
     y -= vector.y;
     z -= vector.z;
 }
コード例 #31
0
ファイル: PrintModel.cs プロジェクト: JackTing/Repetier-Host
 private void includePoint(RHVector3 v)
 {
     float x, y, z;
     Vector4 v4 = v.asVector4();
     x = Vector4.Dot(trans.Column0, v4);
     y = Vector4.Dot(trans.Column1, v4);
     z = Vector4.Dot(trans.Column2, v4);
     bbox.Add(new RHVector3(x, y, z));
 }
コード例 #32
0
ファイル: TopoModel.cs プロジェクト: sean-cc/Repetier-Host
 public TopoVertex findVertexOrNull(RHVector3 pos)
 {
     return vertices.SearchPoint(pos);
     /*  foreach (TopoVertex v in vertices)
       {
           if (v.distance(pos) < epsilon)
               return v;
       }
       return null;*/
 }
コード例 #33
0
ファイル: TopoModel.cs プロジェクト: sean-cc/Repetier-Host
 public bool JoinTouchedOpenEdges(double limit)
 {
     /*Console.WriteLine("Open Edges:");
     foreach (TopoEdge e in OpenLoopEdges())
     {
         Console.WriteLine(e);
     }
     Console.WriteLine("=========");*/
     bool changed = false;
     bool somethingChanged = false;
     RHVector3 projectedPoint = new RHVector3(0, 0, 0);
     double lambda;
     int cnt = 0;
     do
     {
         changed = false;
         HashSet<TopoEdge> list = OpenLoopEdges();
         foreach (TopoEdge edge in list)
         {
             cnt++;
             if ((cnt % 10) == 0)
             {
                 Application.DoEvents();
                 if (IsActionStopped()) return true;
             }
             foreach (TopoEdge test in list)
             {
                 for (int i = 0; i < 2; i++)
                 {
                     if (edge.ProjectPoint(test[i].pos, out lambda, projectedPoint))
                     {
                         double dist = test[i].pos.Distance(projectedPoint);
                         //Console.WriteLine("Distance:" + dist + " lambda " + lambda);
                         if (dist < limit && edge.FirstTriangle.VertexIndexFor(test[i]) == -1)
                         {
                             //Console.WriteLine("RedLine:" + edge);
                             edge.InsertVertex(this, test[i]);
                             changed = true;
                             somethingChanged = true;
                             break;
                         }
                     }
                 }
                 if (changed) break;
             }
             if (changed) break;
         }
     } while (changed == true);
     if (somethingChanged) intersectionsUpToDate = false;
     return somethingChanged;
 }
コード例 #34
0
 public TopoVertex(int _id, RHVector3 _pos)
 {
     id  = _id;
     pos = new RHVector3(_pos);
 }
コード例 #35
0
ファイル: TopoModel.cs プロジェクト: sean-cc/Repetier-Host
 public TopoVertex addVertex(RHVector3 pos)
 {
     /*if (Math.Abs(pos.x + 3.94600009918213) < 0.001 && Math.Abs(pos.y + 2.16400003433228) < 0.001 && Math.Abs(pos.z - 7.9980001449585) < 0.001)
     {
         Console.WriteLine(pos);
     }*/
     TopoVertex newVertex = findVertexOrNull(pos);
     if (newVertex == null)
     {
         newVertex = new TopoVertex(vertices.Count + 1, pos);
         addVertex(newVertex);
     }
     return newVertex;
 }
コード例 #36
0
ファイル: RHMatrix3.cs プロジェクト: JackTing/Repetier-Host
 public void SetZColumn(RHVector3 v)
 {
     xz = v.x;
     yz = v.y;
     zz = v.z;
 }
コード例 #37
0
        public void FitBoundingBox(RHBoundingBox box)
        {
            float bedRadius = (float)(1.5 * Math.Sqrt((ps.PrintAreaDepth * ps.PrintAreaDepth + ps.PrintAreaHeight * ps.PrintAreaHeight + ps.PrintAreaWidth * ps.PrintAreaWidth) * 0.25));
            RHVector3 shift = new RHVector3(-ps.BedLeft - 0.5 * ps.PrintAreaWidth, -ps.BedFront - 0.5 * ps.PrintAreaDepth, -0.5 * ps.PrintAreaHeight);
            viewCenter = box.Center.asVector3();
            distance = defaultDistance;
            int loops = 5;
            while (loops > 0)
            {
                loops--;
                angle = 15.0 * Math.PI / 180;
                double ratio = (double)control.gl.Width / (double)control.gl.Height;
                Vector3 camPos = CameraPosition;
                Matrix4 lookAt = Matrix4.LookAt(camPos.X, camPos.Y, camPos.Z, viewCenter.X, viewCenter.Y, viewCenter.Z, 0, 0, 1.0f);
                Matrix4 persp;
                Vector3 dir = new Vector3();
                Vector3.Subtract(ref viewCenter, ref camPos, out dir);
                dir.Normalize();
                float dist;
                Vector3.Dot(ref dir, ref camPos, out dist);
                dist = -dist;

                float nearDist = Math.Max(1, dist - bedRadius);
                float farDist = Math.Max(bedRadius * 2, dist + bedRadius);
                float nearHeight = 2.0f * (float)Math.Tan(angle) * dist;

                if (control.toolParallelProjection.Checked)
                {
                    persp = Matrix4.CreateOrthographic(nearHeight * (float)ratio, nearHeight, nearDist, farDist);
                    loops = 0;
                }
                else
                {
                    persp = Matrix4.CreatePerspectiveFieldOfView((float)(angle * 2.0), (float)ratio, nearDist, farDist);
                }
                Matrix4 trans = Matrix4.Mult(lookAt, persp);
                RHVector3 min = new RHVector3(0, 0, 0);
                RHVector3 max = new RHVector3(0, 0, 0);
                Vector4 pos;
                RHBoundingBox bb = new RHBoundingBox();
                pos = Vector4.Transform(box.minPoint.asVector4(), trans);
                bb.Add(new RHVector3(pos));
                pos = Vector4.Transform(box.maxPoint.asVector4(), trans);
                bb.Add(new RHVector3(pos));
                Vector4 pnt = new Vector4((float)box.xMin, (float)box.yMax, (float)box.zMin, 1);
                pos = Vector4.Transform(pnt, trans);
                bb.Add(new RHVector3(pos));
                pnt = new Vector4((float)box.xMin, (float)box.yMax, (float)box.zMin, 1);
                pos = Vector4.Transform(pnt, trans);
                bb.Add(new RHVector3(pos));
                pnt = new Vector4((float)box.xMax, (float)box.yMax, (float)box.zMin, 1);
                pos = Vector4.Transform(pnt, trans);
                bb.Add(new RHVector3(pos));
                pnt = new Vector4((float)box.xMin, (float)box.yMax, (float)box.zMax, 1);
                pos = Vector4.Transform(pnt, trans);
                bb.Add(new RHVector3(pos));
                pnt = new Vector4((float)box.xMin, (float)box.yMin, (float)box.zMax, 1);
                pos = Vector4.Transform(pnt, trans);
                bb.Add(new RHVector3(pos));
                pnt = new Vector4((float)box.xMax, (float)box.yMin, (float)box.zMax, 1);
                pos = Vector4.Transform(pnt, trans);
                bb.Add(new RHVector3(pos));
                double fac = Math.Max(Math.Abs(bb.xMin), Math.Abs(bb.xMax));
                fac = Math.Max(fac, Math.Abs(bb.yMin));
                fac = Math.Max(fac, Math.Abs(bb.yMax));
                distance *= fac * 1.03;
                if (distance < 1) angle = Math.Atan(distance * Math.Tan(15.0 * Math.PI / 180.0));
            }
        }
コード例 #38
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public void AddInternal(RHVector3 vector)
 {
     x += vector.x;
     y += vector.y;
     z += vector.z;
 }
コード例 #39
0
ファイル: PrintModel.cs プロジェクト: JackTing/Repetier-Host
 public void ReverseTransformPoint(RHVector3 v, RHVector3 outv)
 {
     Vector4 v4 = v.asVector4();
     outv.x = Vector4.Dot(invTrans.Column0, v4);
     outv.y = Vector4.Dot(invTrans.Column1, v4);
     outv.z = Vector4.Dot(invTrans.Column2, v4);
 }
コード例 #40
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public RHVector3 Add(RHVector3 vector)
 {
     return(new RHVector3(x + vector.x, y + vector.y, z + vector.z));
 }
コード例 #41
0
ファイル: TopoModel.cs プロジェクト: sean-cc/Repetier-Host
 private RHVector3 extractVector(string s)
 {
     RHVector3 v = new RHVector3(0,0,0);
     s = s.Trim().Replace("  ", " ");
     int p = s.IndexOf(' ');
     if (p < 0) throw new Exception("Format error");
     double.TryParse(s.Substring(0, p), NumberStyles.Float, GCode.format, out v.x);
     s = s.Substring(p).Trim();
     p = s.IndexOf(' ');
     if (p < 0) throw new Exception("Format error");
     double.TryParse(s.Substring(0, p), NumberStyles.Float, GCode.format, out v.y);
     s = s.Substring(p).Trim();
     double.TryParse(s, NumberStyles.Float, GCode.format, out v.z);
     return v;
 }
コード例 #42
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public RHVector3(RHVector3 orig)
 {
     x = orig.x;
     y = orig.y;
     z = orig.z;
 }
コード例 #43
0
ファイル: TopoModel.cs プロジェクト: sean-cc/Repetier-Host
 public void CutMesh(Submesh mesh, RHVector3 normal, RHVector3 point,int defaultFaceColor)
 {
     TopoPlane plane = new TopoPlane(normal, point);
     bool drawEdges = Main.threeDSettings.ShowEdges;
     foreach (TopoEdge e in edges)
         e.algHelper = 0; // Mark drawn edges, so we insert them only once
     foreach (TopoTriangle t in triangles)
     {
         int side = plane.testTriangleSideFast(t);
         if (side == -1)
         {
             mesh.AddTriangle(t.vertices[0].pos, t.vertices[1].pos, t.vertices[2].pos, (t.bad ? Submesh.MESHCOLOR_ERRORFACE : defaultFaceColor));
             if (drawEdges)
             {
                 if (t.edges[0].algHelper == 0)
                 {
                     mesh.AddEdge(t.vertices[0].pos, t.vertices[1].pos, t.edges[0].connectedFaces == 2 ? Submesh.MESHCOLOR_EDGE : Submesh.MESHCOLOR_ERROREDGE);
                     t.edges[0].algHelper = 1;
                 }
                 if (t.edges[1].algHelper == 0)
                 {
                     mesh.AddEdge(t.vertices[1].pos, t.vertices[2].pos, t.edges[1].connectedFaces == 2 ? Submesh.MESHCOLOR_EDGE : Submesh.MESHCOLOR_ERROREDGE);
                     t.edges[1].algHelper = 1;
                 }
                 if (t.edges[2].algHelper == 0)
                 {
                     mesh.AddEdge(t.vertices[2].pos, t.vertices[0].pos, t.edges[2].connectedFaces == 2 ? Submesh.MESHCOLOR_EDGE : Submesh.MESHCOLOR_ERROREDGE);
                     t.edges[2].algHelper = 1;
                 }
             }
             else
             {
                 if (t.edges[0].algHelper == 0 && t.edges[0].connectedFaces != 2)
                 {
                     mesh.AddEdge(t.vertices[0].pos, t.vertices[1].pos, Submesh.MESHCOLOR_ERROREDGE);
                     t.edges[0].algHelper = 1;
                 }
                 if (t.edges[1].algHelper == 0 && t.edges[1].connectedFaces != 2)
                 {
                     mesh.AddEdge(t.vertices[1].pos, t.vertices[2].pos, Submesh.MESHCOLOR_ERROREDGE);
                     t.edges[1].algHelper = 1;
                 }
                 if (t.edges[2].algHelper == 0 && t.edges[2].connectedFaces != 2)
                 {
                     mesh.AddEdge(t.vertices[2].pos, t.vertices[0].pos, Submesh.MESHCOLOR_ERROREDGE);
                     t.edges[2].algHelper = 1;
                 }
             }
         }
         else if (side == 0)
         {
             plane.addIntersectionToSubmesh(mesh, t, drawEdges, (t.bad ? Submesh.MESHCOLOR_ERRORFACE : defaultFaceColor));
         }
     }
 }
コード例 #44
0
 public TopoVertex SearchPoint(RHVector3 vertex)
 {
     if (IsLeaf) return leaf.SearchPoint(vertex);
     if (left == null) return null;
     if (vertex[splitDimension] < splitPosition)
         return left.SearchPoint(vertex);
     else
         return right.SearchPoint(vertex);
 }
コード例 #45
0
ファイル: TopoModel.cs プロジェクト: sean-cc/Repetier-Host
 public void importSTL(string filename)
 {
     StartAction("L_LOADING...");
     clear();
     try
     {
         FileStream f = File.OpenRead(filename);
         byte[] header = new byte[80];
         ReadArray(f, header);
         /*   if (header[0] == 's' && header[1] == 'o' && header[2] == 'l' && header[3] == 'i' && header[4] == 'd')
            {
                f.Close();
                LoadText(file);
            }
            else
            {*/
         BinaryReader r = new BinaryReader(f);
         int nTri = r.ReadInt32();
         if (f.Length != 84 + nTri * 50)
         {
             f.Close();
             importSTLAscii(filename);
         }
         else
         {
             for (int i = 0; i < nTri; i++)
             {
                 Progress((double)i / nTri);
                 if (i % 2000 == 0)
                 {
                     Application.DoEvents();
                     if(IsActionStopped()) return;
                 }
                 RHVector3 normal = new RHVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                 RHVector3 p1 = new RHVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                 RHVector3 p2 = new RHVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                 RHVector3 p3 = new RHVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                 normal.NormalizeSafe();
                 addTriangle(p1, p2, p3, normal);
                 r.ReadUInt16();
             }
             r.Close();
             f.Close();
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString(), "Error reading STL file", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #46
0
 public void ChangeCoordinates(TopoVertex vertex, RHVector3 newPos)
 {
     Remove(vertex);
     vertex.pos = new RHVector3(newPos);
     Add(vertex);
 }
コード例 #47
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public RHVector3 Subtract(RHVector3 vector)
 {
     return(new RHVector3(x - vector.x, y - vector.y, z - vector.z));
 }
コード例 #48
0
 public void Clear()
 {
     minPoint = maxPoint = null;
 }
コード例 #49
0
 void UpdateCutData()
 {
     updateCuts = true;
     cutBBox.Clear();
     foreach (PrintModel model in Main.main.objectPlacement.ListObjects(false))
     {
         cutBBox.Add(model.bbox);
     }
     oldPosition = Main.main.objectPlacement.cutPositionSlider.Value;
     oldInclination = Main.main.objectPlacement.cutInclinationSlider.Value;
     oldAzimuth = Main.main.objectPlacement.cutAzimuthSlider.Value;
     double inclination = (double)oldInclination * Math.PI / 1800.0;
     double azimuth = (double)oldAzimuth * Math.PI / 1800.0;
     cutDirection.x = Math.Sin(inclination) * Math.Cos(azimuth);
     cutDirection.y = Math.Sin(inclination) * Math.Sin(azimuth);
     cutDirection.z = Math.Cos(inclination);
     RHVector3 center = cutBBox.Center;
     TopoPlane plane = new TopoPlane(cutDirection, center);
     double min = 0, max = 0, dist;
     RHVector3 p = new RHVector3(cutBBox.xMin, cutBBox.yMin, cutBBox.zMin);
     dist = plane.VertexDistance(p);
     max = Math.Max(dist, max);
     min = Math.Min(dist, min);
     p = new RHVector3(cutBBox.xMax, cutBBox.yMin, cutBBox.zMin);
     dist = plane.VertexDistance(p);
     max = Math.Max(dist, max);
     min = Math.Min(dist, min);
     p = new RHVector3(cutBBox.xMin, cutBBox.yMax, cutBBox.zMin);
     dist = plane.VertexDistance(p);
     max = Math.Max(dist, max);
     min = Math.Min(dist, min);
     p = new RHVector3(cutBBox.xMax, cutBBox.yMax, cutBBox.zMin);
     dist = plane.VertexDistance(p);
     max = Math.Max(dist, max);
     min = Math.Min(dist, min);
     p = new RHVector3(cutBBox.xMin, cutBBox.yMin, cutBBox.zMax);
     dist = plane.VertexDistance(p);
     max = Math.Max(dist, max);
     min = Math.Min(dist, min);
     p = new RHVector3(cutBBox.xMax, cutBBox.yMin, cutBBox.zMax);
     dist = plane.VertexDistance(p);
     max = Math.Max(dist, max);
     min = Math.Min(dist, min);
     p = new RHVector3(cutBBox.xMin, cutBBox.yMax, cutBBox.zMax);
     dist = plane.VertexDistance(p);
     max = Math.Max(dist, max);
     min = Math.Min(dist, min);
     p = new RHVector3(cutBBox.xMax, cutBBox.yMax, cutBBox.zMax);
     dist = plane.VertexDistance(p);
     max = Math.Max(dist, max);
     min = Math.Min(dist, min);
     double spos = min + 1.001 * (max - min) * (double)oldPosition / 1000.0;
     cutPos.x = center.x + spos * cutDirection.x;
     cutPos.y = center.y + spos * cutDirection.y;
     cutPos.z = center.z + spos * cutDirection.z;
 }
コード例 #50
0
 public double distance(RHVector3 vertex)
 {
     return(pos.Distance(vertex));
 }
コード例 #51
0
ファイル: TopoVertex.cs プロジェクト: JackTing/Repetier-Host
 public TopoVertex(int _id, RHVector3 _pos)
 {
     id = _id;
     pos = new RHVector3(_pos);
 }
コード例 #52
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public double Angle(RHVector3 direction)
 {
     return(Math.Acos(ScalarProduct(direction) / (Length * direction.Length)));
 }
コード例 #53
0
 public TopoVertex SearchPoint(RHVector3 vertex)
 {
     foreach (TopoVertex v in vertices)
     {
         if (vertex.Distance(v.pos) < TopoModel.epsilon)
             return v;
     }
     return null;
 }
コード例 #54
0
ファイル: TopoVertex.cs プロジェクト: JackTing/Repetier-Host
 public double distance(RHVector3 vertex)
 {
     return pos.Distance(vertex);
 }
コード例 #55
0
        private void TrySplit()
        {
            int newDim          = 0;
            int parentDimension = -1;

            if (parent != null)
            {
                parentDimension = parent.dimension;
            }
            RHVector3 size = box.Size;

            if (parentDimension != 0)
            {
                newDim = 0;
            }
            if (parentDimension != 1 && size.x < size.y)
            {
                newDim = 1;
            }
            if (parentDimension != 2 && size.z > size[newDim])
            {
                newDim = 2;
            }
            int    loop           = 0;
            int    maxLoop        = 4;
            double bestCenter     = 0;
            double bestPercentage = 3000;
            int    bestDim        = 0;

            for (int dim = 0; dim < 3; dim++)
            {
                if (dim == parentDimension)
                {
                    continue;
                }
                for (loop = 0; loop < maxLoop; loop++)
                {
                    int    count    = 0;
                    double testDist = box.minPoint[newDim] + size[newDim] * (1 + loop) / (maxLoop + 1);
                    foreach (TopoTriangle tri in triangles)
                    {
                        if (tri.boundingBox.maxPoint[newDim] < testDist)
                        {
                            count++;
                        }
                    }
                    double percent = 100.0 * (double)count / triangles.Count;
                    if (Math.Abs(50 - percent) < bestPercentage)
                    {
                        bestPercentage = percent;
                        bestCenter     = testDist;
                        bestDim        = dim;
                    }
                }
            }
            if (bestPercentage < 5)
            {
                nextTrySplit = (nextTrySplit * 3) / 2;
                return; // not effective enough
            }
            left           = new TopoTriangleNode(this);
            right          = new TopoTriangleNode(this);
            middle         = new TopoTriangleNode(this);
            dimension      = newDim;
            middlePosition = bestCenter;
            foreach (TopoTriangle tri in triangles)
            {
                if (tri.boundingBox.maxPoint[dimension] < middlePosition)
                {
                    left.AddTriangle(tri);
                }
                else if (tri.boundingBox.minPoint[dimension] > middlePosition)
                {
                    right.AddTriangle(tri);
                }
                else
                {
                    middle.AddTriangle(tri);
                }
            }
            triangles = null;
        }
コード例 #56
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public double AngleForNormalizedVectors(RHVector3 direction)
 {
     return(Math.Acos(ScalarProduct(direction)));
 }
コード例 #57
0
ファイル: PrintModel.cs プロジェクト: JackTing/Repetier-Host
 public void TransformPoint(RHVector3 v, out float x, out float y, out float z)
 {
     Vector4 v4 = v.asVector4();
     x = Vector4.Dot(trans.Column0, v4);
     y = Vector4.Dot(trans.Column1, v4);
     z = Vector4.Dot(trans.Column2, v4);
 }
コード例 #58
0
ファイル: RHVector3.cs プロジェクト: rdacomp/Repetier-Host2
 public void StoreMaximum(RHVector3 vec)
 {
     x = Math.Max(x, vec.x);
     y = Math.Max(y, vec.y);
     z = Math.Max(z, vec.z);
 }
コード例 #59
0
ファイル: PrintModel.cs プロジェクト: JackTing/Repetier-Host
        public override void Paint()
        {
            TopoModel model = ActiveModel;

            if (Main.main.objectPlacement.checkCutFaces.Checked)
            {
                int cutpos = Main.main.objectPlacement.cutPositionSlider.Value;
                if (ForceRefresh || Main.main.threedview.updateCuts || lastRendered!=1 || activeModel != activeSubmesh || lastShowEdges != Main.threeDSettings.ShowEdges || lastSelected != Selected)
                {
                    RHVector3 normpoint = Main.main.threedview.cutPos.Add(Main.main.threedview.cutDirection);
                    RHVector3 point = new RHVector3(0, 0, 0);
                    ReverseTransformPoint(Main.main.threedview.cutPos, point);
                    ReverseTransformPoint(normpoint, normpoint);
                    RHVector3 normal = normpoint.Subtract(point);
                    
                    submesh.Clear();
                    model.CutMesh(submesh, normal, point,outside ? Submesh.MESHCOLOR_OUTSIDE : Submesh.MESHCOLOR_FRONTBACK);
                    submesh.selected = Selected;
                    submesh.Compress();
                    lastShowEdges = Main.threeDSettings.ShowEdges;
                    lastSelected = Selected;
                    activeSubmesh = activeModel;
                    lastRendered = 1;
                }
            }
            else
            {
                if (ForceRefresh || Main.main.threedview.updateCuts || lastRendered != 0 || activeModel != activeSubmesh || lastShowEdges != Main.threeDSettings.ShowEdges)
                {
                    submesh.Clear();
                    model.FillMesh(submesh, outside ? Submesh.MESHCOLOR_OUTSIDE : Submesh.MESHCOLOR_FRONTBACK);
                    submesh.selected = Selected;
                    submesh.Compress();
                    lastShowEdges = Main.threeDSettings.ShowEdges;
                    lastSelected = Selected;
                    activeSubmesh = activeModel;
                    lastRendered = 0;
                }
            }
            submesh.Draw(Main.threeDSettings.drawMethod,Main.main.threedview.cam.EdgeTranslation());
            ForceRefresh = false;
        }
コード例 #60
0
ファイル: RHMatrix3.cs プロジェクト: JackTing/Repetier-Host
 public void SetYColumn(RHVector3 v)
 {
     xy = v.x;
     yy = v.y;
     zy = v.z;
 }