QhullPoint.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2009-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/libqhullcpp/QhullPoint.cpp#3 $$Change: 1348 $
00005 ** $DateTime: 2011/03/25 23:54:58 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 #include "UsingLibQhull.h"
00010 #include "QhullPoint.h"
00011 
00012 #include <iostream>
00013 #include <algorithm>
00014 
00015 #ifdef _MSC_VER  // Microsoft Visual C++ -- warning level 4
00016 #endif
00017 
00018 namespace orgQhull {
00019 
00020 #//Class public variables and methods
00021 
00023 int QhullPoint::
00024 id(int qhRunId, int dimension, const coordT *c)
00025 {
00026     QHULL_UNUSED(dimension);
00027 
00028     if(UsingLibQhull::hasPoints()){
00029         if(qhRunId==UsingLibQhull::NOqhRunId){
00030             const coordT *pointsEnd;
00031             int dim;
00032             const coordT *points= UsingLibQhull::globalPoints(&dim, &pointsEnd);
00033             if(c>=points && c<pointsEnd){
00034                 int offset= (int)(c-points); // WARN64
00035                 return offset/dim;
00036             }
00037         }else{
00038             UsingLibQhull q(qhRunId);
00039             // NOerrors from qh_pointid or qh_setindex
00040             return qh_pointid(const_cast<coordT *>(c));
00041         }
00042     }
00043     long long i=(long long)c;
00044     return (int)i; // WARN64
00045 }//id
00046 
00047 #//Conversion
00048 
00049 // See qt-qhull.cpp for QList conversion
00050 
00051 #ifndef QHULL_NO_STL
00052 std::vector<coordT> QhullPoint::
00053 toStdVector() const
00054 {
00055     QhullPointIterator i(*this);
00056     std::vector<coordT> vs;
00057     while(i.hasNext()){
00058         vs.push_back(i.next());
00059     }
00060     return vs;
00061 }//toStdVector
00062 #endif //QHULL_NO_STL
00063 
00064 #//Operator
00065 
00066 bool QhullPoint::
00067 operator==(const QhullPoint &other) const
00068 {
00069     if(point_dimension!=other.point_dimension){
00070         return false;
00071     }
00072     const coordT *c= point_coordinates;
00073     const coordT *c2= other.point_coordinates;
00074     if(c==c2){
00075         return true;
00076     }
00077     double dist2= 0.0;
00078     for(int k= point_dimension; k--; ){
00079         double diff= *c++ - *c2++;
00080         dist2 += diff*diff;
00081     }
00082     double epsilon= UsingLibQhull::globalDistanceEpsilon();
00083     // std::cout << "DEBUG dist2 " << dist2 << " epsilon^2 " << epsilon*epsilon << std::endl;
00084     return (dist2<=(epsilon*epsilon));
00085 }//operator==
00086 
00087 
00088 #//Value
00089 
00091 double QhullPoint::
00092 distance(const QhullPoint &p) const
00093 {
00094     const coordT *c= coordinates();
00095     const coordT *c2= p.coordinates();
00096     int dim= dimension();
00097     QHULL_ASSERT(dim==p.dimension());
00098     double dist;
00099 
00100     switch(dim){
00101   case 2:
00102       dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]);
00103       break;
00104   case 3:
00105       dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]);
00106       break;
00107   case 4:
00108       dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]);
00109       break;
00110   case 5:
00111       dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]);
00112       break;
00113   case 6:
00114       dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]);
00115       break;
00116   case 7:
00117       dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]) + (c[6]-c2[6])*(c[6]-c2[6]);
00118       break;
00119   case 8:
00120       dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]) + (c[6]-c2[6])*(c[6]-c2[6]) + (c[7]-c2[7])*(c[7]-c2[7]);
00121       break;
00122   default:
00123       dist= 0.0;
00124       for(int k=dim; k--; ){
00125           dist += (*c - *c2) * (*c - *c2);
00126           ++c;
00127           ++c2;
00128       }
00129       break;
00130     }
00131     return sqrt(dist);
00132 }//distance
00133 
00134 }//namespace orgQhull
00135 
00136 #//Global functions
00137 
00138 using std::ostream;
00139 using orgQhull::QhullPoint;
00140 using orgQhull::UsingLibQhull;
00141 
00142 #//operator<<
00143 
00144 ostream &
00145 operator<<(ostream &os, const QhullPoint &p)
00146 {
00147     os << p.printWithIdentifier(UsingLibQhull::NOqhRunId, "");
00148     return os;
00149 }
00150 
00152 ostream &
00153 operator<<(ostream &os, const QhullPoint::PrintPoint &pr)
00154 {
00155     QhullPoint p= *pr.point; 
00156     int i= p.id(pr.run_id);
00157     if(pr.point_message){
00158         if(*pr.point_message){
00159             os << pr.point_message << " ";
00160         }
00161         if(pr.with_identifier && (i!=-1)){
00162             os << "p" << i << ": ";
00163         }
00164     }
00165     const realT *c= p.coordinates();
00166     for(int k=p.dimension(); k--; ){
00167         realT r= *c++;
00168         if(pr.point_message){
00169             os << " " << r; // FIXUP QH11010 %8.4g
00170         }else{
00171             os << " " << r; // FIXUP QH11010 qh_REAL_1
00172         }
00173     }
00174     os << std::endl;
00175     return os;
00176 }//printPoint
00177 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


libqhull
Author(s): Robert Krug
autogenerated on Tue Jun 18 2013 12:38:50