質問

誰かが私が問題を抱えている少しプログラミング数学で私を助けることができるかどうか疑問に思う。

私が作成しようとしているのは、Nuke(VFX)の送信スクリプト(Pythonと.batを使用)です。私が持っている問題は、すでに計算されたスタックに残りのフレームを追加する方法を理解することができません。

より明確にする...

Nukeでは、20フレームをレンダリングしなければなりません。私は16個のスレッドを持っています。 Nukeは1つのスレッドのみを使用します。フレーム数を取り、スレッド数で分割し、Pythonを使用してBATファイルを書き出すスクリプトを作成します。問題は私が残りを持っているときです。残りを取り、レンダリングスタックに取り戻したい。

例(最初のループ)

thread1 = 1 frame
thread2 = 1 frame
thread3 = 1 frame
thread4 = 1 frame
thread5 = 1 frame
thread6 = 1 frame
...
thread16 = 1 frame
.

これを行ったら残りの部分は4です。残りの部分はスレッド間で配布されます。 とても...

例(2番目のループ)

thread1 = 2 frame
thread2 = 2 frame
thread3 = 2 frame
thread4 = 2 frame
thread5 = 1 frame
thread6 = 1 frame
...
thread16 = 1 frame
.

合計20フレームの最初の数スレッド間で4が追加されます。

誰もが提供しなければならないヘルプ、ヒント、コメントを大いに感謝します。 :)

ありがとう

役に立ちましたか?

解決

framesは、任意のオブジェクトのリスト、例えばDICTまたは「フレーム」オブジェクトのリストにすることができます。ここで私はints

を使っただけでした
>>> frames = range(20)
>>> threads = 16
>>> [frames[x::threads] for x in range(threads)]
[[0, 16], [1, 17], [2, 18], [3, 19], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15]]
.

いくつかのフレームは他のものよりも速くレンダリングされる可能性があるので、私はQueueにフレームを入れるのが良いかもしれないと思います。

他のヒント

これは Bresenhamアルゴリズム

def partition(lst, n):
    increment = len(lst) / float(n)
    last = 0
    i = 1
    results = []
    while last < len(lst):
        idx = int(round(increment * i))
        results.append(lst[last:idx])
        last = idx
        i += 1
    return results


for i, frames in enumerate(partition(range(20),16)):
    if len(frames)>1:
        print 'thread'+str(i+1),'=', len(frames),'frames'
    else:
        print 'thread'+str(i+1),'=', len(frames),'frame'
.

パーティションビットはこの回答です。

プリント:

thread1 = 1 frame
thread2 = 2 frames
thread3 = 1 frame
thread4 = 1 frame
thread5 = 1 frame
thread6 = 2 frames
thread7 = 1 frame
thread8 = 1 frame
thread9 = 1 frame
thread10 = 2 frames
thread11 = 1 frame
thread12 = 1 frame
thread13 = 1 frame
thread14 = 2 frames
thread15 = 1 frame
thread16 = 1 frame
.

Mark Dickinsonのソリューション正面ロードされている2つのフレームスレッドが気にしない場合は

それからあなたは持っています:

def partition(lst, n):
    q, r = divmod(len(lst), n)
    indices = [q*i + min(i, r) for i in xrange(n+1)]
    return [lst[indices[i]:indices[i+1]] for i in xrange(n)]
.

どのプリント:

thread1 = 2 frames
thread2 = 2 frames
thread3 = 2 frames
thread4 = 2 frames
thread5 = 1 frame
thread6 = 1 frame
thread7 = 1 frame
thread8 = 1 frame
thread9 = 1 frame
thread10 = 1 frame
thread11 = 1 frame
thread12 = 1 frame
thread13 = 1 frame
thread14 = 1 frame
thread15 = 1 frame
thread16 = 1 frame
.

frames=20
tPos=16
Ts=divmod(frames,tPos)
threads=[Ts[0]+1 if i < Ts[1] else Ts[0] for i in range(tPos)]

>>> threads    
>>> [2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
.

リストの総合的な関係に問題がある場合は、このように同じことを書くことができます。

threads=[]
for i in range(tPos):
    threads.append(Ts[0]+1 if i<Ts[1] else Ts[0])
.

それをフォーマットするには、次のようにします。

for i,e in enumerate(threads):
    print 'thread{} {}frames'.format(i,e)
.

これは私が執着したものです....あなたがみんなを助けてくれてありがとう。

frames=20 
tPos=16 
Ts=divmod(frames,tPos) 
threads=[] 
for i in range(tPos): 
    threads.append(Ts[0]+1 if i<Ts[1] else Ts[0])

start = 1
end = 0
x=1
while x <= (tPos):
    end = start +(threads[x-1]-1)
    print (start, "-", end)
    start = end + 1
    x+=1


prints:
1 - 2
3 - 4
5 - 6
7 - 8
9 - 9
10 - 10
11 - 11
12 - 12
13 - 13
14 - 14
15 - 15
16 - 16
17 - 17
18 - 18
19 - 19
20 - 20
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top