def LoadSaveTransform(self, transform):

        transformString = factory.TransformToIRToolsString(transform)

        loadedTransform = factory.LoadTransform(transformString)

        pointMatch = numpy.allclose(transform.points,
                                    loadedTransform.points,
                                    atol=0.5)

        self.assertTrue(
            pointMatch,
            "Converting transform to string and back alters transform")

        self.assertTrue(
            numpy.allclose(transform.FixedBoundingBox.ToArray(),
                           loadedTransform.FixedBoundingBox.ToArray(),
                           rtol=1e-04),
            "Fixed bounding box should match after converting transform to string and back"
        )
        self.assertTrue(
            numpy.allclose(transform.MappedBoundingBox.ToArray(),
                           loadedTransform.MappedBoundingBox.ToArray(),
                           rtol=1e-04),
            "Mapped bounding box should match after converting transform to string and back"
        )

        secondString = factory.TransformToIRToolsString(loadedTransform)
        self.assertTrue(
            secondString == transformString,
            "Converting transform to string twice should produce identical string"
        )
Esempio n. 2
0
    def _ConvertTransformStringsToTransforms(cls, image_to_transform):
        '''If the dictionary contains transforms in string format convert them to transform objects in place'''

        for (image, transform) in image_to_transform.items():
            if isinstance(transform, str):
                transform_object = tfactory.LoadTransform(transform)
                image_to_transform[image] = transform_object

        return
Esempio n. 3
0
def ParameterToStosTransform(transformData):
    '''
    :param object transformData: Either a full path to a .stos file, a stosfile, or a transform object
    :return: A transform
    '''
    stostransform = None

    if isinstance(transformData, str):
        if not os.path.exists(transformData):
            raise ValueError(
                "transformData is not a valid path to a .stos file %s" %
                transformData)
        stos = StosFile.Load(transformData)
        stostransform = factory.LoadTransform(stos.Transform)
    elif isinstance(transformData, StosFile):
        stos = transformData.Transform
        stostransform = factory.LoadTransform(stos.Transform)
    elif isinstance(transformData, transformbase.Base):
        stostransform = transformData

    return stostransform
Esempio n. 4
0
    def LoadTransform(self, StosData):
        ''':return: A Transform'''

        obj = None
        if isinstance(StosData, str):
            obj = StosFile.Load(StosData)
        elif isinstance(StosData, StosFile):
            obj = StosData

        if obj is None:
            return

        stostransform = factory.LoadTransform(obj.Transform)
        if not stostransform is None:
            self.TransformController.SetPoints(stostransform.points)
Esempio n. 5
0
    def Load(cls, StosGroupNode):
        '''Load transforms from a stos group into a volume object.'''

        vol = StosGroupVolume()

        TransformToNodeAndStosObj = {}

        for mappingNode in StosGroupNode.SectionMappings:
            for transformNode in mappingNode.Transforms:
                stosObj = stosfile.StosFile.Load(transformNode.FullPath)
                stosTransform = factory.LoadTransform(stosObj.Transform,
                                                      StosGroupNode.Downsample)

                sectionKey = "%s_%s" % (transformNode.MappedSectionNumber,
                                        transformNode.MappedChannelName)

                stosTransform.transformNode = transformNode
                stosTransform.stosObj = stosObj

                vol.AddOrUpdateSection(sectionKey, stosTransform)

        return vol