Exemplo n.º 1
0
        public ParticleSystem(int numParticles, Real step)
        {
            fNumParticles = numParticles;

            fPosition = new float3[numParticles];
            fVelocity = new float3[numParticles];
            fAcceleration = new float3[numParticles];
            fMass = new float[numParticles];
            fMassInverse = new float[numParticles];

            SetStep(step);

            // Setup variables used by the Runge-Kutta fourth-order solver
            m_akPTmp = new float3[numParticles];
            m_akDPTmp1 = new float3[numParticles];
            m_akDPTmp2 = new float3[numParticles];
            m_akDPTmp3 = new float3[numParticles];
            m_akDPTmp4 = new float3[numParticles];

            m_akVTmp = new float3[numParticles];
            m_akDVTmp1 = new float3[numParticles];
            m_akDVTmp2 = new float3[numParticles];
            m_akDVTmp3 = new float3[numParticles];
            m_akDVTmp4 = new float3[numParticles];
        }
Exemplo n.º 2
0
        static Constants()
        {
            var machEps = One;

            do
            {
                machEps *= Half;
            }
            while (One + Half * machEps != One);

            MachineEpsilon = machEps;
        }
Exemplo n.º 3
0
 /** 設定。
  */
 public void Reset(System.Single a_raw)
 {
     this.valuetype = ValueType.FloatingNumber;
     this.raw       = (FLOATING_NUMBER_TYPE)a_raw;
 }
Exemplo n.º 4
0
 internal override bool ShouldTravelLeft(T x, T y)
 {
     // ReSharper disable once CompareOfFloatsByEqualityOperator
     return(x == _point.X ? y < _point.Y : x < _point.X);
 }
Exemplo n.º 5
0
 public void setWarpZ(System.Single v)
 {
     TrinusProcessor.getUserSettings().lensParams.warpz = (v / 100f);
     trinusProcessor.setWarp(TrinusProcessor.getUserSettings().lensParams.warpx, TrinusProcessor.getUserSettings().lensParams.warpy, TrinusProcessor.getUserSettings().lensParams.warpz);
 }
Exemplo n.º 6
0
 public void setScaleY(System.Single v)
 {
     TrinusProcessor.getUserSettings().lensParams.scaley = (v / 100f);
     trinusProcessor.setScale(TrinusProcessor.getUserSettings().lensParams.scalex, TrinusProcessor.getUserSettings().lensParams.scaley);
 }
Exemplo n.º 7
0
 public void setIpd(System.Single v)
 {
     TrinusProcessor.getUserSettings().ipd = (v / 100f);
     trinusProcessor.setIpd(TrinusProcessor.getUserSettings().ipd);
 }
Exemplo n.º 8
0
 public static unsafe void PutFloat32(Float32 x, byte[] b, int pos)
 {
     Debug.Assert(b.Length - pos  >= sizeof(Float32));
       fixed (byte* sb = b) {
     *((Float32*)(sb + pos)) = x;
       }
 }
Exemplo n.º 9
0
 public override void Convert(byte[] data)
 {
     byte[] l_bytes = new byte[4];
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 0];
     }
     this.m_File_id_0 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 4];
     }
     this.m_Level_id_4 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 8];
     }
     this.m_TXMP_link_8 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 12];
     }
     this.m_TXMP_link_C = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 16];
     }
     this.m_TXMP_link_10 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 20];
     }
     this.m_TXMP_link_14 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 24];
     }
     this.m_TXMP_link_18 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 28];
     }
     this.m_Not_used_1C = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 32];
     }
     this.m_TXMP_link_20 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 36];
     }
     this.m_Not_used_24 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 40];
     }
     this.m_Not_used_28 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 44];
     }
     this.m_Not_used_2C = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 48];
     }
     this.m_Not_used_30 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 52];
     }
     this.m_Not_used_34 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 56];
     }
     this.m_Not_used_38 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 60];
     }
     this.m_Not_used_3C = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 64];
     }
     this.m_Not_used_40 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 68];
     }
     this.m_TXMP_link_44 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 72];
     }
     this.m_Not_used_48 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 76];
     }
     this.m_Not_used_4C = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 80];
     }
     this.m_Not_used_50 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 84];
     }
     this.m_Not_used_54 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 88];
     }
     this.m_Unknown_58 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 92];
     }
     this.m_Unknown_5C = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 96];
     }
     this.m_Unknown_60 = (System.Single)BinaryDatReader.l_float(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 100];
     }
     this.m_Not_used_64 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 128];
     }
     this.m_Unknown_80 = (System.Single)BinaryDatReader.l_float(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 132];
     }
     this.m_Not_used_84 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 160];
     }
     this.m_Unknown_A0 = (System.Single)BinaryDatReader.l_float(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 164];
     }
     this.m_Not_used_A4 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 192];
     }
     this.m_Unknown_C0 = (System.Single)BinaryDatReader.l_float(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 196];
     }
     this.m_Not_used_C4 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 224];
     }
     this.m_Unknown_E0 = (System.Single)BinaryDatReader.l_float(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 228];
     }
     this.m_Unknown_E4 = (System.Single)BinaryDatReader.l_float(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 232];
     }
     this.m_Unknown_E8 = (System.Single)BinaryDatReader.l_float(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 236];
     }
     this.m_Unknown_EC = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 240];
     }
     this.m_Unknown_F0 = (System.Int32)BinaryDatReader.l_int32(l_bytes, 4);
     for (int i = 0; i < 4; i++)
     {
         l_bytes[i] = data[i + 244];
     }
     this.m_Not_used_F4 = (System.Int32)BinaryDatReader.ConverterStub(l_bytes, 4);
 }
 public float[] GetTabStops(out System.Single& firstTabOffset)
 {
 }
