MathFunctions.h
#ifndef __MATHFUNCTIONS_H__
#define __MATHFUNCTIONS_H__
/*LICENSE_START*/
/*
* Copyright (c) 2014, Washington University School of Medicine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
namespace cifti {
//NOTE: in CiftiLib, we only reference matrixToQuatern and quaternToMatrix, both used only in NiftiHeader when using volume files, not cifti files
class MathFunctions {
public:
static int64_t combinations(
const int64_t n,
const int64_t k);
static int64_t permutations(
const int64_t n,
const int64_t k);
static int64_t factorial(const int64_t n);
static bool normalVector(
const float v1[3],
const float v2[3],
const float v3[3],
float normalVectorOut[3]);
static bool normalVector(
const double v1[3],
const double v2[3],
const double v3[3],
double normalVectorOut[3]);
static void normalVectorDirection(
const float v1[3],
const float v2[3],
const float v3[3],
float directionOut[3]);
static void crossProduct(
const float v1[],
const float v2[],
float resultOut[]);
static void crossProduct(
const double v1[],
const double v2[],
double resultOut[]);
static void normalizedCrossProduct(
const float x1[],
const float x2[],
float resultOut[]);
static float normalizeVector(
float vectorsAll[],
const int32_t offset);
static float normalizeVector(float vectorInOut[3]);
static double normalizeVector(double vectorInOut[3]);
static float vectorLength(const float vector[3]);
static float vectorLength(
const float vectorsAll[],
const int32_t offset);
static double vectorLength(const double vector[3]);
static float distanceSquared3D(
const float p1[3],
const float p2[3]);
static float distanceSquared3D(
const float xyzAll[],
const int32_t offsetCoord1,
const int32_t offsetCoord2);
static float distance3D(
const float p1[3],
const float p2[3]);
static double distanceSquared3D(
const double p1[3],
const double p2[3]);
static double distance3D(
const double p1[3],
const double p2[3]);
static double distanceSquared2D(const double x1,
const double y1,
const double x2,
const double y2);
static void subtractVectors(
const float v1[3],
const float v2[3],
float resultOut[3]);
static void addVectors(
const float v1[3],
const float v2[3],
float resultOut[3]);
static void createUnitVector(
const float startXYZ[3],
const float endXYZ[3],
float unitVectorOut[3]);
static void createUnitVector(
const double startXYZ[3],
const double endXYZ[3],
double unitVectorOut[3]);
static float dotProduct(
const float p1[3],
const float p2[3]);
static double dotProduct(
const double p1[3],
const double p2[3]);
static float triangleArea(
const float v1[3],
const float v2[3],
const float v3[3]);
static float triangleArea(const double v1[3],
const double v2[3],
const double v3[3]);
static float triangleArea(
const float xyzAll[],
const int32_t offsetCoord1,
const int32_t offsetCoord2,
const int32_t offsetCoord3);
static float triangleAreaSigned2D(
const float p1[3],
const float p2[3],
const float p3[3]);
static float triangleAreaSigned3D(
const float referenceNormal[3],
const float p1[3],
const float p2[3],
const float p3[3]);
static bool lineIntersection2D(
const float p1[3],
const float p2[3],
const float q1[3],
const float q2[3],
const float tolerance,
float intersectionOut[3]);
static bool rayIntersectPlane(
const float p1[3],
const float p2[3],
const float p3[3],
const float rayOrigin[3],
const float rayVector[3],
float intersectionXYZandDistance[3]);
static void projectPoint(
const float pt[3],
const float origin[3],
const float normal[3],
float projectedPointOut[3]);
static float signedDistanceFromPlane(
const float planeNormal[3],
const float pointInPlane[3],
const float queryPoint[3]);
static int32_t limitRange(
const int32_t value,
const int32_t minimumValue,
const int32_t maximumValue);
static float limitRange(
const float value,
const float minimumValue,
const float maximumValue);
static double limitRange(
const double value,
const double minimumValue,
const double maximumValue);
static float distanceToLine3D(
const float p1[3],
const float p2[3],
const float point[3]);
static bool arraysEqual(
const float a[],
const float b[],
const int32_t numElements);
static void averageOfThreeCoordinates(
const float c1[3],
const float c2[3],
const float c3[3],
float outputAverage[3]);
static void averageOfThreeCoordinates(
const float xyzAll[],
const int32_t offsetCoord1,
const int32_t offsetCoord2,
const int32_t offsetCoord3,
float outputAverage[],
const int32_t outputOffset);
static float angle(
const float p1[3],
const float p2[3],
const float p3[3]);
static float signedAngle(
const float pi[3],
const float pj[3],
const float pk[3],
const float n[3]);
static bool isOddNumber(const int32_t number);
static bool isEvenNumber(const int32_t number);
static bool isNaN(const float number);
static bool isPosInf(const float number);
static bool isNegInf(const float number);
static bool isInf(const float number);
static bool isNumeric(const float number);
static bool compareArrays(
const float a1[],
const float a2[],
const int32_t numElements,
const float tolerance);
static int32_t clamp(
const int32_t value,
const int32_t minimum,
const int32_t maximum);
static float clamp(
const float value,
const float minimum,
const float maximum);
static uint32_t gcd(uint32_t num1, uint32_t num2);
static void quaternToMatrix(const float cijk[4], float matrix[3][3]);
static void quaternToMatrix(const double cijk[4], double matrix[3][3]);
static bool matrixToQuatern(const float matrix[3][3], float cijk[4]);
static bool matrixToQuatern(const double matrix[3][3], double cijk[4]);
static double remainder(const double numerator,
const double denominator);
static double round(const double value);
};
} // namespace
#endif // __MATHFUNCTIONS_H__
cifti::MathFunctions
Definition MathFunctions.h:39
cifti::MathFunctions::normalVector
static bool normalVector(const float v1[3], const float v2[3], const float v3[3], float normalVectorOut[3])
Definition MathFunctions.cxx:132
cifti::MathFunctions::subtractVectors
static void subtractVectors(const float v1[3], const float v2[3], float resultOut[3])
Definition MathFunctions.cxx:541
cifti::MathFunctions::angle
static float angle(const float p1[3], const float p2[3], const float p3[3])
Definition MathFunctions.cxx:1162
cifti::MathFunctions::vectorLength
static float vectorLength(const float vector[3])
Definition MathFunctions.cxx:379
cifti::MathFunctions::clamp
static int32_t clamp(const int32_t value, const int32_t minimum, const int32_t maximum)
Definition MathFunctions.cxx:1298
cifti::MathFunctions::isNumeric
static bool isNumeric(const float number)
true only if not NaN, inf, or -inf
Definition MathFunctions.cxx:1381
cifti::MathFunctions::round
static double round(const double value)
Definition MathFunctions.cxx:1706
cifti::MathFunctions::permutations
static int64_t permutations(const int64_t n, const int64_t k)
Definition MathFunctions.cxx:88
cifti::MathFunctions::createUnitVector
static void createUnitVector(const float startXYZ[3], const float endXYZ[3], float unitVectorOut[3])
Definition MathFunctions.cxx:568
cifti::MathFunctions::averageOfThreeCoordinates
static void averageOfThreeCoordinates(const float c1[3], const float c2[3], const float c3[3], float outputAverage[3])
Definition MathFunctions.cxx:1113
cifti::MathFunctions::triangleAreaSigned2D
static float triangleAreaSigned2D(const float p1[3], const float p2[3], const float p3[3])
Definition MathFunctions.cxx:734
cifti::MathFunctions::distance3D
static float distance3D(const float p1[3], const float p2[3])
Definition MathFunctions.cxx:477
cifti::MathFunctions::normalizedCrossProduct
static void normalizedCrossProduct(const float x1[], const float x2[], float resultOut[])
Definition MathFunctions.cxx:294
cifti::MathFunctions::normalizeVector
static float normalizeVector(float vectorsAll[], const int32_t offset)
Definition MathFunctions.cxx:319
cifti::MathFunctions::signedAngle
static float signedAngle(const float pi[3], const float pj[3], const float pk[3], const float n[3])
Definition MathFunctions.cxx:1207
cifti::MathFunctions::triangleAreaSigned3D
static float triangleAreaSigned3D(const float referenceNormal[3], const float p1[3], const float p2[3], const float p3[3])
Definition MathFunctions.cxx:756
cifti::MathFunctions::projectPoint
static void projectPoint(const float pt[3], const float origin[3], const float normal[3], float projectedPointOut[3])
Definition MathFunctions.cxx:917
cifti::MathFunctions::triangleArea
static float triangleArea(const float v1[3], const float v2[3], const float v3[3])
Definition MathFunctions.cxx:643
cifti::MathFunctions::arraysEqual
static bool arraysEqual(const float a[], const float b[], const int32_t numElements)
Definition MathFunctions.cxx:1088
cifti::MathFunctions::distanceToLine3D
static float distanceToLine3D(const float p1[3], const float p2[3], const float point[3])
Definition MathFunctions.cxx:1057
cifti::MathFunctions::distanceSquared3D
static float distanceSquared3D(const float p1[3], const float p2[3])
Definition MathFunctions.cxx:435
cifti::MathFunctions::remainder
static double remainder(const double numerator, const double denominator)
Definition MathFunctions.cxx:1636
cifti::MathFunctions::rayIntersectPlane
static bool rayIntersectPlane(const float p1[3], const float p2[3], const float p3[3], const float rayOrigin[3], const float rayVector[3], float intersectionXYZandDistance[3])
Definition MathFunctions.cxx:862
cifti::MathFunctions::dotProduct
static float dotProduct(const float p1[3], const float p2[3])
Definition MathFunctions.cxx:610
cifti::MathFunctions::gcd
static uint32_t gcd(uint32_t num1, uint32_t num2)
greatest common divisor
Definition MathFunctions.cxx:1343
cifti::MathFunctions::matrixToQuatern
static bool matrixToQuatern(const float matrix[3][3], float cijk[4])
try to convert 3x3 matrix to quaternion (return false if not a rotation matrix)
Definition MathFunctions.cxx:1439
cifti::MathFunctions::lineIntersection2D
static bool lineIntersection2D(const float p1[3], const float p2[3], const float q1[3], const float q2[3], const float tolerance, float intersectionOut[3])
Definition MathFunctions.cxx:801
cifti::MathFunctions::distanceSquared2D
static double distanceSquared2D(const double x1, const double y1, const double x2, const double y2)
Definition MathFunctions.cxx:1332
cifti::MathFunctions::signedDistanceFromPlane
static float signedDistanceFromPlane(const float planeNormal[3], const float pointInPlane[3], const float queryPoint[3])
Definition MathFunctions.cxx:950
cifti::MathFunctions::compareArrays
static bool compareArrays(const float a1[], const float a2[], const int32_t numElements, const float tolerance)
Definition MathFunctions.cxx:1272
cifti::MathFunctions::combinations
static int64_t combinations(const int64_t n, const int64_t k)
Definition MathFunctions.cxx:49
cifti::MathFunctions::crossProduct
static void crossProduct(const float v1[], const float v2[], float resultOut[])
Definition MathFunctions.cxx:256
cifti::MathFunctions::limitRange
static int32_t limitRange(const int32_t value, const int32_t minimumValue, const int32_t maximumValue)
Definition MathFunctions.cxx:979
cifti::MathFunctions::isEvenNumber
static bool isEvenNumber(const int32_t number)
Definition MathFunctions.cxx:1256
cifti::MathFunctions::isInf
static bool isInf(const float number)
true if either inf or -inf
Definition MathFunctions.cxx:1366
cifti::MathFunctions::factorial
static int64_t factorial(const int64_t n)
Definition MathFunctions.cxx:109
cifti::MathFunctions::normalVectorDirection
static void normalVectorDirection(const float v1[3], const float v2[3], const float v3[3], float directionOut[3])
Definition MathFunctions.cxx:226
cifti::MathFunctions::quaternToMatrix
static void quaternToMatrix(const float cijk[4], float matrix[3][3])
convert quaternion to rotation matrix
Definition MathFunctions.cxx:1391
cifti::MathFunctions::isOddNumber
static bool isOddNumber(const int32_t number)
Definition MathFunctions.cxx:1243
cifti
namespace for all CiftiLib functionality
Definition CiftiBrainModelsMap.h:42