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

Added animation.

parent 27b0922c
This diff is collapsed.
...@@ -51,11 +51,11 @@ bHQDistortion=False ...@@ -51,11 +51,11 @@ bHQDistortion=False
bUpdateOnRT=True bUpdateOnRT=True
[WindowsApplication.Accessibility] [WindowsApplication.Accessibility]
StickyKeysHotkey=False StickyKeysHotkey=True
ToggleKeysHotkey=False ToggleKeysHotkey=True
FilterKeysHotkey=False FilterKeysHotkey=True
StickyKeysConfirmation=False StickyKeysConfirmation=True
ToggleKeysConfirmation=False ToggleKeysConfirmation=True
FilterKeysConfirmation=False FilterKeysConfirmation=True
...@@ -41,20 +41,61 @@ void UDataComponent::BeginPlay() ...@@ -41,20 +41,61 @@ void UDataComponent::BeginPlay()
if (!FileNameToLoadOnStart.IsEmpty()) if (!FileNameToLoadOnStart.IsEmpty())
{ {
LoadFile(FileNameToLoadOnStart); LoadFile(FileNameToLoadOnStart);
LoadStep(GroupNames[0]);
} }
} }
void UDataComponent::LoadFile(FString FileName) void UDataComponent::LoadFile(FString FileName)
{ {
// Load File // 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); UHDF5Library::LoadGroup(LoadedFile, GroupName, X, Y, Z, U, V, W);
CurrentGroupName = GroupName;
// Prepare Data // Prepare Data
Num = X.Num(); Num = X.Num();
if (OverrideMaxPointCount > 0 && OverrideMaxPointCount < Num) if (OverrideMaxPointCount > 0 && OverrideMaxPointCount < Num)
...@@ -62,9 +103,13 @@ void UDataComponent::LoadStep(FString GroupName) ...@@ -62,9 +103,13 @@ void UDataComponent::LoadStep(FString GroupName)
Num = OverrideMaxPointCount; Num = OverrideMaxPointCount;
} }
IsBrushed = TArray<bool>(); if (ResetBrush) // TODO
IsBrushed.Init(false, Num); {
IsBrushed = TArray<bool>();
IsBrushed.Init(false, Num);
}
Length.Empty();
for (int32 i = 0; i < Num; i++) for (int32 i = 0; i < Num; i++)
{ {
Length.Emplace(FVector(U[i], V[i], W[i]).Size()); Length.Emplace(FVector(U[i], V[i], W[i]).Size());
...@@ -86,6 +131,7 @@ void UDataComponent::LoadStep(FString GroupName) ...@@ -86,6 +131,7 @@ void UDataComponent::LoadStep(FString GroupName)
UKismetMathLibrary::MaxOfFloatArray(W, MaxIndex, MaxW); UKismetMathLibrary::MaxOfFloatArray(W, MaxIndex, MaxW);
UKismetMathLibrary::MinOfFloatArray(W, MinIndex, MinW); UKismetMathLibrary::MinOfFloatArray(W, MinIndex, MinW);
PColor.Empty();
for (int32 i = 0; i < Num; i++) for (int32 i = 0; i < Num; i++)
{ {
FColor TempColor = CalculateColorOfPoint(i, MaxLength, MinLength); FColor TempColor = CalculateColorOfPoint(i, MaxLength, MinLength);
...@@ -93,13 +139,8 @@ void UDataComponent::LoadStep(FString GroupName) ...@@ -93,13 +139,8 @@ void UDataComponent::LoadStep(FString GroupName)
PColor.Emplace(FVector(TempColor.R, TempColor.G, TempColor.B)); PColor.Emplace(FVector(TempColor.R, TempColor.G, TempColor.B));
} }
// Spawn Plot3D Cast<APawnBase>(GetOwner())->Plot3D->OnLoadStep(IsFirstTime, !ResetBrush);
FVector Location(-1610.0f, -341.0f, 100.0f); IsFirstTime = false;
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);
} }
FColor UDataComponent::CalculateColorOfPoint(int32 Index, float Min, float Max) FColor UDataComponent::CalculateColorOfPoint(int32 Index, float Min, float Max)
......
...@@ -19,11 +19,23 @@ class IMMERSIVEANALYTICS_API UDataComponent : public UActorComponent ...@@ -19,11 +19,23 @@ class IMMERSIVEANALYTICS_API UDataComponent : public UActorComponent
public: public:
UDataComponent(); 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) UFUNCTION(BlueprintCallable, Category = HDF5)
void LoadFile(FString FileName); void LoadFile(FString FileName);
UFUNCTION(BlueprintCallable, Category = HDF5) UFUNCTION(BlueprintCallable, Category = HDF5)
void LoadStep(FString GroupName); void LoadStep(FString GroupName, bool ResetBrush);
UPROPERTY(Category = Plot3D, EditAnywhere) UPROPERTY(Category = Plot3D, EditAnywhere)
FString FileNameToLoadOnStart; FString FileNameToLoadOnStart;
...@@ -31,7 +43,7 @@ public: ...@@ -31,7 +43,7 @@ public:
UPROPERTY(EditAnywhere, Category = Plot3D) UPROPERTY(EditAnywhere, Category = Plot3D)
UCurveVector* TransferFunction; UCurveVector* TransferFunction;
UPROPERTY(Category = Plot3D, EditAnywhere) UPROPERTY(Category = Plot3D, EditAnywhere, BlueprintReadWrite)
int32 OverrideMaxPointCount; int32 OverrideMaxPointCount;
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
...@@ -89,9 +101,8 @@ protected: ...@@ -89,9 +101,8 @@ protected:
private: private:
H5File LoadedFile; H5File LoadedFile;
TArray<FString> GroupNames;
TArray<FString> FileNames;
FColor CalculateColorOfPoint(int32 Index, float Min, float Max); FColor CalculateColorOfPoint(int32 Index, float Min, float Max);
bool IsFirstTime;
public: public:
UPROPERTY(Category = Plot3D, BlueprintReadWrite) UPROPERTY(Category = Plot3D, BlueprintReadWrite)
......
...@@ -31,24 +31,6 @@ void APlot3D::Init(UDataComponent* DataComponent) ...@@ -31,24 +31,6 @@ void APlot3D::Init(UDataComponent* DataComponent)
{ {
Data = 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 // Init cloud
PointCloud = NewObject<UPointCloud>(); PointCloud = NewObject<UPointCloud>();
PointCloud->Offset = EPointCloudOffset::Center; PointCloud->Offset = EPointCloudOffset::Center;
...@@ -56,7 +38,6 @@ void APlot3D::Init(UDataComponent* DataComponent) ...@@ -56,7 +38,6 @@ void APlot3D::Init(UDataComponent* DataComponent)
PointCloud->SpriteMask = EPointCloudSpriteMask::Circle; PointCloud->SpriteMask = EPointCloudSpriteMask::Circle;
//PointCloud->SpriteTexture = //PointCloud->SpriteTexture =
PointCloud->ColorOverride = EPointCloudColorOverride::None; PointCloud->ColorOverride = EPointCloudColorOverride::None;
PointCloud->SpriteSize = FVector2D(0.5, 0.5);
if (Data->D3_UseTransparency) if (Data->D3_UseTransparency)
{ {
...@@ -66,9 +47,45 @@ void APlot3D::Init(UDataComponent* DataComponent) ...@@ -66,9 +47,45 @@ void APlot3D::Init(UDataComponent* DataComponent)
{ {
PointCloud->CustomMaterial = Data->D3_MaterialNontransparent; 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); GetPointCloudComponent()->SetPointCloud(PointCloud);
RebuildCloud();
} }
void APlot3D::RebuildCloud() void APlot3D::RebuildCloud()
...@@ -224,9 +241,13 @@ void APlot3D::EnableAllPoints() ...@@ -224,9 +241,13 @@ void APlot3D::EnableAllPoints()
}; };
} }
void APlot3D::UpdateSpriteSize() void APlot3D::UpdateSpriteSize(bool Rebuild)
{ {
float Size = GetActorScale3D().X / 100 / DataScaleFactor * Data->D3_SpriteSizeFactor; float Size = GetActorScale3D().X / 100 / DataScaleFactor * Data->D3_SpriteSizeFactor;
PointCloud->SpriteSize = FVector2D(Size, Size); PointCloud->SpriteSize = FVector2D(Size, Size);
PointCloud->Rebuild();
if (Rebuild)
{
PointCloud->Rebuild();
}
} }
...@@ -19,6 +19,7 @@ public: ...@@ -19,6 +19,7 @@ public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
APlot3D(); APlot3D();
void Init(class UDataComponent* DataComponent); void Init(class UDataComponent* DataComponent);
void OnLoadStep(bool IsFirstTime, bool KeepBrushedIndexes);
protected: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
...@@ -27,6 +28,8 @@ protected: ...@@ -27,6 +28,8 @@ protected:
private: private:
void RebuildCloud(); void RebuildCloud();
void UpdatePoints(bool KeepBrushedIndexes);
FVector Center; FVector Center;
UPROPERTY(Category = PointCloudActor, VisibleAnywhere, BlueprintReadOnly, meta = (ExposeFunctionCategories = "Rendering,Components|PointCloud", AllowPrivateAccess = "true")) UPROPERTY(Category = PointCloudActor, VisibleAnywhere, BlueprintReadOnly, meta = (ExposeFunctionCategories = "Rendering,Components|PointCloud", AllowPrivateAccess = "true"))
...@@ -66,5 +69,5 @@ public: ...@@ -66,5 +69,5 @@ public:
void EnableAllPoints(); void EnableAllPoints();
UFUNCTION(BlueprintCallable) 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