<commit_before># standard python modules
import re

# extensions
import vtk
import numpy

from icqBaseShape import BaseShape

class CompositeShape(BaseShape):

  def __init__(self,):
    """
    Constructor
    """
    BaseShape.__init__(self,)

    self.expression = ''
    self.argShapes = []

  def assemble(self, expression, shapes):
    """
    Assemble shapes into a composite object
    @param expression expression of the shape objects, $0 for shape 0, $1 for shape 1, etc. 
           operations include + (union), * (intersection), and - (removal)
    """
    self.expression = expression
    self.argShapes = shapes
    # replace $1 by self.argShape[0]
    for i in range(len(self.argShapes)):
      self.expression = re.sub('\${0}'.format(i), 
        'self.argShapes[{0}].evaluate(pts)'.format(i), self.expression)

  def evaluate(self, pts):
    """
    Evaluate the inside/outside function 
    @param pts array of points
    """
    return eval(self.expression)

  def computeSurfaceMeshes(self, maxTriArea):
    """
    Compute the surface meshes
    @param maxTriArea maximum triangle area
    """

    # get the bounds
    loBound, hiBound = self._getBounds()

    # get the optimal number of cells in each direction
    nx, ny, nz = self._getUniformGridResolution(loBound, hiBound, maxTriArea)
    nx1, ny1, nz1 = nx + 1, ny + 1, nz + 1

    x = loBound[0] + (hiBound[0] - loBound[0])*numpy.array([i for i in range(nx1)])/nx
    y = loBound[1] + (hiBound[1] - loBound[1])*numpy.array([j for j in range(ny1)])/ny
    z = loBound[2] + (hiBound[2] - loBound[2])*numpy.array([i for k in range(nz1)])/nz
    xxx = numpy.outer(numpy.ones((nz1, ny1)), x)
    yyy = numpy.outer(numpy.outer(numpy.ones((nz1,)), y), numpy.ones((nx1,)))
    zzz = numpy.outer(z, numpy.ones((ny1, nx1)))
    verts = numpy.zeros( (nz1*ny1*nx1, 3), numpy.float64 )
    verts[:, 0] = xxx.flat
    verts[:, 1] = yyy.flat
    verts[:, 2] = zzz.flat

    insideVals = self.evaluate(verts)

    # build the VTK contour pipeline
    xyz = vtk.vtkDoubleArray()
    pts = vtk.vtkPoints()
    data = vtk.vtkDoubleArray()
    grd = vtk.vtkStructuredGrid()
    cont = vtk.vtkContourFilter()

    numPoints = nx1*ny1*nz1
    xyz.SetNumberOfTuples(numPoints)
    xyz.SetNumberOfComponents(3)
    xyz.SetVoidArray(verts, numPoints*3, 1)

    data.SetNumberOfTuples(numPoints)
    data.SetNumberOfComponents(1)
    data.SetVoidArray(insideVals, numPoints*3, 1)

    grd.SetDimensions(nz1, ny1, nx1)
    grd.SetPoints(pts)
    grd.GetPointData().SetScalars(data)

    cont.SetInputConnection(grd.GetOutputPort())
    cont.SetValue(0, 0.0) # or should it be 0.5?
    cont.Update()

    pdata = cont.GetOutput()
    print pdata

  def _getBounds(self,):
    """
    Compute the min/max corner points
    """
    loBound = numpy.array([float('inf')] * 3)
    hiBound = numpy.array([-float('inf')] * 3)
    for shp in self.argShapes:
      points = shp.getPoints()
      loBound[0] = min(loBound[0], points[:, 0].min())
      loBound[1] = min(loBound[1], points[:, 1].min())
      loBound[2] = min(loBound[2], points[:, 2].min())
      hiBound[0] = max(hiBound[0], points[:, 0].min())
      hiBound[1] = max(hiBound[1], points[:, 1].min())
      hiBound[2] = max(hiBound[2], points[:, 2].min())
    return loBound, hiBound
<commit_msg> bug fix<commit_after># standard python modules
import re

# extensions
import vtk
import numpy

from icqBaseShape import BaseShape

