Hi,

Dirk Reiners wrote:
	Hi folks,

On Mon, 2004-02-16 at 05:18, Carsten Neumann wrote:
  
I'm not sure if this is what you are asking for, but the IntersectAction 
starts the traversal at the Node you pass in (i.e. scene_root) and 
proceeds in the usual depth-first style. From the code you've given 
above I assume you only need the information if anything was hit, or 
maybe the geometry as well, but the IntersectAction will also determine 
the triangle that was hit. This is a likely the place where your 
performance hit comes from, as OpenSG has no special structure inside a 
Geometry to improve intersection on the triangle level. IIRC there is 
currently no way to turn off the triangle determination.

    
does the intersect action use bounding boxes to fast discard negative 
collisions??
      
Yes, but this only helps if you have many Geometries, not when looking 
for a hit triangle inside a Geometry.

Sorry, maybe someone else has some ideas here,
    

hm, not much we can do here. The main reason dedicated ray-tracers are
fast is because they add a lot of additional structure on the polygon
level, which you don't need for OpenGL rendering, which is why we don't
have any of that yet. Exception: polygon sorting for transparencies,
which is why we might it someday, but not right now.

The one thing that might help is Christoph Fuenfzig's work for OpenSG
Plus, which does add these kinds of polygon-based structures for quick
collision detection, for which ray intersection is a basic operation.

Christoph, can you comment on how hard it is to use your code for simple
ray intersection?

Thanks

	Dirk
  

Oh, there are also classes for simple ray intersection. There are two possibilities:
You can use a k-DOP bounding volume hierarchy on the triangles of a given subtree,
or you can use a regular grid to structure them.
    // create adapters with 18-dops for (NodePtr) scene
    typedef FaceBVolHierarchy<OpenSGTraits,OpenSGFaceInput<K18Dop> > Hierarchy;
    Hierarchy hier;
    OSGCache::the().setHierarchy(&hier);
    OSGCache::the().apply(scene);
    std::cout << "adapters with 18DOPs created.." << std::endl;

    // * ray intersect with bvol-hierarchy
    {
      // parameter: algorithm="LongestSideMedian", maxDepth=50, maxNumPrim=10
      hier.setParameter("LongestSideMedian", 50, 10);
      hier.hierarchy();
      BVolGroup<K18Dop>* root = hier.getRoot();
      std::cout << "18DOP-hierarchy (max depth 50, max num primitives 10) build...." << std::endl;

      Ray          ray(Pnt3f(0,0,10), Vec3f(0,0,-1));
      Intersection in(ray);

      SingleEnterLeaveTraverser<OpenSGTraits,BVolRayIntersectTraits<OpenSGTraits> > trav;
      trav.getData().setIntersect(in);
      OSGCache::CacheData& data = ""
      trav.apply(data, root);
      if (trav.getData().getHit()) {
	std::cout << "bvol-hierarchy: hit found (" 
		  << "distance=" << in.getDist() 
		  << ", point="  << in.getPoint()
		  << ")"
		  << std::endl;
	in.clearData();
      } else {
	std::cout << "bvol-hierarchy: no hit found" << std::endl; 
      }
    }

    // * ray intersect with regular-grid
    {
       OSGCache::AdapterVector prim;
       OSGCache::the().collectAdapter(Hierarchy::AdapterType::getAdapterId(), prim);
       // create grid for scene extent
       // parameter: create prim.size() voxels in total
       OSGRegularGrid grid(AABox(root->getBoundingVolume()), 
			   prim.size(), 
			   RegularGridBase::MaxVoxels);
       // insert all adapters into the grid
       OSGRecursiveFillGrid(grid).fillVoxels(prim);
       std::cout << "regular-grid build...." << std::endl;

       Ray          ray(Pnt3f(0,0,10), Vec3f(0,0,-1));
       Intersection in(ray);
       if (grid.calcIntersect(in)) {
	std::cout << "regular-grid: hit found (" 
		  << "distance=" << in.getDist() 
		  << ", point="  << in.getPoint()
		  << ")"
		  << std::endl;
	in.clearData();
       } else {
	std::cout << "regular-grid: no hit found" << std::endl; 
       }
    }

It looks a bit long, but it first builds the hierarchy or the regular grid and then performs one ray intersection.
I will sent you the sources but currently I have no projectfile for Visual Studio .NET 2003

Bye,
Christoph
-- 
--------------------------------------------------------------------
Christoph Fünfzig
Computer Graphics          tel:   +49 531 391-2105
TU Braunschweig            fax:   +49 531 391-2103
Muehlenpfordstr. 23        eMail: [EMAIL PROTECTED]
D-38106 Braunschweig       http://www.cg.cs.tu-bs.de/people/fuenfzig
 

Reply via email to