DataAccessorImpl* createDataAccessor(DataElement* pElement, DataAccessorArgs* pArgs) { RasterElement* pRasterElement = dynamic_cast<RasterElement*>(pElement); if (pRasterElement == NULL) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } FactoryResource<DataRequest> pRequest; RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); if (pArgs != NULL) { pRequest->setRows(pDescriptor->getActiveRow(pArgs->rowStart), pDescriptor->getActiveRow(pArgs->rowEnd),pArgs->concurrentRows); pRequest->setColumns(pDescriptor->getActiveColumn(pArgs->columnStart), pDescriptor->getActiveColumn(pArgs->columnEnd),pArgs->concurrentColumns); pRequest->setBands(pDescriptor->getActiveBand(pArgs->bandStart), pDescriptor->getActiveBand(pArgs->bandEnd),pArgs->concurrentBands); pRequest->setInterleaveFormat(static_cast<InterleaveFormatTypeEnum>(pArgs->interleaveFormat)); pRequest->setWritable(pArgs->writable != 0); } DataAccessor dataAccessor(pRasterElement->getDataAccessor(pRequest.release())); if (!dataAccessor.isValid()) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } DataAccessorImpl* pRval = dataAccessor.operator->(); pRval->incrementRefCount(); setLastError(SIMPLE_NO_ERROR); return pRval; }
bool bilinear_bayer::copyImage(RasterElement * pRaster, RasterElement * dRaster, int i, Progress * pProgress) { VERIFY(pRaster != NULL); RasterDataDescriptor *pDesc = dynamic_cast < RasterDataDescriptor * >(pRaster->getDataDescriptor()); VERIFY(dRaster != NULL); RasterDataDescriptor *rDesc = dynamic_cast < RasterDataDescriptor * >(dRaster->getDataDescriptor()); DimensionDescriptor thirdBand = pDesc->getActiveBand(i); // get active // band // source FactoryResource < DataRequest > pRequest; pRequest->setInterleaveFormat(BSQ); pRequest->setBands(thirdBand, thirdBand); DataAccessor thirdBandDa = pRaster->getDataAccessor(pRequest.release()); thirdBand = rDesc->getActiveBand(i); // destination FactoryResource < DataRequest > pResultRequest; pResultRequest->setWritable(true); pRequest->setInterleaveFormat(BSQ); pResultRequest->setBands(thirdBand, thirdBand); DataAccessor pDestAcc = dRaster->getDataAccessor(pResultRequest.release()); VERIFY(thirdBandDa.isValid()); VERIFY(pDestAcc.isValid()); for (unsigned int curRow = 0; curRow < pDesc->getRowCount(); ++curRow) { for (unsigned int curCol = 0; curCol < pDesc->getColumnCount(); ++curCol) { switchOnEncoding(pDesc->getDataType(), bilinear, pDestAcc->getColumn(), thirdBandDa, curRow, curCol, pDesc->getRowCount(), pDesc->getColumnCount(), i, pRaster); pDestAcc->nextColumn(); } pDestAcc->nextRow(); } return true; }
DataAccessor getAccessor(int band, bool writable = false) { FactoryResource<DataRequest> pRequest = FactoryResource<DataRequest>(); pRequest->setRows(pDataDescriptor->getActiveRow(0), pDataDescriptor->getActiveRow(getRowCount() - 1)); pRequest->setColumns(pDataDescriptor->getActiveColumn(0), pDataDescriptor->getActiveColumn(getColumnCount() - 1)); pRequest->setBands(pDataDescriptor->getActiveBand(band), pDataDescriptor->getActiveBand(band)); pRequest->setWritable(writable); return pRaster->getDataAccessor(pRequest.release()); }
std::vector<ImportDescriptor*> VideoImporter::getImportDescriptors(const std::string &filename) { std::vector<ImportDescriptor*> descriptors; AVFormatResource pFormatCtx; { // scope AVFormatContext* pTmp = NULL; if (av_open_input_file(&pTmp, filename.c_str(), NULL, 0, NULL) != 0) { return descriptors; } pFormatCtx.reset(pTmp); } if (av_find_stream_info(pFormatCtx) < 0) { return descriptors; } for(int streamId = 0; streamId < pFormatCtx->nb_streams; streamId++) { if(pFormatCtx->streams[streamId]->codec->codec_type == CODEC_TYPE_VIDEO) { AVCodecContext* pCodecCtx = pFormatCtx->streams[streamId]->codec; AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id); VERIFYRV(pCodec != NULL, descriptors); if(pCodec->capabilities & CODEC_CAP_TRUNCATED) { pCodecCtx->flags |= CODEC_FLAG_TRUNCATED; } if(avcodec_open(pCodecCtx, pCodec) < 0) { return descriptors; } ImportDescriptorResource pStreamDescriptor(filename, "VideoStream"); VERIFYRV(pStreamDescriptor.get() != NULL, descriptors); pStreamDescriptor->getDataDescriptor()->setProcessingLocation(ON_DISK_READ_ONLY); RasterUtilities::generateAndSetFileDescriptor(pStreamDescriptor->getDataDescriptor(), filename, StringUtilities::toDisplayString(streamId), LITTLE_ENDIAN); std::string rasterName = filename + QString(":%1").arg(streamId).toStdString(); ImportDescriptorResource pRasterDescriptor(rasterName, TypeConverter::toString<RasterElement>(), std::vector<std::string>(1, filename)); VERIFYRV(pRasterDescriptor.get() != NULL, descriptors); RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pRasterDescriptor->getDataDescriptor()); std::vector<DimensionDescriptor> rowDims = RasterUtilities::generateDimensionVector(pCodecCtx->height); pDesc->setRows(rowDims); std::vector<DimensionDescriptor> colDims = RasterUtilities::generateDimensionVector(pCodecCtx->width); pDesc->setColumns(colDims); std::vector<DimensionDescriptor> bandDims = RasterUtilities::generateDimensionVector(3); pDesc->setBands(bandDims); pDesc->setInterleaveFormat(BIP); pDesc->setDataType(INT1UBYTE); pDesc->setProcessingLocation(IN_MEMORY); pDesc->setDisplayMode(RGB_MODE); pDesc->setDisplayBand(RED, pDesc->getActiveBand(0)); pDesc->setDisplayBand(GREEN, pDesc->getActiveBand(1)); pDesc->setDisplayBand(BLUE, pDesc->getActiveBand(2)); RasterUtilities::generateAndSetFileDescriptor(pDesc, filename, StringUtilities::toDisplayString(streamId), LITTLE_ENDIAN); descriptors.push_back(pStreamDescriptor.release()); descriptors.push_back(pRasterDescriptor.release()); } } return descriptors; }
bool bilinear_bayer::execute(PlugInArgList * pInArgList, PlugInArgList * pOutArgList) { StepResource pStep("bilinear_bayer", "pratik", "27170298-10CE-4E6C-AD7A-97E8058C29FF"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress *pProgress = pInArgList->getPlugInArgValue < Progress > (Executable::ProgressArg()); RasterElement *pCube = pInArgList->getPlugInArgValue < RasterElement > (Executable::DataElementArg()); // pCube if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pProgress->updateProgress("Starting calculations", 10, NORMAL); RasterDataDescriptor *pDesc = static_cast < RasterDataDescriptor * >(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); std::string msg = "De-bayerize by bilinear interpolation \n"; pProgress->updateProgress(msg, 20, NORMAL); // show initial R,G and B // values RasterElement *dRas = RasterUtilities::createRasterElement(pCube->getName() + "RGB", pDesc->getRowCount(), pDesc->getColumnCount(), 3, pDesc->getDataType(), BSQ); // request pProgress->updateProgress(msg, 50, NORMAL); copyImage(pCube, dRas, 0, pProgress); pProgress->updateProgress(msg + "RED complete", 60, NORMAL); copyImage(pCube, dRas, 1, pProgress); pProgress->updateProgress(msg + "GREEN complete", 70, NORMAL); copyImage(pCube, dRas, 2, pProgress); pProgress->updateProgress(msg + "BLUE complete", 80, NORMAL); // new model resource RasterDataDescriptor *rDesc = dynamic_cast < RasterDataDescriptor * >(dRas->getDataDescriptor()); rDesc->setDisplayMode(RGB_MODE); // enable color mode rDesc->setDisplayBand(RED, rDesc->getActiveBand(0)); rDesc->setDisplayBand(GREEN, rDesc->getActiveBand(1)); rDesc->setDisplayBand(BLUE, rDesc->getActiveBand(2)); ModelResource < RasterElement > pResultCube(dRas); pProgress->updateProgress("Final", 100, NORMAL); // create window if (!isBatch()) { Service < DesktopServices > pDesktop; SpatialDataWindow *pWindow = static_cast < SpatialDataWindow * >(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView *pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } pOutArgList->setPlugInArgValue("bilinear_bayer_Result", pResultCube.release()); // for // saving // data pStep->finalize(); return true; }
bool RasterTimingTest::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { if (isBatch()) { VERIFY(pOutArgList != NULL); } Service<DesktopServices> pDesktop; SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pDesktop->getCurrentWorkspaceWindowView()); if (pView) { UndoLock lock(pView); RasterElement* pElement = pView->getLayerList()->getPrimaryRasterElement(); RasterDataDescriptor* pDesc = dynamic_cast<RasterDataDescriptor*>(pElement->getDataDescriptor()); int bands = pDesc->getBandCount(); int frameNumber = 0; RasterLayer* pLayer = NULL; vector<Layer*> layers; pView->getLayerList()->getLayers(RASTER, layers); for (vector<Layer*>::iterator iter = layers.begin(); iter != layers.end(); ++iter) { RasterLayer* pRasterLayer = static_cast<RasterLayer*>(*iter); if (pRasterLayer != NULL) { RasterElement* pCurrentRasterElement = dynamic_cast<RasterElement*>(pRasterLayer->getDataElement()); if (pCurrentRasterElement == pElement) { pLayer = pRasterLayer; break; } } } for (int i = 0; i < bands; ++i) { pElement->getStatistics(pDesc->getActiveBand(i))->getMin(); } // set grayscale display mode DisplayMode initialDisplayMode = pLayer->getDisplayMode(); pLayer->setDisplayMode(GRAYSCALE_MODE); const int frameiterations = 10000; clock_t startTime = clock(); QWidget* pWidget = pView->getWidget(); int i = 0; for (i = 0; i < frameiterations; ++i, ++frameNumber) { if (frameNumber >= bands) { frameNumber = 0; } pLayer->setDisplayedBand(GRAY, pDesc->getActiveBand(frameNumber)); if (pWidget) { pWidget->repaint(); } if ((i + 1) % (frameiterations / 100) == 0) { QString message = QString("Frame ") + QString::number(i+1) + QString(" of ") + QString::number(frameiterations); pDesktop->setStatusBarMessage(message.toStdString()); } if ((i + 1) % 20 == 0) { clock_t stopTime = clock(); double elapsedTime = static_cast<double>(stopTime - startTime) / CLOCKS_PER_SEC; if (elapsedTime > 30) { ++i; break; } } } clock_t stopTime = clock(); double framesPerSec = i / (static_cast<double>(stopTime - startTime) / CLOCKS_PER_SEC); // restore display mode pLayer->setDisplayMode(initialDisplayMode); if (isBatch()) { pOutArgList->setPlugInArgValue<double>("Framerate", &framesPerSec); } else { QMessageBox::information(pDesktop->getMainWidget(), "Frame Rate", QString("The number of frames per second was: %1\nGPU Acceleration was%2 enabled\n").arg(framesPerSec) .arg(pLayer->isGpuImageEnabled() ? "" : " not")); } return true; } return false; }
bool adaptive_median::execute(PlugInArgList * pInArgList, PlugInArgList * pOutArgList) { StepResource pStep("adap_median", "noise", "5EA0CC75-9E0B-4c3d-BA23-6DB7157BBD55"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } std::string msg = "Noise Reduction by Adaptive Median Filter "; Progress *pProgress = pInArgList->getPlugInArgValue < Progress > (Executable::ProgressArg()); RasterElement *pCube = pInArgList->getPlugInArgValue < RasterElement > (Executable::DataElementArg()); if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } RasterDataDescriptor *pDesc = static_cast < RasterDataDescriptor * >(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); if (pDesc->getDataType() == INT4SCOMPLEX || pDesc->getDataType() == FLT8COMPLEX) { std::string msg = "Noise Reduction cannot be performed on complex types."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource < DataRequest > pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); RasterElement *dRas = RasterUtilities::createRasterElement(pCube->getName() + "Noise_reduction_Median_filter", pDesc->getRowCount(), pDesc->getColumnCount(), 3, pDesc->getDataType(), BSQ); pProgress->updateProgress(msg, 50, NORMAL); copyImage4(pCube, dRas, 0, pProgress); pProgress->updateProgress(msg + "RED complete", 60, NORMAL); copyImage4(pCube, dRas, 1, pProgress); pProgress->updateProgress(msg + "GREEN complete", 70, NORMAL); copyImage4(pCube, dRas, 2, pProgress); pProgress->updateProgress(msg + "BLUE complete", 80, NORMAL); // new model resource RasterDataDescriptor *rDesc = dynamic_cast < RasterDataDescriptor * >(dRas->getDataDescriptor()); rDesc->setDisplayMode(RGB_MODE); // enable color mode rDesc->setDisplayBand(RED, rDesc->getActiveBand(0)); rDesc->setDisplayBand(GREEN, rDesc->getActiveBand(1)); rDesc->setDisplayBand(BLUE, rDesc->getActiveBand(2)); ModelResource < RasterElement > pResultCube(dRas); if (pResultCube.get() == NULL) { std::string msg = "A raster cube could not be created."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pProgress->updateProgress("Final", 100, NORMAL); pProgress->updateProgress(msg, 100, NORMAL); if (!isBatch()) { Service < DesktopServices > pDesktop; SpatialDataWindow *pWindow = static_cast < SpatialDataWindow * >(pDesktop-> createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView *pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } if (pProgress != NULL) { pProgress->updateProgress("adaptive_median is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("adaptive_median_Result", pResultCube.release()); // saving // data pStep->finalize(); return true; }
bool adaptive_median::copyImage4(RasterElement * pRaster, RasterElement * dRaster, int i, Progress * pProgress) { int flag = 0; int size = 3; int sizeMax = MAX_SIZE; VERIFY(pRaster != NULL); RasterDataDescriptor *pDesc = dynamic_cast < RasterDataDescriptor * >(pRaster->getDataDescriptor()); VERIFY(dRaster != NULL); RasterDataDescriptor *rDesc = dynamic_cast < RasterDataDescriptor * >(dRaster->getDataDescriptor()); DimensionDescriptor thirdBand = pDesc->getActiveBand(i); // get active // band // source FactoryResource < DataRequest > pRequest; pRequest->setInterleaveFormat(BSQ); pRequest->setBands(thirdBand, thirdBand); DataAccessor thirdBandDa = pRaster->getDataAccessor(pRequest.release()); thirdBand = rDesc->getActiveBand(i); // destination FactoryResource < DataRequest > pResultRequest; pResultRequest->setWritable(true); pRequest->setInterleaveFormat(BSQ); pResultRequest->setBands(thirdBand, thirdBand); DataAccessor pDestAcc = dRaster->getDataAccessor(pResultRequest.release()); VERIFY(thirdBandDa.isValid()); VERIFY(pDestAcc.isValid()); for (unsigned int curRow = 0; curRow < pDesc->getRowCount(); ++curRow) { for (unsigned int curCol = 0; curCol < pDesc->getColumnCount(); ++curCol) { VERIFY(pDestAcc.isValid()); switchOnEncoding(pDesc->getDataType(), adaptivemedian, pDestAcc->getColumn(), thirdBandDa, curRow, curCol, pDesc->getRowCount(), pDesc->getColumnCount(), size, sizeMax, pProgress, &flag); if (flag == 1 && size <= sizeMax) { // increase window size size = size + 2; curCol--; } else { pDestAcc->nextColumn(); size = 3; flag = 0; } } pDestAcc->nextRow(); } return true; }
bool NefImporter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { if (pInArgList == NULL || pOutArgList == NULL) { return false; } //setting up mpRasterElement parseInputArgList(pInArgList); RasterElement* pRaster = getRasterElement(); VERIFY(pRaster != NULL); RasterDataDescriptor *pDescriptor = dynamic_cast<RasterDataDescriptor*>(pRaster->getDataDescriptor()); VERIFY(pDescriptor != NULL); FileDescriptor *pFileDescriptor = pDescriptor->getFileDescriptor(); VERIFY(pFileDescriptor != NULL); //data accessor //RED DimensionDescriptor firstBand = pDescriptor->getActiveBand(0); FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); pRequest->setBands(firstBand, firstBand); pRequest->setWritable(true); DataAccessor firstBandDa = pRaster->getDataAccessor(pRequest.release()); //GREEN DimensionDescriptor secondBand = pDescriptor->getActiveBand(1); FactoryResource<DataRequest> qRequest; qRequest->setInterleaveFormat(BSQ); qRequest->setBands(secondBand, secondBand); qRequest->setWritable(true); DataAccessor secondBandDa = pRaster->getDataAccessor(qRequest.release()); //BLUE DimensionDescriptor thirdBand = pDescriptor->getActiveBand(2); FactoryResource<DataRequest> rRequest; rRequest->setInterleaveFormat(BSQ); rRequest->setBands(thirdBand, thirdBand); rRequest->setWritable(true); DataAccessor thirdBandDa = pRaster->getDataAccessor(rRequest.release()); std::string filename = pRaster->getFilename(); Progress *pProgress = getProgress(); FactoryResource<Filename> pFilename; pFilename->setFullPathAndName(filename); LibRaw RawProcessor; putenv ((char*)"TZ=UTC"); #define P1 RawProcessor.imgdata.idata #define S RawProcessor.imgdata.sizes #define C RawProcessor.imgdata.color #define T RawProcessor.imgdata.thumbnail #define P2 RawProcessor.imgdata.other #define OUT RawProcessor.imgdata.params const char *fname=filename.c_str(); RawProcessor.open_file(fname); // Let us unpack the image if (RawProcessor.unpack() != LIBRAW_SUCCESS) { return false; } /* unsigned int *r=NULL; unsigned int *g=NULL; unsigned int *b=NULL; unsigned int *h=NULL; */ unsigned int *zero=0; int row=0,col=0,r=0,c=0; /* r=(unsigned int*)(&RawProcessor.imgdata.image[i][0]); g=(unsigned int*)(&RawProcessor.imgdata.image[i][1]); b=(unsigned int*)(&RawProcessor.imgdata.image[i][2]); h=(unsigned int*)(&RawProcessor.imgdata.image[i][3]); */ //secondBandDa->toPixel(row,col); //thirdBandDa->toPixel(row,col); unsigned short *pData=reinterpret_cast<unsigned short*>(pRaster->getRawData()); if (pData == NULL) { return NULL; } memcpy(pData, RawProcessor.imgdata.rawdata.raw_image, sizeof(unsigned short) * RawProcessor.imgdata.sizes.raw_height * RawProcessor.imgdata.sizes.raw_width); /* if(i%2==0) //RG1 {memcpy(firstBandDa->getColumn(),(unsigned int*)RawProcessor.imgdata.image[i][0],sizeof(unsigned int)); memcpy(thirdBandDa->getColumn(),(unsigned int*)RawProcessor.imgdata.image[i][2],sizeof(unsigned int)); memcpy(secondBandDa->getColumn(),zero,sizeof(unsigned int)); } else{ //G2B memcpy(thirdBandDa->getColumn(),(unsigned int*)RawProcessor.imgdata.image[i][3],sizeof(unsigned int)); memcpy(secondBandDa->getColumn(),(unsigned int*)RawProcessor.imgdata.image[i][1],sizeof(unsigned int)); memcpy(firstBandDa->getColumn(),zero,sizeof(unsigned int)); } */ unsigned short *ptr=NULL; //band 0 Red for(row=0,r=0;row<S.iheight;row++,r++) { for(col=0,c=0;col<S.iwidth;col++,c++) { if(row%2==0) //RG row { if(col%2==0) //Red pixel { ptr=reinterpret_cast<unsigned short*>(firstBandDa->getColumn()); *ptr=pData[c+(r*S.iwidth)+(0*S.iheight*S.iwidth)]; } else { *ptr=0; c--; } } else //GB row { *ptr=0; } firstBandDa->nextColumn(); } if(row%2!=0) r--; firstBandDa->nextRow(); } //band 2 Blue for(row=0,r=0;row<S.iheight;row++,r++) { for(col=0,c=0;col<S.iwidth;col++,c++) { if(row%2!=0) //GB row { if(col%2!=0) //Blue pixel { ptr=reinterpret_cast<unsigned short*>(secondBandDa->getColumn()); *ptr=pData[c+(r*S.iwidth)+(2*S.iheight*S.iwidth)]; } else { *ptr=0; c--; } } else //RG row { *ptr=0; } secondBandDa->nextColumn(); } if(row%2==0) r--; secondBandDa->nextRow(); } //band 1 Green for(row=0,r=0;row<S.iheight;row++,r++) { for(col=0,c=0;col<S.iwidth;col++,c++) { if(row%2==0) //RG row { if(col%2!=0) //Green pixel { ptr=reinterpret_cast<unsigned short*>(thirdBandDa->getColumn()); *ptr=pData[c+(r*S.iwidth)+(1*S.iheight*S.iwidth)]; //g1 } else { *ptr=0; c--; } } else //GB row { if(col%2==0) //Green pixel { ptr=reinterpret_cast<unsigned short*>(thirdBandDa->getColumn()); *ptr=pData[c+(r*S.iwidth)+(3*S.iheight*S.iwidth)]; //g2 } else { *ptr=0; c--; } } thirdBandDa->nextColumn(); } thirdBandDa->nextRow(); } if (createView() == NULL) { return false; } RawProcessor.recycle(); return true; }
bool ImageRegistration::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Image Registration", "app", "A2E0FC44-2A31-41EE-90F8-805773D01FCA"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); //RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); std::vector<Window*> windows; Service<DesktopServices>()->getWindows(SPATIAL_DATA_WINDOW, windows); std::vector<RasterElement*> elements; for (unsigned int i = 0; i < windows.size(); ++i) { SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(windows[i]); if (pWindow == NULL) { continue; } LayerList* pList = pWindow->getSpatialDataView()->getLayerList(); elements.push_back(pList->getPrimaryRasterElement()); } RasterElement* pCube = elements[0]; RasterElement* pCubeRef = elements[1]; if ((pCube == NULL) || (pCubeRef == NULL)) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); EncodingType ResultType = pDesc->getDataType(); if (pDesc->getDataType() == INT4SCOMPLEX) { ResultType = INT4SBYTES; } else if (pDesc->getDataType() == FLT8COMPLEX) { ResultType = FLT8BYTES; } FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); FactoryResource<DataRequest> pRequestRef; pRequestRef->setInterleaveFormat(BSQ); DataAccessor pSrcAccRef = pCubeRef->getDataAccessor(pRequestRef.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "_Image_Registration_Result", pDesc->getRowCount(), pDesc->getColumnCount(), ResultType)); if (pResultCube.get() == NULL) { std::string msg = "A raster cube could not be created."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } std::vector<int> badValues = pDesc->getBadValues(); //badValues.push_back(0); RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pResultCube->getDataDescriptor()); Statistics* pStatistics = pResultCube->getStatistics(pDescriptor->getActiveBand(0)); pStatistics->setBadValues(badValues); FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); nCountMas = 0; nCountRef = 0; int windowSize = 6; double *pBuffer = (double *)calloc(pDesc->getRowCount()*pDesc->getColumnCount(), sizeof(double)); GetGrayScale(pDesc->getDataType()); for (unsigned int row = 0; row < pDesc->getRowCount(); ++row) { if (pProgress != NULL) { pProgress->updateProgress("Image registration", row * 100 / pDesc->getRowCount(), NORMAL); } if (isAborted()) { std::string msg = getName() + " has been aborted."; pStep->finalize(Message::Abort, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ABORT); } return false; } for (unsigned int col = 0; col < pDesc->getColumnCount(); ++col) { locateAllStarPosition(pSrcAcc, pSrcAccRef, row, col, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType(), windowSize, pBuffer); } } ModifyCenter(pSrcAcc, pDesc->getDataType(), windowSize, nCountMas, nStarPositionsMas); ModifyCenter(pSrcAccRef, pDesc->getDataType(), windowSize, nCountRef, nStarPositionsRef); GetAllNeighborStars(); GetMatchingStars(); GetParameters(pDesc->getRowCount(), pDesc->getColumnCount()); DrawStars(pBuffer, pSrcAccRef, pDesc->getDataType(), matrixT, pDesc->getRowCount(), pDesc->getColumnCount()); //Output the value for (unsigned int m = 0; m < pDesc->getRowCount(); m++) { for (unsigned int n = 0; n < pDesc->getColumnCount(); n++) { if (isAborted()) { std::string msg = getName() + " has been aborted."; pStep->finalize(Message::Abort, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ABORT); } return false; } if (!pDestAcc.isValid()) { std::string msg = "Unable to access the cube data."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } switchOnEncoding(ResultType, updatePixel, pDestAcc->getColumn(), pBuffer, m, n, pDesc->getRowCount(), pDesc->getColumnCount()); pDestAcc->nextColumn(); } pDestAcc->nextRow(); } free(pBuffer); if (!isBatch()) { Service<DesktopServices> pDesktop; SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } double theta = std::acos(matrixT[0][0])*180.0/3.1415926; std::string msg = "Image Registration is complete.\n Translation x = " + StringUtilities::toDisplayString(round(shiftX)) + ", y = " + StringUtilities::toDisplayString(round(shiftY)) + ", rotation = " + StringUtilities::toDisplayString(round(theta)) + " degree"; if (pProgress != NULL) { pProgress->updateProgress(msg, 100, NORMAL); } pOutArgList->setPlugInArgValue("Image Registration Result", pResultCube.release()); pStep->finalize(); return true; }