Skip to content

Commit

Permalink
Merge remote-tracking branch 'abi/main' into biunit_bladder
Browse files Browse the repository at this point in the history
  • Loading branch information
rchristie committed Jul 20, 2023
2 parents 3f56ed2 + df43843 commit 1fb35da
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/scaffoldmaker/utils/exportvtk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
"""
Class for exporting a Scaffold from Zinc to legacy vtk text format.
'''
"""

import io
import os
Expand All @@ -14,17 +14,17 @@


class ExportVtk:
'''
"""
Class for exporting a Scaffold from Zinc to legacy vtk text format.
Limited to writing only 3-D hexahedral elements. Assumes all nodes have field defined.
'''
"""

def __init__(self, region, description, annotationGroups = None):
'''
def __init__(self, region, description, annotationGroups=None):
"""
:param region: Region containing finite element model to export.
:param description: Single line text description up to 256 characters.
:param annotationGroups: Optional list of AnnotationGroup for model.
'''
"""
self._region = region
self._fieldmodule = self._region.getFieldmodule()
for dimension in range(3, 1, -1):
Expand All @@ -43,7 +43,7 @@ def __init__(self, region, description, annotationGroups = None):

def _write(self, outstream):
if version_info.major > 2:
assert isinstance(outstream, io.TextIOBase), 'ExportVtk.write: Invalid outstream argument'
assert isinstance(outstream, io.TextIOBase), 'ExportVtk.write: Invalid outstream argument'
outstream.write('# vtk DataFile Version 2.0\n')
outstream.write(self._description + '\n')
outstream.write('ASCII\n')
Expand All @@ -67,7 +67,7 @@ def _write(self, outstream):
result, x = self._coordinates.evaluateReal(cache, coordinatesCount)
if result != RESULT_OK:
print("Coordinates not found for node", node.getIdentifier())
x = [ 0.0 ]*coordinatesCount
x = [0.0] * coordinatesCount
if coordinatesCount < 3:
for c in range(coordinatesCount - 1, 3):
x.append(0.0)
Expand All @@ -78,15 +78,15 @@ def _write(self, outstream):
# following assumes all hex (3-D) or all quad (2-D) elements
if self._mesh.getDimension() == 2:
localNodeCount = 4
vtkIndexing = [ 0, 1, 3, 2 ]
vtkIndexing = [0, 1, 3, 2]
cellTypeString = '9'
else:
localNodeCount = 8
vtkIndexing = [ 0, 1, 3, 2, 4, 5, 7, 6 ]
vtkIndexing = [0, 1, 3, 2, 4, 5, 7, 6]
cellTypeString = '12'
localNodeCountStr = str(localNodeCount)
cellCount = self._mesh.getSize()
cellListSize = (1 + localNodeCount)*cellCount
cellListSize = (1 + localNodeCount) * cellCount
outstream.write('CELLS ' + str(cellCount) + ' ' + str(cellListSize) + '\n')
elementIter = self._mesh.createElementiterator()
element = elementIter.next()
Expand Down Expand Up @@ -119,7 +119,7 @@ def _write(self, outstream):
for annotationGroup in cellAnnotationGroups:
safeName = annotationGroup.getName().replace(' ', '_')
outstream.write('SCALARS ' + safeName + ' int 1\n')
outstream.write('LOOKUP_TABLE default\n')
outstream.write('LOOKUP_TABLE default\n')
meshGroup = annotationGroup.getMeshGroup(self._mesh)
elementIter = self._mesh.createElementiterator()
element = elementIter.next()
Expand All @@ -133,7 +133,7 @@ def _write(self, outstream):
for annotationGroup in pointAnnotationGroups:
safeName = annotationGroup.getName().replace(' ', '_')
outstream.write('SCALARS ' + safeName + ' int 1\n')
outstream.write('LOOKUP_TABLE default\n')
outstream.write('LOOKUP_TABLE default\n')
nodesetGroup = annotationGroup.getNodesetGroup(self._nodes)
nodeIter = self._nodes.createNodeiterator()
node = nodeIter.next()
Expand All @@ -143,7 +143,6 @@ def _write(self, outstream):
node = nodeIter.next()
outstream.write('\n')


def _writeMarkers(self, outstream):
coordinatesCount = self._coordinates.getNumberOfComponents()
cache = self._fieldmodule.createFieldcache()
Expand All @@ -163,11 +162,10 @@ def _writeMarkers(self, outstream):
node = nodeIter.next()
del markerCoordinates


def writeFile(self, filename):
'''
"""
Export to legacy vtk file.
'''
"""
try:
with open(filename, 'w') as outstream:
self._write(outstream)
Expand Down

0 comments on commit 1fb35da

Please sign in to comment.