Structural deformable models
utils.cpp
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <fstream>
3 #include <string>
4 #ifdef LINUX
5 #include <fnmatch.h>
6 #endif
7 #include "utils.h"
8 
9 using namespace std;
10 
11 static string matlabprog = "matlab -nojvw -nosplash -nodesktop -r ";
12 static string matpath = "./";
13 
14 static string __fnmatchpattern;
15 const string& __set_fnmatchpattern(const string& pattern)
16 { return __fnmatchpattern = pattern; }
17 #ifdef LINUX
18 int __fixed_fnmatch(const struct dirent* dent)
19 { return !fnmatch(__fnmatchpattern.c_str(), dent->d_name,0); }
20 #else
21 int __fixed_fnmatch(const struct dirent* dent)
22 { return 0; }
23 #endif
24 
25 const char* getTemp()
26 {
27  const char* tc = getenv("TEMP");
28  if(!tc) tc = getenv("TMP");
29  return tc;
30 }
31 
32 string& replaceAll(string& txt, char src, char tar)
33 {
34  int pos = 0;
35  while((pos = txt.find(src,pos)) != (int)txt.npos) {
36  txt[pos++] = tar;
37  }
38  return txt;
39 }
40 
41 int matlabCall(const std::string& cmd)
42 {
43  return system((matlabprog+"\""+cmd+", exit\"").c_str());
44 }
45 
46 /*
47  int matlabCall(const std::string& cmd)
48  {
49  string temp = getTemp();
50  string tmpfile = temp+"/matlabscript.m";
51  string wintmpfile = tmpfile;
52  replaceAll(wintmpfile,'/','\\');
53  ofstream mf(tmpfile.c_str());
54  if(mf) {
55  mf << "% This is an automatically generated matlab script file"<<endl;
56  mf << cmd << endl;
57  mf << "exit" << endl;
58  mf.close();
59  int ret = system((matlabprog+wintmpfile).c_str());
60  remove(tmpfile.c_str());
61  return ret;
62  } else cerr << "could not create tempfile " << tmpfile << endl;
63  return -1;
64  }
65 */
66 
67 #ifdef NOGLUT
68 extern "C" {
69  void glutBitmapCharacter(void *font, int character)
70  {}
71  int glutBitmapWidth(void *font, int character)
72  { return 0; }
73 }
74 #endif
static string matpath
Definition: utils.cpp:12
int matlabCall(const std::string &cmd)
Definition: utils.cpp:41
STL namespace.
const string & __set_fnmatchpattern(const string &pattern)
Definition: utils.cpp:15
string & replaceAll(string &txt, char src, char tar)
Definition: utils.cpp:32
static string __fnmatchpattern
Definition: utils.cpp:14
int __fixed_fnmatch(const struct dirent *dent)
Definition: utils.cpp:21
const char * getTemp()
Definition: utils.cpp:25
static string matlabprog
Definition: utils.cpp:11