LR-splines  0.5
Meshline.cpp
Go to the documentation of this file.
00001 
00002 #include "LRSpline/Meshline.h"
00003 #include "LRSpline/Element.h"
00004 #include "LRSpline/Basisfunction.h"
00005 #include <cmath>
00006 
00007 namespace LR {
00008 
00009 #define DOUBLE_TOL 1e-14
00010 
00011 Meshline::Meshline() {
00012         span_u_line_  = false;
00013         const_par_    = 0;
00014         start_        = 0;
00015         stop_         = 0;
00016         multiplicity_ = 0;
00017         type_         = INITIAL;
00018 }
00019 
00020 Meshline::Meshline(bool span_u_line, double const_par, double start, double stop, int multiplicity) {
00021         span_u_line_  =  span_u_line   ;
00022         const_par_    =  const_par     ;
00023         start_        =  start         ;
00024         stop_         =  stop          ;
00025         multiplicity_ =  multiplicity  ;
00026         type_         =  INITIAL       ;
00027 }
00028 
00029 Meshline::~Meshline() {
00030 }
00031 
00032 
00033 Meshline* Meshline::copy() {
00034          Meshline *returnvalue     = new Meshline();
00035          
00036          returnvalue->span_u_line_ = this->span_u_line_;
00037          returnvalue->const_par_   = this->const_par_;
00038          returnvalue->start_       = this->start_;
00039          returnvalue->stop_        = this->stop_;
00040          returnvalue->multiplicity_= this->multiplicity_;
00041          returnvalue->type_        = this->type_;
00042          return returnvalue;
00043 }
00044 
00045 int Meshline::nKnotsIn(Basisfunction *basis) const {
00046         int hits = 0;
00047         if(span_u_line_) {
00048                 for(int i=0; i<=basis->getOrder(1); i++)
00049                         if( fabs((*basis)[1][i] - const_par_) < DOUBLE_TOL )
00050                                 hits++;
00051         } else { // span-v_line
00052                 for(int i=0; i<=basis->getOrder(0); i++)
00053                         if( fabs((*basis)[0][i] - const_par_) < DOUBLE_TOL)
00054                                 hits++;
00055         }
00056         return hits;
00057 }
00058 
00059 bool Meshline::touches(Element *el) const {
00060         if(span_u_line_) {
00061                 if( el->vmin() < const_par_ && const_par_ < el->vmax() &&
00062                    (start_ == el->umax()    || el->umin() == stop_))
00063                         return  true;
00064         } else { // span-v line
00065                 if( el->umin() < const_par_ && const_par_ < el->umax() &&
00066                    (start_ == el->vmax()    || el->vmin() == stop_))
00067                         return  true;
00068         }
00069         return false;
00070 }
00071 
00072 bool Meshline::splits(Element *el) const {
00073         if(span_u_line_) {
00074                 if( el->vmin() < const_par_ && const_par_ < el->vmax() &&
00075                     start_ <= el->umin()    && el->umax() <= stop_)
00076                         return  true;
00077         } else { // span-v line
00078                 if( el->umin() < const_par_ && const_par_ < el->umax() &&
00079                     start_ <= el->vmin()    && el->vmax() <= stop_)
00080                         return  true;
00081         }
00082         return false;
00083 }
00084 
00085 bool Meshline::touches(Basisfunction *basis) const {
00086         if(span_u_line_) {
00087                 if( (*basis)[1][0] < const_par_ && const_par_ < (*basis)[1][basis->getOrder(1)] &&
00088                    (start_ < (*basis)[0][basis->getOrder(0)]  || (*basis)[0][0] < stop_))
00089                         return true;
00090         } else { // span-v line
00091                 if( (*basis)[0][0] < const_par_ && const_par_ < (*basis)[0][basis->getOrder(0)] &&
00092                    (start_ < (*basis)[1][basis->getOrder(1)]  || (*basis)[1][0] < stop_))
00093                         return true;
00094         }
00095         return false;
00096 }
00097 
00098 bool Meshline::splits(Basisfunction *basis) const {
00099         if(span_u_line_) {
00100                 if( (*basis)[1][0] < const_par_ && const_par_ < (*basis)[1][basis->getOrder(1)] &&
00101                     start_ <= (*basis)[0][0]  && (*basis)[0][basis->getOrder(0)] <= stop_)
00102                         return  true;
00103         } else { // span-v line
00104                 if( (*basis)[0][0] < const_par_ && const_par_ < (*basis)[0][basis->getOrder(0)] &&
00105                     start_ <= (*basis)[1][0]  && (*basis)[1][basis->getOrder(1)] <= stop_)
00106                         return  true;
00107         }
00108         return false;
00109 }
00110 
00111 bool Meshline::is_spanning_u() const {
00112         return span_u_line_;
00113 }
00114 
00115 bool Meshline::operator==(const Meshline &other) const {
00116         return span_u_line_  == other.span_u_line_ &&
00117                const_par_    == other.const_par_ &&
00118                start_        == other.start_ &&
00119                stop_         == other.stop_ &&
00120                multiplicity_ == other.multiplicity_;
00121         
00122 }
00123 
00124 // convenience macro for reading formated input
00125 #define ASSERT_NEXT_CHAR(c) {ws(is); nextChar = is.get(); if(nextChar!=c) { std::cerr << "Error parsing meshline\n"; std::cout << is; exit(325); } ws(is); }
00126 void Meshline::read(std::istream &is) {
00127         char nextChar;
00128         ws(is);
00129         nextChar = is.peek();
00130         if(nextChar == '[') { // first parametric direction interval => const v
00131                 ASSERT_NEXT_CHAR('[');
00132                 span_u_line_ = true;
00133                 is >> start_;
00134                 ASSERT_NEXT_CHAR(',');
00135                 is >> stop_;
00136                 ASSERT_NEXT_CHAR(']');
00137                 ASSERT_NEXT_CHAR('x');
00138                 is >> const_par_;
00139                 ASSERT_NEXT_CHAR('(');
00140                 is >> multiplicity_;
00141                 ASSERT_NEXT_CHAR(')');
00142         } else {
00143                 span_u_line_ = false;
00144                 is >> const_par_;
00145                 ASSERT_NEXT_CHAR('x');
00146                 ASSERT_NEXT_CHAR('[');
00147                 is >> start_;
00148                 ASSERT_NEXT_CHAR(',');
00149                 is >> stop_;
00150                 ASSERT_NEXT_CHAR(']');
00151                 ASSERT_NEXT_CHAR('(');
00152                 is >> multiplicity_;
00153                 ASSERT_NEXT_CHAR(')');
00154         }
00155 }
00156 #undef ASSERT_NEXT_CHAR
00157 
00158 void Meshline::write(std::ostream &os) const {
00159         if(span_u_line_) 
00160                 os <<  "[" << start_ << ", " << stop_ << "] x " << const_par_ << " (" << multiplicity_ << ")";
00161         else // span-v line
00162                 os << const_par_ << " x [" << start_ << ", " << stop_ << "] (" << multiplicity_ << ")";
00163 }
00164 
00165 void Meshline::writeMore(std::ostream &os) const {
00166         if(span_u_line_) 
00167                 os <<  "[" << start_ << ", " << stop_ << "] x " << const_par_ << " (" << multiplicity_ << ")";
00168         else // span-v line
00169                 os << const_par_ << " x [" << start_ << ", " << stop_ << "] (" << multiplicity_ << ")";
00170         if(type_ == INITIAL)
00171                 os << " INITIAL";
00172         else if(type_ == NEWLINE)
00173                 os << " NEWLINE";
00174         else if(type_ == MERGING)
00175                 os << " MERGING";
00176         else if(type_ == ELONGATION)
00177                 os << " ELONGATION";
00178 }
00179 
00180 #undef DOUBLE_TOL
00181 
00182 } // end namespace LR
00183 
00184