ActorID & PooledActors

本文详细介绍了jBPM中的两种任务分配模式——推模式和拉模式,并解释了这两种模式下任务如何被分配给用户。同时,文章还探讨了如何设置用户、获取任务列表以及如何管理候选参与者和真正参与者的区别。

jBPM有两种分配任务的模式,推模式和拉模式。

推模式:系统主动分配任务给actorID。推模式只有一个人能参与这个任务。通过actorId指定用户

拉模式:actorId去申请这个任务。拉模式的任务可以是多个人参与的,但是只能有其中的一个人能结束。通过PooledActors指定用户群。

当同时指定了这两个属性的时候,actorId才是真正被指定的参与者。只有这个参与者才能完成这个任务,其他的在PooledActors里面的用户,是无法得到这个任务的,所以也没有办法处理这个任务。

设置用户

推模式:Assignable.setActorID(String actorId)

拉模式:Assignable.setPooledActors(String[] actorIds)

得到用户任务列表

推模式:TaskMgmtSession.findTaskInstances(String actorId)

拉模式:TaskMgmtSesion.findPooledTaskInstances(String actorId)  TaskMgmtSession.findPooledTaskInstances(List actorIds)

到今天才真正了解了为什么有些人把pooledActors翻译成候选参与者,因为当有真正的参与者的时候,候选参与者是没有权利查看并完成任务的。

又或者只设置了pooledActors的那个taskInstance称之为共享任务。只要在pooledActors数组里面的用户都可以查看并完成这个任务。所以防止冲突,需要把执行任务的这个候选参与者升格为参与者,即把这个用户设置到actorID里面,如果需要重新把这个任务作为共享任务,只需要把actorId这个属性设置为null.

以上是今天研究用户权限的一些体会。经过这几天的研究,发现jBPM没有想象中的负责,不过还有很多的地方没有没有搞清楚,继续努力......