Exemplo n.º 11
0
 public static Symbol ModScalar(Symbol lhs, mx_float scalar)
 {
     return(new Operator("_ModScalar").Set(lhs)
            .SetParam("scalar", scalar)
            .CreateSymbol());
 }
Exemplo n.º 12
0
 public static Symbol RDivScalar(mx_float scalar, Symbol rhs)
 {
     return(new Operator("_RDivScalar").Set(rhs)
            .SetParam("scalar", scalar)
            .CreateSymbol());
 }
Exemplo n.º 13
0
 protected virtual void OnJointBreak(System.Single breakForce)
 {
 }
Exemplo n.º 14
0
        /// <summary>
        /// Called when a joint attached to the same game object broke
        /// </summary>
#if LOG_ONJOINTBREAK
        protected virtual void OnJointBreak(System.Single breakForce) => Log("OnJointBreak", $"{this} [{GetInstanceID ()}] ({breakForce})");
Exemplo n.º 15
0
 public TimedFloat(global::RTC.TimedFloat source)
 {
     _Tm = Converter.RtcTimeToDateTime(source.tm);
     _Data = source.data;
 }
Exemplo n.º 16
0
 public void SetStep(Real step)
 {
     fStep = step;
     fHalfStep = step / 2;
     fSixthStep = step / 6;
 }
Exemplo n.º 17
0
        public void TrainTest(bool isTtrain, bool finetune)
        {
            Python.Initialize();
            Chainer.Initialize();

            int batchCount = Mother.Dice.Next(1, 50);
            int ioCount    = Mother.Dice.Next(1, 50);

            Real[,] input = Initializer.GetRandomValues <Real[, ]>(batchCount, ioCount);

            Real[,] dummyGy = Initializer.GetRandomValues <Real[, ]>(batchCount, ioCount);

            Real[] gamma = Initializer.GetRandomValues <Real[]>(ioCount);
            Real[] beta  = Initializer.GetRandomValues <Real[]>(ioCount);

            Real[] avgMean = Initializer.GetRandomValues <Real[]>(ioCount);
            Real[] avgVar  = Initializer.GetRandomValues <Real[]>(ioCount);

            //Chainer
            Chainer.Config["train"] = isTtrain;

            NChainer.BatchNormalization <Real> cBatchNormalization = new NChainer.BatchNormalization <Real>(ioCount, dtype: typeof(Real));

            cBatchNormalization.gamma = new Variable <Real>(gamma);
            cBatchNormalization.beta  = new Variable <Real>(beta);

            cBatchNormalization.avgMean = avgMean;
            cBatchNormalization.avgVar  = avgVar;

            Variable <Real> cX = new Variable <Real>(input);

            Variable <Real> cY = cBatchNormalization.Forward(cX, finetune);

            cY.Grad = dummyGy;

            cY.Backward();

            //KelpNet
            KelpNet.BatchNormalization <Real> batchNormalization = new BatchNormalization <Real>(ioCount, train: isTtrain, finetune: finetune);

            batchNormalization.Gamma.Data = gamma;
            batchNormalization.Beta.Data  = beta;

            batchNormalization.AvgMean.Data = avgMean;
            batchNormalization.AvgVar.Data  = avgVar;

            NdArray <Real> x = new NdArray <Real>(input, asBatch: true);

            NdArray <Real> y = batchNormalization.Forward(x)[0];

            y.Grad = dummyGy.Flatten();

            y.Backward();


            Real[] cYdata = ((Real[, ])cY.Data).Flatten();
            Real[] cXgrad = ((Real[, ])cX.Grad).Flatten();

            Real[] cGammaGrad = (Real[])cBatchNormalization.gamma.Grad;
            Real[] cBetaGrad  = (Real[])cBatchNormalization.beta.Grad;

            //許容範囲を算出
            Real delta = 0.00005f;

            //y
            Assert.AreEqual(cYdata.Length, y.Data.Length);
            for (int i = 0; i < y.Data.Length; i++)
            {
                Assert.AreEqual(cYdata[i], y.Data[i], delta);
            }

            //x.grad
            Assert.AreEqual(cXgrad.Length, x.Grad.Length);
            for (int i = 0; i < x.Grad.Length; i++)
            {
                Assert.AreEqual(cXgrad[i], x.Grad[i], delta);
            }

            //gamma.grad
            Assert.AreEqual(cGammaGrad.Length, batchNormalization.Gamma.Grad.Length);
            for (int i = 0; i < batchNormalization.Gamma.Grad.Length; i++)
            {
                Assert.AreEqual(cGammaGrad[i], batchNormalization.Gamma.Grad[i], delta);
            }

            //beta.grad
            Assert.AreEqual(cBetaGrad.Length, batchNormalization.Beta.Grad.Length);
            for (int i = 0; i < batchNormalization.Beta.Grad.Length; i++)
            {
                Assert.AreEqual(cBetaGrad[i], batchNormalization.Beta.Grad[i], delta);
            }
        }
Exemplo n.º 18
0
 public static void AreEqual(AmountType expected, AmountType actual)
 {
     Assert.AreEqual(0, AmountComparer.Instance.Compare(expected, actual));
 }
Exemplo n.º 19
0
 /** 値設定。
  *
  *      -3.40282347E+38 -- 3.40282347E+38
  *
  */
 public void SetSingle(System.Single a_value)
 {
     this.jsonstring = null;
     this.value.Reset(a_value);
 }
 /// <inheritdoc cref="System.Math.Sign(System.Single)" />
 public static System.Int32 Sign(this System.Single value)
 {
     return(System.Math.Sign(value));
 }
Exemplo n.º 21
0
        public virtual void OLEDragOver(ref MSMask.DataObject data, ref int effect, ref short button, ref short shift, ref System.Single x, ref System.Single y, ref short state)
        {
            MaskEdBoxEvents_OLEDragOverEvent oledragoverEvent = new MaskEdBoxEvents_OLEDragOverEvent(data, effect, button, shift, x, y, state);

            this.parent.RaiseOnOLEDragOver(this.parent, oledragoverEvent);
            data   = oledragoverEvent.data;
            effect = oledragoverEvent.effect;
            button = oledragoverEvent.button;
            shift  = oledragoverEvent.shift;
            x      = oledragoverEvent.x;
            y      = oledragoverEvent.y;
            state  = oledragoverEvent.state;
        }
Exemplo n.º 22
0
 public void setScreenX(System.Single v)
 {
     TrinusProcessor.getUserSettings().lensParams.screenx = (v / 100f);
     trinusProcessor.setScreenCenter(TrinusProcessor.getUserSettings().lensParams.screenx, TrinusProcessor.getUserSettings().lensParams.screeny);
 }
Exemplo n.º 23
0
 public MaskEdBoxEvents_OLEDragDropEvent(MSMask.DataObject data, int effect, short button, short shift, System.Single x, System.Single y)
 {
     this.data   = data;
     this.effect = effect;
     this.button = button;
     this.shift  = shift;
     this.x      = x;
     this.y      = y;
 }
