What Have You Done Today - (Computer Version)

  • Thread starter tlowr4
  • 4,135 comments
  • 257,411 views
Today I wrote a marching squares algorithm in Python, for creating contour maps.

screen (1).png


Edit: Marching squares upgraded to marching triangles! No more ambiguous saddle points :)

IMG_8327.JPG
 
Last edited:
I installed a third 8-port switch in my local network.
I need to get my network all sorted out. I have all the stuff bought, just need to switch over the phone jacks to network and get the switches in place.

I'd like to work on it this weekend but I'm betting my wife has other plans. :P
 
Edit: Marching squares upgraded to marching triangles! No more ambiguous saddle points :)

<Nitpicky> Saddle points are still there in the underlying height map, the ambiguity disappears only for the height interpolation over the triangle. ;) </Nitpicky> Looking forward to the code! :cheers:
 
<Nitpicky> Saddle points are still there in the underlying height map, the ambiguity disappears only for the height interpolation over the triangle. ;) </Nitpicky> Looking forward to the code! :cheers:

Well, to be nitpicky there is no ambiguity in the underlying height map since it only has height data for specific points and doesn't say anything about how the contours are shaped. The ambiguity is created by the marching squares because it's only at that point that you start making predictions about how the landscape is shaped ;)

Edit: The code.

Code:
class Coordinate():
    def __init__(self, x = None, y = None, z = None, radius = None, index = None, distance = None):
        self.x = x
        self.y = y
        self.z = z
        self.xyz = (x, y, z)
        self.radius = radius
        self.index = index
        self.distance = distance

Code:
class HeightMap():
    def __init__(self, flat, columns, rows, zmin, zmax, array, mapSize):
        self.flat = flat
        self.columns = columns
        self.rows = rows
        self.zmin = zmin
        self.zmax = zmax
        self.array = array
        self.mapSize = mapSize

    def fraction_to_meters(self, fraction):
        m_value = fraction * (self.zmax-self.zmin) + self.zmin
        return m_value

    def coord_to_fraction(self, x, y, output='f'):
        x+=self.mapSize/2
        y+=self.mapSize/2
        x_interval = self.mapSize / (self.columns-1)
        y_interval = self.mapSize / (self.rows-1)
        column = int(x//x_interval)
        row = int(y//y_interval)

        x1 = column*x_interval
        x2 = (column+1)*x_interval
        y1 = row*y_interval
        y2 = (row+1)*y_interval

        x_factor = (x-x1)/x_interval
        y_factor = (y-y1)/y_interval

        total_area = x_interval*y_interval
        a_area = x_interval*(1-x_factor)*y_interval*(1-y_factor)
        b_area = x_interval*x_factor*y_interval*(1-y_factor)
        c_area = x_interval*(1-x_factor)*y_interval*y_factor
        d_area = x_interval*x_factor*y_interval*y_factor  

        a_weight = a_area/total_area
        b_weight = b_area/total_area
        c_weight = c_area/total_area
        d_weight = d_area/total_area

        az = self.array[row][column]
        bz = self.array[row][column+1]
        cz = self.array[row+1][column]
        dz = self.array[row+1][column+1]

        z = az*a_weight+bz*b_weight+cz*c_weight+dz*d_weight

        if output == 'm':
            z = self.fraction_to_meters(z)
        return z

Code:
class TriCell():
    def __init__(self):
        self.a = None
        self.b = None
        self.c = None
        self.value = 0

    def evaluate(self, elevation):
        a = (self.a.z > elevation)*4
        b = (self.b.z > elevation)*2
        c = (self.c.z > elevation)*1

        self.value = sum([a, b, c])

    def interpolate(self, p0, p1, z):
        dx = p1.x-p0.x
        dy = p1.y-p0.y
        dz = p1.z-p0.z

        rel_z = z-p0.z
        if dz == 0:
            fraction = 0
        else:
            fraction = rel_z/dz

        x = p0.x+dx*fraction
        y = p0.y+dy*fraction

        return Coordinate(x, y, z)

    def line_coords(self, elevation):
        lines = []
        if self.value in (0, 7):
            return lines
       
        alfa = self.interpolate(self.a, self.b, elevation)
        beta = self.interpolate(self.b, self.c, elevation)
        gamma = self.interpolate(self.c, self.a, elevation)
       
        if self.value in (1,6):
            lines.append((beta, gamma))
        elif self.value in (2,5):
            lines.append((alfa, beta))
        elif self.value in (3,4):
            lines.append((alfa, gamma))

Code:
def contours(heightMap, size=100, _range=[-500,-500,500,500], step=None):
    '''For marching squares'''
    def make_cell():
        '''Generates a single cell'''
        ax = dx = columnStart+columnSize*column
        ay = by = rowStart+rowSize*row

        bx = cx = ax+columnSize
        cy = dy = ay+rowSize

        cell = Cell()
        cell.a = Coordinate(ax, ay)
        cell.b = Coordinate(bx, by)
        cell.c = Coordinate(cx, cy)
        cell.d = Coordinate(dx, dy)

        for corner in (cell.a, cell.b, cell.c, cell.d):
            get_corner_z(corner)
        cells.append(cell)

    def make_triangle_cell():
        '''Generates two triangle cells'''
        x0 = columnStart+columnSize*column
        y0 = rowStart+rowSize*row

        x1 = x0+columnSize
        y1 = y0+rowSize

        if row%2 == 0:
            ax = bx = x0
            cx = dx = x1
            bx += columnSize*0.5
            cx += columnSize*0.5
            ay = dy = y1
            by = cy = y0

        else:
            ax = dx = x0
            bx = cx = x1
            cx += columnSize*0.5
            dx += columnSize*0.5
            ay = by = y0
            cy = dy = y1

        a = Coordinate(ax, ay)
        b = Coordinate(bx, by)
        c = Coordinate(cx, cy)
        d = Coordinate(dx, dy)

        for corner in (a, b, d):
            get_corner_z(corner)

        cell1 = TriCell()
        cell1.a = a
        cell1.b = b
        cell1.c = d

        cells.append(cell1)

        if cx <= hm.mapSize/2:
            get_corner_z(c)

            cell2 = TriCell()
            cell2.a = b
            cell2.b = c
            cell2.c = d

            cells.append(cell2)    

    def get_corner_z(corner):
        '''Gets the z value for a cell corner'''
        global zmax, zmin
        corner.z = hm.coord_to_fraction(corner.x, corner.y, 'm')
        if zmax is None or corner.z > zmax:
            zmax = corner.z
        if zmin is None or corner.z < zmin:
            zmin = corner.z
        #print(column, row, corner.x, corner.y, corner.z, sep='\t')

    def print_cell_values():
        for row in range(divRow):
            this_row = []
            for column in range(divColumn):
                cellindex = row*divColumn+column
                cell = cells[cellindex]
                this_row.append(cell.value)
            print(*this_row, sep='\t')
        print('\n')
       
    # 1. Calculate cell size
    hm = heightMap
    if _range == None:
        r = hm.mapSize/2
        _range = [-r, -r, r, r]

    else:
        for i in range(4):
            if _range[i] < -hm.mapSize/2:
                _range[i] = -hm.mapSize/2
            elif _range[i] > hm.mapSize/2:
                _range[i] = hm.mapSize/2

    rowStart = int(_range[1])
    rowEnd = int(_range[3])
    rowLen = rowEnd - rowStart

    columnStart = int(_range[0])
    columnEnd = int(_range[2])
    columnLen = columnEnd - columnStart
   
    divRow = rowLen//size
    divColumn = columnLen//size
   
    rowSize = rowLen/divRow
    columnSize = columnLen/divColumn

    # 2. Sample the heightmap
    cells = []
    global zmax, zmin
    zmin = None
    zmax = None
    for row in range(divRow):
        for column in range(divColumn):
            make_triangle_cell()
            #make_cell()
           
    #print(zmin, zmax)
    # 3. subdivide range zmin, zmax to determine which lines to draw
    if step == None:
        lines, step, factor = subdivide(zmin, zmax, 10)
    else:
        lines, step, factor = subdivide(zmin, zmax, step=step)
    #print(*lines, sep='\t')

    # 4. Evaluate cells and get line coordinates
    lineDict = {}
    for elevation in lines:
        lineDict[elevation] = []
        for cell in cells:
            cell.evaluate(elevation)
            lineDict[elevation] += cell.line_coords(elevation)

    return lineDict, zmin, zmax

Code:
def subdivide(p0, p1, subdivisions=3, step=None, _range=None):
    '''Subdivides the distance p1-p0'''
   
    def stepFinder(n, subdivisions):
        '''Finds the step size'''
        #Find if n is negative
        sign = 1 - (n < 0)*2

        #List containing the available step factors
        factors = (1, 2, 2.5, 5)

        #Extract significand and potencia
        string = '%.1E' %(n/subdivisions)
        [significand, potencia] = [float(s) for s in string.split('E')]

        #Select step factor and return step size
        stepFactor = min(factors, key=lambda x:abs(x-abs(significand)))*sign
        step = stepFactor*10**potencia
        return step, stepFactor

    p0, p1 = sorted((p0, p1))
    n = p1-p0
    factor = None
    if step==None:
        step, factor = stepFinder(n, subdivisions)

    if _range==None:
        _range=(p0, p1)
    r0, r1 = _range[0], _range[1]
       
    offset = (r0//step)*step

    my_list = []
    i = 1
    while float(format(offset+i*step, 'g')) < r1:
        my_list.append(float(format(offset+i*step, 'g')))
        i += 1

    return my_list, step, factor
 
Last edited:
Finally got around to upgrading my PC, went from Intel Haswell to Kaby Lake, 8GB DDR3 to 32GB DDR4 RAM and made switch from a HDD to a NVME SSD as OS drive.

Also finished installing all games on Xbox One S external 2TB drive, shows that I've got over 140+ games. :crazy::scared:

Might start downloading all my Steam, Origin, Uplay and Windows games now on PC, my ISP will be happy. :lol: Probably be over 2TB download in less than a week.
 
More network than computer, but close enough.

My Series 2 TiVo will NOT connect to my new router (on either the secured 5G or 2.4) and I haven't had time to move the hutch out and change the cover plate to hardwire it yet so I threw in a switch and connected both the new router and old one. Not ideal having 3 SSIDs in the house, but at least everything works.
 
Updated my phone to Nougat, then tried changing the Data partition to F2FS. Ended up screwing up the filesystem, but I eventually managed to reinstall the ROM. I think I'll stay on Ext4 for now. :lol:

Edit: Apparently the Data partition is now F2FS. Nice.
 
Last edited:
I mostly have been testing out my new Turtle Beach 60P gaming headset. Unfortunately, I will need to get that PC splitter cable to be able to use this headset for PC gaming and for recording. It is a very nice headset. I want to be able to use this headset for PC gaming and even for maybe trying to start up doing a podcast or live stream audio. I otherwise will use this headset for PS3 gaming for now.


[UPDATE] No need to get the PC cable splitter! I took the advice of one website just to jack in the USB port to an available USB connection. I can now almost comfortably listen to media and even do some voice chatting with my Turtle Beach 60P. I don't really care about having amplified sound all that much. So because of this, I am happy to just have something a bit more comfortable on my ears to listen to music or do some voice recording. It's better than my more-than-reliable Logitech USB headset. I am mostly happy to have a new sort of headset and microphone combination. Since the female to USB jack to this thing is brutally long, I could almost fall asleep on my bed listening to stuff on my PC!

So there you have it. I got me a new headset and like it a lot for the most part. I may possibly consider alternating using this for my PC and my PS3.
 
Last edited:
I love my Lian-Li, but I'm never going back to a non-magnetic PC case. This goddamn thing weighs a TON though. I have a place to hang my headphones and room for document bins to get my papers off my desk. Just look at all this utility!
DSCF5455.JPG


If you're into RGB, the motherboard doesn't stop rainbowing. Even when it's off, it's still running through an acid trip. I need to fix this. Luckily it all shines into my closet and I don't have to see any LED light from my seat.

DSCF5456.JPG


Waiting for the new GPUs to come out. In the mean time, my old 670 GTX (with 680 cooler and card) is on duty. Funnily enough, the red and black case was the one that was on sale. And everything else is red and black. Surprise wolfpack color scheme.

DSCF5457.JPG


Cable management.
DSCF5458.JPG


The brains of the operation

DSCF5459.JPG
 
Had to set up Speedfan all over again after reinstalling Windows. Spent way too long figuring out how to automatically set fan control with my GPU radiator, realizing that the temperature probe was set to the fan itself, not the GPU die temp probe.
 
@Techy .. Once you have it set correctly you should go to the program folder and save the three .cfg files into a .zip and store it on another drive, probably in the same place that you might keep the Speedfan installer.

It's then just a case of restoring those files whenever you need to reinstall windows. 👍
 
So I plopped this on my desk today...
Before:
Z5XeY1bl.jpg

After:
DWy0vPSl.jpg


This monitor is such a steal. It's a PVA panel too, which basically means that it has enough contrast to liquefy your retinas. Anything with a white screen is basically the devil.

fMXGhGG.jpg


I'm watching raw ungraded 4k video and my jaw is just on the floor. The lights of all the cars going by actually look like they're illuminating, and it's friggin blindingly bright.

I really didn't expect it to be this huge though. I'm kind of bummed because a) I'm not sure if my vesa desk clamp can support its weight, and b) I probably have to scuttle my document bin setup. I'm also not sure if the side arms will even clear the screen to keep a multi-monitor setup.

Oh well. I can always use it as a TV with roku or apple tv since I don't use cable anyway.
 
Wrote an algorithm to connect a bunch of line segments into polylines, which made it possible to draw them with the smooth option enabled.

Code:
    for elevation in lineDict:
        coordinates = lineDict[elevation]
        lines = [[a, b] for a, b in coordinates]
        for i in range(len(lines)):
            line = lines.pop(0)
            start = line[0]
            end = line[-1]
            for other_line in lines:
                other_start = other_line[0]
                other_end = other_line[-1]
                if (start.x, start.y) == (other_start.x, other_start.y):
                    other_line.reverse()
                    other_line += line[1:]
                    break
                elif (start.x, start.y) == (other_end.x, other_end.y):
                    other_line += line[1:]
                    break
                elif (end.x, end.y) == (other_start.x, other_start.y):
                    other_line.reverse()
                    line.reverse()
                    other_line += line[1:]
                    break
                elif (end.x, end.y) == (other_end.x, other_end.y):
                    line.reverse()
                    other_line += line[1:]
                    break
            else:
                lines.append(line)

        lineDict[elevation] = lines

RenderImage (1).png
 
It's not a matter of "what I've done", it's more a matter of "don't be stupid and look further into that financing deal and order yourself a gaming laptop when your current one is still better than you expected".
 
I tried some more Open Broadcaster Software settings. Now that I am using my Turtle Beach Recon 60P headset, I tried doing some test videos utilizing the audio and the microphone. There is no Microphone Boost feature for the headset. I almost felt like wanting to get the PX24 headset from Turtle Beach in the future. Anyhow, OBS has a feature that allows you to boost the microphone sound in case the mic is rather quiet. So I made a GTR2 video lap where I was providing some commentary as I nearly completed a lap of a course. I had no problems with the in-game audio, so I left that at its regular setting. I had to boost the microphone audio to about 10 dB in OBS so I can properly hear my voice. The whole test went well. I could now simply make video clips and supply my voice without needing to use Audacity or something to make the audio track to go with videos.

What I haven't yet tried was live streaming. It is something I ultimately want to do. Some of us here on GTPlanet have done live streams before. Using this microphone and Open Broadcaster Software, I feel a bit more confident to do a live stream and to maybe do it right on my first try. There are still a lot of things I have to learn if and when I ultimately get to doing live streams of some kind. People who use OBS mostly use OBS Studio. I have struggled to find a winning combination using OBS Studio, so I may work with basic OBS instead.
 
So I ordered and just received an ASUS PG279Q, I'm not at home so I've not got an adequate PC to test it at >60Hz with, but I've tried a 1440p 60Hz YouTube video on it and it looks amazing. Yes, there is quite a lot of backlight bleed with the brightness at 100% but at a reasonable level it's much less pronounced, in fact I only really started to see it at about 80%, I think 40% is about right for me. For reference I set my current Dell U2313HM's brightness to 0%, but 0% on the ASUS is much darker, I guess their backlight PWM smoothing is better.

Still, I'll have to test it at full speed and check for dead pixels before I decide to keep it, but initial impressions are good.

CC @Saidur_Ali
 
Enjoy if you keep it. Have you played games at higher than 60Hz before with a screen that supports it? Reminded me, I hadn't tested out my new G5 screen (QHD IPS) so looked now for backlight bleed test video. It's so much better than first one I got. Did notice your monitor come up near top of the results on YouTube, may want to check it out to see how yours compares. Pictures: Link



Even the best example looked quite bad to me, makes it look so cheap looking IMO. Hard to believe they charge close to £800 for it. My G5 screen has much higher contrast ratio, higher brightness, same resolution and also IPS and very minimal backlight bleeding. Wonder why quality is so bad for this particular AUO AHVA panel in the Asus. Hopefully new 4K panel is a lot better, may get it as a PC monitor one day.
 
No, I've never tried gaming at over 60Hz, I'm deliberating over what to try first...

Wonder why quality is so bad for this particular AUO AHVA panel in the Asus.

I assume it's because there's only two products that use it, they've had basically no incentive to develop it, especially since people like me will buy it anyway. I've seen that video too, but I always knew I wouldn't be using it at full brightness (where the bleed is most visible) so I was willing to give it a go for myself.

Edit: Doom at 144Hz with G-sync is absolutely perfect, it was already a great game but seeing it running so smoothly is properly incredible, especially at 1440p with all the settings maxed.
 
Last edited:
I made a Tasker profile on my phone that sends a Wake On LAN command to my PC, so now my PC turns on when my alarm goes off. Might make getting out of bed easier. :lol:
 
No, I've never tried gaming at over 60Hz, I'm deliberating over what to try first...



I assume it's because there's only two products that use it, they've had basically no incentive to develop it, especially since people like me will buy it anyway. I've seen that video too, but I always knew I wouldn't be using it at full brightness (where the bleed is most visible) so I was willing to give it a go for myself.
What you have in mind, a driving game like AC or a shooting game?

Probably just a flawed design, gives buyers incentive though to upgrade once they come out with a new one that improves backlighting. That panel might hold some kind of record in terms of monitors returned due to it. Is it still quite visible on any dark images with lower brightness?
 
Is it still quite visible on any dark images with lower brightness?

On a completely black image you can see it around the edges, I won't lie, even at 20% brightness (which feels about right for me) I can see it if I look directly at it, but I can't see it in my peripheral vision. It's not great that the monitor has this flaw, of course, but given that there's nothing around right now that does everything this does and I spend very little time looking at the edge of my monitor when I play games, I'm happy to keep it. It's annoying, though, as this is quite literally the only flaw, but I knew what I was buying so I'm not exactly surprised and I know my odds of doing better next time are quite low as the bleed on this one is nowhere near as bad as some seen in the 20-monitor test video... And it's out of stock again which hardly helps.

And as I alluded to in my edit, I played Doom first and it's just amazing, with my GTX 1080 it runs at 120-144fps at 1440p with all of the settings turned up (except maybe MSAA, which I probably have at 4x instead of 8). Deus Ex: MD is less smooth, unfortunately, with the same settings as I was using at 1080p I get ~50fps at 1440p, but G-sync does make it much easier to tolerate. Forza Horizon 3 struggled to hit 60fps even at 1080p but in the areas in which it did, it can now hit 90fps and it looks extremely pretty, and as an added bonus there's no screen tearing when I drive through the city area, but the combination of the low frame rate and the physics engine being tied to the frame rate does make it feel like a Dreamcast game, which is weird as hell but not the monitor's fault, I am still on a 4690K after all and the game is barely optimised.

All in all, it's a huge upgrade for me (coming from a Dell U2312HM with pretty extreme bleed) and I love it.

Edit: I did actually try AC, but I forgot I had to change the refresh rate in the Nvidia control panel. Still, it does look incredible even at 60Hz with G-sync enabled.
 
On a completely black image you can see it around the edges, I won't lie, even at 20% brightness (which feels about right for me) I can see it if I look directly at it, but I can't see it in my peripheral vision. It's not great that the monitor has this flaw, of course, but given that there's nothing around right now that does everything this does and I spend very little time looking at the edge of my monitor when I play games, I'm happy to keep it. It's annoying, though, as this is quite literally the only flaw, but I knew what I was buying so I'm not exactly surprised and I know my odds of doing better next time are quite low as the bleed on this one is nowhere near as bad as some seen in the 20-monitor test video... And it's out of stock again which hardly helps.

And as I alluded to in my edit, I played Doom first and it's just amazing, with my GTX 1080 it runs at 120-144fps at 1440p with all of the settings turned up (except maybe MSAA, which I probably have at 4x instead of 8). Deus Ex: MD is less smooth, unfortunately, with the same settings as I was using at 1080p I get ~50fps at 1440p, but G-sync does make it much easier to tolerate. Forza Horizon 3 struggled to hit 60fps even at 1080p but in the areas in which it did, it can now hit 90fps and it looks extremely pretty, and as an added bonus there's no screen tearing when I drive through the city area, but the combination of the low frame rate and the physics engine being tied to the frame rate does make it feel like a Dreamcast game, which is weird as hell but not the monitor's fault, I am still on a 4690K after all and the game is barely optimised.

All in all, it's a huge upgrade for me (coming from a Dell U2312HM with pretty extreme bleed) and I love it.

Edit: I did actually try AC, but I forgot I had to change the refresh rate in the Nvidia control panel. Still, it does look incredible even at 60Hz with G-sync enabled.
Panel lottery, not worth the hassle if reasonable already.

Didn't realise a new Doom game came out last year, can your computer run Crysis though as well? (Reminds me I've yet to try and run that game in years, hopefully finally now got a computer that can run it at 60FPS on max settings at 1080p. Nearly a decade old now, time goes by quick.) I need to see how FH3 runs on my upgraded PC, I like that saves are stored online so works on Xbox One so far without any hassle. I don't use my PC or game consoles much though.

Have you already maxed out OC on the 4690K? Are you going to upgrade further to a 4790K or upgrade completely to say a 7700K or wait for something better to come out? 2019 looks like it is going to be a good year for computing hardware, sort of scary to think though we might be reaching close to peak affordable computer hardware performance within next decade. It will become like buying a new washing machine or something like that. Hopefully that's not the case.

You love your bleeding monitors. ;)

I use V-sync on AC on laptop and gaming PC to keep at 1080p 60FPS, wonder if that causes more lag? Have you since tried running at maximum Hz your monitor allows, much of a improvement / difference over 60Hz?
 
Finally bought additional storage for my growing photo collection - two 3TB drives on the cheap that I've setup in RAID I. Gives me an extra TB over my previous setup and redundancy that is desperately needed when working with 10+ years of digital photos.

That being said, I do need to upgrade from my epic Phenom X3 someday :dopey:
 
Finally bought additional storage for my growing photo collection - two 3TB drives on the cheap that I've setup in RAID I. Gives me an extra TB over my previous setup and redundancy that is desperately needed when working with 10+ years of digital photos.

That being said, I do need to upgrade from my epic Phenom X3 someday :dopey:

Only 6TB(5.45TiB)?

Fox as a 4x4TB raid 5 array
Which gives me 12TB(10.9TiB)
 

Latest Posts

Back