def unitSquare():
    """Return square composed of 2 facets in the xy plane, centered at zero with unit extents."""
    import gts
    vv = [
        gts.Vertex(1, 1, 0),
        gts.Vertex(-1, 1, 0),
        gts.Vertex(-1, -1, 0),
        gts.Vertex(1, -1, 0)
    ]
    ee = [
        gts.Edge(vv[0], vv[1]),
        gts.Edge(vv[1], vv[2]),
        gts.Edge(vv[2], vv[3]),
        gts.Edge(vv[3], vv[0]),
        gts.Edge(vv[0], vv[2])
    ]
    surf = gts.Surface()
    surf.add(gts.Face(ee[0], ee[1], ee[4]))
    surf.add(gts.Face(ee[2], ee[3], ee[4]))
    return surf
Exemple #2
0
def test_tetrahedron():
    """
    A tetrahedron is assembled from these primitives as follows.  
    First, create Vertices for each of the tetrahedron's points:
    """
    v1 = gts.Vertex(1, 1, 1)
    v2 = gts.Vertex(-1, -1, 1)
    v3 = gts.Vertex(-1, 1, -1)
    v4 = gts.Vertex(1, -1, -1)
    """
    Next, connect the four vertices to create six unique Edges:
    """
    e1 = gts.Edge(v1, v2)
    e2 = gts.Edge(v2, v3)
    e3 = gts.Edge(v3, v1)
    e4 = gts.Edge(v1, v4)
    e5 = gts.Edge(v4, v2)
    e6 = gts.Edge(v4, v3)
    """
    The four triangular faces are composed using three edges each:
    """
    f1 = gts.Face(e1, e2, e3)
    f2 = gts.Face(e1, e4, e5)
    f3 = gts.Face(e2, e5, e6)
    f4 = gts.Face(e3, e4, e6)
    """
    Finally, the surface is assembled from the faces.
    Some care must be taken in the orientation of the faces.  
    In the above example, the surface normals are pointing inward, 
    and so the surface technically defines a void, rather than a solid.  
    To create a tetrahedron with surface normals pointing outward, 
    use the following instead:
    """
    s = gts.Surface()
    for face in [f1, f2, f3, f4]:
        if not face.is_compatible(s):
            face.revert()
        s.add(face)

    print s.volume()
    print s.center_of_mass()
Exemple #3
0
 def MakeVertexMap(self):
     # pre-create all of our vertex objects.  I was having a hard time
     # getting GTS to collapse my intersecting edges.  Re-using the same
     # vector object for each edge seems to have solved the problem.
     # However, the issue might've been my normal vectors, so I'm not
     # 100% certain.
     self.top = []  # all the vertexes on the front of the plaque
     self.bottom = []  # all the vertexes on the back of the plaque
     for x in range(0, self.pixels_x):
         col = []  # column of top-face points
         bcol = []  # column of back-face points
         for y in range(0, self.pixels_y):
             pz = self.y_to_pz(y)
             px = self.x_to_px(x)
             py = self.GetDisplacement(x, y)
             if py < 0.0:
                 py = 0.0
             print 'make.top', x, y, py
             col.append(gts.Vertex(px, -pz, py))
             bcol.append(gts.Vertex(px, -pz, 0.0))
         # append:
         self.top.append(col)
         self.bottom.append(bcol)
