NAP
Namespaces | Classes | Typedefs | Enumerations | Functions
nap::utility Namespace Reference

Namespaces

 path
 

Classes

class  AutoResetEvent
 
class  ErrorState
 
class  MemoryStream
 
class  UniquePtrConstMapWrapper
 
class  UniquePtrConstVectorWrapper
 
class  UniquePtrMapIterator
 
class  UniquePtrMapWrapper
 
class  UniquePtrVectorIterator
 
class  UniquePtrVectorWrapper
 

Typedefs

using MeshConnectivityMap = std::vector< std::vector< Triangle > >
 

Enumerations

enum  ETextOrientation : int { Left = 0, Center = 1, Right = 2 }
 

Functions

bool NAPAPI createSignature (const std::string &privkey, const std::string &message, ESigningScheme scheme, std::string &outSignature)
 
bool NAPAPI verifyMessage (const std::string &pubkey, const std::string &message, ESigningScheme scheme, const std::string &signature)
 
bool NAPAPI generateRSAKey (unsigned int bits, std::string &outPrivKey, std::string &outPubKey)
 
std::string NAPAPI sha256 (const std::string &str)
 Generate a SHA256 hash of a string. More...
 
std::string NAPAPI encode64 (const std::string &str)
 Encode a string to base64. More...
 
std::string NAPAPI decode64 (const std::string &str)
 Decode a base64 string. More...
 
bool NAPAPI isTriangleMesh (const nap::MeshInstance &meshInstance)
 
int NAPAPI getTriangleCount (const MeshInstance &meshInstance)
 
glm::vec3 NAPAPI computeTriangleNormal (const TriangleData< glm::vec3 > &vertices)
 
void NAPAPI setTriangleIndices (nap::MeshShape &mesh, EDrawMode drawMode, int number, const std::array< int, 3 > &indices)
 
template<typename T >
void computeBoundingBox (const MeshInstance &mesh, math::Box &outBox)
 
template<typename T >
void computeBoundingBox (const nap::MeshInstance &mesh, const nap::MeshShape &shape, math::Box &outBox)
 
void NAPAPI computeNormals (const nap::MeshInstance &mesh, const nap::VertexAttribute< glm::vec3 > &vertices, nap::VertexAttribute< glm::vec3 > &outNormals)
 
void NAPAPI reverseWindingOrder (nap::MeshInstance &mesh)
 
void NAPAPI generateIndices (nap::MeshShape &shape, int vertexCount, bool loop=false, int offset=0)
 
void NAPAPI computeConnectivity (const nap::MeshInstance &mesh, MeshConnectivityMap &outConnectivityMap)
 
float NAPAPI computeTriangleArea (const TriangleData< glm::vec3 > &vertices)
 
float NAPAPI computeArea (nap::MeshInstance &mesh, const nap::VertexAttribute< glm::vec3 > &vertices, std::vector< float > &outList)
 
bool NAPAPI intersect (const glm::vec3 &rayOrigin, const glm::vec3 &rayDirection, const TriangleData< glm::vec3 > &vertices, glm::vec3 &outCoordinates)
 
glm::vec3 NAPAPI computeBarycentric (const glm::vec3 &point, const TriangleData< glm::vec3 > &triangle)
 
template<typename T >
interpolateVertexAttr (const TriangleData< T > &vertexValues, const glm::vec3 &barycentricCoordinates)
 
bool NAPAPI createRenderPass (VkDevice device, VkFormat colorFormat, VkFormat depthFormat, VkSampleCountFlagBits samples, VkImageLayout targetLayout, bool consumeDepth, VkRenderPass &renderPass, utility::ErrorState &errorState)
 
bool NAPAPI createRenderPass (VkDevice device, VkFormat colorFormat, VkFormat depthFormat, VkSampleCountFlagBits samples, VkImageLayout targetLayout, VkRenderPass &renderPass, utility::ErrorState &errorState)
 
bool NAPAPI createDepthOnlyRenderPass (VkDevice device, VkFormat depthFormat, VkRenderPass &renderPass, utility::ErrorState &errorState)
 
bool NAPAPI create2DImage (VmaAllocator allocator, uint32 width, uint32 height, VkFormat format, uint32 mipLevels, VkSampleCountFlagBits samples, VkImageTiling tiling, VkImageUsageFlags imageUsage, VmaMemoryUsage memoryUsage, VkImage &outImage, VmaAllocation &outAllocation, VmaAllocationInfo &outAllocationInfo, utility::ErrorState &errorState)
 
bool NAPAPI create2DImageView (VkDevice device, VkImage image, VkFormat format, uint32 mipLevels, VkImageAspectFlags aspectFlags, VkImageView &outImageView, utility::ErrorState &errorState)
 
bool NAPAPI createLayered2DImage (VmaAllocator allocator, uint32 width, uint32 height, VkFormat format, uint32 mipLevels, uint32 layerCount, VkSampleCountFlagBits samples, VkImageTiling tiling, VkImageUsageFlags imageUsage, VmaMemoryUsage memoryUsage, VkImageCreateFlags flags, VkImage &outImage, VmaAllocation &outAllocation, VmaAllocationInfo &outAllocationInfo, utility::ErrorState &errorState)
 
