コード例 #1
0
            public Overlap?Split(Overlap o, out bool isRemoved)
            {
                if (o.A <= A && o.B >= B)
                {
                    isRemoved = true;
                    return(null);
                }

                isRemoved = false;
                if (A < o.A && B > o.B)
                {
                    var temp = B;
                    B = o.A;

                    return(new Overlap(o.B, temp, C));
                }
                else if (A < o.A)
                {
                    B = o.A;
                }
                else if (B > o.B)
                {
                    A = o.B;
                }

                return(null);
            }
コード例 #2
0
        private static MutableGene GetFlattenedGene(MutableGene seedGene, List <MutableGene> genesWithSameGeneId,
                                                    int overlapStart, int overlapEnd)
        {
            var  flattenedGene = MutableGene.Clone(seedGene);
            bool useOverlap    = overlapStart != -1 && overlapEnd != -1;

            foreach (var gene in genesWithSameGeneId)
            {
                if (gene.Invalid || flattenedGene.OnReverseStrand != gene.OnReverseStrand ||
                    flattenedGene.ReferenceIndex != gene.ReferenceIndex)
                {
                    continue;
                }

                if (useOverlap && !Overlap.Partial(overlapStart, overlapEnd, gene.Start, gene.End))
                {
                    continue;
                }
                if (!useOverlap && !Overlap.Partial(flattenedGene.Start, flattenedGene.End, gene.Start, gene.End))
                {
                    continue;
                }

                UpdateCoordinates(gene, flattenedGene);
                gene.Invalid = true;
            }

            return(flattenedGene);
        }
コード例 #3
0
    public int registerOverlap(int i, bool d, string t)
    {
        Overlap ov = new Overlap(i, d, t);

        overlaps.Add(ov);
        return(overlaps.Count);
    }
コード例 #4
0
ファイル: Swap.cs プロジェクト: UnforeseenOcean/Gibbed.IO
        public static float Swap(this float value)
        {
            var overlap = new Overlap <float, uint>(value);

            overlap.AsB = overlap.AsB.Swap();
            return(overlap.AsA);
        }
コード例 #5
0
ファイル: TestOverlap.cs プロジェクト: FanZhangSX/Aderant
        public void TestWholeProcessByNullString()
        {
            var overlap = new Overlap((string)null);

            Assert.AreEqual(overlap.MergeOverlap(), string.Empty);
            overlap.Dispose();
        }
コード例 #6
0
ファイル: Swap.cs プロジェクト: UnforeseenOcean/Gibbed.IO
        public static double Swap(this double value)
        {
            var overlap = new Overlap <double, ulong>(value);

            overlap.AsB = overlap.AsB.Swap();
            return(overlap.AsA);
        }
コード例 #7
0
        private void AnnotateAltAllele(VariantFeature variant, VariantAlternateAllele altAllele, Transcript transcript)
        {
            // handle upstream or downstream transcripts
            if (!Overlap.Partial(transcript.Start, transcript.End, altAllele.Start, altAllele.End))
            {
                return;
            }

            var ta = new TranscriptAnnotation
            {
                AlternateAllele         = altAllele,
                HasValidCdnaCodingStart = false,
                HasValidCdsStart        = false
            };

            MapCdnaCoordinates(transcript, ta, altAllele);
            _pianoVariant.CreateAnnotationObject(transcript, altAllele);

            GetCodingAnnotations(transcript, ta, _compressedSequence);
            var consequence = new Consequences(new VariantEffect(ta, transcript, variant.InternalCopyNumberType));

            consequence.DetermineVariantEffects(variant.InternalCopyNumberType);

            _pianoVariant.FinalizeAndAddAnnotationObject(transcript, ta, consequence.GetConsequenceStrings());
        }
コード例 #8
0
        /// <summary>
        /// Whether the arc has a valid placement.
        /// A placement is valid if:
        /// 1. No Arc exists in the field
        /// 2. Arc length is equal to field length
        /// 3. Arcs do not overlap
        /// </summary>
        /// <param name="arc"></param>
        /// <returns></returns>
        public bool ValidPlacement(Arc arc)
        {
            var noArc   = !HasArc;
            var overlap = Overlap.Any(field => field.HasArc);

            return(noArc && arc.Length == Length && !overlap);
        }
