示例#1
0
文件: AA_tree.cpp 项目: pulsa/t.hex
void test()
{
    Segment *nil = NULL;
    AATree<Segment*> segs(nil);

    Segment *s[10];
    for (int i = 0; i < 10; i++)
    {
        s[i] = new Segment(10, i);
    }
    segs.insert(0, s[0]);
    segs.insert(10, s[1]);
    segs.insert(10, s[2]);
    segs.insert(30, s[3]);
}
示例#2
0
cv::Mat ArmObjSegmentation::convertFlowToMat(GraphType *g, NodeTable& nt, int R, int C)
{
  cv::Mat segs(R,C, CV_8UC1, cv::Scalar(0));
  for (int r = 0; r < R; ++r)
  {
    uchar* seg_row = segs.ptr<uchar>(r);
    for (int c = 0; c < C; ++c)
    {
      int idx = nt.find(r,c);
      if (idx < 0) continue;
      int label = (g->what_segment(idx) == GraphType::SOURCE);
      seg_row[c] = label*255;
    }
  }
  return segs;
}
示例#3
0
Py::Object TriContourGenerator::contour_to_segs(const Contour& contour)
{
    Py::List segs(contour.size());
    for (Contour::size_type i = 0; i < contour.size(); ++i) {
        const ContourLine& line = contour[i];
        npy_intp dims[2] = {static_cast<npy_intp>(line.size()),2};
        PyArrayObject* py_line = (PyArrayObject*)PyArray_SimpleNew(
                                                     2, dims, PyArray_DOUBLE);
        double* p = (double*)PyArray_DATA(py_line);
        for (ContourLine::const_iterator it = line.begin(); it != line.end(); ++it) {
            *p++ = it->x;
            *p++ = it->y;
        }
        segs[i] = Py::asObject((PyObject*)py_line);
    }
    return segs;
}
int solution(vector<int> &A) {
    // write your code in C++11
    int n = A.size();
    vector<seg> segs(n);
    for (int i = 0; i < n; i++) {
        segs[i].left = (long long)i - (long long)A[i];
        segs[i].right = (long long)i + (long long)A[i];
    } 
    sort(segs.begin(), segs.end());
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
        int b = search(segs, segs[i].right, i + 1, n - 1);
        sum += b - i - 1;
        if (sum > 10000000) {
            return -1;
        }
    }
    return sum;
}
示例#5
0
        void
        SpectrogramData::updateData() 
        {
            m_.clear();

            size_t id1 = std::distance( spectra_->x().begin(), std::lower_bound( spectra_->x().begin(), spectra_->x().end(), xlimits_.first ) );
            size_t id2 = std::distance( spectra_->x().begin(), std::lower_bound( spectra_->x().begin(), spectra_->x().end(), xlimits_.second ) );
            size1_ = std::min( m_.size1(), id2 - id1 + 1 );
            
            double z_max = std::numeric_limits<double>::lowest();
            size_t id = 0;
            for ( auto& ms: *spectra_ ) {
                double x = spectra_->x()[ id++ ];
                
                if ( xlimits_.first <= x && x <= xlimits_.second ) {
                    size_t ix = dx(x);

                    adcontrols::segment_wrapper< const adcontrols::MassSpectrum > segs( *ms );
                    for ( auto& seg: segs ) {
                        for ( size_t i = 0; i < seg.size(); ++i ) {
                            double m = seg.getMass( i );
                            if ( ylimits_.first < m && m < ylimits_.second ) {
                                size_t iy = dy(m);
                                m_( ix, iy ) += seg.getIntensity( i ); 
                                z_max = std::max( z_max, m_( ix, iy ) );
                            }
                        }
                    }
                }
            }
            setInterval( Qt::XAxis, QwtInterval( spectra_->x_left(), spectra_->x_right() ) );   // time (sec -> min)
            setInterval( Qt::YAxis, QwtInterval( spectra_->lower_mass(), spectra_->upper_mass() ) ); // m/z
#if 0       // normaize
            m_ /= ( z_max / 1000.0 );
            setInterval( Qt::ZAxis, QwtInterval( 0.0, 1000 ) );
#else
            setInterval( Qt::ZAxis, QwtInterval( 0.0, z_max ) );
#endif
        }