bool NAPAPI createLayered2DImageView (VkDevice device, VkImage image, VkFormat format, uint32 mipLevels, VkImageAspectFlags aspectFlags, uint32 layerIndex, uint32 layerCount, VkImageView &outImageView, utility::ErrorState &errorState)
 
bool NAPAPI createCubeImageView (VkDevice device, VkImage image, VkFormat format, uint32 mipLevels, VkImageAspectFlags aspectFlags, uint32 layerCount, VkImageView &outImageView, utility::ErrorState &errorState)
 
void NAPAPI destroyImageAndView (ImageData &data, VkDevice device, VmaAllocator allocator)
 
bool NAPAPI createBuffer (VmaAllocator allocator, uint32 size, VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags allocationFlags, BufferData &outBuffer, utility::ErrorState &error)
 
void NAPAPI destroyBuffer (VmaAllocator allocator, BufferData &buffer)
 
bool NAPAPI uploadToBuffer (VmaAllocator allocator, uint32 size, const void *data, BufferData &buffer)
 
VkFormat NAPAPI getTextureFormat (ESurfaceDataType dataType, ESurfaceChannels channels, EColorSpace colorSpace)
 
VkFormat NAPAPI getTextureFormat (const SurfaceDescriptor &descriptor)
 
void NAPAPI transitionImageLayout (VkCommandBuffer commandBuffer, VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkPipelineStageFlags srcStage, VkPipelineStageFlags dstStage, uint mipLevel, uint mipLevelCount, VkImageAspectFlags aspect)
 
void NAPAPI transitionImageLayout (VkCommandBuffer commandBuffer, VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkPipelineStageFlags srcStage, VkPipelineStageFlags dstStage, uint mipLevel, uint mipLevelCount, uint layer, uint layerCount, VkImageAspectFlags aspect)
 
void NAPAPI createMipmaps (VkCommandBuffer buffer, VkImage image, VkFormat imageFormat, VkImageLayout targetLayout, VkImageAspectFlags aspect, uint32 texWidth, uint32 texHeight, uint32 mipLevels)
 
void NAPAPI createMipmaps (VkCommandBuffer buffer, VkImage image, VkFormat imageFormat, VkImageLayout targetLayout, VkImageAspectFlags aspect, uint32 texWidth, uint32 texHeight, uint32 mipLevels, uint layer, uint layerCount)
 
void NAPAPI blit (VkCommandBuffer commandBuffer, const Texture2D &srcTexture, const Texture2D &dstTexture)
 
bool listDir (const char *directory, std::vector< std::string > &outFilenames, bool absolute=true)
 
bool isAbsolutePath (const std::string &path)
 
std::string getAbsolutePath (const std::string &relPath)
 
std::string getFileExtension (const std::string &filename)
 
std::string getFileName (const std::string &file)
 
std::string getFileDir (const std::string &file)
 
std::string getFileNameWithoutExtension (const std::string &file)
 
void stripFileExtension (std::string &file)
 
std::string stripFileExtension (const std::string &file)
 
std::string appendFileExtension (const std::string &file, const std::string &ext)
 
bool hasExtension (const std::string &file, const std::string &extension)
 
bool fileExists (const std::string &filename)
 
bool dirExists (const std::string &dirName)
 
bool ensureDirExists (const std::string &dirName)
 
bool makeDirs (const std::string &directory)
 
bool deleteFile (const std::string &path)
 
void writeStringToFile (const std::string &filename, const std::string &contents)
 
std::string toComparableFilename (const std::string &filename)
 
bool isFilenameEqual (const std::string &filenameA, const std::string &filenameB)
 
bool getFileModificationTime (const std::string &path, uint64_t &modTime)
 
std::string getExecutablePath ()
 
std::string getExecutableDir ()
 
bool changeDir (const std::string &newDir)
 
std::string getCWD ()
 
bool readFileToString (const std::string &filename, std::string &outBuffer, utility::ErrorState &err)
 
std::string findFileInDirectories (const std::string &filename, const std::vector< std::string > &dirs)
 
std::string joinPath (const std::vector< std::string > &parts)
 
std::string forceSeparator (const std::string &path)
 
void splitString (const std::string &string, const char delim, std::vector< std::string > &ioParts)
 
std::vector< std::string > splitString (const std::string &string, const char delim)
 
template<typename T >
std::string joinString (const T &list, const char *delim)
 
void writeString (std::ostream &stream, const std::string &text)
 
std::string readString (std::istream &stream)
 
void toLower (std::string &ioString)
 
std::string toLower (const std::string &string)
 
void toUpper (std::string &ioString)
 
std::string toUpper (const std::string &string)
 
std::string stripNamespace (const std::string &str)
 
void tokenize (const std::string &str, std::list< std::string > &tokens, const std::string &delims, bool omitTokens=false)
 
bool startsWith (const std::string &string, const std::string &subString, bool caseSensitive=true)
 
bool endsWith (const std::string &string, const std::string &subString, bool caseSensitive=true)
 
