Changeset 1933


Ignore:
Timestamp:
01/03/07 16:48:59 (17 years ago)
Author:
mattausch
Message:

worked on gvs reverse sampling (still in debug state)

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r1923 r1933  
    10231023 
    10241024                const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small)); 
    1025                 const float sum = noValidSplit ? 1e25 : objectsLeft * al + objectsRight * ar; 
     1025                const float sum = noValidSplit ? 1e25f : objectsLeft * al + objectsRight * ar; 
    10261026       
    10271027                /*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=("  
     
    13251325                // the heuristics 
    13261326            const float sum = noValidSplit ?  
    1327                         1e25 : volLeft * (float)nObjectsLeft + volRight * (float)nObjectsRight; 
     1327                        1e25f : volLeft * (float)nObjectsLeft + volRight * (float)nObjectsRight; 
    13281328 
    13291329#ifdef GTP_DEBUG 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1920 r1933  
    824824                                                 const bool onlyMailedRays) const; 
    825825 
    826         /** Counts the view cells of this object. note: only 
    827                 counts unmailed objects. 
    828         */ 
    829         int CountViewCells(Intersectable *obj) const; 
    830  
    831         /** Counts the view cells seen by this bvh leaf 
    832         */ 
    833         int CountViewCells(const ObjectContainer &objects) const; 
    834  
    835826        /** Collects view cells which see an object. 
     827                @param useMailBoxing if mailing should be used and 
     828                only unmailed object should pass 
     829                @param setCounter counter for the sweep algorithm 
     830                @param onlyMailedRays if only mailed rays should be considered 
    836831        */ 
    837832        int CollectViewCells(Intersectable *object,  
     
    840835                                                 const bool setCounter, 
    841836                                                 const bool onlyMailedRays) const; 
     837 
     838        /** Counts the view cells of this object. note: only 
     839                counts unmailed objects. 
     840        */ 
     841        int CountViewCells(Intersectable *obj) const; 
     842 
     843        /** Counts the view cells seen by this bvh leaf 
     844        */ 
     845        int CountViewCells(const ObjectContainer &objects) const; 
    842846 
    843847        /** Evaluates increase in pvs size. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r1932 r1933  
    6161         
    6262        // distance large => this is likely to be a discontinuity 
     63#if 1 
    6364        if ((predictedLen - len) > mThreshold) 
     65#else // rather use relative distance 
     66        if ((predictedLen / len) > mThreshold) 
     67#endif 
    6468        { 
    6569                cout << "d"; 
     70                // apply reverse sampling to find the gap 
    6671                VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 
    67                  
     72 
     73                if (!newRay) 
     74                        return false; 
     75 
    6876                // set flag for visualization 
    6977                newRay->mFlags |= VssRay::ReverseSample; 
     
    7179                // if ray is not further processed => can delete ray 
    7280                if (!HandleRay(newRay)) 
     81                { 
    7382                        delete newRay; 
    74                  
     83                } 
     84                else if (mVssRays.size() < 3) 
     85                { 
     86                        mVssRays.push_back(new VssRay(oldRay)); 
     87                        mVssRays.push_back(new VssRay(currentRay)); 
     88                        mVssRays.push_back(new VssRay(*newRay)); 
     89                } 
     90 
    7591                return true; 
    7692        } 
     
    84100        // compute the contribution to the view cells 
    85101        const bool storeRaysForViz = true; 
     102 
    86103        mViewCellsManager->ComputeSampleContribution(*vssRay,  
    87104                                                                                                 true,  
     
    317334 
    318335 
    319 Vector3 GvsPreprocessor::GetPassingPoint(const VssRay &currentRay, 
     336/*Vector3 GvsPreprocessor::GetPassingPoint(const VssRay &currentRay, 
    320337                                                                                 const Triangle3 &hitTriangle, 
    321338                                                                                 const VssRay &oldRay) const 
     
    333350 
    334351        return newPoint; 
     352}*/ 
     353 
     354 
     355Vector3 GvsPreprocessor::GetPassingPoint(const VssRay &currentRay, 
     356                                                                                 const Triangle3 &occluder, 
     357                                                                                 const VssRay &oldRay) const 
     358{ 
     359        //-- The plane p = (xp, hit(x), hit(xold)) is intersected 
     360        //-- with the newly found occluder (xold is the previous ray from 
     361        //-- which x was generated). On the intersecting line, we select a point 
     362        //-- pnew which lies just outside of the new triangle so the ray 
     363        //-- just passes through the gap 
     364 
     365        const Plane3 plane(currentRay.GetOrigin(),  
     366                                           currentRay.GetTermination(),  
     367                                           oldRay.GetTermination()); 
     368         
     369        Vector3 pt1, pt2; 
     370 
     371        const bool intersects = occluder.GetPlaneIntersection(plane, pt1, pt2); 
     372 
     373        cout << "triangle: " << occluder << " pt1: " << pt1 << " pt2: " << pt2 << endl; 
     374        if (!intersects) 
     375                cerr << "big error!! no intersection" << endl; 
     376 
     377        // get the intersection point on the old ray 
     378        const Plane3 triPlane(occluder.GetNormal(), occluder.mVertices[0]); 
     379 
     380        const float t = triPlane.FindT(oldRay.mOrigin, oldRay.mTermination); 
     381        const Vector3 pt3 = oldRay.mOrigin + t * (oldRay.mTermination - oldRay.mOrigin); 
     382 
     383        // Evaluate new hitpoint just outside the triangle 
     384        Vector3 newPoint; 
     385 
     386        const float eps = mEps; 
     387        // the point is chosen to be on the side closer to the original ray 
     388        if (Distance(pt1, pt3) < Distance(pt2, pt3)) 
     389        { 
     390                newPoint = pt1 + eps * (pt1 - pt2); 
     391        }        
     392        else 
     393        { 
     394                newPoint = pt2 + eps * (pt2 - pt1); 
     395        } 
     396 
     397        cout << "passing point: " << newPoint << endl << endl; 
     398        return newPoint; 
    335399} 
    336400 
     
    340404                                                                                 const VssRay &oldRay) 
    341405{ 
    342         //-- The plane p = (xp, hit(x), hit(xold)) is intersected 
    343         //-- with the newly found triangle (xold is the previous ray from 
    344         //-- which x was generated). On the intersecting line, we select a point 
    345         //-- pnew which lies just outside of the new triangle so the ray 
    346         //-- just passes by inside the gap 
    347     const Vector3 newPoint = GetPassingPoint(currentRay, hitTriangle, oldRay); 
     406        // get triangle occluding the path to the hit mesh 
     407        Triangle3 occluder; 
     408        Intersectable *tObj = currentRay.mTerminationObject; 
     409        // q: why can this happen? 
     410        if (!tObj) 
     411                return NULL; 
     412 
     413        // other types not implemented yet 
     414        if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 
     415                occluder = dynamic_cast<TriangleIntersectable *>(tObj)->GetItem(); 
     416        else 
     417                cout << "not yet implemented" << endl; 
     418         
     419        // get a point which is passing just outside of the occluder 
     420    const Vector3 newPoint = GetPassingPoint(currentRay, occluder, oldRay); 
    348421        const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 
    349422 
    350423        //-- Construct the mutated ray with xnew, 
    351424        //-- dir = predicted(x)- pnew as direction vector 
    352         const Vector3 newDir = predicted - newPoint ; 
    353  
    354         // take xnew,p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 
     425        const Vector3 newDir = predicted - newPoint; 
     426 
     427        // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 
    355428        // difficult to say!! 
    356         const Vector3 newOrigin = newDir * -5000.0f; 
    357  
    358         ++ mReverseSamples; 
    359  
    360         return new VssRay(currentRay); 
     429        const Vector3 newOrigin = newPoint + newDir * -5000.0f; 
     430 
     431        const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 
     432 
     433        VssRay *reverseRay =  
     434                mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox()); 
     435 
     436    ++ mReverseSamples; 
     437 
     438        return reverseRay; 
    361439} 
    362440 
     
    533611        } 
    534612 
    535         exporter->ExportRays(mVssRays); 
     613        VssRayContainer::const_iterator rit, rit_end = mVssRays.end(); 
     614        for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 
     615        { 
     616                Intersectable *obj = (*rit)->mTerminationObject; 
     617                exporter->ExportIntersectable(obj); 
     618        } 
     619 
     620        VssRayContainer vcRays, vcRays2, vcRays3; 
     621 
     622        // prepare some rays for output 
     623        for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 
     624        { 
     625                const float p = RandomValue(0.0f, (float)mVssRays.size()); 
     626                if (1)//(p < raysOut) 
     627                { 
     628                        if ((*rit)->mFlags & VssRay::BorderSample) 
     629                        { 
     630                                vcRays.push_back(*rit); 
     631                        } 
     632                        else if ((*rit)->mFlags & VssRay::ReverseSample) 
     633                        { 
     634                                vcRays2.push_back(*rit); 
     635                        } 
     636                        else 
     637                        { 
     638                                vcRays3.push_back(*rit); 
     639                        }        
     640                } 
     641        } 
     642 
     643        exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 
     644        exporter->ExportRays(vcRays2, RgbColor(0, 1, 0)); 
     645        exporter->ExportRays(vcRays3, RgbColor(1, 1, 1)); 
     646 
     647        //exporter->ExportRays(mVssRays); 
    536648        delete exporter; 
    537649} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1920 r1933  
    10691069                                                                                                   const ObjectContainer &objects) 
    10701070{        
    1071         SubdivisionCandidate *firstCandidate; 
    1072  
    10731071        // object space partition constructed => reconstruct 
    10741072        switch (mObjectSpaceSubdivisionType) 
     
    21462144                char str[100]; 
    21472145                char statsPrefix[100]; 
    2148                 int histoStepSize; 
     2146                //int histoStepSize; 
    21492147 
    21502148                Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix); 
     
    22132211                bool isLeaf; 
    22142212                int timeStamp; 
    2215                 float rcDecr;  
    2216                 int entriesIncr;  
     2213                //float rcDecr;  
     2214                //int entriesIncr;  
    22172215 
    22182216                if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp

    r1932 r1933  
    186186 
    187187 
    188 bool Triangle3::IntersectPlane(const Plane3 &plane,  
    189                                                           Vector3 &intersectA,  
    190                                                           Vector3 &intersectB) const 
     188bool Triangle3::GetPlaneIntersection(const Plane3 &plane,  
     189                                                                        Vector3 &intersectA,  
     190                                                                        Vector3 &intersectB) const 
    191191{ 
    192192        int side[3]; 
     
    215215                        intersectA = mVertices[i]; 
    216216                        intersectB = mVertices[(i + 1) % 3]; 
    217  
     217                         
    218218                        return true; 
    219219                } 
     
    228228 
    229229                // intersection found 
    230                 if ((side[i] >= 0) && (side[i_2] <= 0)) 
     230                if ((side[i] >= 0) && (side[i_2] <= 0) || 
     231                        (side[i] <= 0) && (side[i_2] >= 0)) 
    231232                {        
    232233                        const float t = plane.FindT(mVertices[i], mVertices[i_2]); 
     
    235236                        { 
    236237                                intersectA = mVertices[i] + t * (mVertices[i_2] - mVertices[i]); 
     238                         
    237239                                foundA = true; 
    238240                        } 
     
    240242                        { 
    241243                                intersectB = mVertices[i] + t * (mVertices[i_2] - mVertices[i]); 
     244                         
    242245                                return true; 
    243246                        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h

    r1932 r1933  
    4444                @returns true if triangle intersects plane 
    4545        */ 
    46         bool IntersectPlane(const Plane3 &plane, Vector3 &intersectA, Vector3 &intersectB) const; 
     46        bool GetPlaneIntersection(const Plane3 &plane,  
     47                                                          Vector3 &intersectA,  
     48                                                          Vector3 &intersectB) const; 
    4749 
    4850        /////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1926 r1933  
    343343        { 
    344344                cout << "executing main thread" << endl; 
    345  
    346345                // just call the mail method -> will be executed in the main thread 
    347346                pt->Main(); 
Note: See TracChangeset for help on using the changeset viewer.