34 #include <gsl/gsl_linalg.h> 35 #include <gsl/gsl_blas.h> 52 bool polarNotation = (tmpStr[0] ==
'<' && tmpStr[tmpStr.size()-1] ==
'>');
55 std::string allowableStartChars, allowableEndChars;
56 allowableStartChars=
"([{<'";
57 allowableEndChars=
")]}>'";
60 size_t startPos,endPos;
61 startPos=allowableStartChars.find(tmpStr[0]);
62 endPos=allowableEndChars.find(tmpStr[tmpStr.size()-1]);
66 if(startPos !=std::string::npos && endPos != std::string::npos)
67 tmpStr=tmpStr.substr(1,tmpStr.size()-1);
68 else if (startPos !=endPos)
73 vector<string> components;
74 const char *NONWHITE_SEPARATOR=
",;|_";
77 if(components.size()!=3)
85 const char *ALLOWABLE_SEPARATORS=
",; \t|_";
89 for(
size_t ui=0;ui<components.size();ui++)
93 vector<string>::iterator rmIt;
94 rmIt=std::remove(components.begin(),components.end(),string(
""));
95 components.erase(rmIt,components.end());
97 if(components.size()!=3)
101 for(
size_t ui=0;ui<3;ui++)
143 for(
unsigned int ui=0; ui<3; ui++)
145 *(valArr+ui) = *(value+ui);
151 for(
unsigned int ui=0;ui<3; ui++)
152 value[ui]-= pt.value[ui];
159 return (value[0] == pt.value[0] && value[1] == pt.value[1] && value[2] == pt.value[2]);
164 value [0] = pt.value[0];
165 value [1] = pt.value[1];
166 value [2] = pt.value[2];
172 for(
unsigned int ui=0;ui<3; ui++)
173 value[ui]+= pt.value[ui];
182 for(
unsigned int ui=0;ui<3; ui++)
183 ptTmp.value[ui] = value[ui] + pt.value[ui];
191 for(
unsigned int ui=0;ui<3; ui++)
192 tmp.value[ui] = value[ui] + f;
201 for(
unsigned int ui=0;ui<3; ui++)
202 ptTmp.value[ui] = value[ui] - pt.value[ui];
211 for(
unsigned int ui=0;ui<3; ui++)
212 ptTmp.value[ui] = -value[ui];
219 value[0] = value[0]*scale;
220 value[1] = value[1]*scale;
221 value[2] = value[2]*scale;
230 tmpPt.value[0] = value[0]*scale;
231 tmpPt.value[1] = value[1]*scale;
232 tmpPt.value[2] = value[2]*scale;
241 tmpPt.value[0] = value[0]*pt[0];
242 tmpPt.value[1] = value[1]*pt[1];
243 tmpPt.value[2] = value[2]*pt[2];
253 tmpPt.value[0] = value[0]*scale;
254 tmpPt.value[1] = value[1]*scale;
255 tmpPt.value[2] = value[2]*scale;
264 tmpPt.value[0] = value[0]/pt[0];
265 tmpPt.value[1] = value[1]/pt[1];
266 tmpPt.value[2] = value[2]/pt[2];
274 return (pt.value[0]-value[0])*(pt.value[0]-value[0])+
275 (pt.value[1]-value[1])*(pt.value[1]-value[1])+
276 (pt.value[2]-value[2])*(pt.value[2]-value[2]);
282 return value[0]*pt.value[0] + value[1]*pt.value[1] + value[2]*pt.value[2];
289 cross.value[0] = (pt.value[2]*value[1] - pt.value[1]*value[2]);
290 cross.value[1] = (value[2]*pt.value[0] - pt.value[2]*value[0]);
291 cross.value[2] = (value[0]*pt.value[1] - value[1]*pt.value[0]);
311 return (value[0] < farPoint.value[0] && value[0] >=0) &&
312 (value[1] < farPoint.value[1] && value[1] >=0) &&
313 (value[2] < farPoint.value[2] && value[2] >=0);
319 return (value[0] < highPt.value[0] && value[0] >=lowPt.value[0]) &&
320 (value[1] < highPt.value[1] && value[1] >=lowPt.value[1]) &&
321 (value[2] < highPt.value[2] && value[2] >=lowPt.value[2]);
327 value[0] = obj.value[0] + value[0];
328 value[1] = obj.value[1] + value[1];
329 value[2] = obj.value[2] + value[2];
334 return value[0]*value[0] + value[1]*value[1] + value[2]*value[2];
360 value[0] = -value[0];
361 value[1] = -value[1];
362 value[2] = -value[2];
367 value[0] = 1.0/value[0];
368 value[1] = 1.0/value[1];
369 value[2] = 1.0/value[2];
378 if(crossp.
sqrMag() < sqrt(std::numeric_limits<float>::epsilon()))
396 size_t nPoints=points.size();
401 std::vector<Point3D> centroids(omp_get_max_threads(),
Point3D(0,0,0));
402 #pragma omp parallel for 403 for(
size_t ui=0;ui<nPoints;ui++)
404 centroids[omp_get_thread_num()]+=points[ui];
406 for(
size_t ui=0;ui<centroids.size();ui++)
407 centroid+=centroids[ui];
411 for(
unsigned int ui=0;ui<nPoints;ui++)
412 centroid+=points[ui];
415 centroid*=1.0f/(float)nPoints;
419 stream <<
"(" << pt.value[0] <<
"," << pt.value[1]
420 <<
"," << pt.value[2] <<
")";
427 value[0] = r*sin(theta)*cos(phi);
428 value[1] = r*sin(theta)*sin(phi);
429 value[2] = r*cos(theta);
436 if(r < std::numeric_limits<float>::epsilon())
441 theta =acos(value[2]/r);
442 phi =atan2(value[1],value[0]);
448 for(
unsigned int row=0;row<3;row++)
452 for(
unsigned int col=0;col<3;col++)
455 newValue[row]+= gsl_matrix_get(matrix,row,col)*value[col];
459 value[0]=newValue[0];
460 value[1]=newValue[1];
461 value[2]=newValue[2];
464 #ifdef __LITTLE_ENDIAN__ 465 void Point3D::switchEndian()
485 TEST(p2 ==
Point3D(0,0,1),
"parse check (spherical)");
487 TEST(p2.
mag() == 1.0,
"mag check");
491 TEST(TOL_EQ(p1.dotProd(p1),(3.0)),
"Dot product");
497 (p1.crossProd(p2) -
Point3D(0,0,1)).
sqrMag(),0),
"cross prod");
float sqrDist(const Point3D &pt) const
Returns the square of distance to another Point3D.
void reciprocal()
Makes each value its reciprocal (1/X, 1/Y, 1/Z)
void negate()
Makes each value negative of old value (-X, -Y, -Z)
float operator[](unsigned int ui) const
Array indexing operator, Point3D[1] returns the value of the ui-th dim.
const Point3D operator*(float scale) const
Scalar multiplication (X*f, Y*f, Z*f)
Point3D crossProd(const Point3D &pt) const
Calculate the cross product of this and another point.
std::string stripWhite(const std::string &str)
Strip whitespace, (eg tab,space) from either side of a string.
const Point3D & operator+=(const Point3D &pt)
+= operator
Point3D()
Constructor with no initialisation.
void copyValueArr(float *value) const
Copy data from internal into target array of length 3 : Pointer MUST be allocated.
bool orthogonalise(const Point3D &p)
Perform a cross-product based orthogonalisation with the specified vector.
void getISOSpherical(float &radius, float &theta, float &phi) const
Get the Point3D value as spherical coordinates (ISO 30-11)
const Point3D operator+(const Point3D &pt) const
Addition of Point3D objects (X1+X2, Y1+Y2, Z1+Z2)
float sqrMag() const
Returns magnitude^2, taking this as a position vector.
void splitStrsRef(const char *cpStr, const char delim, std::vector< std::string > &v)
Split string references using a single delimiter.
A 3D point data class storage.
void setISOSpherical(float radius, float theta, float phi)
Assign the vector using spherical coordinates.
bool parse(const std::string &s)
Set from string representation.
float angle(const Point3D &pt) const
Calculate the angle between two position vectors in radians.
float mag() const
Magnitude of position vector.
Point3D normal() const
Return point unit magnitude, maintianing direction.
const Point3D & operator-=(const Point3D &pt)
-= operator
friend std::ostream & operator<<(std::ostream &stream, const Point3D &)
Output streaming operator. Streams values in the text format (x,y,z)
void setValueArr(const float *val)
Set value by pointer (X, Y, Z from array of len 3)
void transform3x3(const gsl_matrix *matrix)
Perform a 3x3 matrix transformation using a GSL matrix.
void floatSwapBytes(float *inFloat)
void normalise()
Make point unit magnitude, maintaining direction.
Point3D operator*=(const float scale)
*= operator, multiplies the whole Point3D by a scalar
bool operator==(const Point3D &pt) const
Equality operator.
const Point3D operator-() const
Negation, Returns a Point3D object with the negative of the previous value.
void add(const Point3D &obj)
Add a point to this, without generating a return value.
const Point3D & operator=(const Point3D &pt)
Assignment operator.
bool stream_cast(T1 &result, const T2 &obj)
Template function to cast and object to another by the stringstream.
const Point3D operator/(float scale) const
Scalar division of Point3D by scale (X/scale, Y/scale, Z/scale)
bool insideBox(const Point3D &farPoint) const
Is this point inside a box bounded by orign and farPoint?
float dotProd(const Point3D &pt) const
Calculate the dot product of this and another point.
void extend(float distance)
Extend the vector by the specified distance.
static void getCentroid(const std::vector< Point3D > &pts, Point3D &p)
find the centroid of a set of points