bool contains (const std::string &string, const std::string &subString, bool caseSensitive=true)
 
std::string trim (const std::string &string)
 
std::string lTrim (const std::string &string)
 
std::string rTrim (const std::string &string)
 
template<typename T >
std::string addresStr (T thing)
 
void namedFormat (std::string &subject, const std::unordered_map< std::string, std::string > &rep)
 
void namedFormat (std::vector< std::string > &subjects, const std::unordered_map< std::string, std::string > &rep)
 
std::string replaceTemplateType (const std::string &typeName, const std::string &templateTypeName)
 
void replaceAllInstances (std::string &inString, const std::string &find, const std::string &replace)
 
std::string replaceAllInstances (const std::string &inString, const std::string &find, const std::string &replace)
 
int getLine (const std::string &buffer, size_t offset)
 
template<typename... Args>
std::string stringFormat (const char *format, Args &&... args)
 

Detailed Description

String utilities not offered by std::string

Typedef Documentation

◆ MeshConnectivityMap

using MeshConnectivityMap = std::vector<std::vector<Triangle> >

Enumeration Type Documentation

◆ ETextOrientation

enum ETextOrientation : int
strong

Controls the horizontal text draw orientation, vertical alignment is based on the character origin line This enum is serializable and can be used as a property

Enumerator
Left 

Draws text to the right of the horizontal coordinate.

Center 

Centers the text around the horizontal coordinate.

Right 

Draws the text to the left of the horizontal coordinate.

Function Documentation

◆ addresStr()

std::string addresStr ( thing)

Converts T in to a string using an std stringstream.

Parameters
thingthe object to convert into a string
Returns
the object as a string

◆ appendFileExtension()

std::string nap::utility::appendFileExtension ( const std::string &  file,
const std::string &  ext 
)
Returns
file with appended extension
Parameters
filethe file to add extension to
extextension without preceding '.'

◆ blit()

void NAPAPI nap::utility::blit ( VkCommandBuffer  commandBuffer,
const Texture2D srcTexture,
const Texture2D dstTexture 
)

Pushes a full-size blit to the command buffer. Must be called inside a render pass, in onDraw(). Assumes a color texture without mip-maps. The layouts of srcTexture and dstTexture are transferred to SHADER_READ after the blit operation.

Parameters
commandBufferthe command buffer to push the blit operation to
srcTexturethe source texture
dstTexturethe destination texture

◆ changeDir()

bool nap::utility::changeDir ( const std::string &  newDir)

Change current working directory

Parameters
newDirThe working directory to change to
Returns
if working directory changed

◆ computeArea()

float NAPAPI nap::utility::computeArea ( nap::MeshInstance mesh,
const nap::VertexAttribute< glm::vec3 > &  vertices,
std::vector< float > &  outList 
)

Computes the area of every triangle in the mesh and stores the results in outList. The total is returned This call assumes the mesh has position vertex attribute data!

Parameters
meshthe mesh that contains the triangles
verticesthe mesh vertex positions
outLista vector that contains the individual area of every triangle in the mesh
Returns
the total area of the mesh

◆ computeBarycentric()

glm::vec3 NAPAPI nap::utility::computeBarycentric ( const glm::vec3 &  point,
const TriangleData< glm::vec3 > &  triangle 
)

Computes the barycentric coordinates for a point with respect to a triangle

Parameters
pointthe position of the point in respect to the triangle
trianglethe vertices of the triangle

◆ computeBoundingBox() [1/2]

void computeBoundingBox ( const MeshInstance mesh,
math::Box outBox 
)

Computes the bounding box of a mesh using its associated position data. Note that indices are not considered. This call loops over all available points regardless of whether if they're drawn or not

Template Parameters
thedata type of the position attribute
Parameters
meshthe mesh to get the bounding box for
outBoxthe computed bounding box

◆ computeBoundingBox() [2/2]

void computeBoundingBox ( const nap::MeshInstance mesh,
const nap::MeshShape shape,
math::Box outBox 
)

Computes the bounding box of a single shape within a mesh using its associated position data. Note that the given shape must be part of the mesh.

Template Parameters
thedata type of the position attribute
Parameters
meshthe mesh that contains position data
shapethe shape to compute the bounding box for
outBoxthe computed bounding box

◆ computeConnectivity()

void NAPAPI nap::utility::computeConnectivity ( const nap::MeshInstance mesh,
MeshConnectivityMap outConnectivityMap 
)

Builds a 'map' that binds points (mesh index values) to faces The index in the array corresponds to a mesh vertex index (point). This call only works for meshes that have indices. When the mesh does not have indices this call asserts Try to avoid building the map regularly, it's a heavy operation This call asserts when the mesh is not a triangular mesh or has no indices associated with it

Parameters
meshthe mesh to get build the array from
outConnectivityMapthe array that is populated with the triangles associated with a single index

◆ computeNormals()

void NAPAPI nap::utility::computeNormals ( const nap::MeshInstance mesh,
const nap::VertexAttribute< glm::vec3 > &  vertices,
nap::VertexAttribute< glm::vec3 > &  outNormals 
)

