-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Texture coordinates #46
Changes from 3 commits
ef40e5d
358b76e
f5e4921
6f23521
0276ce1
a18b728
155369e
d2cc1e2
5d7e753
5e7d344
f5a52d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,3 +206,22 @@ def createEftSplitXi1RightOut(self): | |
remapEftNodeValueLabel(eft, [ 5, 7 ], self._d_ds2, [ (self._d_ds1, [1]), (self._d_ds2, []) ]) | ||
assert eft.validate(), 'eftfactory_bicubichermitelinear.createEftSplitXi1RightOut: Failed to validate eft' | ||
return eft | ||
|
||
def createEftOpenTube(self): | ||
''' | ||
Create a basic bicubic hermite linear element template for elements | ||
along boundary where a tube is opened for a flat preparation. Retain node | ||
numbering with two versions for boundary nodes. | ||
:return: Element field template | ||
''' | ||
eft = self.createEftBasic() | ||
for n in [ 1, 3, 5, 7 ]: | ||
ln = n + 1 | ||
eft.setTermNodeParameter(n*4 + 1, 1, ln, Node.VALUE_LABEL_VALUE, 2) | ||
eft.setTermNodeParameter(n*4 + 2, 1, ln, Node.VALUE_LABEL_D_DS1, 2) | ||
eft.setTermNodeParameter(n*4 + 3, 1, ln, Node.VALUE_LABEL_D_DS2, 2) | ||
if self._useCrossDerivatives: | ||
eft.setTermNodeParameter(n*4 + 4, 1, ln, Node.VALUE_LABEL_D2_DS1DS2, 2) | ||
|
||
assert eft.validate(), 'eftfactory_bicubichermitelinear.createEftFlattenTube: Failed to validate eft' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function name difference in assert. |
||
return eft |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,6 +243,107 @@ def generatetubemesh(region, | |
result = element.setNodesByIdentifier(eft, nodeIdentifiers) | ||
elementIdentifier = elementIdentifier + 1 | ||
|
||
# Create texture coordinates | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define texture coordinates field |
||
textureCoordinates = getOrCreateTextureCoordinateField(fm) | ||
textureNodetemplate1 = nodes.createNodetemplate() | ||
textureNodetemplate1.defineField(textureCoordinates) | ||
textureNodetemplate1.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_VALUE, 1) | ||
textureNodetemplate1.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_D_DS1, 1) | ||
textureNodetemplate1.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_D_DS2, 1) | ||
if useCrossDerivatives: | ||
textureNodetemplate1.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_D2_DS1DS2, 1) | ||
|
||
textureNodetemplate2 = nodes.createNodetemplate() | ||
textureNodetemplate2.defineField(textureCoordinates) | ||
textureNodetemplate2.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_VALUE, 2) | ||
textureNodetemplate2.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_D_DS1, 2) | ||
textureNodetemplate2.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_D_DS2, 2) | ||
if useCrossDerivatives: | ||
textureNodetemplate2.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_D2_DS1DS2, 2) | ||
|
||
bicubichermitelinear = eftfactory_bicubichermitelinear(mesh, useCrossDerivatives) | ||
eftTexture = bicubichermitelinear.createEftBasic() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eftTexture1 for consistency with elementtemplate1 below. |
||
|
||
elementtemplate1 = mesh.createElementtemplate() | ||
elementtemplate1.setElementShapeType(Element.SHAPE_TYPE_CUBE) | ||
elementtemplate1.defineField(textureCoordinates, -1, eftTexture) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eftTexture1 |
||
|
||
eftTexture2 = bicubichermitelinear.createEftOpenTube() | ||
elementtemplate2 = mesh.createElementtemplate() | ||
elementtemplate2.setElementShapeType(Element.SHAPE_TYPE_CUBE) | ||
elementtemplate2.defineField(textureCoordinates, -1, eftTexture2) | ||
|
||
# Calculate texture coordinates and derivatives | ||
uTexture = [] | ||
d1Texture = [] | ||
d2Texture = [] | ||
for n3 in range(elementsCountThroughWall + 1): | ||
for n2 in range(elementsCountAlong + 1): | ||
for n1 in range(elementsCountAround + 1): | ||
u = [ 1.0 / elementsCountAround * n1, | ||
1.0 / elementsCountAlong * n2, | ||
1.0 / elementsCountThroughWall * n3] | ||
d1 = [1.0 / elementsCountAround, 0.0, 0.0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d1 and d2 are not functions of n1, n2 or n3, so no need to calculate and store. |
||
d2 = [0.0, 1.0 / elementsCountAlong, 0.0] | ||
uTexture.append(u) | ||
d1Texture.append(d1) | ||
d2Texture.append(d2) | ||
|
||
nodeIdentifier = nextNodeIdentifier | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change 'next' to 'first' in nextNodeIdentifier, nextElementIdentifier throughout this function as it's clearer. |
||
for n in range(len(uTexture)): | ||
if n%(elementsCountAround+1) == 0.0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. == 0, not a floating point.
... and then compute coordinates from those precalculated around one slice. |
||
node = nodes.findNodeByIdentifier(nodeIdentifier) | ||
node.merge(textureNodetemplate2) | ||
cache.setNode(node) | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1, uTexture[n]) | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1, d1Texture[n]) | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1, d2Texture[n]) | ||
endIdx = n + elementsCountAround | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 2, uTexture[endIdx]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the code in the if and else clauses is the same except setting the second version for the last nodes. Put the common code in one place. i.e. at the end:
|
||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 2, d1Texture[endIdx]) | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 2, d2Texture[endIdx]) | ||
if useCrossDerivatives: | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 1, zero) | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 2, zero) | ||
nodeIdentifier = nodeIdentifier + 1 | ||
elif (n+1)%(elementsCountAround+1) > 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to just 'else'. |
||
node = nodes.findNodeByIdentifier(nodeIdentifier) | ||
node.merge(textureNodetemplate1) | ||
cache.setNode(node) | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1, uTexture[n]) | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1, d1Texture[n]) | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1, d2Texture[n]) | ||
if useCrossDerivatives: | ||
textureCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 1, zero) | ||
nodeIdentifier = nodeIdentifier + 1 | ||
|
||
# create texture coordinate elements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change comment to 'define texture coordinates field over elements |
||
elementIdentifier = nextElementIdentifier | ||
now = (elementsCountAlong + 1)*elementsCountAround | ||
for e3 in range(elementsCountThroughWall): | ||
for e2 in range(elementsCountAlong): | ||
for e1 in range(elementsCountAround): | ||
if e1 < elementsCountAround - 1: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of this code is common. Change to:
(note renamed to eftTexture1 for consistency earlier) |
||
element = mesh.findElementByIdentifier(elementIdentifier) | ||
element.merge(elementtemplate1) | ||
bni11 = e3*now + e2*elementsCountAround + e1 + 1 | ||
bni12 = e3*now + e2*elementsCountAround + (e1 + 1)%elementsCountAround + 1 | ||
bni21 = e3*now + (e2 + 1)*elementsCountAround + e1 + 1 | ||
bni22 = e3*now + (e2 + 1)*elementsCountAround + (e1 + 1)%elementsCountAround + 1 | ||
nodeIdentifiers = [ bni11, bni12, bni21, bni22, bni11 + now, bni12 + now, bni21 + now, bni22 + now ] | ||
result = element.setNodesByIdentifier(eftTexture, nodeIdentifiers) | ||
else: | ||
element = mesh.findElementByIdentifier(elementIdentifier) | ||
element.merge(elementtemplate2) | ||
# element = mesh.createElement(elementIdentifier, elementtemplate2) | ||
bni11 = e3*now + e2*elementsCountAround + e1 + 1 | ||
bni12 = e3*now + e2*elementsCountAround + (e1 + 1)%elementsCountAround + 1 | ||
bni21 = e3*now + (e2 + 1)*elementsCountAround + e1 + 1 | ||
bni22 = e3*now + (e2 + 1)*elementsCountAround + (e1 + 1)%elementsCountAround + 1 | ||
nodeIdentifiers = [ bni11, bni12, bni21, bni22, bni11 + now, bni12 + now, bni21 + now, bni22 + now] | ||
result2 = element.setNodesByIdentifier(eftTexture2, nodeIdentifiers) | ||
elementIdentifier = elementIdentifier + 1 | ||
|
||
fm.endChange() | ||
|
||
return annotationGroups, nodeIdentifier, elementIdentifier | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document: opened on xi1 = 1. Could eventually have 6 variants.