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
42 
44 
47 {
48  // pass
49 }
50 
52  const std::filesystem::path& filePath,
53  const std::filesystem::path& ext) :
54  visionx::imrec::AbstractRecordingStrategy(filePath), m_ext{ext}
55 {
56  // pass
57 }
58 
60 {
61  // pass
62 }
63 
64 void
66 {
68  std::filesystem::path pathStem = getPath() / getStem();
69 
70  ARMARX_CHECK_EXPRESSION(not std::filesystem::exists(pathStem)) << "Folder already exists";
71 
72  std::filesystem::create_directory(pathStem);
73 
74  writeMetadataLine("frames_per_chunk", "unsigned int", std::to_string(CHUNK_SIZE));
75  writeMetadataLine("extension", "string", getDotExtension().string());
76 }
77 
78 std::filesystem::path
80 {
81  return m_ext;
82 }
83 
84 std::filesystem::path
86 {
87  std::filesystem::path path = getPath() / getStem();
88  return std::filesystem::canonical(path) / "metadata.csv";
89 }
90 
91 std::filesystem::path
93  const unsigned int sequence_number,
94  const std::string& frame_name)
95 {
96  const std::filesystem::path frame_filename = frame_name + getDotExtension().string();
97 
98  if (sequence_number % CHUNK_SIZE == 0)
99  {
100  unsigned int chunk_number = sequence_number / CHUNK_SIZE;
101  m_frames_chunk = "chunk_" + std::to_string(chunk_number);
102  std::filesystem::create_directory(std::filesystem::canonical(getPath() / getStem()) /
103  m_frames_chunk);
104  }
105 
106  return std::filesystem::canonical(getPath() / getStem() / m_frames_chunk) / frame_filename;
107 }
CHUNK_SIZE
#define CHUNK_SIZE
Definition: AbstractSequencedRecordingStrategy.cpp:25
visionx::imrec::AbstractSequencedRecordingStrategy::getMetadataPath
std::filesystem::path getMetadataPath() const override
Definition: AbstractSequencedRecordingStrategy.cpp:85
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
AbstractSequencedRecordingStrategy.h
visionx::imrec::AbstractRecordingStrategy
Abstract interface of a recording strategy.
Definition: AbstractRecordingStrategy.h:52
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:92
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
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:79
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:73
visionx::imrec::AbstractSequencedRecordingStrategy::~AbstractSequencedRecordingStrategy
~AbstractSequencedRecordingStrategy() override
Destruct the recording strategy.
Definition: AbstractSequencedRecordingStrategy.cpp:59
helper.h
visionx::imrec::AbstractSequencedRecordingStrategy::startRecording
void startRecording() override
Starts the recording manually if constructed empty.
Definition: AbstractSequencedRecordingStrategy.cpp:65