Automatically re-computes all the normals of a mesh When the mesh has indices the normal is computed based on connectivity Meshes without indices receive the triangular face normal

Parameters
meshthe triangular mesh
verticesthe vertex position attribute
outNormalsthe recomputed normals, the normals have to be initialized and of the same length as the vertices

◆ computeTriangleArea()

float NAPAPI nap::utility::computeTriangleArea ( const TriangleData< glm::vec3 > &  vertices)
Parameters
verticesthe triangle vertex position data
Returns
the area of a triangle

◆ computeTriangleNormal()

glm::vec3 NAPAPI nap::utility::computeTriangleNormal ( const TriangleData< glm::vec3 > &  vertices)

Computes the normal that is associated with a triangular face. The normal is weighted (not normalized) This call asserts when the index is out of bounds.

Parameters
verticesmesh vertices
Returns
the weighted (not normalized) normal associated with a face

◆ contains()

bool nap::utility::contains ( const std::string &  string,
const std::string &  subString,
bool  caseSensitive = true 
)

Checks if subString is present in string

Parameters
stringthe full string that could contain substring
subStringpart of the string that could be present in string
caseSensitiveif the lookup is case sensitive or not
Returns
if string contains subString

◆ create2DImage()

bool NAPAPI nap::utility::create2DImage ( VmaAllocator  allocator,
uint32  width,
uint32  height,
VkFormat  format,
uint32  mipLevels,
VkSampleCountFlagBits  samples,
VkImageTiling  tiling,
VkImageUsageFlags  imageUsage,
VmaMemoryUsage  memoryUsage,
VkImage &  outImage,
VmaAllocation &  outAllocation,
VmaAllocationInfo &  outAllocationInfo,
utility::ErrorState errorState 
)

Creates a Vulkan image based on the described image usage and given properties.

◆ create2DImageView()

bool NAPAPI nap::utility::create2DImageView ( VkDevice  device,
VkImage  image,
VkFormat  format,
uint32  mipLevels,
VkImageAspectFlags  aspectFlags,
VkImageView &  outImageView,
utility::ErrorState errorState 
)

Creates a Vulkan image view based on the described image usage and given properties.

◆ createBuffer()

bool NAPAPI nap::utility::createBuffer ( VmaAllocator  allocator,
uint32  size,
VkBufferUsageFlags  bufferUsage,
VmaMemoryUsage  memoryUsage,
VmaAllocationCreateFlags  allocationFlags,
BufferData outBuffer,
utility::ErrorState error 
)

Creates a Vulkan buffer

◆ createCubeImageView()

bool NAPAPI nap::utility::createCubeImageView ( VkDevice  device,
VkImage  image,
VkFormat  format,
uint32  mipLevels,
VkImageAspectFlags  aspectFlags,
uint32  layerCount,
VkImageView &  outImageView,
utility::ErrorState errorState 
)

Creates a Vulkan cube image view based on the described image usage and given properties.

◆ createDepthOnlyRenderPass()

bool NAPAPI nap::utility::createDepthOnlyRenderPass ( VkDevice  device,
VkFormat  depthFormat,
VkRenderPass &  renderPass,
utility::ErrorState errorState 
)

Creates a single or multi-sample depth-only renderpass based depth format.

◆ createLayered2DImage()

bool NAPAPI nap::utility::createLayered2DImage ( VmaAllocator  allocator,
uint32  width,
uint32  height,
VkFormat  format,
uint32  mipLevels,
uint32  layerCount,
VkSampleCountFlagBits  samples,
VkImageTiling  tiling,
VkImageUsageFlags  imageUsage,
VmaMemoryUsage  memoryUsage,
VkImageCreateFlags  flags,
VkImage &  outImage,
VmaAllocation &  outAllocation,
VmaAllocationInfo &  outAllocationInfo,
utility::ErrorState errorState 
)

Creates a Vulkan layered image based on the described image usage and given properties.

◆ createLayered2DImageView()

bool NAPAPI nap::utility::createLayered2DImageView ( VkDevice  device,
VkImage  image,
VkFormat  format,
uint32  mipLevels,
VkImageAspectFlags  aspectFlags,
uint32  layerIndex,
uint32  layerCount,
VkImageView &  outImageView,
utility::ErrorState errorState 
)

Creates a Vulkan layered image view based on the described image usage and given properties.

◆ createMipmaps() [1/2]

void NAPAPI nap::utility::createMipmaps ( VkCommandBuffer  buffer,
VkImage  image,
VkFormat  imageFormat,
VkImageLayout  targetLayout,
VkImageAspectFlags  aspect,
uint32  texWidth,
uint32  texHeight,
uint32  mipLevels 
)

Creates mip maps for the specified Vulkan image.

◆ createMipmaps() [2/2]

void NAPAPI nap::utility::createMipmaps ( VkCommandBuffer  buffer,
VkImage  image,
VkFormat  imageFormat,
VkImageLayout  targetLayout,
VkImageAspectFlags  aspect,
uint32  texWidth,
uint32  texHeight,
uint32  mipLevels,
uint  layer,
uint  layerCount 
)

Creates mip maps for the specified Vulkan image.

◆ createRenderPass() [1/2]

