void ReadCurve(std::ifstream & is, Curve_2 & cv) { // Read a line from the input file. char one_line[128]; skip_comments (is, one_line); std::string stringvalues(one_line); std::istringstream str_line (stringvalues, std::istringstream::in); // Get the arc type. // Supported types are: 'f' - Full ellipse (or circle). // 'e' - Elliptic arc (or circular arc). // 's' - Line segment. char type; bool is_circle = false; // Is this a circle. Rat_circle_2 circle; Rational r, s, t, u, v, w; // The conic coefficients. str_line >> type; // An ellipse (full ellipse or a partial ellipse): if (type == 'f' || type == 'F' || type == 'e' || type == 'E') { // Read the ellipse (using the format "a b x0 y0"): // // x - x0 2 y - y0 2 // ( -------- ) + ( -------- ) = 1 // a b // int a, b, x0, y0; str_line >> a >> b >> x0 >> y0; Rational a_sq = Rational(a*a); Rational b_sq = Rational(b*b); if (a == b) { is_circle = true; circle = Rat_circle_2 (Rat_point_2 (Rational(x0), Rational(y0)), Rational(a*b)); } else { r = b_sq; s = a_sq; t = 0; u = Rational(-2*x0*b_sq); v = Rational(-2*y0*a_sq); w = Rational(x0*x0*b_sq + y0*y0*a_sq - a_sq*b_sq); } if (type == 'f' || type == 'F') { // Create a full ellipse (or circle). if (is_circle) cv = Curve_2 (circle); else cv = Curve_2 (r, s, t, u, v, w); } else { // Read the endpointd of the arc. int x1, y1, x2, y2; str_line >> x1 >> y1 >> x2 >> y2; Point_2 source = Point_2 (Algebraic(x1), Algebraic(y1)); Point_2 target = Point_2 (Algebraic(x2), Algebraic(y2)); // Create the arc. Note that it is always clockwise oriented. if (is_circle) cv = Curve_2 (circle, CGAL::CLOCKWISE, source, target); else cv = Curve_2 (r, s, t, u, v, w, CGAL::CLOCKWISE, source, target); } }
void sdpPlayerParseStateTableData::LoadDataFromFile(vctPlot2DBase::Signal * SignalHandle ,double TimeStampForSearch, double VisualRange, bool ResetSignalBuffer) { double MinimumTime, MaxmumTime; std::string TempLine; std::vector <std::string> Token; std::vector <double> TimeIndex; size_t LeftBoundaryPosition = 0, RightBoundaryPosition = 0; double LeftBoundaryTime = 0.0, RightBoundaryTime = 0.0; size_t ElementsNumber =0, SignalBufferSize = 0; if (ResetSignalBuffer) { ElementsNumber = SignalHandle->GetNumberOfPoints(); SignalBufferSize = SignalHandle->GetSize(); SignalHandle->SetSize(SignalBufferSize); } // Get Max & Minimum Time std::ifstream inf(Header.FilePath.c_str()); std::getline(inf, TempLine); Tokenize(TempLine, Token, Header.Delimiter); MinimumTime = strtod(Token.at(IndexOfTimeField).c_str() , NULL); TimeBaseOffset = MinimumTime; inf.close(); Token.clear(); Tokenize(Index.at(Index.size()-1).LineAtIndex, Token, Header.Delimiter); MaxmumTime =strtod(Token.at(IndexOfTimeField).c_str() , NULL); MinimumTime -= TimeBaseOffset; MaxmumTime -= TimeBaseOffset; LeftBoundaryTime = (TimeStampForSearch-(1.5*VisualRange)); if(TimeStampForSearch!=0) LeftBoundaryTime -= TimeBaseOffset; LeftBoundaryTime = (LeftBoundaryTime<MinimumTime)?MinimumTime:LeftBoundaryTime; RightBoundaryTime = (TimeStampForSearch+(1.5*VisualRange)); if(TimeStampForSearch!=0) RightBoundaryTime -= TimeBaseOffset; RightBoundaryTime = (RightBoundaryTime>MaxmumTime)?MaxmumTime:RightBoundaryTime; if ( RightBoundaryTime < MinimumTime || LeftBoundaryTime > MaxmumTime || LeftBoundaryTime >= RightBoundaryTime) return; // find where is the LeftBoundaryPosition & RightBoundaryPosition // where is TimeStampForSearch postition in index file? double min, max; SignalHandle->ComputeDataRangeX(min,max,true); if (min<= LeftBoundaryTime && (LeftBoundaryTime >= MinimumTime && !ResetSignalBuffer)) { LeftBoundaryPosition = GetDataPositionFromFile(max+TimeBaseOffset, IndexOfTimeField); RightBoundaryPosition = GetDataPositionFromFile(RightBoundaryTime+TimeBaseOffset, IndexOfTimeField); if (LeftBoundaryPosition >= RightBoundaryPosition) return; // load Data from File: [LeftBoundaryPosition, RightBoundaryPosition] inf.open(Header.FilePath.c_str(), std::ios_base::binary | std::ios_base::in); inf.seekg(LeftBoundaryPosition, std::ios::beg); double TimeElement = 0, DataElement; char *StringBuffer = new char [RightBoundaryPosition - LeftBoundaryPosition]; inf.read(StringBuffer, RightBoundaryPosition - LeftBoundaryPosition); std::string stringvalues(StringBuffer, RightBoundaryPosition - LeftBoundaryPosition); std::istringstream iss (stringvalues); inf.close(); while(1) { std::string TempLine = "aaaa"; std::vector <std::string> Token; std::getline(iss, TempLine); Tokenize(TempLine, Token, Header.Delimiter); if (Token.size() < IndexOfDataField || Token.size() < IndexOfTimeField || iss.eof()) break; DataElement = strtod(Token.at(IndexOfDataField).c_str() , NULL); TimeElement = strtod(Token.at(IndexOfTimeField).c_str() , NULL); // SignalHandle->GetNumberOfPoints(ElementsNumber, SignalBufferSize); ElementsNumber = SignalHandle->GetNumberOfPoints(); SignalBufferSize = SignalHandle->GetSize(); if (ElementsNumber == SignalBufferSize && (LeftBoundaryTime <= min)) { // Buffer overflow, we need to add size SignalBufferSize *= 1.5; SignalHandle->Resize(SignalBufferSize); } TimeElement -= TimeBaseOffset; SignalHandle->AppendPoint(vctDouble2(TimeElement,DataElement)); SignalHandle->ComputeDataRangeX(min,max,true); } // should we resize to a smaller one? //SignalHandle->GetNumberOfPoints(ElementsNumber, SignalBufferSize); ElementsNumber = SignalHandle->GetNumberOfPoints(); SignalBufferSize = SignalHandle->GetSize(); if (SignalBufferSize > ElementsNumber*1.5) { SignalHandle->Resize(ElementsNumber*1.5); } delete StringBuffer; } else if (min > RightBoundaryTime || max < LeftBoundaryTime) { // if every thing is not in our range, reset buffer and reload everything //SignalHandle->GetNumberOfPoints(ElementsNumber, SignalBufferSize); ElementsNumber = SignalHandle->GetNumberOfPoints(); SignalBufferSize = SignalHandle->GetSize(); SignalHandle->SetSize(SignalBufferSize); LeftBoundaryPosition = GetDataPositionFromFile(LeftBoundaryTime+TimeBaseOffset ,IndexOfTimeField); RightBoundaryPosition = GetDataPositionFromFile(RightBoundaryTime+TimeBaseOffset, IndexOfTimeField); if (LeftBoundaryPosition >= RightBoundaryPosition) return; // load Data from File: [LeftBoundaryPosition, RightBoundaryPosition] inf.open(Header.FilePath.c_str(), std::ios_base::binary | std::ios_base::in); inf.seekg(LeftBoundaryPosition, std::ios::beg); double TimeElement = 0, DataElement; char *StringBuffer = new char [RightBoundaryPosition - LeftBoundaryPosition]; inf.read(StringBuffer, RightBoundaryPosition - LeftBoundaryPosition); std::string stringvalues(StringBuffer, RightBoundaryPosition - LeftBoundaryPosition); std::istringstream iss (stringvalues); inf.close(); while(1) { std::string TempLine; std::vector <std::string> Token; std::getline(iss, TempLine); Tokenize(TempLine, Token, Header.Delimiter); if (Token.size() < IndexOfDataField || Token.size() < IndexOfTimeField || iss.eof()) break; DataElement = strtod(Token.at(IndexOfDataField).c_str() , NULL); TimeElement = strtod(Token.at(IndexOfTimeField).c_str() , NULL); //SignalHandle->GetNumberOfPoints(ElementsNumber, SignalBufferSize); ElementsNumber = SignalHandle->GetNumberOfPoints(); SignalBufferSize = SignalHandle->GetSize(); if (ElementsNumber == SignalBufferSize && (LeftBoundaryTime <= min)) { // Buffer overflow, we need to add size SignalBufferSize *= 1.5; SignalHandle->Resize(SignalBufferSize); } TimeElement -= TimeBaseOffset; SignalHandle->AppendPoint(vctDouble2(TimeElement,DataElement)); SignalHandle->ComputeDataRangeX(min,max,true); } // should we resize to a smaller one? //SignalHandle->GetNumberOfPoints(ElementsNumber, SignalBufferSize); ElementsNumber = SignalHandle->GetNumberOfPoints(); SignalBufferSize = SignalHandle->GetSize(); if (SignalBufferSize > ElementsNumber*1.5) { SignalHandle->Resize(ElementsNumber*1.5); } delete StringBuffer; } else{ // reload only what we need //SignalHandle->GetNumberOfPoints(ElementsNumber, SignalBufferSize); ElementsNumber = SignalHandle->GetNumberOfPoints(); SignalBufferSize = SignalHandle->GetSize(); SignalHandle->Resize(SignalBufferSize); LeftBoundaryPosition = GetDataPositionFromFile(LeftBoundaryTime+TimeBaseOffset ,IndexOfTimeField); //********************************************************************************************* // SECTION ONE, prepend data //********************************************************************************************* RightBoundaryPosition = GetDataPositionFromFile(min+TimeBaseOffset ,IndexOfTimeField); { inf.open(Header.FilePath.c_str(), std::ios_base::binary | std::ios_base::in); inf.seekg(LeftBoundaryPosition, std::ios::beg); double TimeElement = 0, DataElement; char *StringBuffer = new char [RightBoundaryPosition - LeftBoundaryPosition]; inf.read(StringBuffer, RightBoundaryPosition - LeftBoundaryPosition); std::string stringvalues(StringBuffer, RightBoundaryPosition - LeftBoundaryPosition); std::istringstream iss (stringvalues); inf.close(); std::vector <double> TimeDataBuffer; TimeDataBuffer.clear(); while(1) { std::string TempLine; std::vector <std::string> Token; std::getline(iss, TempLine); Tokenize(TempLine, Token, Header.Delimiter); if (Token.size() < IndexOfDataField || Token.size() < IndexOfTimeField || iss.eof()) break; DataElement = strtod(Token.at(IndexOfDataField).c_str() , NULL); TimeElement = strtod(Token.at(IndexOfTimeField).c_str() , NULL); TimeElement -= TimeBaseOffset; TimeDataBuffer.push_back(TimeElement); TimeDataBuffer.push_back(DataElement); } // reset buffer size for prepend data //SignalHandle->GetNumberOfPoints(ElementsNumber, SignalBufferSize); ElementsNumber = SignalHandle->GetNumberOfPoints(); SignalBufferSize = SignalHandle->GetSize(); if ((SignalBufferSize - ElementsNumber) < TimeDataBuffer.size()) { SignalHandle->Resize(SignalBufferSize+ TimeDataBuffer.size()); } if (!TimeDataBuffer.empty()) SignalHandle->PrependArray((double*) &TimeDataBuffer[0], TimeDataBuffer.size()); delete StringBuffer; } //********************************************************************************************* // SECTION 2, append data, we let PLAY to load data ahead //********************************************************************************************* } return; }