Skip to content

Commit

Permalink
UE naming standard, cross-compatibility stable (linux tested)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmilke committed Nov 10, 2023
1 parent 319b039 commit f9cac8c
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 86 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Intermediate/*

# ignore vtk library folder except the UE build script
Temporary
Source/ThirdParty/VTKLibrary/*
!Source/ThirdParty/VTKLibrary/VTKLibrary.Build.cs
Source/ThirdParty/VtkLibrary/*
!Source/ThirdParty/VtkLibrary/VtkLibrary.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.IO;
using UnrealBuildTool;

public class VTKLibrary : ModuleRules
public class VtkLibrary : ModuleRules
{
public VTKLibrary(ReadOnlyTargetRules Target) : base(Target)
public VtkLibrary(ReadOnlyTargetRules Target) : base(Target)
{
Type = ModuleType.External;

Expand All @@ -23,7 +23,7 @@ public VTKLibrary(ReadOnlyTargetRules Target) : base(Target)
var dllSearchPath = Path.Combine(ModuleDirectory, BuildDir, "bin");

if (!Directory.Exists(libSearchPath) || !Directory.Exists(dllSearchPath))
Console.WriteLine("Did not find lib- or dll-path for VTKLibrary!");
Console.WriteLine("Did not find lib- or dll-path for VtkLibrary!");

// Libs
foreach (var libPath in Directory.EnumerateFiles(libSearchPath, "*.lib" , SearchOption.AllDirectories))
Expand All @@ -40,7 +40,7 @@ public VTKLibrary(ReadOnlyTargetRules Target) : base(Target)

// TODO: Investigate why we can't delayload VTK like this on Windows, uncomment if fix is found
// This prevents the dlls to be auto-loaded when the plugin is read
// and allows us to load them later in VTKPlugin.cpp during StartupModule.
// and allows us to load them later in VtkPlugin.cpp during StartupModule.
// That allows us to load dlls from specific paths, which is not (easily) possible otherwise on Windows.
//PublicDelayLoadDLLs.Add(dllName);
//RuntimeDependencies.Add(srcPath);
Expand All @@ -55,13 +55,13 @@ public VTKLibrary(ReadOnlyTargetRules Target) : base(Target)
var dylibSearchPath = Path.Combine(ModuleDirectory, "Mac", BuildDir, "lib");

if (!Directory.Exists(dylibSearchPath))
Console.WriteLine("Did not find dylib-path for VTKLibrary!");
Console.WriteLine("Did not find dylib-path for VtkLibrary!");

// DyLibs
foreach (var filePath in Directory.EnumerateFiles(dylibSearchPath, "*.dylib" , SearchOption.AllDirectories))
{
var dylibName = Path.GetFileName(filePath);
var dylibPath = Path.Combine("$(ModuleDir)", "Mac", BuildDir, "bin", dylibName);
var dylibPath = Path.Combine("$(ModuleDir)", "Mac", BuildDir, "lib", dylibName);

PublicDelayLoadDLLs.Add(dylibPath);
RuntimeDependencies.Add(dylibPath);
Expand All @@ -72,13 +72,13 @@ public VTKLibrary(ReadOnlyTargetRules Target) : base(Target)
var soSearchPath = Path.Combine(ModuleDirectory, "Linux", BuildDir, "lib");

if (!Directory.Exists(soSearchPath))
Console.WriteLine("Did not find so-path for VTKLibrary!");
Console.WriteLine("Did not find so-path for VtkLibrary!");

// SOs
foreach (var filePath in Directory.EnumerateFiles(soSearchPath, "*.so" , SearchOption.AllDirectories))
{
var soName = Path.GetFileName(filePath);
var soPath = Path.Combine("$(ModuleDir)", "Linux", BuildDir, "bin", soName);
var soPath = Path.Combine("$(ModuleDir)", "Linux", BuildDir, "lib", soName);

PublicAdditionalLibraries.Add(soPath);
PublicDelayLoadDLLs.Add(soPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "VTKFunctionLibrary.h"
#include "VtkFunctionLibrary.h"

THIRD_PARTY_INCLUDES_START
// DistanceBetweenTwoPoins example
#include "vtkMath.h"

#if PLATFORM_WINDOWS
// StructuredGridReader example
#include "vtkNamedColors.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkStructuredGridGeometryFilter.h"
#include "vtkXMLStructuredGridReader.h"
#include "vtk-9.3/vtkStructuredGrid.h"
#include "vtkStructuredGrid.h"
#endif
THIRD_PARTY_INCLUDES_END

float UVTKFunctionLibrary::DistanceBetweenTwoPoints(const FVector3f& P0, const FVector3f& P1)
float UVtkFunctionLibrary::DistanceBetweenTwoPoints(const FVector3f& P0, const FVector3f& P1)
{
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] VTK Example: Distance Between Two Points"));
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] P0: (%f, %f, %f), P1: (%f, %f, %f)"),
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] VTK Example: Distance Between Two Points"));
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] P0: (%f, %f, %f), P1: (%f, %f, %f)"),
P0.X, P0.Y, P0.Z, P1.X, P1.Y, P1.Z);

// Create two vtk compatible points.
Expand All @@ -31,22 +35,23 @@ float UVTKFunctionLibrary::DistanceBetweenTwoPoints(const FVector3f& P0, const F
const double distance = std::sqrt(squaredDistance);

// Output the results.
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] SquaredDistance = %f"), squaredDistance);
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Distance = %f"), distance);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] SquaredDistance = %f"), squaredDistance);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Distance = %f"), distance);

// Return the Euclidean distance.
return distance;
}

bool UVTKFunctionLibrary::ReadStructuredGridTest(const FString& Filepath)
bool UVtkFunctionLibrary::ReadStructuredGridTest(const FString& Filepath)
{
#if PLATFORM_WINDOWS
const FString CleanFilepath = Filepath.TrimQuotes();
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] VTK Example: Read Structured Grid"));
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Reading structured grid: %s"), *CleanFilepath);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] VTK Example: Read Structured Grid"));
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Reading structured grid: %s"), *CleanFilepath);

if (!FPaths::FileExists(CleanFilepath))
{
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] File does not exist: %s"), *CleanFilepath);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] File does not exist: %s"), *CleanFilepath);
return false;
}

Expand All @@ -57,7 +62,7 @@ bool UVTKFunctionLibrary::ReadStructuredGridTest(const FString& Filepath)

if (reader->CheckAbort())
{
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] VTK encountered a problem"));
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] VTK encountered a problem"));
return false;
}

Expand All @@ -70,11 +75,15 @@ bool UVTKFunctionLibrary::ReadStructuredGridTest(const FString& Filepath)
structuredGrid->GetDimensions(gridDims);
structuredGrid->GetCellDims(cellDims);

UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Data dimension: %d"), dataDim);
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Grid Extents: (%d, %d, %d)"), gridDims[0], gridDims[1], gridDims[2]);
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Cell Extents: (%d, %d, %d)"), cellDims[0], cellDims[1], cellDims[2]);
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Number Points: %d"), numPoints);
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Data Cells: %d"), numCells);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Data dimension: %d"), dataDim);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Grid Extents: (%d, %d, %d)"), gridDims[0], gridDims[1], gridDims[2]);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Cell Extents: (%d, %d, %d)"), cellDims[0], cellDims[1], cellDims[2]);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Number Points: %d"), numPoints);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Data Cells: %d"), numCells);

return true;
#else
UE_LOG(LogTemp, Error, TEXT("[VtkPlugin] The ReadStructuredGridTest example is not yet implemented on Unix-based systems because of missing RTTI support."));
return false;
#endif
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#include "VTKPlugin.h"
#include "VtkPlugin.h"
#include "Modules/ModuleManager.h"
#include "Interfaces/IPluginManager.h"

#include "Misc/Paths.h"
#include "HAL/PlatformProcess.h"

#define LOCTEXT_NAMESPACE "FVTKPluginModule"
#define LOCTEXT_NAMESPACE "FVtkPluginModule"

void FVTKPluginModule::StartupModule()
void FVtkPluginModule::StartupModule()
{
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Delay-loading VTK module..."));
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Delay-loading VTK module..."));

#if PLATFORM_WINDOWS
// VTK will throw an exception when the library is delay-loaded in Windows.
// The exception happens before this codeblock triggers and may originate in vtk.
// TODO: fix delay-loading for windows

UE_LOG(LogTemp, Error, TEXT("[VTKPlugin] VTK is currently NOT delayloaded on Windows, as this causes UE to crash (dlls are available directly at runtime)."));
UE_LOG(LogTemp, Error, TEXT("[VtkPlugin] VTK is currently NOT delayloaded on Windows, as this causes UE to crash (dlls are available directly at runtime)."));
#else
LoadDLLs();
#endif

UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] %d VTK libraries delay-loaded!"), DynamicLinkLibraryHandles.Num());
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] %d VTK libraries delay-loaded!"), DynamicLinkLibraryHandles.Num());
}



void FVTKPluginModule::ShutdownModule()
void FVtkPluginModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
Expand All @@ -43,25 +43,25 @@ void FVTKPluginModule::ShutdownModule()
// If you know a fix or want to do it anyway, remove the platform check.
// TODO: fix unloading for windows

UE_LOG(LogTemp, Error, TEXT("[VTKPlugin] Not freeing dlls on Windows because dlls are not delay-loaded & this additionally generates a crash on shutdown (with debugger attached)."));
UE_LOG(LogTemp, Error, TEXT("[VtkPlugin] Not freeing dlls on Windows because dlls are not delay-loaded & this additionally generates a crash on shutdown (with debugger attached)."));
#else
UnloadDLLs();
#endif
}

bool FVTKPluginModule::SupportsDynamicReloading()
bool FVtkPluginModule::SupportsDynamicReloading()
{
#if PLATFORM_WINDOWS
UE_LOG(LogTemp, Error, TEXT("[VTKPlugin] VTK currently does NOT support dynamic reloading on Windows, because handles can't be freed."));
UE_LOG(LogTemp, Error, TEXT("[VtkPlugin] VTK currently does NOT support dynamic reloading on Windows, because handles can't be freed."));
return false;
#else
return true;
#endif
}

FString FVTKPluginModule::GetVTKBinariesDir()
FString FVtkPluginModule::GetVTKBinariesDir()
{
auto Plugin = IPluginManager::Get().FindPlugin("VTKPlugin");
auto Plugin = IPluginManager::Get().FindPlugin("VtkPlugin");
FString BaseDir = Plugin->GetBaseDir();

// If you want to load a debug or release build based on UE build, specify here
Expand All @@ -73,25 +73,25 @@ FString FVTKPluginModule::GetVTKBinariesDir()


#if PLATFORM_WINDOWS
//FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/VTKLibrary/Win64"));
FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/VTKLibrary"), *BuildDir, "bin");
//FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/VtkLibrary/Win64"));
FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/VtkLibrary"), *BuildDir, "bin");
#elif PLATFORM_LINUX
//FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/VTKLibrary/Linux"));
FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/VTKLibrary/Linux"), *BuildDir, "bin");
//FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/VtkLibrary/Linux"));
FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/VtkLibrary/Linux"), *BuildDir, "lib");
#elif PLATFORM_MAC
//FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/VTKLibrary/Mac"));
FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/VTKLibrary/Mac"), *BuildDir, "bin");
//FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/VtkLibrary/Mac"));
FString BinariesDir = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/VtkLibrary/Mac"), *BuildDir, "lib");
#endif

if (!FPaths::DirectoryExists(BinariesDir))
{
UE_LOG(LogTemp, Error, TEXT("[VTKPlugin] VTK Binaries directory does not exist: %s"), *BinariesDir);
UE_LOG(LogTemp, Error, TEXT("[VtkPlugin] VTK Binaries directory does not exist: %s"), *BinariesDir);
}

return BinariesDir;
}

FString FVTKPluginModule::GetExtensionFilter()
FString FVtkPluginModule::GetExtensionFilter()
{
#if PLATFORM_WINDOWS
return "dll";
Expand All @@ -102,7 +102,7 @@ FString FVTKPluginModule::GetExtensionFilter()
#endif
}

void FVTKPluginModule::LoadDLLs()
void FVtkPluginModule::LoadDLLs()
{
const FString VTKBinariesDir = GetVTKBinariesDir();
const FString ExtFilter = GetExtensionFilter();
Expand All @@ -127,7 +127,7 @@ void FVTKPluginModule::LoadDLLs()

if (FilesSkipped.Contains(Filename))
{
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Skipped %s because it is not delay-loaded."), *Filename);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Skipped %s because it is not delay-loaded."), *Filename);
continue;
}

Expand All @@ -141,11 +141,11 @@ void FVTKPluginModule::LoadDLLs()
DynamicLinkLibraryHandles.Add(Dll);
DynamicLinkLibraryNames.Add(Filename);
FilesAdded.Add(File);
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Delay-loaded %d/%d dlls: %s"), DynamicLinkLibraryHandles.Num(), Files.Num() - FilesSkipped.Num(), *Filename);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Delay-loaded %d/%d dlls: %s"), DynamicLinkLibraryHandles.Num(), Files.Num() - FilesSkipped.Num(), *Filename);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Delay-loading didn't work, retrying again"));
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Delay-loading didn't work, retrying again"));
}
}

Expand All @@ -155,14 +155,14 @@ void FVTKPluginModule::LoadDLLs()
}
}

void FVTKPluginModule::UnloadDLLs()
void FVtkPluginModule::UnloadDLLs()
{
for (auto Idx = DynamicLinkLibraryHandles.Num() - 1; Idx >= 0; Idx--)
{
auto& LibraryHandle = DynamicLinkLibraryHandles[Idx];
auto& LibraryName = DynamicLinkLibraryNames[Idx];

UE_LOG(LogTemp, Warning, TEXT("[VTKPlugin] Freeing dll: %s"), *LibraryName);
UE_LOG(LogTemp, Warning, TEXT("[VtkPlugin] Freeing dll: %s"), *LibraryName);
FPlatformProcess::FreeDllHandle(LibraryHandle);
}

Expand All @@ -172,4 +172,4 @@ void FVTKPluginModule::UnloadDLLs()

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FVTKPluginModule, VTKPlugin)
IMPLEMENT_MODULE(FVtkPluginModule, VtkPlugin)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "VTKFunctionLibrary.generated.h"
#include "VtkFunctionLibrary.generated.h"

/**
*
*/
UCLASS()
class VTKPLUGIN_API UVTKFunctionLibrary : public UBlueprintFunctionLibrary
class VTKPLUGIN_API UVtkFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "Modules/ModuleManager.h"