bool NAPAPI nap::utility::createRenderPass ( VkDevice  device,
VkFormat  colorFormat,
VkFormat  depthFormat,
VkSampleCountFlagBits  samples,
VkImageLayout  targetLayout,
bool  consumeDepth,
VkRenderPass &  renderPass,
utility::ErrorState errorState 
)

Creates a single or multi-sample renderpass based on rasterization samples and color/depth formats.

◆ createRenderPass() [2/2]

bool NAPAPI nap::utility::createRenderPass ( VkDevice  device,
VkFormat  colorFormat,
VkFormat  depthFormat,
VkSampleCountFlagBits  samples,
VkImageLayout  targetLayout,
VkRenderPass &  renderPass,
utility::ErrorState errorState 
)

Creates a single or multi-sample renderpass based on rasterization samples and color/depth formats.

◆ createSignature()

bool NAPAPI nap::utility::createSignature ( const std::string &  privkey,
const std::string &  message,
ESigningScheme  scheme,
std::string &  outSignature 
)

Create a signature for a given message. outSignature is encoded in base64.

Parameters
privkeyThe private key to use
messageThe message to sign
schemeThe signing scheme to use
outSignatureThe signature encoded in base64
Returns
True if the signature was created successfully

◆ decode64()

std::string NAPAPI nap::utility::decode64 ( const std::string &  str)

Decode a base64 string.

Parameters
strThe string to decode
Returns
The decoded string

◆ deleteFile()

bool nap::utility::deleteFile ( const std::string &  path)

Delete the file at the specified path.

Parameters
pathThe path to the file to delete
Returns
true on success, false if it failed

◆ destroyBuffer()

void NAPAPI nap::utility::destroyBuffer ( VmaAllocator  allocator,
BufferData buffer 
)

Destroys a Vulkan buffer

◆ destroyImageAndView()

void NAPAPI nap::utility::destroyImageAndView ( ImageData data,
VkDevice  device,
VmaAllocator  allocator 
)

Destroys a Vulkan image and Vulkan ImageView if present in data

◆ dirExists()

bool nap::utility::dirExists ( const std::string &  dirName)

Check if a directory exists or not

Parameters
dirNamename of the directory to check for
Returns
if the directory exists

◆ encode64()

std::string NAPAPI nap::utility::encode64 ( const std::string &  str)

Encode a string to base64.

Parameters
strThe string to encode
Returns
The encoded string

◆ endsWith()

bool nap::utility::endsWith ( const std::string &  string,
const std::string &  subString,
bool  caseSensitive = true 
)

Checks if string ends with subString

Parameters
stringthe string to check
subStringthe part of the string to check for
caseSensitiveif the lookup is case sensitive or now
Returns
if string ends with substring

◆ ensureDirExists()

bool nap::utility::ensureDirExists ( const std::string &  dirName)

Makes sure the given directory exists, attempts to create the directory if it does not exist, recursively

Parameters
dirNamename of the directory to check for
Returns
if directory exists

◆ fileExists()

bool nap::utility::fileExists ( const std::string &  filename)

Check whether a file exists or not.

Parameters
filenameThe absolute or relative file path to check for
Returns
true if the file exists, false otherwise

◆ findFileInDirectories()

std::string nap::utility::findFileInDirectories ( const std::string &  filename,
const std::vector< std::string > &  dirs 
)

Find a file in one of the given directories.

Parameters
filenameThe file to look for, including extension
dirsThe directories to search in
Returns
The absolute path to the found file or an empty string if none was found

◆ forceSeparator()

std::string nap::utility::forceSeparator ( const std::string &  path)

Returns a file path with the correct path separator for the current platform.

Parameters
pathpath name to correct
Returns
A file path with the correct path separator for the current platform

◆ generateIndices()

void NAPAPI nap::utility::generateIndices ( nap::MeshShape shape,
int  vertexCount,
bool  loop = false,
int  offset = 0 
)

Generates a list of sequential indices from offset up to vertexCount + offset.

Parameters
shapeThe shape to generate indices for.
vertexCountnumber of indices to generate.
loopan extra index is added at the end, pointing to the the first one. Useful when creating a line loop.
offsetThe first index value.

◆ generateRSAKey()

bool NAPAPI nap::utility::generateRSAKey ( unsigned int  bits,
std::string &  outPrivKey,
std::string &  outPubKey 
)

Generate a RSA public-private key pair.

Parameters
bitsnumber of bits
outPrivKeystring will be filled with the private key
outPubKeystring will be filled with the public key
Returns
True if the key pair was generated successfully

◆ getAbsolutePath()

std::string nap::utility::getAbsolutePath ( const std::string &  relPath)

Given a relative path, return an absolute path.

Parameters
relPathThe path to convert
Returns
Absolute file path, empty string if path can't be resolved.

◆ getCWD()

std::string nap::utility::getCWD ( )

Returns the current working directory

Returns
the current working directory

◆ getExecutableDir()

std::string nap::utility::getExecutableDir ( )
Returns
the full path to the executable directory.

◆ getExecutablePath()

std::string nap::utility::getExecutablePath ( )
Returns
the full path to the executable including the application name

