Changeset 2001


Ignore:
Timestamp:
01/20/07 14:03:37 (17 years ago)
Author:
bittner
Message:

mutation updates

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1997 r2001  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: ?t 18. I 20:30:31 2007 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: pá 19. I 15:33:39 2007 
    44# Project:  preprocessor.pro 
    55# Template: app 
     
    6363        $(MAKE) -f $(MAKEFILE).Debug uninstall 
    6464 
    65 Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc.net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
     65Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
    6666                C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 
    6767                C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp

    r1997 r2001  
    99#include "RndGauss.h" 
    1010#include "Mutation.h" 
     11#include "Exporter.h" 
    1112 
    1213#ifdef GTP_INTERNAL 
     
    2021 
    2122#define USE_SIL_TERMINATION_MUTATION 1 
     23#define MUTATE_ORIGIN 1 
    2224 
    2325#define EVALUATE_MUTATION_STATS 1 
     26 
     27#define Q_SEARCH_STEPS 2 
    2428 
    2529void 
     
    5155  int dummyNcMutations = 0; 
    5256  int dummyCMutations = 0; 
     57 
     58  int reverseCandidates = 0; 
    5359   
    5460  for (int i=0; i < vssRays.size(); i++) { 
     
    8692                *mRays[mBufferStart].mRay = *vssRays[i]; 
    8793                mRays[mBufferStart].mMutations = 0; 
     94                mRays[mBufferStart].ResetReverseMutation(); 
    8895                //              mRays[mBufferStart] = RayEntry(newRay); 
    8996                mBufferStart++; 
    9097                if (mBufferStart >= mMaxRays) 
    9198                  mBufferStart = 0; 
     99                 
     100 
    92101          } 
    93102        } else { 
    94 #if EVALUATE_MUTATION_STATS  
    95103          if (vssRays[i]->mDistribution == MUTATION_BASED_DISTRIBUTION && 
    96104                  vssRays[i]->mGeneratorId != -1 
    97105                  ) { 
     106                // check whether not to store a new backward mutation candidate 
     107                VssRay *oldRay = mRays[vssRays[i]->mGeneratorId].mRay; 
     108                VssRay *newRay = vssRays[i]; 
     109 
     110#define DIST_THRESHOLD 3.0f 
     111 
     112                Intersectable *oldObject = 
     113                  mPreprocessor.mViewCellsManager->GetIntersectable( 
     114                                                                                                                        *oldRay, 
     115                                                                                                                        true); 
     116                 
     117 
     118                if (!mRays[newRay->mGeneratorId].HasReverseMutation()) { 
     119                  if (DotProd(oldRay->GetDir(), newRay->GetDir()) > 0.0f) { 
     120                  float oldDist = Magnitude(oldRay->mTermination - newRay->mOrigin); 
     121                  float newDist = Magnitude(newRay->mTermination - newRay->mOrigin); 
     122                   
     123                  if (newDist < oldDist - oldObject->GetBox().Radius()*DIST_THRESHOLD) { 
     124                        Vector3 origin, termination; 
     125                        if (ComputeReverseMutation(*oldRay, *newRay, origin, termination)) { 
     126                          mRays[newRay->mGeneratorId].SetReverseMutation(origin, termination); 
     127                        } 
     128                         
     129                        reverseCandidates++; 
     130                        //mReverseCandidates 
     131                  } 
     132                  } 
     133                } 
     134#if EVALUATE_MUTATION_STATS  
    98135                mutationRays++; 
    99  
     136                 
    100137                Intersectable *newObject = 
    101138                  mPreprocessor.mViewCellsManager->GetIntersectable( 
     
    103140                                                                                                                        true); 
    104141 
    105                 Intersectable *oldObject = 
    106                   mPreprocessor.mViewCellsManager->GetIntersectable( 
    107                                                                                                                         *mRays[vssRays[i]->mGeneratorId].mRay, 
    108                                                                                                                         true); 
    109142 
    110143                if (oldObject == newObject) 
    111144                  dummyNcMutations++; 
     145#endif 
    112146          } 
    113 #endif 
    114147        } 
    115148  } 
    116  
     149   
    117150  if (mutationRays) { 
    118151        cout<<"Mutated rays:"<<mutationRays<<endl; 
     
    121154        cout<<"Dummy NC mutations ratio:"<<100.0f*dummyNcMutations/(float)mutationRays<<"%"<<endl; 
    122155        cout<<"Dummy C mutations ratio:"<<100.0f*dummyCMutations/(float)mutationRays<<"%"<<endl; 
     156        cout<<"Reverse candidates:"<<reverseCandidates<<endl; 
    123157  } 
    124158 
     
    259293} 
    260294 
     295bool 
     296MutationBasedDistribution::ComputeReverseMutation( 
     297                                                                                                  const VssRay &oldRay, 
     298                                                                                                  const VssRay &newRay, 
     299                                                                                                  Vector3 &origin, 
     300                                                                                                  Vector3 &termination 
     301                                                                                                  ) 
     302{ 
     303  // first reconstruct the termination point 
     304  Vector3 oldDir = Normalize(oldRay.GetDir()); 
     305  Plane3 oldPlane(oldDir, oldRay.mTermination); 
     306   
     307  termination = oldPlane.FindIntersection(newRay.mOrigin, 
     308                                                                                  newRay.mTermination); 
     309   
     310  // now find the new origin of the ray by casting ray backward from the termination and termining 
     311  // silhouette point with respect to the occluding object (object containing the newRay termination) 
     312 
     313  Plane3 newPlane(oldDir, newRay.mTermination); 
     314 
     315  Vector3 oldPivot = newPlane.FindIntersection(oldRay.mOrigin, 
     316                                                                                           oldRay.mTermination); 
     317 
     318  Vector3 newPivot = newRay.mTermination; 
     319  Vector3 line = 2.0f*(oldPivot - newPivot); 
     320 
     321  Intersectable *occluder = mPreprocessor.mViewCellsManager->GetIntersectable( 
     322                                                                                                                                                          newRay, 
     323                                                                                                                                                          true); 
     324   
     325  AxisAlignedBox3 box = occluder->GetBox(); 
     326  box.Scale(2.0f); 
     327   
     328  const int packetSize = 4; 
     329  static int hit_triangles[packetSize]; 
     330  static float dist[packetSize]; 
     331  static Vector3 dirs[packetSize]; 
     332  static Vector3 shifts[packetSize]; 
     333  // now find the silhouette along the line 
     334  int i; 
     335  float left = 0.0f; 
     336  float right = 1.0f; 
     337  // cast rays to find silhouette ray 
     338  for (int j=0; j < Q_SEARCH_STEPS; j++) { 
     339        for (i=0; i < packetSize; i++) { 
     340          float r = left + (i+1)*(right-left)/(packetSize+1); 
     341          shifts[i] = r*line; 
     342          dirs[i] = Normalize(newPivot + shifts[i] - termination ); 
     343          mlrtaStoreRayASEye4(&termination.x, 
     344                                                  &dirs[i].x, 
     345                                                  i); 
     346        } 
     347         
     348        mlrtaTraverseGroupASEye4(&box.Min().x, 
     349                                                         &box.Max().x, 
     350                                                         hit_triangles, 
     351                                                         dist); 
     352         
     353        for (i=0; i < packetSize; i++) { 
     354          if (hit_triangles[i] == -1) { 
     355                // break on first passing ray 
     356                break; 
     357          } 
     358        } 
     359        float rr = left + (i+1)*(right-left)/(packetSize+1); 
     360        float rl = left + i*(right-left)/(packetSize+1); 
     361        left = rl; 
     362        right = rr; 
     363  } 
     364 
     365  float t = right; 
     366  if (right==1.0f) 
     367        return false; 
     368   
     369  if (i == packetSize) 
     370        origin = newPivot + right*line; 
     371  else 
     372        origin = newPivot + shifts[i]; 
     373 
     374  if (0) { 
     375         
     376        static VssRayContainer rRays; 
     377        static int counter = 0; 
     378        char filename[256]; 
     379 
     380        if (counter < 50) { 
     381          sprintf(filename, "reverse_rays_%03d.x3d", counter++); 
     382           
     383          VssRay tRay(origin, termination, NULL, NULL); 
     384          rRays.push_back((VssRay *)&oldRay); 
     385          rRays.push_back((VssRay *)&newRay); 
     386          rRays.push_back(&tRay); 
     387           
     388          Exporter *exporter = NULL; 
     389          exporter = Exporter::GetExporter(filename); 
     390           
     391          exporter->SetFilled(); 
     392           
     393          Intersectable *occludee = mPreprocessor.mViewCellsManager->GetIntersectable( 
     394                                                                                                                                                                  oldRay, 
     395                                                                                                                                                                  true); 
     396           
     397          exporter->SetForcedMaterial(RgbColor(0,0,1)); 
     398          exporter->ExportIntersectable(occluder); 
     399          exporter->SetForcedMaterial(RgbColor(0,1,0)); 
     400          exporter->ExportIntersectable(occludee); 
     401          exporter->ResetForcedMaterial(); 
     402           
     403          exporter->SetWireframe(); 
     404           
     405           
     406          exporter->ExportRays(rRays, RgbColor(1, 0, 0)); 
     407          delete exporter; 
     408          rRays.clear(); 
     409        } 
     410  } 
     411 
     412 
     413   
     414  return true; 
     415   
     416  // now the origin and termination is swapped compred to the generator ray 
     417  // swap(origin, termination);??? 
     418  // -> perhaps not neccessary as the reverse mutation wil only be used once! 
     419} 
    261420 
    262421Vector3 
     
    270429                                                                                                                                ) 
    271430{ 
    272   const int packetSize = 16; 
    273  
     431  const int packetSize = 4; 
    274432  static int hit_triangles[packetSize]; 
    275433  static float dist[packetSize]; 
    276434  static Vector3 dirs[packetSize]; 
     435  static Vector3 shifts[packetSize]; 
    277436  // mutate the  
    278437  float alpha = RandomValue(0.0f, 2.0f*M_PI); 
     438  //float alpha = vr2.x*2.0f*M_PI; 
    279439   
    280440  // direction along which we will mutate the ray 
     
    283443  //  cout<<line<<endl; 
    284444  // create 16 rays along the selected dir 
    285    
     445  int i; 
     446  float left = 0.0f; 
     447  float right = radius; 
    286448  // cast rays to find silhouette ray 
    287   for (int i=0; i < packetSize; i++) { 
    288         dirs[i] = Normalize(ray.mTermination + ((radius/(packetSize - i))*line) - origin ); 
    289         mlrtaStoreRayAS16(&origin.x, 
    290                                           &dirs[i].x, 
    291                                           i); 
    292   } 
    293    
    294   mlrtaTraverseGroupAS16(&box.Min().x, 
    295                                                  &box.Max().x, 
    296                                                  hit_triangles, 
    297                                                  dist); 
    298    
    299   for (int i=0; i < packetSize; i++) { 
    300         if (hit_triangles[i] == -1 || !box.IsInside(origin + dist[i]*dirs[i])) { 
    301           // break on first passing ray 
    302           break; 
     449  for (int j=0; j < Q_SEARCH_STEPS; j++) { 
     450        for (i=0; i < packetSize; i++) { 
     451          float r = left + (i+1)*(right-left)/(packetSize+1); 
     452          shifts[i] = r*line; 
     453          dirs[i] = Normalize(ray.mTermination + shifts[i] - origin ); 
     454          mlrtaStoreRayASEye4(&origin.x, 
     455                                                  &dirs[i].x, 
     456                                                  i); 
    303457        } 
     458         
     459        mlrtaTraverseGroupASEye4(&box.Min().x, 
     460                                                         &box.Max().x, 
     461                                                         hit_triangles, 
     462                                                         dist); 
     463         
     464        for (i=0; i < packetSize; i++) { 
     465          if (hit_triangles[i] == -1) { 
     466                //        if (hit_triangles[i] == -1 || !box.IsInside(origin + dist[i]*dirs[i])) { 
     467                // break on first passing ray 
     468                break; 
     469          } 
     470        } 
     471        float rr = left + (i+1)*(right-left)/(packetSize+1); 
     472        float rl = left + i*(right-left)/(packetSize+1); 
     473        left = rl; 
     474        right = rr; 
    304475  } 
    305476   
     
    307478        //      cerr<<"Warning: hit the same box here should never happen!"<<endl; 
    308479        // shift the ray even a bit more 
    309         //      cout<<"W"<<i<<endl; 
    310         return ray.mTermination + (RandomValue(1.0f, 2.0f)*radius)*line; 
    311   } 
    312  
     480        //cout<<"W"<<i<<endl; 
     481        //      return (RandomValue(1.0f, 1.5f)*radius)*line; 
     482        return right*line; 
     483  } 
     484   
    313485  //  cout<<i<<endl; 
    314   return dirs[i]; 
     486  return shifts[i]; 
    315487} 
    316488 
     
    386558  mLastIndex = index; 
    387559 
     560  if (mRays[index].HasReverseMutation()) { 
     561        //cout<<"R "<<mRays[index].mutatedOrigin<<" "<<mRays[index].mutatedTermination<<endl; 
     562        sray = SimpleRay(mRays[index].mutatedOrigin, 
     563                                         Normalize(mRays[index].mutatedTermination - mRays[index].mutatedOrigin), 
     564                                         MUTATION_BASED_DISTRIBUTION, 1.0f); 
     565        sray.mGeneratorId = index; 
     566        mRays[index].ResetReverseMutation(); 
     567        mRays[index].mMutations++; 
     568        return true; 
     569  } 
     570   
    388571#if USE_SILHOUETTE_MUTATIONS 
    389572  return GenerateSilhouetteMutation(index, sray); 
     
    391574  return GenerateMutation(index, sray); 
    392575#endif 
    393    
    394576} 
    395577 
     
    410592 
    411593  mRays[index].mHalton.GetNext(4, rr); 
     594  //  rr[0] = RandomValue(0.0f,0.99999f); 
     595  //  rr[1] = RandomValue(0.0f,0.99999f); 
     596  //  rr[2] = RandomValue(0.0f,0.99999f); 
     597  //  rr[3] = RandomValue(0.0f,0.99999f); 
    412598   
    413599  // mutate the origin 
     
    430616  // optimal for Vienna 0.5f 
    431617   
    432   float radiusExtension = 0.05f; 
     618  float radiusExtension = 0.5f; 
    433619  //  + mRays[index].mMutations/50.0f; 
    434  
     620   
    435621  float mutationRadius = objectRadius*radiusExtension; 
    436  
     622   
    437623  // tmp for pompeii 
    438   mutationRadius = 0.22f; 
    439    
     624  //  mutationRadius = 0.22f; 
     625 
     626#if MUTATE_ORIGIN 
    440627  origin += ComputeOriginMutation(*ray, U, V, 
    441628                                                                  Vector2(rr[0], rr[1]), 
    442629                                                                  mutationRadius); 
     630#endif 
    443631   
    444632#if USE_SIL_TERMINATION_MUTATION 
     
    448636                                                                                                          U, V, 
    449637                                                                                                          Vector2(rr[2], rr[3]), 
    450                                                                                                           3.0f*objectRadius); 
     638                                                                                                          2.0f*objectRadius); 
    451639#else 
    452640  termination += ComputeTerminationMutation(*ray, U, V, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.h

    r1997 r2001  
    4747        // halton sequence for generatin gmutations of this ray 
    4848        VssRay *mRay; 
    49         int mMutations; 
    50         int mUnsuccessfulMutations; 
     49        short mMutations; 
     50        short mUnsuccessfulMutations; 
    5151        HaltonSequence mHalton; 
    5252        float mImportance; 
    5353        float mCdf; 
    5454 
     55        Vector3 mutatedOrigin; 
     56        Vector3 mutatedTermination; 
     57         
    5558        float GetSamplingFactor() const { return mMutations/mImportance; } 
    5659        RayEntry() {} 
     
    5962                                                mUnsuccessfulMutations(0), 
    6063                                                mHalton(), 
    61                                                 mImportance(1.0f) {} 
     64                                                mImportance(1.0f) 
     65        { 
     66          ResetReverseMutation(); 
     67        } 
     68 
     69        void ResetReverseMutation() { 
     70          mutatedOrigin = mutatedTermination = Vector3(0,0,0); 
     71        } 
     72        bool HasReverseMutation() const { 
     73          return !(mutatedOrigin == mutatedTermination); 
     74        } 
     75         
     76        void SetReverseMutation(const Vector3 &a, const Vector3 &b) { 
     77          mutatedOrigin = a; 
     78          mutatedTermination = b; 
     79        } 
     80 
    6281  }; 
    63  
     82   
    6483 
    6584  Vector3 
     
    90109                                                                           ); 
    91110 
     111 
     112  bool 
     113  ComputeReverseMutation( 
     114                                                 const VssRay &oldRay, 
     115                                                 const VssRay &newRay, 
     116                                                 Vector3 &origin, 
     117                                                 Vector3 &termination 
     118                                                 ); 
     119 
    92120  RayEntry &GetEntry(const int index) { 
    93121        return mRays[(mBufferStart+index)%mRays.size()]; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1999 r2001  
    12941294Preprocessor::ExportRays(const char *filename, 
    12951295                                                 const VssRayContainer &vssRays, 
    1296                                                  const int number 
     1296                                                 const int number, 
     1297                                                 const bool exportScene 
    12971298                                                 ) 
    12981299{ 
     
    13091310  exporter->SetFilled(); 
    13101311  // $$JB temporarily do not export the scene 
    1311   if (0) 
     1312  if (exportScene) 
    13121313        exporter->ExportScene(mSceneGraph->GetRoot()); 
    13131314 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1996 r2001  
    123123 
    124124        virtual bool 
    125                 ExportRays(const char *filename, 
    126                 const VssRayContainer &vssRays, 
    127                 const int number 
    128                 ); 
     125        ExportRays(const char *filename, 
     126                           const VssRayContainer &vssRays, 
     127                           const int number, 
     128                           const bool exportScene = false 
     129                           ); 
    129130 
    130131        virtual int 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r2000 r2001  
    652652                                  } else 
    653653                                        if (strcmp(curr, "mutation")==0) { 
    654                                                 // temp matt: still no mutationstrategy! 
    655                                           //mDistributions.push_back(new MutationBasedDistribution(mPreprocessor)); 
    656                                         }  
     654                                          // temp matt: still no mutationstrategy! 
     655                                          mDistributions.push_back(new MutationBasedDistribution(mPreprocessor)); 
     656                                        } 
    657657         
    658658         
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp

    r1634 r2001  
    115115    QueryPerformanceCounter(&counter); 
    116116    // return in usec 
    117     return (long) (1000000*counter.QuadPart/(hrFreq.QuadPart)); 
     117    //return (long) (1000000*counter.QuadPart/(hrFreq.QuadPart)); 
     118        // $$ 
     119        // tmp store time in ms 
     120    return (long) (1000*counter.QuadPart/(hrFreq.QuadPart)); 
    118121  } else { 
    119122    static struct _timeb mtime; 
     
    152155TimeDiff(long time1,long time2) // in ms 
    153156{ 
    154   const Real clk=1.0e-3f; // ticks per second 
     157  //  const Real clk=1.0e-3f; // ticks per second 
     158  // $$ tmp store time in ms 
     159  const Real clk=1.0f; // ticks per second 
    155160  long t=time2-time1; 
    156161   
  • GTP/trunk/Lib/Vis/Preprocessing/src/run_test2

    r1974 r2001  
    1515 
    1616#SCENE=../data/soda/soda.dat 
    17 #VIEWCELLS=../data/soda/soda5-viewcells-1000.xml 
     17#VIEWCELLS=../data/soda/soda5-viewcells.xml 
    1818#VIEWCELLS=../data/soda/soda-viewcells-5000.xml 
    1919#VIEWCELLS=../data/soda/soda5-viewcells-single.xml 
     
    4949$COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
    5050 -rss_distributions=mutation+object_direction+spatial -view_cells_filter_max_size=1 \ 
    51  -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4e.xml \ 
    52  -preprocessor_stats=$PREFIX-i-mixed-b1-n4e.log \ 
    53  -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4e.hlog 
     51 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4g.xml \ 
     52 -preprocessor_stats=$PREFIX-i-mixed-b1-n4g.log \ 
     53 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4g.hlog 
     54 
     55 
     56# e - no origin mutation, silh. tm Q=2, reverse samples 
     57# f - no origin, q=2, no reverse samples 
     58# g - gaussian origin, q=2, reverse samples 
     59 
    5460 
    5561# $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
Note: See TracChangeset for help on using the changeset viewer.