class FVTKPluginModule : public IModuleInterface
class FVtkPluginModule : public IModuleInterface
{
public:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

using UnrealBuildTool;

public class VTKPlugin : ModuleRules
public class VtkPlugin : ModuleRules
{
public VTKPlugin(ReadOnlyTargetRules Target) : base(Target)
public VtkPlugin(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

Expand All @@ -26,7 +26,7 @@ public VTKPlugin(ReadOnlyTargetRules Target) : base(Target)
new string[]
{
"Core",
"VTKLibrary",
"VtkLibrary",
"Projects",
// ... add other public dependencies that you statically link with here ...

Expand All @@ -43,8 +43,8 @@ public VTKPlugin(ReadOnlyTargetRules Target) : base(Target)
"CoreUObject",
"Engine",

// (as said above, the VTKLibrary module should better be defined here)
//"VTKLibrary",
// (as said above, the VtkLibrary module should better be defined here)
//"VtkLibrary",
}
);

Expand Down
4 changes: 2 additions & 2 deletions VTKPlugin.uplugin → VtkPlugin.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"FileVersion" : 3,
"Version" : 1,
"VersionName" : "1.0",
"FriendlyName" : "VTKPlugin",
"FriendlyName" : "VTK Plugin",
"Description" : "A plugin that links & exposes VTK to Unreal Engine.",
"Category" : "Other",
"CreatedBy" : "acdemiralp (RWTH Aachen, VR Group)",
Expand All @@ -17,7 +17,7 @@
"Modules":
[
{
"Name" : "VTKPlugin",
"Name" : "VtkPlugin",
"Type" : "Runtime" ,
"LoadingPhase": "Default"
}
Expand Down
Loading

0 comments on commit f9cac8c

Please sign in to comment.