Changeset 349


Ignore:
Timestamp:
10/26/05 19:18:30 (19 years ago)
Author:
mattausch
Message:

updated ray based subdivision

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r344 r349  
    88#       filename glasgow1.x3d 
    99#       filename vienna.x3d 
    10         filename ../data/vienna/vienna-simple.x3d 
     10#       filename ../data/vienna/vienna-simple.x3d 
    1111#       filename ../data/vienna/vienna-buildings.x3d 
    1212#       filename ../data/vienna/viewcells-25-sel.x3d 
    13 #       filename ../data/atlanta/atlanta2.x3d 
     13        filename ../data/atlanta/atlanta2.x3d 
    1414#       filename ../data/soda/soda.dat 
    1515#       filename ../data/soda/soda5.dat 
     
    5656 
    5757Sampling { 
    58         totalSamples    100 
    59         samplesPerPass  20 
     58        totalSamples    200000 
     59        samplesPerPass  2 
    6060} 
    6161 
     
    7676BspTree { 
    7777        Construction { 
    78         #       input fromRays 
    79                 input fromViewCells 
     78                input fromRays 
     79        #       input fromViewCells 
    8080        #       input fromSceneGeometry 
    81                 samples 200000 
     81                samples 150000 
    8282                sideTolerance 0.005 
    8383        } 
     
    113113        #splitPlaneStrategy 130 
    114114         
    115         splitPlaneStrategy 66 
     115        #splitPlaneStrategy 384 
     116        splitPlaneStrategy 130 
    116117         
    117         maxCandidates 50 
     118        maxCandidates 80 
    118119         
    119120        Termination { 
    120121                # autopartition 
    121                 maxRays -1 
     122                maxRays 10 
    122123                maxPolygons 0 
    123124                maxDepth 100 
    124125                 
    125126                #axis aligned split 
    126                 maxPolysForAxisAligned 100 
     127                maxPolysForAxisAligned 200 
    127128                maxCostRatio 0.9 
    128129                ct_div_ci 0.5 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r313 r349  
    5353             ) = 0; 
    5454   
     55  virtual bool 
     56  ExportRays(const RayContainer &rays, 
     57             const float length=1000, 
     58             const RgbColor &color = RgbColor(1,1,1) 
     59             ) = 0; 
    5560 
    5661  virtual void  
  • trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h

    r340 r349  
    4141  virtual int Type() const = 0; 
    4242 
    43   virtual void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 
     43  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 
    4444 
    4545        virtual ostream &Describe(ostream &s) = 0; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp

    r340 r349  
    266266} 
    267267 
    268  
    269 void 
     268int 
    270269Mesh::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 
    271270{ 
     
    285284         
    286285        normal = GetFacePlane(faceIndex).mNormal; 
    287 } 
    288  
     286 
     287        return faceIndex; 
     288} 
    289289 
    290290int 
     
    308308 
    309309 
    310 void 
     310int 
    311311MeshInstance::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 
    312312{ 
    313   mMesh->GetRandomSurfacePoint(point, normal); 
    314 } 
    315  
    316 void 
     313  return mMesh->GetRandomSurfacePoint(point, normal); 
     314} 
     315 
     316int 
    317317TransformedMeshInstance::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 
    318318{ 
    319   mMesh->GetRandomSurfacePoint(point, normal); 
     319  int index = mMesh->GetRandomSurfacePoint(point, normal); 
    320320  point = mWorldTransform*point; 
    321321  normal = TransformNormal(mWorldTransform, normal); 
     322  return index; 
    322323} 
    323324 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h

    r340 r349  
    143143  AxisAlignedBox3 GetFaceBox(const int faceIndex); 
    144144 
    145   void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
     145  int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    146146 
    147147        virtual ostream &Describe(ostream &s) { 
     
    160160  } 
    161161 
    162   void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
     162  int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    163163 
    164164 
     
    215215  virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; } 
    216216 
    217   void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
     217  int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    218218 
    219219private: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h

    r327 r349  
    3030  } 
    3131 
    32   // relation of objects with the plane 
    33   enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; 
    3432 
    3533  float Distance(const Vector3 &v) const { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r344 r349  
    66#include "Ray.h" 
    77 
    8 float Polygon3::sSideTolerance = 0.002f; 
    9 float Polygon3::sSideToleranceSqrt = 0.000004f; 
    10  
    118Polygon3::Polygon3():  
    12 mMaterial(NULL), mParent(NULL), mPiercingRays(NULL) 
     9mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
    1310{} 
    1411 
    1512Polygon3::Polygon3(const VertexContainer &vertices):  
    16 mVertices(vertices), mMaterial(NULL), mParent(NULL), mPiercingRays(NULL) 
     13mVertices(vertices), mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
    1714{} 
    1815 
    1916Polygon3::Polygon3(MeshInstance *parent):  
    20 mMaterial(NULL), mParent(parent), mPiercingRays(NULL) 
     17mMaterial(NULL), mParent(parent), mPiercingRays(0) 
    2118{} 
    2219 
    2320Polygon3::Polygon3(Face *face, Mesh *parentMesh): 
    24 mMaterial(NULL), mParent(NULL), mPiercingRays(NULL) 
     21mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
    2522{        
    2623        VertexIndexContainer::iterator it = face->mVertexIndices.begin(); 
     
    3027                mMaterial = parentMesh->mMaterial; 
    3128        } 
    32 } 
    33  
    34 Polygon3::~Polygon3() 
    35 { 
    36         DEL_PTR(mPiercingRays); 
    3729} 
    3830 
     
    5547        Vector3 ptA = mVertices.back(); 
    5648         
    57         int sideA = partition.Side(ptA, sSideTolerance); 
     49        int sideA = partition.Side(ptA, Vector3::sDistTolerance); 
    5850         
    5951        VertexContainer::const_iterator it; 
     
    6456        { 
    6557                Vector3 ptB = *it; 
    66                 int sideB = partition.Side(ptB, sSideTolerance); 
     58                int sideB = partition.Side(ptB, Vector3::sDistTolerance); 
    6759         
    6860                // vertices on different sides => split 
     
    7668                                // test if split point not too close to previous split point 
    7769                                if (!foundSplit ||  
    78                                         (SqrDistance(splitPt, splitPts.back()) > sSideToleranceSqrt)) 
     70                                        (SqrDistance(splitPt, splitPts.back()) > Vector3::sDistToleranceSqrt)) 
    7971                                { 
    8072                                        // add vertex to both polygons 
     
    9789                                        // test if split point not too close to previous split point 
    9890                                if (!foundSplit ||  
    99                                         (SqrDistance(splitPt, splitPts.back()) > sSideToleranceSqrt)) 
     91                                        (SqrDistance(splitPt, splitPts.back()) > Vector3::sDistToleranceSqrt)) 
    10092                                { 
    10193                                        // add vertex to both polygons 
     
    136128        int classification = ClassifyPlane(plane); 
    137129         
    138         if (classification == Plane3::BACK_SIDE) 
     130        if (classification == BACK_SIDE) 
    139131                return -1; 
    140         else if (classification == Plane3::FRONT_SIDE) 
     132        else if (classification == FRONT_SIDE) 
    141133                return 1; 
    142134 
     
    155147        for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
    156148        { 
    157                 int side = plane.Side(*it, sSideTolerance); 
     149                int side = plane.Side(*it, Vector3::sDistTolerance); 
    158150                 
    159151                if (side > 0) 
     
    165157                if (onFrontSide && onBackSide) // split  
    166158                { 
    167                         return Plane3::SPLIT; 
     159                        return SPLIT; 
    168160                } 
    169161                // 3 vertices enough to decide coincident 
    170162                else if (((++ count) >= 3) && !onFrontSide && !onBackSide) 
    171                 {   //if (DotProd(plane.mNormal, GetNormal()) > 0) 
    172                         return Plane3::COINCIDENT;  
     163                {    
     164                        return COINCIDENT;  
    173165                } 
    174166        } 
     
    176168        if (onBackSide) 
    177169        { 
    178                 return Plane3::BACK_SIDE; 
     170                return BACK_SIDE; 
    179171        } 
    180172        else if (onFrontSide) 
    181173        { 
    182                 return Plane3::FRONT_SIDE; 
    183         } 
    184         //if (DotProd(plane.mNormal, GetNormal()) < 0) return Plane3::FRONT_SIDE; 
    185         return Plane3::COINCIDENT; // plane and polygon are coincident 
     174                return FRONT_SIDE; 
     175        } 
     176         
     177        return COINCIDENT; // plane and polygon are coincident 
    186178} 
    187179 
     
    227219        for (it = mVertices.begin(); it != it_end; ++it) 
    228220        { 
    229                 if (!(SqrDistance(vtx, *it) > SIDE_TOLERANCE_SQRD)) 
     221                if (!(SqrDistance(vtx, *it) > sDistToleranceSqrt)) 
    230222                { 
    231223                        Debug << "Malformed vertices:\n" << *this << endl; 
     
    356348} 
    357349 
    358 RayContainer *Polygon3::GetPiercingRays() 
    359 { 
    360         if (!mPiercingRays) 
    361                 mPiercingRays = new RayContainer(); 
    362         return mPiercingRays; 
    363 } 
    364  
    365 void Polygon3::AddPiercingRay(Ray *ray) 
    366 { 
    367         GetPiercingRays()->push_back(ray); 
    368 } 
     350void Polygon3::InheritRays(Polygon3 &front_piece,  
     351                                               Polygon3 &back_piece) const 
     352{ 
     353        RayContainer::const_iterator it,  
     354                it_end = mPiercingRays.end(); 
     355 
     356        for (it = mPiercingRays.begin(); it != it_end; ++ it) 
     357        { 
     358                switch((*it)->GetId()) 
     359                { 
     360                case Ray::BACK: 
     361                        back_piece.mPiercingRays.push_back(*it); 
     362                        break; 
     363                case Ray::FRONT: 
     364                        front_piece.mPiercingRays.push_back(*it); 
     365                        break; 
     366                case Ray::FRONT_BACK: 
     367                        back_piece.mPiercingRays.push_back(*it); 
     368                        break; 
     369                case Ray::BACK_FRONT: 
     370                        front_piece.mPiercingRays.push_back(*it); 
     371                        break; 
     372                default: 
     373                        break; 
     374                } 
     375        } 
     376} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r333 r349  
    2323{ 
    2424public: 
     25        enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; 
     26 
     27        /** Default constructor creating an empty polygon. 
     28        */ 
    2529        Polygon3(); 
    26  
     30        /** Constructor creating a polygon from the vertices. 
     31        */ 
    2732        Polygon3(const VertexContainer &vertices); 
     33        /** Creates a polygon and stores pointer to parent mesh 
     34                instance. 
     35        */ 
    2836        Polygon3(MeshInstance *parent); 
    29  
    30         ~Polygon3(); 
    3137 
    3238        // creates an "infinite" polygon from this plane 
     
    8995        int CastRay(const Ray &ray, float &t, const float nearestT); 
    9096 
    91         /** Returns piercing rays container. 
    92         */ 
    93         RayContainer *GetPiercingRays(); 
    94  
    95         /** Adds a ray to the ray container. 
    96         */ 
    97         void AddPiercingRay(Ray *ray); 
    98  
    9997        /// vertices are connected in counterclockwise order. 
    10098        VertexContainer mVertices; 
     
    107105 
    108106        /// Rays piercing this polygon 
    109         RayContainer *mPiercingRays; 
     107        RayContainer mPiercingRays; 
    110108 
    111         static float sSideTolerance; 
    112         static float sSideToleranceSqrt; 
     109        /** The piercing rays of the polygon are inherited by the child fragments 
     110                @parm front_piece the front fragment inheriting the front rays 
     111                @param back_piece the back fragment inheriting the back rays 
     112        */ 
     113        void InheritRays(Polygon3 &front_piece,  
     114                                         Polygon3 &back_piece) const; 
    113115}; 
    114116 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp

    r328 r349  
    158158} 
    159159 
    160 int Ray::ClassifyPlane(const Plane3 &plane, float minT, float maxT) 
     160int Ray::ClassifyPlane(const Plane3 &plane,  
     161                                           const float minT,  
     162                                           const float maxT) const 
    161163{ 
    162         Vector3 entp = Extrap(minT); 
    163         Vector3 extp = Extrap(maxT); 
     164        const Vector3 entp = Extrap(minT); 
     165        const Vector3 extp = Extrap(maxT); 
    164166   
    165         int entSide = plane.Side(entp); 
    166         int extSide = plane.Side(extp); 
     167        const int entSide = plane.Side(entp); 
     168        const int extSide = plane.Side(extp); 
    167169 
    168170        if ((entSide == 0) && (extSide == 0))  
    169         { 
    170                 return Plane3::COINCIDENT; 
     171        { 
     172                return COINCIDENT; 
    171173        } 
    172         else if ((entSide <= 0) && (entSide <= 0)) 
     174        else if ((entSide <= 0) && (extSide <= 0)) 
    173175        { 
    174                 return Plane3::BACK_SIDE; 
     176                return BACK; 
    175177        } 
    176         else if ((entSide >= 0) && (entSide >= 0)) 
     178        else if ((entSide >= 0) && (extSide >= 0)) 
    177179        { 
    178                 return Plane3::FRONT_SIDE; 
     180                return FRONT; 
    179181        } 
     182        else if ((entSide <= 0) && (extSide >= 0)) 
     183                return BACK_FRONT; 
    180184         
    181         return Plane3::SPLIT; 
     185        return FRONT_BACK; 
    182186} 
    183187 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r340 r349  
    2424 
    2525  enum { NO_INTERSECTION=0, INTERSECTION_OUT_OF_LIMITS, INTERSECTION }; 
     26 
     27  /// if ray is on back (front) side of plane, or goes from the front (back) to the back (front) 
     28  enum {FRONT, BACK, BACK_FRONT, FRONT_BACK, COINCIDENT}; 
    2629 
    2730  struct Intersection { 
     
    190193  /** Classifies ray with respect to the plane. 
    191194  */ 
    192   int ClassifyPlane(const Plane3 &plane, float minT, float maxT); 
     195  int ClassifyPlane(const Plane3 &plane, const float minT, const float maxT) const; 
    193196 
    194197private: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r344 r349  
    5555        DEL_PTR(mBspTree); 
    5656        mBspTree = new BspTree(&mUnbounded); 
    57  
    5857        ObjectContainer objects; 
    59         int prunedCells = 0; 
     58         
    6059        switch (BspTree::sConstructionMethod) 
    6160        { 
     
    7675                mBspTree->SetGenerateViewCells(true); 
    7776                mBspTree->Construct(mSampleRays); 
    78 //              prunedCells = mBspTree->MergeViewCells(); 
    7977                 
    8078                mBspTree->CollectViewCells(mViewCells); 
    81  
    82 //              Debug << "Collected " << (int)mViewCells.size() << " cells (" << prunedCells << " pruned)" << endl; 
    8379                break; 
    8480        default: 
     
    169165 
    170166        if (mViewCellsType == BSP_VIEW_CELLS) 
     167        { 
     168                // cast ray to BSP tree to get intersection with view cells 
     169                if (mBspTree) 
    171170                { 
    172                         // cast ray to BSP tree to get intersection with view cells 
    173                         if (mBspTree) 
    174                                 { 
    175                                         mBspTree->CastRay(ray); 
     171                        mBspTree->CastRay(ray); 
    176172                                         
    177                                         sampleContributions += AddObjectSamples(object, ray); 
     173                        sampleContributions += AddObjectSamples(object, ray); 
    178174                                 
    179                                         if (!ray.intersections.empty()) // second intersection found 
    180                                                 { 
    181                                                         sampleContributions +=  
    182                                                                 AddObjectSamples(ray.intersections[0].mObject, ray); 
    183                                                 } 
    184                                 } 
     175                        if (!ray.intersections.empty()) // second intersection found 
     176                        { 
     177                                sampleContributions +=  
     178                                        AddObjectSamples(ray.intersections[0].mObject, ray); 
     179                        } 
    185180                } 
     181        } 
    186182        else 
    187183                { 
     
    319315                int maxTimeIdx = 0; 
    320316 
     317                bool collectSamplesForBsp =  
     318                        (mViewCellsType == BSP_VIEW_CELLS) && 
     319                        (BspTree::sConstructionMethod == BspTree::FROM_RAYS) && 
     320                        (totalSamples < mBspConstructionSamples); 
     321                         
    321322                cout << "totalSamples: "  << totalSamples << endl; 
    322323 
     
    382383                        } 
    383384                         
    384                         object->GetRandomSurfacePoint(point, normal); 
     385                        int faceIndex = object->GetRandomSurfacePoint(point, normal); 
    385386                         
    386387                        long samplesPerObjStart = GetTime(); 
     
    418419                                         
    419420                                        // construct a ray 
    420                                         SetupRay(ray, point, direction, Ray::LOCAL_RAY); 
    421                                          
     421                                        SetupRay(ray, point, direction,  
     422                                                collectSamplesForBsp ? Ray::LINE_SEGMENT : Ray::LOCAL_RAY); 
     423                         
     424                                        // also add origin to sample in order to extract it as input polygons 
     425                                        if (0 && collectSamplesForBsp) 
     426                                        { 
     427                                                MeshInstance *meshInst = dynamic_cast<MeshInstance *>(object); 
     428                                                ray.intersections.push_back(Ray::Intersection(0.0, meshInst, faceIndex)); 
     429                                        } 
     430 
    422431                                        sampleContributions = CastRay(object, ray); 
    423432 
     
    443452                                        if (mViewCellsType == BSP_VIEW_CELLS)  
    444453                                        { 
    445                         // save rays for bsp tree construction 
    446                                                 if ((BspTree::sConstructionMethod = BspTree::FROM_RAYS) && 
    447                                                         (totalSamples < mBspConstructionSamples)) 
     454                                                // save rays for bsp tree construction 
     455                                                if (collectSamplesForBsp) 
    448456                                                { 
    449                                                         mSampleRays.push_back(new Ray(ray)); 
     457                            mSampleRays.push_back(new Ray(ray)); 
    450458                                                } 
    451459                                                else 
    452460                                                { 
    453                             // construct BSP tree using the samples 
     461                                                        // construct BSP tree using the samples 
    454462                                                        if (!mBspTree) 
    455463                                                        { 
     
    463471                                                                Export("vc_bsptree.x3d", false, false, true); 
    464472                                                        } 
    465                                                                                                          
     473                                                                 
    466474                                                        // some random view cells for output 
    467475                                                        if (pvsViewCells.empty()) 
     
    477485                                                        } 
    478486                                                        else 
    479                                                         { 
     487                                                        {        
    480488                                                                // check whether we can add the current ray to the rays 
    481489                                                                for (int k = 0; k < (int)ray.viewCells.size(); ++ k) 
     
    484492                                                                                        vcRays[j].push_back(ray);                                                        
    485493                                                        } 
    486                                                 }                                
     494                                                } 
    487495                                        } 
    488496                 
     
    549557                        "#AvgRayContrib\n" << avgRayContrib << endl; 
    550558        } 
    551  
     559         
    552560        if (mViewCellsType == KD_VIEW_CELLS)     
    553561                cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
     
    559567    exporter->ExportKdTree(*mKdTree); 
    560568 
    561         if (mViewCellsType == BSP_VIEW_CELLS)    
     569        if (mBspTree && (mViewCellsType == BSP_VIEW_CELLS)) 
    562570                exporter->ExportBspTree(*mBspTree); 
    563571 
     
    579587    delete exporter; 
    580588  } 
     589 
    581590  //-- several visualizations and statistics 
    582591  if (1) { 
    583   if (mViewCellsType == BSP_VIEW_CELLS) 
     592  if (mBspTree && (mViewCellsType == BSP_VIEW_CELLS)) 
    584593  { 
    585594          bool exportSplits = false; 
     
    588597          // export the bsp splits 
    589598          if (exportSplits) 
    590           { 
    591                   Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
    592  
    593                   if (exporter)  
    594                   {      
    595                           Material m;  
    596                           m.mDiffuseColor = RgbColor(1, 0, 0); 
    597                           exporter->SetForcedMaterial(m); 
    598                           exporter->SetWireframe(); 
    599                           exporter->ExportBspSplits(*mBspTree); 
    600  
    601                           // take forced material, else big scenes cannot be viewed 
    602                           m.mDiffuseColor = RgbColor(0, 1, 0); 
    603                           exporter->SetForcedMaterial(m); 
    604                           exporter->SetFilled(); 
    605  
    606                           exporter->ResetForcedMaterial(); 
    607  
    608                           // export scene geometry 
    609                           if (0) 
    610                           { 
    611                                   Material m;//= RandomMaterial(); 
    612                                   m.mDiffuseColor = RgbColor(0, 0, 1); 
    613                                   exporter->SetForcedMaterial(m); 
    614                   
    615                                   for (int j = 0; j < objects.size(); ++ j) 
    616                                            exporter->ExportIntersectable(objects[j]); 
    617                          
    618                                   delete exporter; 
    619                           } 
    620                   } 
    621           } 
    622  
     599                  ExportSplits(objects); 
     600                  
    623601          for (int j = 0; j < pvsViewCells.size(); ++ j) 
    624602          { 
     
    666644                  } 
    667645                 
    668                   // output rest of the sobjects 
     646                  // output rest of the objects 
    669647                  if (0) 
    670648                  { 
     
    727705  return true; 
    728706} 
     707 
     708 
     709void SamplingPreprocessor::ExportSplits(const ObjectContainer &objects) 
     710{ 
     711        Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
     712 
     713        if (exporter)  
     714        {        
     715                cout << "exporting splits ... "; 
     716 
     717                Material m;  
     718                m.mDiffuseColor = RgbColor(1, 0, 0); 
     719                exporter->SetForcedMaterial(m); 
     720                exporter->SetWireframe(); 
     721                exporter->ExportBspSplits(*mBspTree); 
     722 
     723                // take forced material, else big scenes cannot be viewed 
     724                m.mDiffuseColor = RgbColor(0, 1, 0); 
     725                exporter->SetForcedMaterial(m); 
     726                exporter->SetFilled(); 
     727 
     728                exporter->ResetForcedMaterial(); 
     729                 
     730                // export rays 
     731                if (0) 
     732                { 
     733                        RayContainer outRays; 
     734                 
     735                        for (int i = 0; i < mSampleRays.size(); ++ i) 
     736                        { 
     737                                // only rays piercing geometry 
     738                                if (!mSampleRays[i]->intersections.empty()) 
     739                                        outRays.push_back(mSampleRays[i]); 
     740                        } 
     741                        if (BspTree::sConstructionMethod == BspTree::FROM_RAYS) 
     742                        { 
     743                                // export rays  
     744                                exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0)); 
     745                        } 
     746                } 
     747 
     748                // export scene geometry 
     749                if (1) 
     750                { 
     751                        Material m;//= RandomMaterial(); 
     752                        m.mDiffuseColor = RgbColor(0, 1, 0); 
     753                        exporter->SetForcedMaterial(m); 
     754            exporter->SetWireframe(); 
     755 
     756                        for (int j = 0; j < objects.size(); ++ j) 
     757                                exporter->ExportIntersectable(objects[j]); 
     758                } 
     759 
     760                delete exporter; 
     761 
     762                cout << "finished" << endl; 
     763        } 
     764} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r335 r349  
    6464 
    6565        bool BuildBspTree(); 
     66 
     67        void ExportSplits(const ObjectContainer &objects); 
    6668}; 
    6769 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.cpp

    r340 r349  
    22#include "Vector3.h" 
    33 
     4float Vector3::sDistTolerance = 0.002f; 
     5float Vector3::sDistToleranceSqrt = 0.000004f; 
    46 
    57// Given min a vector to minimize and a candidate vector, replace 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.h

    r318 r349  
    3636  Vector3(float X) { x = y = z = X; } 
    3737  Vector3(const Vector3 &v) { x = v.x; y = v.y; z = v.z; } 
     38 
     39  /// the distance where two points are still considered equal 
     40  static float sDistTolerance; 
     41  static float sDistToleranceSqrt; 
    3842 
    3943  // Functions to get at the vector components 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r342 r349  
    4343        contribution for a minimum number splits in the tree. 
    4444*/ 
    45 float BspTree::sLeastSplitsTable[] = {0, 0, 1, 0}; 
     45float BspTree::sLeastPolySplitsTable[] = {0, 0, 1, 0}; 
    4646/** Evaluates split plane classification with respect to the plane's  
    4747        contribution for a balanced tree. 
    4848*/ 
    49 float BspTree::sBalancedTreeTable[] = {-1, 1, 0, 0}; 
     49float BspTree::sBalancedPolysTable[] = {1, -1, 0, 0}; 
     50 
     51/** Evaluates split plane classification with respect to the plane's  
     52        contribution for a minimum number of ray splits. 
     53*/ 
     54float BspTree::sLeastRaySplitsTable[] = {0, 0, 1, 1, 0}; 
     55/** Evaluates split plane classification with respect to the plane's  
     56        contribution for balanced rays. 
     57*/ 
     58float BspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 
    5059 
    5160/****************************************************************/ 
     
    158167} 
    159168 
    160 void BspInterior::SplitRays(RayContainer &rays,  
    161                                                         RayContainer &frontRays,  
    162                                                         RayContainer &backRays) 
    163 { 
     169int BspInterior::SplitRays(RayContainer &rays,  
     170                                                   RayContainer &frontRays,  
     171                                                   RayContainer &backRays, 
     172                                                   const AxisAlignedBox3 &box) 
     173{ 
     174        int splits = 0; 
     175 
    164176        while (!rays.empty()) 
    165177        { 
     
    172184         
    173185                // test with tree bounding box 
    174 /*              if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 
     186                if (!box.GetMinMaxT(*ray, &minT, &maxT)) 
    175187                        continue; 
     188 
    176189                if (minT < 0) // start ray from origin 
    177190                        minT = 0; 
    178 */ 
     191 
    179192                // bound ray 
    180193                if ((ray->GetType() == Ray::LOCAL_RAY) &&  
     
    185198                } 
    186199                 
    187                 int classification = ray->ClassifyPlane(mPlane, minT, maxT); 
    188                  
     200                const int classification = ray->ClassifyPlane(mPlane, minT, maxT); 
     201                 
     202                ray->SetId(classification); 
     203 
    189204                switch (classification) 
    190205                { 
    191                 case Plane3::COINCIDENT: 
     206                case Ray::COINCIDENT: 
    192207                        break; 
    193                 case Plane3::BACK_SIDE: 
    194                         ray->SetId(BACK_RAY); 
     208                case Ray::BACK: 
    195209                        backRays.push_back(ray); 
    196210                        break; 
    197                 case Plane3::FRONT_SIDE: 
    198                         ray->SetId(FRONT_RAY); 
     211                case Ray::FRONT: 
    199212                        frontRays.push_back(ray); 
    200213                        break; 
    201                 case Plane3::SPLIT: 
    202                         ray->SetId(SPLIT_RAY); 
     214                case Ray::FRONT_BACK: 
     215                        ray->SetId(Ray::FRONT_BACK); 
     216                        backRays.push_back(ray); 
     217                        ++ splits;                       
     218                        break; 
     219                case Ray::BACK_FRONT: 
    203220                        frontRays.push_back(ray); 
    204                         backRays.push_back(ray); 
    205                         //extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 
     221                        ++ splits; 
    206222                        break; 
    207223                default: 
     224                        Debug << "Should not come here" << endl; 
    208225                        break; 
    209226                } 
    210227        } 
     228 
     229        return splits; 
    211230} 
    212231 
     
    215234                                                           PolygonContainer &backPolys,  
    216235                                                           PolygonContainer &coincident, 
    217                                                            bool storePolys) 
     236                                                           const bool storePolys) 
    218237{ 
    219238        Polygon3 *splitPoly = NULL; 
     
    232251 
    233252                // classify polygon 
    234                 int classification = poly->ClassifyPlane(mPlane); 
     253                const int classification = poly->ClassifyPlane(mPlane); 
    235254 
    236255                Polygon3 *front_piece = NULL; 
     
    241260                switch (classification) 
    242261                { 
    243                         case Plane3::COINCIDENT: 
     262                        case Polygon3::COINCIDENT: 
    244263                                coincident.push_back(poly); 
    245264                                break;                   
    246                         case Plane3::FRONT_SIDE:         
     265                        case Polygon3::FRONT_SIDE:       
    247266                                frontPolys.push_back(poly); 
    248267                                break; 
    249                         case Plane3::BACK_SIDE: 
     268                        case Polygon3::BACK_SIDE: 
    250269                                backPolys.push_back(poly); 
    251270                                break; 
    252                         case Plane3::SPLIT: 
     271                        case Polygon3::SPLIT: 
    253272                                front_piece = new Polygon3(poly->mParent); 
    254273                                back_piece = new Polygon3(poly->mParent); 
     
    262281                                ++ splits; // increase number of splits 
    263282 
    264                                 //-- inherit rays 
    265                                 if (poly->mPiercingRays) 
    266                                         InheritRays(*poly, *front_piece, *back_piece); 
    267  
     283                                //-- inherit rays from parent polygon 
     284                                poly->InheritRays(*front_piece, *back_piece); 
     285                                Debug << "p: " << poly->mPiercingRays.size() << " f: " << front_piece->mPiercingRays.size() << " b: " << back_piece->mPiercingRays.size() << endl; 
     286                                 
    268287                                // check if polygons still valid  
    269288                                if (front_piece->Valid()) 
     
    280299                                Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 
    281300#endif 
    282                                 ProcessPolygon(&poly, storePolys); 
    283                                  
     301                                ProcessPolygon(&poly, storePolys);                       
    284302                                break; 
    285303                        default: 
     
    290308 
    291309        return splits; 
    292 } 
    293  
    294 void BspInterior::InheritRays(const Polygon3 &poly,  
    295                                                       Polygon3 &front_piece,  
    296                                                       Polygon3 &back_piece) 
    297 { 
    298         RayContainer *rays = poly.mPiercingRays; 
    299  
    300         RayContainer::const_iterator it, it_end = rays->end(); 
    301  
    302         for (it = rays->begin(); it != it_end; ++ it) 
    303         { 
    304                 switch((*it)->GetId()) 
    305                 { 
    306                 case BACK_RAY: 
    307                         back_piece.GetPiercingRays()->push_back(*it); 
    308                         break; 
    309                 case FRONT_RAY: 
    310                         front_piece.GetPiercingRays()->push_back(*it); 
    311                         break; 
    312                 } 
    313         } 
    314310} 
    315311 
     
    664660                        if (it != facePolyMap.end())  
    665661                        { 
    666                                 (*it).second->AddPiercingRay(ray); 
     662                                (*it).second->mPiercingRays.push_back(ray); 
    667663                        }  
    668664                        else 
     
    670666                                Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 
    671667                                polys->push_back(poly); 
    672                                 poly->AddPiercingRay(ray); 
     668                                poly->mPiercingRays.push_back(ray); 
    673669 
    674670                                facePolyMap[face] = poly; 
     
    842838                                                                        PolygonContainer &coincident, 
    843839                                                                        RayContainer &rays, 
    844                                                                         RayContainer &backRays, 
    845                                                                         RayContainer &frontRays) 
     840                                                                        RayContainer &frontRays, 
     841                                                                        RayContainer &backRays) 
    846842{ 
    847843        mStat.nodes += 2; 
     
    855851#endif 
    856852         
    857         // partition rays 
    858         interior->SplitRays(rays, frontRays, backRays); 
     853        // subdivide rays into front and back rays 
     854        interior->SplitRays(rays, frontRays, backRays, mBox); 
    859855         
    860856        // split polygons with split plane 
     
    987983} 
    988984 
     985bool BspTree::SelectAxisAlignedPlane(Plane3 &plane,  
     986                                                                         const PolygonContainer &polys) const 
     987{ 
     988        AxisAlignedBox3 box; 
     989        box.Initialize(); 
     990         
     991        // create bounding box of region 
     992        Polygon3::IncludeInBox(polys, box); 
     993         
     994        int objectsBack = 0, objectsFront = 0; 
     995        int axis = 0; 
     996        float costRatio = MAX_FLOAT; 
     997        Vector3 position; 
     998 
     999        //-- area subdivision 
     1000        for (int i = 0; i < 3; ++ i)  
     1001        { 
     1002                float p = 0; 
     1003                float r = BestCostRatio(polys, box, i, p, objectsBack, objectsFront); 
     1004                 
     1005                if (r < costRatio) 
     1006                { 
     1007                        costRatio = r; 
     1008                        axis = i; 
     1009                        position = p; 
     1010                } 
     1011        } 
     1012         
     1013        if (costRatio >= sMaxCostRatio) 
     1014                return false; 
     1015 
     1016        Vector3 norm(0,0,0); norm[axis] = 1.0f; 
     1017        plane = Plane3(norm, position); 
     1018 
     1019        return true; 
     1020} 
     1021 
    9891022Plane3 BspTree::SelectPlane(BspLeaf *leaf,  
    9901023                                                        PolygonContainer &polys,  
    9911024                                                        const RayContainer &rays) 
    9921025{ 
    993         if (polys.size() == 0) 
    994         { 
    995                 Debug << "Warning: No split candidate available\n"; 
    996                 return Plane3(); 
     1026        if (polys.empty()) 
     1027        { 
     1028                Debug << "Warning: No autopartition polygon candidate available\n"; 
     1029         
     1030                // return axis aligned split 
     1031                AxisAlignedBox3 box; 
     1032                box.Initialize(); 
     1033         
     1034                // create bounding box of region 
     1035                Polygon3::IncludeInBox(polys, box); 
     1036 
     1037                const int axis = box.Size().DrivingAxis(); 
     1038                const Vector3 position = (box.Min()[axis] + box.Max()[axis])*0.5f; 
     1039 
     1040                Vector3 norm(0,0,0); norm[axis] = 1.0f; 
     1041                return Plane3(norm, position); 
    9971042        } 
    9981043 
     
    10001045                ((int)polys.size() > sTermMaxPolysForAxisAligned)) 
    10011046        { 
    1002                 AxisAlignedBox3 box; 
    1003                 box.Initialize(); 
    1004          
    1005                 // todo: area subdivision 
    1006                 Polygon3::IncludeInBox(polys, box); 
    1007          
    1008                 int objectsBack = 0, objectsFront = 0; 
    1009                 int axis = 0; 
    1010                 float costRatio = MAX_FLOAT; 
    1011                 Vector3 position; 
    1012  
    1013                 for (int i = 0; i < 3; ++ i)  
    1014                 { 
    1015                         float p = 0; 
    1016                         float r = BestCostRatio(polys, box, i, p, objectsBack, objectsFront); 
    1017                          
    1018                         if (r < costRatio) 
    1019                         { 
    1020                                 costRatio = r; 
    1021                                 axis = i; 
    1022                                 position = p; 
    1023                         } 
    1024                 } 
    1025                  
    1026                 if (costRatio < sMaxCostRatio) 
    1027                 { 
    1028                         Vector3 norm(0,0,0); norm[axis] = 1.0f; 
    1029                         return Plane3(norm, position); 
    1030                 } 
     1047                Plane3 plane; 
     1048                if (SelectAxisAlignedPlane(plane, polys)) 
     1049                        return plane; 
    10311050        } 
    10321051 
     
    10741093int BspTree::GetNextCandidateIdx(int currentIdx, PolygonContainer &polys) 
    10751094{ 
    1076         int candidateIdx = Random(currentIdx --); 
     1095        const int candidateIdx = Random(currentIdx --); 
    10771096 
    10781097        // swap candidates to avoid testing same plane 2 times 
     
    11011120        // needed for balanced view cells criterium 
    11021121        ViewCell::NewMail(); 
    1103         int backId = ViewCell::sMailId; 
     1122        const int backId = ViewCell::sMailId; 
    11041123        ViewCell::NewMail(); 
    1105         int frontId = ViewCell::sMailId; 
     1124        const int frontId = ViewCell::sMailId; 
    11061125        ViewCell::NewMail(); 
    1107         int frontAndBackId = ViewCell::sMailId; 
     1126        const int frontAndBackId = ViewCell::sMailId; 
    11081127 
    11091128        PolygonContainer::const_iterator it, it_end = polys.end(); 
     
    11111130        for (it = polys.begin(); it != it_end; ++ it) 
    11121131        { 
    1113                 int classification = (*it)->ClassifyPlane(candidatePlane); 
     1132                const int classification = (*it)->ClassifyPlane(candidatePlane); 
    11141133 
    11151134                if (sSplitPlaneStrategy & BALANCED_POLYS) 
    1116                         sumBalancedPolys += sBalancedTreeTable[classification]; 
     1135                        sumBalancedPolys += sBalancedPolysTable[classification]; 
    11171136                 
    11181137                if (sSplitPlaneStrategy & LEAST_SPLITS) 
    1119                         sumSplits += sLeastSplitsTable[classification]; 
     1138                        sumSplits += sLeastPolySplitsTable[classification]; 
    11201139 
    11211140                if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 
    11221141                { 
    1123                         if (classification == Plane3::COINCIDENT) 
     1142                        if (classification == Polygon3::COINCIDENT) 
    11241143                                sumPolyArea += (*it)->GetArea(); 
    11251144                        //totalArea += area; 
     
    11281147                if (sSplitPlaneStrategy & BLOCKED_RAYS) 
    11291148                { 
    1130                         float blockedRays = (float)(*it)->GetPiercingRays()->size(); 
    1131                  
    1132                         if (classification == Plane3::COINCIDENT) 
     1149                        const float blockedRays = (float)(*it)->mPiercingRays.size(); 
     1150                 
     1151                        if (classification == Polygon3::COINCIDENT) 
    11331152                                sumBlockedRays += blockedRays; 
    11341153                         
     
    11431162                        // assure that we only count a view cell  
    11441163                        // once for the front and once for the back side of the plane 
    1145                         if (classification == Plane3::FRONT_SIDE) 
     1164                        if (classification == Polygon3::FRONT_SIDE) 
    11461165                        { 
    11471166                                if ((viewCell->mMailbox != frontId) &&  
     
    11581177                                } 
    11591178                        } 
    1160                         else if (classification == Plane3::BACK_SIDE) 
     1179                        else if (classification == Polygon3::BACK_SIDE) 
    11611180                        { 
    11621181                                if ((viewCell->mMailbox != backId) && 
     
    11901209        if (sSplitPlaneStrategy & BLOCKED_RAYS) 
    11911210                if (totalBlockedRays != 0) 
    1192                         val += sBlockedRaysFactor * sumBlockedRays / totalBlockedRays; 
     1211                        val += sBlockedRaysFactor * (totalBlockedRays - sumBlockedRays) / totalBlockedRays; 
    11931212 
    11941213        if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
     
    12181237         
    12191238                // test with tree bounding box 
    1220                 /*if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 
     1239                if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 
    12211240                        continue; 
    12221241                if (minT < 0) // start ray from origin 
    1223                         minT = 0;*/ 
     1242                        minT = 0; 
    12241243 
    12251244                // bound ray 
     
    12311250                } 
    12321251 
    1233                 int classification = ray->ClassifyPlane(candidatePlane, minT, maxT); 
     1252                const int classification =  
     1253                        ray->ClassifyPlane(candidatePlane, minT, maxT); 
    12341254 
    12351255                if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 
    12361256                { 
    1237                         sumBalancedRays += sBalancedTreeTable[classification]; 
     1257                        sumBalancedRays += sBalancedRaysTable[classification]; 
    12381258                } 
    12391259                 
    12401260                if (sSplitPlaneStrategy & BALANCED_RAYS) 
    12411261                { 
    1242                         sumRaySplits += sLeastSplitsTable[classification]; 
     1262                        sumRaySplits += sLeastRaySplitsTable[classification]; 
    12431263                } 
    12441264        } 
     
    13321352        environment->GetBoolValue("BspTree.storeSplitPolys", sStoreSplitPolys); 
    13331353 
    1334         environment->GetFloatValue("BspTree.Construction.sideTolerance", Polygon3::sSideTolerance); 
    1335         Polygon3::sSideToleranceSqrt = Polygon3::sSideTolerance * Polygon3::sSideTolerance; 
     1354        environment->GetFloatValue("BspTree.Construction.sideTolerance", Vector3::sDistTolerance); 
     1355        Vector3::sDistToleranceSqrt = Vector3::sDistTolerance * Vector3::sDistTolerance; 
    13361356 
    13371357    Debug << "BSP max depth: " << sTermMaxDepth << endl; 
     
    13791399                { 
    13801400                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1401 
    13811402                        nodeStack.push(interior->GetBack()); 
    13821403                        nodeStack.push(interior->GetFront()); 
     
    14171438        } 
    14181439         
    1419 #ifdef _DEBUG 
     1440//#ifdef _DEBUG 
    14201441        Debug << "BSP stats: " 
    14211442                  << "Depth: " << data.mDepth << " (max: " << sTermMaxDepth << "), " 
    14221443                  << "#polygons: " << (int)data.mPolygons->size() << " (max: " << sTermMaxPolygons << "), " 
    14231444                  << "#rays: " << (int)data.mRays->size() << " (max: " << sTermMaxRays << ")" << endl; 
    1424 #endif 
     1445//#endif 
    14251446} 
    14261447 
     
    15201541                        entp = extp; 
    15211542                        mint = maxt; // NOTE: need this? 
     1543 
     1544                         if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
     1545                                break; 
     1546 
    15221547                        BspRayTraversalData &s = tStack.top(); 
    15231548 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r344 r349  
    169169                                          PolygonContainer &backPolys,  
    170170                                          PolygonContainer &coincident, 
    171                                           bool storePolys = false); 
    172  
    173         /** Splits the rays into front and back rays according to split plane 
     171                                          const bool storePolys = false); 
     172 
     173        /** Subdivides the rays into front and back rays according to the split plane. 
    174174                @param rays contains the rays to be split. The rays are  
    175                            distributed to front and back rays. 
     175                           distributed into front and back rays. 
    176176                @param frontRays returns rays on the front side of the plane 
    177177                @param backRays returns rays on the back side of the plane 
    178         */ 
    179         void SplitRays(RayContainer &rays,  
    180                                    RayContainer &frontRays,  
    181                                    RayContainer &backRays); 
     178                @param box the bounding box of the scene 
     179                @returns the number of splits 
     180        */ 
     181        int SplitRays(RayContainer &rays,  
     182                              RayContainer &frontRays,  
     183                                  RayContainer &backRays, 
     184                                  const AxisAlignedBox3 &box); 
    182185 
    183186        /** Stores polygon in node or discards them according to storePolys. 
     
    192195        } 
    193196 
    194 protected:       
    195  
    196         /** The piercing rays of the polygon are inherited by the child fragments 
    197                 @param poly the parent polygon 
    198                 @parm front_piece the front fragment inheriting the front rays 
    199                 @param back_piece the back fragment inheriting the back rays 
    200         */ 
    201         void InheritRays(const Polygon3 &poly,  
    202                                          Polygon3 &front_piece,  
    203                                          Polygon3 &back_piece); 
    204  
    205         enum {BACK_RAY, FRONT_RAY, SPLIT_RAY}; 
     197protected: 
     198 
    206199        /// Splitting plane corresponding to this node 
    207200        Plane3 mPlane; 
     
    474467                                                           PolygonContainer &coincident, 
    475468                                                           RayContainer &rays, 
    476                                                            RayContainer &backRays, 
    477                                                            RayContainer &frontRays); 
     469                                                           RayContainer &frontRays, 
     470                                                            RayContainer &backRays); 
    478471 
    479472        /** Filters polygons down the tree. 
     
    571564                                                         vector<SortableEntry> &splitCandidates) const; 
    572565 
     566        /** Selects an axis aligned split plane. 
     567                Returns true if split is valied 
     568        */ 
     569        bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const; 
     570 
    573571        /// Pointer to the root of the tree 
    574572        BspNode *mRoot; 
     
    642640                contribution for a balanced tree. 
    643641        */ 
    644         static float sLeastSplitsTable[4]; 
     642        static float sLeastPolySplitsTable[4]; 
    645643        /** Evaluates split plane classification with respect to the plane's  
    646644                contribution for a minimum number splits in the tree. 
    647645        */ 
    648         static float sBalancedTreeTable[4]; 
     646        static float sBalancedPolysTable[4]; 
     647        /** Evaluates split plane classification with respect to the plane's  
     648                contribution for a minimum number of ray splits. 
     649        */ 
     650        static float sLeastRaySplitsTable[5]; 
     651        /** Evaluates split plane classification with respect to the plane's  
     652                contribution for balanced rays. 
     653        */ 
     654        static float sBalancedRaysTable[5]; 
     655 
    649656}; 
    650657 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r333 r349  
    7272  stream<<"</IndexedLineSet>"<<endl; 
    7373  stream<<"</Shape>"<<endl; 
     74  return true; 
     75} 
     76 
     77bool 
     78X3dExporter::ExportRays(const RayContainer &rays, 
     79                                                const float length, 
     80                                                const RgbColor &color) 
     81{ 
     82  RayContainer::const_iterator ri = rays.begin(); 
     83 
     84  stream<<"<Shape>"<<endl; 
     85  stream<<"<Appearance>"<<endl; 
     86  stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<< 
     87    "\" />"<<endl; 
     88  stream<<"</Appearance>"<<endl; 
     89   
     90  stream<<"<IndexedLineSet coordIndex=\""<<endl; 
     91 
     92  int index = 0; 
     93  for (; ri != rays.end(); ri++) { 
     94    stream<<index<<" "<<index+1<<" -1\n"; 
     95    index+=2; 
     96  } 
     97   
     98  stream<<"\" >"<<endl; 
     99   
     100  stream<<"<Coordinate  point=\""<<endl; 
     101   
     102  ri = rays.begin(); 
     103  for (; ri != rays.end(); ri++) { 
     104    Vector3 a = (*ri)->GetLoc(); 
     105     
     106    Vector3 b; 
     107    if (length < 0) 
     108      b = (*ri)->GetLoc() - length*(*ri)->GetDir(); 
     109    else 
     110      if ((*ri)->intersections.size()==0) 
     111        b = (*ri)->GetLoc() + length*(*ri)->GetDir(); 
     112      else 
     113        b = (*ri)->Extrap((*ri)->intersections[0].mT); 
     114     
     115    stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,"; 
     116    stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n"; 
     117  } 
     118   
     119  stream<<"\" >"<<endl; 
     120  stream<<"</Coordinate>"<<endl; 
     121  stream<<"</IndexedLineSet>"<<endl; 
     122  stream<<"</Shape>"<<endl; 
     123 
    74124  return true; 
    75125} 
     
    668718                                Polygon3 *backPoly = new Polygon3(); 
    669719 
    670                                 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Plane3::SPLIT) 
     720                                if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 
    671721                                { 
    672722                                        planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r329 r349  
    7676  ExportBspSplits(const BspTree &tree); 
    7777 
     78  bool 
     79  ExportRays(const RayContainer &rays, 
     80                         const float length=1000, 
     81                         const RgbColor &color = RgbColor(1,1,1)); 
     82 
    7883  static ViewCellContainer foundViewCells; // todo: remove this 
    7984protected: 
Note: See TracChangeset for help on using the changeset viewer.