Changeset 299 for trunk/VUT


Ignore:
Timestamp:
09/28/05 18:11:32 (19 years ago)
Author:
mattausch
Message:

added polygon area (debugged)

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r298 r299  
    88#define SIDE_TOLERANCE 0.002f // TODO: Test different values 
    99#define SIDE_TOLERANCE_SQRD 0.000004f 
     10#define AREA_LIMIT 0.0001f 
    1011 
    1112Polygon3::Polygon3(): mMaterial(NULL), mParent(NULL) 
     
    108109float Polygon3::GetArea() const 
    109110{ 
    110         float area = 0.0f; 
    111  
    112         VertexContainer vertXY; 
     111        VertexContainer vtx; 
    113112 
    114113        //-- rotate polygon to lie in xy plane 
     
    121120        VertexContainer::const_iterator it, it_end = mVertices.end(); 
    122121 
    123         Debug << "old: "; 
    124122        for (it = mVertices.begin(); it != it_end; ++it) 
    125         { 
    126                 vertXY.push_back(rot * (*it)); 
    127                 Debug << (*it).z << " "; 
    128         } 
    129         Debug << endl << "new: "; 
    130         for (it = vertXY.begin(); it != vertXY.end(); ++it) 
    131                 Debug << (*it).z << " "; 
    132         Debug << endl << endl; 
    133  
    134         return area; 
     123                vtx.push_back(rot * (*it)); 
     124         
     125        Vector3 *cur = &vtx.back(); 
     126 
     127        float area = 0.0f; 
     128        for (it = vtx.begin(); it != vtx.end(); ++it) 
     129        { 
     130                area += cur->y * (*it).x - cur->x * (*it).y; 
     131 
     132                *cur = (*it); 
     133        } 
     134 
     135        return area * 0.5f; 
    135136} 
    136137 
     
    210211} 
    211212 
    212 bool Polygon3::CheckValid() const 
     213bool Polygon3::Valid() const 
    213214{ 
    214215        if (mVertices.size() < 3) 
    215216                return false; 
    216217 
     218#if 1 
     219        // check if area exceeds certain size 
     220        if (AREA_LIMIT > GetArea()) 
     221                return false; 
     222#else 
    217223        Vector3 vtx = mVertices.back(); 
    218224        VertexContainer::const_iterator it, it_end = mVertices.end(); 
     
    227233                vtx = *it; 
    228234        } 
    229          
     235#endif   
    230236        return true; 
    231237} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r298 r299  
    6767                @returns true if polygon is valid. 
    6868        */ 
    69         bool CheckValid() const;  
     69        bool Valid() const;  
    7070 
    7171        /** Includes polygons to axis aligned box. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r298 r299  
    193193 
    194194                                // check if polygons still valid  
    195                                 if (front_piece->mVertices.size() >= 3) 
     195                                if (front_piece->Valid()) 
    196196                                        frontPolys->push_back(front_piece); 
    197197                                else 
    198198                                        DEL_PTR(front_piece); 
    199199                                 
    200                                 if (back_piece->mVertices.size() >= 3) 
     200                                if (back_piece->Valid()) 
    201201                                        backPolys->push_back(back_piece); 
    202202                                else                             
     
    456456                polys.push_back(poly); 
    457457 
    458                 if (!poly->CheckValid()) 
     458                if (!poly->Valid()) 
    459459                        Debug << "Input polygon not valid: " << *poly << endl; 
    460460 
     
    829829 
    830830                        if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 
     831                        { 
     832                                Debug << "polygon area: " << (*it)->GetArea() << " "; 
    831833                                sumPolyArea += (*it)->GetArea(); 
    832                 } 
     834                        } 
     835                }Debug << "\n"; 
    833836        } 
    834837         
Note: See TracChangeset for help on using the changeset viewer.