Beispiel #1
0
    def openBox(self, cmd):
        '''
    Open a bounding box

    '''
        from PyRatBox import PyRatBox
        box = PyRatBox(np.zeros(3), None)
        box.invisible = True
        box.empty = True
        self.top.contents.append(box)
        self.stack.append(self.top)
        self.top = self.top.contents[-1]

        self.verbose == 2 and sys.stderr.write('[%d}' % len(self.stack))
Beispiel #2
0
    def box(self, cmd):
        '''
    Open a solid box

    Start a new container box and push on stack
   
    box minx miny minz maxx maxy maxz 
    '''
        from PyRatBox import PyRatBox
        box = PyRatBox(
            np.array(cmd[1:1 + 3]).astype(float),
            np.array(cmd[4:4 + 3]).astype(float))
        box.invisible = False
        box.empty = False
        self.top.contents.append(box)

        self.verbose == 2 and sys.stderr.write('B' % len(self.stack))
Beispiel #3
0
    def __init__(self,
                 filename,
                 GL=False,
                 verbose=True,
                 reportingFrequency=10):
        self.setupDictionary()
        self.GL = hasGL and GL
        self.verbose = verbose
        self.reportingFrequency = reportingFrequency

        none = np.zeros(3)
        self.top = PyRatBox(none, none, material=None)
        self.top.invisible = True
        self.root = self.top
        self.root.defined = False
        self.root.invisible = True
        self.root.empty = False

        self.infinitePlane = []

        self.error = self.top.error

        # this is where we keep groups
        # we have to reconcile all of these as well as
        # the main object in case some of them
        # are #define'd
        self.group = {}

        self.stack = []
        self.point = []
        self.nPoints = 0
        if self.verbose:
            sys.stderr.write('Reading data from %s\n' % filename)
        self.read(filename)
        if self.verbose:
            sys.stderr.write('\n ... sorting bbox contents\n')
        if not self.root.isDefined():
            self.root = self.reconcile(self.root, 1)
        for i in self.group.keys():
            self.group[i] = self.reconcile(self.group[i], 1, defined=True)
        # reset the stack
        self.point = np.array(self.point)
        self.verbose = verbose
        self.reportingFrequency = 10
        if self.GL:
            self.triangleN = []
            self.triangleData = []
            if self.verbose:
                sys.stderr.write('\n ... sorting GL representation\n')
            self.GLobjects = []
            self.loadGL(self.root, np.eye(3), np.matrix(np.zeros(3)))
            for pl in self.infinitePlane:
                # how big to do an infinite plane then?
                pa = np.array([pl.base-self.root.min.copy(),pl.base-self.root.min.copy(),\
                               pl.base-self.root.max.copy(),pl.base-self.root.max.copy()])
                pa[:, 2] = 0.
                pa[1, 1] = pa[3, 1]
                pa[2, 1] = pa[0, 1]
                NN = len(self.triangleData)
                for i in xrange(4):
                    pa[i, 2] = -1. * dot(pa[i], pl.normal) / pl.normal[2]
                    self.triangleData.append(pl.base - pa[i])
                self.triangleN.append([NN + 0, NN + 1, NN + 3])
                self.triangleN.append([NN + 3, NN + 2, NN + 0])
            if len(self.triangleData):
                self.GLobjects.append(
                    Facet(coords=self.triangleData, indices=self.triangleN))