Пример #1
0
//! give the required data, fill in the necessary information of a grasp
bool GraspitDBGrasp::SetGraspParameters(const std::vector<double>& prejoint,
										const std::vector<double>& prepos,
										const std::vector<double>& finjoint,
										const std::vector<double>& finpos){
  //if(mHand is null, check if we there is a current world hand and if that world hand is the appropriate kind:
  if(!mHand){
    Hand * currentHand = graspItGUI->getIVmgr()->getWorld()->getCurrentHand();
    if(!currentHand || getHandDBName(currentHand).compare(QString(getHandName().c_str())) ){
      //if not, attempt to load the hand with the appropriate name, and then set it to the current world hand
      mHand = loadHandFromDBName(QString(getHandName().c_str()));
      if (!mHand)
	return false;
    }      
    else
      mHand = currentHand;//if the current hand is the appropriate hand, set mHand to it -- WARNING this has some really funky implications for multithreading
    
  }

	mPreGrasp = new GraspPlanningState(mHand);
	initializeHandObjectState(prejoint, prepos, mPreGrasp);

	mFinalGrasp = new GraspPlanningState(mHand);
	initializeHandObjectState(finjoint, finpos, mFinalGrasp);
	return true;
}
HTREEITEM CGrannyListView::InsertEquipItem(CTreeCtrl& tree, HTREEITEM htRoot, Uint32 id, cGrannyModelTD *model)
{
	const UINT nMask = TVIF_TEXT | TVIF_PARAM;

	if (!model) return NULL;

	CString strText;
	strText.Format("%04d %s", GETID(id), getFileName(model->m_filename).c_str());
	
	HTREEITEM htChar = tree.InsertItem(nMask, strText, 0,0,0,0, SETCHAR(id), htRoot, 0);

	strText.Format("file: %s%s", isFileExist(model->m_filename) ? "":"(x) ",model->m_filename.c_str());
	tree.InsertItem(strText, htChar);

	strText.Format("id: %d (0x%08x)", id, id);
	tree.InsertItem(strText, htChar);

	if (!model->desc.empty()) {
		strText.Format("desc: %s", model->desc.c_str());
		tree.InsertItem(strText, htChar);
	}

	strText.Format("hand: %s", getHandName(model->hand).c_str());
	tree.InsertItem(strText, htChar);

	strText.Format("bone left: %d, right: %d", model->left_hand_bone, model->right_hand_bone);
	tree.InsertItem(strText, htChar);

	return htChar;
}
Пример #3
0
//------------------------------------------------------------------------------
// Prints the line of information for a single given hand, hands[i]. 
//------------------------------------------------------------------------------
void printHand (int i, Strategy **chart, int showWinPct, FILE *file)
{
  int j; 
	char *handName;

  if (hands[i].isObvious) //don't print "obvious" hands 
    return; 
    
  fprintf(file, "\\hline\n"); 
	handName = getHandName(hands[i]); 
  fprintf(file, "%s ", handName); 
  
  for (j = 2; j <= NUM_CARDS; j++)
    fprintf(file, " & %s ", actionSymbol(chart[i][j].action)); 
  fprintf(file, " & %s \\\\\n", actionSymbol(chart[i][1].action)); //ace 
  
  if (showWinPct)
  {
    for (j = 2; j <= NUM_CARDS; j++)
      fprintf(file, " & %.0f/%.0f ", 100.*chart[i][j].winPct, 
            100.*chart[i][j].lossPct);
    fprintf(file, " & %.0f/%.0f \\\\\n", 100.*chart[i][1].winPct, 
          100.*chart[i][1].lossPct); //ace 
  }

	free(handName);
}
HTREEITEM CGrannyListView::InsertModelAOS(CTreeCtrl& tree, HTREEITEM htRoot, Uint32 id, cGrannyModelAOS *model)
{
	const UINT nMask = TVIF_TEXT | TVIF_PARAM;

	if (!model) return NULL;

	CString strText;
	strText.Format("%04d %s", GETID(id), model->desc.c_str());

	HTREEITEM htChar  = tree.InsertItem(nMask, strText, 0,0,0,0, SETCHAR(id), htRoot, 0);
	HTREEITEM htPart  = tree.InsertItem("part", htChar);
	//HTREEITEM htAnim  = tree.InsertItem("anim", htChar);
	HTREEITEM htEquip = tree.InsertItem("equip", htChar);

	std::map <int, cGrannyModelTD *> models = model->models;

	if (models.empty()) return htEquip;

	for (std::map<int, cGrannyModelTD*>::iterator i = models.begin(); i != models.end(); i++) {
		cGrannyModelTD *td = i->second;
		if (!td) continue;

		UINT id2 = 0xC000 | id<< 4 | i->first;
		strText.Format("%2d %s", i->first, cGrannyLoader::GetAosBodyName(i->first).c_str());
		HTREEITEM htPart2 = tree.InsertItem(nMask, strText, 0,0,0,0, SETCHAR(id2), htPart, 0);
		strText.Format("file: %s", td->m_filename.c_str());
		tree.InsertItem(strText, htPart2);
	}

	if (!model->desc.empty()) {
		strText.Format("desc: %s", model->desc.c_str());
		tree.InsertItem(strText, htChar);
	}

	strText.Format("hand: %s", getHandName(model->hand).c_str());
	tree.InsertItem(strText, htChar);

	strText.Format("bone left: %d, right: %d", model->left_hand_bone, model->right_hand_bone);
	tree.InsertItem(strText, htChar);

#if 0
	// part animation is same.
	std::map<int, std::string>& anim_names = models.begin()->second->animation_names;
	for (std::map<int, std::string>::iterator i = anim_names.begin(); i != anim_names.end(); i++) {
		strText.Format("%s (%s,%d)", getFileName(i->second).c_str(), 
			AnimTypeData::GetAnimTypeName(i->first).c_str(),i->first);
		HTREEITEM htItem = tree.InsertItem(nMask, strText, 0,0,0,0, SETANIM(i->first), htAnim,0);
		strText.Format("file: %s%s", isFileExist(i->second) ? "":"(x) ",i->second.c_str());
		tree.InsertItem(strText, htItem);
	}
#endif

	return htEquip;
}
HTREEITEM CGrannyListView::InsertModelTD(CTreeCtrl& tree, HTREEITEM htRoot, Uint32 id, cGrannyModelTD *model)
{
	const UINT nMask = TVIF_TEXT | TVIF_PARAM;

	if (!model) return NULL;

	CString strText;
	strText.Format("%04d %s", GETID(id), getFileName(model->m_filename).c_str());
	
	HTREEITEM htChar  = tree.InsertItem(nMask, strText, 0,0,0,0, SETCHAR(id), htRoot, 0);
	//HTREEITEM htAnim  = tree.InsertItem("anim", htChar);
	HTREEITEM htEquip = IsPlayerModelID(id) ? tree.InsertItem("equip", htChar) : NULL;
	
	strText.Format("file: %s%s", isFileExist(model->m_filename) ? "":"(x) ",model->m_filename.c_str());
	tree.InsertItem(strText, htChar);

	if (!model->desc.empty()) {
		strText.Format("desc: %s", model->desc.c_str());
		tree.InsertItem(strText, htChar);
	}

	strText.Format("hand: %s", getHandName(model->hand).c_str());
	tree.InsertItem(strText, htChar);

	strText.Format("bone left: %d, right: %d", model->left_hand_bone, model->right_hand_bone);
	tree.InsertItem(strText, htChar);

#if 0
	strText.Format("%s (default)", getFileName(model->defaultanimname).c_str());
	HTREEITEM htItem = tree.InsertItem(nMask, strText, 0,0,0,0, SETANIM(AnimTypeData::GetAnimType("default.animation")), htAnim, 0);
	strText.Format("file: %s%s", isFileExist(model->defaultanimname) ? "":"(x) ",model->defaultanimname.c_str());
	tree.InsertItem(strText, htItem);
	

	std::map<int, std::string>& anim_names = model->animation_names;
	for (std::map<int, std::string>::iterator i = anim_names.begin(); i != anim_names.end(); i++) {
		strText.Format("%s (%s,%d)", getFileName(i->second).c_str(), 
			AnimTypeData::GetAnimTypeName(i->first).c_str(),i->first);
		HTREEITEM htItem = tree.InsertItem(nMask, strText, 0,0,0,0, SETANIM(i->first), htAnim,0);
		strText.Format("file: %s%s", isFileExist(i->second) ? "":"(x) ",i->second.c_str());
		tree.InsertItem(strText, htItem);
	}
#endif

	return htEquip;
}
Пример #6
0
//------------------------------------------------------------------------------
// Prints the line of results from simulations for a single hand. 
//------------------------------------------------------------------------------
void printHandSims (int i, HandSim **simsChart, Strategy **chart, FILE *file,
              int nsims)
{
  const double THRESHHOLD = .01; //amount above which to print "errors" in red 
  int j; 
  double winpct, losspct, windiff, lossdiff; 

  if (hands[i].isObvious) //don't print "obvious" hands 
    return; 
    
  fprintf(file, "\\hline\n"); 
  fprintf(file, "%s ", getHandName(hands[i])); 
  
  for (j = 2; j <= NUM_CARDS; j++)
    fprintf(file, " & %s ", actionSymbol(chart[i][j].action)); 
  fprintf(file, " & %s \\\\\n", actionSymbol(chart[i][1].action)); //ace 
  
  for (j = 2; j <= NUM_CARDS; j++)
  {
    winpct = ((double) simsChart[i][j].nwins) / nsims; 
    losspct = ((double) simsChart[i][j].nlosses) / nsims; 
    windiff = winpct - chart[i][j].winPct; 
    lossdiff = losspct - chart[i][j].lossPct; 
    
    fprintf(file, " & "); 
    if (fabs(windiff) > THRESHHOLD) 
    {
      fprintf(file, "\\textcolor{red}{"); 
      fprintf(file, "%c%.0f", windiff > 0. ? '+' : '-', 100. * fabs(windiff)); 
    }
    else
      fprintf(file, "%.0f", 100. * winpct); 
    if (fabs(windiff) > THRESHHOLD) 
      fprintf(file, "}"); 
    fprintf(file, "/"); 
    if (fabs(lossdiff) > THRESHHOLD) 
    {
      fprintf(file, "\\textcolor{red}{"); 
      fprintf(file, "%c%.0f", lossdiff > 0. ? '+' : '-', 100. * fabs(lossdiff)); 
    }
    else
      fprintf(file, "%.0f", 100. * losspct); 
    if (fabs(lossdiff) > THRESHHOLD) 
      fprintf(file, "}"); 
  }
  winpct = ((double) simsChart[i][1].nwins) / nsims; 
  losspct = ((double) simsChart[i][1].nlosses) / nsims; 
  windiff = winpct - chart[i][1].winPct; 
  lossdiff = losspct - chart[i][1].lossPct; 

  fprintf(file, " & "); 
  if (fabs(windiff) > THRESHHOLD) 
  {
    fprintf(file, "\\textcolor{red}{"); 
    fprintf(file, "%c%.0f", windiff > 0. ? '+' : '-', 100. * fabs(windiff)); 
  }
  else
    fprintf(file, "%.0f", 100. * winpct); 
  if (fabs(windiff) > THRESHHOLD) 
    fprintf(file, "}"); 
  fprintf(file, "/"); 
  if (fabs(lossdiff) > THRESHHOLD) 
  {
    fprintf(file, "\\textcolor{red}{"); 
    fprintf(file, "%c%.0f", lossdiff > 0. ? '+' : '-', 100. * fabs(lossdiff)); 
  }
  else
    fprintf(file, "%.0f", 100. * losspct); 
  if (fabs(lossdiff) > THRESHHOLD) 
    fprintf(file, "}"); 

  fprintf(file, " \\\\\n"); 
}