mitk::DataNode::Pointer mitk::Tool::CreateEmptySegmentationNode( Image* original, const std::string& organName, const mitk::Color& color ) { // we NEED a reference image for size etc. if (!original) return NULL; // actually create a new empty segmentation PixelType pixelType(mitk::MakeScalarPixelType<DefaultSegmentationDataType>() ); Image::Pointer segmentation = Image::New(); if (original->GetDimension() == 2) { const unsigned int dimensions[] = { original->GetDimension(0), original->GetDimension(1), 1 }; segmentation->Initialize(pixelType, 3, dimensions); } else { segmentation->Initialize(pixelType, original->GetDimension(), original->GetDimensions()); } unsigned int byteSize = sizeof(DefaultSegmentationDataType); if(segmentation->GetDimension() < 4) { for (unsigned int dim = 0; dim < segmentation->GetDimension(); ++dim) { byteSize *= segmentation->GetDimension(dim); } mitk::ImageWriteAccessor writeAccess(segmentation, segmentation->GetVolumeData(0)); memset( writeAccess.GetData(), 0, byteSize ); } else {//if we have a time-resolved image we need to set memory to 0 for each time step for (unsigned int dim = 0; dim < 3; ++dim) { byteSize *= segmentation->GetDimension(dim); } for( unsigned int volumeNumber = 0; volumeNumber < segmentation->GetDimension(3); volumeNumber++) { mitk::ImageWriteAccessor writeAccess(segmentation, segmentation->GetVolumeData(volumeNumber)); memset( writeAccess.GetData(), 0, byteSize ); } } if (original->GetTimeGeometry() ) { TimeGeometry::Pointer originalGeometry = original->GetTimeGeometry()->Clone(); segmentation->SetTimeGeometry( originalGeometry ); } else { Tool::ErrorMessage("Original image does not have a 'Time sliced geometry'! Cannot create a segmentation."); return NULL; } return CreateSegmentationNode( segmentation, organName, color ); }
void mitk::ContourModelSetToImageFilter::InitializeOutputEmpty() { // Initialize the output's volume with zeros mitk::Image *output = this->GetOutput(); unsigned int byteSize = output->GetPixelType().GetSize(); if (output->GetDimension() < 4) { for (unsigned int dim = 0; dim < output->GetDimension(); ++dim) { byteSize *= output->GetDimension(dim); } mitk::ImageWriteAccessor writeAccess(output, output->GetVolumeData(0)); memset(writeAccess.GetData(), 0, byteSize); } else { // if we have a time-resolved image we need to set memory to 0 for each time step for (unsigned int dim = 0; dim < 3; ++dim) { byteSize *= output->GetDimension(dim); } for (unsigned int volumeNumber = 0; volumeNumber < output->GetDimension(3); volumeNumber++) { mitk::ImageWriteAccessor writeAccess(output, output->GetVolumeData(volumeNumber)); memset(writeAccess.GetData(), 0, byteSize); } } }
void mitkImageStatisticsCalculatorTestSuite::TestRecomputeOnModifiedMask() { mitk::Image::Pointer mask_image = mitk::ImageGenerator::GenerateImageFromReference<unsigned char>( m_Image, 0 ); mitk::ImageStatisticsCalculator::Pointer statisticsCalculator = mitk::ImageStatisticsCalculator::New(); statisticsCalculator->SetImage( m_Image ); statisticsCalculator->SetImageMask( mask_image ); statisticsCalculator->SetMaskingModeToImage(); statisticsCalculator->ComputeStatistics(); this->VerifyStatistics( statisticsCalculator->GetStatistics(), 0.0, 0.0, 0.0); // activate voxel in the mask image itk::Index<3U> test_index = {11, 8, 0}; mitk::ImagePixelWriteAccessor< unsigned char, 3> writeAccess( mask_image ); writeAccess.SetPixelByIndex( test_index, 1); mask_image->Modified(); statisticsCalculator->ComputeStatistics(); const mitk::ImageStatisticsCalculator::Statistics stat = statisticsCalculator->GetStatistics(); this->VerifyStatistics( stat, 128.0, 0.0, 128.0); MITK_TEST_CONDITION( stat.GetN() == 1, "Calculated mask voxel count '" << stat.GetN() << "' is equal to the desired value '" << 1 << "'" ); }
void mitkImageStatisticsCalculatorTestSuite::TestImageMaskingNonEmpty() { mitk::Image::Pointer mask_image = mitk::ImageGenerator::GenerateImageFromReference<unsigned char>( m_Image, 0 ); std::vector< itk::Index<3U> > activated_indices; itk::Index<3U> index = {{10, 8, 0}}; activated_indices.push_back( index ); index[0] = 9; index[1] = 8; index[2] = 0; activated_indices.push_back( index ); index[0] = 9; index[1] = 7; index[2] = 0; activated_indices.push_back( index ); index[0] = 10; index[1] = 7; index[2] = 0; activated_indices.push_back( index ); std::vector< itk::Index<3U> >::const_iterator indexIter = activated_indices.begin(); // activate voxel in the mask image mitk::ImagePixelWriteAccessor< unsigned char, 3> writeAccess( mask_image ); while( indexIter != activated_indices.end() ) { writeAccess.SetPixelByIndex( (*indexIter++), 1); } this->VerifyStatistics( ComputeStatistics( m_Image, mask_image ), 127.5, 147.22, 254.5); }
void Bitwise_and::execute(runtime::DataProvider & provider) { switch(int(m_dataFlow)) { case(MANUAL): { runtime::Id2DataPair src1InMapper(SRC_1); runtime::Id2DataPair src2InMapper(SRC_2); runtime::Id2DataPair dstInMapper(DST); provider.receiveInputData(src1InMapper && src2InMapper && dstInMapper); const runtime::Data* src1Data = 0; const runtime::Data* src2Data = 0; runtime::Data* dstData = 0; runtime::ReadAccess src1ReadAccess; runtime::ReadAccess src2ReadAccess; runtime::DataContainer inContainer = dstInMapper.data(); runtime::WriteAccess writeAccess(inContainer); dstData = &writeAccess.get(); if(src1InMapper.data() == inContainer) { throw runtime::InputError(SRC_1, *this, "Can not operate in place."); } else { src1ReadAccess = runtime::ReadAccess(src1InMapper.data()); src1Data = &src1ReadAccess.get(); } if(src2InMapper.data() == inContainer) { throw runtime::InputError(SRC_2, *this, "Can not operate in place."); } else { src2ReadAccess = runtime::ReadAccess(src2InMapper.data()); src2Data = &src2ReadAccess.get(); } if(! src1Data->variant().isVariant(m_src1Description->variant())) { throw runtime::InputError(SRC_1, *this, "Wrong input data variant."); } if(! src2Data->variant().isVariant(m_src2Description->variant())) { throw runtime::InputError(SRC_2, *this, "Wrong input data variant."); } if(! dstData->variant().isVariant(m_dstDescription->variant())) { throw runtime::InputError(DST, *this, "Wrong input data variant."); } const runtime::Image* src1CastedData = runtime::data_cast<runtime::Image>(src1Data); const runtime::Image* src2CastedData = runtime::data_cast<runtime::Image>(src2Data); runtime::Image * dstCastedData = runtime::data_cast<runtime::Image>(dstData); if((src1CastedData->rows() != src2CastedData->rows()) || (src1CastedData->cols() != src2CastedData->cols())) throw runtime::InputError(SRC_1, *this, "Input images must have the same size."); if(src1CastedData->numChannels() != src2CastedData->numChannels()) throw runtime::InputError(SRC_1, *this, "Input images must have the same number of channels."); if(src1CastedData->depth() != src2CastedData->depth()) throw runtime::InputError(SRC_1, *this, "Input images must have the same depth if the destination depth is not explicitely given."); dstCastedData->initializeImage(src1CastedData->width(), src1CastedData->height(), src1CastedData->stride(), dstCastedData->data(), src1CastedData->pixelType()); cv::Mat src1CvData = cvsupport::getOpenCvMat(*src1CastedData); cv::Mat src2CvData = cvsupport::getOpenCvMat(*src2CastedData); cv::Mat dstCvData = cvsupport::getOpenCvMat(*dstCastedData); cv::bitwise_and(src1CvData, src2CvData, dstCvData); runtime::DataContainer dstOutContainer = inContainer; runtime::Id2DataPair dstOutMapper(DST, dstOutContainer); provider.sendOutputData(dstOutMapper); } break; case(ALLOCATE): { runtime::Id2DataPair src1InMapper(SRC_1); runtime::Id2DataPair src2InMapper(SRC_2); provider.receiveInputData(src1InMapper && src2InMapper); const runtime::Data* src1Data = 0; const runtime::Data* src2Data = 0; runtime::ReadAccess src1ReadAccess; runtime::ReadAccess src2ReadAccess; src1ReadAccess = runtime::ReadAccess(src1InMapper.data()); src1Data = &src1ReadAccess.get(); src2ReadAccess = runtime::ReadAccess(src2InMapper.data()); src2Data = &src2ReadAccess.get(); if(! src1Data->variant().isVariant(m_src1Description->variant())) { throw runtime::InputError(SRC_1, *this, "Wrong input data variant."); } if(! src2Data->variant().isVariant(m_src2Description->variant())) { throw runtime::InputError(SRC_2, *this, "Wrong input data variant."); } const runtime::Image* src1CastedData = runtime::data_cast<runtime::Image>(src1Data); const runtime::Image* src2CastedData = runtime::data_cast<runtime::Image>(src2Data); if((src1CastedData->rows() != src2CastedData->rows()) || (src1CastedData->cols() != src2CastedData->cols())) throw runtime::InputError(SRC_1, *this, "Input images must have the same size."); if(src1CastedData->numChannels() != src2CastedData->numChannels()) throw runtime::InputError(SRC_1, *this, "Input images must have the same number of channels."); if(src1CastedData->depth() != src2CastedData->depth()) throw runtime::InputError(SRC_1, *this, "Input images must have the same depth if the destination depth is not explicitely given."); cv::Mat src1CvData = cvsupport::getOpenCvMat(*src1CastedData); cv::Mat src2CvData = cvsupport::getOpenCvMat(*src2CastedData); cv::Mat dstCvData; cv::bitwise_and(src1CvData, src2CvData, dstCvData); runtime::Image* dstCastedData = new cvsupport::Image(dstCvData); runtime::DataContainer dstOutContainer = runtime::DataContainer(dstCastedData); runtime::Id2DataPair dstOutMapper(DST, dstOutContainer); dstCastedData->initializeImage(dstCastedData->width(), dstCastedData->height(), dstCastedData->stride(), dstCastedData->data(), src1CastedData->pixelType()); provider.sendOutputData(dstOutMapper); } break; } }
void PyrUp::execute(runtime::DataProvider & provider) { switch(int(m_dataFlow)) { case(MANUAL): { runtime::Id2DataPair srcInMapper(SRC); runtime::Id2DataPair dstInMapper(DST); provider.receiveInputData(srcInMapper && dstInMapper); const runtime::Data* srcData = 0; runtime::Data* dstData = 0; runtime::ReadAccess srcReadAccess; runtime::DataContainer inContainer = dstInMapper.data(); runtime::WriteAccess writeAccess(inContainer); dstData = &writeAccess.get(); if(srcInMapper.data() == inContainer) { throw runtime::InputError(SRC, *this, "Can not operate in place."); } else { srcReadAccess = runtime::ReadAccess(srcInMapper.data()); srcData = &srcReadAccess.get(); } if(! srcData->variant().isVariant(m_srcDescription->variant())) { throw runtime::InputError(SRC, *this, "Wrong input data variant."); } if(! dstData->variant().isVariant(m_dstDescription->variant())) { throw runtime::InputError(DST, *this, "Wrong input data variant."); } const runtime::Image* srcCastedData = runtime::data_cast<runtime::Image>(srcData); runtime::Image * dstCastedData = runtime::data_cast<runtime::Image>(dstData); int width = 2 * srcCastedData->width(); int height = 2 * srcCastedData->height(); dstCastedData->initializeImage(width, height, width * srcCastedData->pixelSize(), dstCastedData->data(), srcCastedData->pixelType()); cv::Mat srcCvData = cvsupport::getOpenCvMat(*srcCastedData); cv::Mat dstCvData = cvsupport::getOpenCvMat(*dstCastedData); cv::pyrUp(srcCvData, dstCvData); runtime::DataContainer dstOutContainer = inContainer; runtime::Id2DataPair dstOutMapper(DST, dstOutContainer); provider.sendOutputData(dstOutMapper); } break; case(ALLOCATE): { runtime::Id2DataPair srcInMapper(SRC); provider.receiveInputData(srcInMapper); const runtime::Data* srcData = 0; runtime::ReadAccess srcReadAccess; srcReadAccess = runtime::ReadAccess(srcInMapper.data()); srcData = &srcReadAccess.get(); if(! srcData->variant().isVariant(m_srcDescription->variant())) { throw runtime::InputError(SRC, *this, "Wrong input data variant."); } const runtime::Image* srcCastedData = runtime::data_cast<runtime::Image>(srcData); cv::Mat srcCvData = cvsupport::getOpenCvMat(*srcCastedData); cv::Mat dstCvData; cv::pyrUp(srcCvData, dstCvData); runtime::Image* dstCastedData = new cvsupport::Image(dstCvData); runtime::DataContainer dstOutContainer = runtime::DataContainer(dstCastedData); runtime::Id2DataPair dstOutMapper(DST, dstOutContainer); dstCastedData->initializeImage(dstCastedData->width(), dstCastedData->height(), dstCastedData->stride(), dstCastedData->data(), srcCastedData->pixelType()); provider.sendOutputData(dstOutMapper); } break; } }
void CornerMinEigenVal::execute(runtime::DataProvider & provider) { switch(int(m_dataFlow)) { case(MANUAL): { runtime::Id2DataPair srcInMapper(INPUT_SRC); runtime::Id2DataPair dstInMapper(INPUT_DST); provider.receiveInputData(srcInMapper && dstInMapper); const runtime::Data* srcData = 0; runtime::Data* dstData = 0; runtime::ReadAccess srcReadAccess; runtime::DataContainer inContainer = dstInMapper.data(); runtime::WriteAccess writeAccess(inContainer); dstData = &writeAccess.get(); if(srcInMapper.data() == inContainer) { throw runtime::InputError(INPUT_SRC, *this, "Can not operate in place."); } else { srcReadAccess = runtime::ReadAccess(srcInMapper.data()); srcData = &srcReadAccess.get(); } if(! srcData->variant().isVariant(m_srcDescription->variant())) { throw runtime::InputError(INPUT_SRC, *this, "Wrong input data variant."); } if(! dstData->variant().isVariant(m_dstDescription->variant())) { throw runtime::InputError(INPUT_DST, *this, "Wrong input data variant."); } const runtime::Image* srcCastedData = runtime::data_cast<runtime::Image>(srcData); runtime::Matrix * dstCastedData = runtime::data_cast<runtime::Matrix>(dstData); unsigned int stride = srcCastedData->cols() * runtime::Matrix::valueSize(runtime::Matrix::FLOAT_32); dstCastedData->initializeMatrix(srcCastedData->rows(), srcCastedData->cols(), stride, dstCastedData->data(), runtime::Matrix::FLOAT_32); cv::Mat srcCvData = cvsupport::getOpenCvMat(*srcCastedData); cv::Mat dstCvData = cvsupport::getOpenCvMat(*dstCastedData); int blockSizeCvData = int(m_blockSize); int ksizeCvData = int(m_ksize); cv::cornerMinEigenVal(srcCvData, dstCvData, blockSizeCvData, ksizeCvData); runtime::DataContainer dstOutContainer = inContainer; runtime::Id2DataPair dstOutMapper(OUTPUT_DST, dstOutContainer); provider.sendOutputData(dstOutMapper); } break; case(ALLOCATE): { runtime::Id2DataPair srcInMapper(INPUT_SRC); provider.receiveInputData(srcInMapper); const runtime::Data* srcData = 0; runtime::ReadAccess srcReadAccess; srcReadAccess = runtime::ReadAccess(srcInMapper.data()); srcData = &srcReadAccess.get(); if(! srcData->variant().isVariant(m_srcDescription->variant())) { throw runtime::InputError(INPUT_SRC, *this, "Wrong input data variant."); } const runtime::Image* srcCastedData = runtime::data_cast<runtime::Image>(srcData); cv::Mat srcCvData = cvsupport::getOpenCvMat(*srcCastedData); cv::Mat dstCvData; int blockSizeCvData = int(m_blockSize); int ksizeCvData = int(m_ksize); cv::cornerMinEigenVal(srcCvData, dstCvData, blockSizeCvData, ksizeCvData); runtime::Matrix* dstCastedData = new cvsupport::Matrix(dstCvData); runtime::DataContainer dstOutContainer = runtime::DataContainer(dstCastedData); runtime::Id2DataPair dstOutMapper(OUTPUT_DST, dstOutContainer); provider.sendOutputData(dstOutMapper); } break; } }
mitk::DataNode::Pointer mitk::Tool::CreateEmptySegmentationNode(Image *original, const std::string &organName, const mitk::Color &color) { // we NEED a reference image for size etc. if (!original) return nullptr; // actually create a new empty segmentation PixelType pixelType(mitk::MakeScalarPixelType<DefaultSegmentationDataType>()); LabelSetImage::Pointer segmentation = LabelSetImage::New(); if (original->GetDimension() == 2) { const unsigned int dimensions[] = {original->GetDimension(0), original->GetDimension(1), 1}; segmentation->Initialize(pixelType, 3, dimensions); segmentation->AddLayer(); } else { segmentation->Initialize(original); } mitk::Label::Pointer label = mitk::Label::New(); label->SetName(organName); label->SetColor(color); label->SetValue(1); segmentation->GetActiveLabelSet()->AddLabel(label); segmentation->GetActiveLabelSet()->SetActiveLabel(1); unsigned int byteSize = sizeof(mitk::Label::PixelType); if (segmentation->GetDimension() < 4) { for (unsigned int dim = 0; dim < segmentation->GetDimension(); ++dim) { byteSize *= segmentation->GetDimension(dim); } mitk::ImageWriteAccessor writeAccess(segmentation.GetPointer(), segmentation->GetVolumeData(0)); memset(writeAccess.GetData(), 0, byteSize); } else { // if we have a time-resolved image we need to set memory to 0 for each time step for (unsigned int dim = 0; dim < 3; ++dim) { byteSize *= segmentation->GetDimension(dim); } for (unsigned int volumeNumber = 0; volumeNumber < segmentation->GetDimension(3); volumeNumber++) { mitk::ImageWriteAccessor writeAccess(segmentation.GetPointer(), segmentation->GetVolumeData(volumeNumber)); memset(writeAccess.GetData(), 0, byteSize); } } if (original->GetTimeGeometry()) { TimeGeometry::Pointer originalGeometry = original->GetTimeGeometry()->Clone(); segmentation->SetTimeGeometry(originalGeometry); } else { Tool::ErrorMessage("Original image does not have a 'Time sliced geometry'! Cannot create a segmentation."); return nullptr; } // Add some DICOM Tags as properties to segmentation image PropertyList::Pointer dicomSegPropertyList = mitk::DICOMSegmentationPropertyHandler::GetDICOMSegmentationProperties(original->GetPropertyList()); segmentation->GetPropertyList()->ConcatenatePropertyList(dicomSegPropertyList); mitk::DICOMSegmentationPropertyHandler::GetDICOMSegmentProperties(segmentation->GetActiveLabel(segmentation->GetActiveLayer())); return CreateSegmentationNode(segmentation, organName, color); }
foreach ( mitk::DataNode::Pointer node, selectedNodes ) { if (node) { mitk::Image::Pointer image = dynamic_cast<mitk::Image*>( node->GetData() ); if (image.IsNull()) return; mitk::ProgressBar::GetInstance()->AddStepsToDo(10); mitk::ProgressBar::GetInstance()->Progress(2); qApp->processEvents(); mitk::AutoCropImageFilter::Pointer cropFilter = mitk::AutoCropImageFilter::New(); cropFilter->SetInput( image ); cropFilter->SetBackgroundValue( 0 ); cropFilter->SetMarginFactor(1.5); try { cropFilter->Update(); image = cropFilter->GetOutput(); if (image.IsNotNull()) { if (image->GetDimension() == 4) { MITK_INFO << "4D AUTOCROP DOES NOT WORK AT THE MOMENT"; throw "4D AUTOCROP DOES NOT WORK AT THE MOMENT"; unsigned int timesteps = image->GetDimension(3); for (unsigned int i = 0; i < timesteps; i++) { mitk::ImageTimeSelector::Pointer imageTimeSelector = mitk::ImageTimeSelector::New(); imageTimeSelector->SetInput(image); imageTimeSelector->SetTimeNr(i); imageTimeSelector->UpdateLargestPossibleRegion(); // We split a long nested code line into separate calls for debugging: mitk::ImageSource::OutputImageType *_3dSlice = imageTimeSelector->GetOutput(); mitk::Image::Pointer _cropped3dSlice = this->IncreaseCroppedImageSize(_3dSlice); // +++ BUG +++ BUG +++ BUG +++ BUG +++ BUG +++ BUG +++ BUG +++ { mitk::ImageWriteAccessor writeAccess(_cropped3dSlice); void *_data = writeAccess.GetData(); // <ToBeRemoved> // We write some stripes into the image if ((i & 1) == 0) { int depth = _cropped3dSlice->GetDimension(2); int height = _cropped3dSlice->GetDimension(1); int width = _cropped3dSlice->GetDimension(0); for (int z = 0; z < depth; ++z) for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) reinterpret_cast<unsigned char *>(_data)[(width * height * z) + (width * y) + x] = x & 1; } // </ToBeRemoved> image->SetVolume(_data, i); } } node->SetData( image ); // bug fix 3145 } else { node->SetData( this->IncreaseCroppedImageSize(image) ); // bug fix 3145 } // Reinit node mitk::RenderingManager::GetInstance()->InitializeViews( node->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } catch(...) { MITK_ERROR << "Cropping image failed..."; } mitk::ProgressBar::GetInstance()->Progress(8); } else { MITK_INFO << " a nullptr node selected"; } }
void Merge::execute(runtime::DataProvider & provider) { switch(int(m_dataFlow)) { case(MANUAL): { runtime::Id2DataPair src1InMapper(INPUT_SRC_1); runtime::Id2DataPair src2InMapper(INPUT_SRC_2); runtime::Id2DataPair dstInMapper(INPUT_DST); provider.receiveInputData(src1InMapper && src2InMapper && dstInMapper); const runtime::Data* src1Data = 0; const runtime::Data* src2Data = 0; runtime::Data* dstData = 0; runtime::ReadAccess src1ReadAccess; runtime::ReadAccess src2ReadAccess; runtime::DataContainer inContainer = dstInMapper.data(); runtime::WriteAccess writeAccess(inContainer); dstData = &writeAccess.get(); if(src1InMapper.data() == inContainer) { throw runtime::InputError(INPUT_SRC_1, *this, "Can not operate in place."); } else { src1ReadAccess = runtime::ReadAccess(src1InMapper.data()); src1Data = &src1ReadAccess.get(); } if(src2InMapper.data() == inContainer) { throw runtime::InputError(INPUT_SRC_2, *this, "Can not operate in place."); } else { src2ReadAccess = runtime::ReadAccess(src2InMapper.data()); src2Data = &src2ReadAccess.get(); } if(! src1Data->variant().isVariant(m_src1Description->variant())) { throw runtime::InputError(INPUT_SRC_1, *this, "Wrong input data variant."); } if(! src2Data->variant().isVariant(m_src2Description->variant())) { throw runtime::InputError(INPUT_SRC_2, *this, "Wrong input data variant."); } if(! dstData->variant().isVariant(m_dstDescription->variant())) { throw runtime::InputError(INPUT_DST, *this, "Wrong input data variant."); } const runtime::Matrix* src1CastedData = runtime::data_cast<runtime::Matrix>(src1Data); const runtime::Matrix* src2CastedData = runtime::data_cast<runtime::Matrix>(src2Data); runtime::Matrix * dstCastedData = runtime::data_cast<runtime::Matrix>(dstData); if((src1CastedData->rows() != src2CastedData->rows()) || (src1CastedData->cols() != src2CastedData->cols())) throw runtime::InputError(INPUT_SRC_1, *this, "Input matrices must have the same size."); if(src1CastedData->type() != src2CastedData->type()) throw runtime::InputError(INPUT_SRC_1, *this, "Input matrices must have the same types."); dstCastedData->initializeMatrix(src1CastedData->rows(), 2*src1CastedData->cols(), 2*src1CastedData->cols()*src1CastedData->valueSize(), dstCastedData->data(), src1CastedData->valueType()); cv::Mat src1CvData = cvsupport::getOpenCvMat(*src1CastedData); cv::Mat src2CvData = cvsupport::getOpenCvMat(*src2CastedData); cv::Mat dstCvData = cvsupport::getOpenCvMat(*dstCastedData); merge(src1CvData, src2CvData, dstCvData); runtime::DataContainer dstOutContainer = inContainer; runtime::Id2DataPair dstOutMapper(OUTPUT_DST, dstOutContainer); provider.sendOutputData(dstOutMapper); } break; case(ALLOCATE): { runtime::Id2DataPair src1InMapper(INPUT_SRC_1); runtime::Id2DataPair src2InMapper(INPUT_SRC_2); provider.receiveInputData(src1InMapper && src2InMapper); const runtime::Data* src1Data = 0; const runtime::Data* src2Data = 0; runtime::ReadAccess src1ReadAccess; runtime::ReadAccess src2ReadAccess; src1ReadAccess = runtime::ReadAccess(src1InMapper.data()); src1Data = &src1ReadAccess.get(); src2ReadAccess = runtime::ReadAccess(src2InMapper.data()); src2Data = &src2ReadAccess.get(); if(! src1Data->variant().isVariant(m_src1Description->variant())) { throw runtime::InputError(INPUT_SRC_1, *this, "Wrong input data variant."); } if(! src2Data->variant().isVariant(m_src2Description->variant())) { throw runtime::InputError(INPUT_SRC_2, *this, "Wrong input data variant."); } const runtime::Matrix* src1CastedData = runtime::data_cast<runtime::Matrix>(src1Data); const runtime::Matrix* src2CastedData = runtime::data_cast<runtime::Matrix>(src2Data); if((src1CastedData->rows() != src2CastedData->rows()) || (src1CastedData->cols() != src2CastedData->cols())) throw runtime::InputError(INPUT_SRC_1, *this, "Input matrices must have the same size."); if(src1CastedData->type() != src2CastedData->type()) throw runtime::InputError(INPUT_SRC_1, *this, "Input matrices must have the same types."); cv::Mat src1CvData = cvsupport::getOpenCvMat(*src1CastedData); cv::Mat src2CvData = cvsupport::getOpenCvMat(*src2CastedData); cv::Mat dstCvData; merge(src1CvData, src2CvData, dstCvData); runtime::Matrix* dstCastedData = new cvsupport::Matrix(dstCvData); runtime::DataContainer dstOutContainer = runtime::DataContainer(dstCastedData); runtime::Id2DataPair dstOutMapper(OUTPUT_DST, dstOutContainer); dstCastedData->initializeMatrix(dstCastedData->rows(), dstCastedData->cols(), dstCastedData->stride(), dstCastedData->data(), src1CastedData->valueType()); provider.sendOutputData(dstOutMapper); } break; } }