class CompositeShape(BaseShape):

  def __init__(self,):
    """
    Constructor
    """
    BaseShape.__init__(self,)

    self.expression = ''
    self.argShapes = []

  def assemble(self, expression, shapes):
    """
    Assemble shapes into a composite object
    @param expression expression of the shape objects, $0 for shape 0, $1 for shape 1, etc. 
           operations include + (union), * (intersection), and - (removal)
    """
    self.expression = expression
    self.argShapes = shapes
    # replace $1 by self.argShape[0]
    for i in range(len(self.argShapes)):
      self.expression = re.sub('\${0}'.format(i), 
        'self.argShapes[{0}].evaluate(pts)'.format(i), self.expression)

  def evaluate(self, pts):
    """
    Evaluate the inside/outside function 
    @param pts array of points
    """
    return eval(self.expression)

  def computeSurfaceMeshes(self, maxTriArea):
    """
    Compute the surface meshes
    @param maxTriArea maximum triangle area
    """

    # get the bounds
    loBound, hiBound = self._getBounds()

    # get the optimal number of cells in each direction
    nx, ny, nz = self._getUniformGridResolution(loBound, hiBound, maxTriArea)
    nx1, ny1, nz1 = nx + 1, ny + 1, nz + 1

    x = loBound[0] + (hiBound[0] - loBound[0])*numpy.array([i for i in range(nx1)])/nx
    y = loBound[1] + (hiBound[1] - loBound[1])*numpy.array([j for j in range(ny1)])/ny
    z = loBound[2] + (hiBound[2] - loBound[2])*numpy.array([i for k in range(nz1)])/nz
    xxx = numpy.outer(numpy.ones((nz1, ny1)), x)
    yyy = numpy.outer(numpy.outer(numpy.ones((nz1,)), y), numpy.ones((nx1,)))
    zzz = numpy.outer(z, numpy.ones((ny1, nx1)))
    verts = numpy.zeros( (nz1*ny1*nx1, 3), numpy.float64 )
    verts[:, 0] = xxx.flat
    verts[:, 1] = yyy.flat
    verts[:, 2] = zzz.flat

    insideVals = self.evaluate(verts)

    # build the VTK contour pipeline
    xyz = vtk.vtkDoubleArray()
    pts = vtk.vtkPoints()
    data = vtk.vtkDoubleArray()
    grd = vtk.vtkStructuredGrid()
    cont = vtk.vtkContourFilter()

    numPoints = nx1*ny1*nz1
    xyz.SetNumberOfTuples(numPoints)
    xyz.SetNumberOfComponents(3)
    xyz.SetVoidArray(verts, numPoints*3, 1)

    data.SetNumberOfTuples(numPoints)
    data.SetNumberOfComponents(1)
    data.SetVoidArray(insideVals, numPoints*3, 1)

    grd.SetDimensions(nz1, ny1, nx1)
    grd.SetPoints(pts)
    grd.GetPointData().SetScalars(data)

    print dir(grd)
    if vtk.VTK_MAJOR_VERSION >= 6:
      cont.SetInputData(grd)
    else:
      cont.SetInput(grd)
    cont.SetValue(0, 0.0) # or should it be 0.5?
    cont.Update()

    pdata = cont.GetOutput()
    print pdata

  def _getBounds(self,):
    """
    Compute the min/max corner points
    """
    loBound = numpy.array([float('inf')] * 3)
    hiBound = numpy.array([-float('inf')] * 3)
    for shp in self.argShapes:
      points = shp.getPoints()
      loBound[0] = min(loBound[0], points[:, 0].min())
      loBound[1] = min(loBound[1], points[:, 1].min())
      loBound[2] = min(loBound[2], points[:, 2].min())
      hiBound[0] = max(hiBound[0], points[:, 0].min())
      hiBound[1] = max(hiBound[1], points[:, 1].min())
      hiBound[2] = max(hiBound[2], points[:, 2].min())
    return loBound, hiBound

{'fraction_non_alphanumeric': 0.1518285371702638, 'fraction_numerical': 0.023531175059952038, 'mean_word_length': 3.1758448060075093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5268748', 'n_tokens_mistral': 2524, 'n_tokens_neox': 2386, 'n_words': 549}