Exemple #4
0
def sweptPolylines2gtsSurface(pts,threshold=0,capStart=False,capEnd=False):
	"""Create swept suface (as GTS triangulation) given same-length sequences of points (as 3-tuples).

If threshold is given (>0), then

* degenerate faces (with edges shorter than threshold) will not be created
* gts.Surface().cleanup(threshold) will be called before returning, which merges vertices mutually closer than threshold. In case your pts are closed (last point concident with the first one) this will the surface strip of triangles. If you additionally have capStart==True and capEnd==True, the surface will be closed.

.. note:: capStart and capEnd make the most naive polygon triangulation (diagonals) and will perhaps fail for non-convex sections.

.. warning:: the algorithm connects points sequentially; if two polylines are mutually rotated or have inverse sense, the algorithm will not detect it and connect them regardless in their given order.
	"""
	import gts # will raise an exception in gts-less builds
	if not len(set([len(pts1) for pts1 in pts]))==1: raise RuntimeError("Polylines must be all of the same length!")
	vtxs=[[gts.Vertex(x,y,z) for x,y,z in pts1] for pts1 in pts]
	sectEdges=[[gts.Edge(vtx[i],vtx[i+1]) for i in range(0,len(vtx)-1)] for vtx in vtxs]
	interSectEdges=[[] for i in range(0,len(vtxs)-1)]
	for i in range(0,len(vtxs)-1):
		for j in range(0,len(vtxs[i])):
			interSectEdges[i].append(gts.Edge(vtxs[i][j],vtxs[i+1][j]))
			if j<len(vtxs[i])-1: interSectEdges[i].append(gts.Edge(vtxs[i][j],vtxs[i+1][j+1]))
	if threshold>0: # replace edges of zero length with None; their faces will be skipped
		def fixEdges(edges):
			for i,e in enumerate(edges):
				if (Vector3(e.v1.x,e.v1.y,e.v1.z)-Vector3(e.v2.x,e.v2.y,e.v2.z)).norm()<threshold: edges[i]=None
		for ee in sectEdges: fixEdges(ee)
		for ee in interSectEdges: fixEdges(ee)
	surf=gts.Surface()
	for i in range(0,len(vtxs)-1):
		for j in range(0,len(vtxs[i])-1):
			ee1=interSectEdges[i][2*j+1],sectEdges[i+1][j],interSectEdges[i][2*j]
			ee2=sectEdges[i][j],interSectEdges[i][2*j+2],interSectEdges[i][2*j+1]
			if None not in ee1: surf.add(gts.Face(interSectEdges[i][2*j+1],sectEdges[i+1][j],interSectEdges[i][2*j]))
			if None not in ee2: surf.add(gts.Face(sectEdges[i][j],interSectEdges[i][2*j+2],interSectEdges[i][2*j+1]))
	def doCap(vtx,edg,start):
		ret=[]
		eFan=[edg[0]]+[gts.Edge(vtx[i],vtx[0]) for i in range(2,len(vtx))]
		for i in range(1,len(edg)):
			ret+=[gts.Face(eFan[i-1],eFan[i],edg[i]) if start else gts.Face(eFan[i-1],edg[i],eFan[i])]
		return ret
	caps=[]
	if capStart: caps+=doCap(vtxs[0],sectEdges[0],start=True)
	if capEnd: caps+=doCap(vtxs[-1],sectEdges[-1],start=False)
	for cap in caps: surf.add(cap)
	if threshold>0: surf.cleanup(threshold)
	return surf
Exemple #5
0
    def data(self, text):
        """
Call back for content between nodes. For vertex data this converts the text
into the appropriate objects from the gts library. For indice data the text is
split and converted into integers to be used as [index] lookups.
		"""
        # ignore white space
        text = text.strip()
        if 0 == len(text):
            return

        if 'vertices' == self.current_node:
            point = []
            for vextex in text.split():
                point.append(float(vextex))

                if 3 == len(point):
                    self.vertices.append(
                        gts.Vertex(point[0], point[1], point[2]))
                    point = []

        if 'indices' == self.current_node:
            for index in text.split():
                self.indices.append(int(index))
import numpy as np
#import math

# angle of the crack with the horizontal (degrees)
#sc=0.0125
#sp=6
#Rmean=sc*100000.**(1./3)
#alpha_patch=45.

alpha = math.radians(alpha_patch)
radius = sp * sc / 2.
discret = 50
center = np.array(PP)

# creation des vertices des triangles
pcenter = gts.Vertex(center[0] * X, center[1] * Y, center[2] * Z)
pt = []

angle_step = 2. * math.pi / (discret)
for i in list(range(discret)):
    x = radius * math.cos(i * angle_step)
    y = radius * math.sin(i * angle_step)
    z = 0.
    pt.append(
        gts.Vertex(center[0] * X + x, center[1] * Y + math.cos(alpha) * y,
                   center[2] * Z + math.sin(alpha) * y))

# creation des edges des triangles
edge = []
for i in list(range(discret)):
    if i == discret - 1:
