Exemplo n.º 1
0
 def testGetNextVersionValue(self):
     val1 = Annotationelement().getNextVersionValue()
     val2 = Annotationelement().getNextVersionValue()
     assert val2 > val1
     Annotationelement().versionId = None
     val3 = Annotationelement().getNextVersionValue()
     assert val3 > val2
Exemplo n.º 2
0
 def testBoundingBox(self):
     bbox = Annotationelement()._boundingBox(
         {'points': [[1, -2, 3], [-4, 5, -6], [7, -8, 9]]})
     assert bbox == {
         'lowx': -4,
         'lowy': -8,
         'lowz': -6,
         'highx': 7,
         'highy': 5,
         'highz': 9,
         'details': 3,
         'size': ((7 + 4)**2 + (8 + 5)**2)**0.5
     }
     bbox = Annotationelement()._boundingBox({'center': [1, -2, 3]})
     assert bbox == {
         'lowx': 0.5,
         'lowy': -2.5,
         'lowz': 3,
         'highx': 1.5,
         'highy': -1.5,
         'highz': 3,
         'details': 1,
         'size': 2**0.5
     }
     bbox = Annotationelement()._boundingBox({
         'center': [1, -2, 3],
         'radius': 4
     })
     assert bbox == {
         'lowx': -3,
         'lowy': -6,
         'lowz': 3,
         'highx': 5,
         'highy': 2,
         'highz': 3,
         'details': 4,
         'size': 8 * 2**0.5
     }
     bbox = Annotationelement()._boundingBox({
         'center': [1, -2, 3],
         'width': 2,
         'height': 4
     })
     assert bbox == {
         'lowx': 0,
         'lowy': -4,
         'lowz': 3,
         'highx': 2,
         'highy': 0,
         'highz': 3,
         'details': 4,
         'size': (2**2 + 4**2)**0.5
     }
     bbox = Annotationelement()._boundingBox({
         'center': [1, -2, 3],
         'width': 2,
         'height': 4,
         'rotation': math.pi * 0.25
     })
     assert bbox['size'] == pytest.approx(4, 1.0e-4)
Exemplo n.º 3
0
    def testOverlayBounds(self, server, admin, fsAssetstore):
        file = utilities.uploadExternalFile('sample_image.ptif', admin, fsAssetstore)
        itemId = str(file['itemId'])

        # test no transform
        lowx, highx, lowy, highy = Annotationelement()._overlayBounds({
            'type': 'image', 'girderId': itemId
        })
        assert lowx == 0
        assert lowy == 0
        assert highx == 58368
        assert highy == 12288

        # test offset
        lowx, highx, lowy, highy = Annotationelement()._overlayBounds({
            'type': 'image', 'girderId': itemId,
            'transform': {'xoffset': 500, 'yoffset': 1000}
        })
        assert lowx == 500
        assert lowy == 1000
        assert highx == 58868
        assert highy == 13288

        # test affine matrix, scale to 50%
        lowx, highx, lowy, highy = Annotationelement()._overlayBounds({
            'type': 'image', 'girderId': itemId,
            'transform': {
                'matrix': [[0.5, 0], [0, 0.5]]
            }
        })
        assert lowx == 0
        assert lowy == 0
        assert highx == 58368 / 2
        assert highy == 12288 / 2

        # test transform and scaling
        lowx, highx, lowy, highy = Annotationelement()._overlayBounds({
            'type': 'image', 'girderId': itemId,
            'transform': {
                'xoffset': 500,
                'yoffset': 1000,
                'matrix': [[0.5, 0], [0, 0.5]]
            }
        })
        assert lowx == 500
        assert lowy == 1000
        assert highx == (58368 / 2) + 500
        assert highy == (12288 / 2) + 1000
Exemplo n.º 4
0
 def testRemoveElements(self, admin):
     publicFolder = utilities.namedFolder(admin, 'Public')
     item = Item().createItem('sample', admin, publicFolder)
     annot = Annotation().createAnnotation(item, admin, sampleAnnotation)
     assert len(Annotation().load(
         annot['_id'], user=admin)['annotation']['elements']) == 1
     Annotationelement().removeElements(annot)
     assert len(Annotation().load(
         annot['_id'], user=admin)['annotation']['elements']) == 0