◆ getFileDir()

std::string nap::utility::getFileDir ( const std::string &  file)
Parameters
filethe filename
Returns
the directory of the given file

◆ getFileExtension()

std::string nap::utility::getFileExtension ( const std::string &  filename)

Return the extension of the given filename. Eg. "my.directory/myFile.tar.gz" -> "gz"

Parameters
filenameThe filename to get the extension from
Returns
The file extension without the dot

◆ getFileModificationTime()

bool nap::utility::getFileModificationTime ( const std::string &  path,
uint64_t &  modTime 
)

Get the modification time of the specified path

Parameters
pathThe path to the file
modTimeThe modification time of the file
Returns
Whether file modification time was successfully retrieved

◆ getFileName()

std::string nap::utility::getFileName ( const std::string &  file)
Parameters
filethe file to extract the name frame
Returns
the name of the given file with extension, empty string if file has no extension

◆ getFileNameWithoutExtension()

std::string nap::utility::getFileNameWithoutExtension ( const std::string &  file)
Returns
file name without extension
Parameters
filepath that is stripped

◆ getLine()

int nap::utility::getLine ( const std::string &  buffer,
size_t  offset 
)

Based on a string and a character offset into this string, return the line number

Parameters
bufferThe string to search
offsetCharacter offset into the provided buffer
Returns
The line number at which the character at offset appears

◆ getTextureFormat() [1/2]

VkFormat NAPAPI nap::utility::getTextureFormat ( const SurfaceDescriptor descriptor)
Returns
the Vulkan format of the specified surface descriptor

◆ getTextureFormat() [2/2]

VkFormat NAPAPI nap::utility::getTextureFormat ( ESurfaceDataType  dataType,
ESurfaceChannels  channels,
EColorSpace  colorSpace 
)
Returns
the Vulkan format of the specified surface properties

◆ getTriangleCount()

int NAPAPI nap::utility::getTriangleCount ( const MeshInstance meshInstance)

Returns the total number of triangles associated with a mesh.

Parameters
meshInstancethe mesh to inspect.
Returns
the total number of triangles associated with a mesh

◆ hasExtension()

bool nap::utility::hasExtension ( const std::string &  file,
const std::string &  extension 
)
Returns
if the file has the associated file extension
Parameters
filethe file to check extension for
extensionthe file extension without preceding '.'

◆ interpolateVertexAttr()

T interpolateVertexAttr ( const TriangleData< T > &  vertexValues,
const glm::vec3 &  barycentricCoordinates 
)

Interpolates triangle vertex values based on barycentric u and v coordinates

Parameters
vertexValuesthe values associated with the triangle vertices
barycentricCoordinatesthe triangle barycentric coordinates (u,v,w)
Returns
the interpolated vertex attribute value

◆ intersect()

bool NAPAPI nap::utility::intersect ( const glm::vec3 &  rayOrigin,
const glm::vec3 &  rayDirection,
const TriangleData< glm::vec3 > &  vertices,
glm::vec3 &  outCoordinates 
)

Calculates the intersection of a ray and a triangle in 3 dimensions Based on the Moller Trumbore intersection algorithm: https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm Back-facing triangles relative to the ray direction are not considered

Parameters
rayOriginthe origin of the ray, often the world space position of a camera
rayDirectionthe direction of the ray from it's origin
verticesthe triangle vertex positions
outCoordinatesbarycentric coordinates of point of intersection, where z is the scalar factor for the ray.
Returns
if the ray intersects the triangle

◆ isAbsolutePath()

bool nap::utility::isAbsolutePath ( const std::string &  path)

Check if the given path is absolute

Parameters
pathThe path to check
Returns
True if the path is absolute, false otherwise

◆ isFilenameEqual()

bool nap::utility::isFilenameEqual ( const std::string &  filenameA,
const std::string &  filenameB 
)
Parameters
filenameAfilename to compare against filenameB.
filenameBfilename to comapre against filenameA.
Returns
return true when file are logically equal (uses toComparableFilename).

◆ isTriangleMesh()

bool NAPAPI nap::utility::isTriangleMesh ( const nap::MeshInstance meshInstance)

Returns if the mesh is of type: TRIANGLES, TRIANGLE_STRIP or TRIANGLE_FAN

Parameters
meshInstancethe mesh to check
Returns
if the mesh is of type: TRIANGLES, TRIANGLE_STRIP or TRIANGLE_FAN

◆ joinPath()

std::string nap::utility::joinPath ( const std::vector< std::string > &  parts)

Join parts path parts using the correct path separator for the current platform

◆ joinString()

std::string joinString ( const T &  list,
const char *  delim 
)

Joins a list of strings together. For example: joinString({"one", "two", "three"}, ", ") -> becomes: "one, two, three"

Parameters
listThe list of strings to join
delimThe delimiter to inject between the elements
Returns
The joined string.

◆ listDir()

bool nap::utility::listDir ( const char *  directory,
std::vector< std::string > &  outFilenames,
bool  absolute = true 
)

List all files in a directory

