Esempio n. 1
0
def main():

    room = Room()

    # Define a simple cube (1000 x 1000 x 1000 mm) as room geometry
    face1poly = Polygon([
        Vector3(0, 0, 0),
        Vector3(0, 1000, 0),
        Vector3(1000, 1000, 0),
        Vector3(1000, 0, 0)
    ], 1)
    face2poly = Polygon([
        Vector3(0, 0, 0),
        Vector3(0, 1000, 0),
        Vector3(0, 1000, 1000),
        Vector3(0, 0, 1000)
    ])
    face3poly = Polygon([
        Vector3(0, 0, 0),
        Vector3(1000, 0, 0),
        Vector3(1000, 0, 1000),
        Vector3(0, 0, 1000)
    ])
    face4poly = Polygon([
        Vector3(0, 0, 1000),
        Vector3(0, 1000, 1000),
        Vector3(1000, 1000, 1000),
        Vector3(1000, 0, 1000)
    ])
    face5poly = Polygon([
        Vector3(0, 1000, 1000),
        Vector3(0, 1000, 0),
        Vector3(1000, 1000, 0),
        Vector3(1000, 1000, 1000)
    ])
    face6poly = Polygon([
        Vector3(1000, 0, 1000),
        Vector3(1000, 1000, 1000),
        Vector3(1000, 1000, 0),
        Vector3(1000, 0, 0)
    ])
    polygons = [
        face1poly, face2poly, face3poly, face4poly, face5poly, face6poly
    ]
    for poly in polygons:
        room.addPolygon(poly, color=Vector3(0.5, 0.5, 0.5))
    room.constructBSP()

    center = room.getCenter()
    print('Room maximum length: ', room.getMaxLength())
    print('Room center: x=%f, y=%f, z=%f' % (center.x, center.y, center.z))
    print('Number of elements: ', room.numElements())
    print('Number of convex elements: ', room.numConvexElements())

    # Create source localized in room
    src1 = Source()
    src1.setPosition(Vector3(750, 750, 750))
    src1.setOrientation(Matrix3(0, 0, 1, 1, 0, 0, 0, 1, 0))
    src1.setName('Src1')
    room.addSource(src1)
    print('Number of sources: ', room.numSources())

    # Create listener localized in room
    list1 = Listener()
    list1.setPosition(Vector3(250, 250, 500))
    list1.setOrientation(Matrix3(0, 0, -1, -1, 0, 0, 0, 1, 0))
    list1.setName('Lst1')
    room.addListener(list1)

    list2 = Listener()
    list2.setPosition(Vector3(240, 240, 500))
    list2.setOrientation(Matrix3(0, 0, -1, -1, 0, 0, 0, 1, 0))
    list2.setName('Lst2')
    room.addListener(list2)
    print('Number of listeners: ', room.numListeners())

    for s in range(room.numSources()):
        for l in range(room.numListeners()):
            src = room.getSource(s)
            lst = room.getListener(l)

            print('-----------------------------------')
            print('From source %s to listener %s' %
                  (src.getName(), lst.getName()))
            print('-----------------------------------')

            # Calculate paths
            maximumOrder = 8
            solution = PathSolution(room, src, lst, maximumOrder)
            solution.update()
            print('Number of paths calculated: ', solution.numPaths())

            # Analyze paths
            minPathLength = None
            maxPathLength = 0
            for i in range(solution.numPaths()):
                path = solution.getPath(i)

                # Calculate path length
                pathLength = 0.0
                lastPt = path.m_points[0]
                for pt in path.m_points[1:]:
                    pathLength += math.sqrt((lastPt.x - pt.x)**2 +
                                            (lastPt.y - pt.y)**2 +
                                            (lastPt.z - pt.z)**2)
                    lastPt = pt

                if pathLength > maxPathLength:
                    maxPathLength = pathLength
                if pathLength < minPathLength or minPathLength is None:
                    minPathLength = pathLength

            print('Minimum path length: ', minPathLength)
            print('Maximum path length: ', maxPathLength)

    viewer = Viewer(room, 4)
    viewer.show()