コード例 #9
0
ファイル: PitchShiftTDSOLA.cs プロジェクト: tmokmss/LLSynth
        private void PitchShiftTDv(short[] datain, out short[] dataout)
        {
            var length = datain.Length;
            var fratio = FormantShiftRate;
            var newlen = (int)Math.Round(length / fratio);
            var temp   = new double[newlen];

            for (var i = 0; i < Math.Min(newlen, length); i++)
            {
                temp[i] = datain[i];
            }

            var tempout = Stretch(temp, fratio, length);

            if (overlap == null)
            {
                overlap = new Overlap(kOverlapCount, length / kOverlapCount);
            }
            SetPrePostWindow(length);
            for (var i = 0; i < length; i++)
            {
                tempout[i] *= window[i];
            }
            overlap.AddOverlap(ref tempout);

            dataout = ToShort(tempout, length);
        }
コード例 #10
0
        private void assignPredictedText2(PredictedObject predictedObject, HandwritingTextLine[] textLines)
        {
            predictedObject.Text = new List <string>();

            for (int i = 0; i < textLines.Length; i++)
            {
                //if areas are 100% overlapping assign every textline
                Overlap ovl            = new Overlap();
                Entities.BoundingBox b = new Entities.BoundingBox();


                int min_x = textLines[i].Polygon.Points.Min(p => p.X);
                int min_y = textLines[i].Polygon.Points.Min(p => p.Y);

                int max_x = textLines[i].Polygon.Points.Max(p => p.X);
                int max_y = textLines[i].Polygon.Points.Max(p => p.Y);

                b.Left   = min_x;
                b.Top    = min_y;
                b.Width  = max_x - min_x;
                b.Height = max_y - min_y;

                //If boxes overlaps more than 50% we decide they are the same thing
                if (ovl.OverlapArea(predictedObject.BoundingBox, b) > 0.5)
                {
                    for (int j = 0; j < textLines[i].Words.Length; j++)
                    {
                        predictedObject.Text.Add(textLines[i].Words[j].Text);
                    }
                }
            }
        }
コード例 #11
0
ファイル: GeneMerger.cs プロジェクト: YuJiang01/Nirvana
        private List <MutableGene> GetValidGenes(MutableGene seedGene, List <MutableGene> genes, out int start,
                                                 out int end)
        {
            var validGenes = new List <MutableGene>();

            start = seedGene.Start;
            end   = seedGene.End;

            foreach (var gene in genes)
            {
                if (gene.Invalid || seedGene.OnReverseStrand != gene.OnReverseStrand ||
                    seedGene.ReferenceIndex != gene.ReferenceIndex || !Overlap.Partial(start, end, gene.Start, gene.End))
                {
                    continue;
                }

                validGenes.Add(gene);

                if (gene.Start < start)
                {
                    start = gene.Start;
                }
                if (gene.End > end)
                {
                    end = gene.End;
                }
            }

            return(validGenes);
        }
コード例 #12
0
ファイル: TestOverlap.cs プロジェクト: FanZhangSX/Aderant
        public void TestFindAndMergeOverlap()
        {
            var fragments = new List <string>()
            {
                "all is well",
                "ell that en",
                "hat end",
                "t ends well",
                "hat",
                "end"
            };

            var overlap = new Overlap(fragments);

            // to test 2 strings which are not relevant
            overlap.FindAndMergeOverlap(fragments, 2, 3, 2);
            Assert.AreEqual(fragments[2], "hat end");
            Assert.AreEqual(fragments[3], "t ends well");

            // to test 2 strings which are overlaped
            overlap.FindAndMergeOverlap(fragments, 0, 1, 3);
            Assert.AreEqual(fragments[1], "all is well that en");
            Assert.AreEqual(fragments[0], "");

            // to test a string contains another
            overlap.FindAndMergeOverlap(fragments, 2, 4, 3);
            Assert.AreEqual(fragments[2], "hat end");
            Assert.AreEqual(fragments[4], "");

            // to test a string is contained by another
            overlap.FindAndMergeOverlap(fragments, 5, 2, 3);
            Assert.AreEqual(fragments[2], "hat end");
            Assert.AreEqual(fragments[5], "");
        }
