Table of Contents
This document discusses how to generate triangulated surfaces using MineSight® Grail Embedded (MSGe). Triangulation is accomplished by taking MineSight® polyline and polygon elements and using the grail.ms3d.elementop module to generate a set of surface elements.
We will examine how you can take a set of selected polygon and polylines and generate a new surface.
It is assumed that you,
Are familiar with MineSight® 3D.
Have an understanding of the basic mechanics behind python scripting.
See Getting Started for more information on scripting and MineSight®.
Understand how MineSight® Grail Embedded scripting works within MineSight® 3D.
For more information on MineSight® Grail Embedded scripting, see HowTo: Create an Embedded Script.
Have a working knowledge of operating with the selection buffer.
Although not critical, it is used as part of our example. See HowTo: Work with the Selection Buffer for more details.
Have a working knowledge of accessing the datamanager via a Python script.
This is how we store our triangulated surfaces in our example. See grail.ms3d.datamanager for more details.
Before proceeding it is recommended that you familiarize yourself with the above topics.
Generating triangulated surfaces based on the selection buffer requires the following steps,
- Retrieve the Element objects from the selection buffer.
- For the group of polyline/polygon Element objects selected generate a surface.
- Store the surface into a new MineSight® geometry object (GeometryMob).
We will follow these steps in our sample triangulate-selected.py script discussed below. For the purposes of our script will refer to only polylines; however, all the discussion with polylines is also applicable to MineSight® polygons.
We will start by cloning the em-boilerplate.py script found in the $(medexe)\scripts\samples directory, and renaming the new script triangulate-selected.py.
The first step will be to add modules that are required to build our script. The following statements should be added alongside the other import statements already within our triangulate-selected.py script,
The grail.ms3d.selectionbuffer module is used to query the user's selection. The grail.ms3d.element module is used to check the type of Elements that the user selected. We only want to generate surfaces for polylines selected by the user. The grail.ms3d.elementop module is used to perform the triangulation. Finally, the grail.ms3d.datamanager module is used to store our resulting surfaces into a new MineSight® object.
The next step is to start writing our new script in the run_code function of the new triangulate-area.py script. We will start by querying the selection buffer for any selected items, and make sure we only have selected polylines. If we fail to have anything useful, we will report an error and exit our run_code function.
View the complete triangulate-selected.py script.
As mentioned above, this script will inspect the selection buffer and generate a surface based on the selected polylines.
The steps illustrated in the sample code above can be broken down as follows,
Get what the user has selected.
We accomplish this by using the grail.ms3d.selectionbuffer module and reading the Element objects selected by the user.
Filter so we only have polylines and polygons.
By supplying a list of element types that we are interested in during our selection, we ensure that we only have selected items that we are interested in.
Start Triangulating.
This is where we start triangulating. We simply pass the list of polylines and polygon Element objects to the triangulate function and we get back a new surface Element object.
Store our results.
For the sake of simplicity, we will just store our triangulated surface into a MineSight® Object called \triangulated. If one already exists, this script will remove it prior to adding the new surface.
Update the display.
To see our new surface we will tell the datamanager to refresh its display.
In order to start triangulating with MineSight® Grail Embedded, you need to get a set of polylines/polygon Element objects, and put those objects through the grail.ms3d.elementop triangulate function.
[1] | "Built-in Functions". Python Library Reference. 21 December 2001. 20 May 2005. <http://www.python.org/doc/2.2/lib/built-in-funcs.html> |