Changeset 2383


Ignore:
Timestamp:
05/16/07 14:26:36 (17 years ago)
Author:
vizrt_christian_seidl
Message:

some smaller changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBiHierarchy.cpp

    r2361 r2383  
    11151115BiHierarchy::Node * BiHierarchy::recBuild(BihPlaneEventList& events, int nObjects, AxisAlignedBox& aabb, BiHierarchy::Branch * parent) 
    11161116{ 
     1117#define OLD_METHOD       
     1118//      859 
    11171119        // determine the depth we are on 
    11181120        int level = 0; 
     
    11511153        AxisAlignedBox minRights[dim]; 
    11521154 
     1155        Vector3 MaxBoundingLeft=aabb.getMaximum(); 
     1156        Vector3 MinBoundingRight=aabb.getMinimum(); 
     1157 
     1158        Vector3 LastPosition=MinBoundingRight; 
     1159 
     1160 
     1161         
     1162 
     1163 
     1164        bool LeftMod[dim]; 
     1165        bool RightMod[dim]; 
     1166 
    11531167        AxisAlignedBox minLeft; 
    11541168        AxisAlignedBox minRight; 
     1169        BihPlaneEventList::iterator LeftBorder[dim]; 
    11551170         
    1156  
     1171    for (int i=0; i<dim; i++) 
     1172        { 
     1173          minLefts[i].setNull();                         
     1174          minRights[i]=aabb; 
     1175          nRight[i]=nObjects; 
     1176          nLeft[i]=0; 
     1177          LeftBorder[i]=it; 
     1178        } 
    11571179        // try all planes to find the best one for the given set of objects 
    11581180         
    11591181        // Use SAH method 
     1182        //mBuildLog->logMessage("------------NewRun:" + StringConverter::toString(nObjects)); 
    11601183        if (mAlgorithm==BIHAL_SAH) 
    11611184        { 
     1185 
     1186#ifdef OLD_METHOD 
     1187                it = begin; 
     1188                 
    11621189                while (it != end) 
    11631190                { 
    11641191                        BihPlaneEventList::iterator p = it; 
     1192 
     1193 
    11651194                        pStart = pOn = pEnd = 0; 
    11661195                         
    11671196                        while (it != end && p->equalsType(*it, BihPlaneEvent::PET_END)) 
    11681197                        { 
    1169                                 it++; pEnd++; 
     1198                                it++; pEnd++;  
    11701199                        } 
    11711200                        while (it != end && p->equalsType(*it, BihPlaneEvent::PET_ON)) 
     
    11771206                                it++; pStart++; 
    11781207                        } 
    1179                          
     1208 
    11801209                         
    11811210                        int d = p->getDimension(); 
     1211 
    11821212                        nPlane[d] = pOn; 
    1183                         //nRight[d] -= pOn; nRight[d] -= pEnd; 
     1213                        nRight[d] -= pOn; nRight[d] -= pEnd; 
     1214 
    11841215 
    11851216            // find the corrected offsets for the left and right bounding box 
     
    11871218                        LeftOffset[d]=0; 
    11881219                        RightOffset[d]=0; 
    1189                         minLefts[d].setNull(); 
    1190                 minRights[d].setNull(); 
     1220                         
     1221                         
     1222                         
     1223         
    11911224                        nRight[d]=0; 
    11921225                        nLeft[d]=0; 
     1226                        minLefts[d].setNull(); 
     1227                        minRights[d].setNull(); 
     1228 
     1229            if (minLefts[d].isNull() && minRights[d].isNull()) 
     1230                        { 
     1231                                while (it_a != end) 
     1232                                { 
     1233                                        if ((it_a->getDimension()==d) && (it_a->GetType() == BihPlaneEvent::PET_START)) 
     1234                                        { 
     1235                                                it_a->getRenderable()->setSide(BihPlaneEvent::PES_BOTH); 
     1236                                                it_a->getRenderable()->setClassified(false); 
     1237                                                it_a->classify(*p, split.side,true); 
     1238                                                if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_RIGHT) 
     1239                                                { 
     1240                                                        if (!it_a->getRenderable()->isClassified()) 
     1241                                                        { 
     1242                                                                it_a->getRenderable()->setClassified(true); 
     1243                                                                nRight[d]++; 
     1244                                                        } 
     1245                                                        minRights[d].merge(it_a->getRenderable()->getBoundingBox()); 
     1246                                                         
     1247                                                } 
     1248                                                // left-only nodes go in left list 
     1249                                                else if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_LEFT) 
     1250                                                { 
     1251                                                         
     1252                                                        if (!it_a->getRenderable()->isClassified()) 
     1253                                                        { 
     1254                                                                it_a->getRenderable()->setClassified(true); 
     1255                                                                nLeft[d]++; 
     1256                                                        } 
     1257                                                        minLefts[d].merge(it_a->getRenderable()->getBoundingBox()); 
     1258                                                         
     1259                                                } 
     1260                                        } 
     1261 
     1262 
     1263                                        it_a++; 
     1264                                } 
     1265                        } 
     1266 
     1267 
     1268 
     1269                            
     1270#endif 
     1271 
     1272/////////////////////////////////////////////////////////////////////////// 
     1273 
     1274#ifndef OLD_METHOD               
     1275                it = begin; 
     1276                while (it != end) 
     1277                { 
     1278                        it->getRenderable()->setDecided(0,false); 
     1279                        it->getRenderable()->setDecided(1,false); 
     1280                        it->getRenderable()->setDecided(2,false); 
     1281                        it->ClearGrowBB(); 
     1282                        it++; 
     1283                } 
     1284                it = end; 
     1285                AxisAlignedBox tempBB[3]; 
     1286                for (int i=0; i<3; i++) tempBB[i].setNull(); 
     1287                while (it != begin) 
     1288                { 
     1289            it--; 
     1290                        if ((it->getRenderable()) && (it->equalsType(*it, BihPlaneEvent::PET_START))) 
     1291                        { 
     1292                          tempBB[it->getDimension()].merge(it->getRenderable()->getBoundingBox()); 
     1293                          it->GrowBB(tempBB[it->getDimension()]); 
     1294                        } 
    11931295                         
    1194  
    1195                         while (it_a != end) 
    1196                         { 
    1197                                 if (it_a->getDimension()==d) 
    1198                                 { 
    1199                                         it_a->getRenderable()->setSide(BihPlaneEvent::PES_BOTH); 
    1200                                         it_a->getRenderable()->setClassified(false); 
    1201                                         it_a->classify(*p, split.side,true); 
    1202                                         if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_RIGHT) 
     1296                         
     1297                } 
     1298 
     1299                it = begin; 
     1300                 
     1301                 
     1302                while (it != end) 
     1303                { 
     1304                         
     1305 
     1306            BihPlaneEventList::iterator p = it; 
     1307                         
     1308                        int d = p->getDimension(); 
     1309 
     1310 
     1311            // find the corrected offsets for the left and right bounding box 
     1312                         
     1313                        LeftOffset[d]=0; 
     1314                        RightOffset[d]=0; 
     1315                         
     1316                         
     1317                         
     1318 
     1319 
     1320 
     1321 
     1322                                 
     1323                    bool foundLeft[3]; 
     1324                                        foundLeft[0]=false; foundLeft[1]=false; foundLeft[2]=false; 
     1325                                         
     1326                                 
     1327                                        // set the right border 
     1328                                        it_a=it; 
     1329                                        while (it_a!=end) 
    12031330                                        { 
    1204                                                 if (!it_a->getRenderable()->isClassified()) 
     1331                                                if ((it_a->getDimension()==d) && (it_a->GetType() == BihPlaneEvent::PET_START)) 
    12051332                                                { 
    1206                                                         it_a->getRenderable()->setClassified(true); 
    1207                                                         nRight[d]++; 
     1333                                                         
     1334                                                         
     1335                                                        minRights[d]=it_a->GetGrowBB(); 
     1336                                                        //mBuildLog->logMessage("Found Right side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 
     1337                                                        break; 
    12081338                                                } 
    1209                                                 minRights[d].merge(it_a->getRenderable()->getBoundingBox()); 
    1210                                                  
     1339                                                it_a++; 
    12111340                                        } 
    1212                                         // left-only nodes go in left list 
    1213                                         else if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_LEFT) 
     1341 
     1342                                         
     1343                                        it_a=LeftBorder[d]; 
     1344                                        while (it_a!=it) 
    12141345                                        { 
    1215                                                 if (!it_a->getRenderable()->isClassified()) 
     1346                                                if (it_a->getRenderable()) 
    12161347                                                { 
    1217                                                         it_a->getRenderable()->setClassified(true); 
    1218                                                         nLeft[d]++; 
     1348                                                        /* 
     1349                                                        if (it_a->getDimension()==0 && d==0) 
     1350                                                        { 
     1351                                                                mBuildLog->logMessage("--------Enter Loop: d"  ); 
     1352                                                                if (it_a->GetType() == BihPlaneEvent::PET_START) 
     1353                                                                        mBuildLog->logMessage("--------START"  ); 
     1354                                                                if (it_a->GetType() == BihPlaneEvent::PET_END) 
     1355                                                                        mBuildLog->logMessage("--------END"  ); 
     1356                                                                if (it_a->GetType() == BihPlaneEvent::PET_ON) 
     1357                                                                        mBuildLog->logMessage("--------ON"  ); 
     1358 
     1359                                                        } 
     1360                                                        */ 
     1361                                                        if ((it_a->getDimension()==d) /*&& (it_a->GetType() == BihPlaneEvent::PET_START) */&& (!it_a->getRenderable()->isDecided(d))) 
     1362                                                        { 
     1363                                                                it_a->classify(*it, split.side,true); 
     1364                                                                if  (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_RIGHT) 
     1365                                                                { 
     1366                                                                        // right side 
     1367                                                                         
     1368                                                                         
     1369                                                                        minRights[d].merge(it_a->GetGrowBB()); 
     1370                                                                        //if (d==0) 
     1371                                                                        //mBuildLog->logMessage("Move to Right side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 
     1372                                                                         
     1373 
     1374                                                                } else 
     1375                                                                { 
     1376                                                                        minLefts[d].merge(it_a->getRenderable()->getBoundingBox()); 
     1377                                                                        it_a->getRenderable()->setDecided(d,true); 
     1378                                                                        Vector3 pos=minLefts[d].getMaximum(); 
     1379                                                                        nLeft[d]++; nRight[d]--; 
     1380                                                                        //if (d==0) 
     1381                                    //mBuildLog->logMessage("Move to Left side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 
     1382 
     1383                                                                        if ((it_a->getPosition()[d]>LeftBorder[d]->getPosition()[d]) && (!foundLeft[d])) 
     1384                                                                        { 
     1385                                                                                LeftBorder[d]=it_a; 
     1386                                                                                //if (d==0) 
     1387                                                                                //mBuildLog->logMessage("Adjust left to  d" + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 
     1388                                                                        } else 
     1389                                                                        { 
     1390                                                                            //if (d==0) 
     1391                                                                                //mBuildLog->logMessage("Found left   d" + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 
     1392                                                                                foundLeft[d]=true; 
     1393                                                                        } 
     1394 
     1395 
     1396                                                                } 
     1397                                                        }  
     1398 
    12191399                                                } 
    1220                                                 minLefts[d].merge(it_a->getRenderable()->getBoundingBox()); 
    1221                                                  
     1400                                                else 
     1401                                                { 
     1402                                                        //if (d==0) 
     1403                                                        //mBuildLog->logMessage("------No renderable " + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 
     1404                                                } 
     1405                                                it_a++; 
    12221406                                        } 
    1223                                 } 
    1224  
    1225  
    1226                                 it_a++; 
    1227                         } 
    1228  
    1229                          
     1407 
     1408 
     1409                                                                 
     1410 
     1411 
     1412 
     1413 
     1414                                         
     1415 
     1416                            
     1417#endif 
     1418                            if (it!=end) it++; 
     1419#ifdef OLD_METHOD 
    12301420                                p->SAH(aabb, nLeft[d], nPlane[d], nRight[d], split,minLefts[d],minRights[d]); 
    1231                                 mBuildLog->logMessage("SAH " + StringConverter::toString(best.cost)+ " " + StringConverter::toString(split.cost) +  
    1232                                         "dim: " + StringConverter::toString(d)); 
    12331421                                if (split.cost < best.cost) 
    12341422                                { 
    12351423                                        best = split; 
    12361424                                } 
     1425#endif 
     1426                                /* 
     1427                                if (d==0) 
     1428                                mBuildLog->logMessage("SAH " + StringConverter::toString(best.cost)+ " " + StringConverter::toString(split.cost) +  
     1429                                        "dim: " + StringConverter::toString(d)+ "Elements: " + StringConverter::toString(nLeft[d]) +   
     1430                                        " " + StringConverter::toString(nRight[d])+ "Planes: "+ StringConverter::toString(minLefts[d].getMaximum()[d]) + 
     1431                                        " " + StringConverter::toString(it->getPosition()[d]) +" " + StringConverter::toString(minRights[d].getMinimum()[d]) 
     1432                                        +" " + StringConverter::toString(LeftBorder[d]->getPosition()[d])); 
     1433                                */ 
     1434#ifndef OLD_METHOD 
     1435                                if (it!=end) 
     1436                                { 
     1437                                if ((it->getPosition()[it->getDimension()]!=LastPosition[it->getDimension()])) 
     1438                                { 
     1439                                        LastPosition[it->getDimension()]=it->getPosition()[it->getDimension()]; 
     1440                                        p->SAH(aabb, nLeft[d], nPlane[d], nRight[d], split,minLefts[d],minRights[d]); 
     1441                                        if (split.cost < best.cost) 
     1442                                        { 
     1443                                                best = split; 
     1444                                        } 
     1445                                } 
     1446                                } else 
     1447                                { 
     1448                                        p->SAH(aabb, nLeft[d], nPlane[d], nRight[d], split,minLefts[d],minRights[d]); 
     1449                                        if (split.cost < best.cost) 
     1450                                        { 
     1451                                                best = split; 
     1452                                        } 
     1453                                } 
     1454 
     1455#endif 
     1456 
     1457 
     1458 
     1459                                 
     1460                                 
    12371461                         
    1238  
    1239                         //nLeft[d] += pStart; nLeft[d] += pOn;  
     1462#ifdef OLD_METHOD 
     1463                        nLeft[d] += pStart; nLeft[d] += pOn;  
     1464#endif 
    12401465                         
    12411466                    nPlane[d] = 0; 
     
    12901515        /************************************************/ 
    12911516        // check terminating condition 
    1292         if (/*best.cost > BihPlaneEvent::KI*nObjects ||*/ level >= mMaxDepth || nObjects<20 ) 
     1517        if (best.cost > BihPlaneEvent::KI*nObjects || level >= mMaxDepth  || nObjects<4 ) 
     1518        //if (best.cost > 2*nObjects || level >= mMaxDepth )//|| nObjects<4 ) 
    12931519        { 
    12941520                // Terminating condition reached, create leaf and add renderables to list 
     
    14061632                                " O: " + StringConverter::toString(nObjects)); 
    14071633 
     1634                 
     1635 
    14081636 
    14091637                // calculate minimum of the left bounding box 
     
    14191647                */ 
    14201648 
    1421  
     1649  
    14221650 
    14231651                // create a new branch node and continue recursion 
     
    14261654 
    14271655                // now create the child nodes and continue recursion 
    1428                 /* 
    1429                 if (best.bleft.volume()>minLeft.volume()) 
     1656         
     1657                //if (best.bleft.volume()>minLeft.volume()) 
    14301658                { 
    14311659                        mBuildLog->logMessage("Volume Smaller Left " + StringConverter::toString(minLeft.volume()) + " " + StringConverter::toString(best.bleft.volume(),3,3)); 
    1432                 } 
    1433  
    1434                 if (best.bright.volume()>minRight.volume()) 
     1660                    if (best.bleft.volume()!=minLeft.volume()) 
     1661                        { 
     1662                                mBuildLog->logMessage("Error Volume Left "   + StringConverter::toString(best.bleft.getMinimum())+ " " + StringConverter::toString(best.bleft.getMaximum())); 
     1663                                mBuildLog->logMessage("Error Volume Left " + StringConverter::toString(minLeft.getMinimum()) + " " + StringConverter::toString(minLeft.getMaximum()) ); 
     1664                        } 
     1665 
     1666                } 
     1667 
     1668                //if (best.bright.volume()>minRight.volume()) 
    14351669                { 
    14361670                        mBuildLog->logMessage("Volume Smaller Right " + StringConverter::toString(minRight.volume()) + " " + StringConverter::toString(best.bright.volume(),3,3)); 
    1437                 } 
    1438                 */ 
     1671                        if (best.bright.volume()!=minRight.volume()) 
     1672                        { 
     1673                                mBuildLog->logMessage("Error Volume Right " + StringConverter::toString(best.bright.getMinimum())+ " " + StringConverter::toString(best.bright.getMaximum())); 
     1674                                mBuildLog->logMessage("Error Volume Right " + StringConverter::toString(minRight.getMinimum()) + " " + StringConverter::toString(minRight.getMaximum()) ); 
     1675                        } 
     1676                } 
     1677                 
    14391678 
    14401679                if (eventsLeft.size() > 0) 
     
    14431682                        branch->mLeft = recBuild(eventsLeft, nLeftS + nBothS, /*best.bleft*/minLeft, branch); 
    14441683                        branch->mLeft->SetToLeft(); 
    1445                         mBuildLog->logMessage("SetToLeft"); 
     1684                        //mBuildLog->logMessage("SetToLeft"); 
    14461685                        //branch->mLeft = recBuild(eventsLeft, nLeftS + nBothS, best.bleft, branch); 
    14471686                } 
     
    14511690                        branch->mRight = recBuild(eventsRight, nBothS + nRightS, /*best.bright*/ minRight, branch); 
    14521691                        branch->mRight->SetToRight(); 
    1453                         mBuildLog->logMessage("SetToRight"); 
     1692                        //mBuildLog->logMessage("SetToRight"); 
    14541693 
    14551694 
     
    20342273        if (showBoxes) 
    20352274        { 
    2036         if (mLevel == mOwner->getHiLiteLevel()|| (mLevel-1) == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes()) 
     2275        /* 
     2276                if (mLevel == mOwner->getHiLiteLevel()|| (mLevel-1) == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes()) 
    20372277                queue->addRenderable(getWireBoundingBox()); 
     2278                */ 
    20382279                /* 
    20392280                if (mLevel == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes()) 
Note: See TracChangeset for help on using the changeset viewer.