CppNCorr
C++ ncorr Digital Image Correlation engine
Loading...
Searching...
No Matches
session.h
Go to the documentation of this file.
1#pragma once
23#include <cstdint>
24#include <memory>
25#include <string>
26#include <vector>
27
28namespace ncorr {
29
42 const std::uint8_t* data = nullptr;
44 int width = 0;
46 int height = 0;
48 int channels = 1;
49
51 ImageBuffer() = default;
52
60 ImageBuffer(const std::uint8_t* data_, int width_, int height_, int channels_ = 1)
61 : data(data_), width(width_), height(height_), channels(channels_) {}
62
64 bool valid() const { return data != nullptr && width > 0 && height > 0 && channels > 0; }
65
67 std::size_t size_bytes() const { return static_cast<std::size_t>(width) * height * channels; }
68};
69
84struct DICResult {
86 int width = 0;
88 int height = 0;
90 std::vector<double> u;
92 std::vector<double> v;
94 std::vector<double> corrcoef;
96 bool valid = false;
98 std::string message;
99};
100
109 int scalefactor = 3;
115 int num_threads = 4;
117 bool debug = false;
118};
119
139 public:
144 explicit NcorrSession(const SessionConfig& config = SessionConfig());
145
148
149 // Movable, non-copyable (owns engine state).
151 NcorrSession& operator=(NcorrSession&&) noexcept;
152 NcorrSession(const NcorrSession&) = delete;
153 NcorrSession& operator=(const NcorrSession&) = delete;
154
164 void set_reference(const ImageBuffer& ref);
165
177 void set_roi(const ImageBuffer& roi_mask);
178
187
189 bool has_reference() const;
190
191 private:
192 // PIMPL: hides internal ncorr engine types from this public header.
193 struct Impl;
194 std::unique_ptr<Impl> impl_;
195};
196
197} // namespace ncorr
Drives an in-memory Digital Image Correlation session.
Definition session.h:138
void set_roi(const ImageBuffer &roi_mask)
Optionally supply a region-of-interest mask.
Definition session.cpp:82
~NcorrSession()
Destructor (defined in session.cpp because of the PIMPL).
void set_reference(const ImageBuffer &ref)
Set the reference (undeformed) frame.
Definition session.cpp:68
bool has_reference() const
Definition session.cpp:175
DICResult process_frame(const ImageBuffer &def)
Push a deformed frame and run DIC against the reference.
Definition session.cpp:97
NcorrSession(NcorrSession &&) noexcept
Result of running DIC on a single deformed frame.
Definition session.h:84
int height
Height of the displacement fields, in reduced-grid samples.
Definition session.h:88
std::vector< double > v
Vertical Lagrangian displacement (v), pixels, row-major. NaN outside ROI.
Definition session.h:92
bool valid
True if the frame was processed successfully.
Definition session.h:96
int width
Width of the displacement fields, in reduced-grid samples.
Definition session.h:86
std::vector< double > u
Horizontal Lagrangian displacement (u), pixels, row-major. NaN outside ROI.
Definition session.h:90
std::vector< double > corrcoef
Per-point correlation coefficient, row-major, size width*height. NaN outside ROI.
Definition session.h:94
std::string message
Human-readable status / error message (empty on success).
Definition session.h:98
Thin, non-owning view over a raw image in memory.
Definition session.h:40
const std::uint8_t * data
Pointer to the first byte of the (row-major, interleaved) pixel data.
Definition session.h:42
std::size_t size_bytes() const
Definition session.h:67
int channels
Number of interleaved channels per pixel (1 = grayscale, 3 = BGR, ...).
Definition session.h:48
int width
Image width in pixels.
Definition session.h:44
int height
Image height in pixels.
Definition session.h:46
ImageBuffer()=default
Default-construct an empty (invalid) buffer.
bool valid() const
Definition session.h:64
ImageBuffer(const std::uint8_t *data_, int width_, int height_, int channels_=1)
Construct an image buffer view.
Definition session.h:60
Configuration for an in-memory DIC session.
Definition session.h:107
int scalefactor
Pyramid scale factor (downsampling level for the seed search).
Definition session.h:109
int subregion_radius
Subregion (correlation window) radius in pixels.
Definition session.h:111
bool debug
Enable verbose debug output from the engine.
Definition session.h:117
int num_threads
Number of worker threads for parallel analysis.
Definition session.h:115
int strain_radius
Strain subregion radius in pixels.
Definition session.h:113