Beispiel #1
0
def main():
	# Input mesh is a cube of size 1 and centered on (0, 0, 0)
	triangles = numpy.array([
		[[-.5,  .5, -.5],
		 [ .5,  .5,  .5],
		 [ .5,  .5, -.5]],
		[[-.5,  .5, -.5],
		 [-.5,  .5,  .5],
		 [ .5,  .5,  .5]],
		[[-.5, -.5, -.5],
		 [-.5, -.5,  .5],
		 [-.5,  .5, -.5]],  
		[[-.5, -.5,  .5],
		 [-.5,  .5,  .5],
		 [-.5,  .5, -.5]],
		[[-.5, -.5, -.5],
		 [ .5, -.5, -.5],
		 [-.5, -.5,  .5]],
		[[ .5, -.5, -.5],
		 [ .5, -.5,  .5],
		 [-.5, -.5,  .5]],   
		[[ .5, -.5, -.5],
		 [ .5,  .5, -.5],
		 [ .5,  .5,  .5]],
		[[ .5, -.5, -.5],
		 [ .5,  .5,  .5],
		 [ .5, -.5,  .5]],
		[[-.5, -.5,  .5],
		 [ .5, -.5,  .5],
		 [ .5,  .5,  .5]],
		[[-.5, -.5,  .5],
		 [ .5,  .5,  .5],
		 [-.5,  .5,  .5]],
		[[-.5, -.5, -.5],
		 [-.5,  .5, -.5],
		 [ .5, -.5, -.5]],
		[[ .5, -.5, -.5],
		 [-.5,  .5, -.5],
		 [ .5,  .5, -.5]]])
	
	# Compute uniform distribution that fits in a cube of size 2 and centered on (0, 0, 0)
	P = 2 * (numpy.random.random((4096, 3)) - .5)
	P = P.astype('longdouble')

	# Test each point using the point in cube test
	P_inside_cube = is_inside_cube(1, P)
	
	# Test each point using the point-in-mesh test
	P_inside_mesh = is_inside(triangles, P)

	# Print statistics on the difference between the two tests
	positive_count = sum(P_inside_cube)
	negative_count = sum(~P_inside_cube)

	true_positive_count = sum(P_inside_cube & P_inside_mesh)
	false_positive_count = sum(~P_inside_cube & P_inside_mesh)
	true_negative_count = sum(~P_inside_cube & ~P_inside_mesh)
	false_negative_count = sum(P_inside_cube & ~P_inside_mesh)
Beispiel #2
0
    def volApprox(self, file):
        mf = magfield()
        stlmesh = mesh.Mesh.from_file(file)
        vectors = stlmesh.vectors
        npoints = 15  #Should be Adaptable
        points = mf.withinDomain_mid(npoints, file)
        points = points.T
        check = (is_inside(vectors, points))
        vol = points[check == True]

        return vol
Beispiel #3
0
    def getVolume(self, numTries):

        # self.getBounds()

        # self.updateVolume()
        if self.P is None:
            self.P = self.getRandomPoints(numTries)

        if self.inF is None:
            # inF = np.full(numTries,False)
            self.inF = is_inside(self.triangles,self.P)
        
        inS = np.full([numTries, self.numAtoms],False)
        for k in range(0,self.numAtoms):
            inS[:,k] = is_inside_sphere(self.atoms[k],self.P)
        
        return self.inF, inS
Beispiel #4
0
    def randomSamplingMethod(self, numPoints, file):
        stlmesh = mesh.Mesh.from_file(file)
        vectors = stlmesh.vectors

        min_corner = np.amin(np.amin(vectors, axis=0), axis=0)
        max_corner = np.amax(np.amax(vectors, axis=0), axis=0)
        P = (max_corner - min_corner) * np.random.random(
            (4096, 3)) + min_corner
        check = (is_inside(vectors, P))
        P = P[(check == True), :]
        dist = np.linalg.norm(P[0] - P, axis=1)

        order = np.argsort(dist)
        P = P[order]
        P = P[0:numPoints]

        return P
Beispiel #5
0
def main():
	# Load the input mesh as a list of triplets (ie. triangles) of 3d vertices
	try:
		triangles = numpy.array([X for X, N in stlparser.load(sys.stdin)])
	except stlparser.ParseError as e:
		sys.stderr.write(f'{e}\n')
		sys.exit(0)

	# Compute uniform distribution within the axis-aligned bound box for the mesh
	min_corner = numpy.amin(numpy.amin(triangles, axis = 0), axis = 0)
	max_corner = numpy.amax(numpy.amax(triangles, axis = 0), axis = 0)
	P = (max_corner - min_corner) * numpy.random.random((8198, 3)) + min_corner

	# Filter out points which are not inside the mesh
	P = P[is_inside(triangles, P)]

	# Display
	fig = plot.figure()
	ax = fig.gca(projection = '3d')
	ax.scatter(P[:,0], P[:,1], P[:,2], lw = 0., c = 'k')
	plot.show()
Beispiel #6
0
    def is_inside_stl(self, vectors, points):
        P_inside_mesh = is_inside(vectors, points)

        return P_inside_mesh
Beispiel #7
0
#folder = 'D:\Downloads'
filename = 'cube.STL'
filename = 'torroid.STL'
#filename = 'amforma_132.stl'
#filename = 'hex.STL'
file = os.path.join(folder, filename)
file2 = os.path.join(folder, 'coil_loc.STL')
colors = vtk.vtkNamedColors()

npoints = 15
points = mg.withinDomain_mid(npoints, file)
points = points.T
point_actor = mg.viewFieldPoints(points)
stlmesh = mesh.Mesh.from_file(file)
vectors = stlmesh.vectors
check = (is_inside(vectors, points))
ideal_points = points[check == True]
index = np.random.choice(ideal_points.shape[0], 1)
point0 = ideal_points[index, :]
ideal_points = np.delete(ideal_points, index, 0)
coil_distance = 0
points = point0
length = 0
while length <= 100:
    difference = points[len(points) - 1, :] - ideal_points
    distance = np.linalg.norm(difference, axis=1)
    index = np.where(distance == min(distance))
    endpoint = ideal_points[index]
    ideal_points = np.delete(ideal_points, index, 0)
    length = np.linalg.norm(endpoint - point0)
    print(length)