Exemplo n.º 24
0
 public void setLensX(System.Single v)
 {
     TrinusProcessor.getUserSettings().lensParams.lensx = (v / 100f);
     trinusProcessor.setLensCenter(TrinusProcessor.getUserSettings().lensParams.lensx, TrinusProcessor.getUserSettings().lensParams.lensy);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Initialize a physical unit object that is the standard unit of the specific quantity
 /// </summary>
 /// <param name="symbol">Unit display symbol</param>
 public ConstantConverterUnit(string symbol) : base(true, symbol)
 {
     this.amountToStandardUnitFactor = Constants.One;
     this.standardAmountToUnitFactor = Constants.One;
 }
Exemplo n.º 26
0
 public void setChroma(System.Single v)
 {
     TrinusProcessor.getUserSettings().lensParams.chroma = (v / 100f);
     trinusProcessor.setChroma(TrinusProcessor.getUserSettings().lensParams.chroma);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Initialize a physical unit object
 /// </summary>
 /// <param name="symbol">Unit display symbol</param>
 /// <param name="toStandardUnitFactor">Amount converter factor from this unit to quantity's standard unit</param>
 // ReSharper disable once CompareOfFloatsByEqualityOperator
 public ConstantConverterUnit(string symbol, AmountType toStandardUnitFactor)
     : base(toStandardUnitFactor == Constants.One, symbol)
 {
     this.amountToStandardUnitFactor = toStandardUnitFactor;
     this.standardAmountToUnitFactor = Constants.One / toStandardUnitFactor;
 }
Exemplo n.º 28
0
 internal override bool ShouldTravelLeft(T x, T y, T edgeSlope)
 {
     return(ShouldTravelLeft(x, y));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Convert the amount from the current unit to the standard unit of the specified quantity
 /// </summary>
 /// <param name="amount">Amount in this unit</param>
 /// <returns>Amount converted to standard unit</returns>
 public override AmountType ConvertAmountToStandardUnit(AmountType amount)
 {
     return(this.amountToStandardUnitFactor * amount);
 }
Exemplo n.º 30
0
 public TimedFloat()
 {
     _Tm = default(System.DateTime);
     _Data = new System.Single();
 }
Exemplo n.º 31
0
 /// <summary>
 /// Convert a standard amount to this unit of the specified quantity
 /// to the current unit
 /// </summary>
 /// <param name="standardAmount">Standard amount of the current <see cref="IUnit.Quantity"/>.</param>
 /// <returns>Amount in this unit.</returns>
 public override AmountType ConvertStandardAmountToUnit(AmountType standardAmount)
 {
     return(this.standardAmountToUnitFactor * standardAmount);
 }
Exemplo n.º 32
0
 abstract protected float3 Acceleration (int i, Real fTime, float3[] position, float3[] velocity);
Exemplo n.º 33
0
        public void RandomTest(bool gpuEnable)
        {
            Python.Initialize();
            Chainer.Initialize();

            int batchCount = Mother.Dice.Next(1, 5);
            int inChCount  = Mother.Dice.Next(1, 5);
            int outChCount = Mother.Dice.Next(1, 5);
            int wideSize   = Mother.Dice.Next(8, 32);
            int heightSize = Mother.Dice.Next(8, 32);

            int kWidth  = Mother.Dice.Next(1, 5);
            int kHeight = Mother.Dice.Next(1, 5);

            int strideX = Mother.Dice.Next(1, 5);
            int strideY = Mother.Dice.Next(1, 5);

            int padX = Mother.Dice.Next(0, 5);
            int padY = Mother.Dice.Next(0, 5);

            int outputHeight = (heightSize - 1) * strideY + kHeight - padY * 2;
            int outputWidth  = (wideSize - 1) * strideX + kWidth - padX * 2;

            Real[,,,] input = Initializer.GetRandomValues <Real[, , , ]>(batchCount, inChCount, heightSize, wideSize);

            Real[,,,] dummyGy = Initializer.GetRandomValues <Real[, , , ]>(batchCount, outChCount, outputHeight, outputWidth);
            Real[,,,] w       = Initializer.GetRandomValues <Real[, , , ]>(inChCount, outChCount, kHeight, kWidth);

            Real[] b = Initializer.GetRandomValues <Real[]>(outChCount);

            //Chainer
            NChainer.Deconvolution2D <Real> cDeconvolotion2D = new NChainer.Deconvolution2D <Real>(
                inChCount, outChCount,
                new[] { kHeight, kWidth },
                new[] { strideY, strideX },
                new[] { padY, padX },
                false,
                new PyObject[] { outputHeight, outputWidth },
                w,
                b);

            Variable <Real> cX = new Variable <Real>(input);

            Variable <Real> cY = cDeconvolotion2D.Forward(cX);

            cY.Grad = dummyGy;

            cY.Backward();


            //KelpNet
            CL.Deconvolution2D <Real> deconvolution2D = new CL.Deconvolution2D <Real>(
                inChCount, outChCount,
                new [] { kWidth, kHeight },
                new [] { strideX, strideY },
                new [] { padX, padY },
                false, w, b, gpuEnable: gpuEnable);

            NdArray <Real> x = new NdArray <Real>(input, asBatch: true);

            NdArray <Real> y = deconvolution2D.Forward(x)[0];

            y.Grad = dummyGy.Flatten();

            y.Backward();


            Real[] cYdata = ((Real[, , , ])cY.Data.Copy()).Flatten();
            Real[] cXgrad = ((Real[, , , ])cX.Grad.Copy()).Flatten();

            Real[] cWgrad = ((Real[, , , ])cDeconvolotion2D.W.Grad).Flatten();
            Real[] cbgrad = (Real[])cDeconvolotion2D.b.Grad;

            //許容範囲を算出
            Real delta = 0.00001f;

            Assert.AreEqual(cYdata.Length, y.Data.Length);
            Assert.AreEqual(cXgrad.Length, x.Grad.Length);
            Assert.AreEqual(cWgrad.Length, deconvolution2D.Weight.Grad.Length);
            Assert.AreEqual(cbgrad.Length, deconvolution2D.Bias.Grad.Length);

            //y
            for (int i = 0; i < y.Data.Length; i++)
            {
                Assert.AreEqual(cYdata[i], y.Data[i], delta);
            }

            //x.grad
            for (int i = 0; i < x.Grad.Length; i++)
            {
                Assert.AreEqual(cXgrad[i], x.Grad[i], delta);
            }

            delta = 0.1f;
            //W.grad
            for (int i = 0; i < deconvolution2D.Weight.Grad.Length; i++)
            {
                Assert.AreEqual(cWgrad[i], deconvolution2D.Weight.Grad[i], delta);
            }

            //b.grad
            for (int i = 0; i < deconvolution2D.Bias.Grad.Length; i++)
            {
                Assert.AreEqual(cbgrad[i], deconvolution2D.Bias.Grad[i], delta);
            }
        }
Exemplo n.º 34
0
        public virtual void Update(Real fTime)
        {
            // Runge-Kutta fourth-order solver
            Real fHalfTime = fTime + fHalfStep;
            Real fFullTime = fTime + fStep;

            // first step
            int i;
            for (i = 0; i < fNumParticles; i++)
            {
                if (MassInverse[i] > (Real)0.0)
                {
                    m_akDPTmp1[i] = Velocity[i];
                    m_akDVTmp1[i] = Acceleration(i, fTime, Position, Velocity);
                }
            }
            for (i = 0; i < fNumParticles; i++)
            {
                if (MassInverse[i] > (Real)0.0)
                {
                    m_akPTmp[i] = Position[i] + fHalfStep * m_akDPTmp1[i];
                    m_akVTmp[i] = Velocity[i] + fHalfStep * m_akDVTmp1[i];
                }
                else
                {
                    m_akPTmp[i] = Position[i];
                    m_akVTmp[i] = Vector3D.Zero;
                }
            }

            // second step
            for (i = 0; i < fNumParticles; i++)
            {
                if (MassInverse[i] > (Real)0.0)
                {
                    m_akDPTmp2[i] = m_akVTmp[i];
                    m_akDVTmp2[i] = Acceleration(i, fHalfTime, m_akPTmp, m_akVTmp);
                }
            }
            for (i = 0; i < fNumParticles; i++)
            {
                if (MassInverse[i] > (Real)0.0)
                {
                    m_akPTmp[i] = Position[i] + fHalfStep * m_akDPTmp2[i];
                    m_akVTmp[i] = Velocity[i] + fHalfStep * m_akDVTmp2[i];
                }
                else
                {
                    m_akPTmp[i] = Position[i];
                    m_akVTmp[i] = float3.Zero;
                }
            }

            // third step
            for (i = 0; i < fNumParticles; i++)
            {
                if (MassInverse[i] > (Real)0.0)
                {
                    m_akDPTmp3[i] = m_akVTmp[i];
                    m_akDVTmp3[i] = Acceleration(i, fHalfTime, m_akPTmp, m_akVTmp);
                }
            }
            for (i = 0; i < fNumParticles; i++)
            {
                if (MassInverse[i] > (Real)0.0)
                {
                    m_akPTmp[i] = Position[i] + fStep * m_akDPTmp3[i];
                    m_akVTmp[i] = Velocity[i] + fStep * m_akDVTmp3[i];
                }
                else
                {
                    m_akPTmp[i] = Position[i];
                    m_akVTmp[i] = Vector3D.Zero;
                }
            }

            // fourth step
            for (i = 0; i < fNumParticles; i++)
            {
                if (MassInverse[i] > (Real)0.0)
                {
                    m_akDPTmp4[i] = m_akVTmp[i];
                    m_akDVTmp4[i] = Acceleration(i, fFullTime, m_akPTmp, m_akVTmp);
                }
            }
            for (i = 0; i < fNumParticles; i++)
            {
                if (MassInverse[i] > (Real)0.0)
                {
                    Position[i] += fSixthStep * (m_akDPTmp1[i] +
                        ((Real)2.0) * (m_akDPTmp2[i] + m_akDPTmp3[i]) + m_akDPTmp4[i]);
                    Velocity[i] += fSixthStep * (m_akDVTmp1[i] +
                        ((Real)2.0) * (m_akDVTmp2[i] + m_akDVTmp3[i]) + m_akDVTmp4[i]);
                }
            }
        }
Exemplo n.º 35
0
 // In the tree, left is "above", right is "below"
 internal override bool ShouldTravelLeft(T x, T y)
 {
     // We want to go left if we're above - i.e., to the left of the line travelling
     // from left to right.
     return(Geometry2D.FLeft(_leftEnd, _rightEnd, new Vector(x, y)));
 }
Exemplo n.º 36
0
 public static LDPoint interporate(LDPoint p1, LDPoint p2, ld_float factor)
 {
     var d = (p2 - p1) * factor;
     return p1 + d;
 }
Exemplo n.º 37
0
        /// <summary>
        /// Open an existing file
        /// </summary>
        public ErdasImageFile(string filename, RWFlag mode)
        {
            this.open = false;
            this.mode = mode;

            // if filename does not end in .gis or .lan throw exception
            string extension = Path.GetExtension(filename).ToLower();

            if (!(extension.Equals(".gis")) && !(extension.Equals(".lan")))
            {
                throw new System.ApplicationException("Erdas file must have either GIS or LAN as extension");
            }

            // open file
            this.file       = new FileStream(filename, FileMode.Open);
            this.fileReader = new BinaryReader(this.file);
            this.open       = true;

            try
            {
                // prepare to build metadata while reading
                Metadata metadata = new Metadata();

                // Read Header

                // if not start with "HEAD74" throw exception
                byte[] sentinel = fileReader.ReadBytes(6);
                if ((sentinel[0] != (byte)'H') ||
                    (sentinel[1] != (byte)'E') ||
                    (sentinel[2] != (byte)'A') ||
                    (sentinel[3] != (byte)'D') ||
                    (sentinel[4] != (byte)'7') ||
                    (sentinel[5] != (byte)'4'))
                {
                    throw new System.ApplicationException(filename + " is not an ERDAS 7.4 compatible image file");
                }

                // packing
                System.UInt16 ipack = this.fileReader.ReadUInt16();
                if ((ipack != 0) && (ipack != 2))
                {
                    throw new System.ApplicationException("Only 8 and 16 bit bands are supported by Erdas reader");
                }

                // nbands
                System.UInt16 nbands = this.fileReader.ReadUInt16();

                // unused
                byte[] unused = this.fileReader.ReadBytes(6);

                // icols
                System.UInt32 icols = this.fileReader.ReadUInt32();

                // irows
                System.UInt32 irows = this.fileReader.ReadUInt32();

                // xstart
                System.Int32 xstart = this.fileReader.ReadInt32();
                metadata[RASTER_ULX] = xstart;

                // ystart
                System.Int32 ystart = this.fileReader.ReadInt32();
                metadata[RASTER_ULY] = ystart;

                // unused
                unused = this.fileReader.ReadBytes(56);

                // maptyp
                System.UInt16 maptyp     = this.fileReader.ReadUInt16();
                string        projection = Projections.find(maptyp);
                if (projection != null)
                {
                    metadata[PROJECTION] = projection;
                }
                if (maptyp == 0)
                {
                    metadata[SCALE_UNITS] = "degrees";
                }
                else if (maptyp == 2)
                {
                    metadata[SCALE_UNITS] = "feet";
                }
                else
                {
                    metadata[SCALE_UNITS] = "meters";
                }

                // nclass : calc if needed but never has been in past
                System.UInt16 nclass = this.fileReader.ReadUInt16();

                // unused
                unused = this.fileReader.ReadBytes(14);

                // iautyp
                System.UInt16 iautyp = this.fileReader.ReadUInt16();

                // acre
                System.Single acre = this.fileReader.ReadSingle();

                // xmap
                System.Single xmap = this.fileReader.ReadSingle();
                metadata[WORLD_ULX] = xmap;

                // ymap
                System.Single ymap = this.fileReader.ReadSingle();
                metadata[WORLD_ULY] = ymap;

                // xcell
                System.Single xcell = this.fileReader.ReadSingle();
                metadata[X_SCALE] = xcell;

                // ycell
                System.Single ycell = this.fileReader.ReadSingle();
                metadata[Y_SCALE] = ycell;

                // construct instance variables based upon hedaer info
                this.dimensions = new Dimensions((int)irows, (int)icols);
                if (ipack == 0)
                {
                    this.bandType = System.TypeCode.Byte;
                    this.bandSize = 1;
                }
                else  // ipack == 2 due to earlier screening
                {
                    this.bandType = System.TypeCode.UInt16;
                    this.bandSize = 2;
                }
                this.bandCount   = nbands;
                this.currPixel   = 0;
                this.totalPixels = (int)irows * (int)icols;
                this.metadata    = metadata;

                if (mode == RWFlag.Write)
                {
                    this.fileReader.Close();
                    this.fileReader = null;
                    // need to reopen stream - fileReader.Close() shuts it
                    this.file       = new FileStream(filename, FileMode.Open);
                    this.fileWriter = new BinaryWriter(this.file);
                }
            }
            catch (System.Exception)
            {
                Close();
                throw;
            }
        }
Exemplo n.º 38
0
        RWFlag mode;              // file open mode: Read or Write

        /// <summary>
        /// Create a file given specs
        /// </summary>
        public ErdasImageFile(string filename,
                              Dimensions dimensions,
                              int bandCount,
                              System.TypeCode bandType,
                              IMetadata metadata)
        {
            // set instance variables
            this.open        = false;
            this.mode        = RWFlag.Write;
            this.dimensions  = dimensions;
            this.bandType    = bandType;
            this.bandCount   = bandCount;
            this.currPixel   = 0;
            this.totalPixels = dimensions.Rows * dimensions.Columns;
            this.metadata    = metadata;

            // if filename does not end in .gis or .lan throw exception
            string extension = Path.GetExtension(filename).ToLower();

            if (!(extension.Equals(".gis")) && !(extension.Equals(".lan")))
            {
                throw new System.ApplicationException("Erdas file must have either GIS or LAN as extension");
            }

            // if dimensions are messed up throw exception
            if ((dimensions.Rows < 1) || (dimensions.Columns < 1))
            {
                throw new System.ApplicationException("Erdas file given invalid dimensions");
            }

            // if bandCount messed up throw exception
            if ((bandCount < 1) || (bandCount > 0xffff))
            {
                throw new System.ApplicationException("Erdas file given invalid band count");
            }

            // more bandCount checking
            if (extension.Equals(".gis"))
            {
                if (bandCount > 1)
                {
                    throw new System.ApplicationException("Erdas GIS files cannot support multiband images");
                }
                if (bandType != System.TypeCode.Byte)
                {
                    throw new System.ApplicationException("Erdas GIS files only suupport byte for bandtype");
                }
            }

            // if bandType not System.Byte or System.UInt16 throw exception
            if (bandType == System.TypeCode.Byte)
            {
                this.bandSize = 1;
            }
            else if (bandType == System.TypeCode.UInt16)
            {
                this.bandSize = 2;
            }
            else
            {
                throw new System.ApplicationException("Erdas file given unsupported band type");
            }

            // open file for writing
            this.file       = new FileStream(filename, FileMode.OpenOrCreate);
            this.fileWriter = new BinaryWriter(this.file);
            this.open       = true;

            // write header (using metadata whenever possible)

            try
            {
                // sentinel
                byte[] sentinel = new byte[6];
                sentinel[0] = (byte)'H';
                sentinel[1] = (byte)'E';
                sentinel[2] = (byte)'A';
                sentinel[3] = (byte)'D';
                sentinel[4] = (byte)'7';
                sentinel[5] = (byte)'4';
                this.fileWriter.Write(sentinel);

                // packing
                System.UInt16 ipack;
                if (bandType == System.TypeCode.Byte)
                {
                    ipack = 0;
                }
                else
                {
                    ipack = 2;
                }
                this.fileWriter.Write(ipack);

                // nbands
                System.UInt16 nbands = (System.UInt16)bandCount;
                this.fileWriter.Write(nbands);

                // unused
                for (int i = 0; i < 6; i++)
                {
                    this.fileWriter.Write((byte)0);
                }

                // icols
                System.UInt32 icols = (System.UInt32)dimensions.Columns;
                this.fileWriter.Write(icols);

                // irows
                System.UInt32 irows = (System.UInt32)dimensions.Rows;
                this.fileWriter.Write(irows);

                // xstart
                System.Int32 xstart = 0;
                if ((metadata != null) &&
                    (metadata.TryGetValue <System.Int32>(RASTER_ULX, ref xstart)))
                {
                }
                this.fileWriter.Write(xstart);

                // ystart
                System.Int32 ystart = 0;
                if ((metadata != null) &&
                    (metadata.TryGetValue <System.Int32>(RASTER_ULY, ref ystart)))
                {
                }
                this.fileWriter.Write(ystart);

                // unused
                for (int i = 0; i < 56; i++)
                {
                    this.fileWriter.Write((byte)0);
                }

                // maptyp
                System.UInt16 maptyp     = 99; // 99 means NONE
                string        projection = null;
                if ((metadata != null) &&
                    (metadata.TryGetValue <string>(PROJECTION, ref projection)))
                {
                    int projNum = Projections.find(projection);
                    if (projNum != -1)
                    {
                        maptyp = (System.UInt16)projNum;
                    }
                }
                this.fileWriter.Write(maptyp);

                // nclass : calc if needed but never has been in past
                System.UInt16 nclass = 0;
                this.fileWriter.Write(nclass);

                // unused
                for (int i = 0; i < 14; i++)
                {
                    this.fileWriter.Write((byte)0);
                }

                // iautyp : first need xcell and ycell and then acre
                System.Single xcell = 0;
                if ((metadata != null) &&
                    (metadata.TryGetValue <System.Single>(X_SCALE, ref xcell)))
                {
                }
                if (maptyp == 99)
                {
                    xcell = 0;
                }
                System.Single ycell = 0;
                if ((metadata != null) &&
                    (metadata.TryGetValue <System.Single>(Y_SCALE, ref ycell)))
                {
                }
                if (maptyp == 99)
                {
                    ycell = 0;
                }
                System.UInt16 iautyp = 0;
                System.Single acre   = 0;
                switch (maptyp) // iautyp depends upon maptyp indirectly
                {
                case 0:         // Lat/Long -> dist unit == degrees
                    iautyp = 0; // default to no area unit
                    break;

                case 2:         // State Plane ->  dist unit == feet
                    iautyp = 1; // default to acres
                    acre   = xcell * ycell;
                    // acre = sq.feet at this pt
                    //   so now convert to acres
                    acre = (float)((double)acre * 0.0000229568411386593);
                    break;

                default:        //  dist unit == meters
                    iautyp = 2; // default to hectares
                    acre   = xcell * ycell;
                    // acre = sq.meters at this pt
                    //   so now convert to hectares
                    acre *= 0.0001f;
                    break;
                }
                this.fileWriter.Write(iautyp);

                // acre
                this.fileWriter.Write(acre);

                // xmap
                System.Single xmap = 0;
                if ((metadata != null) &&
                    (metadata.TryGetValue <System.Single>(WORLD_ULX, ref xmap)))
                {
                }
                this.fileWriter.Write(xmap);

                // ymap
                System.Single ymap = 0;
                if ((metadata != null) &&
                    (metadata.TryGetValue <System.Single>(WORLD_ULY, ref ymap)))
                {
                }
                this.fileWriter.Write(ymap);

                // xcell
                this.fileWriter.Write(xcell);

                // ycell
                this.fileWriter.Write(ycell);

                // now create pixel data as zeroes for now
                // many nested for loops avoids index calc overflows
                for (int row = 0; row < dimensions.Rows; row++)
                {
                    for (int bandNum = 0; bandNum < this.bandCount; bandNum++)
                    {
                        for (int col = 0; col < dimensions.Columns; col++)
                        {
                            for (int byteNum = 0; byteNum < this.bandSize; byteNum++)
                            {
                                this.fileWriter.Write((byte)0);
                            }
                        }
                    }
                }
            }
            catch (System.Exception)
            {
                Close();
                throw;
            }
        }
Exemplo n.º 39
0
 public void setFov(System.Single v)
 {
     trinusProcessor.setFov((int)v);
 }
Exemplo n.º 40
0
		static extern void gtk_widget_style_get (GtkWidgetPointer widget, string property, out gfloat value, IntPtr nullTerminator);
 /// <inheritdoc cref="System.Math.Min(System.Single, System.Single)" />
 public static System.Single Min(this System.Single val1, System.Single val2)
 {
     return(System.Math.Min(val1, val2));
 }