vertex_schedule.cc

Go to the documentation of this file.
00001 #include "vertex_schedule.h"
00002 
00003 #include <iostream>
00004 
00005 #include "box.h"
00006 #include "log.h"
00007 #include "container.h"
00008 #include "face.h"
00009 #include "gain_schedule.h"
00010 #include "intersecting_faces.h"
00011 #include "nice.h"
00012 #include "refractory.h"
00013 #include "space.h"
00014 #include "state.h"
00015 #include "vertex.h"
00016 #include "virtual_disp.h"
00017 
00018 using std::cout;
00019 using std::endl;
00020 
00021 Vertex_Schedule * Vertex_Schedule::only_one = NULL;
00022 
00023 Vertex_Schedule & Vertex_Schedule::instance(void)
00024 {
00025   // Not thread-safe.
00026   // -- lock mutex
00027   if (only_one == NULL)
00028     only_one = new Vertex_Schedule();
00029   // -- unlock mutex
00030   return *only_one;
00031 }
00032 
00033 Vertex_Schedule::Vertex_Schedule (const Vertex_Schedule& rhs)
00034   :cv(NULL),seed(NULL),vset(),pH(3,0),count(0),count_ref(0)
00035 {
00036   cout << "Assignment operator prohibited on instances of Vertex_Schedule class.\n";
00037   cout << "Vertex_Schedule " << rhs.count<< endl;
00038   exit(0);
00039 }
00040 
00041 Vertex_Schedule& Vertex_Schedule::operator = (const Vertex_Schedule& rhs)
00042 {
00043   cout << "Assignment operator prohibited on instances of Vertex_Schedule class.\n";
00044   cout << "Vertex_Schedule " << rhs.count << endl;
00045   exit(0);
00046 }
00047 
00048 Vertex_Schedule::Vertex_Schedule (void)
00049   :cv(NULL),seed(NULL),vset(),pH(3,0),count(0),count_ref(0)
00050 {
00051   // reserve capacity for vectors
00052 }
00053 
00054 bool Vertex_Schedule::noSetVerticesMoved (void) const
00055 {
00056   return count_ref==count;
00057 }
00058 
00059 void Vertex_Schedule::computeVertex (Vertex * const v)
00060 {
00061   cv=v;
00062   // compute new holding position coordinates (x,y,z)
00063   pH = cv->getNewPos(Gain_Schedule::instance().getGain());
00064   // impose max displacement policy
00065   Refractory::instance().screenDisp(cv,pH);
00066   // displacement along x,y,z
00067   double a=pH[0]-cv->getCoord(0);
00068   double b=pH[1]-cv->getCoord(1);
00069   double d=pH[2]-cv->getCoord(2);
00070   // compute and store squared displacement 
00071   State::instance().setVD2(a*a+b*b+d*d);
00072 }
00073 
00074 void Vertex_Schedule::identifyMeshRegionToUpdate (void)
00075 {
00076   seed=NULL;
00077   if(MOVE_NONNICE_AND_INTERSECTED_FIRST)
00078   {
00079     // try to pick nonnice vertex as set seed
00080     // for each element of nice hashmap
00081     for(vhm_cit j=Nice::instance().beginNice();j!=Nice::instance().endNice();j++)
00082     {
00083       Vertex *vv=(*j).first;
00084       // if vertex is not punished and not refracted
00085       // and not frozen and has a closest face
00086       if ( Refractory::instance().isPunished(vv)==false && Refractory::instance().Refracted(vv)==false && vv->getFace()!=NULL
00087            && (Container::instance().vertexIsFrozen(vv)==false))
00088       {
00089         seed = vv;break;
00090       }
00091     }
00092 
00093     // else try to pick intersected face vertex as set seed
00094     if(seed==NULL)
00095     {
00096       // for each element of intf hashmap
00097       for(htff_cit j=Intersecting_Faces::instance().begin();j!=Intersecting_Faces::instance().end();j++)
00098       {
00099         Face *ff=(*j).first;
00100         // for each vertex of face
00101         for(int k=0;k<3;k++)
00102         {
00103           Vertex *vv=ff->getVertex(k);
00104           // if vertex is not punished and not refracted
00105           // and not frozen and has a closest face
00106           if (Refractory::instance().isPunished(vv)==false && Refractory::instance().Refracted(vv)==false && vv->getFace()!=NULL
00107               && (Container::instance().vertexIsFrozen(vv)==false))
00108           {
00109             seed = vv;break;
00110           }
00111         }
00112         if(seed!=NULL){break;}
00113       }
00114     }
00115   }
00116 
00117   // else pick vertex from sorted virtual displacement list
00118   if(seed==NULL)
00119   {
00120     // starting at current location of tvi in topN
00121     // find vertex with largest virtual displacement that is not punished
00122     // and not refracted and not frozen and has a closest face
00123     while(Refractory::instance().isPunished((*(Virtual_Disp::instance().getIterator())).second)==true 
00124           || Refractory::instance().Refracted((*(Virtual_Disp::instance().getIterator())).second)==true
00125           || (Container::instance().vertexIsFrozen((*(Virtual_Disp::instance().getIterator())).second)==true)
00126           || (*(Virtual_Disp::instance().getIterator())).second->getFace()==NULL)
00127     {
00128       Virtual_Disp::instance().incrementIterator();
00129       if(Virtual_Disp::instance().getIterator()==Virtual_Disp::instance().rendTopN())
00130       {vset.clear();return;}
00131     }
00132     seed = (*(Virtual_Disp::instance().getIterator())).second;
00133   }
00134 //  // grab Box* of worst vertex
00135 //  Box *bp=Space::instance().getBox(Space::instance().indices2Index(
00136 //        Space::instance().location2Index(seed->getCoord(0),"x"),
00137 //        Space::instance().location2Index(seed->getCoord(1),"y"),
00138 //        Space::instance().location2Index(seed->getCoord(2),"z")));
00139 //  // grab unique set of vertices of all faces in box
00140 //  vec_vp bin;
00141 //  for(fp_cit z=bp->begin();z!=bp->end();z++)
00142 //  {
00143 //    for(int k=0;k<3;k++)
00144 //    {
00145 //      if((*z)->getVertex(k)!=seed)
00146 //      {
00147 //        bin.push_back((*z)->getVertex(k));
00148 //      }
00149 //    }
00150 //  }
00151   vec_d origin(3,0),end(3,0);
00152   origin[0] = seed->getCoord(0)-(SEED_ADJACENT_BOXES*SPACE_LENGTH)*SCALE;
00153   origin[1] = seed->getCoord(1)-(SEED_ADJACENT_BOXES*SPACE_LENGTH)*SCALE;
00154   origin[2] = seed->getCoord(2)-(SEED_ADJACENT_BOXES*SPACE_LENGTH)*SCALE;
00155   end[0]    = seed->getCoord(0)+(SEED_ADJACENT_BOXES*SPACE_LENGTH)*SCALE;
00156   end[1]    = seed->getCoord(1)+(SEED_ADJACENT_BOXES*SPACE_LENGTH)*SCALE;
00157   end[2]    = seed->getCoord(2)+(SEED_ADJACENT_BOXES*SPACE_LENGTH)*SCALE;
00158   vec_bp bp;
00159   Space::instance().getBoxesFromPosition(origin,end,bp);
00160   vec_vp bin;
00161   bin.reserve(VECTOR_RESERVE);
00162   // for each box
00163   for(bp_it i=bp.begin();i!=bp.end();i++)
00164   {
00165     // for each face in box
00166     for(fp_cit j=(*i)->begin();j!=(*i)->end();j++)
00167     {
00168       // add face vertices to vector
00169       bin.push_back((*j)->getVertex(0));
00170       bin.push_back((*j)->getVertex(1));
00171       bin.push_back((*j)->getVertex(2));
00172     }
00173   }
00174   // sort and keep unique Vertex*
00175   sort(bin.begin(),bin.end(),my_ltv());
00176   bin.assign(bin.begin(),unique(bin.begin(),bin.end()));
00177   // build vset
00178   vset.clear(); 
00179   vset.push_back(seed);
00180   for(vp_it i=bin.begin();i!=bin.end();i++)
00181   {
00182     vset.push_back(*i);
00183   }
00184   // to detect if any vertices from set were moved
00185   count_ref = count;
00186   // collect statistics on number of vertices per set
00187   Log::instance().updateVertexSchedulingStats(vset.size());
00188 }
00189 
00190 Vertex * Vertex_Schedule::getCurrentVertex (void) const
00191 {
00192   return cv;
00193 }
00194 
00195 Vertex * Vertex_Schedule::getSeedVertex (void) const
00196 {
00197   return seed;
00198 }
00199 
00200 int Vertex_Schedule::getNumMovedVertsGroup (void) const
00201 {
00202   return count;
00203 }
00204 
00205 void Vertex_Schedule::setNumMovedVertsGroup (int i)
00206 {
00207   count = i;
00208 }
00209 
00210 bool Vertex_Schedule::noMoreVertices (void) const
00211 {
00212   return vset.empty();
00213 }
00214 
00215 vp_cit Vertex_Schedule::beginVset (void) const
00216 {
00217   return vset.begin();
00218 }
00219 
00220 vp_cit Vertex_Schedule::endVset (void) const
00221 {
00222   return vset.end();
00223 }
00224 
00225 void Vertex_Schedule::incrementNumMovedVertsGroup (void)
00226 {
00227   count++;
00228 }
00229 
00230 vec_d const & Vertex_Schedule::getVertexDestination (void) const
00231 {
00232   return pH;
00233 }
00234 

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