Revision: 7729
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7729&view=rev
Author:   asadat
Date:     2009-05-27 19:42:15 +0000 (Wed, 27 May 2009)

Log Message:
-----------
Added a method to get the extent of the world and models. And also did some 
refactoring

Modified Paths:
--------------
    code/websim/src/websim.cc
    code/websim/src/websim.hh

Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc   2009-05-27 19:39:57 UTC (rev 7728)
+++ code/websim/src/websim.cc   2009-05-27 19:42:15 UTC (rev 7729)
@@ -255,6 +255,13 @@
                         return false;
                  }
         }
+  else if(prop == "extent")
+        {
+               double x,y,z;
+               GetModelExtent("sim", x, y, z, response);
+               GetXMLModelExtent("sim", x, y, z, response);
+               
+        }
   else if(prop == "greet") // action is the name of the greeting server
         {        
                // TODO - check to see if this server was anticipated
@@ -313,35 +320,16 @@
           return false;
         }
 
-    }else if(prop=="lasercfg"){
-
-       Time t;
-       uint32_t res;
-       double fov;
-       Pose p;
-
-       if(GetLaserCfgData(model, t, res, fov, p, response))
-       {
-               
-                GetTextLaserCfgData(model, t, res, fov, p, response);
-                        return true;
-                               
-       }       
-        else
-        {
-          response = "ERROR: Failed to get laser cfg data for model " + model;
-          return false;
-        }
-
     }else if(prop=="ranger"){
 
        Time t;
        std::vector<double> ranges;
+       std::vector<Pose> p;
        
-       if(GetRangerData(model, t, ranges, response))
+       if(GetRangerData(model, t, p, ranges, response))
        {
                
-                GetTextRangerData(model, t, ranges, response);
+                GetXMLRangerData(model, t, p, ranges, response);
                         return true;
                                
        }       
@@ -351,24 +339,13 @@
           return false;
         }
 
-    }else if(prop=="rangercfg"){
-
-       Time t;
-       std::vector<Pose> p;
-       
-       if(GetRangerCfgData(model, t, p, response))
-       {
+    }else if(prop == "extent")
+        {
+               double x,y,z;
+               GetModelExtent(model, x, y, z, response);
+               GetXMLModelExtent(model, x, y, z, response);
                
-                GetTextRangerCfgData(model, t, p, response);
-                        return true;
-                               
-       }       
-        else
-        {
-          response = "ERROR: Failed to get ranger Cfg data for model " + model;
-          return false;
         }
-    }
     else
     {
       response = "ERROR: Unknown property " + prop + " for model " + model;
@@ -720,28 +697,10 @@
     xmlBufferFree(buf);
                
 } 
-void 
-WebSim::GetTextLaserCfgData(const std::string& name,
-                                                                       Time& t,
-                                                                       
uint32_t& resolution,
-                                                                       double& 
fov,
-                                                                       Pose& p,
-                                                                       
std::string& response)
-{
-               char buf[2048];
-               snprintf(buf, sizeof(buf), 
-                        "%s's state @%s: \n  resolution(%d)\n  fov(%.2f)\n"
-                        "  pose (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)\n",
-                                 name.c_str(),
-                         t.String().c_str(),
-                         resolution,
-                         fov,
-                         p.x,p.y,p.z,p.r,p.p,p.a);
-                        response = buf;
-}
 void
 WebSim::GetTextRangerData(const std::string& name,
                                                                        Time& t,
+                                                                       
std::vector<Pose>& p,
                                                                        
std::vector<double>& ranges,                                                    
                                                                                
         std::string& response)
 {
                std::string res;
@@ -753,19 +712,30 @@
                        res.append(",");
                }
 
+               std::string pstr; 
+               char ptmp[256];
+               for(unsigned int i=0;i<p.size();i++){
+                  Pose pos = p.at(i);
+                  sprintf(ptmp," (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)",
+                         pos.x,pos.y,pos.x,pos.r,pos.p,pos.a);
+                  pstr.append(ptmp);
+                  
+               }
                
                char buf[2048];
                snprintf(buf, sizeof(buf), 
-                        "%s's state @%s: \n  ranger: (%s)\n",
+                        "%s's state @%s: \n  ranger\n  ranges: (%s)\n  pose:  
%s",
                                  name.c_str(),
                          t.String().c_str(),
-                         res.c_str());
+                         res.c_str(),
+                         pstr.c_str());
                         response = buf;
 }
 
 void
 WebSim::GetXMLRangerData(const std::string& name,
                                                                        Time& t,
+                                                                       
std::vector<Pose>& p,
                                                                        
std::vector<double>& ranges,                                                    
                                                                                
         std::string& response)
 {
 
@@ -776,7 +746,7 @@
 
     
     std::string res;
-    char temp[128];
+    char temp[1024];
     for(unsigned int i=0;i<ranges.size();i++){
           sprintf(temp,"%.3f",ranges.at(i));
           res.append(temp);
@@ -784,6 +754,14 @@
                res.append(",");
     }
 
+    std::string pstr; 
+    char ptmp[2048];
+    for(unsigned int i=0;i<p.size();i++){
+    Pose pos = p.at(i);
+    sprintf(ptmp," (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)",
+                 pos.x,pos.y,pos.x,pos.r,pos.p,pos.a);
+    pstr.append(ptmp);
+    }
 
     buf = xmlBufferCreate();
     writer = xmlNewTextWriterMemory(buf, 0);
@@ -803,8 +781,10 @@
     
     
     tmp = ConvertInput(res.c_str(), MY_ENCODING);
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "samples", BAD_CAST tmp);    
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "Samples", BAD_CAST tmp);    
     
