Changeset 844
- Timestamp:
- 01/17/08 19:05:09
- Files:
-
- trunk/include/vpb/Destination (modified) (2 diffs)
- trunk/src/vpb/Destination.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/include/vpb/Destination
r843 r844 16 16 17 17 #include <vpb/Source> 18 #include <osg/ClusterCullingCallback> 18 19 19 20 namespace vpb … … 161 162 osg::Node* createTerrainTile(); 162 163 osg::Node* createPolygonal(); 164 165 osg::ClusterCullingCallback* createClusterCullingCallback(); 163 166 164 167 void addSource(Source* source) { _sources.push_back(source); } trunk/src/vpb/Destination.cpp
r843 r844 20 20 #include <osg/ShapeDrawable> 21 21 #include <osg/Geometry> 22 #include <osg/ClusterCullingCallback>23 22 #include <osg/MatrixTransform> 24 23 #include <osg/Notify> … … 1243 1242 } 1244 1243 1244 osg::ClusterCullingCallback* DestinationTile::createClusterCullingCallback() 1245 { 1246 // make sure we are dealing with a geocentric database 1247 if (!_dataSet->mapLatLongsToXYZ()) return 0; 1248 1249 osg::HeightField* grid = _terrain.valid() ? _terrain->_heightField.get() : 0; 1250 if (!grid) return 0; 1251 1252 const osg::EllipsoidModel* et = _dataSet->getEllipsoidModel(); 1253 double globe_radius = et ? et->getRadiusPolar() : 1.0; 1254 unsigned int numColumns = grid->getNumColumns(); 1255 unsigned int numRows = grid->getNumRows(); 1256 1257 1258 double midLong = grid->getOrigin().x()+grid->getXInterval()*((double)(numColumns-1))*0.5; 1259 double midLat = grid->getOrigin().y()+grid->getYInterval()*((double)(numRows-1))*0.5; 1260 double midZ = grid->getOrigin().z(); 1261 1262 double midX,midY; 1263 et->convertLatLongHeightToXYZ(osg::DegreesToRadians(midLat),osg::DegreesToRadians(midLong),midZ, midX,midY,midZ); 1264 1265 osg::Vec3 center_position(midX,midY,midZ); 1266 1267 osg::Vec3 center_normal(midX,midY,midZ); 1268 center_normal.normalize(); 1269 1270 osg::Vec3 transformed_center_normal = center_normal; 1271 1272 unsigned int r,c; 1273 1274 // populate the vertex/normal/texcoord arrays from the grid. 1275 double orig_X = grid->getOrigin().x(); 1276 double delta_X = grid->getXInterval(); 1277 double orig_Y = grid->getOrigin().y(); 1278 double delta_Y = grid->getYInterval(); 1279 double orig_Z = grid->getOrigin().z(); 1280 1281 1282 float min_dot_product = 1.0f; 1283 float max_cluster_culling_height = 0.0f; 1284 float max_cluster_culling_radius = 0.0f; 1285 1286 for(r=0;r<numRows;++r) 1287 { 1288 for(c=0;c<numColumns;++c) 1289 { 1290 double X = orig_X + delta_X*(double)c; 1291 double Y = orig_Y + delta_Y*(double)r; 1292 double Z = orig_Z + grid->getHeight(c,r); 1293 double height = Z; 1294 1295 et->convertLatLongHeightToXYZ(osg::DegreesToRadians(Y),osg::DegreesToRadians(X),Z, 1296 X,Y,Z); 1297 1298 osg::Vec3d v(X,Y,Z); 1299 osg::Vec3 dv = v - center_position; 1300 double d = sqrt(dv.x()*dv.x() + dv.y()*dv.y() + dv.z()*dv.z()); 1301 double theta = acos( globe_radius/ (globe_radius + fabs(height)) ); 1302 double phi = 2.0 * asin (d*0.5/globe_radius); // d/globe_radius; 1303 double beta = theta+phi; 1304 double cutoff = osg::PI_2 - 0.1; 1305 1306 //log(osg::INFO,"theta="<<theta<<"\tphi="<<phi<<" beta "<<beta); 1307 if (phi<cutoff && beta<cutoff) 1308 { 1309 1310 float local_dot_product = -sin(theta + phi); 1311 float local_m = globe_radius*( 1.0/ cos(theta+phi) - 1.0); 1312 float local_radius = static_cast<float>(globe_radius * tan(beta)); // beta*globe_radius; 1313 min_dot_product = osg::minimum(min_dot_product, local_dot_product); 1314 max_cluster_culling_height = osg::maximum(max_cluster_culling_height,local_m); 1315 max_cluster_culling_radius = osg::maximum(max_cluster_culling_radius,local_radius); 1316 } 1317 else 1318 { 1319 //log(osg::INFO,"Turning off cluster culling for wrap around tile."); 1320 return 0; 1321 } 1322 } 1323 } 1324 1325 1326 // set up cluster cullling, 1327 osg::ClusterCullingCallback* ccc = new osg::ClusterCullingCallback; 1328 1329 ccc->set(center_position + transformed_center_normal*max_cluster_culling_height , 1330 transformed_center_normal, 1331 min_dot_product, 1332 max_cluster_culling_radius); 1333 1334 return ccc; 1335 } 1336 1245 1337 osg::Node* DestinationTile::createTerrainTile() 1246 1338 { 1247 #if 01248 return createHeightField();1249 #else1250 1251 1339 if (!_terrain) _terrain = new DestinationData(_dataSet); 1252 1340 … … 1334 1422 } 1335 1423 1336 #if 11337 1424 // assign the terrain technique that will be used to render the terrain tile. 1338 1425 osgTerrain::GeometryTechnique* gt = new osgTerrain::GeometryTechnique; 1339 1426 terrain->setTerrainTechnique(gt); 1340 #endif 1427 1428 // assign cluster culling callback to terrain 1429 terrain->setCullCallback(createClusterCullingCallback()); 1341 1430 1342 1431 return terrain; 1343 #endif1344 1432 } 1345 1433 … … 2087 2175 readFrom(itr->get()); 2088 2176 } 2089 log(osg::NOTICE,"DestinationTile::readFrom(CompositeSource* ) numChecked %i",numChecked); 2177 2178 log(osg::INFO,"DestinationTile::readFrom(CompositeSource* ) numChecked %i",numChecked); 2090 2179 2091 2180 optimizeResolution(); … … 2102 2191 allocate(); 2103 2192 2104 log(osg:: NOTICE,"DestinationTile::readFrom() %i",_sources.size());2193 log(osg::INFO,"DestinationTile::readFrom() %i",_sources.size()); 2105 2194 for(Sources::iterator itr = _sources.begin(); 2106 2195 itr != _sources.end(); … … 2284 2373 { 2285 2374 Triple(): 2286 _ drawable(0),2375 _object(0), 2287 2376 _callback(0) {} 2288 2377 2289 Triple(osg::NodePath nodePath, osg:: Drawable* drawable, osg::ClusterCullingCallback* callback):2378 Triple(osg::NodePath nodePath, osg::Object* object, osg::ClusterCullingCallback* callback): 2290 2379 _nodePath(nodePath), 2291 _ drawable(drawable),2380 _object(object), 2292 2381 _callback(callback) {} 2293 2382 2294 2383 Triple(const Triple& t): 2295 2384 _nodePath(t._nodePath), 2296 _ drawable(t._drawable),2385 _object(t._object), 2297 2386 _callback(t._callback) {} 2298 2387 … … 2300 2389 { 2301 2390 _nodePath = t._nodePath; 2302 _ drawable = t._drawable;2391 _object = t._object; 2303 2392 _callback = t._callback; 2304 2393 return *this; … … 2306 2395 2307 2396 osg::NodePath _nodePath; 2308 osg:: Drawable* _drawable;2397 osg::Object* _object; 2309 2398 osg::ClusterCullingCallback* _callback; 2310 2399 }; … … 2317 2406 virtual void apply(osg::Group& group) 2318 2407 { 2319 if (dynamic_cast<osgTerrain::Terrain*>(&group)==0) 2408 osgTerrain::Terrain* terrain = dynamic_cast<osgTerrain::Terrain*>(&group); 2409 if (terrain) 2410 { 2411 osg::ClusterCullingCallback* callback = dynamic_cast<osg::ClusterCullingCallback*>(terrain->getCullCallback()); 2412 if (callback) 2413 { 2414 _callbackList.push_back(Triple(getNodePath(),terrain,callback)); 2415 } 2416 } 2417 else 2320 2418 { 2321 2419 osg::NodeVisitor::apply(group); … … 2463 2561 2464 2562 // remove it from the drawable. 2465 triple._drawable->setCullCallback(0); 2563 2564 osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(triple._object); 2565 if (drawable) drawable->setCullCallback(0); 2566 2567 osg::Node* node = dynamic_cast<osg::Node*>(triple._object); 2568 if (node) node->setCullCallback(0); 2466 2569 } 2467 2570 } … … 2684 2787 pagedLOD->setCullCallback(triple._callback); 2685 2788 2686 // remove it from the drawable. 2687 triple._drawable->setCullCallback(0); 2789 osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(triple._object); 2790 if (drawable) drawable->setCullCallback(0); 2791 2792 osg::Node* node = dynamic_cast<osg::Node*>(triple._object); 2793 if (node) node->setCullCallback(0); 2688 2794 } 2689 2795 }
