Esempio n. 1
0
void VS10Inst::ValidateDestMask()
{
    char temp[256];
    typedef std::map<char, int> MyMap;
    typedef MyMap::value_type MyPair;
    static const MyPair pairs[] = 
    {
        MyPair('x',1),
        MyPair('y',2),
        MyPair('z',3),
        MyPair('w',4),
    };
    static const MyMap swizzleMap(pairs, pairs+(sizeof(pairs)/sizeof(pairs[0])));

    if ( dst.mask[0] == 0 ) return;
    int i = 1;
    while ( i < 4 && dst.mask[i] != 0 )
    {
        MyMap::const_iterator lastMaskIt = swizzleMap.find(dst.mask[i-1]);
        MyMap::const_iterator curMaskIt = swizzleMap.find(dst.mask[i]);
        if (lastMaskIt == swizzleMap.end() || curMaskIt == swizzleMap.end() ||
            lastMaskIt->second >= curMaskIt->second)
//        if ( dst.mask[i-1] >= dst.mask[i] )
        {
            char mask[5];
            strncpy( mask, dst.mask, 4 );
            mask[4] = 0;
            sprintf( temp, "(%d) Error: destination register has invalid mask: %s\n", line, mask );
            errors.set( temp );
            break;
        }
        i++;
    }
}
 static typename DerivedF::Scalar  add_vertex(const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 1> &values,
                                              const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 3> &points,
                                              unsigned int i0,
                                              unsigned int i1,
                                              PointMatrixType &vertices,
                                              int &num_vertices,
                                              MyMap &edge2vertex)
 {
   // find vertex if it has been computed already
   MyMapIterator it = edge2vertex.find(EdgeKey(i0, i1));
   if (it != edge2vertex.end()) 
     return it->second;
   ;
   
   // generate new vertex
   const Eigen::Matrix<typename DerivedV::Scalar, 1, 3> & p0 = points.row(i0);
   const Eigen::Matrix<typename DerivedV::Scalar, 1, 3> & p1 = points.row(i1);
   
   typename DerivedV::Scalar s0 = fabs(values[i0]);
   typename DerivedV::Scalar s1 = fabs(values[i1]);
   typename DerivedV::Scalar t  = s0 / (s0+s1);
   
   
   num_vertices++;
   if (num_vertices > vertices.rows())
     vertices.conservativeResize(vertices.rows()+10000, Eigen::NoChange);
   
   vertices.row(num_vertices-1)  = (1.0f-t)*p0 + t*p1;
   edge2vertex[EdgeKey(i0, i1)] = num_vertices-1;
   
   return num_vertices-1;
 }
int main()
{
    MyMap *mymap = new MyMap();
    vector<int> *sum_vec;
    const Key *key;
    int len;
    int p[MaxLen];
    srand( unsigned(time(NULL)));
    for(int c = 0; c < MaxNum; ++c)
    {
        len = rand() % MaxLen + 1;
        int sum = 0;
        for(int i = 0; i < len; ++i)
        {
            p[i] = rand() % MaxNum;
            sum += p[i];
        }
        key = new Key(p, len);
        sum_vec = new vector<int>();
        sum_vec->push_back(sum);
        mymap->insert(make_pair(*key, sum_vec));
        delete key;
    }
    for(MyMap::iterator it = mymap->begin(); it != mymap->end(); ++it)
    {
        delete it->second;
    }
    delete mymap;
    return 0;
}
Esempio n. 4
0
int main(int argc, char * argv[]) {
    if (argc == 0) {
        cout << "usage: " << argv[0] << "[File1 [File2 [File3 [...]]]]" << endl;
    }
    for (int i = 1; i < argc; i++) {
        cout << "File: " << argv[i] << endl;
        printNames(argv[i]);

        MyMap::iterator it = names.begin();
        while (it != names.end()) {
            //cout << it->first << ": " << it->second << endl;
            sortiert.push_back(it);
            it++;
        }
        //partial_sort (sortiert.begin(), sortiert.bein() + 20, sortiert.end(), mySort);
        partial_sort (sortiert.begin(), sortiert.begin() + 20, sortiert.end(), myObject);

        size_t c = 0;
        for (MyVec::iterator it = sortiert.begin(); it != sortiert.end() && c < 20; it++, c++) {
            cout << (*it)->first << ": " << (*it)->second << endl;
        }
        cout << "==============================" << endl;

        names.clear();
    }
}
Esempio n. 5
0
bool Test_STL()
{
    TTRACE(_T("====================================================="));
    typedef std::map<int, char> MyMap;
    MyMap map;
    map.insert(std::make_pair(1, 'A'));
    map.insert(std::make_pair(2, 'B'));
    std::for_each(map.begin(), map.end(), pair_second(Printer()));
    std::for_each(map.begin(), map.end(), pair_second(&Print));

    return true;
}
Esempio n. 6
0
/*
 *  Method that determines the colors of silhouettes and background
 *
 *  @param  imageMatrix 2d array that contains color's
 *  @param  width The width of the image
 *  @param  height The height of the image
 *  @param  backgroundColor Variable that indicate background color
 */
void SilCounter::identifyColors(int** imageMatrix, int width, int height,int& backgroundColor){
    // map with key color and value amount of pixels with this color
    MyMap<int,int> colorFreq;

    // walk through 2d array and fill the map
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            colorFreq[imageMatrix[i][j]]++;
        }
    }

    // variables that will contain two most frequent colors
    int mostFreqFirst[2] = {0, 0};
    int mostFreqSecond[2] = {0, 0};

    // searching for two most frequent colors
    for(MyMap<int,int>::iterator it = colorFreq.begin(); it != colorFreq.end(); it++){
        if(it.node->value > mostFreqFirst[1]){
            mostFreqFirst[0] = it.node->key;
            mostFreqFirst[1] = it.node->value;
        }
    }
    for(MyMap<int,int>::iterator it = colorFreq.begin(); it != colorFreq.end(); it++){
        if((it.node->key > mostFreqSecond[1]) && (it.node->key != mostFreqFirst[0] )){
            mostFreqSecond[0] = it.node->key;
            mostFreqSecond[1] = it.node->value;
        }
    }

    // find average between most frequent colors
    int averageValue = (mostFreqFirst[0] + mostFreqSecond[0]) / 2;

    // set all colors that is lower then average to qrequent color with lower index to 0 and vice versa
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            imageMatrix[i][j] < averageValue ? imageMatrix[i][j] = 0 : imageMatrix[i][j] = 1;
        }
    }

    // check the perimeter of the image to identify pixels with what value are more often
    // it will be a background color
    int zeroCounter = 0;
    int oneCounter = 0;

    // checking upper and lower bounds
    for(int i = 0; i < width; i++){
        imageMatrix[0][i] ? oneCounter++ : zeroCounter++;

        imageMatrix[height-1][i] ? oneCounter++ : zeroCounter++;
    }

    // checking sides
    for(int i = 0; i < height; i++){
        imageMatrix[i][0] ? oneCounter++ : zeroCounter++;

        imageMatrix[i][width-1] ? oneCounter++ : zeroCounter++;
    }
    // set background color
    if(oneCounter > zeroCounter ){
        backgroundColor = 1;
    }
}
Esempio n. 7
0
void display(MyMap<string, int>& months) {
    MyMap<string, int>::iterator it;
    for (it = months.begin(); it != months.end(); it++)
        cout << it->first << "->" << it->second << endl;
    cout << endl;
}