Parameters
directoryThe directory to search in
outFilenamesA vector of files to populate with filenames
absoluteWhether to populate absolute filenames
Returns
False on failure

◆ lTrim()

std::string nap::utility::lTrim ( const std::string &  string)

Strips white space characters from the start(left) of a string

Parameters
stringthe string to remove white space characters from
Returns
the string without white space characters

◆ makeDirs()

bool nap::utility::makeDirs ( const std::string &  directory)

Attempts to create a directory with the given name, recursively. Creation will fail if the path is invalid or the directory already exists.

Parameters
directorypath to the directory to create, absolute or relative.
Returns
If the directory has been created.

◆ namedFormat() [1/2]

void nap::utility::namedFormat ( std::string &  subject,
const std::unordered_map< std::string, std::string > &  rep 
)

Replace all occurrences of the provided keys with their associated values in the given subject string. The keys in the subject string are to be wrapped in curly braces. Example: subject: My {animal}'s name is {name}, it's a good {animal}. replacement: {{"animal", "snake"}, {"name", "Donald"}} result: My snake's name is Donald, it's a good snake.

Parameters
subjectThe string to search and replace keys in.
repThe keys and values used in the replacement operation.
Returns
The resulting string after replacement

◆ namedFormat() [2/2]

void nap::utility::namedFormat ( std::vector< std::string > &  subjects,
const std::unordered_map< std::string, std::string > &  rep 
)

Replace all occurrences of the provided keys with their associated values in the given subject strings. The keys in the subject string are to be wrapped in curly braces. Example: subject: My {animal}'s name is {name}, it's a good {animal}. replacement: {{"animal", "snake"}, {"name", "Donald"}} result: My snake's name is Donald, it's a good snake.

Parameters
subjectsThe strings to search and replace keys in.
repThe keys and values used in the replacement operation.

◆ readFileToString()

bool nap::utility::readFileToString ( const std::string &  filename,
std::string &  outBuffer,
utility::ErrorState err 
)

Read the contents of a file into a string.

Parameters
filenameName of the file to read from
outBufferThe string in which the contents will be stored
errWill contain the error details if there were any problems.
Returns
True if the read succeeded, false otherwise

◆ readString()

std::string nap::utility::readString ( std::istream &  stream)

Reads a string form an input stream

Parameters
streamthe stream to read the string from
Returns
the string read from the input stream

◆ replaceAllInstances() [1/2]

std::string nap::utility::replaceAllInstances ( const std::string &  inString,
const std::string &  find,
const std::string &  replace 
)

Replace all instances of a string with a replacement string.

Parameters
inStringThe input string to search in
findThe string to replace
replaceThe replacement string
Returns
A copy of the input string with all instances of the search term replaced

◆ replaceAllInstances() [2/2]

void nap::utility::replaceAllInstances ( std::string &  inString,
const std::string &  find,
const std::string &  replace 
)

Replace all instances of search string with replacement

Parameters
inStringThe input string to search in
findThe search string
replaceThe replacement string

◆ replaceTemplateType()

std::string nap::utility::replaceTemplateType ( const std::string &  typeName,
const std::string &  templateTypeName 
)

Given a templated type name, replace its template parameter with the provided template type.

Parameters
typeNameThe original templated type name, eg. "nap::MyType<SomeClass<float>>"
templateTypeNameA replacement type name, eg. "float"
Returns
A modified type name such as "nap::MyType<float>"

◆ reverseWindingOrder()

void NAPAPI nap::utility::reverseWindingOrder ( nap::MeshInstance mesh)

Reverses the winding order of all the triangle vertices in a mesh When a triangle has vertices A, B, C the new order will be C, B, A This call only works for triangle meshes that have indices associated with it This call asserts when the mesh is not a triangular mesh or the mesh has no indices

Parameters
meshthe mesh to reverse the index winding order for

◆ rTrim()

std::string nap::utility::rTrim ( const std::string &  string)

Strips white space characters from the end(right) of a string string

Parameters
stringthe string to remove white space characters from
Returns
the string without white space characters

◆ setTriangleIndices()

void NAPAPI nap::utility::setTriangleIndices ( nap::MeshShape mesh,
EDrawMode  drawMode,
int  number,
const std::array< int, 3 > &  indices 
)

Sets the vertex indices associated with a triangle. Note that this function only works for meshes that are of type: TRIANGLES, TRIANGLE_STRIP or TRIANGLE_FAN This call asserts when the triangle number is out of bounds, the mesh has no indices or the draw mode is not of type triangle

Parameters
meshthe mesh to get the indices from
drawModemesh topology
numberthe triangle number to get the for
indicesthe new indices
Returns
if the triangle indices are valid

◆ sha256()

std::string NAPAPI nap::utility::sha256 ( const std::string &  str)

Generate a SHA256 hash of a string.

Parameters
strThe string to hash
Returns
The hash

◆ splitString() [1/2]

std::vector<std::string> nap::utility::splitString ( const std::string &  string,
const char  delim 
)

◆ splitString() [2/2]

void nap::utility::splitString ( const std::string &  string,
const char  delim,
std::vector< std::string > &  ioParts 
)

◆ startsWith()

