object.cc

Go to the documentation of this file.
00001 #include "object.h"
00002 
00003 #include <cassert>
00004 #include <iostream>
00005 
00006 #include "edge.h"
00007 #include "face.h"
00008 #include "vertex.h"
00009 
00010 using std::cout;
00011 using std::endl;
00012 
00013 Object::Object (const Object& rhs)
00014   :name(rhs.name),
00015   fv(rhs.fv),ff(rhs.ff),fe(rhs.fe),
00016   v(rhs.v),f(rhs.f),e(rhs.e)
00017 {
00018 }
00019 
00020 Object& Object::operator = (const Object& rhs)
00021 {
00022   cout << "Copy assignment operator prohibited on instances of Object class.\n";
00023   cout << "Object " << rhs.name << endl;
00024   exit(0);
00025 }
00026 
00027 Object::Object (str s)
00028   :name(s),
00029   fv(NULL),ff(NULL),fe(NULL),
00030   v(),f(),e()
00031 {
00032 }
00033 
00034 str Object::keyPair (int a,int b,int num_digits) const
00035 {
00036   char str[128],format[32];
00037   sprintf(format,"%%0%dd%%0%dd",num_digits,num_digits);
00038   if (a<b){ sprintf(str,format,a,b);}
00039   else { sprintf(str,format,b,a); }
00040   return str;
00041 }
00042 
00043 #if 0
00044 void Object::setVertexNiceVal(int newval,Container * const c,Vertex * const vv)
00045 {
00046   int oldval=0;
00047   vhm_it i = nice.find(vv);
00048   // if vertex in hashtable
00049   if(i!=nice.end()){oldval=nice[vv];}
00050   // process
00051   // not old==new needs no action
00052   // nice val == 1, nonnice in different object
00053   // nice val == 2, nonnice in same object
00054   switch (oldval+newval*3)
00055   {
00056     case 1 :
00057       // old==1 + new==0*3
00058       // remove this vertex from hashtable
00059       nice.erase(i);
00060       c->nonnice--;
00061       break;
00062 
00063     case 2 :
00064       // old==2 + new==0*3
00065       nice.erase(i);
00066       c->nonnice--;
00067       c->s_nonnice--;
00068       break;
00069 
00070     case 3 :
00071       // old==0 + new==1*3
00072       nice[vv]=newval;
00073       c->nonnice++;
00074       break;
00075 
00076     case 5 :
00077       // old==2 + new==1*3
00078       nice[vv]=newval;
00079       c->s_nonnice--;
00080       break;
00081 
00082     case 6 :
00083       // old==0 + new==2*3
00084       nice[vv]=newval;
00085       c->nonnice++;
00086       c->s_nonnice++;
00087       break;
00088 
00089     case 7 :
00090       // old==1 + new==2*3
00091       nice[vv]=newval;
00092       c->s_nonnice++;
00093       break;
00094   }     
00095 }
00096 #endif
00097 
00098 Edge* Object::findEdge (Vertex const * const va,Vertex const * const vb,map_s_ep const &hm,int num_digits) const
00099 {
00100   str s = keyPair(va->getIndex(),vb->getIndex(),num_digits);
00101   // if element exists given key, then get Edge pointer
00102   if (hm.count(s)>0)
00103   {
00104     msep_cit i = hm.find(s);    
00105     return (*i).second;
00106     //return hm[s];
00107   }
00108   else { return NULL;}
00109 }
00110 
00111 void Object::createEdge (Face * const i,Vertex* const va,Vertex* const vb,map_s_ep &hm,int num_digits)
00112 {
00113   // check for space in vector
00114   if(e.capacity()>e.size())
00115   {
00116     // add edge pointer to object
00117     e.push_back(Edge(i,va,vb));
00118     // store edge pointer in hash table
00119     hm[keyPair(va->getIndex(),vb->getIndex(),num_digits)]=&e.back();;
00120     // add edge pointer to face
00121     i->addEdge(&e.back());
00122     // store first edge pointer
00123     if(e.size()==1)
00124     {
00125       fe = &e[0];
00126     }
00127   }
00128   else
00129   {
00130     cout << "\n\nObject::createEdge: Error. "
00131           << "Must increase capacity of edge vector which is currently equal to "
00132           << e.capacity() << endl << endl;
00133     exit(0);
00134   }
00135 }
00136 
00137 void Object::processEdge (Face * const i,Vertex * const va,Vertex * const vb,map_s_ep &hm,int num_digits)
00138 {
00139   assert(va!=NULL);
00140   assert(vb!=NULL);
00141   Edge *ee=findEdge(va,vb,hm,num_digits);
00142   if(ee!=NULL){ee->update(i);}
00143   else {createEdge(i,va,vb,hm,num_digits);}
00144 }
00145 
00146 int Object::setNumDigits (void) const
00147 {
00148   int max=0;
00149   // for each vertex in object
00150   for(v_cit i=v.begin();i!=v.end();i++)
00151   {
00152     if(i->getIndex()>max){max=i->getIndex();}
00153   }
00154   char phrase[64];
00155   sprintf(phrase,"%d",max);
00156   str s = phrase;
00157   return s.length();
00158 }
00159 
00160 void Object::findVertAdj (void)
00161 {
00162   // for each face in object
00163   for (f_it j=f.begin();j!=f.end();j++)
00164   {
00165     // for each vertex of face
00166     for(int i=0;i<3;i++)
00167     {
00168       Vertex *vv=j->getVertex(i);
00169       // add face* to vertex
00170       vv->addAdjacentFace(&(*j));
00171       //vv->f.push_back(&(*j));
00172     }
00173   }
00174 }
00175 
00176 void Object::boundObject (double * const &r) const
00177 {
00178   double xmin,xmax,ymin,ymax,zmin,zmax,x,y,z;
00179   //initialize mins and maxes
00180   xmin = v[0].getCoord(0);
00181   xmax = v[0].getCoord(0);
00182   ymin = v[0].getCoord(1);
00183   ymax = v[0].getCoord(1);
00184   zmin = v[0].getCoord(2);
00185   zmax = v[0].getCoord(2);
00186   // for each vertex in object
00187   for (v_cit i=v.begin();i!=v.end();i++)
00188   {
00190     x = i->getCoord(0);
00191     y = i->getCoord(1);
00192     z = i->getCoord(2);
00193     if (x>xmax) {xmax = x;}
00194     else if (x<xmin) {xmin = x;}
00195     if (y>ymax) {ymax = y;}
00196     else if (y<ymin) {ymin = y;}
00197     if (z>zmax) {zmax = z;}
00198     else if (z<zmin) {zmin = z;}
00199   }
00200   r[0]=xmin;r[1]=xmax;
00201   r[2]=ymin;r[3]=ymax;
00202   r[4]=zmin;r[5]=zmax;
00203 }
00204 
00205 str const & Object::getName (void) const
00206 {
00207   return name;
00208 }
00209 
00210 //v_it Object::vbegin (void) const
00211 //{
00212 //  return v.begin();
00213 //}
00214 //
00215 //v_it Object::vend (void) const
00216 //{
00217 //  return v.end();
00218 //}
00219 
00220 void Object::setFE (Edge * ee)
00221 {
00222   fe = ee;;
00223 }
00224 
00225 void Object::setFF (Face * fptr)
00226 {
00227   ff = fptr;
00228 }
00229 
00230 void Object::setFV (Vertex * vv)
00231 {
00232   fv = vv;
00233 }
00234 
00235 Edge * Object::getFE (void) const
00236 {
00237   return fe;
00238 }
00239 
00240 Face * Object::getFF (void) const
00241 {
00242   return ff;
00243 }
00244 
00245 Vertex * Object::getFV (void) const
00246 {
00247   return fv;
00248 }
00249 

Generated on Fri Jul 18 19:43:40 2008 for meshmorph by  doxygen 1.5.1