def SingleTriCut(self, ztcuts, hitstack, tbar, x, y):
     assert tbar.nodeback.p.x <= tbar.nodefore.p.x 
     if x < tbar.nodeback.p.x:
         return
     tbar1 = tbar.barforeright
     assert tbar1.nodeback.p.x <= tbar1.nodefore.p.x 
     if tbar1.nodeback == tbar.nodefore:
         assert tbar.nodeback.p.x <= tbar1.nodefore.p.x
         if x < tbar.nodefore.p.x:
             tbarA = tbar
         elif x < tbar1.nodefore.p.x:
             tbarA = tbar1
         else:
             return
         tbarB = tbar1.barforeright
         assert tbarB.nodeback == tbar.nodeback
     else:
         if x < tbar.nodefore.p.x:
             tbarA = tbar
         else:
             return
         assert tbar1.nodeback.p.x >= tbar.nodeback.p.x
         if x < tbar1.nodeback.p.x:
             tbarB = tbar1.barbackleft
             assert tbarB.nodeback == tbar.nodeback
         else:
             tbarB = tbar1
     lamA, cyA = self.BarLowerSide(hitstack, tbarA, x)
     lamB, cyB = self.BarLowerSide(hitstack, tbarB, x)
     if (y < cyA) != (y < cyB):
         czA = Along(lamA, tbarA.nodeback.p.z, tbarA.nodefore.p.z)
         czB = Along(lamB, tbarB.nodeback.p.z, tbarB.nodefore.p.z)
         lamY = (y - cyA)/(cyB - cyA)
         ztcut = Along(lamY, czA, czB)
         ztcuts.append(ztcut)
Beispiel #2
0
    def CalcPixelYcuts(self, z, tbm):
        tbarpairs = []
        barcuts = {}
        for bar in tbm.bars:  # bucketing could speed this up
            assert bar.nodeback.p.z <= bar.nodefore.p.z
            if bar.nodeback.p.z <= z < bar.nodefore.p.z:
                bar1 = bar.barforeright
                node2 = bar1.GetNodeFore(bar1.nodeback == bar.nodefore)
                barC = bar1 if node2.p.z <= z else bar1.GetForeRightBL(
                    bar1.nodeback == bar.nodefore)
                tbarpairs.append((bar.i, barC.i))

                lam = (z - bar.nodeback.p.z) / (bar.nodefore.p.z -
                                                bar.nodeback.p.z)
                cx = Along(lam, bar.nodeback.p.x, bar.nodefore.p.x)
                cy = Along(lam, bar.nodeback.p.y, bar.nodefore.p.y)
                barcuts[bar.i] = P2(cx, cy)

        ycuts = [[] for iy in range(self.ypixels.nparts)
                 ]  # plural for set of all raster rows
        for i, i1 in tbarpairs:
            p0, p1 = barcuts[i], barcuts[i1]
            iyl, iyh = self.ypixmidsE.GetPartRange(min(p0.v, p1.v),
                                                   max(p0.v, p1.v))
            for iy in range(iyl, iyh):
                yc = self.ypixmidsE.vs[iy + 1]
                assert (p0.v < yc) != (p1.v < yc)
                lam = (yc - p0.v) / (p1.v - p0.v)
                xc = Along(lam, p0.u, p1.u)
                ycuts[iy].append(xc)

        return ycuts
 def BarLowerSide(self, hitstack, bar, x):
     if self.hitreg[bar.i] < self.nhitreg:
         assert bar.nodeback.p.x <= x < bar.nodefore.p.x
         lam = (x - bar.nodeback.p.x)/(bar.nodefore.p.x - bar.nodeback.p.x)
         cy = Along(lam, bar.nodeback.p.y, bar.nodefore.p.y)
         self.hitreg[bar.i] = len(hitstack) + self.nhitreg
         hitstack.append((lam, cy))
         assert (lam, cy) == hitstack[self.hitreg[bar.i] - self.nhitreg]
     else:
         lam, cy = hitstack[self.hitreg[bar.i] - self.nhitreg]
     return lam, cy
