def model_to_pb(self): ''' Converts the db model into a protobuf message. Parameters: None Returns: structure - protobuf message for a structure. ''' structure = Model_pb2.Structure() structure.Name = self.name structure.Color.R = self.color_r structure.Color.G = self.color_g structure.Color.B = self.color_b structure.Type = self.structure_type structure.FMACode = self.FMA_code structure.InputChannelID = self.input_channel_id structure.StructureID = self.structure_id return structure
def model_to_pb(self, filename=None): # Not implemented ''' Converts the db model into a protobuf message. Parameters: None Returns: m_f - protobuf message for a model family. ''' m_f = Model_pb2.ModelFamily() # Protobuf top-level fields m_f.CanonicalName = self.canonical_name m_f.LanguageCode = self.language_code # Family Description fields m_f.FamilyDescription.Name = self.name m_f.FamilyDescription.Description = self.description m_f.FamilyDescription.ClinicalDomain = self.clinical_domain m_f.FamilyDescription.AnatomicalRegion = self.anatomical_region m_f.FamilyDescription.PrimaryStructure = self.primary_structure m_f.FamilyDescription.Modalities = self.modalities # Family Description Input Channels for chan_desc in self.modelchanneldescription_set.all(): model_channel = Model_pb2.ModelChannelDescription() model_channel.ChannelID = chan_desc.channel_id for mode in ast.literal_eval(chan_desc.accepted_modalities_pb): model_channel.Constraints.AcceptedModalities.append(mode) model_channel.Constraints.OriginalDataRequired = chan_desc.req_original model_channel.Constraints.IsAxial = chan_desc.is_axial model_channel.Constraints.SpacingMinInMillimeters.X = chan_desc.spacing_min_x model_channel.Constraints.SpacingMinInMillimeters.Y = chan_desc.spacing_min_y model_channel.Constraints.SpacingMinInMillimeters.Z = chan_desc.spacing_min_z model_channel.Constraints.SpacingMaxInMillimeters.X = chan_desc.spacing_max_x model_channel.Constraints.SpacingMaxInMillimeters.Y = chan_desc.spacing_max_y model_channel.Constraints.SpacingMaxInMillimeters.Z = chan_desc.spacing_max_z model_channel.Constraints.DimensionsMinInPixels.X = chan_desc.dimensions_min_x model_channel.Constraints.DimensionsMinInPixels.Y = chan_desc.dimensions_min_y model_channel.Constraints.DimensionsMinInPixels.Z = chan_desc.dimensions_min_z model_channel.Constraints.DimensionsMaxInPixels.X = chan_desc.dimensions_max_x model_channel.Constraints.DimensionsMaxInPixels.Y = chan_desc.dimensions_max_y model_channel.Constraints.DimensionsMaxInPixels.Z = chan_desc.dimensions_max_z m_f.FamilyDescription.InputChannels.append(model_channel) # Family Description Constraint fields m_f.FamilyDescription.Constraints.Gender = self.gender for bpe in self.bodypartexamined_set.all(): m_f.FamilyDescription.Constraints.BodyPartsExamined.append( bpe.part_type) # Model Version fields for m_v in self.modelversion_set.all(): model_version = Model_pb2.ModelVersion() model_version.ID = m_v.model_version_id model_version.VersionDescription = m_v.model_version_desc timestamp = Timestamp() timestamp.FromDatetime(m_v.created_time) model_version.CreatedOn.seconds = timestamp.seconds model_version.CreatedOn.nanos = timestamp.nanos model_version.NumberOfCreditsRequired = m_v.credits_req model_version.MajorVersion = m_v.major_version model_version.MinorVersion = m_v.minor_version model_version.LanguageCode = m_v.language_code for m_struct in m_v.structure_set.all(): model_structure = Model_pb2.Structure() model_structure.Name = m_struct.name model_structure.Color.R = m_struct.color_r model_structure.Color.G = m_struct.color_g model_structure.Color.B = m_struct.color_b model_structure.Type = m_struct.structure_type model_structure.FMACode = m_struct.FMA_code model_structure.InputChannelID = m_struct.input_channel_id model_structure.StructureID = m_struct.structure_id model_version.Structures.append(model_structure) m_f.ModelVersions.append(model_version) return m_f