proj home

Files   Classes   Functions   Hierarchy  

visconvex.cpp

Go to the documentation of this file.
00001 #include <sstream>
00002 using namespace std;
00003 
00004 #include <commandline.h>
00005 #include <random.h>
00006 #include <stringserialization.h>
00007 #include <visconvex.h>
00008 #include <visoperator.h>
00009 
00010 visconvex::visconvex()
00011 {
00012   N=200;
00013   colorrandom=true;
00014   color = pt3(0.0,0.0,1.0);
00015 }
00016 
00017 void visconvex::handlecommand( bool & matches, viscmd & c )
00018 {
00019   assert(ve!=0);
00020   matches=false;
00021   if (c.command != this->id())
00022     return;
00023   matches=true;
00024 
00025   commandline cmd(c.arg);
00026 //cout << SHOW(c.arg) << endl;
00027 
00028 //cout << "*" << this->id() << "*" << endl;
00029 
00030   string points;
00031   cmd.mapvar(points,"points");
00032   cmd.mapvar(N,"N");
00033 //cout << SHOW(points) << endl;
00034 
00035 //cout << SHOW(N) << endl;
00036 
00037   vector<uint> vk;
00038   vectorstring::serializeInverse(vk,points);
00039 assert(vk.size()!=0);
00040 
00041   uint sz = vk.size();
00042   vector< pt3 > & pi(ve->pi);
00043 
00044 //for (uint i=0; i<vk.size(); ++i)
00045 //  cout << SHOW(vk[i]) << endl;
00046 
00047   // Check array bounds.
00048   for (uint k=0; k<sz; ++k)
00049   {
00050     if (vk[k]>=pi.size())
00051       return;
00052   }
00053 
00054   // Create the vector of random convex points.
00055   random11<> r;
00056   vector<pt3> v2;
00057   for (uint i=0; i<N; ++i)
00058   {
00059     pt3 p;
00060     double r1=0.0;
00061     double rs=0.0;
00062     for (uint k=0; k<sz; ++k)
00063     {
00064       r1=r();
00065 //cout << SHOW(r1) << endl;
00066       rs += r1;
00067       p += (pi[ vk[k] ]*r1);
00068 //cout << SHOW(p) << endl;
00069     }
00070     assert(rs!=0.0);
00071     p /= rs;
00072     v2.push_back(p);
00073   }
00074 
00075 //cout << SHOW(v2.size()) << endl;
00076 //for (uint i=0; i<v2.size(); ++i)
00077 //cout << SHOW(v2[i]) << endl;
00078 
00079   gobjpush( new gobjglPushAttrib(GL_LIGHTING) ); 
00080   gobjpush( new gobjglPushAttrib(GL_CURRENT_BIT) );
00081 //cout << SHOW(colorrandom) << endl;
00082 // Compiler on Eee PC Ubuto doing strange things here.
00083 //   Possibly because I used inline functions in one-line 
00084 //   if then statements.
00085   if (colorrandom)
00086   {
00087     pt3 col(r(),r(),r());
00088 //    cout << SHOW(col) << endl;
00089     gobjpush( new gobjglColor3d(col)); 
00090   }
00091   else
00092   {
00093     gobjpush( new gobjglColor3d(color) );
00094   }
00095   gobjpush( new gobjglDisable( GL_LIGHTING));
00096 
00097   gobjpush(new gobjglBegin(GL_POINTS));
00098   for (uint i=0; i<v2.size(); ++i)
00099     { gobjpush(new gobjglVertex3d(v2[i])); }
00100   gobjpush(new gobjglEnd());
00101 
00102   gobjpush( new gobjglPopAttrib() );
00103   gobjpush( new gobjglPopAttrib() );
00104  
00105   c.valid=true; 
00106 }
00107 
00108 
00109 
00110 

Generated on Fri Mar 4 00:49:31 2011 for Chelton Evans Source by  doxygen 1.5.8