Joachim,
Yes, you can provide your own mesher to substitute BRepMesh_IncrementalMesh (which is default).
As of 6.3.0, Open CASCADE provides a plugin architecture for that. Release Notes do mention that but apparently User's Guide does not uncover details.
Here is what you should do:
1. Subclass you meshing algorithm from BRepMesh_DiscretRoot and redefine its Perform() method using already saved shapes and parameters (deflection, angle, etc + optionally your own). This class must be located in a library (not executable)
1a. For convenience, it must also contain a static method
static Standard_Integer Discret (const TopoDS_Shape& theShape,
const Standard_Real theDeflection,
const Standard_Real theAngle,
BRepMesh_PDiscretRoot& theAlgo);
that will create an instance of your mesher using specified parameters. For instance:
Standard_Integer ExchangerLib_Mesher::Discret (const TopoDS_Shape& theShape,
const Standard_Real theDeflection,
const Standard_Real theAngle,
BRepMesh_PDiscretRoot& theAlgo)
{
theAlgo = new ExchangerLib_Mesher (theShape, theDeflection, theAngle);
return 0;
}
Alternatively, you must have another class with such static method.
2. Use DISCRETALGO macro defined in BRepMesh_PluginMacro.hxx to create a C function and export it. Its argument is a class that has above Discret() static method.
DISCRETPLUGIN(ExchangerLib_Mesher)
3. In your application, before it starts tessellating any shape specify your mesher as a new default using BRepMesh_DiscretFactory::SetDefaultName(). For example:
BRepMesh_DiscretFactory::Get().SetDefaultName (ExchangerLib_Mesher::LibName());
where argument is a name of the dynamic library that exports your function defined at step 2 above, without prefix and suffix (e.g. MyLib for libMyLib.so or MyLib.dll).
This will make it work.
However internal implementation is not optimal and has several issues (these are only those I noticed, in the order of decreasing severity):
a. It reveals big performance problems. If you have to visualize many individual shapes you will definitively notice that. The root-cause is that every time the framework employs OSD_SharedLibrary trying to load the library and resolve the symbol.
b. It does not provide a way to pass your own extra arguments to the mesher. The code assumes that only parameters available in Prs3d_Drawer will be used (deflection and angle) which is not a valid assumption.
c. Only one mesher at a time - you cannot tessellate shapes using different meshers in one AIS_InteractiveContext.
Alternative, more flexible solution would be to have Factory use some cache (as hash table or data map) that would store registered meshers and could dynamically select between them. The mesher would provide either a copy constructor or a Factory method (see Design Patterns) in order to fastly clone itself. But I have not really deeply thought of it (and I currently switched off a custom mesher).
Hope this helps.
Commenter-1
---
opencascade.blogspot.com - the Open CASCADE blog
www.cadexchanger.com - CAD Exchanger, your 3D data translator