| 704 | } |
| 705 | |
| 706 | bool mitk::Image::SetImportChannel(void *data, int n, ImportMemoryManagementType importMemoryManagement) |
| 707 | { |
| 708 | if (IsValidChannel(n) == false) |
| 709 | return false; |
| 710 | |
| 711 | // channel descriptor |
| 712 | |
| 713 | const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize(); |
| 714 | |
| 715 | ImageDataItemPointer ch; |
| 716 | if (IsChannelSet(n)) |
| 717 | { |
| 718 | ch = GetChannelData(n, data, importMemoryManagement); |
| 719 | if (ch->GetManageMemory() == false) |
| 720 | { |
| 721 | ch = AllocateChannelData(n, data, importMemoryManagement); |
| 722 | if (ch.GetPointer() == nullptr) |
| 723 | return false; |
| 724 | } |
| 725 | if (ch->GetData() != data) |
| 726 | std::memcpy(ch->GetData(), data, m_OffsetTable[4] * (ptypeSize)); |
| 727 | ch->Modified(); |
| 728 | ch->SetComplete(true); |
| 729 | // we have changed the data: call Modified()! |
| 730 | Modified(); |
| 731 | } |
| 732 | else |
| 733 | { |
| 734 | ch = AllocateChannelData(n, data, importMemoryManagement); |
| 735 | if (ch.GetPointer() == nullptr) |
| 736 | return false; |
| 737 | if (ch->GetData() != data) |
| 738 | std::memcpy(ch->GetData(), data, m_OffsetTable[4] * (ptypeSize)); |
| 739 | ch->SetComplete(true); |
| 740 | |
| 741 | this->m_ImageDescriptor->GetChannelDescriptor(n).SetData(ch->GetData()); |
| 742 | // we just added a missing Channel, which is not regarded as modification. |
| 743 | // Therefore, we do not call Modified()! |
| 744 | } |
| 745 | return true; |
| 746 | } |
| 747 | |
| 748 | void mitk::Image::Initialize() |
| 749 | { |