[Smtk-developers] New CGM operators

David Thompson david.thompson at kitware.com
Thu Nov 13 14:49:00 EST 2014


Hi all,

I've added a batch of new CGM operators to SMTK (and fixed a few things in the process). The operators include:

- create vertex
- create edge (straight, arc, ellipse, parabola, hyperbola... but only straight and arc are tested)
- create face (planar or "best fit" -- which is a synonym for planar as far as I can tell)
- create cylinder
- create brick
- create sphere
- create prism
- union (a boolean, but only tested in a simple case)
- read (from a file supported by CGM)

There are examples of the operators in the smtk/bridge/cgm/testing/python directory.

Some notes:

1. The "create brick" operator is interesting because it demonstrates conditional items.
2. the "union" operator is interesting because it expects the models you wish to unite to be associated with it rather than passed in via an smtk::attribute::ModelEntityItem.
3. The edge and face creation operators currently take vertices and edges to connect as input items, but will probably move to using an association in the future.
4. Yumin has discovered that the union operator exposes an issue in the model manager... the result of the operation does not appear to be properly transcribed when using a forwarding bridge.
5. Some of the operator XML descriptions are marked as requiring a "b" association. This is a new type of association and indicates that the operator should be associated to a bridge session. Creation operators in general should have this type of association so that the user can choose which session/kernel to use.

	David

PS. As an example, the Python script below created the 4 vertices, 6 edges, and 3 faces in the screenshot.

import smtk
mgr = smtk.model.Manager.create()
sess = mgr.createSession('cgm')
brg = sess.bridge()

def setCoord(x,v):
  for i in range(len(v)):
    x.setValue(i,v[i])

def setEntitiesByIndex(p,ep,v):
  for i in range(len(ep)):
    p.setValue(i, v[ep[i]])

verts = []
edges = []
faces = []
volus = []

# Create vertices
pcoords = [ (0,0,0), (1,0,0), (0,1,0), (0,0,1)]
crv = sess.op('create vertex')
x = crv.findAsDouble('point')
c = crv.findAsInt('color')
c.setValue(0, 1)
for pt in pcoords:
  setCoord(x,pt);
  verts.append(crv.operate().findModelEntity('vertex').value(0))

# Create edges
epts = [(0,1), (0,2), (0,3), (1,2), (1,3), (2,3)]
cre = sess.op('create edge')
t = cre.findAsInt('curve type')
t.setValue(0,6) # 6 == line segment in OpenCascade
v = cre.findAsModelEntity('vertices')
x = cre.findAsDouble('point')
c = cre.findAsInt('color')
c.setValue(0, 2)
for epair in epts:
  setEntitiesByIndex(v,epair,verts)
  if epair == (2,3):
    # Make the last edge an arc:
    t.setValue(0,1) # 1 == arc
    setCoord(x,[0,0.6,0.6]) # third point on arc
  edges.append(cre.operate().findModelEntity('edge').value(0))

# Create faces
fedg = [
    (12, 0, 3, 1),
    (12, 0, 4, 2),
    (16, 1, 5, 2)
    ]
#   (16, 3, 5, 4) # <-- OpenCascade cannot infer that this face should be cylindrical
crf = sess.op('create face')
t = crf.findAsInt('surface type')
t.setValue(0, 12)
e = crf.findAsModelEntity('edges')
c = crf.findAsInt('color')
c.setValue(0, 3)
for face in fedg:
  e.setNumberOfValues(len(face)-1)
  setEntitiesByIndex(e,face[1:],edges)
  t.setValue(face[0]) # These values are OpenCascade enum values.
  faces.append(crf.operate().findModelEntity('face').value(0))

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/smtk-developers/attachments/20141113/8f9a82eb/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SMTK geometry creation.png
Type: image/png
Size: 15267 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/smtk-developers/attachments/20141113/8f9a82eb/attachment-0001.png>


More information about the Smtk-developers mailing list