proj home

Files   Classes   Functions   Hierarchy  

visconvex Class Reference

Draws random points in convex hull. More...

#include <visconvex.h>

Inheritance diagram for visconvex:
Collaboration diagram for visconvex:

List of all members.

Public Member Functions

 visconvex ()
 Default settings.
void handlecommand (bool &matches, viscmd &c)
 Possibly run the command.
stringc id () const
 Command name.

Public Attributes

pt3 color
 Default line color.
bool colorrandom
 Each time convex is called color the area/volume randomly.
uint N
 Number of random points.


Detailed Description

Draws random points in convex hull.

Definition at line 10 of file visconvex.h.


Constructor & Destructor Documentation

visconvex::visconvex (  ) 

Default settings.

Definition at line 10 of file visconvex.cpp.

References color, colorrandom, and N.

00011 {
00012   N=200;
00013   colorrandom=true;
00014   color = pt3(0.0,0.0,1.0);
00015 }


Member Function Documentation

void visconvex::handlecommand ( bool matches,
viscmd c 
) [virtual]

Possibly run the command.

Implements visoperator.

Definition at line 17 of file visconvex.cpp.

References viscmd::arg, color, colorrandom, viscmd::command, gobjpush, commandline::mapvar(), N, visenv::pi, r, vectorstring::serializeInverse(), viscmd::valid, and visoperator::ve.

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 }

stringc visconvex::id (  )  const [inline, virtual]

Command name.

Implements visoperator.

Definition at line 31 of file visconvex.h.

00032     { return string("convex"); }


Member Data Documentation

Default line color.

Definition at line 15 of file visconvex.h.

Referenced by handlecommand(), and visconvex().

Each time convex is called color the area/volume randomly.

Definition at line 19 of file visconvex.h.

Referenced by handlecommand(), and visconvex().

Number of random points.

Definition at line 22 of file visconvex.h.

Referenced by handlecommand(), and visconvex().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:23 2011 for Chelton Evans Source by  doxygen 1.5.8