예제 #1
0
파일: treenode.py 프로젝트: fzadow/CATMAID
def _create_interpolated_treenode(request, params, project_id, skip_last):
    """ Create interpolated treenodes between the 'parent_id' and the clicked
    x,y,z coordinate. The skip_last is to prevent the creation of the last
    node, used by the join_skeletons_interpolated. """
    response_on_error = 'Could not create interpolated treenode'
    try:
        # Raise an Exception if the user doesn't have permission to edit
        # the neuron the skeleton of the treenode is modeling.
        can_edit_treenode_or_fail(request.user, project_id,
                                  params['parent_id'])

        parent = Treenode.objects.get(pk=params['parent_id'])
        parent_skeleton_id = parent.skeleton_id
        parent_x = decimal.Decimal(parent.location_x)
        parent_y = decimal.Decimal(parent.location_y)
        parent_z = decimal.Decimal(parent.location_z)

        steps = abs((params['z'] - parent_z) / params['resz']) \
            .quantize(decimal.Decimal('1'), rounding=decimal.ROUND_FLOOR)
        if steps == decimal.Decimal(0):
            steps = decimal.Decimal(1)

        dx = (params['x'] - parent_x) / steps
        dy = (params['y'] - parent_y) / steps
        dz = (params['z'] - parent_z) / steps

        broken_slices = set(int(bs.index) for bs in \
            BrokenSlice.objects.filter(stack=params['stack_id']))
        sign = -1 if dz < 0 else 1

        # Loop the creation of treenodes in z resolution steps until target
        # section is reached
        parent_id = params['parent_id']
        atn_slice_index = ((parent_z - params['stack_translation_z']) / params['resz']) \
            .quantize(decimal.Decimal('1'), rounding=decimal.ROUND_FLOOR)
        for i in range(1, steps + (0 if skip_last else 1)):
            if (atn_slice_index + i * sign) in broken_slices:
                continue
            response_on_error = 'Error while trying to insert treenode.'
            new_treenode = Treenode()
            new_treenode.user_id = request.user.id
            new_treenode.editor_id = request.user.id
            new_treenode.project_id = project_id
            new_treenode.location_x = float(parent_x + dx * i)
            new_treenode.location_y = float(parent_y + dy * i)
            new_treenode.location_z = float(parent_z + dz * i)
            new_treenode.radius = params['radius']
            new_treenode.skeleton_id = parent_skeleton_id
            new_treenode.confidence = params['confidence']
            new_treenode.parent_id = parent_id  # This is not a root node.
            new_treenode.save()

            parent_id = new_treenode.id

        # parent_id contains the ID of the last added node
        return parent_id, parent_skeleton_id

    except Exception as e:
        raise Exception(response_on_error + ':' + str(e))
예제 #2
0
파일: treenode.py 프로젝트: fzadow/CATMAID
def _create_interpolated_treenode(request, params, project_id, skip_last):
    """ Create interpolated treenodes between the 'parent_id' and the clicked
    x,y,z coordinate. The skip_last is to prevent the creation of the last
    node, used by the join_skeletons_interpolated. """
    response_on_error = 'Could not create interpolated treenode'
    try:
        # Raise an Exception if the user doesn't have permission to edit
        # the neuron the skeleton of the treenode is modeling.
        can_edit_treenode_or_fail(request.user, project_id, params['parent_id'])

        parent = Treenode.objects.get(pk=params['parent_id'])
        parent_skeleton_id = parent.skeleton_id
        parent_x = decimal.Decimal(parent.location_x)
        parent_y = decimal.Decimal(parent.location_y)
        parent_z = decimal.Decimal(parent.location_z)

        steps = abs((params['z'] - parent_z) / params['resz']) \
            .quantize(decimal.Decimal('1'), rounding=decimal.ROUND_FLOOR)
        if steps == decimal.Decimal(0):
            steps = decimal.Decimal(1)

        dx = (params['x'] - parent_x) / steps
        dy = (params['y'] - parent_y) / steps
        dz = (params['z'] - parent_z) / steps

        broken_slices = set(int(bs.index) for bs in \
            BrokenSlice.objects.filter(stack=params['stack_id']))
        sign = -1 if dz < 0 else 1

        # Loop the creation of treenodes in z resolution steps until target
        # section is reached
        parent_id = params['parent_id']
        atn_slice_index = ((parent_z - params['stack_translation_z']) / params['resz']) \
            .quantize(decimal.Decimal('1'), rounding=decimal.ROUND_FLOOR)
        for i in range(1, steps + (0 if skip_last else 1)):
            if (atn_slice_index + i * sign) in broken_slices:
                continue
            response_on_error = 'Error while trying to insert treenode.'
            new_treenode = Treenode()
            new_treenode.user_id = request.user.id
            new_treenode.editor_id = request.user.id
            new_treenode.project_id = project_id
            new_treenode.location_x = float(parent_x + dx * i)
            new_treenode.location_y = float(parent_y + dy * i)
            new_treenode.location_z = float(parent_z + dz * i)
            new_treenode.radius = params['radius']
            new_treenode.skeleton_id = parent_skeleton_id
            new_treenode.confidence = params['confidence']
            new_treenode.parent_id = parent_id  # This is not a root node.
            new_treenode.save()

            parent_id = new_treenode.id

        # parent_id contains the ID of the last added node
        return parent_id, parent_skeleton_id

    except Exception as e:
        raise Exception(response_on_error + ':' + str(e))
