Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/metaobjects/property/extrapolatedproperty.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001, 2002 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <tetron@interreality.org>
00022 */
00023 #ifndef _EXTRAPOLATEDPROPERTY_HH_
00024 #define _EXTRAPOLATEDPROPERTY_HH_
00025 
00026 #include <typeinfo>
00027 #include <set>
00028 #include <vector>
00029 
00030 #include "property.hh"
00031 
00032 #include "bufferedproperty.hh"
00033 
00034 #include "propertylistener.hh"
00035 
00036 /** @class ExtrapolatedProperty extrapolatedproperty.hh vos/metaobjects/property/extrapolatedproperty.hh
00037  *
00038  * Use this Property subclass to store continusouly changing numerical values.
00039  * Scalars and vectors can be used.  The values are extrapolated by remote
00040  * objects, avoiding the need for repeated update messages.  
00041  *
00042  * @todo remove interfaces for setting datatype, it should always be
00043  * "text/x-vector-float".
00044  * @todo document this class better, incl. write otd.
00045  */
00046 
00047 class PROPERTY_API ExtrapolatedProperty : public virtual Property
00048 {
00049 protected:
00050     typedef set<ExtrapolatedPropertyListener*, ExtrapolatedListenerSiteWrapper::Cmp> ExtrapolationListenerSet;
00051     ExtrapolationListenerSet extrapolationListeners;
00052     static set<ExtrapolatedProperty*> allexps;
00053     typedef set<ExtrapolatedProperty*> AllExpSet;
00054     vector<double> x;
00055     vector<double> dx;
00056     vector<double> ddx;
00057     double lastCheckpoint;
00058     ExtrapolatedProperty(MetaObject* superobject);
00059 public:
00060     virtual ~ExtrapolatedProperty();
00061     static void registerExtenders();
00062     static void updateAll();
00063     virtual void update();
00064     virtual void set(const vector<double>& x, const vector<double>& dx, const vector<double>& ddx, double t = 0.0) = 0;
00065     static string stringifyVector(const vector<double>& x);
00066     static void stringToVector(const string& prop, vector<double>& x);
00067     void getBase(vector<double>& ax,
00068                  vector<double>& adx,
00069                  vector<double>& addx);
00070     void getCurrent(vector<double>& ax,
00071                     vector<double>& adx,
00072                     vector<double>& addx,
00073                     double& t);
00074     virtual double now();
00075     virtual void calculatePosition(vector<double>& newx, vector<double>& newdx, double& t);
00076 
00077     virtual void notifyObjectExcise(VOS::RefCounted *);
00078     virtual void doExcise();
00079 
00080     virtual void addExtrapolationListener(ExtrapolatedPropertyListener* x);
00081     virtual void removeExtrapolationListener(ExtrapolatedPropertyListener* x);
00082     virtual const string getType();
00083 
00084 
00085     /** Read current extrapolated values.
00086      * @bug You will not get valid data if there are no ExtrapolationListeners for
00087      * this extrapolated property!
00088      */
00089     virtual void readRaw(string& target, int start, int length);
00090 
00091     /** Read current extrapolated values.
00092      * @warning no data decoding is performed, this method is the
00093      * same as readRaw().
00094      * @bug You will not get valid data if there are no ExtrapolationListeners for
00095      * this extrapolated property!
00096      */
00097     virtual void read(string& target, int start, int length);
00098 
00099     /** Get length of property
00100      * @bug You will not get valid data if there are no ExtrapolationListeners for
00101      * this extrapolated property!
00102      */
00103     virtual int getRawLength();
00104 
00105     /** Get length of property
00106      * @warning no data decoding is performed, this method is the
00107      * same as getRawLength().
00108      * @bug You will not get valid data if there are no ExtrapolationListeners for
00109      * this extrapolated property!
00110      */
00111     virtual int getLength();
00112 
00113     /** Initialize property with x, dx, ddx and time values of (0.0).
00114         @see ExtrapolatedLocalProperty::initialize()
00115     */
00116     virtual void initialize();
00117 
00118     /** Initialize property with given vector size and value.
00119         t (time) is set to 0.
00120         @see ExtrapolatedLocalProperty::initialize(unsigned int, double)
00121         @param size     Size of x, dx and ddx vectors.
00122         @param val      Value for all variables. (Default is 0.0)
00123     */
00124     virtual void initialize(unsigned int size, double val = 0.0);
00125 
00126     /** Set dx value using current time step.
00127         @param val  New value
00128     */
00129     void setVelocity(const vector<double>& val);
00130 
00131     /** Set dx value using current time step.
00132         @param val  New value
00133     */
00134     void setVelocity(const double val);
00135 
00136     /** Set ddx value using current time step.
00137         @param val  New value
00138     */
00139     void setAcceleration(const vector<double>& val);
00140 
00141     /** Set ddx value using current time step.
00142         @param val  New value
00143     */
00144     void setAcceleration(const double val);
00145 
00146     /** Set x value using current time step.
00147         @param val New value
00148     */
00149     void setPosition(const vector<double>& val);
00150 
00151     /** Set x value using current time step.
00152         @param val New value
00153     */
00154     void setPosition(const double val);
00155 
00156     /** Get current x */
00157     void getCurrentPos(vector<double>& x);
00158 
00159     /** Get current velocity */
00160     void getVelocity(double& v);
00161 
00162     /** Get current velocity */
00163     void getVelocity(vector<double>& v);
00164 
00165     /** Get current acceleration */
00166     void getAcceleration(double& a);
00167 
00168     /** Get current acceleration */
00169     void getAcceleration(vector<double>& a);
00170 };
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 /** @class ExtrapolatedLocalProperty extrapolatedproperty.hh vos/metaobjects/property/extrapolatedproperty.hh
00181  */
00182 
00183 class PROPERTY_API ExtrapolatedLocalProperty : public virtual ExtrapolatedProperty, public virtual BufferedLocalProperty
00184 {
00185 private:
00186     bool extrap_base_changed;
00187 public:
00188     ExtrapolatedLocalProperty(MetaObject* superobject);
00189     ExtrapolatedLocalProperty(MetaObject* superobject, const string& d, const string& dt = "?");
00190     virtual ~ExtrapolatedLocalProperty();
00191     static MetaObject* new_ExtrapolatedLocalProperty(MetaObject* superobject, const string& type);
00192 
00193     virtual void set(const vector<double>& x, const vector<double>& dx, const vector<double>& ddx, double t = 0.0);
00194     virtual void write(int start, const string& newdata);
00195     virtual void replace(const string& newdata, const string& newtype = "?");
00196 
00197     /* try to coax the compiler into working */
00198     virtual void readRaw(string& target, int start, int length) {
00199         ExtrapolatedProperty::readRaw(target, start, length);
00200     }
00201     virtual int getRawLength() {
00202         return ExtrapolatedProperty::getRawLength();
00203     }
00204     virtual int getLength() {
00205         return ExtrapolatedProperty::getLength();
00206     }
00207     virtual void read(string& target, int start, int length) {
00208         ExtrapolatedProperty::read(target, start, length);
00209     }
00210 
00211 
00212 
00213 
00214     virtual void flush();
00215 
00216     virtual void sendMessage(Message* m);
00217 
00218     /** Initialize property with x, dx, ddx and time values of (0.0).
00219         Set no access control.
00220         @see ExtrapolatedProperty::initialize()
00221     */
00222     virtual void initialize() {
00223         insertPropertyAccessControl(-1, &NoPropertyAccessControl::static_);
00224         ExtrapolatedProperty::initialize();
00225     }
00226 
00227     /** Initialize property with given vector size and value.
00228         t (time) is set to 0.
00229         Set no access control.
00230         @see ExtrapolatedProperty::initialize(unsigned int, double)
00231         @param size     Size of x, dx and ddx vectors.
00232         @param val      Value for all variables. (Default is 0.0)
00233     */
00234     virtual void initialize(unsigned int size, double val = 0.0) {
00235         insertPropertyAccessControl(-1, &NoPropertyAccessControl::static_);
00236         ExtrapolatedProperty::initialize(size, val);
00237     }
00238 };
00239 
00240 
00241 /** @class ExtrapolatedProperty extrapolatedproperty.hh vos/metaobjects/property/extrapolatedproperty.hh
00242  */
00243 class PROPERTY_API ExtrapolatedRemoteProperty : public virtual ExtrapolatedProperty, public virtual BufferedRemoteProperty
00244 {
00245 public:
00246     ExtrapolatedRemoteProperty(MetaObject* superobject);
00247     virtual ~ExtrapolatedRemoteProperty();
00248     static MetaObject* new_ExtrapolatedRemoteProperty(MetaObject* superobject, const string& type);
00249 
00250     virtual void set(const vector<double>& x, const vector<double>& dx, const vector<double>& ddx, double t = 0.0);
00251     virtual void sendUpdateMessage(Message* m);
00252 
00253     virtual void addExtrapolationListener(ExtrapolatedPropertyListener* x);
00254     virtual void removeExtrapolationListener(ExtrapolatedPropertyListener* x);
00255 
00256     /** If there are any listeners, return current value, otherwise send a
00257      * message*/
00258     virtual void readRaw(string& target, int start, int length) ;
00259 
00260     /** If there are any listeners, return current value, otherwise send a
00261      * message*/
00262     virtual int getRawLength() ;
00263 
00264     /* try to coax the compiler into working */
00265     virtual int getLength() { return ExtrapolatedProperty::getLength(); }
00266     virtual void read(string& target, int start, int length) { ExtrapolatedProperty::read(target, start, length); }
00267 
00268 };
00269 
00270 #endif

Generated on Tue Aug 12 03:55:45 2003 for Interreality Project - VOS by doxygen 1.3.2