Exemplo n.º 5
0
 def testOverlayBoundingBox(self, server, admin, fsAssetstore):
     file = utilities.uploadExternalFile('sample_image.ptif', admin, fsAssetstore)
     itemId = str(file['itemId'])
     bbox = Annotationelement()._boundingBox(
         {'type': 'image', 'girderId': itemId})
     assert bbox == {
         'lowx': 0, 'lowy': 0, 'lowz': 0,
         'highx': 58368, 'highy': 12288, 'highz': 0,
         'details': 1,
         'size': (58368**2 + 12288**2)**0.5}
Exemplo n.º 6
0
 def testGetElementsByCentroids(self, admin):
     publicFolder = utilities.namedFolder(admin, 'Public')
     item = Item().createItem('sample', admin, publicFolder)
     largeSample = makeLargeSampleAnnotation()
     # Use a copy of largeSample so we don't just have a reference to it
     annot = Annotation().createAnnotation(item, admin, largeSample.copy())
     # Clear existing element data, the get elements
     annot.pop('elements', None)
     annot.pop('_elementQuery', None)
     Annotationelement().getElements(annot, {'centroids': True})
     assert '_elementQuery' in annot
     assert len(annot['annotation']['elements']) == len(largeSample['elements'])  # 7707
     assert annot['_elementQuery']['centroids'] is True
     assert 'props' in annot['_elementQuery']
     elements = annot['annotation']['elements']
     assert isinstance(elements[0], list)
Exemplo n.º 7
0
 def testGetElements(self, admin):
     publicFolder = utilities.namedFolder(admin, 'Public')
     item = Item().createItem('sample', admin, publicFolder)
     largeSample = makeLargeSampleAnnotation()
     # Use a copy of largeSample so we don't just have a reference to it
     annot = Annotation().createAnnotation(item, admin, largeSample.copy())
     # Clear existing element data, the get elements
     annot.pop('elements', None)
     annot.pop('_elementQuery', None)
     Annotationelement().getElements(annot)
     assert '_elementQuery' in annot
     assert len(annot['annotation']['elements']) == len(largeSample['elements'])  # 7707
     assert 'centroids' not in annot['_elementQuery']
     annot.pop('elements', None)
     annot.pop('_elementQuery', None)
     Annotationelement().getElements(annot, {'limit': 100})
     assert '_elementQuery' in annot
     assert annot['_elementQuery']['count'] == len(largeSample['elements'])
     assert annot['_elementQuery']['returned'] == 100
     assert len(annot['annotation']['elements']) == 100
     annot.pop('elements', None)
     annot.pop('_elementQuery', None)
     Annotationelement().getElements(annot, {
         'left': 3000, 'right': 4000, 'top': 4500, 'bottom': 6500})
     assert len(annot['annotation']['elements']) == 157
     annot.pop('elements', None)
     annot.pop('_elementQuery', None)
     Annotationelement().getElements(annot, {
         'left': 3000, 'right': 4000, 'top': 4500, 'bottom': 6500,
         'minimumSize': 16})
     assert len(annot['annotation']['elements']) == 39
     annot.pop('elements', None)
     annot.pop('_elementQuery', None)
     Annotationelement().getElements(annot, {'maxDetails': 300})
     assert len(annot['annotation']['elements']) == 75
     annot.pop('elements', None)
     annot.pop('_elementQuery', None)
     Annotationelement().getElements(annot, {
         'maxDetails': 300, 'sort': 'size', 'sortdir': -1})
     elements = annot['annotation']['elements']
     assert (elements[0]['width'] * elements[0]['height'] >
             elements[-1]['width'] * elements[-1]['height'])
     annot.pop('elements', None)
     annot.pop('_elementQuery', None)
     Annotationelement().getElements(annot, {
         'maxDetails': 300, 'sort': 'size', 'sortdir': 1})
     elements = annot['annotation']['elements']
     assert (elements[0]['width'] * elements[0]['height'] <
             elements[-1]['width'] * elements[-1]['height'])
Exemplo n.º 8
0
 def testInitialize(self):
     # initialize should be called as we fetch the model
     assert Annotationelement().name == 'annotationelement'