public void AddTriangle(TopoTriangle triangle)
 {
     if (left == null && triangles == null)
     {
         triangles = new HashSet <TopoTriangle>();
     }
     if (triangles != null)
     {
         triangles.Add(triangle);
         box.Add(triangle.boundingBox);
         if (triangles.Count > nextTrySplit)
         {
             TrySplit();
         }
     }
     else
     {
         if (triangle.boundingBox.maxPoint[dimension] < middlePosition)
         {
             left.AddTriangle(triangle);
         }
         else if (triangle.boundingBox.minPoint[dimension] > middlePosition)
         {
             right.AddTriangle(triangle);
         }
         else
         {
             middle.AddTriangle(triangle);
         }
     }
 }
        public TopoTriangle(TopoModel model, TopoVertex v1, TopoVertex v2, TopoVertex v3, double nx, double ny, double nz)
        {
            vertices[0] = v1;
            vertices[1] = v2;
            vertices[2] = v3;
            RHVector3 normalTest = new RHVector3(nx, ny, nz);

            //normal.NormalizeSafe();
            edges[0] = model.getOrCreateEdgeBetween(v1, v2);
            edges[1] = model.getOrCreateEdgeBetween(v2, v3);
            edges[2] = model.getOrCreateEdgeBetween(v3, v1);
            edges[0].connectFace(this);
            edges[1].connectFace(this);
            edges[2].connectFace(this);
            v1.connectFace(this);
            v2.connectFace(this);
            v3.connectFace(this);
            boundingBox.Add(v1.pos);
            boundingBox.Add(v2.pos);
            boundingBox.Add(v3.pos);
            RecomputeNormal();
            if (normalTest.ScalarProduct(normal) < 0)
            {
                FlipDirection();
            }

            /* double d1 = edges[0].EdgeLength;
             * double d2 = edges[1].EdgeLength;
             * double d3 = edges[2].EdgeLength;
             * if (d1 < epsilonZero || d2 < epsilonZero || d3 < epsilonZero)
             *   Console.WriteLine("Df:" + this);*/
        }
        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));
            }
        }
 public RHBoundingBox ObjectsBoundingBox()
 {
     RHBoundingBox b = new RHBoundingBox();
     foreach (PrintModel model in Main.main.objectPlacement.ListObjects(false))
     {
         b.Add(model.bbox.minPoint);
         b.Add(model.bbox.maxPoint);
     }
     if (b.minPoint == null) return PrinterBoundingBox();
     return b;
 }
 public RHBoundingBox PrinterBoundingBox()
 {
     RHBoundingBox b = new RHBoundingBox();
     b.Add(ps.BedLeft, ps.BedFront, -0.0 * ps.PrintAreaHeight);
     b.Add(ps.BedLeft + ps.PrintAreaWidth, ps.BedFront + ps.PrintAreaDepth, 1.0 * ps.PrintAreaHeight);
     return b;
 }
Exemple #6
0
 public void Add(TopoVertex vertex)
 {
     vertices.Add(vertex);
     box.Add(vertex.pos);
 }