Ejemplo n.º 1
0
CV_IMPL void
cvMerge( const void* srcarr0, const void* srcarr1, const void* srcarr2,
         const void* srcarr3, void* dstarr )
{
    const void* sptrs[] = { srcarr0, srcarr1, srcarr2, srcarr3 };
    cv::Mat dst = cv::cvarrToMat(dstarr);
    int i, j, nz = 0;
    for( i = 0; i < 4; i++ )
        nz += sptrs[i] != 0;
    CV_Assert( nz > 0 );
    std::vector<cv::Mat> svec(nz);
    std::vector<int> pairs(nz*2);

    for( i = j = 0; i < 4; i++ )
    {
        if( sptrs[i] != 0 )
        {
            svec[j] = cv::cvarrToMat(sptrs[i]);
            CV_Assert( svec[j].size == dst.size &&
                svec[j].depth() == dst.depth() &&
                svec[j].channels() == 1 && i < dst.channels() );
            pairs[j*2] = j;
            pairs[j*2+1] = i;
            j++;
        }
    }

    if( nz == dst.channels() )
        cv::merge( svec, dst );
    else
    {
        cv::mixChannels( &svec[0], nz, &dst, 1, &pairs[0], nz );
    }
}
Ejemplo n.º 2
0
void ToolTip::SetTool(Tool * tool, LPRECT rect)
{
   TOOLINFO ti;
   LRESULT update;

   ti.cbSize = sizeof(TOOLINFO);
   ti.hwnd = m_hOwnerWnd;
   ti.uId = (UINT_PTR)tool;
   ti.lpszText = NULL;

   update = SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, (LPARAM) (LPTOOLINFO) &ti);

   ti.uFlags = TTF_SUBCLASS;
   ti.hinst = vdWindow;
   std::vector<TCHAR> svec(
	   tool->GetText(),
	   tool->GetText() + _tcslen(tool->GetText()) + 1);
   ti.lpszText = &(svec[0]);
   if (rect)
      ti.rect = *rect;
   else
      tool->GetRect(&ti.rect);

   if (update)
      SendMessage(m_hWnd, TTM_SETTOOLINFO, 0, (LPARAM) (LPTOOLINFO) &ti);
   else
      SendMessage(m_hWnd, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
}
Ejemplo n.º 3
0
int main(int argc, char **argv) {
  // Load the model from the file given as first non-option argument.
  // Normalization constant Z, will be calculated (takes long) if not provided.
  double Z = 0;
  int opt;
  while((opt = getopt(argc, argv, "z:")) != -1) {
    switch(opt) {
    case 'z': Z = atof(optarg); break;
    default: die("%s", usage);
    }
  }
  if (optind == argc) die("%s", usage);
  msg("Loading model from %s.", argv[optind]);
  if (Z > 0) msg("Will use fixed Z of %g.", Z);
  else msg("Will calculate Z, this may take some time...");
  model_t m = load_model(argv[optind], Z);

  // Read data from stdin and calculate logL
  char **toks = _d_calloc(m->ntok, sizeof(char *));
  svec_t *x = _d_calloc(m->ntok, sizeof(svec_t));
  double *logZ = _d_calloc(m->ntok, sizeof(double));
  for (size_t i = 1; i < m->ntok; i++) {
    logZ[i] = log(m->z[i]);
  }
  double logL = 0;
  size_t nline = 0;

  msg("Reading data from stdin (each dot = 1M lines)...");
  forline (line, NULL) {
    if ((++nline & ((1<<20)-1)) == 0) fputc('.', stderr);
    line[strlen(line)-1] = 0;	// chop newline
    size_t ntok = split(line, "\t", toks, m->ntok);
    if (ntok != m->ntok) die("Wrong number of columns.");
    for (size_t i = 0; i < m->ntok; i++) {
      if (*toks[i] == '\0') {
	x[i] = NULL;
      } else {
	x[i] = svec(m->v[i], toks[i]);
	assert(x[i]->vec != NULL && x[i]->cnt > 0);
      }
    }
    assert(x[0] != NULL);
    double logx = log(((double) x[0]->cnt) / m->n[0]);
    for (size_t i = 1; i < m->ntok; i++) {
      if (x[i] == NULL) continue;
      double logy = log(((double) x[i]->cnt) / m->n[i]);
      logL += logx + logy - logZ[i] - d2(x[0]->vec, x[i]->vec, m->ndim);
    }
  }
  fputc('\n', stderr);
  logL /= nline;
  _d_free(toks); _d_free(x); _d_free(logZ);
  free_model(m);
  msg("nlines=%zu avg-logL=%g", nline, logL);
}
Ejemplo n.º 4
0
int main(int argc, char const *argv[])
{
	std::vector<int> ivec(9, 8);
	std::vector<double> dvec(8, 9.9);
	std::vector<char> cvec(7, 'h');
	std::cout << count(ivec, 8) << std::endl;
	std::cout << count(dvec, 9.9) << std::endl;
	std::cout << count(cvec, 'h') << std::endl;

	std::vector<std::string> svec(6, "hey");
	std::cout << count(svec, std::string("hey")) << std::endl;
	return 0;
}
Ejemplo n.º 5
0
model_t load_model(char *modelfile, double Z) {  
  model_t m = _d_calloc(1, sizeof(struct model_s));
  char **toks = NULL;   	// array to tokenize each line
  size_t len1 = 0;		// length of the first line (used as upper bound on number of toks)

  // msg("Reading %s...", modelfile);
  forline (line, modelfile) {
    line[strlen(line)-1] = 0;	// chop newline
    if (len1 == 0) {
      len1 = strlen(line);
      toks = _d_calloc(len1, sizeof(char *));
    }
    size_t n = split(line, "\t", toks, len1);
    if (m->ndim == 0) {
      m->ndim = n - 2;
    }
    assert(n == m->ndim + 2);

    char *ptr = NULL;
    long int index = strtol(toks[0], &ptr, 10);
    assert(ptr > toks[0] && *ptr == ':' && index >= 0);
    if (index >= m->ntok) {
      size_t oldn = m->ntok;
      m->ntok = index + 1;
      m->v = _d_realloc(m->v, m->ntok * sizeof(darr_t));
      m->n = _d_realloc(m->n, m->ntok * sizeof(size_t));
      m->z = _d_realloc(m->z, m->ntok * sizeof(double));
      for (int i = oldn; i < m->ntok; i++) {
	m->v[i] = darr(0, svec_t);
	m->n[i] = 0;
	m->z[i] = 0;
      }
    }

    char *token = ptr+1;
    svec_t s = svec(m->v[index], token);
    assert(!strcmp(s->key, token));

    long int count = strtol(toks[1], &ptr, 10);
    assert(ptr > toks[1] && *ptr == 0 && count > 0);
    assert(s->cnt == 0);
    s->cnt = count;
    m->n[index] += count;

    assert(s->vec == NULL);
    s->vec = _d_calloc(m->ndim, sizeof(float));
    for (size_t i = 0; i < m->ndim; i++) {
      s->vec[i] = strtof(toks[i+2], &ptr);
      assert(ptr > toks[i+2] && *ptr == 0);
    }
  }
Ejemplo n.º 6
0
void benchmark_convert_type ()
{
    const size_t size = 10000000;
    const S testval(1.0);
    std::vector<S> svec (size, testval);
    std::vector<D> dvec (size);
    std::cout << Strutil::format("Benchmark conversion of %6s -> %6s : ",
                                 TypeDesc(BaseTypeFromC<S>::value),
                                 TypeDesc(BaseTypeFromC<D>::value));
    float time = time_trial (bind (do_convert_type<S,D>, OIIO::cref(svec), OIIO::ref(dvec)),
                             ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%7.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    D r = convert_type<S,D>(testval);
    OIIO_CHECK_EQUAL (dvec[size-1], r);
}
Ejemplo n.º 7
0
void TrayIcon::OnContextMenu()
{
   HMENU hMenu, hmenuTrackPopup;
   POINT pt;
   HRESULT res;
   int i;
   Desktop * desk;

   //Get the "base" menu
   hMenu = Locale::GetInstance().LoadMenu(IDC_VIRTUALDIMENSION);
   if (hMenu == NULL)
      return;
   hmenuTrackPopup = GetSubMenu(hMenu, 0);

   //Append the list of desktops
   InsertMenu(hmenuTrackPopup, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);

   i = 0;
   for( desk = deskMan->GetFirstDesktop();
        desk != NULL;
        desk = deskMan->GetNextDesktop())
   {
      MENUITEMINFO mii;

      mii.cbSize = sizeof(mii);
      mii.fMask = MIIM_STATE | MIIM_STRING | MIIM_ID | MIIM_DATA;
      if (desk->IsActive())
         mii.fState = MFS_CHECKED;
      else
         mii.fState = MFS_UNCHECKED;
      mii.dwItemData = (DWORD)desk;
	  std::vector<TCHAR> svec(
		  desk->GetText(),
		  desk->GetText() + _tcslen(desk->GetText()) + 1);
      mii.dwTypeData = &(svec[0]);
      mii.cch = (UINT)_tcslen(mii.dwTypeData);
      mii.wID = WM_USER + i++;
      InsertMenuItem(hmenuTrackPopup, 0, TRUE, &mii);
   }

   //And show the menu
   GetCursorPos(&pt);
   SetForegroundWindow(m_hWnd);
   res = TrackPopupMenu(hmenuTrackPopup, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, m_hWnd, NULL);

   //Process the resulting message
   if (res >= WM_USER)
   {
      Desktop * desk;
      MENUITEMINFO mii;

      mii.cbSize = sizeof(mii);
      mii.fMask = MIIM_DATA;
      GetMenuItemInfo(hmenuTrackPopup, res, FALSE, &mii);
      desk = (Desktop*)mii.dwItemData;

      deskMan->SwitchToDesktop(desk);
      InvalidateRect(m_hWnd, NULL, TRUE);
   }
   else
      PostMessage(m_hWnd, WM_COMMAND, res, 0);

   //Do not forget to destroy the menu
   DestroyMenu(hMenu);
}
Ejemplo n.º 8
0
/** Read examples into memory
 */
void CSeqFeature::LoadFeatures()
{ 
        unsigned int tmpFidx = 0;
        Scalar tmpFval = 0;
        unsigned int featureCnt = 0;
        unsigned int seqNum = 0;
        unsigned int phiNum = 0;
        unsigned int posNum1 = 0, posNum2 = 0;
        std::string line = "";
        std::string token = "";
        std::ifstream featureFp;
   
        featureFp.open(featureFile.c_str());   
        if(!featureFp.good()) 
        {
                string msg = "Cannot open feature file <" + featureFile + ">!";
                throw CBMRMException(msg, "CSeqFeature::ScanFeatureFile()");
        }
   
        // read header information
        int headerInfoCnt = 3; // min duration, max duration, feature dimension
        do {
                getline(featureFp, line);
                trim(line);
                if(IsBlankLine(line)) continue;  // blank line
                if(line[0] == '#') continue;  // comment line
                if(sscanf(line.c_str(),"maxDuration:%d",&maxDuration)==1) headerInfoCnt--;
                if(sscanf(line.c_str(),"minDuration:%d",&minDuration)==1) headerInfoCnt--;
                if(sscanf(line.c_str(),"globalFeatureDim:%d",&featureDimension)==1) headerInfoCnt--;
        } while(!featureFp.eof() && (headerInfoCnt != 0));
        
        assert(maxDuration >= minDuration);
        assert(featureDimension < (1<<30));  // featureDimension is normally less then 1 billion
                
        if(featureFp.eof())
                throw CBMRMException("Feature file does not contain valid examples","CSeqFeature::LoadFeatures()");
        
        // read sequences
        nnz = 0;
        while(!featureFp.eof()) 
        {
                // read sequence number
                do {
                        getline(featureFp, line);
                        trim(line);
                        if(IsBlankLine(line)) continue;  // blank line
                        if(line[0] == '#') continue;  // comment line
                        if(sscanf(line.c_str(),"sequence:%d",&seqNum)==1) break;
                } while(!featureFp.eof());
                
                if(featureFp.eof())
                        throw CBMRMException("Feature file does not contain valid phi:*","CSeqFeature::LoadFeatures()");
                
                
                // read phi:1 tag
                phiNum = 0;
                do {
                        getline(featureFp, line);
                        trim(line);
                        if(IsBlankLine(line)) continue;  // blank line
                        if(line[0] == '#') continue;  // comment line
                        if(sscanf(line.c_str(),"phi:%d",&phiNum)==1) break;
                } while(!featureFp.eof());
                
                if(featureFp.eof() || (phiNum != 1))
                        throw CBMRMException("Feature file does not contain valid phi:1","CSeqFeature::LoadFeatures()");
                
                // read phi:1 sparse vectors
                do {
                        getline(featureFp, line);
                        trim(line);
                        if(IsBlankLine(line)) continue;  // blank line
                        if(line[0] == '#') continue;  // comment line
                        
                        if(sscanf(line.c_str(),"phi:%d",&phiNum) == 1)
                                break;
                        
                        istringstream iss(line);
                        iss >> token;
                        if((sscanf(token.c_str(),"pos:%d",&posNum1) != 1))
                                throw CBMRMException("Feature file does not contain valid pos tag in phi:1","CSeqFeature::LoadFeatures()");
                        
                        TheMatrix svec(1,featureDimension,SML::SPARSE);
                        featureCnt = 0;
                        while(!iss.eof())
                        {
                                iss >> token;
                                if(sscanf(token.c_str(),svec_feature_index_and_value_format.c_str(),&tmpFidx, &tmpFval) != 2)
                                {
                                        ostringstream msg;
                                        msg << "Invalid #" << featureCnt + 1 << " sparse vector element in phi:"<< phiNum << " seq:" << seqNum << " pos:" << posNum1;
                                        throw CBMRMException(msg.str(),"CSeqFeature::LoadFeatures()");
                                }
                                svec.Set(0,tmpFidx,tmpFval);       
                                nnz++;
                        }
                        
                        if(featureCnt == 0)
                                throw CBMRMException("Feature file does not contain valid phi:2 sparse vector","CSeqFeature::LoadFeatures()");
                        
                        phi_1.push_back(svec);
                } while(!featureFp.eof());
                
                if(phi_1.size() < 1)
                        throw CBMRMException("Feature file does not contain valid phi:1","CSeqFeature::LoadFeatures()");
                
                numOfSeq = phi_1.size();
                
                if(featureFp.eof() || (phiNum != 2))
                        throw CBMRMException("Feature file does not contain valid phi:2","CSeqFeature::LoadFeatures()");
                
                // read phi:2 sparse vectors
                unsigned int prevPosNum1 = 0, prevPosNum2 = 0; 
                vector<TheMatrix> tmp_phi_2_svecs;
                featureCnt = 0;
                do {
                        getline(featureFp, line);
                        trim(line);
                        if(IsBlankLine(line)) continue;  // blank line
                        if(line[0] == '#') continue;  // comment line
                        
                        if((sscanf(line.c_str(),"phi:%d",&phiNum) == 1))
                                break;
                        
                        istringstream iss(line);
                        iss >> token;
                        if((sscanf(token.c_str(),"pos:%d,%d",&posNum1,&posNum2) != 2))
                                throw CBMRMException("Feature file does not containt valid pos tag in phi:2","CSeqFeature::LoadFeatures()");
                        
                        if(prevPosNum2 >= posNum2)
                        {
                                ostringstream msg;
                                msg << "previous posNum2 must be > current posNum2 in phi:2 (phi:2 pos:" << posNum1 << "," << posNum2;
                                throw CBMRMException(msg.str(),"CSeqFeature::LoadFeatures()");
                        }
                        
                        if(prevPosNum1 >= posNum1)
                        {
                                ostringstream msg;
                                msg << "previous posNum1 must be > current posNum1 in phi:2 (phi:2 pos:" << posNum1 << "," << posNum2;
                                throw CBMRMException(msg.str(),"CSeqFeature::LoadFeatures()");
                        }
                        
                        if(posNum1 != prevPosNum1)
                        {
                                phi_2.push_back(tmp_phi_2_svecs);
                                tmp_phi_2_svecs.clear();                                
                        }
                        
                        TheMatrix svec(1,featureDimension,SML::SPARSE);
                        featureCnt = 0;
                        while(!iss.eof())
                        {
                                iss >> token;
                                if(sscanf(token.c_str(),svec_feature_index_and_value_format.c_str(),&tmpFidx, &tmpFval) != 2)
                                {
                                        ostringstream msg;
                                        msg << "Invalid #" << featureCnt + 1 << " sparse vector element in phi:"<< phiNum << " seq:" << seqNum << " pos:" << posNum1;
                                        throw CBMRMException(msg.str(),"CSeqFeature::LoadFeatures()");
                                }
                                svec.Set(0,tmpFidx,tmpFval);    
                                nnz++;
                        }
                        
                        if(featureCnt == 0)
                                throw CBMRMException("Feature file does not containt valid phi:2 sparse vector","CSeqFeature::LoadFeatures()");
                        
                        tmp_phi_2_svecs.push_back(svec);

                } while(!featureFp.eof());
                
                if(phi_2.size() < 1)
                        throw CBMRMException("Feature file does not contain phi:2","CSeqFeature::LoadFeatures()");
        }
        
        // data matrix density
        density = ((double)nnz/featureDimension)/numOfSeq;
   
        featureFp.close();
}