bool nap::utility::startsWith ( const std::string &  string,
const std::string &  subString,
bool  caseSensitive = true 
)

Checks if string starts with subString

Parameters
stringthe string to check
subStringthe part of the string to check for
caseSensitiveif the lookup is case sensitive or not
Returns
if the given string starts with subString

◆ stringFormat()

std::string nap::utility::stringFormat ( const char *  msg,
Args &&...  args 
)

Formats a string based on the incoming arguments example: utility::stringFormat("%s contains %d number of items", object.name().c_str(), i)

Parameters
msgthe string to format
argsthe arguments to replace
Returns
the formatted string

◆ stripFileExtension() [1/2]

std::string nap::utility::stripFileExtension ( const std::string &  file)
Returns
file without extension
Parameters
filethe file to string the extension from

◆ stripFileExtension() [2/2]

void nap::utility::stripFileExtension ( std::string &  file)
Parameters
filethe file to strip the extension from

◆ stripNamespace()

std::string nap::utility::stripNamespace ( const std::string &  str)

Strips all name space related identifiers from the given string.

Parameters
strthe string to remove the namespace from
Returns
the stripped string

◆ toComparableFilename()

std::string nap::utility::toComparableFilename ( const std::string &  filename)

TODO: This may well be a platform independent 'toCanonicalFilename' or 'URI' as described here: https://en.wikipedia.org/wiki/File_URI_scheme

Returns
returns a string that can be used to compare against other filenames. Is also suitable for use as key in map or set.
Parameters
filenamethe source filename.

◆ tokenize()

void nap::utility::tokenize ( const std::string &  str,
std::list< std::string > &  tokens,
const std::string &  delims,
bool  omitTokens = false 
)

Tokenize str into tokens.

Parameters
strthe string to tokenize
tokensthe tokens used to process the string
delimsthe delimiters used for the the tokenization process
omitTokensif the tokens are discarded from the result

◆ toLower() [1/2]

std::string nap::utility::toLower ( const std::string &  string)

Converts all upper case characters in ioString to lower case characters

Parameters
stringthe input string that is converted
Returns
the lower case version of the given string

◆ toLower() [2/2]

void nap::utility::toLower ( std::string &  ioString)

Converts all upper case characters in ioString to lower case characters

Parameters
ioStringthe input string that is converted to a lower case string

◆ toUpper() [1/2]

std::string nap::utility::toUpper ( const std::string &  string)

Converts all lower case characters in ioString to upper case characters

Parameters
stringthe input string that is converted
Returns
the upper case version of the given string

◆ toUpper() [2/2]

void nap::utility::toUpper ( std::string &  ioString)

Converts all lower case characters in ioString to upper case characters

Parameters
ioStringthe input string that is converted to an upper case string

◆ transitionImageLayout() [1/2]

void NAPAPI nap::utility::transitionImageLayout ( VkCommandBuffer  commandBuffer,
VkImage  image,
VkImageLayout  oldLayout,
VkImageLayout  newLayout,
VkAccessFlags  srcAccessMask,
VkAccessFlags  dstAccessMask,
VkPipelineStageFlags  srcStage,
VkPipelineStageFlags  dstStage,
uint  mipLevel,
uint  mipLevelCount,
uint  layer,
uint  layerCount,
VkImageAspectFlags  aspect 
)

Transition image to a new layout using an image barrier.

◆ transitionImageLayout() [2/2]

void NAPAPI nap::utility::transitionImageLayout ( VkCommandBuffer  commandBuffer,
VkImage  image,
VkImageLayout  oldLayout,
VkImageLayout  newLayout,
VkAccessFlags  srcAccessMask,
VkAccessFlags  dstAccessMask,
VkPipelineStageFlags  srcStage,
VkPipelineStageFlags  dstStage,
uint  mipLevel,
uint  mipLevelCount,
VkImageAspectFlags  aspect 
)

Transition image to a new layout using an image barrier.

◆ trim()

std::string nap::utility::trim ( const std::string &  string)

Strips white space characters from a string

Parameters
stringthe string to remove white space characters from
Returns
the string without white space characters

◆ uploadToBuffer()

bool NAPAPI nap::utility::uploadToBuffer ( VmaAllocator  allocator,
uint32  size,
const void *  data,
BufferData buffer 
)

Uploads data into a staging buffer

◆ verifyMessage()

bool NAPAPI nap::utility::verifyMessage ( const std::string &  pubkey,
const std::string &  message,
ESigningScheme  scheme,
const std::string &  signature 
)

Verify a message against a signature. Signature is expected to be encoded in base64.

Parameters
pubkeyThe public key to use
messageThe message to verify
schemeThe signing scheme to use
signatureThe signature encoded in base64
Returns
True if the message was verified successfully

◆ writeString()

void nap::utility::writeString ( std::ostream &  stream,
const std::string &  text 
)

Writes a string to an output stream

Parameters
streamthe output stream to write to
textthe string to write

◆ writeStringToFile()

void nap::utility::writeStringToFile ( const std::string &  filename,
const std::string &  contents 
)

Dump a string to a file.

Parameters
filenameThe name of the file to write to.
contentsThe string to write