def TranslateCoordinates(self,translation,type): """Returns a translated grid This method can be used to translate the coordinates of a grid. Two different types of translation exist * 'active' : Translates every grid point according to 'translation' * 'passive' : Translates the origin of the grid according to 'translation' This method only supports a translation vector that matches the grid coordinates and for this reason 'translation' should be specified in terms of these coordinates. """ import ArrayTools from Numeric import asarray from Vector import Vector import copy # finding the output grid translategrid=copy.copy(self) # preparing for translation and calculating origin #trunctranslation=self._GetTruncatedTranslation(translation) if type=='active': translationnumbers=self._GetTranslationNumbers(-asarray(translation)) # origin translategrid.SetOrigin(self.GetOrigin()) elif type=='passive': translationnumbers=self._GetTranslationNumbers(asarray(translation)) # origin transorigin=Vector(space=self.GetOrigin().GetSpace()) transorigin.SetCartesianCoordinates(translategrid.GetSpace().CartesianCoordinatesFromCoordinates(self.CoordinatesFromGridCoordinates(translation))) translategrid.SetOrigin(self.GetOrigin()+transorigin) else: raise ValueError, 'translation type not defined' # finding the output array translatearray=ArrayTools.Translate(self.GetArray(),translationnumbers) translategrid.SetArray(translatearray) return translategrid