ControlComparison.cxx

Go to the documentation of this file.
00001 #include "ControlComparison.hxx"
00002 #include "ProcessingFactory.hxx"
00003 #include "math.h"
00004 namespace CLAM
00005 {
00006 namespace Hidden
00007 {
00008         static const char * metadata[] = {
00009                 "key", "ControlComparison",
00010                 "category", "Controls",
00011                 "description", "ControlComparison",
00012                 0
00013         };
00014         static FactoryRegistrator<ProcessingFactory, ControlComparison> reg = metadata;
00015 }
00016 
00017 void ControlComparisonConfig::DefaultInit()
00018 {
00019         AddAll();
00020         UpdateData();
00021         SetRightTerm( 0.0 );
00022         SetConvertOps2IntegersFirst(false);
00023 }
00024 
00025 ControlComparison::ControlComparison()
00026         : _inOperator1(1, "Operator 1", this , &ControlComparison::InControlCallback )
00027         , _inOperator2(2, "Operator 2", this , &ControlComparison::InControlCallback )
00028         , _outControlBool( "Result of comparison (bool)", this )
00029         , _outControlFloat( "Result of comparison (float)", this )
00030         , _firstValueReceived(false)
00031 {
00032         Configure( mConfig );   
00033 }
00034 
00035 ControlComparison::ControlComparison( const ControlComparisonConfig& cfg ) 
00036         : _inOperator1(1, "Operator 1", this , &ControlComparison::InControlCallback )
00037         , _inOperator2(2, "Operator 2", this , &ControlComparison::InControlCallback )
00038         , _outControlBool( "Result of comparison (bool)", this )
00039         , _outControlFloat( "Result of comparison (float)", this )
00040         , _firstValueReceived(false)
00041 { 
00042         Configure( cfg );
00043 }
00044 
00045 bool ControlComparison::ConcreteConfigure( const ProcessingConfig& cfg )
00046 {
00047         CopyAsConcreteConfig( mConfig, cfg );
00048         _inOperator2.DoControl(mConfig.GetRightTerm());
00049         return true;            
00050 }
00051 
00052 void ControlComparison::InControlCallback(unsigned controlId, const TControlData & value)
00053 {
00054 
00055         if (controlId==1)
00056                 _firstValueReceived=true;
00057         else if (controlId==2)
00058                 if (not _firstValueReceived) return;
00059 
00060         TControlData op1 = _inOperator1.GetLastValue();
00061         TControlData op2 = _inOperator2.GetLastValue();
00062         bool equal = (op1 == op2);  
00063         if (mConfig.GetConvertOps2IntegersFirst())
00064                 equal = (round(op1) == round(op2));
00065         _outControlBool.SendControl(equal);
00066         _outControlFloat.SendControl(equal ? 1 : 0 );
00067 }
00068 
00069 bool ControlComparison::Do()
00070 {
00071         return true;
00072 }
00073 }
00074 
Generated by  doxygen 1.6.3