コード例 #13
0
        public IBarChart SetOverlap(double ratio)
        {
            Overlap overlap = this.barChart.GetFirstChild <Overlap>() ?? this.barChart.AppendChild(new Overlap());

            overlap.Val = (sbyte)(ratio * 100);

            return(this);
        }
コード例 #14
0
ファイル: GffCreator.cs プロジェクト: YuJiang01/Nirvana
 private static bool HasCds(CdnaCoordinateMap exon, int codingRegionStart, int codingRegionEnd)
 {
     if (codingRegionStart == -1 || codingRegionEnd == -1)
     {
         return(false);
     }
     return(Overlap.Partial(exon.GenomicStart, exon.GenomicEnd, codingRegionStart, codingRegionEnd));
 }
コード例 #15
0
        public void Execute(int index)
        {
            Vector3 pos1 = Coordinates[Links[index].x]; // Note: X
            Vector3 pos2 = Coordinates[Links[index].y]; // Note: Y

            if (Mathf.Abs(pos1.x - pos2.x) < 2 * MaxDist && Mathf.Abs(pos1.z - pos2.z) < 2 * MaxDist)
            {
                // finding edges of the first seen area
                Overlap seenarea1 = EdgesFind(pos1, MaxDist);
                // finding edges of the second seen area
                Overlap seenarea2 = EdgesFind(pos2, MaxDist);

                // finding edges of the overlapping area
                Vector2 ii = new Vector2(Mathf.Max(seenarea1.InfInf.x, seenarea2.InfInf.x), Mathf.Max(seenarea1.InfInf.y, seenarea2.InfInf.y));
                Vector2 ss = new Vector2(Mathf.Min(seenarea1.SupSup.x, seenarea2.SupSup.x), Mathf.Min(seenarea1.SupSup.y, seenarea2.SupSup.y));

                // writing it in the nativearray
                Overlap overlap1 = new Overlap(ii, ss);
                AreaArray1[index] = overlap1;

                // searching MPC2 areas overlap
                if (Mathf.Abs(pos1.x - pos2.x) < 1.5 * MaxDist && Mathf.Abs(pos1.z - pos2.z) < 1.5 * MaxDist)
                {
                    // Tx areas for MPC2
                    Overlap Tx_seenarea2 = EdgesFind(pos1, MaxDist / 2);
                    Vector2 Tx_ii        = new Vector2(Mathf.Max(overlap1.InfInf.x, Tx_seenarea2.InfInf.x), Mathf.Max(overlap1.InfInf.y, Tx_seenarea2.InfInf.y));
                    Vector2 Tx_ss        = new Vector2(Mathf.Min(overlap1.SupSup.x, Tx_seenarea2.SupSup.x), Mathf.Min(overlap1.SupSup.y, Tx_seenarea2.SupSup.y));
                    Overlap Tx_overlap2  = new Overlap(Tx_ii, Tx_ss);
                    TxAreaArray2[index] = Tx_overlap2;

                    // Rx areas for MPC2
                    Overlap Rx_seenarea2 = EdgesFind(pos2, MaxDist / 2);
                    Vector2 Rx_ii        = new Vector2(Mathf.Max(overlap1.InfInf.x, Rx_seenarea2.InfInf.x), Mathf.Max(overlap1.InfInf.y, Rx_seenarea2.InfInf.y));
                    Vector2 Rx_ss        = new Vector2(Mathf.Min(overlap1.SupSup.x, Rx_seenarea2.SupSup.x), Mathf.Min(overlap1.SupSup.y, Rx_seenarea2.SupSup.y));
                    Overlap Rx_overlap2  = new Overlap(Rx_ii, Rx_ss);
                    RxAreaArray2[index] = Rx_overlap2;

                    // searching MPC3 areas overlap
                    if (Mathf.Abs(pos1.x - pos2.x) < (4 * MaxDist) / 3 && Mathf.Abs(pos1.z - pos2.z) < (4 * MaxDist) / 3)
                    {
                        // Tx areas for MPC3
                        Overlap Tx_seenarea3 = EdgesFind(pos1, MaxDist / 3);
                        Vector2 Tx_ii3       = new Vector2(Mathf.Max(overlap1.InfInf.x, Tx_seenarea3.InfInf.x), Mathf.Max(overlap1.InfInf.y, Tx_seenarea3.InfInf.y));
                        Vector2 Tx_ss3       = new Vector2(Mathf.Min(overlap1.SupSup.x, Tx_seenarea3.SupSup.x), Mathf.Min(overlap1.SupSup.y, Tx_seenarea3.SupSup.y));
                        Overlap Tx_overlap3  = new Overlap(Tx_ii3, Tx_ss3);
                        TxAreaArray3[index] = Tx_overlap3;

                        // Rx areas for MPC3
                        Overlap Rx_seenarea3 = EdgesFind(pos2, MaxDist / 3);
                        Vector2 Rx_ii3       = new Vector2(Mathf.Max(overlap1.InfInf.x, Rx_seenarea3.InfInf.x), Mathf.Max(overlap1.InfInf.y, Rx_seenarea3.InfInf.y));
                        Vector2 Rx_ss3       = new Vector2(Mathf.Min(overlap1.SupSup.x, Rx_seenarea3.SupSup.x), Mathf.Min(overlap1.SupSup.y, Rx_seenarea3.SupSup.y));
                        Overlap Rx_overlap3  = new Overlap(Rx_ii3, Rx_ss3);
                        RxAreaArray3[index] = Rx_overlap3;
                    }
                }
            }
        }
