public LineSource(Curve SrcPath, String Code, int el_m, int SrcID, Phase_Regime ph)
                :base(new double[8]{60, 49, 41, 35, 31, 28, 26, 24}, new Point3d(0,0,0), ph, SrcID)
            {
                string type = SrcPath.GetUserString("SourceType");
                
                if (type == "Aircraft (ANCON derived)")
                {
                    double velocity = double.Parse(SrcPath.GetUserString("Velocity"));
                    double delta = double.Parse(SrcPath.GetUserString("delta"));
                    D = new ANCON(delta, velocity);
                }
                else D = new Simple();

                samplespermeter = el_m;
                Curve = SrcPath;

                //Divide curve up in ~equal length segments.
                Samples = Curve.DivideEquidistant(1.0 / (double)samplespermeter);

                Level = Utilities.PachTools.DecodeSourcePower(Code);
                Power = new double[8];
            
                double PowerMod = Curve.GetLength() / (double)Samples.Length;
                for (int oct = 0; oct < 8; oct++) Power[oct] = 1E-12 * Math.Pow(10, .1 * Level[oct]) * PowerMod;
            }
Ejemplo n.º 2
0
 private static Curve[][] Rotate(Curve[][] input)
 {
     //Rotate 2d array of curves(flips rows and columns)
     int length = input.GetLength(0);
     Curve[][] retVal = new Curve[length][];
     for (int x = 0; x < length; x++)
     {
         retVal[x] = input.Select(p => p[x]).ToArray();
     }
     return retVal;
 }
        public Edge_Curved(ref IEnumerable<Hare.Geometry.Point> SPT, ref IEnumerable<Hare.Geometry.Point> RPT, Environment.Medium_Properties Env_Props, Brep[] B, int[] Brep_Index, Curve i)
            : base(B, i)
        {
            //if (i.IsLinear()) throw new Exception("Curved Edge object called for straight edge.");
            //Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(i);
            ParentBreps = Brep_Index;
            
            //Get the open wedge angle. This needs the source location, and occlusion info...
            //Assuming tangent angles are always correctly oriented...
            //Vector Z_Dir = PointA - PointB;
            //double length = Z_Dir.Length();
            //Z_Dir.Normalize();
            //double MinAngle = double.PositiveInfinity;
            //Hare.Geometry.Point[] Dpt = new Hare.Geometry.Point[0];

            //Find the secondary source spacing DeltaZ
            /// 1/4 wavelength substituted for now...
            double fs = 88200; //Hz.
            //double DeltaZ = speed_of_sound / (fs * Math.Cos(MinAngle));//TODO: Adjust depending on distance from source to receiver... (nearest, farthest?
           
            /////
            //double El_Ct = Math.Ceiling(i.GetLength() / DeltaZ);
            //DeltaZ = i.GetLength() / El_Ct;
            //List<Point3d> Pts;
            double length = Env_Props.Sound_Speed(i.PointAtStart)/ (8 * fs);
            double total_length = i.GetLength();
            double t;
            
            //for (int j = 1; j < Pts.Length; j++)
            while (true)
            {
                if (!i.LengthParameter(length, out t)) break;
                Plane P;
                i.PerpendicularFrameAt(t, out P);
                Curve[] Csects1, Csects2;
                Point3d[] Psects;

                //double DeltaZ = Env_Props.Sound_Speed(Point3d.Origin) / (4 * fs);
                Rhino.Geometry.Intersect.Intersection.BrepPlane(B[0], P, 0.001, out Csects1, out Psects);
                Rhino.Geometry.Intersect.Intersection.BrepPlane(B[1], P, 0.001, out Csects2, out Psects);
                Vector3d[] Tangents = new Vector3d[2];
                ///Control Start Point of curve
                if ((Csects1[0].PointAtStart.X * P.Origin.X + Csects1[0].PointAtStart.Y * P.Origin.Y + Csects1[0].PointAtStart.Z * P.Origin.Z) < 0.00001) Csects1[0].Reverse();
                if ((Csects2[0].PointAtStart.X * P.Origin.X + Csects2[0].PointAtStart.Y * P.Origin.Y + Csects2[0].PointAtStart.Z * P.Origin.Z) < 0.00001) Csects2[0].Reverse();
                ///Get Tangent Vector
                Tangents[0] = (Csects1[0].PointAtNormalizedLength(0.05) - P.Origin);
                Tangents[0].Unitize();
                Tangents[1] = (Csects2[0].PointAtNormalizedLength(0.05) - P.Origin);
                Tangents[1].Unitize();
                Hare.Geometry.Vector[] HTangents = new Hare.Geometry.Vector[2] { new Hare.Geometry.Vector(Tangents[0].X, Tangents[0].Y, Tangents[0].Z), new Hare.Geometry.Vector(Tangents[1].X, Tangents[1].Y, Tangents[1].Z) };
                ///Get Normal
                double up, vp;
                ComponentIndex CI;
                Point3d outPt;
                Vector3d[] Normals = new Vector3d[2];
                //Point3d CPT = Utilities.PachTools.HPttoRPt(Z_mid);
                B[0].ClosestPoint(P.Origin, out outPt, out CI, out up, out vp, 0.01, out Normals[0]);
                B[1].ClosestPoint(P.Origin, out outPt, out CI, out up, out vp, 0.01, out Normals[1]);
                Hare.Geometry.Vector[] HNormals = new Hare.Geometry.Vector[2] { new Hare.Geometry.Vector(Normals[0].X, Normals[0].Y, Normals[0].Z), new Hare.Geometry.Vector(Normals[1].X, Normals[1].Y, Normals[1].Z) };
                //// Get Vector Tangents.
                //Hare.Geometry.Point Pt1 = new Hare.Geometry.Point(Pts[j-1].X, Pts[j-1].Y, Pts[j-1].Z);
                //Hare.Geometry.Point Pt2 = new Hare.Geometry.Point(Pts[j].X, Pts[j].Y, Pts[j].Z);
                double Delta_Z = Env_Props.Sound_Speed(P.Origin) / (4 * fs);//TODO: Adjust depending on distance from source to receiver... (nearest, farthest?)
                Sources.Add(new EdgeSource(Edge.Rigid, Utilities.PachTools.RPttoHPt(P.Origin), Delta_Z, HTangents));

                length += Delta_Z;
            }
        }
