MultiplyInt.cpp

Demonstrates creation of a VObject and how to create parameters and do some computation with these parameter values. This a very basic tutorial. A good point to start from.

Use it to mulitply an integer by a given integer. Connect it to any other int input parameter of other VObjects.

Start e.g.: ../../../bin/vish MultiplyInt.vis

See also:
Further tutorials: - Simple3DObject.cpp
00001 #include <ocean/plankton/VModules.hpp>
00002 #include <ocean/plankton/VCreator.hpp>
00003 
00004 // an empty macro to make code more readable
00005 #define override
00006 
00007 using namespace Wizt;
00008 
00009 
00024 class MultiplyInt : public Wizt::VObject
00025 {
00026   // define input and output Parameters of the VObject  
00027   TypedSlot<int> IntInParam;
00028   TypedSlot<int> Multiplier;
00029   VOutput<int> IntOutParam;
00030 
00031 public:
00032   MultiplyInt(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
00033   : VObject(name, p, VP)
00034     // Set the name of the parameter (seen in the GUI and used as name in the script language)
00035     // and the default value. Initialisation must be done in the same order as declarations.
00036     // An additional value calles 'expert level' may be set to hide same parameters to certain
00037     // expert levels. Use the slider 'EL' provided in 'Properties' of a module to control the 
00038     // expert level. (right click on module's name)
00039     , IntInParam(this, "intinput", 0, 5)
00040     , IntOutParam(self(), "intoutput", 1)
00041     , Multiplier( this, "multiplier", 2 )
00042   {
00043           // Set a maximum value for the parameter slider.
00044           Multiplier.setProperty("max", 8);
00045   }
00046   
00047   // The update function is the heart of the VObject. All functionality of the VObject is 
00048   // provided inside the update function. All data is handled through the VRequest. The precision
00049   // value is internally used to estimate the time the update function evaluation takes. In 
00050   // certain casese an update function call may be skipped if it has a long precision. 
00051   override bool update(VRequest&R, double precision)
00052   {
00053     int x = 0;
00054     int m = 0;
00055     
00056     // Get the Value of the IntInParam and Multiplier of actual context.
00057     IntInParam << R >> x; 
00058     Multiplier << R >> m;
00059     
00060     // Calculate new Value.
00061     x *= m;
00062     
00063     // Out value into IntOutParam at actual context.
00064     IntOutParam << R << x;
00065 
00066     return true;
00067   }
00068                                                                   
00069   
00070 };
00071       
00072 
00073 // create one creator object VCreator for MultiplyInt and specify where it should be placed in the creation menu ('examples/..')
00074 static Ref< VCreator<MultiplyInt, AcceptList<int> > > VMultiplyIntCreator("Tutorial/MultiplyInt");
00075 
00076 // callback that ensures global constructors are really called
00077 VISH_DEFAULT_INIT

Generated on Thu Apr 2 18:58:47 2009 for VISHTutorial by  doxygen 1.4.7