コード例 #16
0
        private Overlap EdgesFind(Vector3 p, float d)
        {
            float   x_inf   = p.x - d;
            float   x_sup   = p.x + d;
            float   z_inf   = p.z - d;
            float   z_sup   = p.z + d;
            Overlap overlap = new Overlap(new Vector2(x_inf, z_inf), new Vector2(x_sup, z_sup));

            return(overlap);
        }
コード例 #17
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (int)DisplayId;
         hashCode = (hashCode * 397) ^ Overlap.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)PixelShiftType;
         hashCode = (hashCode * 397) ^ (int)Rotation;
         return(hashCode);
     }
 }
コード例 #18
0
ファイル: Field.cs プロジェクト: tng2903/nodulus
        public bool ValidPlacement(Arc arc)
        {
            // A placement is valid if:
            // 1. No Arc exists in the field
            // 2. Arc length is equal to field length
            // 3. Arcs do not overlap

            var noArc   = !HasArc;// || Arc.Equals(arc);
            var overlap = Overlap.Any(field => field.HasArc);

            return(noArc && arc.Length == Length && !overlap);
        }
コード例 #19
0
 /// <inheritdoc />
 public bool Equals(SurroundTopologyDisplay other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return((DisplayId == other.DisplayId) && Overlap.Equals(other.Overlap) &&
            (PixelShiftType == other.PixelShiftType) && (Rotation == other.Rotation));
 }
コード例 #20
0
ファイル: TestOverlap.cs プロジェクト: FanZhangSX/Aderant
        public void TestWholeProcessByString()
        {
            var fragments = new StringBuilder();

            fragments.Append("all is well\n");
            fragments.Append("ell that en\n");
            fragments.Append("hat end\n");
            fragments.Append("t ends well\n");
            var overlap = new Overlap(fragments.ToString());

            Assert.AreEqual(overlap.MergeOverlap(), "all is well that ends well");
            overlap.Dispose();
        }
