// Method reads body-nbr from Ideas univ. file
int
InputIdeasWF::readBodyNbr(char* s) 
{
  int dummy;
  int nbr;

  istrstream strline(s);
  // Body nbr is field-4 (color code)
    strline >> dummy >> dummy >> dummy >> nbr;
  
  return nbr;
}
// Method reads curve-type info from Ideas univ. file (801)
ecif_geometryType
InputIdeasWF::readGeomType(char* s)
{
  ecif_geometryType g_type = ECIF_LINE;
  int dummy;
  int cnstr_flag;
  int nurbs_flag;

  istrstream strline(s);
  // Points/constraints-exist flag is field-3 (0=no, 1=yes).
  strline >> dummy >> dummy >> cnstr_flag;  
  // Nurbs-format flag is field-5 (0=no, 1=yes)
  strline >> dummy >> nurbs_flag;   

  if (nurbs_flag == 1)
    g_type = ECIF_NURBS;

  return g_type;
}
// Method reads body-name from Ideas univ. file
char*
InputIdeasWF::readBodyName(char* s)
{
  int dummy;
  char* name = new char[MAXBODYNAME+1];
  char* cptr;

  istrstream strline(s);  
  // Body 'name' is field-4 (simply color code)
  strline >> dummy >> dummy >> dummy;   
  cptr = name;
  int i = 0; char c;
  // Trim left all blanks
  while (strline.get() == ' ');
  // read all non-blanks into name
  while (((c = strline.get()) != ' ') && (i < MAXBODYNAME)) {
    *cptr = c;
    cptr++; i++;
  }
  *cptr = '\0';
  return name;
}
// Method reads a spline-segment-element in nurbs-form from Ideas univ. file (801)
bool
InputIdeasWF::readNurbs(Body* body, char* buffer)
{
  static ecif_EdgeGeometry_X edge;
  init_trx_data(edge);

  int i,j,pos;
  // *** Control-point section.
  int nf_vec[NF_SIZE];

  // Read curve-desrcribing vector.
  readFileLine(infile, buffer);
  istrstream strline(buffer);
  for (i = 0; i < NF_SIZE; i++) {
    strline >> nf_vec[i];
  }
  
  // Pick curve-defining factors from nf-vector.
  int nf_dim  = nf_vec[NFI_DIM];  // Dimension of control-points.
  int nf_len  = nf_vec[NFI_LEN];  // Length of data.
  int nf_n  = nf_vec[NFI_N];    // Nof control points.
  int nf_nk   = nf_vec[NFI_NK];   // Nof knot points.
  int nf_k  = nf_vec[NFI_K];    // Order of basis.

  // Read nurbs-curve defining data into a temporary data-vector.
  double* ct_data = new double[nf_len]; // a temporary data vector.
  
  int nf_rows; // nof data-rows in this section.
  if ( NF_COLS > 0 )
    nf_rows = nf_len / NF_COLS;
  else
    nf_rows = nf_len;

  pos = 0;

  for (i = 0; i < nf_rows; i++) {
    readFileLine(infile, buffer);
    istrstream strline(buffer);
    for (j = 0; j < NF_COLS; j++) {
      strline >> ct_data[pos++];
    }
  }

  // Now create final data-structures for nurbs-curve and
  // read them from temporary data-vector *ct_data*.

  // *** Control points (at the beginning of the data)
  Point4* ct_points = new Point4[nf_n];

  pos = 0;
  for (i = 0; i < nf_n; i++) {

    //We use always 4D-points
    int pos = 4 * i;
    ct_points[i][0] = 0.0;
    ct_points[i][1] = 0.0;
    ct_points[i][2] = 0.0;
    ct_points[i][3] = 1.0;

    for (j = 0; j < nf_dim; j++) {
      //Note: coordinates are scaled by unit
      ct_points[i][j] = model->unit.conv[j] * ct_data[pos++];
    }
  }

  // *** Next come knot-points
  double* knots = new double[nf_nk]; 

  pos = nf_n * nf_dim;
  for (i = 0; i < nf_nk; i++) {
    knots[i] = ct_data[pos + i];
  }

  //---Create a nurbs-curve body-element

  //-Two vertices
  // first vertex from the first control-point
  // second vertex from the last control-point
  edge.start = new Point3[1]; 
  edge.end = new Point3[1];

  for (i = 0; i < 3; i++) {
    edge.start[0][i] = ct_points[0][i] / ct_points[0][3];
    edge.end[0][i] = ct_points[nf_n - 1][i] / ct_points[nf_n - 1][3];
  }

  //-Other parameters
  edge.type = ECIF_NURBS;
  edge.isRational = (nf_dim == 4); // Is this ok !!!###!!!
  edge.degree = nf_k - 1;
  edge.nofKnots = nf_nk;
  edge.nofCpoints = nf_n;
  edge.knots = knots;
  edge.cpoints = ct_points;
  
  //-Create a new 2D element into the body
  int body_layer = 0;
  createBodyElement2D(body, body_layer, edge);

  // *** Defining points section.
  // Read nof defining point
  // NOT IN USE in practice. Used only to read 'off' the data from file !!!***!!!
  int df_n;
  readFileLine(infile, buffer);
  strline >> df_n;

  // Read defining-points desrcibing vector. All data on a single line.
  // This is a table where there are three items per defining-point:
  // 1. curve passes through point flag (0=no, 1=yes).
  // 2. tangent/derivative vector specified (0=no, 1=tangent, 2=derivative).
  // 3. curvature specified (0=no, 1=yes).
  readFileLine(infile, buffer);

  // Jump to the end of defining points section.
  readFileLine(infile, buffer, df_n);

  reset_trx_data(edge);

  return true;
}
Exemple #5
0
void LLFloaterAO::onNotecardLoadComplete(LLVFS *vfs,const LLUUID& asset_uuid,LLAssetType::EType type,void* user_data, S32 status, LLExtStat ext_status)
{
	if(status == LL_ERR_NOERR)
	{
		S32 size = vfs->getSize(asset_uuid, type);
		U8* buffer = new U8[size];
		vfs->getData(asset_uuid, type, buffer, 0, size);

		if(type == LLAssetType::AT_NOTECARD)
		{
			LLViewerTextEditor* edit = new LLViewerTextEditor("",LLRect(0,0,0,0),S32_MAX,"");
			if(edit->importBuffer((char*)buffer, (S32)size))
			{
				llinfos << "ao nc decode success" << llendl;
				std::string card = edit->getText();
				edit->die();

				LUA_CALL("OnAONotecardRead") << card << LUA_END;

				mAOAllAnims.clear();
				mAOStands.clear();
				//mAODefaultAnims.clear();

				struct_stands standsloader;
				struct_all_anims all_anims_loader;

				typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
				boost::char_separator<char> sep("\n");
				tokenizer tokline(card, sep);

				for (tokenizer::iterator line = tokline.begin(); line != tokline.end(); ++line)
				{
					std::string strline(*line);

					boost::regex type("^(\\s*)(\\[ )(.*)( \\])");
					boost::smatch what; 
					if (boost::regex_search(strline, what, type)) 
					{
						boost::char_separator<char> sep("|,");
						std::string stranimnames(boost::regex_replace(strline, type, ""));
						tokenizer tokanimnames(stranimnames, sep);
						for (tokenizer::iterator anim = tokanimnames.begin(); anim != tokanimnames.end(); ++anim)
						{
							std::string strtoken(what[0]);
							std::string stranim(*anim);
							int state = GetStateFromToken(strtoken.c_str());
							LLUUID animid(getAssetIDByName(stranim));

							if (!(animid.notNull()))
							{
								cmdline_printchat(llformat("Warning: animation '%s' could not be found (Section: %s).",stranim.c_str(),strtoken.c_str()));
							}
							else
							{
								all_anims_loader.ao_id = animid; all_anims_loader.anim_name = stranim.c_str(); all_anims_loader.state = state; mAOAllAnims.push_back(all_anims_loader);

								if (state == STATE_AGENT_STAND)
								{
									standsloader.ao_id = animid; standsloader.anim_name = stranim.c_str(); mAOStands.push_back(standsloader);
									continue;
								}

								for (std::vector<struct_default_anims>::iterator iter = mAODefaultAnims.begin(); iter != mAODefaultAnims.end(); ++iter)
								{
									if (state == iter->state) iter->ao_id = animid;
								}
							}
						}
					} 
				}
				llinfos << "ao nc read sucess" << llendl;

				loadComboBoxes();

				run();
			}
			else
			{
				llinfos << "ao nc decode error" << llendl;
			}
		}
	}
	else
	{
		llinfos << "ao nc read error" << llendl;
	}
}
void MatrixFactorization::test(string in, string out){
   
    ifstream is(in.c_str());
    ofstream os(out.c_str());
    string row, col;
    double val, pred, err, loss, clf_err;
    char line[MAX_LINE_LENGTH];
    int n;
    Triplet* p = new Triplet();
    
    loss = 0.0;
    clf_err = 0.0;
    n = 0;

    while(is.getline(line, MAX_LINE_LENGTH)){
        string strline(line);
        row = string(strtok(line, " "));
        col = string(strtok(NULL, " "));
        val = atof(strtok(NULL, " "));
       
        if(_matrix->rows()->find(row) == _matrix->rows()->end()){
            p->row = -1;
        }
        else{
            p->row = _matrix->rows()->find(row)->second;
        }

        if(_matrix->cols()->find(col) == _matrix->cols()->end()){
            p->col = -1;
        }
        else{
            p->col = _matrix->cols()->find(col)->second;
        }

        p->val = val;

        // cerr << row << " " << p->row << " " << col << " " << p->col << " " << p->val << endl;
        pred = predict(p);
        // cerr << pred << endl;
        err = p->val - pred;

        if(_params->type == T_REGRESS){
            loss += err * err;
            os << pred << "\t" << strline << endl;
        }

        else if(_params->type == T_CLASSIFY){
            loss -= p->val * log(pred) + (1.0 - p->val) * log(1.0 - pred);
            if((pred >= 0.5 && p->val == 0.0) || (pred < 0.5 && p->val == 1.0))
                clf_err += 1.0;
            os << (pred >= 0.5 ? "1" : "0") << "\t" << setprecision(4) << pred << "\t" << strline << endl;
        }

        n++;
    }

    is.close();
    os.close();

    if(_params->type == T_REGRESS){
        loss = sqrt(1.0 * loss / n);
        cerr << "[Test]: Loss=" << setprecision(4) << loss << endl;
    }
    else if(_params->type == T_CLASSIFY){
        loss = 1.0 * loss / n;
        clf_err = 1.0 * clf_err / n;
        cerr << "[Test]: Loss=" << setprecision(4) << loss << " ";
        cerr << "Accuracy=" << setprecision(4) << 100.0 * (1.0 - clf_err) << "% " << endl;
    }

}