QhullHyperplane.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/QhullHyperplane.cpp#5 $$Change: 1382 $
00005 ** $DateTime: 2011/05/14 10:45:42 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 #include "QhullHyperplane.h"
00010 #include "QhullPoint.h"
00011 
00012 #include <iostream>
00013 
00014 
00015 #ifdef _MSC_VER  // Microsoft Visual C++ -- warning level 4
00016 #endif
00017 
00018 namespace orgQhull {
00019 
00020 #//Conversion
00021 
00022 // See qt-qhull.cpp for QList conversions
00023 
00024 #ifndef QHULL_NO_STL
00025 std::vector<coordT> QhullHyperplane::
00026 toStdVector() const
00027 {
00028     QhullHyperplaneIterator i(*this);
00029     std::vector<coordT> fs;
00030     while(i.hasNext()){
00031         fs.push_back(i.next());
00032     }
00033     fs.push_back(hyperplane_offset);
00034     return fs;
00035 }//toStdVector
00036 #endif //QHULL_NO_STL
00037 
00038 #//Value
00039 
00042 // qh_distplane [geom.c], QhullFacet::distance, and QhullHyperplane::distance are copies
00043 //    Does not support RANDOMdist or logging
00044 double QhullHyperplane::
00045 distance(const QhullPoint &p) const
00046 {
00047     const coordT *point= p.coordinates();
00048     int dim= p.dimension();
00049     QHULL_ASSERT(dim==dimension());
00050     const coordT *normal= coordinates();
00051     double dist;
00052 
00053     switch (dim){
00054   case 2:
00055       dist= offset() + point[0] * normal[0] + point[1] * normal[1];
00056       break;
00057   case 3:
00058       dist= offset() + point[0] * normal[0] + point[1] * normal[1] + point[2] * normal[2];
00059       break;
00060   case 4:
00061       dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3];
00062       break;
00063   case 5:
00064       dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4];
00065       break;
00066   case 6:
00067       dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5];
00068       break;
00069   case 7:
00070       dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5]+point[6]*normal[6];
00071       break;
00072   case 8:
00073       dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5]+point[6]*normal[6]+point[7]*normal[7];
00074       break;
00075   default:
00076       dist= offset();
00077       for (int k=dim; k--; )
00078           dist += *point++ * *normal++;
00079       break;
00080     }
00081     return dist;
00082 }//distance
00083 
00084 double QhullHyperplane::
00085 norm() const {
00086     double d= 0.0;
00087     const coordT *c= coordinates();
00088     for (int k=dimension(); k--; ){
00089         d += *c * *c;
00090         ++c;
00091     }
00092     return sqrt(d);
00093 }//norm
00094 
00095 #//Operator
00096 
00097 bool QhullHyperplane::
00098 operator==(const QhullHyperplane &other) const
00099 {
00100     if(hyperplane_dimension!=other.hyperplane_dimension){
00101         return false;
00102     }
00103     double d= fabs(hyperplane_offset-other.hyperplane_offset);
00104     if(d>UsingLibQhull::globalDistanceEpsilon()){
00105         return false;
00106     }
00107     const coordT *c= hyperplane_coordinates;
00108     const coordT *c2= other.hyperplane_coordinates;
00109     if(c==c2){
00110         return true;
00111     }
00112     double dist2= 0.0;
00113     for(int k= hyperplane_dimension; k--; ){
00114         double diff= *c++ - *c2++;
00115         dist2 += diff*diff;
00116     }
00117     if(dist2 > UsingLibQhull::globalAngleEpsilon()){
00118         return false;
00119     }
00120     return true;
00121 }//operator==
00122 
00123 #//GetSet
00124 
00125 }//namespace orgQhull
00126 
00127 #//Global functions
00128 
00129 using std::ostream;
00130 using orgQhull::QhullHyperplane;
00131 using orgQhull::UsingLibQhull;
00132 
00133 #//operator<<
00134 
00135 ostream &
00136 operator<<(ostream &os, const QhullHyperplane &p)
00137 {
00138     os << p.print();
00139     return os;
00140 }
00141 
00142 ostream &
00143 operator<<(ostream &os, const QhullHyperplane::PrintHyperplane &pr)
00144 {
00145     QhullHyperplane p= *pr.hyperplane;
00146     if(pr.print_message){
00147         os << pr.print_message;
00148     }
00149     const realT *c= p.coordinates();
00150     for(int k=p.dimension(); k--; ){
00151         realT r= *c++;
00152         if(pr.print_message){
00153             os << " " << r; // FIXUP QH11010 %8.4g
00154         }else{
00155             os << " " << r; // FIXUP QH11010 qh_REAL_1
00156         }
00157     }
00158     if(pr.hyperplane_offset_message){
00159         os << pr.hyperplane_offset_message << " " << p.offset();
00160     }else{
00161         os << " " << p.offset();
00162     }
00163     os << std::endl;
00164     return os;
00165 }//PrintHyperplane
00166 


libqhull-ours
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:11