HowTo: Use Embedded Contouring

Version: 16.2

Table of Contents

Preface

This document discusses how to generate contours using the MineSight® Grail Embedded (MSGe) contouring engine. Contouring is accomplished by taking MineSight® surface elements and using the grail.ms3d.elementop module to generate a set of polyline and polygon elements for a given elevation start, end and step.

We will examine how you can take a set of surfaces selected by the user and generate contours at with a start of 0 units and an end of 2000 units, and steps of 10 units and 50 units.

Assumptions

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 contours in our example. See grail.ms3d.datamanager for more details.

Before proceeding it is recommended that you familiarize yourself with the above topics.

Getting Started

Generating contours based on the selection buffer requires the following steps,

  1. Retrieve the surface Element objects from the selection buffer.
  2. For each surface Element object, generate contours.
  3. Store the contours into a new MineSight® geometry object (GeometryMob).

We will follow these steps in our sample contour-selected.py script discussed below. For the purposes of our script will refer to only surfaces; however, all the discussion with surfaces is also applicable to MineSight® solids.

Example of Contouring Selected Surfaces

We will start by cloning the em-boilerplate.py script found in the $(medexe)\scripts directory, and renaming the new script contour-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 contour-selected.py script,

from grail.ms3d import selectionbuffer
from grail.ms3d import element
from grail.ms3d import elementop
from grail.ms3d import datamanager

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 contours for surfaces selected by the user. The grail.ms3d.elementop module is used to perform the contouring. Finally, the grail.ms3d.datamanager module is used to store our resulting contours into a new MineSight® object.

The next step is to start writing our new script in the run_code function of the new contour-area.py script. We will start by querying the selection buffer for any selected items, and make sure we only have selected surfaces. If we fail to have anything useful, we will report an error and exit our run_code function.

def run_code():
    
"""Sample 'function' in embedded script.

    This function will write some text out the message
    window, but you can have it do anything you like.
    """

    
# (1) Get what the user has selected.
    
# (2) Filter so we only have surfaces.
    
selected = selectionbuffer.get_elements([element.ShellType])

    
if not surfaces:
        
return # exit our script

    
# (3) For each surface, start contouring.
    
start = 0
    
end = 2000
    
minor_elevation = 10
    
major_elevation = 50
    
print "contouring...",
    
for surface in surfaces:
        
print ".",
        
minor = elementop.contour(surface, start, end, minor_elevation)
        
major = elementop.contour(surface, start, end, major_elevation)

        
# (4) Store them into a MineSight(r) Object; if one already exists,
        
#     then remove it prior to adding new contours.
        
if datamanager.is_object("\\contours"):
            
datamanager.remove("\\contours")

        
g = datamanager.create_geometry("\\contours",
                
"\\materials\\geometry")
        
g.add_elements(minor)
        
g.add_elements(major)
    
print "OK."

View the complete contour-selected.py script.

As mentioned above, this script will inspect the selection buffer and generate contours for each selected surface. The contours will be generated from 0 to 2000 units, with minor contours at 10 units and major contours at 50 units.

The steps illustrated in the sample code above can be broken down as follows,

  1. 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.

  2. Filter so we only have surfaces.

    By supplying a list of element types that we are interested in we can ensure that only surfaces will be selected.

  3. Start contouring.

    This is where we start contouring. For the sake of simplicity, we will just attempt to contour between 0 and 2000 units, with major contours every 50 units, and minor contours every 10 units.

    The for loop operates on each surface selected by the user, and runs the elementop.contour function on the surface. The elementop.contour function requires the start, end and step for the resulting contours. The results are stored back into the minor or major Python variables, which are a list of polyline/polygon Element objects.

    These objects can now be either stored back to a GeometryMob, or operated on further.

    It is important to remember that contours are not always exactly one single line per step. You can imagine a surface with two mountains on it that will result in two contours having the same elevation.

  4. Store our results.

    For the sake of simplicity, we will just store our contours into a MineSight® Object called \contours. If one already exists, this script will remove it prior to adding the new contours.

Summary

In order to start contouring with MineSight® Grail Embedded, you need to get a set of surface/solid Element objects, and put those objects through the grail.ms3d.elementop contour function.

The contour function requires a surface, start elevation, end elevation and a elevation step for your contours, and the contour operation will begin.

After you have all your contours you can store them or do further operations on them such as running the smooth_bezier function in grail.ms3d.elementop in order to smooth your results.