Beispiel #4
0
    def makesplitnodes(self, btop, bm, lamendgap):
        if btop:
            ktnode, ktbar, ktbarlam = self.ktnodetop, self.ktbartop, self.ktbartoplam
        else:
            ktnode, ktbar, ktbarlam = self.ktnodebot, self.ktbarbot, self.ktbarbotlam
        assert not ktbar.bbardeleted
        ktnodefore = ktbar.GetNodeFore(ktbar.nodeback == ktnode)

        if lamendgap < ktbarlam < 1 - lamendgap:
            splitnode = bm.InsertNodeIntoBarF(
                ktbar, bm.NewNode(Along(ktbarlam, ktnode.p, ktnodefore.p)),
                True)
            assert ktbar.bbardeleted
            leadsplitbar = ktbar.GetForeRightBL(ktnode == ktbar.nodefore)
            assert not leadsplitbar.bbardeleted
            bnewnode = True

        else:
            if ktbarlam < 0.5:
                splitnode = ktnode
                if ktnode == ktbar.nodeback:
                    leadsplitbar = ktbar.GetBarBackRight()
                else:
                    leadsplitbar = ktbar.GetBarForeLeft()
                assert splitnode == leadsplitbar.nodeback or splitnode == leadsplitbar.nodefore
            else:
                splitnode = ktnodefore
                leadsplitbar = ktbar
                assert splitnode == leadsplitbar.nodeback or splitnode == leadsplitbar.nodefore
            bnewnode = False

        if btop:
            self.leadsplitbartop, self.splitnodetop = leadsplitbar, splitnode
            assert self.splitnodetop == self.leadsplitbartop.nodeback or self.splitnodetop == self.leadsplitbartop.nodefore
            self.bsplitnnodetopnew = bnewnode
        else:
            self.leadsplitbarbot, self.splitnodebot = leadsplitbar, splitnode
            assert self.splitnodebot == self.leadsplitbarbot.nodeback or self.splitnodebot == self.leadsplitbarbot.nodefore
            self.bsplitnnodebotnew = bnewnode
        return bnewnode
Beispiel #5
0
    def splitbarsdirectionchangesR(self, barstosplit):
        barsplitsdc = []
        bsdsq = self.barsplitdelta * self.barsplitdelta
        for bar in barstosplit:
            if bar.bbardeleted:
                continue
            if not ((bar.nodeback.pointzone.izone == barmesh.PZ_BEYOND_R) and
                    (bar.nodefore.pointzone.izone == barmesh.PZ_BEYOND_R)):
                continue
            vb = bar.nodefore.p - bar.nodeback.p
            vbsq = vb.Lensq()
            if vbsq < bsdsq:
                continue
            lamclossplit = -1
            dvbsq = -1
            if bar.nodeback.pointzone.v is not None:
                lampcb = P3.Dot(bar.nodeback.pointzone.v, vb) / vbsq
                if 0 < lampcb < 1:
                    dvb = bar.nodeback.pointzone.v - vb * lampcb
                    assert abs(P3.Dot(dvb, vb)) < 0.001
                    dvbsq = dvb.Lensq()
                    if dvbsq < self.rdsq:
                        lamclossplit = lampcb

            if bar.nodefore.pointzone.v is not None:
                lampcf = -P3.Dot(bar.nodefore.pointzone.v, vb) / vbsq
                if 0 < lampcf < 1:
                    dvf = bar.nodefore.pointzone.v + vb * lampcf
                    assert abs(P3.Dot(dvf, vb)) < 0.001
                    dvfsq = dvf.Lensq()
                    if dvfsq < self.rdsq:
                        if lamclossplit == -1 or dvfsq < dvbsq:
                            lamclossplit = 1 - lampcf

            if lamclossplit != -1:
                barsplitsdc.append((bar, lamclossplit))

        # split the bars
        nowsplitbars = []
        splitnodes = []
        for bar, lamc in barsplitsdc:
            splitnode = self.bm.InsertNodeIntoBarF(
                bar,
                self.bm.NewNode(Along(lamc, bar.nodeback.p, bar.nodefore.p)),
                True)
            assert bar.bbardeleted
            splitnodes.append(splitnode)
            nowsplitbars.append(bar.barforeright)
            nowsplitbars.append(bar.barbackleft)

        # make the measurements on all the new splitnodes
        self.MakePointZoneRFS(splitnodes)

        # make the measurements on all the new bars
        newbarpolycuts = []
        for bar in nowsplitbars:
            if IsCutBar(bar, barmesh.PZ_BEYOND_R):
                newbarpolycuts.append(bar)

        self.CutbarRFS(newbarpolycuts)
        #print("splitbarsdirectionchanges", len(barstosplit), len(nowsplitbars))
        return nowsplitbars
