MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / calculate

Method calculate

pj_scripting/src/lua_mimo_transform.cpp:131–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131bool LuaMimoTransform::calculate(
132 PJ::Timestamp time, PJ::Span<const PJ::VarValue> inputs, PJ::Timestamp& out_time,
133 std::vector<PJ::VarValue>& output) {
134 out_time = time; // MIMO v1: outputs share the joined input timestamp (no explicit out_time).
135 if (!instance_ || inputs.empty()) {
136 if (instance_) {
137 error_ = instance_->error();
138 }
139 return false;
140 }
141 if (instance_->failed()) {
142 error_ = instance_->error();
143 return false;
144 }
145
146 // Capture the session epoch from the first sample, then rebase on the int64 spine
147 // BEFORE the double cast (epoch-in-double quantizes to ~256 ns — see header).
148 if (!has_session_start_) {
149 session_start_ns_ = time;
150 has_session_start_ = true;
151 }
152 const double t_sec = static_cast<double>(time - session_start_ns_) * 1e-9;
153
154 std::vector<double> input_doubles;
155 input_doubles.reserve(inputs.size());
156 for (const PJ::VarValue& v : inputs) {
157 input_doubles.push_back(proc::detail::toDouble(v));
158 }
159
160 const FilterInstance::MimoResult r = instance_->calculateMimo(t_sec, input_doubles);
161 if (instance_->failed()) {
162 error_ = instance_->error(); // sticky: fail the node, do not corrupt downstream
163 return false;
164 }
165 if (r.suppress) {
166 return false;
167 }
168 if (r.values.size() != num_outputs_) {
169 error_ = "filter returned " + std::to_string(r.values.size()) + " value(s) but " + std::to_string(num_outputs_) +
170 " output(s) are declared";
171 return false;
172 }
173
174 // `output` is pre-sized to num_outputs_ by the engine. Every output mirrors the
175 // first input (input 0) when out_mode_ == kMirror.
176 const PJ::VarValue& mirror_input = inputs[0];
177 for (std::size_t k = 0; k < num_outputs_; ++k) {
178 output[k] = makeOutputValue(r.values[k], mirror_input);
179 }
180 return true;
181}
182
183} // namespace PJ::scripting

Callers 5

calculateNextPointMethod · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls 6

reserveMethod · 0.80
toDoubleFunction · 0.50
emptyMethod · 0.45
failedMethod · 0.45
sizeMethod · 0.45
calculateMimoMethod · 0.45

Tested by 4

TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36