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)
SetFileBounds();
}
IsFirstTime = true;
LoadStep(GroupNames[0], true);
}
......@@ -140,6 +139,8 @@ void UDataComponent::LoadStep(FString GroupName, bool ResetBrush)
UKismetMathLibrary::MinOfFloatArray(V, MinIndex, MinV);
UKismetMathLibrary::MaxOfFloatArray(W, MaxIndex, MaxW);
UKismetMathLibrary::MinOfFloatArray(W, MinIndex, MinW);
UpdateDataScaleFactor();
}
PColor.Empty();
......@@ -150,8 +151,7 @@ void UDataComponent::LoadStep(FString GroupName, bool ResetBrush)
PColor.Emplace(FVector(TempColor.R, TempColor.G, TempColor.B));
}
Cast<APawnBase>(GetOwner())->Plot3D->OnLoadStep(IsFirstTime, !ResetBrush);
IsFirstTime = false;
Cast<APawnBase>(GetOwner())->Plot3D->OnLoadStep(!ResetBrush);
APawnBase* BasePawn = Cast<APawnBase>(GetOwner());
for (APlot2D* Plot2D : BasePawn->Plots2D)
......@@ -232,6 +232,14 @@ void UDataComponent::SetFileBounds()
UKismetMathLibrary::MinOfFloatArray(VMinTemp, MinIndex, MinV);
UKismetMathLibrary::MaxOfFloatArray(WMaxTemp, MaxIndex, MaxW);
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)
......
......@@ -105,8 +105,8 @@ protected:
private:
H5File LoadedFile;
FColor CalculateColorOfPoint(int32 Index, float Min, float Max);
bool IsFirstTime;
void SetFileBounds();
void UpdateDataScaleFactor();
public:
UPROPERTY(Category = Plot3D, BlueprintReadWrite)
......@@ -181,4 +181,6 @@ public:
UPROPERTY(Category = Plot3D, BlueprintReadOnly)
float MaxW;
UPROPERTY(Category = Plot3D, BlueprintReadOnly)
float DataScaleFactor;
};
......@@ -49,22 +49,10 @@ void APlot3D::Init(UDataComponent* DataComponent)
}
}
void APlot3D::OnLoadStep(bool IsFirstTime, bool KeepBrushedIndexes)
void APlot3D::OnLoadStep(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);
}
SetActorScale3D(FVector(Data->DataScaleFactor, Data->DataScaleFactor, Data->DataScaleFactor));
UpdateSpriteSize(false);
UpdatePoints(KeepBrushedIndexes);
RebuildCloud(); // TODO needed?
}
......@@ -243,7 +231,7 @@ void APlot3D::EnableAllPoints()
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);
if (Rebuild)
......
......@@ -19,7 +19,7 @@ public:
// Sets default values for this actor's properties
APlot3D();
void Init(class UDataComponent* DataComponent);
void OnLoadStep(bool IsFirstTime, bool KeepBrushedIndexes);
void OnLoadStep(bool KeepBrushedIndexes);
protected:
// Called when the game starts or when spawned
......@@ -47,11 +47,6 @@ public:
UPROPERTY(Category = Plot3D, VisibleDefaultsOnly, BlueprintReadOnly)
TArray<FPointCloudPoint> Points;
// rendering
UPROPERTY(Category = Plot3D, VisibleDefaultsOnly, BlueprintReadOnly)
float DataScaleFactor;
// plot interface
void BrushPoints(TArray<int32> PointIndexes, bool Rebuild);
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