GetMasterNodes and GetInterpolation function

General discussion about TexGen.

Moderators: Martin, Developers

Post Reply
lorenex
Posts: 8
Joined: Tue Sep 17, 2019 12:41 pm

GetMasterNodes and GetInterpolation function

Post by lorenex »

Dear Louise

Thank you for the reply on the email.
I tried the function "weave = GetTextile().GetWeave()" to get the textile which is created by the wizard. But when I use the GetMasterNodes function, it is still not working correctly.

the weave is as followed
weave33.png
weave33.png (63.54 KiB) Viewed 13117 times
I want to get the path information of the yarn0(red),
Is there a problem in my code in the python console?

Code: Select all

> weave = GetTextile().GetWeave()
>>> yarn0 = weave.GetYarn(0)
>>> yarn0.GetMasterNodes()
(<TexGen.Core.CNode; proxy of <Swig Object of type 'std::vector< TexGen::CNode >::value_type *' at 0x0000019992BFBFC0> >, <TexGen.Core.CNode; proxy of <Swig Object of type 'std::vector< TexGen::CNode >::value_type *' at 0x0000019992BFBF30> >, <TexGen.Core.CNode; proxy of <Swig Object of type 'std::vector< TexGen::CNode >::value_type *' at 0x0000019992BCB120> >, <TexGen.Core.CNode; proxy of <Swig Object of type 'std::vector< TexGen::CNode >::value_type *' at 0x0000019992BCB150> >)
>>> yarn0.GetInterpolation
<bound method CYarn.GetInterpolation of <TexGen.Core.CYarn; proxy of <Swig Object of type 'TexGen::CYarn *' at 0x0000019992BFBF60> >>
>>> 
Hope you could help me with the problem. Thank you very much

Best regards

Tong Qu
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: GetMasterNodes and GetInterpolation function

Post by louisepb »

Dear Tong Qu,

Apologies, getting the weave pattern wasn't the issue here after all because all of the functions that you're trying to access are functions of the base textile or the yarn class (bear in mind that if you want to use any of the functions contained in the weave class then you will need to do the GetWeave ).

It will help if you use the API reference to inform you about what parameters are passed to the functions and what the return values are. In the case of GetMasterNodes it returns a reference to a vector of nodes and so the error that you are getting is because you haven't provided a return value. Because the nodes are returned in a Python wrapped version of the C++ stl::vector you need to then use its access functions to get at the nodes. Once you have the node then you can access its position variable. See the code below.

>>> textile = GetTextile()
>>> yarn = textile.GetYarn(0)
>>> nodes = yarn.GetMasterNodes()
>>> node = nodes[0]
>>> point = node.GetPosition()
>>> point
0, 0, 0.15

Hope that helps,
Louise
lorenex
Posts: 8
Joined: Tue Sep 17, 2019 12:41 pm

Re: GetMasterNodes and GetInterpolation function

Post by lorenex »

Dear Louise,

Thank you very much! Your code is really hepful!

And I have another 2 questions:
1. Does the yarn path use one interpolation function through all master nodes, or there are different interpolation functions between every two master nodes ?
2. Can I get the interpolation function of the path or the control point of the Bézier spline?

Thank you!

best regards,

Tong Qu
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: GetMasterNodes and GetInterpolation function

Post by louisepb »

Hi Tong Qu,

The calculation of the interpolation is described in Martin Sherburn's thesis: http://eprints.nottingham.ac.uk/10303/1 ... -final.pdf

If you want to see the exact method that is used for the calculation look at the InterpolationBezier and mymath.h files here: https://github.com/louisepb/TexGen/tree/master/Core

Hope that helps,
Louise
lorenex
Posts: 8
Joined: Tue Sep 17, 2019 12:41 pm

Re: GetMasterNodes and GetInterpolation function

Post by lorenex »

Hello Louise,

Thank you for your information, it is really helpful.
I am a beginner to the python , and I find this code in the InterpolationBezier.cpp
Points.PNG
Points.PNG (14.98 KiB) Viewed 13097 times
Can I directly extract the position of point P2 and P3 from the python console through some functions?
And can the "m_Tangents[]" be used in the texgen python console? Thank you~

best regards

Tong Qu
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: GetMasterNodes and GetInterpolation function

Post by louisepb »

Hi Tong Qu,

The code you're looking at is C++ code which is wrapped to give the Python interface. The m_Tangents variable is a protected class variable and is therefore not accessible via the Python interface. The function in Interpolation.cpp which calculates these values is also protected so not accessible from the Python interface.

Is there a reason that you want to access this? What are you trying to do?

Best regards,
Louise
lorenex
Posts: 8
Joined: Tue Sep 17, 2019 12:41 pm

Re: GetMasterNodes and GetInterpolation function

Post by lorenex »

Hi Louise,

Actually I want to build a thin fiber(10µm in diameter) with the same shape as the yarn path in Abaqus. And I find that I can't directly export the path from TexGen into Abaqus. So I try to draw the path by my self.

Best regards,

Tong Qu
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: GetMasterNodes and GetInterpolation function

Post by louisepb »

Hi Tong Qu,

In that case I think what you need to do is to use the Yarn.GetSlaveNodes function. This will return a vector of the slave node positions calculated by the interpolation function. How many slave nodes there are is determined by the resolution. If you use the X-ray rendering in the GUI you can see how many there will be - one for each section rendered.

Alternately could you just create your very thin fibre in TexGen and then export that to Abaqus?

Hope that helps,
Louise
lorenex
Posts: 8
Joined: Tue Sep 17, 2019 12:41 pm

Re: GetMasterNodes and GetInterpolation function

Post by lorenex »

Hi Louise,

Thank you for your solution.

I have a problem on the code again...

Code: Select all

>>> textile = GetTextile()
>>> yarn = textile.GetYarn(0)
>>> yarn.SetResolution(20)
>>> nodes = yarn.GetSlaveNodes()
and the result is:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".\Python\libxtra\TexGen\Core.py", line 2277, in GetSlaveNodes
def GetSlaveNodes(self, *args): return _Core.CYarn_GetSlaveNodes(self, *args)
TypeError: CYarn_GetSlaveNodes() takes exactly 2 arguments (1 given)

What should I defined in the "( )" ?
And can I get all the slave nodes position once in the console?
Thank you!

Best,

Tong Qu
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: GetMasterNodes and GetInterpolation function

Post by louisepb »

Hi Tong Qu,

You will find the required parameters for functions in the Python API in the API reference guide http://texgen.sourceforge.net/api/class ... _yarn.html. The error message is telling you that you haven't passed enough parameters to the function. If you look at the documentation for the GetSlaveNodes function you will see that it is expecting a build type. In your case as you just want to get the data for the centreline it will probably be sufficient to send the LINE parameter.

Once you have got the slave node vector you will be able to use the appropriate functions to get the individual nodes and the positions stored in these nodes.

Hope that helps,
Louise
lorenex
Posts: 8
Joined: Tue Sep 17, 2019 12:41 pm

Re: GetMasterNodes and GetInterpolation function

Post by lorenex »

Hi Louise,

Thank you for the link! I forget to look up the API guide. It is really helpful.

Best,
Tong
Post Reply