Thanks Pete!

On 22 August 2011 19:49, Pete O'Connell <[email protected]> wrote:

> #and here is the script in case anyone is interested :)
> import nuke
> def getTheCornerpinAsMatrix():
>
>     projectionMatrixTo = nuke.math.Matrix4()
>     projectionMatrixFrom = nuke.math.Matrix4()
>
>     #dir(projectionMatrix)
>     theCornerpinNode = nuke.selectedNode()
>
>     imageWidth = float(theCornerpinNode.width())
>     imageHeight = float(theCornerpinNode.height())
>
>
>     to1x = theCornerpinNode['to1'].value()[0]
>     to1y = theCornerpinNode['to1'].value()[1]
>     to2x = theCornerpinNode['to2'].value()[0]
>     to2y = theCornerpinNode['to2'].value()[1]
>     to3x = theCornerpinNode['to3'].value()[0]
>     to3y = theCornerpinNode['to3'].value()[1]
>     to4x = theCornerpinNode['to4'].value()[0]
>     to4y = theCornerpinNode['to4'].value()[1]
>
>     from1x = theCornerpinNode['from1'].value()[0]
>     from1y = theCornerpinNode['from1'].value()[1]
>     from2x = theCornerpinNode['from2'].value()[0]
>     from2y = theCornerpinNode['from2'].value()[1]
>     from3x = theCornerpinNode['from3'].value()[0]
>     from3y = theCornerpinNode['from3'].value()[1]
>     from4x = theCornerpinNode['from4'].value()[0]
>     from4y = theCornerpinNode['from4'].value()[1]
>
>
>
> projectionMatrixTo.mapUnitSquareToQuad(to1x,to1y,to2x,to2y,to3x,to3y,to4x,to4y)
>
> projectionMatrixFrom.mapUnitSquareToQuad(from1x,from1y,from2x,from2y,from3x,from3y,from4x,from4y)
>
>     theCornerpinAsMatrix =
> projectionMatrixTo*projectionMatrixFrom.inverse()
>     theCornerpinAsMatrix.transpose()
>
>     return theCornerpinAsMatrix
>
>
> On Tue, Aug 23, 2011 at 11:42 AM, Pete O'Connell 
> <[email protected]>wrote:
>
>> Thanks very much Ivan. It works after transposing!
>>
>> Cheers
>> Pete
>>
>>
>> On Tue, Aug 23, 2011 at 11:34 AM, Ivan Busquets 
>> <[email protected]>wrote:
>>
>>> Hi Pete,
>>>
>>> Sorry I forgot to send that example as reference, but what you have so
>>> far is good.
>>>
>>> I think there's just a couple of things you should need to change to get
>>> this working.
>>>
>>> 1- Don't normalize the "from" and "to" coordinates. The matrices you're
>>> building need to map from the "to" corners to a unit square, and then from a
>>> unit square to your from coordinates, using absolute values.
>>> So just do:
>>>
>>> to1x = theCornerpinNode['to1'].value()[0]
>>> etc...
>>>
>>> 2- By the time you fill the "theCornerpinAsMatrix" object, you should
>>> have the correct transformation matrix already, but in column-major order.
>>> Unfortunately, values in matrix knobs seem to be returned (or set when using
>>> setValue) in row-major order, so you would either need to fill in the matrix
>>> knob in a loop mirroring the cell values, or, what I usually do is transpose
>>> the matrix before filling in the knob.
>>>
>>> So, in your script, after this line:
>>>
>>> theCornerpinAsMatrix = projectionMatrixTo *
>>> projectionMatrixFrom.inverse()
>>>
>>> You can just do:
>>>
>>> theCornerpinAsMatrix.transpose()
>>>
>>> And then continue as you were.
>>>
>>> See if that helps.
>>>
>>> Cheers,
>>> Ivan
>>>
>>>
>>>
>>> On Mon, Aug 22, 2011 at 6:37 PM, Pete O'Connell <[email protected]
>>> > wrote:
>>>
>>>> #OK I think I'm getting close. I tried Ivan's instructions but I think I
>>>> missed something. It looks really close though. Anyone care to take a look
>>>> at what I have so far?
>>>>
>>>> ##############################################################################################################################
>>>> projectionMatrixTo = nuke.math.Matrix4()
>>>> projectionMatrixFrom = nuke.math.Matrix4()
>>>>
>>>> #dir(projectionMatrix)
>>>> theCornerpinNode = nuke.toNode("CornerPin2D1")
>>>> imageWidth = float(theCornerpinNode.width())
>>>> imageHeight = float(theCornerpinNode.height())
>>>>
>>>> #normalized to and from coordinates
>>>> to1x = theCornerpinNode['to1'].value()[0]/imageWidth
>>>> to1y = theCornerpinNode['to1'].value()[1]/imageHeight
>>>> to2x = theCornerpinNode['to2'].value()[0]/imageWidth
>>>> to2y = theCornerpinNode['to2'].value()[1]/imageHeight
>>>> to3x = theCornerpinNode['to3'].value()[0]/imageWidth
>>>> to3y = theCornerpinNode['to3'].value()[1]/imageHeight
>>>> to4x = theCornerpinNode['to4'].value()[0]/imageWidth
>>>> to4y = theCornerpinNode['to4'].value()[1]/imageHeight
>>>>
>>>> from1x = theCornerpinNode['from1'].value()[0]/imageWidth
>>>> from1y = theCornerpinNode['from1'].value()[1]/imageHeight
>>>> from2x = theCornerpinNode['from2'].value()[0]/imageWidth
>>>> from2y = theCornerpinNode['from2'].value()[1]/imageHeight
>>>> from3x = theCornerpinNode['from3'].value()[0]/imageWidth
>>>> from3y = theCornerpinNode['from3'].value()[1]/imageHeight
>>>> from4x = theCornerpinNode['from4'].value()[0]/imageWidth
>>>> from4y = theCornerpinNode['from4'].value()[1]/imageHeight
>>>>
>>>>
>>>>
>>>> projectionMatrixTo.mapUnitSquareToQuad(to1x,to1y,to2x,to2y,to3x,to3y,to4x,to4y)
>>>>
>>>> projectionMatrixFrom.mapUnitSquareToQuad(from1x,from1y,from2x,from2y,from3x,from3y,from4x,from4y)
>>>>
>>>> theCornerpinAsMatrix = projectionMatrixTo*projectionMatrixFrom.inverse()
>>>>
>>>> theNewCornerpinNode = nuke.toNode("CornerPin2D2")
>>>> theNewCornerpinNode['transform_matrix'].setValue(theCornerpinAsMatrix)
>>>>
>>>>
>>>> ############################################################################################################################
>>>> #Thanks
>>>> #Pete
>>>>
>>>>
>>>> On Tue, Aug 23, 2011 at 10:14 AM, Pete O'Connell <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi Michael. I had a look at the planar tracker but as far as I can
>>>>> tell, that node creates a cornerpin based on the matrix that it 
>>>>> calculates,
>>>>> but as far as I can see there is no way in that you can feed the planar
>>>>> tracker cornerpin data and have it calculate the corresponding Matrix. I
>>>>> think nuke.math.Matrix4 is the way.
>>>>>
>>>>> Pete
>>>>>
>>>>>
>>>>> On Tue, Aug 23, 2011 at 3:30 AM, Michael Garrett <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> I haven't got 6.3 in front of me but does the PlanarTracker add
>>>>>> anything into the mix to make this easier?  I seem to remember it 
>>>>>> outputs a
>>>>>> 4*4 matrix for the planar track which is essentially a corner pin but 
>>>>>> I'll
>>>>>> admit I need to look more closely at it.
>>>>>>
>>>>>>
>>>>>> On 21 August 2011 23:40, Pete O'Connell <[email protected]>wrote:
>>>>>>
>>>>>>> Thanks a lot Ivan. I'll have a play around with that tonight.
>>>>>>>
>>>>>>> Cheers
>>>>>>> Pete
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Aug 22, 2011 at 3:57 PM, Ivan Busquets <
>>>>>>> [email protected]> wrote:
>>>>>>>
>>>>>>>> Hi Pete,
>>>>>>>>
>>>>>>>> It's very possible, but probably easier to do it in Python than
>>>>>>>> using
>>>>>>>> expression-links. Have a look at the nuke.math.Matrix4 class, and
>>>>>>>> its
>>>>>>>> mapUnitSquareToQuad() method.
>>>>>>>>
>>>>>>>> I have a function somewhere to feed the transformation of a
>>>>>>>> CornerPin
>>>>>>>> node into the "matrix" knob of a roto/rotopaint node that would
>>>>>>>> probably fit the bill for this too. I can try to dig that up if
>>>>>>>> you're
>>>>>>>> interested, but it would roughly consist of the following steps:
>>>>>>>>
>>>>>>>> 1 - Get the coordinates of the 4 "TO" corners from your cornerpin
>>>>>>>> node.
>>>>>>>> 2 - Build a "TO" matrix using mapUnitSquareToQuad(to0.x, to0.y,
>>>>>>>> to1.x,
>>>>>>>> to1.y, ...)
>>>>>>>> 3 - Get the coordinates of the 4 "FROM" corners from your cornerpin
>>>>>>>> node.
>>>>>>>> 4 - Build a "FROM" matrix using mapUnitSquareToQuad(from0.x,
>>>>>>>> from0.y,
>>>>>>>> from1.x, from1.y, ...)
>>>>>>>> 5 - The final transformation matrix should be =>  to_matrix *
>>>>>>>> from_matrix.inverse().
>>>>>>>>
>>>>>>>> Then you can use that to fill in the matrix knob in a gridwarp, a
>>>>>>>> roto
>>>>>>>> node, etc.
>>>>>>>>
>>>>>>>> Not the best example, but if you want some more info on how to use
>>>>>>>> nuke.math.Matrix4.mapUnitSquareToQuad(), have a look here (towards
>>>>>>>> the
>>>>>>>> end of the page).
>>>>>>>>
>>>>>>>>
>>>>>>>> http://www.nukepedia.com/written-tutorials/using-the-nukemath-python-module-to-do-vector-and-matrix-operations/page-4/
>>>>>>>>
>>>>>>>> Hope that helps.
>>>>>>>>
>>>>>>>> Cheers,
>>>>>>>> Ivan
>>>>>>>>
>>>>>>>> On Sun, Aug 21, 2011 at 10:24 PM, Pete O'Connell
>>>>>>>> <[email protected]> wrote:
>>>>>>>> > Hi does anyone know if it is possible somehow to convert cornerpin
>>>>>>>> values to
>>>>>>>> > a 4 by 4 matrix? Seem like it would be useful for the new Gridwarp
>>>>>>>> and
>>>>>>>> > Splinewarp nodes.
>>>>>>>> > Thanks
>>>>>>>> > Pete
>>>>>>>> >
>>>>>>>> >
>>>>>>>> > _______________________________________________
>>>>>>>> > Nuke-users mailing list
>>>>>>>> > [email protected],
>>>>>>>> http://forums.thefoundry.co.uk/
>>>>>>>> >
>>>>>>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>>>>>>>> >
>>>>>>>> _______________________________________________
>>>>>>>> Nuke-users mailing list
>>>>>>>> [email protected],
>>>>>>>> http://forums.thefoundry.co.uk/
>>>>>>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Pete
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Nuke-users mailing list
>>>>>>> [email protected], http://forums.thefoundry.co.uk/
>>>>>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Nuke-users mailing list
>>>>>> [email protected], http://forums.thefoundry.co.uk/
>>>>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Pete
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Pete
>>>>
>>>> _______________________________________________
>>>> Nuke-users mailing list
>>>> [email protected], http://forums.thefoundry.co.uk/
>>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>>>>
>>>
>>>
>>> _______________________________________________
>>> Nuke-users mailing list
>>> [email protected], http://forums.thefoundry.co.uk/
>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>>>
>>
>>
>>
>> --
>> Pete
>>
>
>
>
> --
> Pete
>
> _______________________________________________
> Nuke-users mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users

Reply via email to