예제 #3
0
파일: treenode.py 프로젝트: fzadow/CATMAID
 def insert_new_treenode(parent_id=None, skeleton=None):
     """ If the parent_id is not None and the skeleton_id of the parent does
     not match with the skeleton.id, then the database will throw an error
     given that the skeleton_id, being defined as foreign key in the
     treenode table, will not meet the being-foreign requirement.
     """
     new_treenode = Treenode()
     new_treenode.user = request.user
     new_treenode.editor = request.user
     new_treenode.project_id = project_id
     new_treenode.location_x = float(params['x'])
     new_treenode.location_y = float(params['y'])
     new_treenode.location_z = float(params['z'])
     new_treenode.radius = int(params['radius'])
     new_treenode.skeleton = skeleton
     new_treenode.confidence = int(params['confidence'])
     if parent_id:
         new_treenode.parent_id = parent_id
     new_treenode.save()
     return new_treenode
예제 #4
0
파일: treenode.py 프로젝트: fzadow/CATMAID
 def insert_new_treenode(parent_id=None, skeleton=None):
     """ If the parent_id is not None and the skeleton_id of the parent does
     not match with the skeleton.id, then the database will throw an error
     given that the skeleton_id, being defined as foreign key in the
     treenode table, will not meet the being-foreign requirement.
     """
     new_treenode = Treenode()
     new_treenode.user = request.user
     new_treenode.editor = request.user
     new_treenode.project_id = project_id
     new_treenode.location_x = float(params['x'])
     new_treenode.location_y = float(params['y'])
     new_treenode.location_z = float(params['z'])
     new_treenode.radius = int(params['radius'])
     new_treenode.skeleton = skeleton
     new_treenode.confidence = int(params['confidence'])
     if parent_id:
         new_treenode.parent_id = parent_id
     new_treenode.save()
     return new_treenode
예제 #5
0
파일: treenode.py 프로젝트: pgunn/CATMAID
 def insert_new_treenode(parent_id=None, skeleton_id=None):
     """ If the parent_id is not None and the skeleton_id of the parent does
     not match with the skeleton.id, then the database will throw an error
     given that the skeleton_id, being defined as foreign key in the
     treenode table, will not meet the being-foreign requirement.
     """
     new_treenode = Treenode()
     new_treenode.user = creator
     new_treenode.editor = editor
     new_treenode.project_id = project_id
     if creation_time:
         new_treenode.creation_time = creation_time
     new_treenode.location_x = float(x)
     new_treenode.location_y = float(y)
     new_treenode.location_z = float(z)
     new_treenode.radius = int(radius)
     new_treenode.skeleton_id = skeleton_id
     new_treenode.confidence = int(confidence)
     if parent_id:
         new_treenode.parent_id = parent_id
     new_treenode.save()
     return new_treenode
예제 #6
0
파일: treenode.py 프로젝트: AdaEne/CATMAID
 def insert_new_treenode(parent_id=None, skeleton_id=None):
     """ If the parent_id is not None and the skeleton_id of the parent does
     not match with the skeleton.id, then the database will throw an error
     given that the skeleton_id, being defined as foreign key in the
     treenode table, will not meet the being-foreign requirement.
     """
     new_treenode = Treenode()
     new_treenode.user = creator
     new_treenode.editor = editor
     new_treenode.project_id = project_id
     if creation_time:
         new_treenode.creation_time = creation_time
     new_treenode.location_x = float(x)
     new_treenode.location_y = float(y)
     new_treenode.location_z = float(z)
     new_treenode.radius = int(radius)
     new_treenode.skeleton_id = skeleton_id
     new_treenode.confidence = int(confidence)
     if parent_id:
         new_treenode.parent_id = parent_id
     new_treenode.save()
     return new_treenode