Commit c6436e74 authored by Katharina Stollenwerk's avatar Katharina Stollenwerk

added c++ tools

parent 2ff4f825
cmake_minimum_required(VERSION 3.7)
find_package(OpenCV)
find_package(TinyXML2)
SET( EIGEN3_INCLUDE_DIR "$ENV{EIGEN3_INCLUDE_DIR}" )
IF( NOT EIGEN3_INCLUDE_DIR )
MESSAGE( FATAL_ERROR "Please point the environment variable EIGEN3_INCLUDE_DIR to the include directory of your Eigen3 installation.")
ENDIF()
##################################
# Our Compiler and Linker Flages
##################################
#link_directories
### include file directories
include_directories(
"src"
"src/utils"
${TinyXML2_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
)
##################################
# Our Sources
##################################
set( INCLUDE_FILES
#
"src/utils/dirent.h"
"src/utils/filechooser_class.h"
"src/utils/filename_class.h"
"src/utils/filestorageocv_class.h"
"src/utils/filestoragexml_class.h"
"src/utils/timestamp_class.h"
)
######## main
### verify user measured hand
set( SOURCES_OCV_HANDVERIFY #
"src/utils/dirent.c"
"src/utils/filechooser_class.cpp"
"src/utils/filename_class.cpp"
"src/utils/filestoragexml_class.cpp"
"src/main_ocvhandverify.cpp"
)
### measure user hand from camera image
set( SOURCES_OCV_HANDMEASURE #
"src/utils/dirent.c"
"src/utils/filechooser_class.cpp"
"src/utils/filename_class.cpp"
"src/utils/filestorageocv_class.cpp"
"src/main_ocvhandmeasure.cpp"
)
##################################
# Our Targets
##################################
######## main
### check user measured hand
add_executable( ocv_handverify
${TinyXML2_INCLUDES}
${INCLUDE_FILES}
${SOURCES_OCV_HANDVERIFY}
)
target_link_libraries( ocv_handverify
${OpenCV_LIBS}
${TinyXML2_LIBRARY}
)
### measure user hand from camera image
add_executable( ocv_handmeasure
${INCLUDE_FILES}
${SOURCES_OCV_HANDMEASURE}
)
target_link_libraries( ocv_handmeasure
${OpenCV_LIBS}
)
##################################
# Messages?
##################################
This diff is collapsed.
This diff is collapsed.
/*
Implementation of POSIX directory browsing functions and types for Win32.
Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com)
History: Created March 1997. Updated June 2003 and July 2012.
Rights: See end of file.
*/
#include "dirent.h"
#include <errno.h>
#include <io.h> /* _findfirst and _findnext set errno iff they return -1 */
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef ptrdiff_t handle_type; /* C99's intptr_t not sufficiently portable */
struct DIR
{
handle_type handle; /* -1 for failed rewind */
struct _finddata_t info;
struct dirent result; /* d_name null iff first time */
char *name; /* null-terminated char string */
};
DIR *opendir(const char *name)
{
DIR *dir = 0;
if(name && name[0])
{
size_t base_length = strlen(name);
const char *all = /* search pattern must end with suitable wildcard */
strchr("/\\", name[base_length - 1]) ? "*" : "/*";
if((dir = (DIR *) malloc(sizeof *dir)) != 0 &&
(dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0)
{
strcat(strcpy(dir->name, name), all);
if((dir->handle =
(handle_type) _findfirst(dir->name, &dir->info)) != -1)
{
dir->result.d_name = 0;
}
else /* rollback */
{
free(dir->name);
free(dir);
dir = 0;
}
}
else /* rollback */
{
free(dir);
dir = 0;
errno = ENOMEM;
}
}
else
{
errno = EINVAL;
}
return dir;
}
int closedir(DIR *dir)
{
int result = -1;
if(dir)
{
if(dir->handle != -1)
{
result = _findclose(dir->handle);
}
free(dir->name);
free(dir);
}
if(result == -1) /* map all errors to EBADF */
{
errno = EBADF;
}
return result;
}
struct dirent *readdir(DIR *dir)
{
struct dirent *result = 0;
if(dir && dir->handle != -1)
{
if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1)
{
result = &dir->result;
result->d_name = dir->info.name;
}
}
else
{
errno = EBADF;
}
return result;
}
void rewinddir(DIR *dir)
{
if(dir && dir->handle != -1)
{
_findclose(dir->handle);
dir->handle = (handle_type) _findfirst(dir->name, &dir->info);
dir->result.d_name = 0;
}
else
{
errno = EBADF;
}
}
#ifdef __cplusplus
}
#endif
/*
Copyright Kevlin Henney, 1997, 2003, 2012. All rights reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose is hereby granted without fee, provided
that this copyright and permissions notice appear in all copies and
derivatives.
This software is supplied "as is" without express or implied warranty.
But that said, if there are any problems please get in touch.
*/
#ifndef DIRENT_INCLUDED
#define DIRENT_INCLUDED
/*
Declaration of POSIX directory browsing functions and types for Win32.
Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com)
History: Created March 1997. Updated June 2003.
Rights: See end of file.
*/
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct DIR DIR;
struct dirent
{
char *d_name;
};
DIR *opendir(const char *);
int closedir(DIR *);
struct dirent *readdir(DIR *);
void rewinddir(DIR *);
/*
Copyright Kevlin Henney, 1997, 2003. All rights reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose is hereby granted without fee, provided
that this copyright and permissions notice appear in all copies and
derivatives.
This software is supplied "as is" without express or implied warranty.
But that said, if there are any problems please get in touch.
*/
#ifdef __cplusplus
}
#endif
#endif
#include <iostream> /* for cout */
#include <algorithm> /* for remove and std::sort *//* otherwise it will take a "remove" from cstdio */
#include <cstdio> /* for popen */
#ifdef _WIN32
#include "dirent.h" /* */
#include <sys/stat.h> /* for stat*/
#else
#include <dirent.h> /* */
#endif
#include "filechooser_class.h"
/*#define KSDEBUG /**/
/////////////////////////////// PUBLIC ///////////////////////////////////////
//============================= LIFECYCLE ====================================
//-----------------------------------------------------------------------------
FileChooser::FileChooser ( void ) {
#ifdef KSDEBUG
std::cout << ">>in ::FileChooser( )" << std::endl;
#endif
defaultdirectory = "$HOME/";
#ifdef KSDEBUG
std::cout << ">>out ::FileChooser( )" << std::endl;
#endif
} // endof constructor FileChooser::FileChooser
//-----------------------------------------------------------------------------
/*virtual*/
FileChooser::~FileChooser ( void ) {
} // endof destructor FileChooser::~FileChooser
//============================= OPERATORS ====================================
/** - none - **/
//============================= OPERATIONS ===================================
//-----------------------------------------------------------------------------
std::string
FileChooser::chooseFile( std::string filetype /*=""*/ ) {
std::string command = "zenity --file-selection --title=\"zenity :: Choose a file\" --filename=";
command += defaultdirectory;
if ( !filetype.empty() ) {
command += " --file-filter=*"+filetype;
}
executeCommand ( command );
return getFile();
} // endof function FileChooser::chooseFile
std::string
FileChooser::chooseDirectory( void ) {
std::string command = "zenity --file-selection --title=\"zenity :: Choose a directory\" --directory --filename=";
command += defaultdirectory;
executeCommand ( command );
if ( !chosenfilename.empty() ) {
chosenfilename += "/";
}
return getFile();
} // endof function FileChooser::chooseFile
//-----------------------------------------------------------------------------
std::string
FileChooser::chooseFileByExtension ( std::string extension ) {
return chooseFile( extension );
} // endof function FileChooser::chooseFileByExtension
//-----------------------------------------------------------------------------
std::string
FileChooser::saveFile( void ) {
// FILE* ptr_stream;
std::string command = "zenity --file-selection --title=\"zenity :: Save the file\" --save";
// std::string intermediateresult;
// int status = -1;
executeCommand ( command );
return getFile();
} // endof function FileChooser::saveFile
//-----------------------------------------------------------------------------
std::vector< std::string>
FileChooser::readDirectory ( std::string directory ) {
std::string file;
std::vector < std::string > filelist;
DIR* ptr_dirstream;
struct dirent* ptr_direntry;
ptr_dirstream = opendir( directory.c_str() );
if ( !ptr_dirstream ) {
std::cout << "error opening directory, file list is empty" << std::endl;
return filelist;
}
ptr_direntry=readdir( ptr_dirstream );
while ( ptr_direntry != NULL ) {
// if entry is a file
bool is_a_file = false;
#ifdef _WIN32
//https://stackoverflow.com/questions/2197918/cross-platform-way-of-testing-whether-a-file-is-a-directory
struct stat s;
stat( ptr_direntry->d_name, &s );
is_a_file = ( s.st_mode & S_IFREG );
#else
is_a_file =( ptr_direntry->d_type == DT_REG );
#endif
if ( is_a_file ) {
file = std::string(ptr_direntry->d_name);
if ( file[0] == '.' ) { /* hidden files */
} else if ( file[file.length()-1] == '~' ) { /* backup file */
} else { /* "good" file */
filelist.push_back( file );
} // fi use only files (no backup files and no hidden files)
} // fi entry is a file
ptr_direntry = readdir( ptr_dirstream );
} // endwhile not empty directory entry
closedir( ptr_dirstream );
std::sort( filelist.begin(), filelist.end() );
return filelist;
} // endof function FileChooser::readDirectory
//============================= ACCESS ===================================
//-----------------------------------------------------------------------------
std::string
FileChooser::getFile ( void ) {
if ( !chosenfilename.empty() ) {
return chosenfilename;
} else {
std::cerr << "File choosing failed, returning an empty string." << std::endl;
return std::string("");
}
} // endof function FileChooser::getFilename
std::string
FileChooser::setDefaultDirectory ( std::string defaultdir /* = "" */ ) {
FILE* ptr_stream;
std::string command = "zenity --file-selection --title=\"zenity :: Choose a default directory\" --directory --filename=";
command += defaultdirectory;
std::string intermediateresult;
int status = -1;
if ( defaultdir.empty() ) {
#ifdef _WIN32
ptr_stream = _popen( static_cast<const char*> ( command.c_str() ), "r" );
#else
ptr_stream = popen( static_cast<const char*> ( command.c_str() ), "r" );
#endif
if ( ptr_stream != NULL ) {
int bytesread;
const int buffersize = 1024;
char charbuffer[buffersize + 1];
while ( ( bytesread = fread ( charbuffer, 1, buffersize, ptr_stream ) ) > 0 ) {
charbuffer[bytesread] = 0;
intermediateresult += std::string ( charbuffer );
}
#ifdef _WIN32
status = _pclose( ptr_stream );
#else
status = pclose( ptr_stream );
#endif
} // fi ptr_stream != NULL
if ( status == 0 ) {
intermediateresult.erase(std::remove(intermediateresult.begin(), intermediateresult.end(), '\n'), intermediateresult.end());
defaultdirectory = intermediateresult;
defaultdirectory += "/";
} else {
std::cerr << "File choosing failed, directory is set to $HOME/." << std::endl;
defaultdirectory="$HOME/";
} // fi status == 0
} else {
defaultdirectory=defaultdir;
}// fi defaultdir empty
return defaultdirectory;
} // endof function FileChooser::setDefaultDirectory
void
FileChooser::unsetDefaultDirectory ( void ) {
defaultdirectory = "";
} // endof function FileChooser::unsetDefaultDirectory
/////////////////////////////// PROTECTED ///////////////////////////////////
//============================= OPERATORS ====================================
/** - none - **/
//============================= OPERATORS ====================================
/** - none - **/
//============================= OPERATIONS ===================================
/** - none - **/
//============================= ACCESS ===================================
/** - none - **/
/////////////////////////////// PRIVATE ///////////////////////////////////
//============================= OPERATORS ====================================
/** - none - **/
//============================= OPERATORS ====================================
/** - none - **/
//============================= OPERATIONS ===================================
/** - none - **/
void
FileChooser::executeCommand ( std::string command ) {
FILE* ptr_stream;
int status = -1;
std::string intermediateresult = "";
#ifdef _WIN32
ptr_stream = _popen( static_cast<const char*> ( command.c_str() ), "r" );
#else
ptr_stream = popen( static_cast<const char*> ( command.c_str() ), "r" );
#endif
if ( ptr_stream != NULL ) {
int bytesread;
const int buffersize = 1024;
char charbuffer[buffersize + 1];
while ( ( bytesread = fread ( charbuffer, 1, buffersize, ptr_stream ) ) > 0 ) {
charbuffer[bytesread] = 0;
intermediateresult += std::string ( charbuffer );
} // endwhile
#ifdef _WIN32
status = _pclose( ptr_stream );
#else
status = pclose( ptr_stream );
#endif
} // fi ptr_stream not empty
if ( status == 0 ) {
intermediateresult.erase(std::remove(intermediateresult.begin(), intermediateresult.end(), '\n'), intermediateresult.end());
chosenfilename = intermediateresult;
} else {
std::cerr << "File choosing failed, file is empty." << std::endl;
//TODO I have no clue how to say there is no file.
} // fi status ok
} // endof function FileChooser::doTheWork
//============================= ACCESS ===================================
/** - none - **/
/** filechooser_class - opens a dialog for choosing a file.
*
* #include "XX.h" <BR>
* -llib
*
* needs zenity
*
* This class opens a simple dialog for choosing a file and saves the chosen filename as string.
*
* @see something
* Created on: Nov 04, 2014
* Author: kstoll2m
*/
#ifndef CLASS_KS_FILECHOOSER_H_
#define CLASS_KS_FILECHOOSER_H_
#include <string>
#include <vector>
/* //**
* *** start CLASS fILEcHOOSER ***************************************** *
\* */
/**************************************************************************//**
* \brief Opens a dialog (zenity only) for choosing a file
*
* This class opens a simple dialog (zenity only) for choosing a file
* and saves the chosen filename as string
*
*****************************************************************************/
class FileChooser {
// partly inspired by http://www.juce.com/forum/topic/filechooser-multi-selection-and-zenity-platform-dialog
// see further down (at the end of the file)
public:
// CLASS VARIABLES
// LIFECYCLE
/** Standard constructor
*/
FileChooser ( void );
/** Destructor
*/
virtual ~FileChooser ( void );
// OPERATORS
/** - none - **/
// OPERATIONS
/**
*/
std::string chooseFile ( std::string = "" );
/**
*/
std::string chooseDirectory ( void );
/**
*/
std::string chooseFileByExtension ( std::string = "" );
/**
*/
std::string saveFile ( void );
/**
*/
std::vector< std::string> readDirectory ( std::string );
// ACCESS
/**
*/
std::string getFile ( void );
/**
*/
std::string setDefaultDirectory ( std::string = "" );
/**
*/
void unsetDefaultDirectory ( void );
protected:
// CLASS VARIABLES
/** - none - **/
// OPERATORS
/** - none - **/
// OPERATIONS
/** - none - **/
// ACCESS