"""
# remove the arms, this function makes a copy of the model array. Hence, the tissue indices have been converted to
# our tissue names and it is not necessary to store the tissue_mapping for this model.
(model_trunk, trunk_mask) = txt_data.calculate_trunk_model(AustinMan, model_type='complete', z_start=480, z_end=821)
outer_shape_trunk = txt_data.calculate_outer_shape(model_trunk)

AustinMan.add_voxel_data(short_name='trunk',
                         name="The trunk of the 'complete' model. Arms have been removed using "
                              "VoxelModel.remove_arms().",
                         outer_shape=outer_shape_trunk,
                         model=model_trunk,
                         mask=trunk_mask,
                         tissue_mapping=None)

# create the 3D surface of the voxel model
surface = AustinMan.create_3d_model(model_type='trunk', patch_size=(30, 30))
AustinMan.models['trunk'].surface_3d = surface

AustinMan.models['trunk'].endpoints = []
for (i, s) in enumerate(surface):
    AustinMan.models['trunk'].endpoints.append(Coordinate(np.array(s['centroid'])))

# plot all the patches
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# plot the surface:
for s in AustinMan.models['trunk'].surface_3d:
    verts = s['verts']
    centroid = s['centroid']
    surf = Poly3DCollection(verts)
    surf.set_facecolor((0, 0, 0, 0.7))
# Calculate the trunk model
start_slice = int(96)
end_slice = int(141)

(model_trunk, trunk_mask) = AVW_Data.calculate_trunk_model(Donna,
                                                           'complete',
                                                           z_start=start_slice,
                                                           z_end=end_slice)
outer_shape_trunk = AVW_Data.calculate_outer_shape(model_trunk)

Donna.add_voxel_data(
    short_name='trunk',
    name="The trunk of the 'complete' model. Arms have been removed using "
    "VoxelModel.remove_arms().",
    outer_shape=outer_shape_trunk,
    model=model_trunk,
    mask=trunk_mask,
    tissue_mapping=None)

# Calculate the 3D surface of Donna
surface = Donna.create_3d_model(model_type='trunk', patch_size=(30, 30))
Donna.models['trunk'].surface_3d = surface

Donna.models['trunk'].endpoints = []
for (i, s) in enumerate(surface):
    Donna.models['trunk'].endpoints.append(Coordinate(np.array(
        s['centroid'])))  #

Donna.save_model()
                            tissue_names=tissue_name_orig)

VisibleHuman.add_voxel_data(short_name='complete',
                            name='The \'original\' model converted to our TissueProperties.',
                            model=VisibleHuman.models['original'].data,
                            outer_shape=outer_shape,
                            tissue_mapping=tissue_mapping)

# calculate the trunk model
# the slice z_end will not be included in the final model
(model_trunk, trunk_mask) = AVW_Data.calculate_trunk_model(VisibleHuman, model_type='complete', z_start=75, z_end=196)
outer_shape_trunk = AVW_Data.calculate_outer_shape(model_trunk)

VisibleHuman.add_voxel_data(short_name='trunk',
                            name="The trunk of the 'complete' model. Arms have been removed using "
                                 "VoxelModel.remove_arms().",
                            outer_shape=outer_shape_trunk,
                            model=model_trunk,
                            mask=trunk_mask,
                            tissue_mapping=None)

surface = VisibleHuman.create_3d_model(model_type='trunk', patch_size=(30, 30))
VisibleHuman.models['trunk'].surface_3d = surface

VisibleHuman.models['trunk'].endpoints = []
for (i, s) in enumerate(surface):
    VisibleHuman.models['trunk'].endpoints.append(Coordinate(np.array(s['centroid'])))


VisibleHuman.save_model()