Skip to content
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

Improve Python Example use_case_02.py with additional example codes #423

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion Wrapping/Python/Examples/use_case_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
import dream3d.simpl_helpers as simpl_helpers



#Generates a csv file with floats 0-37988 and ints 1-37989
def make_random_data():
imikejackson marked this conversation as resolved.
Show resolved Hide resolved
with open('new_data.csv', 'w') as f:
writer = csv.writer(f, lineterminator='\n',)
writer.writerow(["Float", "Int"])
i = 0
while i < 37989:
row = [i, i+1]
writer.writerow(row)
i = i+1

def import_csv_xyz_vertices_2(file_path: str):
"""
Expand All @@ -36,6 +45,35 @@ def import_csv_xyz_vertices_2(file_path: str):
dca.addOrReplaceDataContainer(dc)
# Write the Vertex Geometry out to a .dream3d file.
err = simpl_helpers.WriteDREAM3DFile('vert_geom_2.dream3d', dca, True)
imikejackson marked this conversation as resolved.
Show resolved Hide resolved

# Create Cell AttributeMatrix
tupleDims = simpl.VectorSizeT([1, 37989])
imikejackson marked this conversation as resolved.
Show resolved Hide resolved
am = simpl_helpers.CreateAttributeMatrix(tupleDims, 'CellAttributeMatrix', simpl.AttributeMatrix.Type.Cell)
imikejackson marked this conversation as resolved.
Show resolved Hide resolved

imikejackson marked this conversation as resolved.
Show resolved Hide resolved
# Create Data Arrays
#Loads in csv file and gets data for each type
uints = np.genfromtxt('new_data.csv', dtype=np.uint32, skip_header=1, usecols=1, delimiter=',')
f32s = np.genfromtxt('new_data.csv', dtype=np.float32, usecols=0, skip_header=1, delimiter=',')

#Creates arrays from data with shape of (# of vertices x 1)
uintarr = np.ndarray(shape=(37989, 1), dtype=np.uint32, buffer=uints)
floatarr = np.ndarray(shape=(37989, 1), dtype=np.float32, buffer=f32s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the numVerts variable from above instead of the 37989 hard coded value.


# Number of tuples must match the number of vertices
# Create 2 Data Arrays: UInt32 and Float32
# Populate data ararys with some random data
# or
# for bonus points read the data from another text file
#Makes simpl arrays using numpy arrays
uint32arr = simpl.UInt32Array(uintarr, 'UInt32 Arr', True)
f32arr = simpl.FloatArray(floatarr, 'Float32 Arr', True)

# Add Data Arrays to AttributeMatrix
am.addOrReplaceAttributeArray(uint32arr)
am.addOrReplaceAttributeArray(f32arr)

# Add AttributeMatirx to DataContainer
dc.addOrReplaceAttributeMatrix(am)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if you can add the DREAM3D filter "apply_transformation_to_geometry" which is in the DREAM3DReview plugin. Take a look at https://github.com/dream3d/DREAM3DReview/blob/develop/Test/Python/Apply_Transformation_To_Geometry.py file for inspiration.

In that example we are using a transformation matrix but see if you can figure out how to use just a scaling factor in each direction. Try out a scaling factor of 10x in each direction just to make it obvious when the data is viewed.

Write out the dream3d file before the transformation and after then use ParaView to view the results and verify that you have successfully scaled the vertices.


def import_csv_xyz_vertices_1(file_path: str):
Expand Down