void DebugCLI::displayLines(int line, int count) { if (!lineStart(0)) { if (currentFile) core->console << currentFile; else core->console << "<unknown>"; core->console <<":"<<line<<" "; } else { int lineAt = line; while(count-- > 0) { char* ptr = lineStart(lineAt-1); if (!ptr) { #if WRAP_AROUND lineAt = 1; count++; // reset line number to beginning skip this iteration #else break; #endif } else { core->console << (lineAt) << ": "; while (*ptr && *ptr != '\n') core->console << *ptr++; core->console << '\n'; lineAt++; } } } }
void DebugCLI::displayLines(int line, int count) { if (!lineStart(0)) { core->console << "No source available for current instruction\n"; } else { // Display status int lineAt = line; while(count-- > 0) { char* ptr = lineStart(lineAt-1); if (!ptr) { #if WRAP_AROUND lineAt = 1; count++; // reset line number to beginning skip this iteration #else break; #endif } else { core->console << (lineAt) << ": "; while (*ptr && *ptr != '\n') core->console << *ptr++; core->console << '\n'; lineAt++; } } } }
void EDA_DRAW_PANEL::DrawCrossHair( wxDC* aDC, EDA_COLOR_T aColor ) { if( m_cursorLevel != 0 || aDC == NULL || !m_showCrossHair ) return; wxPoint cursor = GetParent()->GetCrossHairPosition(); GRSetDrawMode( aDC, GR_XOR ); if( GetParent()->m_cursorShape != 0 ) // Draws full screen crosshair. { wxSize clientSize = GetClientSize(); // Y axis wxPoint lineStart( cursor.x, aDC->DeviceToLogicalY( 0 ) ); wxPoint lineEnd( cursor.x, aDC->DeviceToLogicalY( clientSize.y ) ); GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor ); // X axis lineStart = wxPoint( aDC->DeviceToLogicalX( 0 ), cursor.y ); lineEnd = wxPoint( aDC->DeviceToLogicalX( clientSize.x ), cursor.y ); GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor ); } else { int len = aDC->DeviceToLogicalXRel( CURSOR_SIZE ); GRLine( &m_ClipBox, aDC, cursor.x - len, cursor.y, cursor.x + len, cursor.y, 0, aColor ); GRLine( &m_ClipBox, aDC, cursor.x, cursor.y - len, cursor.x, cursor.y + len, 0, aColor ); } }
void RGB24Buffer::drawLine(int x1, int y1, int x2, int y2, RGBColor color ) { Rectangle<int> rect; rect.corner = Vector2d<int>(0,0); rect.size = Vector2d<int>(w - 1,h - 1); Vector2d32 lineStart(x1,y1); Vector2d32 lineEnd(x2,y2); rect.clipCohenSutherland(lineStart, lineEnd); drawLineSimple(lineStart.x(), lineStart.y(),lineEnd.x(), lineEnd.y(), color); }
void IntersectionUnitTests::IntersectionTestFail() { Intersection intersection; Vector2 lineStart(1,1); Vector2 lineEnd(2,2); Vector2 circleCentre(400, 200); float circleRadius = 1.0f; TEST_ASSERT(intersection.LineCircleIntersection(lineStart,lineEnd,circleCentre, circleRadius) == false); }
void IntersectionUnitTests::IntersectionTest() { Intersection intersection; Vector2 lineStart(5,10); Vector2 lineEnd(2,4); Vector2 circleCentre(3,6); float circleRadius = 2.0f; TEST_ASSERT(intersection.LineCircleIntersection(lineStart,lineEnd,circleCentre, circleRadius) == true); }
void IntersectionUnitTests::IntersectionTestBoundaryPass() { Intersection intersection; Vector2 lineStart(3,0); Vector2 lineEnd(3,4); Vector2 circleCentre(2, 2); float circleRadius = 1.0f; TEST_ASSERT(intersection.LineCircleIntersection(lineStart,lineEnd,circleCentre, circleRadius) == true); }
void TEditor::newLine() { const char crlf[] = "\x0D\x0A"; ushort p = lineStart(curPtr); ushort i = p; while( i < curPtr && ( (buffer[i] == ' ') || (buffer[i] == '\x9')) ) i++; insertText(crlf, 2, False); if( autoIndent == True ) insertText( &buffer[p], i - p, False); }
int main(int, char**){ MyImage image; //Set up parameters for the line segment vec2 lineStart(100, 200); vec2 lineEnd(500, 220); //Line drawing - midpoint algorithm //determine if we do a x-loop or y-loop //TODO: Rasterize the line using the mid-point algorithm image.show(); // image.save("output.png"); ///< Does not work on Windows! return EXIT_SUCCESS; }
void TestSnapStrategy::testProject() { //tests for positive point values but backwards leaning line ExtensionSnapStrategy toTestOne; qreal toCompWithOne = -1; QPointF lineStart(4,4); QPointF lineEnd(2,2); QPointF comparisonPoint(6,6); qreal resultingRealOne = toTestOne.project(lineStart, lineEnd, comparisonPoint); QCOMPARE(resultingRealOne, toCompWithOne); //testing for for negative point values ExtensionSnapStrategy toTestTwo; qreal toCompWithTwo = -4; QPointF lineStart_2(-2,-2); QPointF lineEnd_2(-4,-4); QPointF comparisonPoint_2(6,6); qreal resultingRealTwo = toTestTwo.project(lineStart_2, lineEnd_2, comparisonPoint_2); QCOMPARE(resultingRealTwo, toCompWithTwo); //testing for negative and positive point values ExtensionSnapStrategy toTestThree; qreal toCompWithThree = (10*(6/sqrt(72.0)) + 10*(6/sqrt(72.0))) / sqrt(72.0); //diffLength = sqrt(72), scalar = (10*(6/sqrt(72)) + 10*(6/sqrt(72))) QPointF lineStart_3(-2,-2); QPointF lineEnd_3(4, 4); QPointF comparisonPoint_3(8,8); qreal resultingRealThree = toTestThree.project(lineStart_3, lineEnd_3, comparisonPoint_3); QCOMPARE(resultingRealThree, toCompWithThree); //Below we test the formula itself for the dot-product by using values we know return t=0.5 //Formula for how to use the t value is: //ProjectionPoint = lineStart*(1-resultingReal) + resultingReal*lineEnd; (this is the formula used in BoundingBoxSnapStrategy::squareDistanceToLine()) //Note: The angle of the line from projection point to comparison point is always 90 degrees ExtensionSnapStrategy toTestFour; qreal toCompWithFour = 0.5; QPointF lineStart_4(2,1); QPointF lineEnd_4(6,3); QPointF comparisonPoint_4(3,4); qreal resultingRealFour = toTestFour.project(lineStart_4, lineEnd_4, comparisonPoint_4); QCOMPARE(resultingRealFour, toCompWithFour); }
void EDA_DRAW_PANEL::DrawCrossHair( wxDC* aDC, COLOR4D aColor ) { if( m_cursorLevel != 0 || aDC == NULL || !m_showCrossHair ) return; wxPoint cursor = GetParent()->GetCrossHairPosition(); #ifdef USE_WX_GRAPHICS_CONTEXT // Normally cursor color is set to white, so when it is xored with white // background, it is painted black effectively. wxGraphicsContext does not have // xor operation, so we need to invert the color manually. aColor.Invert(); #else GRSetDrawMode( aDC, GR_XOR ); #endif if( GetParent()->GetGalDisplayOptions().m_fullscreenCursor ) { wxSize clientSize = GetClientSize(); // Y axis wxPoint lineStart( cursor.x, aDC->DeviceToLogicalY( 0 ) ); wxPoint lineEnd( cursor.x, aDC->DeviceToLogicalY( clientSize.y ) ); GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor ); // X axis lineStart = wxPoint( aDC->DeviceToLogicalX( 0 ), cursor.y ); lineEnd = wxPoint( aDC->DeviceToLogicalX( clientSize.x ), cursor.y ); GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor ); } else { int len = aDC->DeviceToLogicalXRel( CURSOR_SIZE ); GRLine( &m_ClipBox, aDC, cursor.x - len, cursor.y, cursor.x + len, cursor.y, 0, aColor ); GRLine( &m_ClipBox, aDC, cursor.x, cursor.y - len, cursor.x, cursor.y + len, 0, aColor ); } }
void TEditor::setSelect( ushort newStart, ushort newEnd, Boolean curStart ) { ushort p; if( curStart != 0 ) p = newStart; else p = newEnd; uchar flags = ufUpdate; if( newStart != selStart || newEnd != selEnd ) if( newStart != newEnd || selStart != selEnd ) flags = ufView; if( p != curPtr ) { if( p > curPtr ) { ushort l = p - curPtr; memmove( &buffer[curPtr], &buffer[curPtr + gapLen], l); curPos.y += countLines(&buffer[curPtr], l); curPtr = p; } else { ushort l = curPtr - p; curPtr = p; curPos.y -= countLines(&buffer[curPtr], l); memmove( &buffer[curPtr + gapLen], &buffer[curPtr], l); } drawLine = curPos.y; drawPtr = lineStart(p); curPos.x = charPos(drawPtr, p); delCount = 0; insCount = 0; setBufSize(bufLen); } selStart = newStart; selEnd = newEnd; update(flags); }
void TEditor::doUpdate() { if( updateFlags != 0 ) { setCursor(curPos.x - delta.x, curPos.y - delta.y); if( (updateFlags & ufView) != 0 ) drawView(); else if( (updateFlags & ufLine) != 0 ) drawLines( curPos.y-delta.y, 1, lineStart(curPtr) ); if( hScrollBar != 0 ) hScrollBar->setParams(delta.x, 0, limit.x - size.x, size.x / 2, 1); if( vScrollBar != 0 ) vScrollBar->setParams(delta.y, 0, limit.y - size.y, size.y - 1, 1); if( indicator != 0 ) indicator->setValue(curPos, modified); if( (state & sfActive) != 0 ) updateCommands(); updateFlags = 0; } }
ushort TEditor::lineMove( ushort p, int count ) { ushort i = p; p = lineStart(p); int pos = charPos(p, i); while( count != 0 ) { i = p; if( count < 0 ) { p = prevLine(p); count++; } else { p = nextLine(p); count--; } } if( p != i ) p = charPtr(p, pos); return p; }
// --------------------------------------------------------------- // strategie exploration en passant par la rangee en y = 1350 // --------------------------------------------------------------- bool StrategyLargeAttackCL::preDefinedSkittleExploration2() { LOG_COMMAND("preDefinedLargeSkittleExploration2\n"); MvtMgr->setRobotDirection(MOVE_DIRECTION_FORWARD); bool noRotation = true; Point lineStart(2500, 1500); Point lineEnd(3200, 1500); Move->go2Target(lineStart, MOVE_USE_DEFAULT_GAIN, MOVE_USE_DEFAULT_SPEED, noRotation); Events->wait(evtEndMove); if (!Events->isInWaitResult(EVENTS_MOVE_END)) { // on n'a pas reussi if (checkEndEvents()) return false; // c'est la fin du match? CollisionEnum collision = checkCollisionEvents(); if (collision != COLLISION_NONE) { if (!handleCollision(collision, lineStart, lineEnd)) return false; } else { LOG_WARNING("don't know what caused abort of movement. -> abort predefined exploration\n"); return false; } } else { // go2Target succeeded its movement. Move->rotate(0); // face right border Events->wait(evtEndMove); if (!Events->isInWaitResult(EVENTS_MOVE_END)) { if (checkEndEvents()) return false; // end of match // ok. normally the collision can only be on the left side... CollisionEnum collision = checkCollisionEvents(); if (collision == COLLISION_LEFT) { if (!handleCollision(collision, lineStart, lineEnd)) return false; } else if (collision == COLLISION_NONE) { LOG_WARNING("unhandled event. leaving function\n"); return false; } else { LOG_WARNING("collision, but most likely not a support\n"); return false; } } } bool endOfLine = false; while (!endOfLine) { Move->go2Target(lineEnd); Events->wait(evtEndMove); if (!Events->isInWaitResult(EVENTS_MOVE_END)) { // let's hope it's a support. if (checkEndEvents()) return false; // c'est la fin du match? CollisionEnum collision = checkCollisionEvents(); if (collision != COLLISION_NONE) { if (!handleCollision(collision, lineStart, lineEnd)) return false; } else { LOG_WARNING("don't know what caused abort of movement. -> abort predefined exploration\n"); return false; } if (!RobotPos->isTargetForward(lineEnd)) endOfLine = true; } else { // ok. no more supports detected endOfLine = true; } } LOG_INFO("predefined-large finished.\n"); //alignBorder(); // on recule un petit peu car on ne sais pas ce qu'on va se prendre en // approchant du robot adverse!, mieux vaut tenir que courir MvtMgr->setRobotDirection(MOVE_DIRECTION_BACKWARD); Trajectory t; t.clear(); t.push_back(Point(3144, 1350)); t.push_back(Point(3190, 1700)); Move->followTrajectory(t, TRAJECTORY_BASIC); Events->wait(evtEndMove); if (!Events->isInWaitResult(EVENTS_MOVE_END)) { // on n'a pas reussi // c'est la fin du match? if (checkEndEvents()) return false; // TODO manage collisions return false; } //alignBorder(); // on va droit sur l'adversaire MvtMgr->setRobotDirection(MOVE_DIRECTION_FORWARD); Move->go2Target(Point(3190, 650)); Events->wait(evtEndMove); if (!Events->isInWaitResult(EVENTS_MOVE_END)) { // on n'a pas reussi // c'est la fin du match? if (checkEndEvents()) return false; // TODO manage collisions return false; } // on recule un peu MvtMgr->setRobotDirection(MOVE_DIRECTION_BACKWARD); Move->go2Target(Point(3190, 1050)); Events->wait(evtEndMove); if (!Events->isInWaitResult(EVENTS_MOVE_END)) { // on n'a pas reussi // c'est la fin du match? if (checkEndEvents()) return false; // TODO manage collisions return false; } t.clear(); t.push_back(Point(2550, 1050)); t.push_back(Point(2594, 1650)); t.push_back(Point(3340, 1650)); MvtMgr->setRobotDirection(MOVE_DIRECTION_FORWARD); Move->followTrajectory(t, TRAJECTORY_BASIC); Events->wait(evtEndMove); if (!Events->isInWaitResult(EVENTS_MOVE_END)) { // on n'a pas reussi // c'est la fin du match? if (checkEndEvents()) return false; // TODO manage collisions return false; } MvtMgr->setRobotDirection(MOVE_DIRECTION_BACKWARD); Move->go2Target(Point(3190, 1650)); Events->wait(evtEndMove); if (!Events->isInWaitResult(EVENTS_MOVE_END)) { // on n'a pas reussi // c'est la fin du match? if (checkEndEvents()) return false; // TODO manage collisions return false; } return true; }
void MySQLRecognitionBase::add_error(const std::string &message, ANTLR3_UINT32 token, ANTLR3_MARKER token_start, ANTLR3_UINT32 line, ANTLR3_UINT32 offset_in_line, ANTLR3_MARKER length) { MySQLParserErrorInfo info = { message, token, (size_t)(token_start - (ANTLR3_MARKER)lineStart()), line, offset_in_line, (size_t)length }; d->_error_info.push_back(info); };
ushort TEditor::prevLine( ushort p ) { return lineStart(prevChar(p)); }
void TEditor::handleEvent( TEvent& event ) { TView::handleEvent( event ); convertEvent( event ); Boolean centerCursor = Boolean(!cursorVisible()); uchar selectMode = 0; if( selecting == True || (getShiftState() & 0x03) != 0 ) selectMode = smExtend; switch( event.what ) { case evMouseDown: if( event.mouse.doubleClick == True ) selectMode |= smDouble; do { lock(); if( event.what == evMouseAuto ) { TPoint mouse = makeLocal( event.mouse.where ); TPoint d = delta; if( mouse.x < 0 ) d.x--; if( mouse.x >= size.x ) d.x++; if( mouse.y < 0 ) d.y--; if( mouse.y >= size.y ) d.y++; scrollTo(d.x, d.y); } setCurPtr(getMousePtr(event.mouse.where), selectMode); selectMode |= smExtend; unlock(); } while( mouseEvent(event, evMouseMove + evMouseAuto) ); break; case evKeyDown: if( event.keyDown.charScan.charCode == 9 || ( event.keyDown.charScan.charCode >= 32 && event.keyDown.charScan.charCode < 255 ) ) { lock(); if( overwrite == True && hasSelection() == False ) if( curPtr != lineEnd(curPtr) ) selEnd = nextChar(curPtr); insertText( &event.keyDown.charScan.charCode, 1, False); trackCursor(centerCursor); unlock(); } else return; break; case evCommand: switch( event.message.command ) { case cmFind: find(); break; case cmReplace: replace(); break; case cmSearchAgain: doSearchReplace(); break; default: lock(); switch( event.message.command ) { case cmCut: clipCut(); break; case cmCopy: clipCopy(); // hideSelect(); // JS 12.4.94 break; case cmPaste: clipPaste(); break; case cmUndo: undo(); break; case cmClear: deleteSelect(); break; case cmCharLeft: setCurPtr(prevChar(curPtr), selectMode); break; case cmCharRight: setCurPtr(nextChar(curPtr), selectMode); break; case cmWordLeft: setCurPtr(prevWord(curPtr), selectMode); break; case cmWordRight: setCurPtr(nextWord(curPtr), selectMode); break; case cmLineStart: setCurPtr(lineStart(curPtr), selectMode); break; case cmLineEnd: setCurPtr(lineEnd(curPtr), selectMode); break; case cmLineUp: setCurPtr(lineMove(curPtr, -1), selectMode); break; case cmLineDown: setCurPtr(lineMove(curPtr, 1), selectMode); break; case cmPageUp: setCurPtr(lineMove(curPtr, -(size.y-1)), selectMode); break; case cmPageDown: setCurPtr(lineMove(curPtr, size.y-1), selectMode); break; case cmTextStart: setCurPtr(0, selectMode); break; case cmTextEnd: setCurPtr(bufLen, selectMode); break; case cmNewLine: newLine(); break; case cmBackSpace: deleteRange(prevChar(curPtr), curPtr, True); break; case cmDelChar: deleteRange(curPtr, nextChar(curPtr), True); break; case cmDelWord: deleteRange(curPtr, nextWord(curPtr), False); break; case cmDelStart: deleteRange(lineStart(curPtr), curPtr, False); break; case cmDelEnd: deleteRange(curPtr, lineEnd(curPtr), False); break; case cmDelLine: deleteRange(lineStart(curPtr), nextLine(curPtr), False); break; case cmInsMode: toggleInsMode(); break; case cmStartSelect: startSelect(); break; case cmHideSelect: hideSelect(); break; case cmIndentMode: autoIndent = Boolean(!autoIndent); break; default: unlock(); return; } trackCursor(centerCursor); unlock(); break; } case evBroadcast: switch( event.message.command ) { case cmScrollBarChanged: checkScrollBar( event, hScrollBar, delta.x ); checkScrollBar( event, vScrollBar, delta.y ); break; default: return; } } clearEvent(event); }
Boolean TEditor::insertBuffer( char *p, ushort offset, ushort length, Boolean allowUndo, Boolean selectText ) { selecting = False; ushort selLen = selEnd - selStart; if( selLen == 0 && length == 0 ) return True; ushort delLen = 0; if( allowUndo == True ) if( curPtr == selStart ) delLen = selLen; else if( selLen > insCount ) delLen = selLen - insCount; long newSize = long(bufLen + delCount - selLen + delLen) + length; if( newSize > bufLen + delCount ) if( newSize > 0xFFE0l || setBufSize(ushort(newSize)) == False ) { editorDialog( edOutOfMemory ); return False; } ushort selLines = countLines( &buffer[bufPtr(selStart)], selLen ); if( curPtr == selEnd ) { if( allowUndo == True ) { if( delLen > 0 ) memmove( &buffer[curPtr + gapLen - delCount - delLen], &buffer[selStart], delLen ); insCount -= selLen - delLen; } curPtr = selStart; curPos.y -= selLines; } if( delta.y > curPos.y ) { delta.y -= selLines; if( delta.y < curPos.y ) delta.y = curPos.y; } if( length > 0 ) memmove( &buffer[curPtr], &p[offset], length ); ushort lines = countLines( &buffer[curPtr], length ); curPtr += length; curPos.y += lines; drawLine = curPos.y; drawPtr = lineStart(curPtr); curPos.x = charPos(drawPtr, curPtr); if( selectText == False ) selStart = curPtr; selEnd = curPtr; bufLen += length - selLen; gapLen -= length - selLen; if( allowUndo == True ) { delCount += delLen; insCount += length; } limit.y += lines - selLines; delta.y = max(0, min(delta.y, limit.y - size.y)); if( isClipboard() == False ) modified = True; setBufSize(bufLen + delCount); if( selLines == 0 && lines == 0 ) update(ufLine); else update(ufView); return True; }
void TwoDOrderParam::SetPositions(input_params& inputPars) { m_x.resize(m_row_number,0); m_y.resize(m_row_number,0); if(inputPars.runType.compare("Part")==0) { int counter = 0; vector<double> init_x(inputPars.p + inputPars.nx - 1,-1); vector<double> init_y(inputPars.p + inputPars.nx - 1,-1); vector<int> lineStart(inputPars.p + inputPars.nx - 1,-1); vector<int> lineSize(inputPars.p + inputPars.nx - 1,-1); // > Set limits for(int iii = 0; iii < inputPars.p; ++iii) { lineStart[iii] = 0; init_x[iii] = 0; init_y[iii] = (inputPars.p - 1 - iii); } for(int iii = inputPars.p; iii < inputPars.p + inputPars.nx -1; ++iii) { lineStart[iii] = (iii - inputPars.p + 1); init_x[iii] = (iii - inputPars.p + 1)*sqrt(3)/2; init_y[iii] = -(iii - inputPars.p + 1)*0.5; } for(int iii = 0; iii < inputPars.nx; ++iii) { lineSize[iii] = (inputPars.ny + iii) - lineStart[iii]; } for(int iii = inputPars.nx; iii < inputPars.p + inputPars.nx - 1; ++iii) { lineSize[iii] = (inputPars.nx - 1) + inputPars.ny - lineStart[iii]; } for(int iii = 0; iii < inputPars.p + inputPars.nx - 1; ++iii) { for(int jjj = 0; jjj < lineSize[iii]; ++jjj) { m_x[counter] = init_x[iii] + jjj*sqrt(3)/2; m_y[counter] = init_y[iii] + 0.5*jjj; ++counter; } } } // else if(inputPars.runType.compare("Moessner")==0) // { // int counter = 0; // double init_x = 0; // double init_y = 0; // // for(int iii = 0; iii < inputPars.ny; ++iii) // { // init_x = 0; // init_y = inputPars.ny - iii; // // for(int jjj = 0; jjj < inputPars.nx; ++jjj) // { // m_x[counter] = init_x + jjj*sqrt(3)/2; // m_y[counter] = init_y - 0.5*jjj; // // ++counter; // } // } // } else if(inputPars.runType.compare("Moessner")==0) { int counter = 0; double init_x = 0; double init_y = 0; for(int jjj = 0; jjj < inputPars.ny; ++jjj) { init_x = jjj*0.5; init_y = jjj*sqrt(3)/2; for(int iii = 0; iii < inputPars.nx; ++iii) { m_x[counter] = init_x + iii; m_y[counter] = init_y; ++counter; } } } // else if(inputPars.SimType.compare("Manual")==0) // { // int counter = 0; // // for(int iii = 0; iii < inputPars.ny/3; ++iii) // { // // First line // // x = 4*iii*sqrt(3)/2; // y = 0; // // for(int jjj = 0; jjj < inputPars.nx/2; ++jjj) // { // output << x << " " << y; // for(int kkk = 0; kkk < m_col_number; ++kkk) // { // dataPoint = m_mean[counter]; // // output << " " << dataPoint; // ++counter; // } // output << endl; // // // Move to next // x += sqrt(3)/2; // y +=0.5; // // output << x << " " << y; // for(int kkk = 0; kkk < m_col_number; ++kkk) // { // dataPoint = m_mean[counter]; // // output << " " << dataPoint; // ++counter; // } // output << endl; // // // Move to the next // // x += 0; // y += 1; // } // // // Second line // // x = (1 + 4*iii)*sqrt(3)/2; // y = -0.5; // // for(int jjj = 0; jjj < inputPars.nx/2; ++jjj) // { // output << x << " " << y; // for(int kkk = 0; kkk < m_col_number; ++kkk) // { // dataPoint = m_mean[counter]; // // output << " " << dataPoint; // ++counter; // } // output << endl; // // // Move to next // x += sqrt(3)/2; // y +=0.5; // // output << x << " " << y; // for(int kkk = 0; kkk < m_col_number; ++kkk) // { // dataPoint = m_mean[counter]; // // output << " " << dataPoint; // ++counter; // } // output << endl; // // // Move to the next // // x += 0; // y += 1; // } // // // First line // // x = (3 + 4*iii)*sqrt(3)/2; // y = -0.5; // // for(int jjj = 0; jjj < inputPars.nx/2; ++jjj) // { // output << x << " " << y; // for(int kkk = 0; kkk < m_col_number; ++kkk) // { // dataPoint = m_mean[counter]; // // output << " " << dataPoint; // ++counter; // } // output << endl; // // // Move to the next // x += 0; // y += 1; // // output << x << " " << y; // for(int kkk = 0; kkk < m_col_number; ++kkk) // { // dataPoint = m_mean[counter]; // // output << " " << dataPoint; // ++counter; // } // output << endl; // // // Move to next // x += sqrt(3)/2; // y +=0.5; // } // } // } }
void TubeRendererThread::run() { int numThreads = GLFunctions::idealThreadCount; int chunkSize = m_data.size() / numThreads; int begin = m_id * chunkSize; int end = m_id * chunkSize + chunkSize; if ( m_id == numThreads - 1 ) { end = m_data.size(); } // for all voxels: for ( int i = begin; i < end; ++i ) { QVector<float> fib = m_data[i]; QVector<float> extra = m_extraData[i]; if ( fib.size() < 9 ) { printf( "fib with size < 3 detected" ); continue; } int numFloats = fib.size(); QVector3D lineStart( fib[0], fib[1], fib[2] ); QVector3D lineEnd( fib[numFloats-3], fib[numFloats-2], fib[numFloats-1] ); QVector3D globalColor( fabs( lineStart.x() - lineEnd.x() ), fabs( lineStart.y() - lineEnd.y() ), fabs( lineStart.z() - lineEnd.z() ) ); globalColor.normalize(); // push back the first vertex, done seperately because of nomal calculation QVector3D localColor( fib[0] - fib[3], fib[1] - fib[4], fib[2] - fib[5] ); localColor.normalize(); m_verts->push_back( fib[0] ); m_verts->push_back( fib[1] ); m_verts->push_back( fib[2] ); m_verts->push_back( localColor.x() ); m_verts->push_back( localColor.y() ); m_verts->push_back( localColor.z() ); m_verts->push_back( globalColor.x() ); m_verts->push_back( globalColor.y() ); m_verts->push_back( globalColor.z() ); m_verts->push_back( extra.first() ); m_verts->push_back( 1.0 ); m_verts->push_back( fib[0] ); m_verts->push_back( fib[1] ); m_verts->push_back( fib[2] ); m_verts->push_back( localColor.x() ); m_verts->push_back( localColor.y() ); m_verts->push_back( localColor.z() ); m_verts->push_back( globalColor.x() ); m_verts->push_back( globalColor.y() ); m_verts->push_back( globalColor.z() ); m_verts->push_back( extra.first() ); m_verts->push_back( -1.0 ); for ( int k = 1; k < fib.size() / 3 - 1; ++k ) { QVector3D localColor( fib[k*3-3] - fib[k*3+3], fib[k*3-2] - fib[k*3+4], fib[k*3-1] - fib[k*3+5] ); localColor.normalize(); m_verts->push_back( fib[k*3] ); m_verts->push_back( fib[k*3+1] ); m_verts->push_back( fib[k*3+2] ); m_verts->push_back( localColor.x() ); m_verts->push_back( localColor.y() ); m_verts->push_back( localColor.z() ); m_verts->push_back( globalColor.x() ); m_verts->push_back( globalColor.y() ); m_verts->push_back( globalColor.z() ); m_verts->push_back( extra[k] ); m_verts->push_back( 1.0 ); m_verts->push_back( fib[k*3] ); m_verts->push_back( fib[k*3+1] ); m_verts->push_back( fib[k*3+2] ); m_verts->push_back( localColor.x() ); m_verts->push_back( localColor.y() ); m_verts->push_back( localColor.z() ); m_verts->push_back( globalColor.x() ); m_verts->push_back( globalColor.y() ); m_verts->push_back( globalColor.z() ); m_verts->push_back( extra[k] ); m_verts->push_back( -1.0 ); } QVector3D localColor2( fib[numFloats-6] - fib[numFloats-3], fib[numFloats-5] - fib[numFloats-2], fib[numFloats-4] - fib[numFloats-1] ); localColor.normalize(); // push back the last vertex, done seperately because of nomal calculation m_verts->push_back( fib[numFloats-3] ); m_verts->push_back( fib[numFloats-2] ); m_verts->push_back( fib[numFloats-1] ); m_verts->push_back( localColor2.x() ); m_verts->push_back( localColor2.y() ); m_verts->push_back( localColor2.z() ); m_verts->push_back( globalColor.x() ); m_verts->push_back( globalColor.y() ); m_verts->push_back( globalColor.z() ); m_verts->push_back( extra.last() ); m_verts->push_back( 1.0 ); m_verts->push_back( fib[numFloats-3] ); m_verts->push_back( fib[numFloats-2] ); m_verts->push_back( fib[numFloats-1] ); m_verts->push_back( localColor2.x() ); m_verts->push_back( localColor2.y() ); m_verts->push_back( localColor2.z() ); m_verts->push_back( globalColor.x() ); m_verts->push_back( globalColor.y() ); m_verts->push_back( globalColor.z() ); m_verts->push_back( extra.last() ); m_verts->push_back( -1.0 ); } }
inline void FTSimpleLayoutImpl::WrapTextI(const T *buf, const int len, FTPoint position, int renderMode, FTBBox *bounds) { FTUnicodeStringItr<T> breakItr(buf); // points to the last break character FTUnicodeStringItr<T> lineStart(buf); // points to the line start float nextStart = 0.0; // total width of the current line float breakWidth = 0.0; // width of the line up to the last word break float currentWidth = 0.0; // width of all characters on the current line float prevWidth; // width of all characters but the current glyph float wordLength = 0.0; // length of the block since the last break char int charCount = 0; // number of characters so far on the line int breakCharCount = 0; // number of characters before the breakItr float glyphWidth, advance; FTBBox glyphBounds; // Reset the pen position pen.Y(0); // If we have bounds mark them invalid if(bounds) { bounds->Invalidate(); } // Scan the input for all characters that need output FTUnicodeStringItr<T> prevItr(buf); for (FTUnicodeStringItr<T> itr(buf); *itr; prevItr = itr++, charCount++) { // Find the width of the current glyph glyphBounds = currentFont->BBox(itr.getBufferFromHere(), 1); glyphWidth = glyphBounds.Upper().Xf() - glyphBounds.Lower().Xf(); advance = currentFont->Advance(itr.getBufferFromHere(), 1); prevWidth = currentWidth; // Compute the width of all glyphs up to the end of buf[i] currentWidth = nextStart + glyphWidth; // Compute the position of the next glyph nextStart += advance; // See if the current character is a space, a break or a regular character if((currentWidth > lineLength) || (*itr == '\n')) { // A non whitespace character has exceeded the line length. Or a // newline character has forced a line break. Output the last // line and start a new line after the break character. // If we have not yet found a break, break on the last character if(breakItr == lineStart || (*itr == '\n')) { // Break on the previous character breakItr = prevItr; breakCharCount = charCount - 1; breakWidth = prevWidth; // None of the previous words will be carried to the next line wordLength = 0; // If the current character is a newline discard its advance if(*itr == '\n') advance = 0; } float remainingWidth = lineLength - breakWidth; // Render the current substring FTUnicodeStringItr<T> breakChar = breakItr; // move past the break character and don't count it on the next line either ++breakChar; --charCount; // If the break character is a newline do not render it if(*breakChar == '\n') { ++breakChar; --charCount; } if(breakCharCount >= 0) { OutputWrapped(lineStart.getBufferFromHere(), breakCharCount, //breakItr.getBufferFromHere() - lineStart.getBufferFromHere(), position, renderMode, remainingWidth, bounds); } // Store the start of the next line lineStart = breakChar; // TODO: Is Height() the right value here? pen -= FTPoint(0, currentFont->LineHeight() * lineSpacing); // The current width is the width since the last break nextStart = wordLength + advance; wordLength += advance; currentWidth = wordLength + advance; // Reset the safe break for the next line breakItr = lineStart; charCount -= breakCharCount; } else if(iswspace(*itr)) { // This is the last word break position wordLength = 0; breakItr = itr; breakCharCount = charCount; // Check to see if this is the first whitespace character in a run if(buf == itr.getBufferFromHere() || !iswspace(*prevItr)) { // Record the width of the start of the block breakWidth = currentWidth; } } else { wordLength += advance; } } float remainingWidth = lineLength - currentWidth; // Render any remaining text on the last line // Disable justification for the last row if(alignment == FTGL::ALIGN_JUSTIFY) { alignment = FTGL::ALIGN_LEFT; OutputWrapped(lineStart.getBufferFromHere(), -1, position, renderMode, remainingWidth, bounds); alignment = FTGL::ALIGN_JUSTIFY; } else { OutputWrapped(lineStart.getBufferFromHere(), -1, position, renderMode, remainingWidth, bounds); } }
inline void FTSimpleLayoutImpl::WrapTextI(const T *buf, const int len, FTPoint position, int renderMode, FTBBox *bounds) { FTUnicodeStringItr<T> breakItr(buf); // points to the last break character FTUnicodeStringItr<T> lineStart(buf); // points to the line start float nextStart = 0.0; // total width of the current line float breakWidth = 0.0; // width of the line up to the last word break float currentWidth = 0.0; // width of all characters on the current line float prevWidth; // width of all characters but the current glyph float wordLength = 0.0; // length of the block since the last break char int charCount = 0; // number of characters so far on the line int breakCharCount = 0; // number of characters before the breakItr float glyphWidth, advance; FTBBox glyphBounds; bool refresh = false; // Reset the pen position pen.Y(0); // If we have bounds mark them invalid if(bounds) { bounds->Invalidate(); } //XLOGXN("FTGL1"); // Check if the incoming string is different to the previously // cached string. unsigned int i = 0; for (FTUnicodeStringItr<T> itr(buf); *itr; itr++) { XBREAK(i >= 4096); if (i >= stringCacheCount || stringCache[i++] != (unsigned int)*itr) { refresh = true; break; } } //XLOGXN("FTGL2"); if (refresh) { //XLOGXN("FTGL3"); stringCacheCount = 0; layoutGlyphCache.clear(); // Scan the input for all characters that need output FTUnicodeStringItr<T> prevItr(buf); for (FTUnicodeStringItr<T> itr(buf); *itr; prevItr = itr++, charCount++) { XBREAK(stringCacheCount >= 4096); stringCache[stringCacheCount++] = (unsigned int)*itr; // Find the width of the current glyph glyphBounds = currentFont->BBox(itr.getBufferFromHere(), 1); glyphWidth = glyphBounds.Upper().Xf() - glyphBounds.Lower().Xf(); advance = currentFont->Advance(itr.getBufferFromHere(), 1); prevWidth = currentWidth; // Compute the width of all glyphs up to the end of buf[i] currentWidth = nextStart + glyphWidth; // Compute the position of the next glyph nextStart += advance; // See if the current character is a space, a break or a regular character if((currentWidth > lineLength) || (*itr == '\n')) { // A non whitespace character has exceeded the line length. Or a // newline character has forced a line break. Output the last // line and start a new line after the break character. // If we have not yet found a break, break on the last character if(breakItr == lineStart || (*itr == '\n')) { // Break on the previous character breakItr = prevItr; breakCharCount = charCount - 1; breakWidth = prevWidth; // None of the previous words will be carried to the next line wordLength = 0; // If the current character is a newline discard its advance if(*itr == '\n') advance = 0; } float remainingWidth = lineLength - breakWidth; // Render the current substring FTUnicodeStringItr<T> breakChar = breakItr; // move past the break character and don't count it on the next line either ++breakChar; --charCount; // If the break character is a newline do not render it if(*breakChar == '\n') { ++breakChar; --charCount; } layoutGlyphCacheItem_t cacheItem; cacheItem.buf = (T*)lineStart.getBufferFromHere(); cacheItem.charCount = breakCharCount; cacheItem.position = FTPoint(position.X(), position.Y(), position.Z()); cacheItem.remainingWidth = remainingWidth; cacheItem.penDiff = FTPoint(0, currentFont->LineHeight() * lineSpacing); layoutGlyphCache.push_back(cacheItem); lineStart = breakChar; // The current width is the width since the last break nextStart = wordLength + advance; wordLength += advance; currentWidth = wordLength + advance; // Reset the safe break for the next line breakItr = lineStart; charCount -= breakCharCount; } else if(iswspace(*itr)) { // This is the last word break position wordLength = 0; breakItr = itr; breakCharCount = charCount; // Check to see if this is the first whitespace character in a run if(buf == itr.getBufferFromHere() || !iswspace(*prevItr)) { // Record the width of the start of the block breakWidth = currentWidth; } } else { wordLength += advance; } } //XLOGXN("FTGL4"); float remainingWidth = lineLength - currentWidth; // Render any remaining text on the last line // Disable justification for the last row //XLOGXN("FTGL5"); if(alignment == FTGL::ALIGN_JUSTIFY) { alignment = FTGL::ALIGN_LEFT; layoutGlyphCacheItem_t cacheItem; cacheItem.buf = (T *)lineStart.getBufferFromHere(); cacheItem.charCount = -1; cacheItem.position = FTPoint(position.X(), position.Y(), position.Z()); cacheItem.penDiff = FTPoint(0,0,0); cacheItem.remainingWidth = remainingWidth; layoutGlyphCache.push_back(cacheItem); alignment = FTGL::ALIGN_JUSTIFY; } else { layoutGlyphCacheItem_t cacheItem; cacheItem.buf = (T *)lineStart.getBufferFromHere(); cacheItem.charCount = -1; cacheItem.position = FTPoint(position.X(), position.Y(), position.Z()); cacheItem.penDiff = FTPoint(0,0,0); cacheItem.remainingWidth = remainingWidth; layoutGlyphCache.push_back(cacheItem); } //XLOGXN("FTGL6"); } //XLOGXN("FTGL7"); // Draw each of the glyphs in the cache. currentFont->PreRender(); //XLOGXN("FTGL8"); std::list<layoutGlyphCacheItem_t>::iterator it; for (it = layoutGlyphCache.begin(); it != layoutGlyphCache.end(); it++) { layoutGlyphCacheItem_t cacheItem = (*it); OutputWrapped((T*)cacheItem.buf, cacheItem.charCount, cacheItem.position, renderMode, cacheItem.remainingWidth, bounds); pen -= cacheItem.penDiff; } //XLOGXN("FTGL9"); currentFont->PostRender(); }