Ejemplo n.º 4
0
        public override void draw(bool isTop)
        {
            if (!isTop)
            {
                return;
            }

            // Clean this monstrosity
            OpenTK.Vector4 controller_p      = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
            OpenTK.Vector4 controller_pZ     = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -1, 1);
            Point3d        controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)));
            Point3d        controller_pZRhin = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_pZ.X, controller_pZ.Y, controller_pZ.Z)));

            Rhino.Geometry.Vector3d direction = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_pRhino.X, controller_pZRhin.Y - controller_pRhino.Y, controller_pZRhin.Z - controller_pRhino.Z);

            if (drawnType != DrawnType.In3D)
            {
                UtilOld.rayCasting(controller_pRhino, direction, ref rayCastingObjs, ref projectP, out targetPRhObjID);
            }
            else
            {
                projectP = controller_pRhino;
            }

            //only snap for the first drawing point
            if (currentState != State.DRAW && snapPointsList.Count > 0)
            {
                if (UtilOld.snapToPoints(ref projectP, ref snapPointsList) != -1)
                {
                    isSnap = true;
                    snapPointSN.material = new Material.SingleColorMaterial(1, 1, 1, 1);
                }
                else
                {
                    isSnap = false;
                    snapPointSN.material = new Material.SingleColorMaterial(0, 1, 0, 1);
                }
            }

            //
            Vector3 projectPVR = UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(projectP));

            if (drawnType != DrawnType.In3D)
            {
                OpenTK.Matrix4 t = OpenTK.Matrix4.CreateTranslation(projectPVR);
                t.Transpose();
                drawPoint.transform = t;
                if (targetPRhObjID != Guid.Empty)
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 1);
                }
                else
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 0);
                }
            }



            //moving XYZ planes
            if (currentState == State.MOVEPLANE)
            {
                OpenTK.Vector3 controllerVector = UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)) - UtilOld.RhinoToOpenTKPoint(moveControlerOrigin);

                float translate    = OpenTK.Vector3.Dot(controllerVector, UtilOld.RhinoToOpenTKVector(planeNormal)) / (float)planeNormal.Length;
                float relTranslate = translate - lastTranslate;
                lastTranslate = translate;

                Matrix4 transM = Matrix4.CreateTranslation(new Vector3(relTranslate * (float)planeNormal.X, relTranslate * (float)planeNormal.Y, relTranslate * (float)planeNormal.Z));
                transM.Transpose();
                UtilOld.updateRhinoObjectSceneNode(ref mScene, ref movePlaneRef, UtilOld.OpenTKToRhinoTransform(transM));
            }



            if (currentState != State.DRAW)
            {
                return;
            }
            else
            {
                //checking the projectPoint is valid
                if (drawnType != DrawnType.In3D && targetPRhObjID == Guid.Empty)
                {
                    return;
                }
            }

            //drawing curve section belows
            if (shouldSnap && ((Geometry.GeometryStroke)stroke_g).mNumPoints == 0)
            {
                ((Geometry.GeometryStroke)stroke_g).addPoint(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(snapPointsList[0])));
            }

            ((Geometry.GeometryStroke)stroke_g).addPoint(projectPVR);
            rhinoCurvePoints.Add(projectP);

            if (((Geometry.GeometryStroke)stroke_g).mNumPrimitives == 1)
            {
                strokeSN = new SceneNode("Stroke", ref stroke_g, ref stroke_m);
                UtilOld.addSceneNode(ref mScene, ref strokeSN);
            }

            //create rhino curve for comoputing length of the curve
            if (rhinoCurvePoints.Count == 2)
            {
                if (shouldSnap)
                {
                    //make sure the first point is the snap point if necessary
                    if (UtilOld.computePointDistance(UtilOld.RhinoToOpenTKPoint(rhinoCurvePoints[0]), UtilOld.RhinoToOpenTKPoint(snapPointsList[0])) != 0)
                    {
                        rhinoCurvePoints.Insert(0, snapPointsList[0]);
                    }
                }
                rhinoCurve = Rhino.Geometry.Curve.CreateInterpolatedCurve(rhinoCurvePoints.ToArray(), 3);
            }
            else if (rhinoCurvePoints.Count > 2)
            {
                double length1 = rhinoCurve.GetLength();
                rhinoCurve = Rhino.Geometry.Curve.CreateInterpolatedCurve(rhinoCurvePoints.ToArray(), 3);
                double length2 = rhinoCurve.GetLength();
                displacement = displacement + (float)Math.Abs(length2 - length1);

                //TODO-Debug why it failed
                //rhinoCurve = rhinoCurve.Extend(Rhino.Geometry.CurveEnd.End, Rhino.Geometry.CurveExtensionStyle.Line, rhinoCurvePoints[rhinoCurvePoints.Count - 1]);

                //dynamic render model
                //TODO: finding the right curve
                if (dynamicRender != "none" && backgroundStart == false && displacement > 10)
                {
                    backgroundStart = true;
                    R = d.BeginInvoke(new AsyncCallback(modelCompleted), null);
                }
            }
        }