26 #ifndef CLASS_DECLSPEC
28 #pragma warning(disable:4251)
30 #define CLASS_DECLSPEC __declspec(dllexport)
32 #define CLASS_DECLSPEC __declspec(dllimport)
35 #define CLASS_DECLSPEC
45 #define FOR_EACH_TIXMLELEMENT(CHILDELEMENT, PARENTELEMENT, ELEMENTNAME) \
46 for (TiXmlElement* CHILDELEMENT = (PARENTELEMENT).FirstChildElement(ELEMENTNAME); CHILDELEMENT; CHILDELEMENT = CHILDELEMENT->NextSiblingElement(ELEMENTNAME))
50 inline std::string
stringify(
const T& x,
int iPrecision = 12,
bool bScientific =
true)
55 o << std::setprecision(iPrecision) << x;
64 memset((
void*)&value, 0,
sizeof(T));
65 std::stringstream i(x);
75 memset((
void*)&value, 0,
sizeof(T));
78 std::stringstream i(x);
85 struct LessPairDoubleInt :
public std::binary_function<std::pair<double, int>, std::pair<double, int>, bool>
87 bool operator()(std::pair<double, int> x, std::pair<double, int> y) {
return x.first < y.first; }
91 struct LessPairDoubleXYZ :
public std::binary_function<std::pair<double, XYZ>, std::pair<double, XYZ>, bool>
93 bool operator()(std::pair<double, XYZ> x, std::pair<double, XYZ> y) {
return x.first < y.first; }
101 inline double*
Array() {
return (
double*)
this; }
151 T
GetInterpedValue(
const std::vector<std::pair<double, T> > &InterpValues,
double fraction)
153 if (InterpValues.empty())
155 if (fraction <= InterpValues.front().first)
156 return InterpValues.front().second;
157 if (fraction >= InterpValues.back().first)
158 return InterpValues.back().second;
159 typename std::vector<std::pair<double, T> >::const_iterator itCurrentValue;
160 typename std::vector<std::pair<double, T> >::const_iterator itPrevValue = InterpValues.end();
161 for (itCurrentValue = InterpValues.begin(); itCurrentValue != InterpValues.end(); ++itCurrentValue)
163 if (itPrevValue != InterpValues.end())
165 if (fraction <= itCurrentValue->first)
167 double u = (fraction-itPrevValue->first)/(itCurrentValue->first-itPrevValue->first);
168 T value = itPrevValue->second + u*(itCurrentValue->second-itPrevValue->second);
172 itPrevValue = itCurrentValue;
179 std::pair<double, std::pair<T, T> >
GetClosestValues(
const std::vector<std::pair<double, T> > &InterpValues,
double fraction)
181 std::pair<double, std::pair<T, T> > ClosestVals;
182 if (InterpValues.empty())
184 if (fraction <= InterpValues.front().first)
186 ClosestVals.first = 0.0;
187 ClosestVals.second = std::make_pair(InterpValues.front().second, InterpValues.front().second);
190 if (fraction >= InterpValues.back().first)
192 ClosestVals.first = 1.0;
193 ClosestVals.second = std::make_pair(InterpValues.back().second, InterpValues.back().second);
196 typename std::vector<std::pair<double, T> >::const_iterator itCurrentValue;
197 typename std::vector<std::pair<double, T> >::const_iterator itPrevValue = InterpValues.end();
198 for (itCurrentValue = InterpValues.begin(); itCurrentValue != InterpValues.end(); ++itCurrentValue)
200 if (itPrevValue != InterpValues.end())
202 if (fraction <= itCurrentValue->first)
204 ClosestVals.first = (fraction-itPrevValue->first)/(itCurrentValue->first-itPrevValue->first);
205 ClosestVals.second.first = itPrevValue->second;
206 ClosestVals.second.second = itCurrentValue->second;
210 itPrevValue = itCurrentValue;
248 for (
int i = 1; i < (int)Points.size(); ++i )
250 if ( Points[i].x <
Min.
x )
252 else if ( Points[i].x >
Max.x )
255 if ( Points[i].y <
Min.
y )
257 else if ( Points[i].y >
Max.y )
273 template <
typename T>
274 void WriteValues(std::ostream &Output, T &Values,
int iMaxPerLine)
277 typename T::const_iterator itValue;
278 for (itValue = Values.begin(); itValue != Values.end(); ++itValue)
284 else if (iLinePos < iMaxPerLine)
Namespace containing a series of customised math operations not found in the standard c++ library.
std::string RemoveExtension(std::string &Filename, std::string Extension)
Strip the extension from the filename.
std::string StripPath(std::string Filename)
Strip the path from the filename (e.g. "c:\folder\file.ext -> file.ext")
void GetMinMaxXY(const std::vector< XY > &Points, XY &Min, XY &Max)
std::pair< double, std::pair< T, T > > GetClosestValues(const std::vector< std::pair< double, T > > &InterpValues, double fraction)
Get the two closest values to fraction in the vector InterpValues.
std::string ReplaceFilenameSpaces(std::string Filename)
Replaces spaces in filename with underscore.
void CopyToRange(vector< XYZ > &Offsets, XYZ Vector, int iLowerLimit, int iUpperLimit)
T valueify(const std::string &x)
Function to convert a string to a value (e.g. int, double, etc...)
void WriteElementsHeader(std::ostream &Output)
Write elements header for ABAQUS .eld files.
void WriteOrientationsHeader(std::ostream &Output)
Write orientations header for ABAQUS .ori files.
COLOR GetIndexedColor(int iIndex)
bool CompatibleUnits(std::string SourceUnits, std::string TargetUnits, std::string *pErrorMessage)
void WriteValues(std::ostream &Output, T &Values, int iMaxPerLine)
std::string ReduceUnits(std::string Units)
T GetInterpedValue(const std::vector< std::pair< double, T > > &InterpValues, double fraction)
Get an interpolated value.
double Max(XYZ &Vector)
Get maximum element of vector and return it.
void AddNewUnits(std::string NewUnit, std::string BaseUnits)
std::string stringify(const T &x, int iPrecision=12, bool bScientific=true)
Function to convert a value (e.g. int, double, etc...) to a string.
XYZ Min(const XYZ &P1, const XYZ &P2)
Given two points, return a new point who's coordinates are the smaller of the two.
void AddExtensionIfMissing(std::string &Filename, std::string Extension)
Adds an extension to the filename if it is missing otherwise do nothing (e.g. picture -> picture....
PERIODIC_BOUNDARY_CONDITIONS
double ConvertUnits(double dValue, std::string SourceUnits, std::string TargetUnits)
COLOR(double r, double g, double b)
Used to sort double-int pairs.
bool operator()(std::pair< double, int > x, std::pair< double, int > y)
Used to sort double-XYZ pairs.
bool operator()(std::pair< double, XYZ > x, std::pair< double, XYZ > y)
Structure used to retreive information about a particular point in space.
double dSurfaceDistance
Returns the closest distance from the point to the surface of the yarn.
int iYarnIndex
Index of the yarn, -1 when the point is not inside a yarn.
XYZ Orientation
Local fibre orientation.
XY Location
Location of the point relative to the yarn centerline.
XYZ YarnTangent
Tangent of the yarn centreline.
Struct for representing points in 2D space.
Struct for representing points in 3D space.