Beispiel #6
0

tbarmesh = TriangleBarMesh(fname, spinztox)
#sendactivity("clearalltriangles")
#sendactivity(codetriangles=tbarmesh.GetBarMeshTriangles())
trizcut = TriZCut(tbarmesh)  # this is slow because it builds the boxing

ypixes = Partition1(tbarmesh.ylo - 0.2, tbarmesh.yhi + 0.2, bitmapy - 1)
zpix0 = tbarmesh.zlo - 0.1
zfactopix = ypixes.nparts / (ypixes.vs[-1] - ypixes.vs[0])
#zfactopix *= 0.5

# this is in Z (note rotation by spinztox)
# (here we can make a loop for each slice)
for ix in range(0, 51):
    lx = ix / 50.0
    xslice = Along(lx, tbarmesh.xlo, tbarmesh.xhi)

    fname = "/home/goatchurch/geom3d/bitmapslices/whistle/slice%05d.png" % int(
        xslice * 1000)
    pngslice = PNGslice(fname, bitmapx, bitmapy)
    for iy, y in enumerate(ypixes.vs):
        ztcuts = trizcut.TriSurfCut(xslice, y)
        ztcuts.sort()
        pngslice.AddRow([
            max(0, min(bitmapx, int((zt - zpix0) * zfactopix)))
            for zt in ztcuts
        ])
    pngslice.done()
    print(time.time() - tstart, fname)
Beispiel #7
0
bitmapy = 1140

def spinztox(t):
    return (t[2], t[1], -t[0])
tbarmesh = TriangleBarMesh(fname, spinztox)
#sendactivity("clearalltriangles")
#sendactivity(codetriangles=tbarmesh.GetBarMeshTriangles())
trizcut = TriZCut(tbarmesh)  # this is slow because it builds the boxing

ypixes = Partition1(tbarmesh.ylo-0.2, tbarmesh.yhi+0.2, bitmapy-1)
zpix0 = tbarmesh.zlo - 0.1
zfactopix = ypixes.nparts/(ypixes.vs[-1] - ypixes.vs[0])

# this is in Z (note rotation by spinztox)
# (here we can make a loop for each slice)
xslice = Along(0.5, tbarmesh.xlo, tbarmesh.xhi)  

imgslice = Image.new("1", (bitmapx, bitmapy), 255)
imgslicedr = ImageDraw.Draw(imgslice)

for iy, y in enumerate(ypixes.vs):
    ztcuts = trizcut.TriSurfCut(xslice, y)
    ztcuts.sort()
    for i in range(1, len(ztcuts), 2):
        z0 = int((ztcuts[i-1] - zpix0)*zfactopix + 0.5)
        z1 = int((ztcuts[i] - zpix0)*zfactopix + 0.5)
        imgslicedr.line([z0,iy,z1,iy], 0)  # horizontal line
    #sendactivity(points=[(xslice, ypix, z)  for z in ztcuts])
    print(iy, len(ztcuts))
    
#imgslice.show()