00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "vos/vos.hh"
00029 #include "property/property.hh"
00030 #include "image2D.hh"
00031
00032
00033 Image2D::Image2D(MetaObject* s) : MetaObject(s) {
00034 accessControl = &NoPropertyAccessControl::static_;
00035 }
00036
00037
00038 Image2D::~Image2D() {
00039 }
00040
00041 LocalImage2D::LocalImage2D(MetaObject* s) : Image2D(s), MetaObject(s)
00042 {
00043 }
00044
00045 LocalImage2D::~LocalImage2D() {
00046 }
00047
00048
00049 void LocalImage2D::initialize() {
00050
00051 pREF(LocalSite*, localsite, Site::getDefaultPeer(),
00052 try {
00053 rREF(Vobject&, v, findObject("image2D:position"), );
00054 } catch(NoSuchObjectError) {
00055 setPosition(0, 0);
00056 }
00057 try {
00058 rREF(Vobject&, v, findObject("image2D:orientation"), );
00059 } catch(NoSuchObjectError) {
00060 setOrientation(0.0);
00061 }
00062 try {
00063 rREF(Vobject&, v, findObject("image2D:scaling"), );
00064 } catch(NoSuchObjectError) {
00065 setScaling(100, 100);
00066 }
00067 try {
00068 rREF(Vobject&, v, findObject("image2D:image"), );
00069 } catch(NoSuchObjectError) {
00070 setImage("undefined", "?");
00071 }
00072 );
00073 }
00074
00075 void LocalImage2D::initialize(PropertyAccessControl* ac) {
00076 accessControl = ac;
00077 initialize();
00078 }
00079
00080
00081 RemoteImage2D::RemoteImage2D(MetaObject* s) : Image2D(s), MetaObject(s)
00082 {
00083 }
00084
00085 RemoteImage2D::~RemoteImage2D() {
00086 }
00087
00088
00089
00090 const string Image2D::getType() {
00091 return string("image2D:image2D");
00092 }
00093
00094
00095 void Image2D::registerExtenders() {
00096 LocalSite::addLocalObjectExtension(typeid(LocalImage2D).name(), &LocalImage2D::new_LocalImage2D);
00097 LocalSite::addLocalObjectExtension(typeid(Image2D).name(), &LocalImage2D::new_LocalImage2D);
00098 LocalSite::addLocalObjectExtension("image2D:image2D", &LocalImage2D::new_LocalImage2D);
00099 RemoteSite::addRemoteObjectExtension(typeid(RemoteImage2D).name(), &RemoteImage2D::new_RemoteImage2D);
00100 RemoteSite::addRemoteObjectExtension(typeid(Image2D).name(), &RemoteImage2D::new_RemoteImage2D);
00101 RemoteSite::addRemoteObjectExtension("image2D:image2D", &RemoteImage2D::new_RemoteImage2D);
00102 }
00103
00104
00105
00106 void Image2D::getPosition(double& x, double& y) {
00107 rREF(Vobject&, v, findObject("image2D:position"),
00108 string s;
00109 meta_cast<Property&>(v).read(s);
00110 sscanf(s.c_str(), "%lf %lf", &x, &y);
00111 );
00112 }
00113
00114
00115 void Image2D::setPosition(double x, double y, PropertyAccessControl* ac) {
00116 if(ac == NULL)
00117 ac = accessControl;
00118 char s[20];
00119 snprintf(s, sizeof(s), "%f %f", x, y);
00120 Property::setProperty(*this, "image2D:position", s, "text/x-vector-float", ac);
00121 }
00122
00123 double Image2D::getOrientation() {
00124 double o = 0;
00125 rREF(Vobject&, v, findObject("image2D:orientation"),
00126 string s;
00127 meta_cast<Property&>(v).read(s);
00128 sscanf(s.c_str(), "%lf", &o);
00129 );
00130 return o;
00131 }
00132
00133
00134 void Image2D::setOrientation(double o, PropertyAccessControl* ac) {
00135 if(ac == NULL)
00136 ac = accessControl;
00137 char s[40];
00138 snprintf(s, sizeof(s), "%f", o);
00139 Property::setProperty(*this, "image2D:orientation", s, "text/x-vector-float", ac);
00140 }
00141
00142 void Image2D::getScaling(double& x, double& y) {
00143 string s;
00144 rREF(Vobject&, v, findObject("image2D:scaling"), s = meta_cast<Property&>(v).read();
00145 sscanf(s.c_str(), "%lf %lf", &x, &y);
00146 );
00147 }
00148
00149
00150 void Image2D::setScaling(double x, double y, PropertyAccessControl* ac) {
00151 if(ac == NULL)
00152 ac = accessControl;
00153 char s[40];
00154 snprintf(s, sizeof(s), "%f %f", x, y);
00155 Property::setProperty(*this, "image2D:scaling", s, "text/x-vector-float", ac);
00156 }
00157
00158 string Image2D::getImage() {
00159 string s;
00160 rREF(Vobject&, v, findObject("image2D:image"),
00161 meta_cast<Property&>(v).read(s);
00162 );
00163 return s;
00164 }
00165
00166 void Image2D::getImage(string& s) {
00167 rREF(Vobject&, v, findObject("image2D:image"),
00168 meta_cast<Property&>(v).read(s);
00169 );
00170 }
00171
00172
00173 string Image2D::getImageDatatype() {
00174 string s;
00175 rREF(Vobject&, v, findObject("image2D:image"), s = meta_cast<Property&>(v).getDataType(); );
00176 return s;
00177 }
00178
00179 void Image2D::setImage(const string& value, const string& datatype,
00180 PropertyAccessControl* ac) {
00181 if(ac == NULL)
00182 ac = accessControl;
00183 Property::setProperty(*this, "image2D:image", value, datatype, ac);
00184 }
00185
00186 void Image2D::setImageFromFile(const string& filename, const string& datatype, PropertyAccessControl* ac) {
00187 cerr << "setimagefromfile: ";
00188 cerr << "reading from " << filename << endl;
00189
00190
00191 FILE* F = fopen(filename.c_str(), "r");
00192 string data = "";
00193 char c;
00194 while( (c = fgetc(F)) != EOF) {
00195 data += c;
00196 }
00197 fclose(F);
00198 setImage(data, datatype, ac);
00199 }
00200
00201 int Image2D::getImageLength() {
00202 int l;
00203 rREF(Vobject&, v, findObject("image2D:image"), l = meta_cast<Property&>(v).getLength(); );
00204 return l;
00205 }
00206
00207
00208 void LocalImage2D::sendMessage(Message* m) {
00209
00210
00211
00212 Image2D::sendMessage(m);
00213 }
00214
00215
00216
00217
00218
00219
00220 void RemoteImage2D::sendUpdateMessage(Message* m) {
00221
00222
00223
00224
00225
00226 Image2D::sendUpdateMessage(m);
00227 }
00228
00229
00230
00231
00232
00233 MetaObject* LocalImage2D::new_LocalImage2D(MetaObject *s, const string& type) {
00234 LocalImage2D* o = new LocalImage2D(s);
00235 return o;
00236 }
00237
00238 MetaObject* RemoteImage2D::new_RemoteImage2D(MetaObject *s, const string& type) {
00239 return new RemoteImage2D(s);
00240 }