Rumba C++ SDK
TrackNan.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2023
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 
16 #pragma once
17 
18 #include <assert.h>
19 #include "Maquina/Buffer.h"
20 #include "Maquina/EvalContext.h"
21 #include "Maquina/Node.h"
22 #include "Maquina/Points.h"
23 
24 namespace maquina
25 {
26 
27 inline bool _check_nan(const maquina::Value& v)
28 {
29  bool nan = false;
30  if (v.is_instance("Float"))
31  nan |= isnan(v.as_double());
32  else if (v.is_instance("V3f"))
33  {
34  const auto& vec = v.as_V3d();
35  nan |= isnan(vec.x) || isnan(vec.y) || isnan(vec.z);
36  }
37  else if (v.is_instance("M44f"))
38  {
39  const auto& m = v.as_M44d();
40  for (int i = 0; i < 4; ++i)
41  for (int j = 0; j < 4; ++j)
42  nan |= isnan(m.x[i][j]);
43  }
44  else if (v.is_instance("Array"))
45  {
46  const maquina::Array& a = v;
47  const size_t n = a.size();
48  for (size_t i = 0; i< n; ++i)
49  nan |= _check_nan(a.read(i));
50  }
51  else if (v.is_instance("Points"))
53  else if (v.is_instance("BufferV3f"))
54  {
55  for(const auto& p : maquina::BufferConstV3f(v).read())
56  nan |= isnan(p.x) || isnan(p.y) || isnan(p.z);
57  }
58  else
59  {
60  // assert(false);
61  }
62  return nan;
63 }
64 
65 inline void check_nan(maquina::EvalContext& ctx, const std::string& msg, const maquina::Value& v)
66 {
67  if (_check_nan(v))
68  {
69  std::cerr << "NAN: " << ctx.plug().node().name() << "." << ctx.plug().name() << " - " << msg << std::endl;
70  }
71 }
72 
73 }
const Imath::M44d & as_M44d() const
Returns the value as a M44d.
std::string name() const
Return the plug name.
bool _check_nan(const maquina::Value &v)
Definition: TrackNan.h:27
void check_nan(maquina::EvalContext &ctx, const std::string &msg, const maquina::Value &v)
Definition: TrackNan.h:65
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
const BufferConstV3f read_points() const
Return the points buffer.
size_t size() const
Returns the array size.
This class holds the evaluation context passed to the evaluation handler during a plug evaluation...
Definition: EvalContext.h:51
An array of values.
Definition: Array.h:26
const Value read(size_t i) const
Returns the i-th value.
const Imath::V3d & as_V3d() const
Returns the value as a V3d.
Node node() const
const char * name() const
Return the node name.
double as_double() const
Returns the value as a double.
gsl::span< const value_type > read() const
Return the readable data.
A set of 3d points.
Definition: Points.h:25
bool is_instance(const char *value_type_name) const
Check if this type derives from another value type.
virtual maquina::Plug plug() const =0
Base class of all Rumba values.
Definition: Value.h:34