Ejemplo n.º 1
0
def groupStartEndPoints(geo):
	starts = geo.createPointGroup('StartPoints')
	ends = geo.createPointGroup('EndPoints')

	for prim in geo.prims():
		if hou.updateProgressAndCheckForInterrupt():
			break
		starts.add(prim.vertices()[0].point())
		ends.add(prim.vertices()[len(prim.vertices())-1].point())
Ejemplo n.º 2
0
def groupStartAndEndOfPrim(primNumber):
	starts = geo.createPointGroup('StartPoints' + '_Prim_' + str(primNumber))
	ends = geo.createPointGroup('EndPoints' + '_Prim_' + str(primNumber))

	for prim in geo.prims():
		if hou.updateProgressAndCheckForInterrupt():
			break
		starts.add(prim.vertices()[0].point())
		ends.add(prim.vertices()[len(prim.vertices())-1].point())
Ejemplo n.º 3
0
def getPointsFromTrack(filename):
	geo = hou.pwd().geometry()
	# Read in stream data 
	streams, hdr = trackvis.read(filename)

	streamlines = [s[0] for s in streams]

	# For each streamline add a curve to the geometry
	j = 0
	for stream in streamlines:		
		i = 0
		curve = geo.createNURBSCurve(len(stream))
		if hou.updateProgressAndCheckForInterrupt(int(float(j)/float(len(streamlines))*100)):
			break
		for vertex in curve.vertices():
		    vertex.point().setPosition((float(stream[i][0]),float(stream[i][1]),float(stream[i][2])))
		    i = i + 1
		    if hou.updateProgressAndCheckForInterrupt():
        		break
        j = j+1
Ejemplo n.º 4
0
def _threadCreateAttribute(primitives,geo,end_points,radius):
	stream_starts = {}
	stream_ends = {}
	i = 0
	for prim in primitives:
		stream_starts[str(i)] = ''
		stream_ends[str(i)] = ''
		i = i+1
	
	i = 0
	for prim in primitives:
		if hou.updateProgressAndCheckForInterrupt(int(float(i)/float(len(geo.prims()))*100)):
			break

		# Check prim start and end against all other prim start and ends.
		# Group near ends and near starts.

		pointA = prim.vertices()[0].point().position()

		for stream_id in end_points:
			if stream_id == str(i):
				continue
			pointB = end_points[stream_id]['start'][1]
			if isInside(pointA,pointB,radius):
				stream_starts[str(i)] = stream_starts[str(i)] + stream_id + ' ' + '0' + ','

			pointB = end_points[stream_id]['end'][1]
			if isInside(pointA,pointB,radius):
				stream_starts[str(i)] = stream_starts[str(i)] + stream_id + ' ' + str(end_points[stream_id]['end'][0]) + ','

		pointA = prim.vertices()[len(prim.vertices())-1].point().position()

		for stream_id in end_points:
			if stream_id == str(i):
				continue
			pointB = end_points[stream_id]['start'][1]
			if isInside(pointA,pointB,radius):
				stream_ends[str(i)] = stream_ends[str(i)] + stream_id + ' ' + '0' + ','

			pointB = end_points[stream_id]['end'][1]
			if isInside(pointA,pointB,radius):
				stream_ends[str(i)] = stream_ends[str(i)] + stream_id + ' ' + str(end_points[stream_id]['end'][0]) + ','

		prim.setAttribValue('StartNeighbors',stream_starts[str(i)])
		prim.setAttribValue('EndNeighbors',stream_ends[str(i)])

		i = i+1
Ejemplo n.º 5
0
def createAttributes(radius,singleThreaded=True):
	geo = hou.pwd().geometry()
	prims = geo.prims()
	# Initialize Attributs
	if geo.findPointAttrib('Active') is None:
		geo.addAttrib(hou.attribType.Point,'Active',0)
	if geo.findPrimAttrib('Flow') is None:
		geo.addAttrib(hou.attribType.Prim,'Flow',0)
	if geo.findPrimAttrib('EndNeighbors') is None:
		geo.addAttrib(hou.attribType.Prim,'EndNeighbors',"")
	if geo.findPrimAttrib('StartNeighbors') is None:
		geo.addAttrib(hou.attribType.Prim,'StartNeighbors',"")
	if geo.findPrimAttrib('CurrentPoint') is None:
		geo.addAttrib(hou.attribType.Prim,'CurrentPoint',-1)
	if geo.findGlobalAttrib('ActivePrims') is None:
		geo.addAttrib(hou.attribType.Global,'ActivePrims', (0) )
	
	# Iterate through the streamlines and create a dict from id to Start and End Points
	end_points = {}
	i = 0
	for prim in geo.prims():
		end_points[str(i)] = {'start':(0,prim.vertices()[0].point().position()), 'end':(len(prim.vertices())-1,prim.vertices()[len(prim.vertices())-1].point().position())}
		if hou.updateProgressAndCheckForInterrupt():
			break
		i = i + 1

	# Using start and end dicts, create a new dict of stream # to start points and end
	# points within the radius of a sphere
	if singleThreaded:
		_threadCreateAttribute(geo.prims(),geo,end_points,radius)

	else:
		primitives = chunks(geo.prims(),len(geo.prims())/3)
		threads = []
		for i in range(3):
			t = threading.Thread(target =_threadCreateAttribute, args=(primitives.next(),geo,end_points,radius, ))
			threads.append(t)
			t.start()
		#t.join()

	#for t in threads:
	#	t.join()

	groupStartEndPoints(geo)
Ejemplo n.º 6
0
def solverStep():
	geo = hou.pwd().geometry()

	activePrims = geo.intListAttribValue('ActivePrims')

	# For each prim, look up current point and set next point based on flow direction.
	i = 0
	for index in activePrims:
		prim = geo.prims()[index]
		if hou.updateProgressAndCheckForInterrupt(int(float(i)/float(len(geo.prims()))*100)):
			break
		flowDir = prim.attribValue('Flow')
		if flowDir == 0:
			continue
		
		sizeOfPrim = len(prim.vertices())

		currentPoint = prim.attribValue('CurrentPoint')
		rgb1 = prim.vertices()[currentPoint].point().attribValue('Cd')

		nextPoint = currentPoint + flowDir

		# For all valid points that are not the end points of a stream
		if (currentPoint > 0 and currentPoint < sizeOfPrim - 1) or (currentPoint == 0 and flowDir == 1) or (currentPoint == sizeOfPrim-1 and flowDir == -1):
			rgb2 = prim.vertices()[nextPoint].point().attribValue('Cd')
			rgbSum = (sumColors(rgb1,rgb2))
			prim.vertices()[nextPoint].point().setAttribValue('Cd',rgbSum)
			prim.vertices()[nextPoint].point().setAttribValue('Active',1)
			prim.vertices()[nextPoint].point().setAttribValue('Age',1.0)
			prim.vertices()[currentPoint].point().setAttribValue('Active',0)
			prim.setAttribValue('CurrentPoint',nextPoint)
		# Jump to all the start points
		elif currentPoint == 0 and flowDir == -1:
			_checkForEndPoint(0,rgb1,prim,flowDir,geo)
			prim.vertices()[currentPoint].point().setAttribValue('Active',0)
		# Jump to all the end points
		elif currentPoint == sizeOfPrim-1 and flowDir == 1:
			_checkForEndPoint(sizeOfPrim-1,rgb1,prim,flowDir,geo)
			prim.vertices()[currentPoint].point().setAttribValue('Active',0)

		i = i+1