Commit 458d783d authored by Jan Kremer's avatar Jan Kremer

Added animation.

parent 27b0922c
This diff is collapsed.
......@@ -51,11 +51,11 @@ bHQDistortion=False
bUpdateOnRT=True
[WindowsApplication.Accessibility]
StickyKeysHotkey=False
ToggleKeysHotkey=False
FilterKeysHotkey=False
StickyKeysConfirmation=False
ToggleKeysConfirmation=False
FilterKeysConfirmation=False
StickyKeysHotkey=True
ToggleKeysHotkey=True
FilterKeysHotkey=True
StickyKeysConfirmation=True
ToggleKeysConfirmation=True
FilterKeysConfirmation=True
......@@ -41,20 +41,61 @@ void UDataComponent::BeginPlay()
if (!FileNameToLoadOnStart.IsEmpty())
{
LoadFile(FileNameToLoadOnStart);
LoadStep(GroupNames[0]);
}
}
void UDataComponent::LoadFile(FString FileName)
{
// Load File
LoadedFile = UHDF5Library::LoadFile(FileName, GroupNames);
TArray<FString> TempStringArray = TArray<FString>();
LoadedFile = UHDF5Library::LoadFile(FileName, TempStringArray);
CurrentFileName = FileName;
if (!Cast<APawnBase>(GetOwner())->Plot3D)
{
FVector Location(-1610.0f, -341.0f, 100.0f);
FRotator Rotation(0.0f, 0.0f, 0.0f);
FActorSpawnParameters SpawnInfo;
APlot3D* Plot3D = GetWorld()->SpawnActor<APlot3D>(Location, Rotation, SpawnInfo);
Cast<APawnBase>(GetOwner())->Plot3D = Plot3D;
Plot3D->Init(this);
}
/*
The order would be "1,10,11,12,13,14,15,16,17,18,19,2,20,21,22,23,24" without sorting padded strings!
*/
for (int i = 0; i < TempStringArray.Num(); ++i)
{
int32 Length = TempStringArray[i].Len();
for (int j = 0; j < (12 - Length); ++j) // pad the string to 10 characters
{
TempStringArray[i].InsertAt(5, " "); // 5 is the position after "step#"
}
}
TempStringArray.Sort([](const FString& One, const FString& Two) {
return One < Two;
});
for (int i = 0; i < TempStringArray.Num(); ++i)
{
TempStringArray[i] = TempStringArray[i].Replace(TEXT(" "), TEXT(""));
}
GroupNames.Empty();
for (FString String : TempStringArray)
{
GroupNames.Emplace(String);
}
IsFirstTime = true;
LoadStep(GroupNames[0], true);
}
void UDataComponent::LoadStep(FString GroupName)
void UDataComponent::LoadStep(FString GroupName, bool ResetBrush)
{
UHDF5Library::LoadGroup(LoadedFile, GroupName, X, Y, Z, U, V, W);
CurrentGroupName = GroupName;
// Prepare Data
Num = X.Num();
if (OverrideMaxPointCount > 0 && OverrideMaxPointCount < Num)
......@@ -62,9 +103,13 @@ void UDataComponent::LoadStep(FString GroupName)
Num = OverrideMaxPointCount;
}
IsBrushed = TArray<bool>();
IsBrushed.Init(false, Num);
if (ResetBrush) // TODO
{
IsBrushed = TArray<bool>();
IsBrushed.Init(false, Num);
}
Length.Empty();
for (int32 i = 0; i < Num; i++)
{
Length.Emplace(FVector(U[i], V[i], W[i]).Size());
......@@ -86,6 +131,7 @@ void UDataComponent::LoadStep(FString GroupName)
UKismetMathLibrary::MaxOfFloatArray(W, MaxIndex, MaxW);
UKismetMathLibrary::MinOfFloatArray(W, MinIndex, MinW);
PColor.Empty();
for (int32 i = 0; i < Num; i++)
{
FColor TempColor = CalculateColorOfPoint(i, MaxLength, MinLength);
......@@ -93,13 +139,8 @@ void UDataComponent::LoadStep(FString GroupName)
PColor.Emplace(FVector(TempColor.R, TempColor.G, TempColor.B));
}
// Spawn Plot3D
FVector Location(-1610.0f, -341.0f, 100.0f);
FRotator Rotation(0.0f, 0.0f, 0.0f);
FActorSpawnParameters SpawnInfo;
APlot3D* Plot3D = GetWorld()->SpawnActor<APlot3D>(Location, Rotation, SpawnInfo);
Cast<APawnBase>(GetOwner())->Plot3D = Plot3D;
Plot3D->Init(this);
Cast<APawnBase>(GetOwner())->Plot3D->OnLoadStep(IsFirstTime, !ResetBrush);
IsFirstTime = false;
}
FColor UDataComponent::CalculateColorOfPoint(int32 Index, float Min, float Max)
......
......@@ -19,11 +19,23 @@ class IMMERSIVEANALYTICS_API UDataComponent : public UActorComponent
public:
UDataComponent();
UPROPERTY(Category = Plot3D, BlueprintReadOnly)
TArray<FString> GroupNames;
UPROPERTY(Category = Plot3D, BlueprintReadOnly)
TArray<FString> FileNames;
UPROPERTY(Category = Plot3D, BlueprintReadOnly)
FString CurrentGroupName;
UPROPERTY(Category = Plot3D, BlueprintReadOnly)
FString CurrentFileName;
UFUNCTION(BlueprintCallable, Category = HDF5)
void LoadFile(FString FileName);
UFUNCTION(BlueprintCallable, Category = HDF5)
void LoadStep(FString GroupName);
void LoadStep(FString GroupName, bool ResetBrush);
UPROPERTY(Category = Plot3D, EditAnywhere)
FString FileNameToLoadOnStart;
......@@ -31,7 +43,7 @@ public:
UPROPERTY(EditAnywhere, Category = Plot3D)
UCurveVector* TransferFunction;
UPROPERTY(Category = Plot3D, EditAnywhere)
UPROPERTY(Category = Plot3D, EditAnywhere, BlueprintReadWrite)
int32 OverrideMaxPointCount;
UFUNCTION(BlueprintCallable)
......@@ -89,9 +101,8 @@ protected:
private:
H5File LoadedFile;
TArray<FString> GroupNames;
TArray<FString> FileNames;
FColor CalculateColorOfPoint(int32 Index, float Min, float Max);
bool IsFirstTime;
public:
UPROPERTY(Category = Plot3D, BlueprintReadWrite)
......
......@@ -31,24 +31,6 @@ void APlot3D::Init(UDataComponent* DataComponent)
{
Data = DataComponent;
// Calculate scale and scale factor
float XSum = 0;
for (int32 i = 0; i < Data->Num; i++)
{
XSum += Data->X[i];
}
float XMean = XSum / Data->Num;
DataScaleFactor = 0.5 / XMean;
SetActorScale3D(FVector(DataScaleFactor, DataScaleFactor, DataScaleFactor));
// Add points
for (int32 i = 0; i < Data->Num; i++)
{
FVector Location = FVector(Data->X[i], Data->Y[i], Data->Z[i]);
FColor Color = FColor(Data->PColor[i].X, Data->PColor[i].Y, Data->PColor[i].Z);
Points.Emplace(Location, Color, true);
}
// Init cloud
PointCloud = NewObject<UPointCloud>();
PointCloud->Offset = EPointCloudOffset::Center;
......@@ -56,7 +38,6 @@ void APlot3D::Init(UDataComponent* DataComponent)
PointCloud->SpriteMask = EPointCloudSpriteMask::Circle;
//PointCloud->SpriteTexture =
PointCloud->ColorOverride = EPointCloudColorOverride::None;
PointCloud->SpriteSize = FVector2D(0.5, 0.5);
if (Data->D3_UseTransparency)
{
......@@ -66,9 +47,45 @@ void APlot3D::Init(UDataComponent* DataComponent)
{
PointCloud->CustomMaterial = Data->D3_MaterialNontransparent;
}
}
void APlot3D::OnLoadStep(bool IsFirstTime, bool KeepBrushedIndexes)
{
if (IsFirstTime)
{
// Calculate scale and scale factor
float XSum = 0;
for (int32 i = 0; i < Data->Num; i++)
{
XSum += Data->X[i];
}
float XMean = XSum / Data->Num;
DataScaleFactor = 0.5 / XMean;
SetActorScale3D(FVector(DataScaleFactor, DataScaleFactor, DataScaleFactor));
UpdateSpriteSize(false);
}
UpdatePoints(KeepBrushedIndexes);
RebuildCloud(); // TODO needed?
}
void APlot3D::UpdatePoints(bool KeepBrushedIndexes)
{
Points.Empty();
// Add points
for (int32 i = 0; i < Data->Num; i++)
{
FVector Location = FVector(Data->X[i], Data->Y[i], Data->Z[i]);
FColor Color = FColor(Data->PColor[i].X, Data->PColor[i].Y, Data->PColor[i].Z);
Points.Emplace(Location, Color, true);
if (KeepBrushedIndexes)
{
BrushPoint(i, Data->IsBrushed[i]);
}
}
GetPointCloudComponent()->SetPointCloud(PointCloud);
RebuildCloud();
}
void APlot3D::RebuildCloud()
......@@ -224,9 +241,13 @@ void APlot3D::EnableAllPoints()
};
}
void APlot3D::UpdateSpriteSize()
void APlot3D::UpdateSpriteSize(bool Rebuild)
{
float Size = GetActorScale3D().X / 100 / DataScaleFactor * Data->D3_SpriteSizeFactor;
PointCloud->SpriteSize = FVector2D(Size, Size);
PointCloud->Rebuild();
if (Rebuild)
{
PointCloud->Rebuild();
}
}
......@@ -19,6 +19,7 @@ public:
// Sets default values for this actor's properties
APlot3D();
void Init(class UDataComponent* DataComponent);
void OnLoadStep(bool IsFirstTime, bool KeepBrushedIndexes);
protected:
// Called when the game starts or when spawned
......@@ -27,6 +28,8 @@ protected:
private:
void RebuildCloud();
void UpdatePoints(bool KeepBrushedIndexes);
FVector Center;
UPROPERTY(Category = PointCloudActor, VisibleAnywhere, BlueprintReadOnly, meta = (ExposeFunctionCategories = "Rendering,Components|PointCloud", AllowPrivateAccess = "true"))
......@@ -66,5 +69,5 @@ public:
void EnableAllPoints();
UFUNCTION(BlueprintCallable)
void UpdateSpriteSize();
void UpdateSpriteSize(bool Rebuild);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment