CLAM-Development  1.4.0
ControlComparison.cxx
Go to the documentation of this file.
1 #include "ControlComparison.hxx"
2 #include "ProcessingFactory.hxx"
3 #include "math.h"
4 namespace CLAM
5 {
6 namespace Hidden
7 {
8  static const char * metadata[] = {
9  "key", "ControlComparison",
10  "category", "Controls",
11  "description", "ControlComparison",
12  0
13  };
14  static FactoryRegistrator<ProcessingFactory, ControlComparison> reg = metadata;
15 }
16 
17 void ControlComparisonConfig::DefaultInit()
18 {
19  AddAll();
20  UpdateData();
21  SetRightTerm( 0.0 );
22  SetConvertOps2IntegersFirst(false);
23 }
24 
26  : _inOperator1(1, "Operator 1", this , &ControlComparison::InControlCallback )
27  , _inOperator2(2, "Operator 2", this , &ControlComparison::InControlCallback )
28  , _outControlBool( "Result of comparison (bool)", this )
29  , _outControlFloat( "Result of comparison (float)", this )
30  , _firstValueReceived(false)
31 {
32  Configure( mConfig );
33 }
34 
36  : _inOperator1(1, "Operator 1", this , &ControlComparison::InControlCallback )
37  , _inOperator2(2, "Operator 2", this , &ControlComparison::InControlCallback )
38  , _outControlBool( "Result of comparison (bool)", this )
39  , _outControlFloat( "Result of comparison (float)", this )
40  , _firstValueReceived(false)
41 {
42  Configure( cfg );
43 }
44 
46 {
47  CopyAsConcreteConfig( mConfig, cfg );
48  _inOperator2.DoControl(mConfig.GetRightTerm());
49  return true;
50 }
51 
52 void ControlComparison::InControlCallback(unsigned controlId, const TControlData & value)
53 {
54 
55  if (controlId==1)
56  _firstValueReceived=true;
57  else if (controlId==2)
58  if (not _firstValueReceived) return;
59 
60  TControlData op1 = _inOperator1.GetLastValue();
61  TControlData op2 = _inOperator2.GetLastValue();
62  bool equal = (op1 == op2);
63  if (mConfig.GetConvertOps2IntegersFirst())
64  equal = (round(op1) == round(op2));
65  _outControlBool.SendControl(equal);
66  _outControlFloat.SendControl(equal ? 1 : 0 );
67 }
68 
70 {
71  return true;
72 }
73 }
74