AbstractSequencedRecordingStrategy.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package visionx::imrec
17  * @author Christian R. G. Dreher <christian.dreher@student.kit.edu>
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 // Amount of frames per chunk
25 #define CHUNK_SIZE 100
26 
27 
29 
30 
31 // STD/STL
32 #include <filesystem>
33 
34 // OpenCV 2
35 #include <opencv2/opencv.hpp>
36 
37 // IVT
38 #include <Image/ByteImage.h>
39 
40 // ArmarX
43 
44 
47 {
48  // pass
49 }
50 
51 
52 visionx::imrec::AbstractSequencedRecordingStrategy::AbstractSequencedRecordingStrategy(const std::filesystem::path& filePath, const std::filesystem::path& ext) :
53  visionx::imrec::AbstractRecordingStrategy(filePath),
54  m_ext{ext}
55 {
56  // pass
57 }
58 
59 
61 {
62  // pass
63 }
64 
65 
66 void
68 {
70  std::filesystem::path pathStem = getPath() / getStem();
71 
72  ARMARX_CHECK_EXPRESSION(not std::filesystem::exists(pathStem)) << "Folder already exists";
73 
74  std::filesystem::create_directory(pathStem);
75 
76  writeMetadataLine("frames_per_chunk", "unsigned int", std::to_string(CHUNK_SIZE));
77  writeMetadataLine("extension", "string", getDotExtension().string());
78 }
79 
80 
81 std::filesystem::path
83 {
84  return m_ext;
85 }
86 
87 
88 std::filesystem::path
90 {
91  std::filesystem::path path = getPath() / getStem();
92  return std::filesystem::canonical(path) / "metadata.csv";
93 }
94 
95 
96 std::filesystem::path
97 visionx::imrec::AbstractSequencedRecordingStrategy::deriveFramePath(const unsigned int sequence_number, const std::string& frame_name)
98 {
99  const std::filesystem::path frame_filename = frame_name + getDotExtension().string();
100 
101  if (sequence_number % CHUNK_SIZE == 0)
102  {
103  unsigned int chunk_number = sequence_number / CHUNK_SIZE;
104  m_frames_chunk = "chunk_" + std::to_string(chunk_number);
105  std::filesystem::create_directory(std::filesystem::canonical(getPath() / getStem()) / m_frames_chunk);
106  }
107 
108  return std::filesystem::canonical(getPath() / getStem() / m_frames_chunk) / frame_filename;
109 }
CHUNK_SIZE
#define CHUNK_SIZE
Definition: AbstractSequencedRecordingStrategy.cpp:25
visionx::imrec::AbstractSequencedRecordingStrategy::getMetadataPath
std::filesystem::path getMetadataPath() const override
Definition: AbstractSequencedRecordingStrategy.cpp:89
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
AbstractSequencedRecordingStrategy.h
visionx::imrec::AbstractRecordingStrategy
Abstract interface of a recording strategy.
Definition: AbstractRecordingStrategy.h:54
visionx::imrec::AbstractSequencedRecordingStrategy::AbstractSequencedRecordingStrategy
AbstractSequencedRecordingStrategy()
Default constructor to manually start the recording.
Definition: AbstractSequencedRecordingStrategy.cpp:45
visionx::imrec::AbstractSequencedRecordingStrategy::deriveFramePath
std::filesystem::path deriveFramePath(const unsigned int sequence_number, const std::string &frame_name)
Returns the next sequenced full path and increments the sequence number.
Definition: AbstractSequencedRecordingStrategy.cpp:97
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
ExpressionException.h
visionx::imrec::AbstractSequencedRecordingStrategy::getDotExtension
std::filesystem::path getDotExtension() const override
Gets the extension plus preceeded dot of the configured file (e.g.
Definition: AbstractSequencedRecordingStrategy.cpp:82
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
visionx::imrec::AbstractRecordingStrategy::startRecording
virtual void startRecording()
Starts the recording manually if constructed empty.
Definition: AbstractRecordingStrategy.cpp:78
visionx::imrec::AbstractSequencedRecordingStrategy::~AbstractSequencedRecordingStrategy
~AbstractSequencedRecordingStrategy() override
Destruct the recording strategy.
Definition: AbstractSequencedRecordingStrategy.cpp:60
helper.h
visionx::imrec::AbstractSequencedRecordingStrategy::startRecording
void startRecording() override
Starts the recording manually if constructed empty.
Definition: AbstractSequencedRecordingStrategy.cpp:67