+    tmp = ConvertInput(pstr.c_str(), MY_ENCODING);
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "Positions", BAD_CAST tmp);   
 
 
     xmlTextWriterEndElement(writer);
    
@@ -823,37 +803,80 @@
 
 }
 
+void 
+WebSim::GetTextModelExtent(const std::string& name,
+                  double& x,
+                  double& y,
+                  double& z,
+                  std::string& response)
+{
+       char buf[1024];
+       if(name == "sim")
+               snprintf(buf, sizeof(buf),"World Extent: (%.3f,%.3f,%.3f)\n",
+                               x, y, z);
+       else
+               snprintf(buf, sizeof(buf),"%s's Extent: (%.3f,%.3f,%.3f)\n",
+                               name.c_str(), x, y, z);
 
+       response = buf;
+       
+}
+
 void 
-WebSim::GetTextRangerCfgData(const std::string& name,
-                                                                       Time& t,
-                                                                       
std::vector<Pose>& p,
-                                                                       
std::string& response)
+WebSim::GetXMLModelExtent(const std::string& name,
+                  double& x,
+                  double& y,
+                  double& z,
+                  std::string& response)
 {
+       
+    xmlTextWriterPtr writer;
+    xmlBufferPtr buf;
+    xmlChar *tmp;    
+    char str[32];
 
-               std::string res;
-               char temp[256];
-               for(unsigned int i=0;i<p.size();i++){
-                  Pose pos = p.at(i);
-                  sprintf(temp," (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)",
-                         pos.x,pos.y,pos.x,pos.r,pos.p,pos.a);
-                  res.append(temp);
-                  
-               }
+    buf = xmlBufferCreate();
+    writer = xmlNewTextWriterMemory(buf, 0);
 
-               
-               char buf[2048];
-               snprintf(buf, sizeof(buf), 
-                        "%s's state @%s: \n  rangerCfg:Pose (%s)\n",
-                                 name.c_str(),
-                         t.String().c_str(),
-                         res.c_str());
-                        response = buf;
+    
+    xmlTextWriterStartElement(writer, BAD_CAST "Data");
+   
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "Type", BAD_CAST "extent");   
 
+    
+    tmp = ConvertInput(name.c_str(),MY_ENCODING);
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "Model", BAD_CAST tmp);    
+    
+    xmlTextWriterStartElement(writer, BAD_CAST "ModelExtent");
+    
+    
+    sprintf(str,"%.3f",x);
+    tmp = ConvertInput(str,MY_ENCODING);
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "X", BAD_CAST tmp);    
+    
+    sprintf(str,"%.3f",y);
+    tmp = ConvertInput(str,MY_ENCODING);
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "Y", BAD_CAST tmp);    
 
+    sprintf(str,"%.3f",z);
+    tmp = ConvertInput(str,MY_ENCODING);
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "Z", BAD_CAST tmp);    
+   
+    xmlTextWriterEndElement(writer);
+   
+    xmlTextWriterEndElement(writer);
 
+    xmlTextWriterEndDocument(writer);
+    xmlFreeTextWriter(writer);
+ 
 
+    puts((const char*) buf->content);
+
+    response = (const char*) buf->content;
+   
+    xmlBufferFree(buf);
+
+       
 }
-
 xmlChar *
 ConvertInput(const char *in, const char *encoding)
 {

Modified: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh   2009-05-27 19:39:57 UTC (rev 7728)
+++ code/websim/src/websim.hh   2009-05-27 19:42:15 UTC (rev 7729)
@@ -122,47 +122,44 @@
                                                                        
std::vector<double>& ranges,
                                                                        
std::string& response);
 
-  virtual bool GetLaserCfgData(const std::string& name,
-                                                                       Time& t,
-                                                                       
uint32_t& resolution,
-                                                                       double& 
fov,
-                                                                       Pose& p,
-                                                                       
std::string& response) = 0;
-                                                                       
-  void GetTextLaserCfgData(const std::string& name,
-                                                                       Time& t,
-                                                                       
uint32_t& resolution,
-                                                                       double& 
fov,
-                                                                       Pose& p,
-                                                                       
std::string& response);
         
   virtual bool GetRangerData(const std::string& name,
                                                                        Time& t,
+                                                                       
std::vector<Pose>& p,
                                                                        
std::vector<double>& ranges,
                                                                        
std::string& response) = 0;
   
    
    void GetTextRangerData(const std::string& name,
                                                                        Time& t,
+                                                                       
std::vector<Pose>& p,
                                                                        
std::vector<double>& ranges,
                                                                        
std::string& response);
 
    
    void GetXMLRangerData(const std::string& name,
                                                                        Time& t,
+                                                                       
std::vector<Pose>& p,
                                                                        
std::vector<double>& ranges,
                                                                        
std::string& response);
-   
-   virtual bool GetRangerCfgData(const std::string& name,
-                                                                       Time& t,
-                                                                       
std::vector<Pose>& p,
-                                                                       
std::string& response) = 0;
 
-   void GetTextRangerCfgData(const std::string& name,
-                                                                       Time& t,
-                                                                       
std::vector<Pose>& p,
+  
+   virtual bool GetModelExtent(const std::string& name,
+                                                                       double& 
x,
+                                                                       double& 
y,
+                                                                       double& 
z,
+                                                                       
std::string& response) = 0;
+   void GetTextModelExtent(const std::string& name,
+                                                                       double& 
x,
+                                                                       double& 
y,
+                                                                       double& 
z,
                                                                        
std::string& response);
 
+   void GetXMLModelExtent(const std::string&,
+                                                                       double& 
x,
+                                                                       double& 
y,
+                                                                       double& 
z,
+                                                                       
std::string& response);
   /** Get the current simulation time */
   virtual Time GetTime() = 0;
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to