Exemple #7
0
nSpheres = 1500.0
poros = 0.13  # apparently the value of porosity of samples generated by pack.randomDensePack
rMeanSpheres = pow(Lx * Ly * Lz * 3.0 / 4.0 * (1 - poros) / (pi * nSpheres),
                   1.0 / 3.0)
print('\nGenerating sphere sample, be patient')
sp = pack.randomDensePack(pred,
                          radius=rMeanSpheres,
                          rRelFuzz=0.3,
                          memoizeDb='/tmp/gts-triax-packings.sqlite',
                          returnSpherePack=True)
sp.toSimulation(color=(0.9, 0.8, 0.6), wire=False, material=mat)
print('Sphere sample generated !')

# --- The joint surface : half of the height
import gts
v1 = gts.Vertex(0, 0, Lz / 2.0)
v2 = gts.Vertex(Lx, 0, Lz / 2.0)
v3 = gts.Vertex(Lx, Ly, Lz / 2.0)
v4 = gts.Vertex(0, Ly, Lz / 2.0)

e1 = gts.Edge(v1, v2)
e2 = gts.Edge(v2, v4)
e3 = gts.Edge(v4, v1)
f1 = gts.Face(e1, e2, e3)

e4 = gts.Edge(v4, v3)
e5 = gts.Edge(v3, v2)
f2 = gts.Face(e2, e4, e5)

s1 = gts.Surface()
s1.add(f1)
Exemple #8
0
)
print('')
sp = pack.randomDensePack(pred,
                          radius=rMeanSpheres,
                          rRelFuzz=0.3,
                          memoizeDb='/tmp/gts-triax-packings.sqlite',
                          returnSpherePack=True)
sp.toSimulation(color=(0.9, 0.8, 0.6), wire=False, material=mat)
print('')
print('Sample created !')

# Definition of the facets for joint's geometry

import gts
# joint with ~ 31 deg. dip angle
v1 = gts.Vertex(0, 0, 0.8 * dimModele)
v2 = gts.Vertex(0, dimModele, 0.8 * dimModele)
v3 = gts.Vertex(dimModele, dimModele, 0.2 * dimModele)
v4 = gts.Vertex(dimModele, 0, 0.2 * dimModele)

e1 = gts.Edge(v1, v2)
e2 = gts.Edge(v2, v4)
e3 = gts.Edge(v4, v1)
f1 = gts.Face(e1, e2, e3)

e4 = gts.Edge(v4, v3)
e5 = gts.Edge(v3, v2)
f2 = gts.Face(e2, e4, e5)

s1 = gts.Surface()
s1.add(f1)
Exemple #9
0
         [27, 29, 31], [32, 33, 34], [34, 33, 35], [36, 37, 38], [38, 37, 39],
         [32, 33, 36], [36, 33, 37], [34, 35, 38], [38, 35, 39], [32, 34, 36],
         [36, 34, 38], [33, 35, 37], [37, 35, 39]],
        dtype=int32)

    #    x = tuple(v[0] for v in vertices)
    #    y = tuple(v[1] for v in vertices)
    #    z = tuple(v[2] for v in vertices)
    #
    #    t = tuple((i[0],i[1],i[2]) for i in indices)
    #
    #    mlab.triangular_mesh(x,y,z,t,color=(0.8,0.8,0.8))
    #    mlab.triangular_mesh(x,y,z,t,color=(0,0,1),representation='fancymesh',
    #                         scale_factor=.00000001)
    #    mlab.show()
    vertices_gts = [gts.Vertex(v[0], v[1], v[2]) for v in vertices]
    edges_gts = []
    faces_gts = []
    for tri in indices:
        #print tri,
        edges_gts.append(gts.Edge(vertices_gts[tri[0]], vertices_gts[tri[1]]))
        edges_gts.append(gts.Edge(vertices_gts[tri[1]], vertices_gts[tri[2]]))
        edges_gts.append(gts.Edge(vertices_gts[tri[2]], vertices_gts[tri[0]]))
        faces_gts.append(gts.Face(edges_gts[-3], edges_gts[-2], edges_gts[-1]))
#    for i in xrange(0,len(edges_gts),3):
#        faces_gts.append(gts.Face(edges_gts[i],edges_gts[i+1],edges_gts[i+2]))

    s = gts.Surface()
    for face in faces_gts:
        #if not face.is_compatible(s):
        #    face.revert()