TArray<FColor> UPixelTraceResultProcessor::ParseHitResultsToColor( const TArray<FHitResult>& HitResults, TMap<FColor, TArray<FString>>& ColorToActorIDsMap) // 修改为存储多个ID的数组 { TArray<FColor> results; int32 count = HitResults.Num(); results.SetNum(count); // 临时存储每个像素的颜色和对应ActorID TArray<TPair<FColor, FString>> TempColorActorPairs; TempColorActorPairs.SetNum(count); ParallelFor(count, [&](int32 Index) { uint32 value = 0; FString actorID = TEXT("None"); auto actor = HitResults[Index].GetActor(); if (actor) { actorID = FString::Printf(TEXT("%d"), actor->GetUniqueID()); const TArray<FName>& tags = actor->Tags; for (int32 i = 0; i < tags.Num(); i++) { uint32 temp = MatchComponentNameToStencilNumber(tags[i]); if (temp != 0) { value = temp; break; } } } uint8 r = static_cast<uint8>(value & 0xff); FColor pixelColor(r, r, r); results[Index] = pixelColor; TempColorActorPairs[Index] = TPair<FColor, FString>(pixelColor, actorID); }); // 构建颜色到多个ActorID的映射 for (const auto& Pair : TempColorActorPairs) { TArray<FString>& idArray = ColorToActorIDsMap.FindOrAdd(Pair.Key); if (!idArray.Contains(Pair.Value)) { // 避免重复添加相同ID idArray.Add(Pair.Value); } } return results; } void UPixelTraceResultProcessor::ExportHitResultsToBmpImage( const TArray<FHitResult>& HitResults, int32 Width, int32 Height, const FString& FilePath) { TMap<FColor, TArray<FString>> ColorToActorIDsMap; // 修改为存储多个ID TArray<FColor> points = ParseHitResultsToColor(HitResults, ColorToActorIDsMap); // 统计每个颜色出现的总次数 TMap<FColor, int32> ColorCountMap; for (const FColor& color : points) { ColorCountMap.FindOrAdd(color)++; } // 保存BMP图像 FImageView ImageView(points.GetData(), Width, Height, 1, ERawImageFormat::BGRA8, EGammaSpace::Linear); if (FImageUtils::SaveImageByExtension(*FilePath, ImageView)) { UE_LOG(LogTemp, Display, TEXT("BMP Saved to: %s"), *FilePath); // 输出Actor IDs映射信息和像素数量 FString ActorIDFilePath = FPaths::Combine(FPaths::GetPath(FilePath), FPaths::GetBaseFilename(FilePath) + TEXT("_ActorIDs.txt")); FString ActorIDInfo; for (const auto& Pair : ColorToActorIDsMap) { const FColor& color = Pair.Key; int32 totalCount = ColorCountMap.Contains(color) ? ColorCountMap[color] : 0; ActorIDInfo += FString::Printf(TEXT("Color(R=%d,G=%d,B=%d):\n"), color.R, color.G, color.B); // 输出该颜色对应的所有ActorID及其出现次数 TMap<FString, int32> idCountMap; for (const auto& id : Pair.Value) { idCountMap.FindOrAdd(id)++; } for (const auto& idPair : idCountMap) { ActorIDInfo += FString::Printf(TEXT(" %s - Count: %d\n"), *idPair.Key, idPair.Value); } ActorIDInfo += FString::Printf(TEXT("Total Pixels: %d\n\n"), totalCount); } if (FFileHelper::SaveStringToFile(ActorIDInfo, *ActorIDFilePath)) { UE_LOG(LogTemp, Display, TEXT("Actor IDs mapping saved to: %s"), *ActorIDFilePath); } else { UE_LOG(LogTemp, Error, TEXT("Failed to save Actor IDs mapping")); } } else { UE_LOG(LogTemp, Error, TEXT("Failed to Save BMP")); } } 帮我改一下代码,这段代码之前是颜色对应了多个ID,我想输出ID 对应的颜色,对应有多少像素
最新发布
09-30
TArray<FColor> UPixelTraceResultProcessor::ParseHitResultsToColor(const TArray<FHitResult>& HitResults, TMap<FColor, FString>& ColorToActorIDMap) { TArray<FColor> results; int32 count = HitResults.Num(); results.SetNum(count); TArray<TPair<FColor, FString>> TempColorActorPairs; TempColorActorPairs.SetNum(count); ParallelFor(count, [&](int32 Index) { uint32 value = 0; FString actorID = TEXT("None"); auto actor = HitResults[Index].GetActor(); if (actor) { actorID = FString::Printf(TEXT("%d"), actor->GetUniqueID()); // 使用GetUniqueID获取唯一标识 const TArray<FName>& tags = actor->Tags; for (int32 i = 0; i < tags.Num(); i++) { uint32 temp = MatchComponentNameToStencilNumber(tags[i]); if (temp != 0) { value = temp; break; } } } uint8 r = static_cast<uint8>(value & 0xff); //uint8 g = static_cast<uint8>((value >> 8) & 0xff); //uint8 b = static_cast<uint8>((value >> 16) & 0xff); FColor pixelColor(r, r, r); results[Index] = pixelColor; // 保存颜色到Actor ID的映射 /* if (!ColorToActorIDMap.Contains(pixelColor)) { ColorToActorIDMap.Add(pixelColor, actorID); }*/ TempColorActorPairs[Index] = TPair<FColor, FString>(pixelColor, actorID); }); for (const auto& Pair : TempColorActorPairs) { ColorToActorIDMap.FindOrAdd(Pair.Key, Pair.Value); } return results; } void UPixelTraceResultProcessor::ExportHitResultsToBmpImage(const TArray<FHitResult>& HitResults, int32 Width, int32 Height, const FString& FilePath) { TMap<FColor, FString> ColorToActorIDMap; TArray<FColor> points = ParseHitResultsToColor(HitResults, ColorToActorIDMap); // 统计每个颜色出现的次数 TMap<FColor, int32> ColorCountMap; for (const FColor& color : points) { ColorCountMap.FindOrAdd(color)++; } // 保存BMP图像 FImageView ImageView(points.GetData(), Width, Height, 1, ERawImageFormat::BGRA8, EGammaSpace::Linear); if (FImageUtils::SaveImageByExtension(*FilePath, ImageView)) { UE_LOG(LogTemp, Display, TEXT("BMP Saved to: %s"), *FilePath); // 输出Actor ID映射信息和像素数量 FString ActorIDFilePath = FPaths::Combine(FPaths::GetPath(FilePath), FPaths::GetBaseFilename(FilePath) + TEXT("_ActorIDs.txt")); FString ActorIDInfo; for (const auto& Pair : ColorToActorIDMap) { const FColor& color = Pair.Key; int32 count = ColorCountMap.Contains(color) ? ColorCountMap[color] : 0; ActorIDInfo += FString::Printf(TEXT("Color(R=%d,G=%d,B=%d): %s - Pixel Count: %d\n"), color.R, color.G, color.B, *Pair.Value, count); } if (FFileHelper::SaveStringToFile(ActorIDInfo, *ActorIDFilePath)) { UE_LOG(LogTemp, Display, TEXT("Actor ID mapping saved to: %s"), *ActorIDFilePath); } else { UE_LOG(LogTemp, Error, TEXT("Failed to save Actor ID mapping to: %s"), *ActorIDFilePath); } } else { UE_LOG(LogTemp, Error, TEXT("Failed to Save BMP to: %s"), *FilePath); } }代码会导致一个颜色只能对应一个id 但其实一个颜色对应的id会有多个
09-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值