25 #include <Utils/IOUtils.hh>
27 #include <Base/Image/ImageConvert.hh>
28 #include <Base/Common/FileHandling.hh>
36 #define SUBDIRSEP "\\"
43 ExtractSubPaths(
const std::string& environmentVariable,
44 std::vector<std::string>& subPaths)
47 if (getenv(environmentVariable.c_str()) == NULL)
49 BIASWARN(
"environment variable "<<environmentVariable<<
" not found");
53 string concatenatedPaths(getenv(environmentVariable.c_str()));
56 vector<unsigned int> seperators;
57 string::size_type index = concatenatedPaths.find(SEPERATOR, 0);
58 while (index != string::npos)
60 seperators.push_back(index);
62 index = concatenatedPaths.find(SEPERATOR, index);
64 seperators.push_back(concatenatedPaths.size());
66 subPaths.push_back(concatenatedPaths.substr(0, seperators[0]));
67 for (
unsigned int i = 0; i < seperators.size() - 1; i++)
69 subPaths.push_back(concatenatedPaths.substr(seperators[i] + 1,
70 seperators[i + 1] - seperators[i] - 1));
77 IOUtils::FindFile(
const std::string& searchPaths,
78 const std::string& baseFileName, std::string& fullFileName)
82 vector<string> subPaths;
83 vector<unsigned int> seperators;
84 string::size_type index = searchPaths.find(SEPERATOR, 0);
85 while (index != string::npos)
87 seperators.push_back(index);
89 index = searchPaths.find(SEPERATOR, index);
91 seperators.push_back(searchPaths.size());
93 subPaths.push_back(searchPaths.substr(0, seperators[0]));
94 for (
unsigned int i = 0; i < seperators.size() - 1; i++)
96 subPaths.push_back(searchPaths.substr(seperators[i] + 1,
97 seperators[i + 1] - seperators[i] - 1));
100 for (
unsigned int i = 0; i < subPaths.size() && !found; i++)
102 fullFileName = subPaths[i];
103 fullFileName += SUBDIRSEP;
104 fullFileName += baseFileName;
105 found = FileHandling::FileExists(fullFileName);
113 IOUtils::FindFileEnv(
const std::string& environmentVariable,
114 const std::string& baseFileName, std::string& fullFileName)
117 if (getenv(environmentVariable.c_str()) == NULL)
119 BIASWARN(
"environment variable "<<environmentVariable<<
" not found");
122 return FindFile(getenv(environmentVariable.c_str()), baseFileName,
127 IOUtils::FindShaderFile(
const string& shaderFileName,
string& res)
129 if (!IOUtils::FindFileEnv(
"SHADERSRC", shaderFileName, res))
131 cout <<
"failed loading shader " << shaderFileName << endl;
138 IOUtils::ExtendOutName(
const std::string& outname,
const std::string& suffix,
139 const std::string& extension)
141 string path, base, ext;
142 FileHandling::SplitName(outname, path, base, ext);
143 path = FileHandling::StripTerminatingSlash(path);
144 if (path.size() == 0)
148 pathbase = path +
"\\"+ base;
150 pathbase = path +
"/" + base;
153 return (pathbase +
"_" + extension +
"." + suffix);
157 IOUtils::ExtendOutName(
const std::string& outname,
const std::string& extension)
159 string path, base, ext;
160 FileHandling::SplitName(outname, path, base, ext);
161 path = FileHandling::StripTerminatingSlash(path);
162 if (path.size() == 0)
166 pathbase = path +
"\\"+ base;
168 pathbase = path +
"/" + base;
171 return (pathbase +
"_" + extension + ext);
176 IOUtils::ParseCommandLineEvalHelp(
Param& params,
int argc,
char* argv[])
179 bool* help = params.
AddParamBool(
"help",
"Display help message",
false,
'h', miscGrpID);
192 IOUtils::ParseCommandLineEvalHelp(
Param& params,
int argc,
char* argv[],
196 bool* help = params.
AddParamBool(
"help",
"Display help message",
false,
'h', miscGrpID);
209 IOUtils::PrintWithLineNumbers(
const std::string& text, std::ostream& out)
211 std::istringstream in(text);
214 while (std::getline(in, line))
217 out << lineNumber <<
" | " << line << std::endl;
222 #ifdef BIAS_HAVE_XML2
224 IOUtils::GetProjectionParametersPerspective(
ImageBase& imgBase,
228 if (!GetProjection(imgBase, tempProj))
236 BIASERR(
"contained projection is not of type projection parameters perspective!");
248 if (MD->
Find(AppData::MD_Projection,
"#[Projection]", ad) >= 0)
251 std::string flatproj;
252 if (ad.
tag == AppData::MD_USE_ASCII)
257 char *tmp =
new char[ad.
length + 1];
269 BIASERR(
"Failed to parse string with length: "<<ad.
length<<
" string: "
276 BIASERR(
"returning invalid pose!");
286 #endif //BIAS_HAVE_XML2
288 IOUtils::ProgressIndicator::operator++(
int)
290 switch (indicatorState)
306 std::cerr << std::flush;
308 if (indicatorState > 3)
313 IOUtils::ProgressIndicator::Reset()
319 IOUtils::ProgressBar::Init(
const int steps)
321 incrementThreshold_ = 1;
323 std::cerr <<
"[" << std::flush;
324 for (
int i = 0; i < steps; i++)
328 std::cerr <<
"]\r[" << std::flush;
332 IOUtils::ProgressBar::Init(
const int steps,
const int maxLength)
334 if (steps <= maxLength)
340 float n =
static_cast<float> (steps) / static_cast<float> (maxLength);
342 incrementThreshold_ =
static_cast<int> (ceil(n));
348 IOUtils::ProgressBar::operator++(
int)
350 if (++incrementPos_ == incrementThreshold_)
354 std::cerr <<
"|" << std::flush;
363 if (ImageIO::Load(filename, img) != 0)
365 BIASERR(
"could not load specified image named: "<<filename);
370 case ImageBase::ST_float:
376 if (ImageConvert::ConvertST(img, outcome, ImageBase::ST_float) != 0)
378 BIASERR(
"could not convert storage type!");
389 IOUtils::SaveForPlot(
const std::string& filename,
390 const std::vector<double>& x_vector,
const std::vector<double>& y_vector)
392 BIASASSERT(x_vector.size() == y_vector.size());
393 std::ofstream fs(filename.c_str());
401 for (
unsigned int row = 0; row < x_vector.size(); row++)
403 fs << x_vector[row] <<
"\t" << y_vector[row] <<
"\n";
413 const std::string& fileName,
416 unsigned int& height,
417 unsigned int& channels)
419 if(ImageIO::Load(fileName, img)!=0) {
420 BIASERR(
"could not load image named "<<fileName);
431 IOUtils::ReadIn2DPointList(
const std::string& fileName,
434 std::ifstream ifs(fileName.c_str());
446 pointLst.push_back(pt);
457 IOUtils::ReadIn2DPointList(
const std::string& fileName,
458 std::vector<unsigned int>& xPos,
459 std::vector<unsigned int>& yPos)
461 std::ifstream ifs(fileName.c_str());
int XMLReadFromString(const std::string &str)
reconstruct xml tree from string
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual ProjectionParametersBase * Clone() const =0
Covariant virtual copy constructor used in BIAS::Projection.
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
int length
number of bytes used by the data block
unsigned int GetWidth() const
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
std::string sdata
the data as given in ascii meta data
char * data
pointer to block of data
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
virtual bool PoseValid() const
Check if current pose is valid.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
int GetFreeGroupID()
returns unused group id
enum TAppData tag
The tag defines the type of data, e.g.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
This class Param provides generic support for parameters.
int SetGroupName(const int group_id, const std::string &name)
sets the name for a group
enum EStorageType GetStorageType() const
void SetMetaData(const MetaData &m)
This is the base class for images in BIAS.
this is a chunk of metadata, also see MetaData