示例#6
0
static void
cpMarchCellHard(
	cpFloat t, cpFloat a, cpFloat b, cpFloat c, cpFloat d,
	cpFloat x0, cpFloat x1, cpFloat y0, cpFloat y1,
	cpMarchSegmentFunc segment, void *segment_data
){
	// midpoints
	cpFloat xm = cpflerp(x0, x1, 0.5f);
	cpFloat ym = cpflerp(y0, y1, 0.5f);

	switch((a>t)<<0 | (b>t)<<1 | (c>t)<<2 | (d>t)<<3){
		case 0x1: segs(cpv(x0, ym), cpv(xm, ym), cpv(xm, y0), segment, segment_data); break;
		case 0x2: segs(cpv(xm, y0), cpv(xm, ym), cpv(x1, ym), segment, segment_data); break;
		case 0x3: seg(cpv(x0, ym), cpv(x1, ym), segment, segment_data); break;
		case 0x4: segs(cpv(xm, y1), cpv(xm, ym), cpv(x0, ym), segment, segment_data); break;
		case 0x5: seg(cpv(xm, y1), cpv(xm, y0), segment, segment_data); break;
		case 0x6: segs(cpv(xm, y0), cpv(xm, ym), cpv(x0, ym), segment, segment_data);
		          segs(cpv(xm, y1), cpv(xm, ym), cpv(x1, ym), segment, segment_data); break;
		case 0x7: segs(cpv(xm, y1), cpv(xm, ym), cpv(x1, ym), segment, segment_data); break;
		case 0x8: segs(cpv(x1, ym), cpv(xm, ym), cpv(xm, y1), segment, segment_data); break;
		case 0x9: segs(cpv(x1, ym), cpv(xm, ym), cpv(xm, y0), segment, segment_data);
		          segs(cpv(x0, ym), cpv(xm, ym), cpv(xm, y1), segment, segment_data); break;
		case 0xA: seg(cpv(xm, y0), cpv(xm, y1), segment, segment_data); break;
		case 0xB: segs(cpv(x0, ym), cpv(xm, ym), cpv(xm, y1), segment, segment_data); break;
		case 0xC: seg(cpv(x1, ym), cpv(x0, ym), segment, segment_data); break;
		case 0xD: segs(cpv(x1, ym), cpv(xm, ym), cpv(xm, y0), segment, segment_data); break;
		case 0xE: segs(cpv(xm, y0), cpv(xm, ym), cpv(x0, ym), segment, segment_data); break;
		default: break; // 0x0 and 0xF
	}
}
示例#7
0
void CAlnVec::CreateConsensus(vector<string>& consens) const
{
    bool isNucleotide = GetBioseqHandle(0).IsNucleotide();

    const int numBases = isNucleotide ? 4 : 26;

    int base_count[26]; // must be a compile-time constant for some compilers

    // determine what the number of segments required for a gapped consensus
    // segment is.  this must be rounded to be at least 50%.
    int gap_seg_thresh = m_NumRows - m_NumRows / 2;

    for (size_t j = 0;  j < (size_t)m_NumSegs;  ++j) {
        // evaluate for gap / no gap
        int gap_count = 0;
        for (size_t i = 0;  i < (size_t)m_NumRows;  ++i) {
            if (m_Starts[ j*m_NumRows + i ] == -1) {
                ++gap_count;
            }
        }

        // check to make sure that this seg is not a consensus
        // gap seg
        if ( gap_count > gap_seg_thresh )
            continue;

        // the base threshold for being considered unique is at least
        // 70% of the available sequences
        int base_thresh =
            ((m_NumRows - gap_count) * 7 + 5) / 10;

        {
            // we will build a segment with enough bases to match
            consens[j].resize(m_Lens[j]);

            // retrieve all sequences for this segment
            vector<string> segs(m_NumRows);
            RetrieveSegmentSequences(j, segs);
            TransposeSequences(segs);

            typedef multimap<int, unsigned char, greater<int> > TRevMap;

            // 
            // evaluate for a consensus
            //
            for (size_t i = 0;  i < m_Lens[j];  ++i) {
                if (isNucleotide) {
                    CollectNucleotideFrequences(segs[i], base_count, numBases);
                } else {
                    CollectProteinFrequences(segs[i], base_count, numBases);
                }


                // we create a sorted list (in descending order) of
                // frequencies of appearance to base
                // the frequency is "global" for this position: that is,
                // if 40% of the sequences are gapped, the highest frequency
                // any base can have is 0.6
                TRevMap rev_map;

                for (int k = 0;  k < numBases;  ++k) {
                    // this gets around a potentially tricky idiosyncrasy
                    // in some implementations of multimap.  depending on
                    // the library, the key may be const (or not)
                    TRevMap::value_type p(base_count[k], isNucleotide ? (1<<k) : k);
                    rev_map.insert(p);
                }

                // now, the first element here contains the best frequency
                // we scan for the appropriate bases
                if (rev_map.count(rev_map.begin()->first) == 1 &&
                    rev_map.begin()->first >= base_thresh) {
                        consens[j][i] = isNucleotide ?
                            ToIupac(rev_map.begin()->second) :
                            (rev_map.begin()->second+'A');
                } else {
                    // now we need to make some guesses based on IUPACna
                    // notation
                    int               count;
                    unsigned char     c    = 0x00;
                    int               freq = 0;
                    TRevMap::iterator curr = rev_map.begin();
                    TRevMap::iterator prev = rev_map.begin();
                    for (count = 0;
                         curr != rev_map.end() &&
                         (freq < base_thresh || prev->first == curr->first);
                         ++curr, ++count) {
                        prev = curr;
                        freq += curr->first;
                        if (isNucleotide) {
                            c |= curr->second;
                        } else {
                            unsigned char cur_char = curr->second+'A';
                            switch (c) {
                                case 0x00:
                                    c = cur_char;
                                    break;
                                case 'N': case 'D':
                                    c = (cur_char == 'N' || cur_char == 'N') ? 'B' : 'X';
                                    break;
                                case 'Q': case 'E':
                                    c = (cur_char == 'Q' || cur_char == 'E') ? 'Z' : 'X';
                                    break;
                                case 'I': case 'L':
                                    c = (cur_char == 'I' || cur_char == 'L') ? 'J' : 'X';
                                    break;
                                default:
                                    c = 'X';
                            }
                        }
                    }

                    //
                    // catchall
                    //
                    if (count > 2) {
                        consens[j][i] = isNucleotide ? 'N' : 'X';
                    } else {
                        consens[j][i] = isNucleotide ? ToIupac(c) : c;
                    }
                }
            }
        }
    }
}
示例#8
0
static int three_register_execute(UM_machine machine,
                                  Um_instruction instruction)
{
        unsigned op = Bitpack_getu(instruction, BITS_PER_OP_CODE, 28);
        unsigned A = Bitpack_getu(instruction, BITS_PER_REG_NUM, 6);
        unsigned B = Bitpack_getu(instruction, BITS_PER_REG_NUM, 3);
        unsigned C = Bitpack_getu(instruction, BITS_PER_REG_NUM, 0);

        switch(op){
                case 0: //
                        movc(machine, A, B, C);
                        return 1;

                case 1:
                        segl(machine, A, B, C);
                        return 1;
                        
                case 2:
                        segs(machine, A, B, C);
                        return 1;

                case 3:
                        add(machine, A, B, C); 
                        return 1;

                case 4:
                        mult(machine, A, B, C);
                        return 1;

                case 5:
                        divi(machine, A, B, C);
                        return 1;

                case 6:
                        nand(machine, A, B, C);
                        return 1;

                case 7:
                        return 0;

                case 8:
                        map(machine, B, C);
                        return 1;

                case 9: 
                        unmap(machine, C);
                        return 1;

                case 10:
                        out(machine, C);
                        return 1;

                case 11:
                        in(machine, C);
                        return 1;

                case 12:
                        loadp(machine, B, C);
                        return 1;
                default:
                        return 0;
        }
}