ActionRetCodeEnum RotoShapeRenderNode::getRegionOfDefinition(TimeValue time, const RenderScale& scale, ViewIdx view, RectD* rod) { RotoDrawableItemPtr item = getAttachedRotoItem(); assert(item); assert((isRenderClone() && item->isRenderClone()) || (!isRenderClone() && !item->isRenderClone())); const bool isPainting = isDuringPaintStrokeCreation(); RectD shapeRoD; getRoDFromItem(item, time, view, isPainting, &shapeRoD); bool clipToFormat = _imp->clipToFormatKnob.lock()->getValue(); RotoShapeRenderTypeEnum type = (RotoShapeRenderTypeEnum)_imp->renderType.lock()->getValue(); switch (type) { case eRotoShapeRenderTypeSmear: { RectD defaultRod; ActionRetCodeEnum stat = EffectInstance::getRegionOfDefinition(time, scale, view, &defaultRod); if (isFailureRetCode(stat)) { return stat; } if (!defaultRod.isNull()) { *rod = shapeRoD; rod->merge(defaultRod); } } break; case eRotoShapeRenderTypeSolid: { RotoPaintOutputRoDTypeEnum rodType = (RotoPaintOutputRoDTypeEnum)_imp->outputRoDTypeKnob.lock()->getValue(); switch (rodType) { case eRotoPaintOutputRoDTypeDefault: { *rod = shapeRoD; // No format is set, use the format from the input if (clipToFormat) { EffectInstancePtr inputEffect = getInputRenderEffectAtAnyTimeView(0); if (inputEffect) { RectI outputFormat = inputEffect->getOutputFormat(); RectD outputFormatCanonical; outputFormat.toCanonical_noClipping(scale, inputEffect->getAspectRatio(-1), &outputFormatCanonical); rod->intersect(outputFormatCanonical, rod); } } } break; case eRotoPaintOutputRoDTypeFormat: { KnobIntPtr sizeKnob = _imp->outputFormatSizeKnob.lock(); int w = sizeKnob->getValue(DimIdx(0)); int h = _imp->outputFormatSizeKnob.lock()->getValue(DimIdx(1)); double par = _imp->outputFormatParKnob.lock()->getValue(); RectI pixelFormat; pixelFormat.x1 = pixelFormat.y1 = 0; pixelFormat.x2 = w; pixelFormat.y2 = h; RenderScale renderScale(1.); pixelFormat.toCanonical_noClipping(renderScale, par, rod); if (!clipToFormat) { rod->merge(shapeRoD); } } break; case eRotoPaintOutputRoDTypeProject: { Format f; getApp()->getProject()->getProjectDefaultFormat(&f); f.toCanonical_noClipping(RenderScale(1.), f.getPixelAspectRatio(), rod); if (!clipToFormat) { rod->merge(shapeRoD); } } break; } } break; } return eActionStatusOK; }
/* * @brief This is called by LibMV to retrieve an image either for reference or as search frame. */ mv::FrameAccessor::Key TrackerFrameAccessor::GetImage(int /*clip*/, int frame, mv::FrameAccessor::InputMode input_mode, int downscale, // Downscale by 2^downscale. const mv::Region* region, // Get full image if NULL. const mv::FrameAccessor::Transform* /*transform*/, // May be NULL. mv::FloatImage** destination) { // Since libmv only uses MONO images for now we have only optimized for this case, remove and handle properly // other case(s) when they get integrated into libmv. assert(input_mode == mv::FrameAccessor::MONO); FrameAccessorCacheKey key; key.frame = frame; key.mipMapLevel = downscale; key.mode = input_mode; /* Check if a frame exists in the cache with matching key and bounds enclosing the given region */ RectI roi; if (region) { convertLibMVRegionToRectI(*region, _imp->formatHeight, &roi); QMutexLocker k(&_imp->cacheMutex); std::pair<FrameAccessorCache::iterator, FrameAccessorCache::iterator> range = _imp->cache.equal_range(key); for (FrameAccessorCache::iterator it = range.first; it != range.second; ++it) { if ( (roi.x1 >= it->second.bounds.x1) && (roi.x2 <= it->second.bounds.x2) && ( roi.y1 >= it->second.bounds.y1) && ( roi.y2 <= it->second.bounds.y2) ) { #ifdef TRACE_LIB_MV qDebug() << QThread::currentThread() << "FrameAccessor::GetImage():" << "Found cached image at frame" << frame << "with RoI x1=" << region->min(0) << "y1=" << region->max(1) << "x2=" << region->max(0) << "y2=" << region->min(1); #endif // LibMV is kinda dumb on this we must necessarily copy the data either via CopyFrom or the // assignment constructor: // EDIT: fixed libmv *destination = it->second.image.get(); //destination->CopyFrom<float>(*it->second.image); ++it->second.referenceCount; return (mv::FrameAccessor::Key)it->second.image.get(); } } } EffectInstancePtr effect; if (_imp->trackerInput) { effect = _imp->trackerInput->getEffectInstance(); } if (!effect) { return (mv::FrameAccessor::Key)0; } // Not in accessor cache, call renderRoI RenderScale scale; scale.y = scale.x = Image::getScaleFromMipMapLevel( (unsigned int)downscale ); RectD precomputedRoD; if (!region) { bool isProjectFormat; StatusEnum stat = effect->getRegionOfDefinition_public(_imp->trackerInput->getHashValue(), frame, scale, ViewIdx(0), &precomputedRoD, &isProjectFormat); if (stat == eStatusFailed) { return (mv::FrameAccessor::Key)0; } double par = effect->getAspectRatio(-1); precomputedRoD.toPixelEnclosing( (unsigned int)downscale, par, &roi ); } std::list<ImageComponents> components; components.push_back( ImageComponents::getRGBComponents() ); NodePtr node = _imp->context->getNode(); const bool isRenderUserInteraction = true; const bool isSequentialRender = false; AbortableRenderInfoPtr abortInfo = AbortableRenderInfo::create(false, 0); AbortableThread* isAbortable = dynamic_cast<AbortableThread*>( QThread::currentThread() ); if (isAbortable) { isAbortable->setAbortInfo( isRenderUserInteraction, abortInfo, node->getEffectInstance() ); } ParallelRenderArgsSetter::CtorArgsPtr tlsArgs(new ParallelRenderArgsSetter::CtorArgs); tlsArgs->time = frame; tlsArgs->view = ViewIdx(0); tlsArgs->isRenderUserInteraction = isRenderUserInteraction; tlsArgs->isSequential = isSequentialRender; tlsArgs->abortInfo = abortInfo; tlsArgs->treeRoot = node; tlsArgs->textureIndex = 0; tlsArgs->timeline = node->getApp()->getTimeLine(); tlsArgs->activeRotoPaintNode = NodePtr(); tlsArgs->activeRotoDrawableItem = RotoDrawableItemPtr(); tlsArgs->isDoingRotoNeatRender = false; tlsArgs->isAnalysis = true; tlsArgs->draftMode = false; tlsArgs->stats = RenderStatsPtr(); ParallelRenderArgsSetter frameRenderArgs(tlsArgs); // Stats EffectInstance::RenderRoIArgs args( frame, scale, downscale, ViewIdx(0), false, roi, precomputedRoD, components, eImageBitDepthFloat, true, _imp->context->getNode()->getEffectInstance(), eStorageModeRAM /*returnOpenGLTex*/, frame); std::map<ImageComponents, ImagePtr> planes; EffectInstance::RenderRoIRetCode stat = effect->renderRoI(args, &planes); if ( (stat != EffectInstance::eRenderRoIRetCodeOk) || planes.empty() ) { #ifdef TRACE_LIB_MV qDebug() << QThread::currentThread() << "FrameAccessor::GetImage():" << "Failed to call renderRoI on input at frame" << frame << "with RoI x1=" << roi.x1 << "y1=" << roi.y1 << "x2=" << roi.x2 << "y2=" << roi.y2; #endif return (mv::FrameAccessor::Key)0; } assert( !planes.empty() ); const ImagePtr& sourceImage = planes.begin()->second; RectI sourceBounds = sourceImage->getBounds(); RectI intersectedRoI; if ( !roi.intersect(sourceBounds, &intersectedRoI) ) { #ifdef TRACE_LIB_MV qDebug() << QThread::currentThread() << "FrameAccessor::GetImage():" << "RoI does not intersect the source image bounds (RoI x1=" << roi.x1 << "y1=" << roi.y1 << "x2=" << roi.x2 << "y2=" << roi.y2 << ")"; #endif return (mv::FrameAccessor::Key)0; } #ifdef TRACE_LIB_MV qDebug() << QThread::currentThread() << "FrameAccessor::GetImage():" << "renderRoi (frame" << frame << ") OK (BOUNDS= x1=" << sourceBounds.x1 << "y1=" << sourceBounds.y1 << "x2=" << sourceBounds.x2 << "y2=" << sourceBounds.y2 << ") (ROI = " << roi.x1 << "y1=" << roi.y1 << "x2=" << roi.x2 << "y2=" << roi.y2 << ")"; #endif /* Copy the Natron image to the LivMV float image */ FrameAccessorCacheEntry entry; entry.image.reset( new MvFloatImage( intersectedRoI.height(), intersectedRoI.width() ) ); entry.bounds = intersectedRoI; entry.referenceCount = 1; natronImageToLibMvFloatImage(_imp->enabledChannels, sourceImage.get(), intersectedRoI, *entry.image); // we ignore the transform parameter and do it in natronImageToLibMvFloatImage instead *destination = entry.image.get(); //destination->CopyFrom<float>(*entry.image); //insert into the cache { QMutexLocker k(&_imp->cacheMutex); _imp->cache.insert( std::make_pair(key, entry) ); } #ifdef TRACE_LIB_MV qDebug() << QThread::currentThread() << "FrameAccessor::GetImage():" << "Rendered frame" << frame << "with RoI x1=" << intersectedRoI.x1 << "y1=" << intersectedRoI.y1 << "x2=" << intersectedRoI.x2 << "y2=" << intersectedRoI.y2; #endif return (mv::FrameAccessor::Key)entry.image.get(); } // TrackerFrameAccessor::GetImage