//---------------------------------------------------------------------- int FFileDialog::changeDir (const FString& dirname) { FString lastdir = directory; FString newdir = dirname; if ( newdir.includes('~') ) newdir = newdir.replace('~', getHomeDir()); if ( newdir[0] == '/' ) setPath(newdir); else setPath(directory + newdir); switch ( readDir() ) { case -1: setPath(lastdir); return -1; case -2: setPath(lastdir); readDir(); return -2; case 0: if ( newdir == FString("..") ) { if ( lastdir == FString('/') ) filename.setText('/'); else { auto baseName = basename(C_STR(lastdir.c_str())); selectDirectoryEntry (baseName); } } else { FString firstname = dir_entries[0].name; if ( dir_entries[0].directory ) filename.setText(firstname + '/'); else filename.setText(firstname); } printPath(directory); filename.redraw(); filebrowser.redraw(); // fall through default: return 0; } }
static Array<String> LoadDir( String path ){ std::vector<String> files; #if _WIN32 WIN32_FIND_DATAW filedata; HANDLE handle=FindFirstFileW( OS_STR(path+"/*"),&filedata ); if( handle!=INVALID_HANDLE_VALUE ){ do{ String f=filedata.cFileName; if( f=="." || f==".." ) continue; files.push_back( f ); }while( FindNextFileW( handle,&filedata ) ); FindClose( handle ); }else{ printf( "FindFirstFileW for LoadDir(%s) failed\n",C_STR(path) ); fflush( stdout ); } #else if( DIR *dir=opendir( OS_STR(path) ) ){ while( dirent *ent=readdir( dir ) ){ String f=ent->d_name; if( f=="." || f==".." ) continue; files.push_back( f ); } closedir( dir ); }else{ printf( "opendir for LoadDir(%s) failed\n",C_STR(path) ); fflush( stdout ); } #endif return files.size() ? Array<String>( &files[0],files.size() ) : Array<String>(); }
static uim_lisp c_getaddrinfo(uim_lisp hostname_, uim_lisp servname_, uim_lisp hint_) { const char *hostname; char *servname = NULL; struct addrinfo *hints = C_PTR(hint_); struct addrinfo *res, *res0; uim_lisp ret_ = uim_scm_null(); int error; if (INTP(servname_)) { uim_asprintf(&servname, "%d", C_INT(servname_)); } else { servname = C_STR(servname_); } if (FALSEP(hostname_)) hostname = NULL; else hostname = REFER_C_STR(hostname_); error = getaddrinfo(hostname, servname, hints, &res0); if (error) { const char *errstr = gai_strerror(error); uim_notify_fatal("getaddrinfo: %s", errstr); free(servname); return uim_scm_f(); } free(servname); for (res = res0; res; res = res->ai_next) { ret_ = CONS(MAKE_PTR(res) , ret_); } return uim_scm_callf("reverse", "o", ret_); }
Skeleton::Skeleton(const char* name) : m_vJoints(0) , m_vGlobalPose(0) , m_vWorldGlobalPose(0) { m_ID = ComponentID; std::string sFileName(name); sFileName = "../Assets/" + sFileName; FILE* pFile = fopen(C_STR(sFileName, "_skeleton.bufa"), "r"); char c[256]; int iNumJoints, parentIndex; float transform[16]; fscanf(pFile, "%s", &c); fscanf(pFile, "%i", &iNumJoints); m_vJoints.Resize(iNumJoints); m_vGlobalPose.Resize(iNumJoints); m_vWorldGlobalPose.Resize(iNumJoints); for (int i = 0; i < iNumJoints; ++i) { fscanf(pFile, "%s", &c); for (int j = 0; j < 16; ++j) { fscanf(pFile, "%f", &transform[j]); } fscanf(pFile, "%i", &parentIndex); m_vJoints.Add(Joint(transform, parentIndex)); m_vGlobalPose.Add(new Matrix4); m_vWorldGlobalPose.Add(new Matrix4); } fclose(pFile); }
std::string util::debug::log_time ( std::string fmt ) { char tmstr[60]; time_t t = time ( 0 ); STRFTIME ( tmstr, C_STR ( fmt ), t ); return tmstr; }
IGL_INLINE void igl::matlab::validate_arg_double( const int i, const int nrhs, const mxArray * prhs[], const char * name) { requires_arg(i,nrhs,name); mexErrMsgTxt(mxIsDouble(prhs[i+1]), C_STR("Parameter '"<<name<<"' requires double argument")); }
IGL_INLINE void igl::matlab::validate_arg_scalar( const int i, const int nrhs, const mxArray * prhs[], const char * name) { requires_arg(i,nrhs,name); mexErrMsgTxt(mxGetN(prhs[i+1])==1 && mxGetM(prhs[i+1])==1, C_STR("Parameter '"<<name<<"' requires scalar argument")); }
//-------------------------------------------------------------------------- // Name PrintErrLoc // // //-------------------------------------------------------------------------- static void PrintErrLoc ( const YYLTYPE * loc, const char * s ) { fprintf( stderr, "%s(%d) : %s", loc->fileName != NULL ? C_STR(loc->fileName) : "stdin:", loc->line, s ); };
CRawStream & CRawStream::operator<<(const T_STRING & sValue) { REFERENCE< ::DATASTRUCTURE::CArray<T_BYTE> > tElement; tElement.Create(new ::DATASTRUCTURE::CArray<T_BYTE>((T_BYTE *)C_STR(sValue), sValue.GetLength() + 1)); ::DATASTRUCTURE::CStream::operator<<(tElement); return (* this); } // operator<<
static bool CopyFile( String srcpath,String dstpath ){ #if _WIN32 return CopyFileW( OS_STR(srcpath),OS_STR(dstpath),FALSE ); #elif __APPLE__ // Would like to use COPY_ALL here, but it breaks trans on MacOS - produces weird 'pch out of date' error with copied projects. // // Ranlib strikes back! // return copyfile( OS_STR(srcpath),OS_STR(dstpath),0,COPYFILE_DATA )>=0; #else int err=-1; if( FILE *srcp=_fopen( OS_STR( srcpath ),OS_STR( "rb" ) ) ){ err=-2; if( FILE *dstp=_fopen( OS_STR( dstpath ),OS_STR( "wb" ) ) ){ err=0; char buf[1024]; while( int n=fread( buf,1,1024,srcp ) ){ if( fwrite( buf,1,n,dstp )!=n ){ err=-3; break; } } fclose( dstp ); }else{ printf( "FOPEN 'wb' for CopyFile(%s,%s) failed\n",C_STR(srcpath),C_STR(dstpath) ); fflush( stdout ); } fclose( srcp ); }else{ printf( "FOPEN 'rb' for CopyFile(%s,%s) failed\n",C_STR(srcpath),C_STR(dstpath) ); fflush( stdout ); } return err==0; #endif }
// solution initialisation int cplex_solver::init_solutions() { int status; int cur_numcols = CPXgetnumcols (env, lp); if (solution != (double *)NULL) free(solution); if ((solution = (double *)malloc(nb_vars*sizeof(double))) == (double *)NULL) { fprintf (stderr, "cplex_solver: init_solutions: cannot get enough memory to store solutions.\n"); exit(-1); } status = CPXgetx (env, lp, solution, 0, cur_numcols-1); if ( status ) { fprintf (stderr, "cplex_solver: init_solutions: failed to get solutions.\n"); exit(-1); } else if (verbosity >= VERBOSE) { // Output model to file (when requested) writesol(C_STR("sol-cplex.xml")); } return 0; }
//-------------------------------------------------------------------------- // Name SymbolName // // //-------------------------------------------------------------------------- const char * SymbolName ( const TSymbol * sym ) { return sym->strName ? C_STR(sym->strName) : ""; };
//-------------------------------------------------------------------------- // Name StructName // // returns the name of a struct or "<noname>" if it is anonymous //-------------------------------------------------------------------------- const char * StructName ( const TStructDef * sDef ) { return sDef->strName ? C_STR(sDef->strName) : "<noname>"; };
T_ULONG CString::Find(const T_STRING & sValue) const { return (__strstr(m_String, C_STR(sValue))); } // Find
IGL_INLINE void igl::matlab::requires_arg(const int i, const int nrhs, const char *name) { mexErrMsgTxt((i+1)<nrhs, C_STR("Parameter '"<<name<<"' requires argument")); }
//-------------------------------------------------------------------------- // Name PrintType // // //-------------------------------------------------------------------------- void PrintType ( TYPE * type ) { TTypeNode * tnode; ASSERT( type ); ASSERT( type->tnode ); // Print the qualifier // if (type->isConst) printf( "const " ); if (type->isVolatile) printf( "volatile " ); if (type->isRestrict) printf( "__restrict " ); if (type->attr) printf( "__attr(0x%x) ", type->attr ); // Print the tnode // tnode = type->tnode; // print common flags // putchar( '<' ); if (tnode->isIntegral) putchar( 'I' ); if (tnode->isFloat) putchar( 'F' ); if (tnode->isArith) putchar( 'A' ); if (tnode->isScalar) putchar( 'S' ); putchar( '>' ); putchar( ' ' ); switch (tnode->node) { case NODE_BASIC: if (tnode->isSigned) printf( "signed " ); else printf( "unsigned " ); if (tnode->isShort) printf( "short " ); if (tnode->isLong) printf( "long " ); printf( "%s", BtName[tnode->info.basic] ); break; case NODE_POINTER: printf( "ptr to " ); PrintType( tnode->of ); break; case NODE_STRUCT: case NODE_UNION: case NODE_ENUM: printf( "%s %s", NodeName[tnode->node ], Struct_Name( tnode->info.structDef ) ); break; case NODE_FUNCTION: printf( "Function ( " ); // print the parameters ASSERT( tnode->info.funcParams ); if (tnode->info.funcParams) { TSymbol * param; // Check and print the explicit (void) parameter if (tnode->info.funcParams->locSymbols.first == NULL && !tnode->isImplicit) printf( "void" ); // iterate through all parameters declared in the parameter scope // for ( param = ID_GET_SYMBOL( tnode->info.funcParams->locSymbols.first ); param != NULL; param = ID_GET_SYMBOL( param->id.nextLocal ) ) { // print the name (which is optional) if (param->id.strName != NULL) printf( "%s", C_STR(param->id.strName) ); else if (param == EllipsisSym) printf( "..." ); printf( ":" ); if (param->type) PrintType( param->type ); // if this is not the last symbol, print a comma if (param != ID_GET_SYMBOL(tnode->info.funcParams->locSymbols.last)) printf( ", " ); } } printf( " ) returning " ); PrintType( tnode->of ); break; case NODE_ARRAY: printf( "array[" ); if (TGT_INT_NE_0( tnode->info.arrayLen )) printf( "%lu", (long unsigned)TGT_UINT_2_HOST_INT(tnode->info.arrayLen) ); printf( "] of " ); PrintType( tnode->of ); break; default: ASSERT( 0 ); } };
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { const auto mexErrMsgTxt = [](const bool v ,const char * msg) { igl::matlab::mexErrMsgTxt(v,msg); }; igl::matlab::MexStream mout; std::streambuf *outbuf = std::cout.rdbuf(&mout); mexErrMsgTxt(nrhs >= 4,"Four arguments expected"); Eigen::MatrixXd V,U0,U,bc; Eigen::MatrixXi F; Eigen::VectorXi b; int iters = 100; bool align_guess = true; double p = 1e5; igl::matlab::parse_rhs_double(prhs+0,V); igl::matlab::parse_rhs_index(prhs+1,F); igl::matlab::parse_rhs_index(prhs+2,b); igl::matlab::parse_rhs_double(prhs+3,bc); { int i = 4; while(i<nrhs) { mexErrMsgTxt(mxIsChar(prhs[i]),"Parameter names should be strings"); // Cast to char const char * name = mxArrayToString(prhs[i]); if(strcmp("P",name) == 0) { igl::matlab::validate_arg_scalar(i,nrhs,prhs,name); igl::matlab::validate_arg_double(i,nrhs,prhs,name); p = (double)*mxGetPr(prhs[++i]); }else if(strcmp("AlignGuess",name) == 0) { igl::matlab::validate_arg_scalar(i,nrhs,prhs,name); igl::matlab::validate_arg_logical(i,nrhs,prhs,name); align_guess = (bool)*mxGetLogicals(prhs[++i]); }else if(strcmp("Iters",name) == 0) { igl::matlab::validate_arg_scalar(i,nrhs,prhs,name); igl::matlab::validate_arg_double(i,nrhs,prhs,name); iters = (double)*mxGetPr(prhs[++i]); }else { mexErrMsgTxt(false,C_STR("Unknown parameter: "<<name)); } i++; } } { Eigen::MatrixXi C; igl::vertex_components(F, C); mexErrMsgTxt( C.maxCoeff() == 0, "(V,F) should have exactly 1 connected component"); const int ec = igl::euler_characteristic(F); mexErrMsgTxt( ec == 1, C_STR("(V,F) should have disk topology (euler characteristic = "<<ec)); mexErrMsgTxt( igl::is_edge_manifold(F), "(V,F) should be edge-manifold"); Eigen::VectorXd A; igl::doublearea(V,F,A); mexErrMsgTxt( (A.array().abs() > igl::EPS<double>()).all(), "(V,F) should have non-zero face areas"); } // Initialize with Tutte embedding to disk Eigen::VectorXi bnd; Eigen::MatrixXd bnd_uv; igl::boundary_loop(F,bnd); igl::map_vertices_to_circle(V,bnd,bnd_uv); igl::harmonic(V,F,bnd,bnd_uv,1,U0); if (igl::flipped_triangles(U0,F).size() != 0) { // use uniform laplacian igl::harmonic(F,bnd,bnd_uv,1,U0); } if(align_guess) { Eigen::MatrixXd X,X0,Y,Y0; igl::slice(U0,b,1,X); Y = bc; Eigen::RowVectorXd Xmean = X.colwise().mean(); Eigen::RowVectorXd Ymean = Y.colwise().mean(); Y0 = Y.rowwise()-Ymean; X0 = X.rowwise()-Xmean; Eigen::MatrixXd I = Eigen::MatrixXd::Identity(X0.cols(),X0.cols())*1e-5; Eigen::MatrixXd T = (X0.transpose()*X0+I).inverse()*(X0.transpose()*Y0); U0.rowwise() -= Xmean; U0 = (U0*T).eval(); U0.rowwise() += Ymean; } if(igl::flipped_triangles(U0,F).size() == F.rows()) { F = F.array().rowwise().reverse().eval(); } mexErrMsgTxt( igl::flipped_triangles(U0,F).size() == 0, "Failed to initialize to feasible guess"); igl::SLIMData slim; slim.energy = igl::SYMMETRIC_DIRICHLET; igl::slim_precompute(V,F,U0,slim,igl::SYMMETRIC_DIRICHLET,b,bc,p); igl::slim_solve(slim,iters); U = slim.V_o; switch(nlhs) { default: { mexErrMsgTxt(false,"Too many output parameters."); } case 2: { igl::matlab::prepare_lhs_double(U0,plhs+1); // Fall through } case 1: { igl::matlab::prepare_lhs_double(U,plhs+0); // Fall through } case 0: break; } // Restore the std stream buffer Important! std::cout.rdbuf(outbuf); }
// ends up constraint declaration int cplex_solver::end_add_constraints(void) { if (verbosity >= VERBOSE) writelp(C_STR("cplexpb.lp")); return 0; }