Esempio n. 2
0
def main():

    room = Room()

    # Define a simple cube (1000 x 1000 x 1000 mm) as room geometry
    face1poly = Polygon([
        Vector3(0, 0, 0),
        Vector3(0, 1000, 0),
        Vector3(1000, 1000, 0),
        Vector3(1000, 0, 0)
    ], 1)
    face2poly = Polygon([
        Vector3(0, 0, 0),
        Vector3(0, 1000, 0),
        Vector3(0, 1000, 1000),
        Vector3(0, 0, 1000)
    ])
    face3poly = Polygon([
        Vector3(0, 0, 0),
        Vector3(1000, 0, 0),
        Vector3(1000, 0, 1000),
        Vector3(0, 0, 1000)
    ])
    face4poly = Polygon([
        Vector3(0, 0, 1000),
        Vector3(0, 1000, 1000),
        Vector3(1000, 1000, 1000),
        Vector3(1000, 0, 1000)
    ])
    face5poly = Polygon([
        Vector3(0, 1000, 1000),
        Vector3(0, 1000, 0),
        Vector3(1000, 1000, 0),
        Vector3(1000, 1000, 1000)
    ])
    face6poly = Polygon([
        Vector3(1000, 0, 1000),
        Vector3(1000, 1000, 1000),
        Vector3(1000, 1000, 0),
        Vector3(1000, 0, 0)
    ])
    polygons = [
        face1poly, face2poly, face3poly, face4poly, face5poly, face6poly
    ]
    for poly in polygons:
        room.addPolygon(poly, color=Vector3(0.5, 0.5, 0.5))
    room.constructBSP()

    center = room.getCenter()
    print('Room maximum length: ', room.getMaxLength())
    print('Room center: x=%f, y=%f, z=%f' % (center.x, center.y, center.z))
    print('Number of elements: ', room.numElements())
    print('Number of convex elements: ', room.numConvexElements())

    # Create source localized in room
    src1 = Source()
    src1.setPosition(Vector3(750, 750, 750))
    src1.setOrientation(Matrix3(0, 0, 1, 1, 0, 0, 0, 1, 0))
    src1.setName('Src1')
    room.addSource(src1)
    print('Number of sources: ', room.numSources())

    # Create listener localized in room
    list1 = Listener()
    list1.setPosition(Vector3(250, 250, 500))
    list1.setOrientation(Matrix3(0, 0, -1, -1, 0, 0, 0, 1, 0))
    list1.setName('Lst1')
    room.addListener(list1)

    list2 = Listener()
    list2.setPosition(Vector3(240, 240, 500))
    list2.setOrientation(Matrix3(0, 0, -1, -1, 0, 0, 0, 1, 0))
    list2.setName('Lst2')
    room.addListener(list2)
    print('Number of listeners: ', room.numListeners())

    viewer = Viewer(room, 4)
    viewer.show()
