Changeset 1420


Ignore:
Timestamp:
09/20/06 13:37:29 (18 years ago)
Author:
mattausch
Message:

corrected raycasting bug for triangles because of ill defined triangles

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

Legend:

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

    r1419 r1420  
    152152        } 
    153153 
     154        // reset to filled 
    154155        SetFilled(); 
    155156 
     
    266267                { 
    267268                case Intersectable::TRIANGLE_INTERSECTABLE: 
    268                         { 
     269                        {cout << "y"; 
    269270                                TriangleIntersectable *ti = dynamic_cast<TriangleIntersectable *>(obj); 
    270271                                polys.push_back(new Polygon3(ti->GetItem())); 
     
    272273                        } 
    273274                case Intersectable::MESH_INSTANCE: 
    274                         { 
     275                        {cout << "x"; 
    275276                                MeshInstance *mi = dynamic_cast<MeshInstance *>(obj); 
    276277                                ExportMesh(mi->GetMesh()); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1418 r1420  
    283283        cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    284284 
    285         cout << "here5 " << GetViewSpaceBox() << endl; 
    286         cout << "here6 " << GetObjectSpaceBox() << endl; 
     285#if _DEBUG 
     286        cout << "view space: " << GetViewSpaceBox() << endl; 
     287        cout << "object space:  " << GetObjectSpaceBox() << endl; 
     288#endif 
     289 
    287290        mHierarchyStats.Stop(); 
    288291        mVspTree->mVspStats.Stop(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1419 r1420  
    521521 
    522522 
     523static void PrintFace(const Mesh *mesh, const int idx, ostream &app) 
     524{ 
     525        Face *face = mesh->mFaces[idx]; 
     526 
     527        VertexIndexContainer::iterator it, it_end = face->mVertexIndices.end(); 
     528 
     529        cout << "face " << idx << endl; 
     530        for (it = face->mVertexIndices.begin(); it != it_end; ++ it) 
     531        { 
     532                cout << (*it) << ": " << mesh->mVertices[*it] << " "; 
     533        } 
     534        cout << endl; 
     535} 
     536 
     537 
    523538void Mesh::Print(ostream &app) const 
    524539{ 
     
    531546        app << endl; 
    532547 
    533         /*FaceContainer::const_iterator fit, fit_end = mVertices.end(); 
    534  
    535         for (vit = mVertices.begin(); vit != vit_end; ++ vit) 
     548        for (int i = 0; i < (int)mFaces.size(); ++ i) 
    536549        { 
    537                 app << (*vit); 
    538         } 
    539         app << endl;*/ 
     550                PrintFace(this, i, app); 
     551        } 
    540552} 
    541553 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp

    r1419 r1420  
    4343{        
    4444        mVertices.reserve(face->mVertexIndices.size()); 
    45          
    4645        VertexIndexContainer::iterator it, it_end = face->mVertexIndices.end(); 
    4746 
    48         for (it = face->mVertexIndices.begin(); it != it_end;  ++ it) 
     47        for (it = face->mVertexIndices.begin(); it != it_end; ++ it) 
    4948        { 
    5049                mVertices.push_back(parentMesh->mVertices[*it]); 
     
    6968        VertexContainer::iterator it, it_end = mVertices.end(); 
    7069 
    71         for (it = mVertices.begin(); it != it_end;  ++ it) 
    72         { 
    73                 cout << (*it) << " "; 
    74         }cout<<endl<<endl; 
     70        //for (it = mVertices.begin(); it != it_end;  ++ it){cout << (*it) << " ";}cout<<endl<<endl; 
    7571        //cout << "poly n: " << GetNormal() << " t normal: " << tri.GetNormal() << endl; 
    7672} 
     
    267263} 
    268264 
     265 
    269266bool Polygon3::Valid(const float epsilon) const 
    270267{ 
     
    272269                return false; 
    273270 
    274         //TODO: remove for performance 
    275 #if 0 
    276         if (1) 
     271        // matt: removed for performance issues 
     272#if _DEBUG 
     273        if (0) 
    277274        { 
    278275                // check if area exceeds certain size 
     
    291288                for (it = mVertices.begin(); it != it_end; ++it) 
    292289                { 
    293                         if (EpsilonEqualV3(vtx, *it, 0.0001)) 
     290                        if (EpsilonEqualV3(vtx, *it, epsilon)) 
    294291                        { 
    295                                 //Debug << "Malformed vertices:\n" << *this << endl; 
     292                                //cout << "Malformed vertices:\n" << *this << endl; 
    296293                                return false; 
    297294                        } 
     
    590587        const int n = (int)mesh.mVertices.size(); 
    591588 
     589 
    592590        ///////////// 
    593591    //-- add the vertices to the mesh 
     
    609607        poly.Triangulate(indices); 
    610608 
     609        //if (indices.size() < 3) return; // something is wrong 
     610         
    611611        // add indices of triangle strip 
    612         for (int i = n; i < (int)indices.size() + n; i += 3) 
    613         { 
    614                 Face *face = new Face(indices[i],  
    615                                                           indices[i + 1],  
    616                                                           indices[i + 2]); 
     612        for (int i = 0; i < (int)indices.size(); i += 3) 
     613        { 
     614                Face *face = new Face(indices[i] + n,  
     615                                                          indices[i + 1] + n,  
     616                                                          indices[i + 2] + n); 
    617617                mesh.AddFace(face); 
    618618        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h

    r1404 r1420  
    174174        //s << setprecision(6) << "Polygon:\n"; 
    175175        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it) 
    176                 s << *it << endl; 
     176                s << *it << " "; 
    177177         
    178178        return s; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp

    r1344 r1420  
    3131int Triangle3::CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const 
    3232{ 
    33         /*VertexContainer vertices; 
     33#if 0 
     34        VertexContainer vertices; 
    3435        vertices.push_back(mVertices[0]); 
    3536        vertices.push_back(mVertices[1]); 
     
    4041        int dummy = poly.CastRay(ray, t, nearestT); 
    4142 
    42          cout << "polyversion code: " << dummy << " t: " << t << " nearestT: " << nearestT << endl; 
    43 return dummy;*/ 
    44         ///////////////////////////////////////////// 
    45         // specialised ray casting version 
     43        cout << "polyversion code: " << dummy << " t: " << t << " nearestT: " << nearestT << endl; 
     44        return dummy; 
     45#endif 
     46         
     47        ////////////// 
     48        // specialised triangle ray casting version 
    4649 
     50        /////////// 
    4751        //-- calc ray-plane intersection 
    4852         
     
    5155    const Vector3 v = mVertices[2] - mVertices[1]; 
    5256 
    53     normal = Normalize(CrossProd(v, u)); // cross product 
     57        // cross product 
     58    normal = Normalize(CrossProd(v, u)); 
    5459 
    55     const Vector3 dir = ray.GetDir(); // ray direction vector 
     60        // ray direction vector 
     61    const Vector3 dir = ray.GetDir(); 
    5662    const Vector3 w0 = ray.GetLoc() - mVertices[1]; 
    5763 
     
    6470        {    
    6571                // ray is parallel to triangle plane 
    66         if (a == 0) // ray lies in triangle plane 
     72        if (a == 0) 
    6773                { 
     74                        // ray lies in triangle plane 
    6875            return Ray::INTERSECTION_OUT_OF_LIMITS; 
    6976                } 
    7077        else 
    7178                { 
    72                         return Ray::NO_INTERSECTION; // ray disjoint from plane 
     79                        // ray disjoint from plane 
     80                        return Ray::NO_INTERSECTION; 
    7381                } 
    7482    } 
     
    8795        } 
    8896 
    89         /////////////////////////////////////////////// 
     97        ///////////////// 
    9098    //-- found intersection point 
    9199        //-- check if it is inside triangle 
    92100   
    93101        const Vector3 pt = ray.GetLoc() + t * dir;  
     102 
     103        if (!pt.CheckValidity()) 
     104        { 
     105                cout << "tr: " << *this << endl; 
     106                cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl; 
     107        } 
    94108 
    95109        const Vector3 w = pt - mVertices[1]; 
     
    157171 
    158172 
     173bool Triangle3::CheckValidity() const 
     174{ 
     175        return !( 
     176                EpsilonEqualV3(mVertices[0], mVertices[1]) || 
     177                EpsilonEqualV3(mVertices[0], mVertices[2]) || 
     178                EpsilonEqualV3(mVertices[1], mVertices[2]) 
     179                ); 
    159180} 
     181 
     182} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h

    r1344 r1420  
    3535         friend istream& operator>> (istream &s, Triangle3 &A); 
    3636 
     37         /** Checks if this triangle is ill-defined. 
     38         */ 
     39         bool CheckValidity() const; 
    3740 
    3841         ////////////////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.cpp

    r863 r1420  
    22#include "Vector3.h" 
    33#include "Halton.h" 
     4#include "float.h" 
     5 
    46 
    57namespace GtpVisibilityPreprocessor { 
     
    253255} 
    254256 
    255 } 
     257 
     258bool Vector3::CheckValidity() const 
     259{ 
     260        return !(_isnan(x) || _isnan(y) || _isnan(z)); 
     261         //return ((x != x) || (y != y) || (z != z)); 
     262} 
     263 
     264} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h

    r1328 r1420  
    9898  inline void Normalize(); 
    9999   
     100  /** Returns false if this vector has a nan component. 
     101  */ 
     102  bool CheckValidity() const; 
     103 
    100104  /** 
    101105    ===> Using ArbitraryNormal() for constructing coord systems  
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1419 r1420  
    50975097                        exporter->ExportBox(bbox); 
    50985098                        exporter->SetFilled();  
    5099  
    51005099                                 
    51015100                        if (0 && mExportGeometry) 
     
    51125111                        mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, &bbox, false); 
    51135112                        ExportViewCellsForViz(exporter, &bbox, GetClipPlane()); 
     5113 
    51145114                        delete exporter; 
    51155115                        cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp

    r1419 r1420  
    125125          const Vector3 a = (*ri)->GetOrigin(); 
    126126          const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir()); 
    127            
     127 
     128#if _DEBUG 
    128129          bool isnan = false; 
    129  
    130           if ((a[0] != a[0]) || (a[1] != a[1]) || (a[2] != a[2])) 
     130          if (!a.CheckValidity()) 
    131131          { 
    132132                  cout << "error a"<<endl; 
     
    134134          } 
    135135 
    136           if ((b[0] != b[0]) || (b[1] != b[1]) || (b[2] != b[2])) 
     136           if (!b.CheckValidity()) 
    137137          { 
    138138                  cout << "error b"<<endl; 
    139139                  isnan = true; 
    140140          } 
    141  
    142           if (!isnan) 
    143           { 
    144                 stream << a.x << " " << a.y << " " << a.z << " ,"; 
    145                 stream << b.x << " " << b.y << " " << b.z << " ,\n"; 
    146           } 
     141          if (isnan) 
     142                  continue; 
     143#endif 
     144          stream << a.x << " " << a.y << " " << a.z << " ,"; 
     145          stream << b.x << " " << b.y << " " << b.z << " ,\n"; 
    147146  } 
    148147 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r1419 r1420  
    231231        if (!mLoadMeshes) 
    232232        { 
    233                 //////////////////////////////////// 
     233                /////////////////// 
    234234                //-- load data as single triangles instead of whole meshes 
    235235 
     
    249249                        Polygon3 poly(face, &tempMesh); 
    250250                        poly.Triangulate(triangles); 
    251  
     251                         
    252252                        vector<Triangle3>::const_iterator tit, tit_end = triangles.end(); 
    253253 
    254254                        for (tit = triangles.begin(); tit != tit_end; ++ tit) 
    255255                        { 
    256                                 TriangleIntersectable *ti = new TriangleIntersectable(*tit); 
    257                                 cout << "t: " << (*tit) << endl; 
    258                                 mCurrentNode->mGeometry.push_back(ti); 
     256                                if ((*tit).CheckValidity()) 
     257                                { 
     258                                        TriangleIntersectable *ti = new TriangleIntersectable(*tit); 
     259                                        //cout << "t: " << (*tit) << endl; 
     260                                        mCurrentNode->mGeometry.push_back(ti); 
     261                                } 
     262                                else 
     263                                { 
     264                                        cout << "error tri:\n" << (*tit) << endl; 
     265                                } 
    259266                        } 
    260267#if 0 
     
    262269                        Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
    263270 
    264                         VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end(); 
    265  
    266                         int i = 0; 
     271                                 
    267272                        // dummy vertex indices container 
    268273                        VertexIndexContainer vcIndices; 
     274                        VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end(); 
     275                        int i = 0; 
    269276 
    270277                        for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i) 
Note: See TracChangeset for help on using the changeset viewer.