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

worked on gvs reverse sampling (still in debug state)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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} 
Note: See TracChangeset for help on using the changeset viewer.