コード例 #21
0
ファイル: PitchShiftPV.cs プロジェクト: tmokmss/LLSynth
        public void Process(short[] datain, out short[] dataout)
        {
            var length       = datain.Length;
            var mBitRev      = FHTArrays.GetBitRevTable(length);
            var mPreWindow   = FHTArrays.GetPreWindow(length);
            var mPostWindow  = FHTArrays.GetPostWindow(length);
            var hopanal      = length / kOverlapCount;
            var hopsyn       = (int)(hopanal * ShiftRate);
            var overlapCount = (int)Math.Ceiling((double)length / hopsyn);
            var temp         = new double[length];

            if (shiftChanged || mLastPhase == null || mLastPhase.Length != length / 2)
            {
                mLastPhase   = new double[length / 2];
                mSumPhase    = new double[length / 2];
                overlap      = new Overlap(overlapCount, hopsyn);
                shiftChanged = false;
            }

            for (var i = 0; i < length; ++i)
            {
                var j = mBitRev[i];
                var k = (uint)(j & (length - 1));
                temp[i] = datain[k] * mPreWindow[k];
            }

            double[] re, im;
            fht.ComputeFHT(temp, out re, out im);
            var temp_shift = new double[length];

            AnalysisAndSynthesis(ref re, ref im);

            ifht.ComputeFHT(re, im, out temp_shift, false);
            temp = temp_shift;

            var window = FHTArrays.GetPostWindow(length);

            if (overlapCount >= kOverlapCount)
            {
                for (var i = 0; i < length; i++)
                {
                    temp_shift[i] *= window[i] * shiftRate / 2;
                }
            }
            overlap.AddOverlap(ref temp_shift);
            temp = new double[hopsyn];
            Array.Copy(temp_shift, temp, hopsyn);
            temp = Stretch(temp, 1 / ShiftRate, length);

            dataout = ToShort(temp, length);
        }
コード例 #22
0
        /// <summary>
        /// constructor
        /// </summary>
        public FeatureVariantEffects(ReferenceAnnotationInterval feature, VariantType vt, int refBegin, int refEnd, bool isSV, VariantType internalCopyNumberType)
        {
            _isSV = isSV;

            _completelyOverlaps = Overlap.Complete(feature.Start, feature.End, refBegin, refEnd);
            _overlaps           = Overlap.Partial(feature.Start, feature.End, refBegin, refEnd);
            _completelyWithin   = refBegin >= feature.Start && refEnd <= feature.End;

            _lossOrDeletion    = vt == VariantType.copy_number_loss || vt == VariantType.deletion || internalCopyNumberType == VariantType.copy_number_loss;
            _gainOrDuplication = vt == VariantType.copy_number_gain || vt == VariantType.duplication ||
                                 vt == VariantType.tandem_duplication || internalCopyNumberType == VariantType.copy_number_gain;
            _isInsertionDeletion = vt == VariantType.indel;
            _isInsertion         = vt == VariantType.insertion;
        }
コード例 #23
0
 private void CheckOverlap(Overlap overlap)
 {
     if (overlap.Other.Behaviors.TryGet <DamageableBehavior>(out var behavior))
     {
         behavior.Damage(new DamageableBehavior.DamageInfo {
             Amount = 1
         });
         Owner.Destroy();
     }
     else if (overlap.Other.IsSolid)
     {
         Owner.Destroy();
     }
 }
コード例 #24
0
ファイル: AlternateAllele.cs プロジェクト: YuJiang01/Nirvana
        public void AddCustomIntervals(List <ICustomInterval> overlappingCustomIntervals)
        {
            if (overlappingCustomIntervals == null)
            {
                return;
            }

            foreach (var customInterval in overlappingCustomIntervals)
            {
                if (Overlap.Partial(this, customInterval))
                {
                    CustomIntervals.Add(customInterval);
                }
            }
        }
