Commit 7af7d661 authored by Jan Kremer's avatar Jan Kremer

Cleanup. 2D diagrams now reduce brightness of brushed particles instead of...

Cleanup. 2D diagrams now reduce brightness of brushed particles instead of coloring them black. Added VR pawn to the repo instead of desktop pawn.
parent 0981d341
No preview for this file type
No preview for this file type
This diff is collapsed.
......@@ -50,12 +50,4 @@ bHQBuffer=False
bHQDistortion=False
bUpdateOnRT=True
[WindowsApplication.Accessibility]
StickyKeysHotkey=True
ToggleKeysHotkey=True
FilterKeysHotkey=True
StickyKeysConfirmation=True
ToggleKeysConfirmation=True
FilterKeysConfirmation=True
......@@ -6,7 +6,7 @@
#include "Components/ActorComponent.h"
#include "H5Cpp.h"
#include "Runtime/Engine/Classes/Curves/CurveVector.h"
#include "MyObject.h"
#include "SharedEnums.h"
#include "DataComponent.generated.h"
using namespace H5;
......
......@@ -7,7 +7,7 @@
#include "PointCloud.h"
#include "PointCloudActor.h"
#include "Runtime/Engine/Classes/Curves/CurveVector.h"
#include "MyObject.h"
#include "SharedEnums.h"
#include "Plot3D.generated.h"
UCLASS()
......
......@@ -106,57 +106,29 @@ void UPlotCanvas::SetYAxisType(EAxisType Type)
}
void UPlotCanvas::InitializeCanvas(const int32 pixelsH, const int32 pixelsV)
{
//dynamic texture initialization
canvasWidth = pixelsH;
canvasHeight = pixelsV;
CanvasWidth = pixelsH;
CanvasHeight = pixelsV;
dynamicCanvas = UTexture2D::CreateTransient(canvasWidth, canvasHeight);
DynamicCanvas = UTexture2D::CreateTransient(CanvasWidth, CanvasHeight);
#if WITH_EDITORONLY_DATA
dynamicCanvas->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
DynamicCanvas->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
#endif
dynamicCanvas->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
dynamicCanvas->SRGB = 1;
dynamicCanvas->AddToRoot();
dynamicCanvas->Filter = TextureFilter::TF_Nearest;
dynamicCanvas->UpdateResource();
DynamicCanvas->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
DynamicCanvas->SRGB = 1;
DynamicCanvas->AddToRoot();
DynamicCanvas->Filter = TextureFilter::TF_Nearest;
DynamicCanvas->UpdateResource();
echoUpdateTextureRegion = std::unique_ptr<FUpdateTextureRegion2D>(new FUpdateTextureRegion2D(0, 0, 0, 0, canvasWidth, canvasHeight));
EchoUpdateTextureRegion = std::unique_ptr<FUpdateTextureRegion2D>(new FUpdateTextureRegion2D(0, 0, 0, 0, CanvasWidth, CanvasHeight));
// buffers initialization
bytesPerPixel = 4; // r g b a
bufferPitch = canvasWidth * bytesPerPixel;
bufferSize = canvasWidth * canvasHeight * bytesPerPixel;
canvasPixelData = std::unique_ptr<uint8[]>(new uint8[bufferSize]);
BytesPerPixel = 4;
BufferPitch = CanvasWidth * BytesPerPixel;
BufferSize = CanvasWidth * CanvasHeight * BytesPerPixel;
CanvasPixelData = std::unique_ptr<uint8[]>(new uint8[BufferSize]);
ClearCanvas();
}
void UPlotCanvas::InitializeDrawingTools(const int32 brushRadius, uint8 r, uint8 g, uint8 b)
{
radius = brushRadius;
brushBufferSize = radius * radius * 4 * bytesPerPixel; //2r*2r * bpp
canvasBrushMask = std::unique_ptr<uint8[]>(new uint8[brushBufferSize]);
uint8* canvasBrushPixelPtr = canvasBrushMask.get();
for (int px = -radius; px < radius; ++px)
{
for (int py = -radius; py < radius; ++py)
{
int32 tx = px + radius;
int32 ty = py + radius;
canvasBrushPixelPtr = canvasBrushMask.get() + (tx + +ty * 2 * radius) * bytesPerPixel;
if (px*px + py * py < radius*radius)
{
setPixelColor(canvasBrushPixelPtr, r,g,b, 255); //black alpha 255 - bgra
}
else
{
setPixelColor(canvasBrushPixelPtr, 0, 0, 0, 0); // alpha 0
}
}
}
}
void UPlotCanvas::DrawScatterPlot()
{
ClearCanvas();
......@@ -166,15 +138,20 @@ void UPlotCanvas::DrawScatterPlot()
for (int i = 0; i < PawnBase->Plot3D->Points.Num(); ++i)
{
int32 x = ((*XArray)[i] - XMin) / (XMax - XMin) * CanvasWidth;
int32 y = ((*YArray)[i] - YMin) / (YMax - YMin) * CanvasHeight;
uint8 r = PawnBase->Plot3D->Points[i].Color.R;
uint8 g = PawnBase->Plot3D->Points[i].Color.G;
uint8 b = PawnBase->Plot3D->Points[i].Color.B;
if (PawnBase->Data->IsBrushed[i])
{
InitializeDrawingTools(1, 0, 0, 0);
DrawPixel(x, y, r/3, g/3, b/3, 255);
}
else
{
InitializeDrawingTools(1, PawnBase->Plot3D->Points[i].Color.R, PawnBase->Plot3D->Points[i].Color.G, PawnBase->Plot3D->Points[i].Color.B);
DrawPixel(x, y, r, g, b, 255);
}
DrawDot(((*XArray)[i] - XMin) / (XMax - XMin) * canvasWidth, ((*YArray)[i] - YMin) / (YMax - YMin) * canvasHeight);
}
UpdateCanvas();
......@@ -188,7 +165,7 @@ void UPlotCanvas::DrawHistogramPlot(int32 bins)
APawnBase* PawnBase = Cast<APawnBase>(Pawn);
float Diff = XMax - XMin;
float Thickness = canvasWidth / (float)bins;
float Thickness = CanvasWidth / (float)bins;
TArray<int32> XCount = TArray<int32>();
TArray<int32> XBrushedCount = TArray<int32>();
......@@ -223,12 +200,12 @@ void UPlotCanvas::DrawHistogramPlot(int32 bins)
int32 x1 = x0 + Thickness;
int32 y0 = 0;
int32 y1 = XCount[i] / (float)MaxCount * canvasHeight;
int32 y1 = XCount[i] / (float)MaxCount * CanvasHeight;
FVector ColorVec;
if (XBrushedCount[i] == XCount[i])
{
ColorVec = FVector(0, 0, 0);
ColorVec = PawnBase->Data->TransferFunction->GetVectorValue((i + 0.5) / (float)bins) / 3;
}
else
{
......@@ -266,17 +243,17 @@ void UPlotCanvas::DrawParallelCoordinatesPlot()
for (int i = 0; i < PawnBase->Plot3D->Points.Num(); ++i)
{
int32 x0 = 0;
int32 x1 = canvasWidth * 1 / 5;
int32 x2 = canvasWidth * 2 / 5;
int32 x3 = canvasWidth * 3 / 5;
int32 x4 = canvasWidth * 4 / 5;
int32 x5 = canvasWidth;
int32 x1 = CanvasWidth * 1 / 5;
int32 x2 = CanvasWidth * 2 / 5;
int32 x3 = CanvasWidth * 3 / 5;
int32 x4 = CanvasWidth * 4 / 5;
int32 x5 = CanvasWidth;
int32 y0;
float Diff = (PawnBase->Data->MaxX - PawnBase->Data->MinX);
if (Diff != 0)
{
y0 = (PawnBase->Data->X[i] - PawnBase->Data->MinX) / Diff * canvasHeight / 4;
y0 = (PawnBase->Data->X[i] - PawnBase->Data->MinX) / Diff * CanvasHeight / 4;
}
else
{
......@@ -287,7 +264,7 @@ void UPlotCanvas::DrawParallelCoordinatesPlot()
Diff = (PawnBase->Data->MaxY - PawnBase->Data->MinY);
if (Diff != 0)
{
y1 = (PawnBase->Data->Y[i] - PawnBase->Data->MinY) / Diff * canvasHeight / 4;
y1 = (PawnBase->Data->Y[i] - PawnBase->Data->MinY) / Diff * CanvasHeight / 4;
}
else
{
......@@ -298,7 +275,7 @@ void UPlotCanvas::DrawParallelCoordinatesPlot()
Diff = (PawnBase->Data->MaxZ - PawnBase->Data->MinZ);
if (Diff != 0)
{
y2 = (PawnBase->Data->Z[i] - PawnBase->Data->MinZ) / Diff * canvasHeight / 4;
y2 = (PawnBase->Data->Z[i] - PawnBase->Data->MinZ) / Diff * CanvasHeight / 4;
}
else
{
......@@ -309,7 +286,7 @@ void UPlotCanvas::DrawParallelCoordinatesPlot()
Diff = (PawnBase->Data->MaxU - PawnBase->Data->MinU);
if (Diff != 0)
{
y3 = (PawnBase->Data->U[i] - PawnBase->Data->MinU) / Diff * canvasHeight / 4;
y3 = (PawnBase->Data->U[i] - PawnBase->Data->MinU) / Diff * CanvasHeight / 4;
}
else
{
......@@ -320,7 +297,7 @@ void UPlotCanvas::DrawParallelCoordinatesPlot()
Diff = (PawnBase->Data->MaxV - PawnBase->Data->MinV);
if (Diff != 0)
{
y4 = (PawnBase->Data->V[i] - PawnBase->Data->MinV) / Diff * canvasHeight / 4;
y4 = (PawnBase->Data->V[i] - PawnBase->Data->MinV) / Diff * CanvasHeight / 4;
}
else
{
......@@ -331,7 +308,7 @@ void UPlotCanvas::DrawParallelCoordinatesPlot()
Diff = (PawnBase->Data->MaxW - PawnBase->Data->MinW);
if (Diff != 0)
{
y5 = (PawnBase->Data->W[i] - PawnBase->Data->MinW) / Diff * canvasHeight / 4;
y5 = (PawnBase->Data->W[i] - PawnBase->Data->MinW) / Diff * CanvasHeight / 4;
}
else
{
......@@ -362,57 +339,35 @@ void UPlotCanvas::DrawParallelCoordinatesPlot()
UpdateCanvas();
}
void UPlotCanvas::DrawDot(const int32 pixelCoordX, const int32 pixelCoordY)
{
uint8* canvasPixelPtr = canvasPixelData.get();
const uint8* canvasBrushPixelPtr = canvasBrushMask.get();
for (int px = -radius; px < radius; ++px)
{
for (int py = -radius; py < radius; ++py)
{
int32 tbx = px + radius;
int32 tby = py + radius;
canvasBrushPixelPtr = canvasBrushMask.get() + (tbx + tby * 2 * radius) * bytesPerPixel;
if (*(canvasBrushPixelPtr + 3) == 255) // check the alpha value of the pixel of the brush mask
{
int32 tx = pixelCoordX + px;
int32 ty = pixelCoordY + py;
DrawPixel(tx, ty, *(canvasBrushPixelPtr + 2), *(canvasBrushPixelPtr + 1), *(canvasBrushPixelPtr), *(canvasBrushPixelPtr + 3));
}
}
}
}
void UPlotCanvas::DrawPixel(const int32 x, const int32 y, const uint8 r, const uint8 g, const uint8 b, const uint8 a)
{
if (x >= 0 && x < canvasWidth && y >= 0 && y < canvasHeight)
if (x >= 0 && x < CanvasWidth && y >= 0 && y < CanvasHeight)
{
uint8* canvasPixelPtr = canvasPixelData.get() + (x + y * canvasWidth) * bytesPerPixel;
setPixelColor(canvasPixelPtr, r, g, b, a);
uint8* CanvasPixelPtr = CanvasPixelData.get() + (x + y * CanvasWidth) * BytesPerPixel;
SetPixelColor(CanvasPixelPtr, r, g, b, a);
}
}
void UPlotCanvas::ClearCanvas()
{
uint8* canvasPixelPtr = canvasPixelData.get();
for (int i = 0; i < canvasWidth * canvasHeight; ++i)
uint8* CanvasPixelPtr = CanvasPixelData.get();
for (int i = 0; i < CanvasWidth * CanvasHeight; ++i)
{
setPixelColor(canvasPixelPtr, 128, 128, 128, 0);
canvasPixelPtr += bytesPerPixel;
SetPixelColor(CanvasPixelPtr, 128, 128, 128, 0);
CanvasPixelPtr += BytesPerPixel;
}
UpdateCanvas();
}
void UPlotCanvas::UpdateCanvas()
{
if (echoUpdateTextureRegion)
if (EchoUpdateTextureRegion)
{
dynamicCanvas->UpdateTextureRegions((int32)0, (uint32)1, echoUpdateTextureRegion.get(), (uint32)bufferPitch, (uint32)bytesPerPixel, canvasPixelData.get());
DynamicCanvas->UpdateTextureRegions((int32)0, (uint32)1, EchoUpdateTextureRegion.get(), (uint32)BufferPitch, (uint32)BytesPerPixel, CanvasPixelData.get());
}
}
void UPlotCanvas::setPixelColor(uint8*& pointer, uint8 red, uint8 green, uint8 blue, uint8 alpha)
void UPlotCanvas::SetPixelColor(uint8*& pointer, uint8 red, uint8 green, uint8 blue, uint8 alpha)
{
*pointer = blue; //b
*(pointer + 1) = green; //g
......
......@@ -6,7 +6,7 @@
#include "UObject/NoExportTypes.h"
#include "Engine/Texture2D.h"
#include <memory>
#include "MyObject.h"
#include "SharedEnums.h"
#include "PlotCanvas.generated.h"
/**
......@@ -20,7 +20,7 @@ class IMMERSIVEANALYTICS_API UPlotCanvas : public UObject
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Variables)
UTexture2D* dynamicCanvas;
UTexture2D* DynamicCanvas;
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void SetXAxisType(EAxisType Type);
......@@ -40,9 +40,6 @@ public:
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void ClearCanvas();
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void InitializeDrawingTools(const int32 brushRadius, uint8 r, uint8 g, uint8 b);
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void DrawScatterPlot();
......@@ -52,19 +49,12 @@ public:
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void DrawParallelCoordinatesPlot();
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void DrawDot(const int32 pixelCoordX, const int32 pixelCoordY);
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void DrawPixel(const int32 x, const int32 y, const uint8 r, const uint8 g, const uint8 b, const uint8 a);
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void DrawLine(int32 x1, int32 y1, int32 x2, int32 y2, const uint8 r, const uint8 g, const uint8 b, const uint8 a);
void BrushPoints(TArray<int32> BrushPoints, bool Add, bool Rebuild);
void BrushPoint(int32 PointIndex, bool Add);
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void DrawRectangle(int32 x1, int32 y1, int32 x2, int32 y2, const uint8 r, const uint8 g, const uint8 b, const uint8 a);
......@@ -78,24 +68,16 @@ public:
float YMax;
private:
// canvas
std::unique_ptr<uint8[]> canvasPixelData;
int canvasWidth;
int canvasHeight;
int bytesPerPixel;
int bufferPitch;
int bufferSize;
// draw brush tool
std::unique_ptr<uint8[]> canvasBrushMask;
int radius;
int brushBufferSize;
std::unique_ptr<FUpdateTextureRegion2D> echoUpdateTextureRegion;
void setPixelColor(uint8*& pointer, uint8 red, uint8 green, uint8 blue, uint8 alpha);
std::unique_ptr<uint8[]> CanvasPixelData;
int CanvasWidth;
int CanvasHeight;
int BytesPerPixel;
int BufferPitch;
int BufferSize;
TArray<float>* XArray;
std::unique_ptr<FUpdateTextureRegion2D> EchoUpdateTextureRegion;
void SetPixelColor(uint8*& pointer, uint8 red, uint8 green, uint8 blue, uint8 alpha);
TArray<float>* XArray;
TArray<float>* YArray;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "PlotRenderTarget.h"
#include "PawnBase.h"
#include "Plot3D.h"
#include "Runtime/Engine/Classes/Engine/Canvas.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
UPlotRenderTarget::UPlotRenderTarget()
{
TScriptDelegate <FWeakObjectPtr> MyDelegate;
MyDelegate.BindUFunction(this, "OnUpdate");
OnCanvasRenderTargetUpdate.Add(MyDelegate);
}
void UPlotRenderTarget::OnUpdate(UCanvas * Canvas, int32 Width, int32 Height)
{
if (!MaterialDot)
{
return;
}
APawn* Pawn = UGameplayStatics::GetPlayerPawn(this, 0);
APawnBase* PawnBase = Cast<APawnBase>(Pawn);
/*
for (int i = 0; i < PawnBase->Plot3D->Points.Num(); ++i)
{
FVector2D Location = FVector2D(PawnBase->Plot3D->Points[i].Location.X * 10000 + Width / 2, PawnBase->Plot3D->U[i] * 5 + Height / 2);
FVector2D LocationB = Location + FVector2D(0, 1);
// Still not fast enough. Using other way to draw the graph.
FCanvasLineItem LineItem(Location, LocationB);
LineItem.LineThickness = 2;
LineItem.SetColor(FLinearColor(1, 1, 1));
LineItem.Draw(Canvas->Canvas);
//Canvas->K2_DrawBox(Location, FVector2D(10, 10), 5);
//Canvas->K2_DrawMaterial(MaterialDot, Location, FVector2D(10, 10), FVector2D(0, 0), FVector2D(1, 1), 0, FVector2D(0.5, 0.5));
//Canvas->K2_DrawLine(Location, LocationB, 2);
}*/
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/CanvasRenderTarget2D.h"
#include "PlotRenderTarget.generated.h"
/**
*
*/
UCLASS()
class IMMERSIVEANALYTICS_API UPlotRenderTarget : public UCanvasRenderTarget2D
{
GENERATED_BODY()
public:
UPlotRenderTarget();
UFUNCTION()
void OnUpdate(UCanvas* Canvas, int32 Width, int32 Height);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Default)
UMaterialInterface* MaterialDot;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyObject.h"
#include "SharedEnums.h"
......@@ -4,7 +4,7 @@
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "MyObject.generated.h"
#include "SharedEnums.generated.h"
UENUM(BlueprintType) //"BlueprintType" is essential to include
enum class EAxisType : uint8
......@@ -16,7 +16,7 @@ enum class EAxisType : uint8
*
*/
UCLASS()
class IMMERSIVEANALYTICS_API UMyObject : public UObject
class IMMERSIVEANALYTICS_API USharedEnums : public UObject
{
GENERATED_BODY()
......
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