예제 #1
0
        public override void Invoke(CancellationToken token)
        {
            OnBegin?.Invoke();

            var tasks = new List <Task>();

            for (var i = 0; i < Workers; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => {
                    foreach (var source in Sources.GetConsumingEnumerable())
                    {
                        token.ThrowIfCancellationRequested();

                        foreach (var result in filter(source))
                        {
                            Results.Add(result, token);
                            OnInnerInterval?.Invoke(result);
                        }

                        OnInterval?.Invoke(source);
                    }
                }, token));
            }

            Task.WaitAll(tasks.ToArray());

            Results.CompleteAdding();
            OnFinish?.Invoke();
        }
예제 #2
0
 /// <summary>
 /// Public constructor
 /// </summary>
 public ZAnalysisVAM()
     : base(ZANALYSIS_VAM_ID, IRhinoVisualAnalysisMode.analysis_style.false_color_style)
 {
     m_z_range        = new OnInterval(-10.0, 10.0);
     m_hue_range      = new OnInterval(0.0, 4.0 * OnUtil.On_PI / 3.0); // red to green to blue
     m_bShowIsoCurves = true;
 }
예제 #3
0
        private void Worker()
        {
            foreach (var source in Sources.GetConsumingEnumerable(token))
            {
                // Cancelが発生していたら例外を投げる
                token.ThrowIfCancellationRequested();

                switch (Mode)
                {
                case PipeLineStageMode.Last:
                    outputAction(source);
                    break;

                case PipeLineStageMode.SelectMany: {
                    foreach (var result in manyFilter(source))
                    {
                        Results.Add(result, token);
                        TotalResultsCount++;
                    }

                    break;
                }

                case PipeLineStageMode.Select:
                    Results.Add(filter(source), token);
                    TotalResultsCount++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                OnInterval?.Invoke(source);
            }
        }
예제 #4
0
 /// <summary>
 /// Public constructor
 /// </summary>
 public ZAnalysisVAM()
     : base(ZANALYSIS_VAM_ID, IRhinoVisualAnalysisMode.analysis_style.false_color_style)
 {
     m_z_range = new OnInterval(-10.0, 10.0);
       m_hue_range = new OnInterval(0.0, 4.0 * OnUtil.On_PI / 3.0); // red to green to blue
       m_bShowIsoCurves = true;
 }
예제 #5
0
        public override void Invoke(CancellationToken token)
        {
            OnBegin?.Invoke();
            var box = new List <List <TItem> > {
                new List <TItem>()
            };
            var idx = 0;

            foreach (var item in Sources.GetConsumingEnumerable())
            {
                token.ThrowIfCancellationRequested();
                OnInterval?.Invoke(item);

                box[idx].Add(item);
                if (box[idx].Count != Size)
                {
                    continue;
                }

                Results.Add(box[idx].ToArray(), token);
                idx++;
                box.Add(new List <TItem>());
            }

            if (box[idx].Any())
            {
                Results.Add(box[idx].ToArray(), token);
            }
            Results.CompleteAdding();
            OnFinish?.Invoke();
        }
예제 #6
0
 public static uint ComputeChecksum(OnInterval dom)
 {
     if (null != dom)
     {
         return(ComputeChecksum(BitConverter.GetBytes(dom.Max() - dom.Min())));
     }
     return(0);
 }
예제 #7
0
 public void Interval(int mils)
 {
     Console.WriteLine($"Intervaling {mils}...");
     OnInterval?.Invoke(this, new IntervalEventArgs
     {
         Millis = mils
     });
 }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select rectangular light");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnLight light = go.Object(0).Light();

            if (null == light)
            {
                return(IRhinoCommand.result.failure);
            }

            if (!light.IsRectangularLight())
            {
                RhUtil.RhinoApp().Print("Not a rectangular light.\n");
                return(IRhinoCommand.result.nothing);
            }

            On3dPoint  origin = light.Location();
            On3dVector xaxis  = light.Length();
            On3dVector yaxis  = light.Width();

            OnPlane    plane      = new OnPlane(origin, xaxis, yaxis);
            OnInterval x_interval = new OnInterval(0.0, xaxis.Length());
            OnInterval y_interval = new OnInterval(0.0, yaxis.Length());

            OnMesh mesh = RhUtil.RhinoMeshPlane(plane, x_interval, y_interval, 2, 2);

            if (null != mesh)
            {
                mesh.ConvertQuadsToTriangles();
                context.m_doc.AddMeshObject(mesh);
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.cancel);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select rectangular light");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IOnLight light = go.Object(0).Light();
              if (null == light)
            return IRhinoCommand.result.failure;

              if (!light.IsRectangularLight())
              {
            RhUtil.RhinoApp().Print("Not a rectangular light.\n");
            return IRhinoCommand.result.nothing;
              }

              On3dPoint origin = light.Location();
              On3dVector xaxis = light.Length();
              On3dVector yaxis = light.Width();

              OnPlane plane = new OnPlane(origin, xaxis, yaxis);
              OnInterval x_interval = new OnInterval(0.0, xaxis.Length());
              OnInterval y_interval = new OnInterval(0.0, yaxis.Length());

              OnMesh mesh = RhUtil.RhinoMeshPlane(plane, x_interval, y_interval, 2, 2);
              if (null != mesh)
              {
            mesh.ConvertQuadsToTriangles();
            context.m_doc.AddMeshObject(mesh);
            context.m_doc.Redraw();
              }

              return IRhinoCommand.result.cancel;
        }