コード例 #25
0
        public async Task <IActionResult> Channel(string name)
        {
            name = name.ToLowerInvariant();
            string cachedChannelData = await _cache.StringGetAsync(ChannelDataCacheKey + name);

            if (!string.IsNullOrEmpty(cachedChannelData))
            {
                return(View(JsonSerializer.Deserialize <ChannelData>(cachedChannelData)));
            }

            Channel channel = await _context.Channels.AsNoTracking().SingleOrDefaultAsync(x => x.LoginName == name);

            if (channel == null)
            {
                return(View("NoData", name));
            }

            Overlap overlaps = await _context.Overlaps.FromSqlInterpolated($@"select *
            from overlap
            where channel = {channel.Id}
              and timestamp = (select max(timestamp)
                               from overlap
                               where channel = {channel.Id})").AsNoTracking()
                               .Include(x => x.ChannelNavigation)
                               .SingleOrDefaultAsync();

            if (overlaps == null)
            {
                return(View("NoData", name));
            }

            var overlappedChannelsData = await _context.Channels.AsNoTracking()
                                         .Where(x => overlaps.Shared.Select(y => y.Name).Contains(x.LoginName))
                                         .Select(x => new { x.LoginName, x.Game })
                                         .ToDictionaryAsync(x => x.LoginName);

            var channelData = new ChannelData(channel);

            foreach (ChannelOverlap overlap in overlaps.Shared)
            {
                channelData.Data[overlap.Name] = new Data(overlappedChannelsData[overlap.Name].Game, overlap.Shared);
            }

            await _cache.StringSetAsync(ChannelDataCacheKey + name, JsonSerializer.Serialize(channelData), TimeSpan.FromMinutes(5));

            return(View(channelData));
        }
コード例 #26
0
        public int Extract()
        {
            var count    = 0;
            var interval = _reader.GetNextCustomInterval();

            while (interval != null)
            {
                if (Overlap.Partial(interval.Start, interval.End, _begin, _end))
                {
                    _writer.WriteInterval(interval);
                    count++;
                }

                interval = _reader.GetNextCustomInterval();
            }
            _writer.Dispose();
            return(count);
        }
コード例 #27
0
ファイル: TestOverlap.cs プロジェクト: FanZhangSX/Aderant
        public void TestWholeProcessByRandomArray()
        {
            var s = @"Other collaborative online encyclopedias were attempted before Wikipedia, but none were as successful.[24] Wikipedia began as a complementary project for Nupedia, a free online English-language encyclopedia project whose articles were written by experts and reviewed under a formal process.[25] It was founded on March 9, 2000, under the ownership of Bomis, a web portal company. Its main figures were Bomis CEO Jimmy Wales and Larry Sanger, editor-in-chief for Nupedia and later Wikipedia.[26][27] Nupedia was initially licensed under its own Nupedia Open Content License, but even before Wikipedia was founded, Nupedia switched to the GNU Free Documentation License at the urging of Richard Stallman.[28] Wales is credited with defining the goal of making a publicly editable encyclopedia,[29][30] while Sanger is credited with the strategy of using a wiki to reach that goal.[31] On January 10, 2001, Sanger proposed on the Nupedia mailing list to create a wiki as a feeder project for Nupedia.[32]";

            int successTimes = 0;

            for (int i = 0; i < 10; i++)
            {
                var l = ProduceTestCase(s);
                l = Shuffle(l);
                var overlap = new Overlap(l);
                if (s.Equals(overlap.MergeOverlap()))
                {
                    successTimes++;
                }
                overlap.Dispose();
            }

            Assert.IsTrue(successTimes > 0);
        }
コード例 #28
0
ファイル: PitchShiftPV.cs プロジェクト: tmokmss/LLSynth
        public void Processb(short[] datain, out short[] dataout)
        {
            // even without FFT, it works to some extent.
            var length       = datain.Length;
            var hopanal      = length / kOverlapCount;
            var hopsyn       = (int)(hopanal * ShiftRate);
            var overlapCount = (int)Math.Ceiling((double)length / hopsyn);

            if (shiftChanged || overlap == null)
            {
                overlap      = new Overlap(overlapCount, hopsyn);
                shiftChanged = false;
            }

            var temp_shift = new double[length];

            for (var i = 0; i < length; i++)
            {
                temp_shift[i] = datain[i];
            }

            var window = FHTArrays.GetPostWindow(length);

            if (overlapCount >= kOverlapCount)
            {
                for (var i = 0; i < length; i++)
                {
                    temp_shift[i] *= window[i] / 2 * ShiftRate;
                }
            }
            overlap.AddOverlap(ref temp_shift);
            var temp = new double[hopsyn];

            Array.Copy(temp_shift, temp, hopsyn);
            temp = Stretch(temp, 1 / ShiftRate, length);

            dataout = ToShort(temp, length);
        }
コード例 #29
0
        private void assignPredictedText(PredictedObject predictedObject, List <Line> textLines)
        {
            predictedObject.Text = new List <string>();

            foreach (var textLine in textLines)
            {
                //if areas are 100% overlapping assign every textline
                Overlap ovl            = new Overlap();
                Entities.BoundingBox b = new Entities.BoundingBox();

                // Bounding box of a recognized region, line, or word, depending on the parent object.
                // It's an arrary of eight numbers represent the four points (x-coordinate, y-coordinate
                // from the left-top corner of the image) of the detected rectangle from the left-top corner
                // in the clockwise direction.
                var xPoints = textLine.BoundingBox.Where((value, index) => index % 2 == 0).ToArray();
                var yPoints = textLine.BoundingBox.Where((value, index) => index % 2 != 0).ToArray();

                var min_x = xPoints.Min();
                var min_y = yPoints.Min();

                var max_x = xPoints.Max();
                var max_y = yPoints.Max();

                b.Left   = min_x;
                b.Top    = min_y;
                b.Width  = max_x - min_x;
                b.Height = max_y - min_y;

                //If boxes overlaps more than 50% we decide they are the same thing
                if (ovl.OverlapArea(predictedObject.BoundingBox, b) > 0.5)
                {
                    for (int j = 0; j < textLine.Words.Count; j++)
                    {
                        predictedObject.Text.Add(textLine.Words[j].Text);
                    }
                }
            }
        }
コード例 #30
0
        private async void Permute(object sender, RoutedEventArgs e)
        {
            // Clear our workspace
            oComponents.Clear();
            _wrkSpace.Children.Clear();

            await _viewModel.Permute();

            Overlap overlap = _dataManager.GetOverlap();

            if (overlap != null)
            {
                int idx = 0;
                foreach (var dataType in _viewModel.DataTypes)
                {
                    if (dataType.Selected)
                    {
                        var cmpView = new GraphView();
                        cmpView.Width             = 600;              // TODO: Make this dynamic and stretchy
                        cmpView.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
                        _wrkSpace.Children.Add(cmpView);
                        _wrkSpaceComponents.Add(cmpView);

                        cmpView.SetDataManager(_dataManager);

                        // TODO: Make this user settable and not blow up
                        cmpView.LoadGraphComponents(overlap, dataType.Tag, NBSmColors[idx]);

                        idx++;
                    }
                }

                oComponents.LoadGraphComponents(overlap);
            }

            _btnSave.IsEnabled = true;
        }
コード例 #31
0
ファイル: PitchShiftTDSOLA.cs プロジェクト: tmokmss/LLSynth
        private void PitchShiftTDv(short[] datain, out short[] dataout)
        {
            var length = datain.Length;
            var fratio = FormantShiftRate;
            var newlen = (int)Math.Round(length / fratio);
            var temp = new double[newlen];
            for (var i = 0; i < Math.Min(newlen, length); i++)
            {
                temp[i] = datain[i];
            }

            var tempout = Stretch(temp, fratio, length);

            if (overlap == null) overlap = new Overlap(kOverlapCount, length / kOverlapCount);
            SetPrePostWindow(length);
            for (var i = 0; i < length; i++)
            {
                tempout[i] *= window[i];
            }
            overlap.AddOverlap(ref tempout);

            dataout = ToShort(tempout, length);
        }
コード例 #32
0
ファイル: PitchShiftTDSOLA.cs プロジェクト: tmokmss/LLSynth
        private void PitchShiftTDold(short[] datain, out short[] dataout)
        {
            var length = datain.Length;
            var startIdx = SearchHeadZeroCross(datain);

            var frame = new short[region];
            Array.Copy(datain, startIdx, frame, 0, region);

            var baseCycle = CalcBaseCycle(frame);
            var pratio = PitchShiftRate;
            var fratio = FormantShiftRate;
            var newlen = (int)Math.Round(length / fratio);
            var temp = new double[newlen];

            //Console.WriteLine(44100.0 / baseCycle);

            int j = 0, count = 0, idx = startIdx;
            var incrementFreq = (int)((length - startIdx) * (fratio - 1) / baseCycle);
            if (baseCycle == 0) incrementFreq = 0;
            var isIncrement = incrementFreq >= 0;
            incrementFreq = Math.Abs(incrementFreq);
            for (var i = 0; i < newlen; i++)
            {
                if (idx >= length) break;
                temp[i] = datain[idx];// * window[j];
                j++;
                idx++;
                if (j >= baseCycle && j >= 3)
                {
                    // search for zero-cross point
                    if (datain[idx - 1] * datain[idx - 2] > 0) continue;
                    count++;
                    baseCycle = j;
                    j = 0;
                    if (incrementFreq != 0 && count % incrementFreq == 0)
                    {
                        idx -= j;
                    }
                }
                //if (i%500 == 0)
                //    Console.WriteLine(String.Format("{0}:{1}", i, idx));
            }

            var tempout = Stretch(temp, fratio, length);

            if (overlap == null) overlap = new Overlap(kOverlapCount, length / kOverlapCount);
            SetPrePostWindow(length);
            for (var i = 0; i < length; i++)
            {
                tempout[i] *= window[i];
            }
            overlap.AddOverlap(ref tempout);

            dataout = ToShort(tempout, length);
        }
コード例 #33
0
ファイル: PitchShiftTDSOLA.cs プロジェクト: tmokmss/LLSynth
        private void PitchShiftTD(short[] datain, out short[] dataout)
        {
            var length = datain.Length;
            var startIdx = SearchHeadZeroCross(datain);

            var frame = new short[region];
            Array.Copy(datain, startIdx, frame, 0, region);

            var baseCycle = CalcBaseCycle(frame);

            if (baseCycle < 5 || baseCycle > region * 0.8)
            {
                dataout = datain;
                return;
            }

            var pratio = PitchShiftRate;
            var fratio = FormantShiftRate;
            var newlen = (int)Math.Round(length / fratio);
            var currentNum = (double)(length - startIdx) / baseCycle;
            var targetNum = currentNum * pratio;
            var overlapNum = (int)((targetNum * baseCycle - newlen) / (targetNum - 1));
            var temp = new double[newlen];

            if (baseCycle == 0)
                currentNum = targetNum = overlapNum = 0;

            //Console.WriteLine(44100.0 / baseCycle);

            int j = 0, count = 0, idx = startIdx;
            //var incrementNum = (int)((length - startIdx) * (pratio - 1) / baseCycle);
            var incrementNum = targetNum - currentNum;
            var incrementFreq = (incrementNum == 0) ? 0 : (int)Math.Round(targetNum / (incrementNum));
            var isIncrement = incrementFreq >= 0;
            incrementFreq = Math.Abs(incrementFreq);

            Array.Copy(beforeBuf, temp, beforeBuf.Length);
            for (var i = beforeBuf.Length; i < newlen; i++)
            {
                if (idx >= length) break;
                temp[i] = datain[idx];// * window[j];
                j++;
                idx++;
                if (j >= baseCycle -10 && j>=3)
                {
                    // search for zero-cross point
                    if (datain[idx - 1] * datain[idx - 2] > 0) continue;
                    count++;
                    //baseCycle = j;
                    if (incrementFreq != 0 && count % incrementFreq == 0)
                    {
                        idx -= j;
                    }
                    j = 0;
                    if (overlapNum > 0)
                    {
                        for (var l = overlapNum - 1; l >= 0 && idx < length; l--)
                        {
                            var fac = Math.Pow(((double)l / overlapNum),3);
                            temp[i - l] = (temp[i - l] * fac + datain[idx] * (1 - fac));
                            j++;
                            idx++;
                        }
                        //i += overlapNum;
                    }
                    else
                    {
                        i -= overlapNum;
                    }
                }
                //if (i%500 == 0)
                //    Console.WriteLine(String.Format("{0}:{1}", i, idx));
            }

            var tempout = Stretch(temp, fratio, length);

            if (overlap == null) overlap = new Overlap(kOverlapCount, length / kOverlapCount);
            SetPrePostWindow(length);
            for (var i = 0; i < length; i++)
            {
                //tempout[i] *= window[i];
            }
            //overlap.AddOverlap(ref tempout);

            dataout = ToShort(tempout, length);

            var bufferSpanS = (int)(bufferSpan / fratio);
            if (bufferSpanS < temp.Length-region && bufferSpanS >= 0)
            {
                beforeBuf = new double[region];
                Array.Copy(temp, bufferSpanS, beforeBuf, 0, region);
                var buflen = SearchHeadZeroCross(beforeBuf);
                beforeBuf = new double[buflen];
                Array.Copy(temp, bufferSpanS, beforeBuf, 0, buflen);
            }

            bufferSpan = this.Position - beforeIdx;
            beforeIdx = this.Position;
        }