예제 #1
0
 public SamplingSurfaceNormalDataPointsFilter(
     SamplingMethod samplingMethod = SamplingMethod.RandomSampling,
     float ratio     = 0.5f,
     int knn         = 7,
     float maxBoxDim = float.PositiveInfinity)
 {
     this.samplingMethod = samplingMethod;
     this.ratio          = ratio;
     this.knn            = knn;
     this.maxBoxDim      = maxBoxDim;
 }
        public void ResampleChunks(SamplingMethod samplingFunction, float noiseOfffset = 0f)
        {
            // Edit Data
            for (int i = 0; i < voxelChunks.Length; i++)
            {
                var currentChunk = voxelChunks[i];
                for (int j = 0; j < voxelChunks[i].Voxels.Length; j++)
                {
                    var currentVoxel = currentChunk.Voxels[j];
                    currentVoxel.Value = samplingFunction(currentChunk.Position + currentVoxel.Position + Vector3.right * noiseOfffset);
                }
            }

            TriangulateVoxels();
        }
예제 #3
0
 public float Sample(Vector2D pt, SamplingMethod mode)
 {
     if (mode == SamplingMethod.Lerp)
     {
         return(SampleLerp(pt));
     }
     else if (mode == SamplingMethod.SmartLerp)
     {
         return(SampleSmart(pt, 1.0f));
     }
     else
     {
         return(Sample(pt));
     }
 }
예제 #4
0
        public static float Sum(SamplingMethod method, Vector3 point, float frequency, int octaves, float lacunarity, float persistence)
        {
            float sum       = method(point);
            float amplitude = 1f;
            float range     = 1f;

            for (int o = 1; o < octaves; o++)
            {
                frequency *= lacunarity;
                amplitude *= persistence;
                range     += amplitude;
                sum       += method(point) * amplitude;
            }
            return(sum / range);
        }
예제 #5
0
        public MCSimulationResults(long iteration, long numberOfHits, Coin coin, SquareTile squareTile, SamplingMethod samplingMethod)
        {
            if (iteration <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(iteration));
            }
            if (numberOfHits <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfHits));
            }
            Iteration    = iteration;
            NumberOfHits = numberOfHits;
            Probability  = (double)NumberOfHits / Iteration;

            Coin           = coin;
            SquareTile     = squareTile;
            SamplingMethod = samplingMethod;
        }
예제 #6
0
        public void Run(Coin coin, SquareTile squareTile, SamplingMethod method)
        {
            if (coin == null)
            {
                throw new ArgumentNullException(nameof(coin));
            }
            if (squareTile == null)
            {
                throw new ArgumentNullException(nameof(squareTile));
            }

            var samplingEngine = Random2DEngineService.GetEngine(method);

            if (samplingEngine == null)
            {
                throw new ArgumentException("Sampling method cannot be found!");
            }

            var  samples       = samplingEngine.GetDoubles().Take(this.SimulationSettings.NumberTrials);
            long nNumberOfHits = 0;
            long nIterations   = 0;

            foreach (Tuple <double, double> xySample in samples)
            {
                ++nIterations;
                var coordinateOnSquareTile = squareTile.TransformCoordinates(xySample);
                var dX = coordinateOnSquareTile.Item1;
                var dY = coordinateOnSquareTile.Item2;

                if (squareTile.CollisionCheckWithCoin(dX, dY, coin.Radius))
                {
                    ++nNumberOfHits;
                    if (nIterations % SimulationSettings.ReportEveryIteration == 0)
                    {
                        OnResultsUpdated(new MCSimulationResults(nIterations,
                                                                 nNumberOfHits, coin, squareTile, method));
                    }
                }
            }

            var probability = (double)nNumberOfHits / nIterations;

            OnFinished(new MCSimulationResults(nIterations, nNumberOfHits, coin, squareTile, method));
        }
예제 #7
0
        public void RegenerateChunks(SamplingMethod samplingFunction, float noiseOffset = 0)
        {
            // Edit Data
            for (int i = 0; i < voxelChunks.Length; i++)
            {
                var currentChunk = voxelChunks[i];
                for (int j = 0; j < voxelChunks[i].Voxels.Length; j++)
                {
                    var currentVoxel = currentChunk.Voxels[j];
                    currentVoxel.Value = samplingFunction(currentChunk.Position + currentVoxel.Position + (Vector3.right * noiseOffset));
                }
            }

            // Triangulate
            TriangulateData(voxelChunks, out MeshData[] meshDataChunks);
            for (int i = 0; i < voxelChunks.Length; i++)
            {
                voxelChunks[i].MeshFilter.mesh = meshDataChunks[i].ToMesh();
            }
        }
        protected void CreateMethodByMetadataDictionary()
        {
            _maxEndLine       = 0;
            _methodDictionary = _aggregators.Select(
                methodAgr =>
            {
                int startLine;
                int endLine;
                bool isConstructor = methodAgr.MethodMd.Name.EndsWith("ctor");
                if (isConstructor)
                {
                    FindConstructorBody(methodAgr.MethodMd, out startLine,
                                        out endLine);
                }
                else
                {
                    startLine =
                        methodAgr.MethodMd.GetSourceLocations().First().StartLine;
                    endLine = methodAgr.MethodMd.GetSourceLocations().Last().EndLine;
                }
                _maxEndLine = Math.Max(_maxEndLine, endLine);

                Method method = new SamplingMethod(
                    methodAgr.FunctionId,
                    methodAgr.MethodMd.Name,
                    startLine,
                    endLine - startLine + 1,
                    methodAgr.MethodMd.Class.Name,
                    methodAgr.MethodMd.GetSourceFilePath(),
                    new UintValue(methodAgr.StackTopOccurrenceCount),
                    new DoubleValue(methodAgr.TimeWallClock));

                return(new KeyValuePair <MethodMetadata, Method>(methodAgr.MethodMd,
                                                                 method));
            }).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
        }
예제 #9
0
 public static extern bool SetSamplingParameters(IntPtr ptr, double clockFreq, SamplingMethod method, double sampleFreq, double passFreq = -1, double filterScale = 0.97);
예제 #10
0
        public static double[][] GetPatches(double[,] spectrogram, int patchWidth, int patchHeight, int numberOfPatches, SamplingMethod samplingMethod)
        {
            List <double[]> patches = new List <double[]>();

            if (samplingMethod == SamplingMethod.Sequential)
            {
                patches = GetSequentialPatches(spectrogram, patchWidth, patchHeight);
            }
            else
            {
                if (samplingMethod == SamplingMethod.Random)
                {
                    patches = GetRandomPatches(spectrogram, patchWidth, patchHeight, numberOfPatches);
                }
                else
                {
                    if (samplingMethod == SamplingMethod.OverlappedRandom)
                    {
                        patches = GetOverlappedRandomPatches(spectrogram, patchWidth, patchHeight, numberOfPatches);
                    }
                }
            }

            return(patches.ToArray());
        }
 public IRandom2DEngine GetEngine(SamplingMethod method)
 {
     return(_dicEngines.TryGetValue(method, out IRandom2DEngine engine) ? _dicEngines[method] : null);
 }
예제 #12
0
        public static float Perlin3DFractal(Vector3 pos)
        {
            SamplingMethod method = Perlin3D;

            return(Sum(method, pos, NoiseFrequency, NoiseOctaves, NoiseLacunarity, NoisePersistence));
        }