예제 #10
0
        public void SetBrep(IOnBrep brep)
        {
            if (null == brep || !brep.IsValid())
            {
                return;
            }

            m_brep = brep;

            int face_count = m_brep.m_F.Count();

            m_points.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);
            m_normals.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);

            m_points.SetCount(0);
            m_normals.SetCount(0);

            for (int i = 0; i < face_count; i++)
            {
                IOnBrepFace face = m_brep.m_F[i];
                IOnBrepLoop loop = face.OuterLoop();
                if (null == loop)
                {
                    continue;
                }

                OnInterval udomain = face.Domain(0);
                OnInterval vdomain = face.Domain(1);

                if (loop.m_pbox.IsValid())
                {
                    OnInterval domain = new OnInterval();
                    domain.Set(loop.m_pbox.m_min.x, loop.m_pbox.m_max.x);
                    domain.Intersection(udomain);
                    if (domain.IsIncreasing())
                    {
                        udomain.Set(domain.Min(), domain.Max());
                    }
                    domain.Set(loop.m_pbox.m_min.y, loop.m_pbox.m_max.y);
                    domain.Intersection(vdomain);
                    if (domain.IsIncreasing())
                    {
                        vdomain.Set(domain.Min(), domain.Max());
                    }
                }

                bool bUntrimmed = m_brep.FaceIsSurface(i);

                ArrayOnInterval intervals = new ArrayOnInterval();
                bool            bRev      = face.m_bRev;

                for (double u = 0.0; u < SURFACE_ARROW_COUNT; u += 1.0)
                {
                    double d = u / (SURFACE_ARROW_COUNT - 1.0);
                    double s = udomain.ParameterAt(d);

                    intervals.SetCount(0);

                    if (bUntrimmed || RhUtil.RhinoGetIsoIntervals(face, 1, s, intervals) > 0)
                    {
                        for (double v = 0.0; v < SURFACE_ARROW_COUNT; v += 1.0)
                        {
                            d = v / (SURFACE_ARROW_COUNT - 1.0);
                            double t = vdomain.ParameterAt(d);

                            bool bAdd = bUntrimmed;
                            for (int k = 0; !bAdd && k < intervals.Count(); k++)
                            {
                                if (intervals[k].Includes(t))
                                {
                                    bAdd = true;
                                }
                            }

                            if (bAdd)
                            {
                                On3dPoint  pt  = new On3dPoint();
                                On3dVector du  = new On3dVector();
                                On3dVector dv  = new On3dVector();
                                On3dVector dir = new On3dVector();
                                if (face.EvNormal(s, t, ref pt, ref du, ref dv, ref dir))
                                {
                                    m_points.Append(pt);
                                    if (bRev)
                                    {
                                        dir.Reverse();
                                    }
                                    m_normals.Append(dir);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #11
0
 public static uint ComputeChecksum(OnInterval dom)
 {
     if (null != dom)
     return ComputeChecksum(BitConverter.GetBytes(dom.Max() - dom.Min()));
       return 0;
 }
예제 #12
0
 private void SetInterval_Click(object sender, TargetEventArgs e) => OnInterval?.Invoke();
        public void SetBrep(IOnBrep brep)
        {
            if (null == brep || !brep.IsValid())
            return;

              m_brep = brep;

              int face_count = m_brep.m_F.Count();
              m_points.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);
              m_normals.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);

              m_points.SetCount(0);
              m_normals.SetCount(0);

              for (int i = 0; i < face_count; i++)
              {
            IOnBrepFace face = m_brep.m_F[i];
            IOnBrepLoop loop = face.OuterLoop();
            if (null == loop)
              continue;

            OnInterval udomain = face.Domain(0);
            OnInterval vdomain = face.Domain(1);

            if (loop.m_pbox.IsValid())
            {
              OnInterval domain = new OnInterval();
              domain.Set(loop.m_pbox.m_min.x, loop.m_pbox.m_max.x);
              domain.Intersection(udomain);
              if (domain.IsIncreasing())
            udomain.Set(domain.Min(), domain.Max());
              domain.Set(loop.m_pbox.m_min.y, loop.m_pbox.m_max.y);
              domain.Intersection(vdomain);
              if (domain.IsIncreasing())
            vdomain.Set(domain.Min(), domain.Max());
            }

            bool bUntrimmed = m_brep.FaceIsSurface(i);

            ArrayOnInterval intervals = new ArrayOnInterval();
            bool bRev = face.m_bRev;

            for (double u = 0.0; u < SURFACE_ARROW_COUNT; u += 1.0)
            {
              double d = u / (SURFACE_ARROW_COUNT - 1.0);
              double s = udomain.ParameterAt(d);

              intervals.SetCount(0);

              if (bUntrimmed || RhUtil.RhinoGetIsoIntervals(face, 1, s, intervals) > 0)
              {
            for (double v = 0.0; v < SURFACE_ARROW_COUNT; v += 1.0)
            {
              d = v / (SURFACE_ARROW_COUNT - 1.0);
              double t = vdomain.ParameterAt(d);

              bool bAdd = bUntrimmed;
              for (int k = 0; !bAdd && k < intervals.Count(); k++)
              {
                if (intervals[k].Includes(t))
                  bAdd = true;
              }

              if (bAdd)
              {
                On3dPoint pt = new On3dPoint();
                On3dVector du = new On3dVector();
                On3dVector dv = new On3dVector();
                On3dVector dir = new On3dVector();
                if (face.EvNormal(s, t, ref pt, ref du, ref dv, ref dir))
                {
                  m_points.Append(pt);
                  if (bRev)
                    dir.Reverse();
                  m_normals.Append(dir);
                }
              }
            }
              }
            }
              }
        }
예제 #14
0
        /// <summary>
        /// The one and only MakeBox
        /// </summary>
        static OnBrep MakeBox()
        {
            /*
             * This example demonstrates how to construct a OnBrep
             * with the topology shown below.
             *
             * v7_______e6_____v6
             |\             |\
             | e7           | e5
             |  \ ______e4_____\
             | e11  v4         |   v5
             |   |        e10   |
             |   |          |   |
             | v3---|---e2----v2   e9
             \   e8         \   |
             \ e3 |           e1 |
             \ |            \ |
             \  \v0_____e0_____\v1
             \
             */

            On3dPoint[] points = new On3dPoint[8];
            points[0] = new On3dPoint(0.0, 0.0, 0.0);
            points[1] = new On3dPoint(10.0, 0.0, 0.0);
            points[2] = new On3dPoint(10.0, 10.0, 0.0);
            points[3] = new On3dPoint(0.0, 10.0, 0.0);
            points[4] = new On3dPoint(0.0, 0.0, 10.0);
            points[5] = new On3dPoint(10.0, 0.0, 10.0);
            points[6] = new On3dPoint(10.0, 10.0, 10.0);
            points[7] = new On3dPoint(0.0, 10.0, 10.0);

            OnBrep brep = new OnBrep();

            int vi = 0, ei = 0, fi = 0, si = 0, c2i = 0;

            for (vi = 0; vi < 8; vi++)
            {
                brep.NewVertex(points[vi], 0.0);
            }

            for (ei = 0; ei < 4; ei++)
            {
                OnBrepVertex v0 = brep.m_V[ei];
                OnBrepVertex v1 = brep.m_V[(ei + 1) % 4];
                brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
                brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
            }
            for (ei = 4; ei < 8; ei++)
            {
                OnBrepVertex v0 = brep.m_V[ei];
                OnBrepVertex v1 = brep.m_V[ei == 7 ? 4 : (ei + 1)];
                brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
                brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
            }
            for (ei = 8; ei < 12; ei++)
            {
                OnBrepVertex v0 = brep.m_V[ei - 8];
                OnBrepVertex v1 = brep.m_V[ei - 4];
                brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
                brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
            }

            OnBrepBoxFaceInfo[] f = new OnBrepBoxFaceInfo[6];
            f[0] = new OnBrepBoxFaceInfo(0, 9, 4, 8, false, false, true, true);
            f[1] = new OnBrepBoxFaceInfo(1, 10, 5, 9, false, false, true, true);
            f[2] = new OnBrepBoxFaceInfo(2, 11, 6, 10, false, false, true, true);
            f[3] = new OnBrepBoxFaceInfo(3, 8, 7, 11, false, false, true, true);
            f[4] = new OnBrepBoxFaceInfo(3, 2, 1, 0, true, true, true, true);
            f[5] = new OnBrepBoxFaceInfo(4, 5, 6, 7, false, false, false, false);

            for (fi = 0; fi < 6; fi++)
            {
                OnBrepEdge   e0 = brep.m_E[f[fi].e[0]];
                OnBrepEdge   e1 = brep.m_E[f[fi].e[1]];
                OnBrepEdge   e2 = brep.m_E[f[fi].e[2]];
                OnBrepEdge   e3 = brep.m_E[f[fi].e[3]];
                OnBrepVertex v0 = brep.m_V[e0.get_m_vi(f[fi].bRev[0] ? 1 : 0)];
                OnBrepVertex v1 = brep.m_V[e1.get_m_vi(f[fi].bRev[1] ? 1 : 0)];
                OnBrepVertex v2 = brep.m_V[e2.get_m_vi(f[fi].bRev[2] ? 1 : 0)];
                OnBrepVertex v3 = brep.m_V[e3.get_m_vi(f[fi].bRev[3] ? 1 : 0)];

                si = brep.AddSurface(OnUtil.ON_NurbsSurfaceQuadrilateral(v0.point, v1.point, v2.point, v3.point));
                OnInterval s  = brep.m_S[si].Domain(0);
                OnInterval t  = brep.m_S[si].Domain(1);
                On2dPoint  p0 = new On2dPoint(s[0], t[0]);
                On2dPoint  p1 = new On2dPoint(s[1], t[0]);
                On2dPoint  p2 = new On2dPoint(s[1], t[1]);
                On2dPoint  p3 = new On2dPoint(s[0], t[1]);

                OnBrepFace face = brep.NewFace(si);
                OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face);

                loop.m_pbox.m_min.x = s[0];
                loop.m_pbox.m_min.y = t[0];
                loop.m_pbox.m_min.z = 0.0;

                loop.m_pbox.m_max.x = s[1];
                loop.m_pbox.m_max.y = t[1];
                loop.m_pbox.m_max.z = 0.0;

                // south side of surface
                c2i = brep.AddTrimCurve(new OnLineCurve(p0, p1));
                OnBrepTrim trim0 = brep.NewTrim(ref e0, f[fi].bRev[0], ref loop, c2i);
                trim0.set_m_tolerance(0, 0.0);
                trim0.set_m_tolerance(1, 0.0);
                trim0.m_type = (trim0.get_m_vi(0) != trim0.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
                trim0.m_iso  = IOnSurface.ISO.S_iso;

                // east side of surface
                c2i = brep.AddTrimCurve(new OnLineCurve(p1, p2));
                OnBrepTrim trim1 = brep.NewTrim(ref e1, f[fi].bRev[1], ref loop, c2i);
                trim1.set_m_tolerance(0, 0.0);
                trim1.set_m_tolerance(1, 0.0);
                trim1.m_type = (trim1.get_m_vi(0) != trim1.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
                trim1.m_iso  = IOnSurface.ISO.E_iso;

                // north side of surface
                c2i = brep.AddTrimCurve(new OnLineCurve(p2, p3));
                OnBrepTrim trim2 = brep.NewTrim(ref e2, f[fi].bRev[2], ref loop, c2i);
                trim2.set_m_tolerance(0, 0.0);
                trim2.set_m_tolerance(1, 0.0);
                trim2.m_type = (trim2.get_m_vi(0) != trim2.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
                trim2.m_iso  = IOnSurface.ISO.N_iso;

                // west side of surface
                c2i = brep.AddTrimCurve(new OnLineCurve(p3, p0));
                OnBrepTrim trim3 = brep.NewTrim(ref e3, f[fi].bRev[3], ref loop, c2i);
                trim3.set_m_tolerance(0, 0.0);
                trim3.set_m_tolerance(1, 0.0);
                trim3.m_type = (trim3.get_m_vi(0) != trim3.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
                trim3.m_iso  = IOnSurface.ISO.W_iso;
            }

            if (!brep.IsValid())
            {
                return(null);
            }

            return(brep);
        }