def _loadOrientationMap(menuitem, microstructure, filename, orientations): # orientations is a list of 3-tuples representing ABG Euler # angles. mscontext = ooflib.common.microstructure.microStructures[microstructure] ms = mscontext.getObject() od = orientmapdata.OrientMap(ms.sizeInPixels(), ms.size()) reader = orientmapdata.OrientMapReader() # just to borrow its set_angle fn count = 0 for pixel in ms.coords(): reader.set_angle(od, pixel, corientation.COrientABG(*orientations[count])) count += 1 orientmapdata.registerOrientMap(microstructure, od) orientmapplugin = mscontext.getObject().getPlugIn('OrientationMap') orientmapplugin.set_data(od, filename) orientmapplugin.timestamp.increment() orientmapdata.orientationmapNotify(ms)
def _createMSFromOrientationMapFile(menuitem, filename, format, microstructure): reader = orientmapdata.getOrientMapReaderClass(format.name)() data = reader.read(filename) # creates OrientMap object if data is None: return ms = ooflib.SWIG.common.cmicrostructure.CMicrostructure( microstructure, data.sizeInPixels(), data.size()) mscontext = ooflib.common.microstructure.microStructures[microstructure] mscontext.reserve() mscontext.begin_writing() try: orientmapdata.registerOrientMap(microstructure, data) orientmapplugin = ms.getPlugIn('OrientationMap') orientmapplugin.set_data(data, filename) orientmapplugin.timestamp.increment() # ======= # reader = orientmapdata.getOrientMapReaderClass(format.name)() # data = reader.read(filename) # creates OrientMap object # if data is None: # return # ms = ooflib.SWIG.common.cmicrostructure.CMicrostructure(microstructure, # data.sizeInPixels(), # data.size()) # mscontext = ooflib.common.microstructure.microStructures[microstructure] # mscontext.reserve() # mscontext.begin_writing() # try: # orientmapdata.registerOrientMap(microstructure, data) # orientmapplugin = ms.getPlugIn('OrientationMap') # orientmapplugin.set_data(data, filename) # orientmapplugin.timestamp.increment() # finally: # mscontext.end_writing() # mscontext.cancel_reservation() # reader.postProcess(mscontext) # orientmapdata.orientationmapNotify(ms) # >>>>>>> 1.10.4.1 finally: mscontext.end_writing() mscontext.cancel_reservation() reader.postProcess(mscontext) orientmapdata.orientationmapNotify(ms)
def _createMSFromOrientationMapFile(menuitem, filename, reader, microstructure): data = reader.read(filename) # creates OrientMap object if data is None: return ms = ooflib.common.microstructure.Microstructure(microstructure, data.sizeInPixels(), data.size()) mscontext = ooflib.common.microstructure.microStructures[microstructure] mscontext.reserve() mscontext.begin_writing() try: orientmapdata.registerOrientMap(microstructure, data) orientmapplugin = ms.getPlugIn('OrientationMap') orientmapplugin.set_data(data, filename) orientmapplugin.timestamp.increment() finally: mscontext.end_writing() mscontext.cancel_reservation() reader.postProcess(mscontext) orientmapdata.orientationmapNotify(ms)
def _loadOrientationMap(menuitem, filename, reader, microstructure): # format is an Enum object. microstructure is a name. mscontext = ooflib.common.microstructure.microStructures[microstructure] mscontext.reserve() mscontext.begin_writing() try: # Check to see if the microstructure already has an # orientation map. It can't have more than one. if orientmapdata.getOrientationMap(mscontext.getObject()) is not None: raise ooferror.ErrUserError( "A Microstructure can contain only one orientation map.") data = reader.read(filename) # creates OrientMap object if (mscontext.getObject().sizeInPixels() != data.sizeInPixels() or mscontext.getObject().size() != data.size()): raise ooferror.ErrUserError( "Cannot load orientation map into an existing Microstructure of a different size. ms=%sx%s (%dx%d), map=%sx%s (%dx%d)" % ( mscontext.getObject().size()[0], mscontext.getObject().size()[1], mscontext.getObject().sizeInPixels()[0], mscontext.getObject().sizeInPixels()[1], data.size()[0], data.size()[1], data.sizeInPixels()[0], data.sizeInPixels()[1])) # Registering the OrientMapData object under its # microstructure's name allows it to be found by the # OrientationMapProp Property in C++. orientmapdata.registerOrientMap(microstructure, data) data.setMicrostructure(mscontext.getObject()) # Storing it as a Python Microstructure plug-in allows the # data to be found by Python (and keeps a live reference to # it, so we don't have to transfer ownership to C++). All of # this registration doesn't actually duplicate the data. orientmapplugin = mscontext.getObject().getPlugIn("OrientationMap") orientmapplugin.set_data(data, filename) orientmapplugin.timestamp.increment() finally: mscontext.end_writing() mscontext.cancel_reservation() reader.postProcess(mscontext) orientmapdata.orientationmapNotify(mscontext.getObject())
def _createMSFromOrientationMapFile(menuitem, filename, reader, microstructure): data = reader.read(filename) # creates OrientMap object if data is None: return ms = ooflib.common.microstructure.Microstructure(microstructure, data.sizeInPixels(), data.size()) mscontext = ooflib.common.microstructure.microStructures[microstructure] mscontext.reserve() mscontext.begin_writing() try: orientmapdata.registerOrientMap(microstructure, data) data.setMicrostructure(mscontext.getObject()) orientmapplugin = ms.getPlugIn('OrientationMap') orientmapplugin.set_data(data, filename) orientmapplugin.timestamp.increment() finally: mscontext.end_writing() mscontext.cancel_reservation() reader.postProcess(mscontext) orientmapdata.orientationmapNotify(ms)
def _loadOrientationMap(menuitem, filename, reader, microstructure): # format is an Enum object. microstructure is a name. mscontext = ooflib.common.microstructure.microStructures[microstructure] mscontext.reserve() mscontext.begin_writing() try: # Check to see if the microstructure already has an # orientation map. It can't have more than one. if orientmapdata.getOrientationMap(mscontext.getObject()) is not None: raise ooferror.ErrUserError( "A Microstructure can contain only one orientation map.") data = reader.read(filename) # creates OrientMap object if (mscontext.getObject().sizeInPixels() != data.sizeInPixels() or mscontext.getObject().size() != data.size()): raise ooferror.ErrUserError( "Cannot load orientation map into an existing Microstructure of a different size. ms=%sx%s (%dx%d), map=%sx%s (%dx%d)" % ( mscontext.getObject().size()[0], mscontext.getObject().size()[1], mscontext.getObject().sizeInPixels()[0], mscontext.getObject().sizeInPixels()[1], data.size()[0], data.size()[1], data.sizeInPixels()[0], data.sizeInPixels()[1])) # Registering the OrientMapData object under its # microstructure's name allows it to be found by the # OrientationMapProp Property in C++. orientmapdata.registerOrientMap(microstructure, data) # Storing it as a Python Microstructure plug-in allows the # data to be found by Python (and keeps a live reference to # it, so we don't have to transfer ownership to C++). All of # this registration doesn't actually duplicate the data. orientmapplugin = mscontext.getObject().getPlugIn("OrientationMap") orientmapplugin.set_data(data, filename) orientmapplugin.timestamp.increment() finally: mscontext.end_writing() mscontext.cancel_reservation() reader.postProcess(mscontext) orientmapdata.orientationmapNotify(mscontext.getObject())