Commit be36b7ff authored by Jan Kremer's avatar Jan Kremer

Tuned 3D plot auto scale.

parent 72d7c5da
No preview for this file type
This diff is collapsed.
...@@ -94,7 +94,6 @@ void UDataComponent::LoadFile(FString FileName) ...@@ -94,7 +94,6 @@ void UDataComponent::LoadFile(FString FileName)
SetFileBounds(); SetFileBounds();
} }
IsFirstTime = true;
LoadStep(GroupNames[0], true); LoadStep(GroupNames[0], true);
} }
...@@ -140,6 +139,8 @@ void UDataComponent::LoadStep(FString GroupName, bool ResetBrush) ...@@ -140,6 +139,8 @@ void UDataComponent::LoadStep(FString GroupName, bool ResetBrush)
UKismetMathLibrary::MinOfFloatArray(V, MinIndex, MinV); UKismetMathLibrary::MinOfFloatArray(V, MinIndex, MinV);
UKismetMathLibrary::MaxOfFloatArray(W, MaxIndex, MaxW); UKismetMathLibrary::MaxOfFloatArray(W, MaxIndex, MaxW);
UKismetMathLibrary::MinOfFloatArray(W, MinIndex, MinW); UKismetMathLibrary::MinOfFloatArray(W, MinIndex, MinW);
UpdateDataScaleFactor();
} }
PColor.Empty(); PColor.Empty();
...@@ -150,8 +151,7 @@ void UDataComponent::LoadStep(FString GroupName, bool ResetBrush) ...@@ -150,8 +151,7 @@ void UDataComponent::LoadStep(FString GroupName, bool ResetBrush)
PColor.Emplace(FVector(TempColor.R, TempColor.G, TempColor.B)); PColor.Emplace(FVector(TempColor.R, TempColor.G, TempColor.B));
} }
Cast<APawnBase>(GetOwner())->Plot3D->OnLoadStep(IsFirstTime, !ResetBrush); Cast<APawnBase>(GetOwner())->Plot3D->OnLoadStep(!ResetBrush);
IsFirstTime = false;
APawnBase* BasePawn = Cast<APawnBase>(GetOwner()); APawnBase* BasePawn = Cast<APawnBase>(GetOwner());
for (APlot2D* Plot2D : BasePawn->Plots2D) for (APlot2D* Plot2D : BasePawn->Plots2D)
...@@ -232,6 +232,14 @@ void UDataComponent::SetFileBounds() ...@@ -232,6 +232,14 @@ void UDataComponent::SetFileBounds()
UKismetMathLibrary::MinOfFloatArray(VMinTemp, MinIndex, MinV); UKismetMathLibrary::MinOfFloatArray(VMinTemp, MinIndex, MinV);
UKismetMathLibrary::MaxOfFloatArray(WMaxTemp, MaxIndex, MaxW); UKismetMathLibrary::MaxOfFloatArray(WMaxTemp, MaxIndex, MaxW);
UKismetMathLibrary::MinOfFloatArray(WMinTemp, MinIndex, MinW); UKismetMathLibrary::MinOfFloatArray(WMinTemp, MinIndex, MinW);
UpdateDataScaleFactor();
}
void UDataComponent::UpdateDataScaleFactor()
{
float Range = FMath::Max3(MaxX - MinX, MaxY - MinY, MaxZ - MinZ);
DataScaleFactor = 2 / Range;
} }
void UDataComponent::AddFilter_Planes(FVector NormalRight, FVector LocationRight, bool UseTwoPlanes, FVector NormalLeft, FVector LocationLeft, bool Add, bool Rebuild, bool Invert) void UDataComponent::AddFilter_Planes(FVector NormalRight, FVector LocationRight, bool UseTwoPlanes, FVector NormalLeft, FVector LocationLeft, bool Add, bool Rebuild, bool Invert)
......
...@@ -105,8 +105,8 @@ protected: ...@@ -105,8 +105,8 @@ protected:
private: private:
H5File LoadedFile; H5File LoadedFile;
FColor CalculateColorOfPoint(int32 Index, float Min, float Max); FColor CalculateColorOfPoint(int32 Index, float Min, float Max);
bool IsFirstTime;
void SetFileBounds(); void SetFileBounds();
void UpdateDataScaleFactor();
public: public:
UPROPERTY(Category = Plot3D, BlueprintReadWrite) UPROPERTY(Category = Plot3D, BlueprintReadWrite)
...@@ -181,4 +181,6 @@ public: ...@@ -181,4 +181,6 @@ public:
UPROPERTY(Category = Plot3D, BlueprintReadOnly) UPROPERTY(Category = Plot3D, BlueprintReadOnly)
float MaxW; float MaxW;
UPROPERTY(Category = Plot3D, BlueprintReadOnly)
float DataScaleFactor;
}; };
...@@ -49,22 +49,10 @@ void APlot3D::Init(UDataComponent* DataComponent) ...@@ -49,22 +49,10 @@ void APlot3D::Init(UDataComponent* DataComponent)
} }
} }
void APlot3D::OnLoadStep(bool IsFirstTime, bool KeepBrushedIndexes) void APlot3D::OnLoadStep(bool KeepBrushedIndexes)
{ {
if (IsFirstTime) SetActorScale3D(FVector(Data->DataScaleFactor, Data->DataScaleFactor, Data->DataScaleFactor));
{ UpdateSpriteSize(false);
// 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); UpdatePoints(KeepBrushedIndexes);
RebuildCloud(); // TODO needed? RebuildCloud(); // TODO needed?
} }
...@@ -243,7 +231,7 @@ void APlot3D::EnableAllPoints() ...@@ -243,7 +231,7 @@ void APlot3D::EnableAllPoints()
void APlot3D::UpdateSpriteSize(bool Rebuild) void APlot3D::UpdateSpriteSize(bool Rebuild)
{ {
float Size = GetActorScale3D().X / 100 / DataScaleFactor * Data->D3_SpriteSizeFactor; float Size = GetActorScale3D().X / 100 / Data->DataScaleFactor * Data->D3_SpriteSizeFactor;
PointCloud->SpriteSize = FVector2D(Size, Size); PointCloud->SpriteSize = FVector2D(Size, Size);
if (Rebuild) if (Rebuild)
......
...@@ -19,7 +19,7 @@ public: ...@@ -19,7 +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); void OnLoadStep(bool KeepBrushedIndexes);
protected: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
...@@ -47,11 +47,6 @@ public: ...@@ -47,11 +47,6 @@ public:
UPROPERTY(Category = Plot3D, VisibleDefaultsOnly, BlueprintReadOnly) UPROPERTY(Category = Plot3D, VisibleDefaultsOnly, BlueprintReadOnly)
TArray<FPointCloudPoint> Points; TArray<FPointCloudPoint> Points;
// rendering
UPROPERTY(Category = Plot3D, VisibleDefaultsOnly, BlueprintReadOnly)
float DataScaleFactor;
// plot interface // plot interface
void BrushPoints(TArray<int32> PointIndexes, bool Rebuild); void BrushPoints(TArray<int32> PointIndexes, bool Rebuild);
void BrushPoint(int32 PointIndex, bool Add); void BrushPoint(int32 PointIndex, bool Add);
......
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