Esempio n. 3
0
def main():

    room = Room()
    
    # Load geometry from file
    filename = os.path.join(CDIR, '../../data/kuunteluhuone.room')
    room.importGeometry(filename)
    print('Using room geometry file: ', filename)
    
    center = room.getCenter()    
    print('Room maximum length: ', room.getMaxLength())
    print('Room center: x=%f, y=%f, z=%f' % (center.x, center.y, center.z))
    
    # Create source
    src1 = Source()
    src1.setPosition(Vector3(500,-250,1200))
    src1.setOrientation(Matrix3(0,0,1,1,0,0,0,1,0))
    src1.setName('Src1')
    room.addSource(src1)
    print('Number of sources: ', room.numSources())
    
    # Create listener
    list1 = Listener()
    list1.setPosition(Vector3(3750,225,1200))
    list1.setOrientation(Matrix3(0,0,-1,-1,0,0,0,1,0))
    list1.setName('Lst1')
    room.addListener(list1)
    print('Number of listeners: ', room.numListeners())
    
    for s in range(room.numSources()):
        for l in range(room.numListeners()):
            src = room.getSource(s)
            lst = room.getListener(l)
    
            print('-----------------------------------')
            print('From source %s to listener %s' % (src.getName(), lst.getName()))
            print('-----------------------------------')
            
            # Calculate paths
            maximumOrder = 5
            solution = PathSolution(room, src, lst, maximumOrder)
            solution.update()
            print('Number of paths calculated: ', solution.numPaths())
            
            # Analyze paths
            minPathLength = None
            maxPathLength = 0
            for i in range(solution.numPaths()):
                path = solution.getPath(i)
                
                # Calculate path length
                pathLength = 0.0
                lastPt = path.m_points[0]
                for pt in path.m_points[1:]:
                    pathLength += math.sqrt((lastPt.x - pt.x)**2 + 
                                            (lastPt.y - pt.y)**2 + 
                                            (lastPt.z - pt.z)**2)
                    lastPt = pt
                
                if pathLength > maxPathLength:
                    maxPathLength = pathLength
                if pathLength < minPathLength or minPathLength is None:
                    minPathLength = pathLength
                
            print('Minimum path length: ', minPathLength)
            print('Maximum path length: ', maxPathLength)

    viewer = Viewer(room, 4)
    viewer.show()
Esempio n. 4
0
        room.addPolygon(polygon, color=Vector3(0.5, 0.5, 0.5))

    # Display object layout
    for polygon in objectPolygons:
        vtx = []
        for i in range(polygon.numPoints()):
            vtx.append([polygon[i].x, polygon[i].y, polygon[i].z])
        vtx = np.array(vtx)
        tri = plt3d.art3d.Poly3DCollection([vtx])
        tri.set_color([1.0, 0.0, 0.0, 0.25])
        tri.set_edgecolor('k')
        ax.add_collection3d(tri)

    # Create binaural listener localized in room
    interauralDistance = 300  # mm
    list1 = Listener()
    list1.setPosition(Vector3(1500, 5000 - interauralDistance / 2, 1000))
    list1.setName('Lst-left')
    room.addListener(list1)
    list2 = Listener()
    list2.setPosition(Vector3(1500, 5000 + interauralDistance / 2, 1000))
    list2.setName('Lst-right')
    room.addListener(list2)

    # Create source localized between the listeners
    src1 = Source()
    src1.setPosition(Vector3(1500, 5000, 1000))
    src1.setName('Src')
    room.addSource(src1)

    # Display listeners and source layout
    xp = rp*np.cos(thetap)
    yp = rp*np.sin(thetap)
    zp = hp*np.ones(len(tp))

    p = np.array([xp,yp,zp])
    p = p.transpose()  
    

    #Create listener moving on the ideal path in room(length x width x height)
    points = 4               #points we want to calculate the positions at
    i = 0
    indexp = 0
    p_est = np.zeros([points,3])
    
    list1 = Listener()
    list1.setName('List1') 
    room.addListener(list1)   
        
    for indexp in range(points):

        room.getListener(0).setPosition(Vector3(p[i,0]+length/2,p[i,1]+width/2,p[i,2]))   #shift them to the center of room (0,0) = corner ==> (length/2,width/2) center
   

        # Display listeners and source layout
        #ax.plot([list1.getPosition().x], [list1.getPosition().y], [list1.getPosition().z], color='k', marker='o')
        #ax.text(list1.getPosition().x, list1.getPosition().y, list1.getPosition().z, "Listener", color='k')
        #ax.plot([src1.getPosition().x], [src1.getPosition().y], [src1.getPosition().z], color='r', marker='o')
        #ax.text(src1.getPosition().x, src1.getPosition().y, src1.getPosition().z, "Source 1", color='r')
        #ax.plot([src2.getPosition().x], [src2.getPosition().y], [src2.getPosition().z], color='r', marker='o')
        #ax.text(src2.getPosition().x, src2.getPosition().y, src2.getPosition().z, "Source 2", color='r')