File size: 3,949 Bytes
4559903 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | /*
* Copyright (c) 2017 Alexandr Menkin
* Use of this source code is governed by an MIT-style license that can be found in the LICENSE file at
* https://github.com/sanchousic/kinect2-recorder
*/
#include "ConsoleController.h"
#include <vector>
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;
ConsoleController::ConsoleController(Kinect2Recorder * pKinect2Recorder):
_pKinect2Recorder(nullptr)
{
if (pKinect2Recorder == nullptr)
{
return;
}
_pKinect2Recorder = pKinect2Recorder;
}
ConsoleController::~ConsoleController()
{
_pKinect2Recorder = nullptr;
}
bool ConsoleController::IsActive()
{
return _pKinect2Recorder != nullptr && _pKinect2Recorder->IsActive();
}
void ConsoleController::Command(const string commandLine)
{
vector<string> * args = ParseLine(commandLine);
size_t argc = args->size();
if (argc <= 0)
{
delete(args);
args = nullptr;
return;
}
std::string command = args->at(0);
if (command.compare(COMMAND_SET_DIR) == 0)
{
if (argc == 2)
{
_pKinect2Recorder->SetDirectoryPath(args->at(1));
}
}
if (command.compare(COMMAND_SET_MODE) == 0)
{
int mode = 0;
int i = 1;
while (i < argc)
{
if (args->at(i).compare(MODE_COLOR) == 0)
{
mode = mode | Kinect2Recorder::MODE_COLOR;
}
if (args->at(i).compare(MODE_DEPTH) == 0)
{
mode = mode | Kinect2Recorder::MODE_DEPTH;
}
_pKinect2Recorder->SetMode(mode);
i++;
}
}
if (command.compare(COMMAND_SET_SIZE) == 0)
{
if (argc == 4)
{
int mode = 0;
if (args->at(1).compare(MODE_COLOR) == 0)
{
mode = mode | Kinect2Recorder::MODE_COLOR;
}
if (args->at(1).compare(MODE_DEPTH) == 0)
{
mode = mode | Kinect2Recorder::MODE_DEPTH;
}
_pKinect2Recorder->SetSize(mode, std::stoi(args->at(2)), std::stoi(args->at(3)));
}
}
if (command.compare(COMMAND_SET_FPS) == 0)
{
if (argc == 2)
{
try
{
_pKinect2Recorder->SetFPS(std::stoi(args->at(1)));
}
catch(...)
{
}
}
}
if (command.compare(COMMAND_START) == 0)
{
if (argc == 1)
{
_pKinect2Recorder->Start();
}
if (argc == 2)
{
try
{
_pKinect2Recorder->Start(std::stoi(args->at(1)));
}
catch(...)
{
}
}
}
if (command.compare(COMMAND_STOP) == 0)
{
_pKinect2Recorder->Stop();
}
if (command.compare(COMMAND_END) == 0)
{
_pKinect2Recorder->Deactivate();
}
delete(args);
args = nullptr;
}
vector<string> * ConsoleController::ParseLine(const string line)
{
vector<string> * pVectorArgs = new vector<string>();
int start = 0;
int finish = 0;
while(finish < line.length())
{
if (isspace(line[finish]))
{
if (start < finish)
{
pVectorArgs->push_back(line.substr(start, finish - start));
}
start = finish + 1;
}
finish++;
}
if (start < finish)
{
string arg = line.substr(start, finish - start);
pVectorArgs->push_back(arg);
}
return pVectorArgs;
}
|