예제 #1
0
void drvFastSweep::dataCallback(epicsInt32 *newData, size_t nelem)
{
    int i;

    if (!acquiring_) return;
    
    lock();

    /* No need to average if collecting every point */
    if (numAverage_ == 1) {
        nextPoint(newData);
        goto done;
    }
    for (i=0; i<maxSignals_; i++) 
        pAverageStore_[i] += newData[i];
    if (++(accumulated_) < numAverage_) goto done;
    /* We have now collected the desired number of points to average */
    for (i=0; i<maxSignals_; i++) 
        newData[i] = (epicsInt32)(0.5 + pAverageStore_[i]/accumulated_);
    nextPoint(newData);
    for (i=0; i<maxSignals_; i++) 
        pAverageStore_[i] = 0;
    accumulated_ = 0;
done:
    unlock();
}
예제 #2
0
QVector<QPoint> ImageProcessor::findOcculsionSlower(QImage input) {
    QVector<QPoint> returnMe;

    int radius = (int) (.1 * input.height());
    //qDebug()<<"radius: " <<radius;

    //left side
    int bestLeftY=0;
    int bestLeftYval=INT_MAX;
    for(int currentY=radius;currentY<input.height()-radius;currentY++) {
        int sum =0;
        foreach(int x,ImageProcessor::regionVals(0,currentY,radius,input)) {
            sum+=x;
        }

        if(sum < bestLeftYval) {
            bestLeftY = currentY;
            bestLeftYval = sum;
        }
    }

    QPoint currentPoint(0,bestLeftY);
    returnMe.append(currentPoint);
    for(int lookX =0;lookX<input.width();lookX++) {
        qreal bestAngle=0;
        qreal bestAngleValue=1024;
        for(int angle=-89;angle<90;angle++) {
            qreal angleValue = vectorSum(input,currentPoint,angle);
            if(angleValue < bestAngleValue) {
                bestAngle = angle;
                bestAngleValue = angleValue;
            }
        }
        qDebug()<<"Best angle was: " << bestAngle << " with "<< bestAngleValue;
        if(bestAngle > 15) {
            QPoint nextPoint(currentPoint.x() +1, currentPoint.y() +1);
            currentPoint = nextPoint;
        } else if(bestAngle < -15) {
            QPoint nextPoint(currentPoint.x() +1, currentPoint.y() - 1);
            currentPoint = nextPoint;
        } else {
            QPoint nextPoint(currentPoint.x() +1, currentPoint.y());
            currentPoint = nextPoint;
        }
        returnMe.append(currentPoint);
    }

    return returnMe;
}
예제 #3
0
void EnemyBase::runFollowPoint()
{
	auto point = currPoint();
	auto prevP = point;
	setPosition(point->getPosition());
	point = nextPoint();
	auto nextP = point;

	if (point != nullptr)
	{

		float distancePrevToNext;
		//计算2个点的距离差,保证匀速运动
		if (abs(prevP->getPosition().x - nextP->getPosition().x) <= abs(prevP->getPosition().y - nextP->getPosition().y))
		{
			distancePrevToNext = abs(prevP->getPosition().y - nextP->getPosition().y);
		}
		else
		{
			distancePrevToNext = abs(prevP->getPosition().x - nextP->getPosition().x);
		}

		float timeToMove = distancePrevToNext / (getRunSpeed()*20.0);

		runAction(Sequence::create(MoveTo::create(timeToMove, point->getPosition())
			, CallFuncN::create(CC_CALLBACK_0(EnemyBase::runFollowPoint, this))
			, NULL));
	}
	else
	{
		//setEnemySuccessful(true);
	}
}
예제 #4
0
파일: lbt.cpp 프로젝트: ppdg123/LBtool
void mCallBack(int event,int x,int y, int flags, void * userdata)
{
	if(event == CV_EVENT_LBUTTONDOWN)
	{
		printf("x:%d y:%d\n",x,y);
		if(lb_type==TYPE_REC||lb_type==TYPE_PNT||lb_type==TYPE_SQR)
		{
			point_val[cur_point_ptr][0] = x;
			point_val[cur_point_ptr][1] = y;
			if(cur_point_ptr==1&&lb_type==TYPE_SQR)
			{
				cur_point_ptr = -1;    
			}
			nextPoint();
		}
		if(lb_type==TYPE_SP)
		{
			sp_val[(int)cvmGet(spmat,y,x)-1] = cur_point_ptr;
		}
		showImage();
	}
	if(event == CV_EVENT_RBUTTONDOWN)
	{
		if(lb_type==TYPE_SP)
		{
			sp_val[(int)cvmGet(spmat,y,x)-1] = -1;
		}
		showImage();
	}
}
예제 #5
0
void search(Step start){
    int x, y;
    for (x = 0; x < mapSize.width; x++){
        for (y = 0; y < mapSize.height; y++){
            visited[x][y] = 0;
        }
    }
    pushHeap(start);
    while(heapIndex >= 0){
        Step step = popHeap();
        if(finished(step)){
            //printf("FOUND: %d, %d.\tValue: %d\tIndex: %d\n", step.point.x, step.point.y, step.distance, heapIndex);
            min = step.distance;
            break;
        }
        if(visited[step.point.x][step.point.y]){
            continue;
        }
        visited[step.point.x][step.point.y] = 1;
        int i;
        for(i = 0; i < 8; i++){
            Point next = nextPoint(step.point, i);
            if(isValidPoint(next)){
                pushHeap(makeStep(next, step.distance + map[next.x][next.y]));
            }
        }
    }
}
예제 #6
0
파일: Actor.cpp 프로젝트: numeroband/lage
void Actor::walkTo(SQInteger x, SQInteger y)
{
    SDL_Point dest;
    Box *destBox = _room->boxes()->getClosestBox(SDL_Point{(int)x,(int)y},
                                                 &dest);

    if (_engine->isDebug(Engine::kDebugWalkboxes))
    {
        std::cout << "walkTo " << destBox << ": "
        << dest.x << "," << dest.y << std::endl;
    }
    
   
    _path = _room->boxes()->getPath(_pos, dest);
    
    if (_path.empty())
    {
        if (_engine->isDebug(Engine::kDebugWalkboxes))
        {
            std::cout << "UNREACHABLE!!!" << std::endl;
        }
        return;
    }
    
    nextPoint();
}
예제 #7
0
int doSearch(Point start){
    int minDist = INT_MAX;
    pointInMap(start) = 0;
    push(start)
    while (queueIsNotEmpty) {
        Point curr = pop();
        int i;
        for (i = 0; i < MOVCOUNT; i++) {
            Point next = nextPoint(curr, i);
            if (isValidPoint(next)) {
                if (pointInMap(next) == SPOTB && minDist > pointInMap(curr)) {
                    minDist = pointInMap(curr);
                } else if (pointInMap(next) == SPOTA) {
                    pointInMap(next) = 0;
                    push(next);
                } else if (pointInMap(next) == EMPTY) {
                    pointInMap(next) = pointInMap(curr) + 1;
                    push(next);
                } else if (pointInMap(next) > pointInMap(curr) + 1) {
                    pointInMap(next) = pointInMap(curr) + 1;
                    push(next);
                }
            }
        }
    }
    return minDist;
}
예제 #8
0
파일: lbt.cpp 프로젝트: ppdg123/LBtool
void kCallBack(char ch)
{
	switch(ch)
	{
		case ' ':
			saveDataFile(file_set[cur_file_ptr]);
			loadNext();
			break;
		case '\n':
			saveDataFile(file_set[cur_file_ptr]);
			loadPrevious();
			break;
		case 'p':
			loadPrevious();
			break;
		case 'q':
			exitLBT();
			break;
		case 'n':
			loadNext();
			break;
		case '=':
			nextPoint();
			showImage();
			break;
		case '-':
			previousPoint();
			showImage();
			break;
		case '[':
			previousAttrVal();
			showImage();
			break;
		case ']':
			nextAttrVal();
			showImage();
			break;
		case 'c':
			if(lb_type==TYPE_SQR)
			{
		        	saveSQR();
			}
	}
	if(ch>='0'&&ch<='9'&&lb_type==TYPE_DEG)
	{
		degree = ch-'0';
		printf("%c\n",ch);
		showImage();
	}
}
예제 #9
0
int QgsMapToolCapture::addVertex( const QPoint &p )
{
  QgsPoint layerPoint;
  QgsPoint mapPoint;

  if ( mode() == CaptureNone )
  {
    QgsDebugMsg( "invalid capture mode" );
    return 2;
  }

  int res = nextPoint( p, layerPoint, mapPoint );
  if ( res != 0 )
  {
    QgsDebugMsg( "nextPoint failed: " + QString::number( res ) );
    return res;
  }

  if ( !mRubberBand )
  {
    mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line );
  }
  mRubberBand->addPoint( mapPoint );
  mCaptureList.append( layerPoint );

  if ( !mTempRubberBand )
  {
    mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line , true );
  }
  else
  {
    mTempRubberBand->reset( mCaptureMode == CapturePolygon ? true : false );
  }
  if ( mCaptureMode == CaptureLine )
  {
    mTempRubberBand->addPoint( mapPoint );
  }
  else if ( mCaptureMode == CapturePolygon )
  {
    const QgsPoint *firstPoint = mRubberBand->getPoint( 0 , 0 );
    mTempRubberBand->addPoint( *firstPoint );
    mTempRubberBand->movePoint( mapPoint );
    mTempRubberBand->addPoint( mapPoint );
  }

  validateGeometry();

  return 0;
}
예제 #10
0
void color(Point start, int col){
    push(start);
    while (queueIsNotEmpty) {
        Point curr = pop();
        pointInMap(curr) = col;
        int i;
        for (i = 0; i < MOVCOUNT; i++) {
            Point next = nextPoint(curr, i);
            if (isValidPoint(next) && pointInMap(next) == SPOT) {
                push(next);
            }
        }
    }
    resetQueue();
}
예제 #11
0
int QgsMapToolCapture::addVertex( const QgsPoint& point )
{
  if ( mode() == CaptureNone )
  {
    QgsDebugMsg( "invalid capture mode" );
    return 2;
  }

  int res;
  QgsPoint layerPoint;
  res = nextPoint( point, layerPoint );
  if ( res != 0 )
  {
    return res;
  }

  if ( !mRubberBand )
  {
    mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line );
  }
  mRubberBand->addPoint( point );
  mCaptureCurve.addVertex( QgsPointV2( layerPoint.x(), layerPoint.y() ) );

  if ( !mTempRubberBand )
  {
    mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line, true );
  }
  else
  {
    mTempRubberBand->reset( mCaptureMode == CapturePolygon ? true : false );
  }
  if ( mCaptureMode == CaptureLine )
  {
    mTempRubberBand->addPoint( point );
  }
  else if ( mCaptureMode == CapturePolygon )
  {
    const QgsPoint *firstPoint = mRubberBand->getPoint( 0, 0 );
    mTempRubberBand->addPoint( *firstPoint );
    mTempRubberBand->movePoint( point );
    mTempRubberBand->addPoint( point );
  }

  validateGeometry();

  return 0;
}
예제 #12
0
// Return the border of the given object containing the given point.
vector<Point> extractBorderFromPoint(const Domain domain, const DigitalSet object, Point start) {
    vector<Point> border ;
    border.push_back(start) ;
    vector<Point> neigh = getNeighbours(domain, start) ;
    for(unsigned i = 0 ; i <= neigh.size() ; i++) {
        if(!object(neigh[mod(i-1, neigh.size())]) && object(neigh[mod(i, neigh.size())])) {
          border.push_back(neigh[mod(i, neigh.size())]) ;
          break ;
      }
    }
    if(border.size() == 2) {
        while(border.back() != start) {
            border.push_back(nextPoint(object, border.end()[-2], border.end()[-1])) ;
        }
    }
    return border ;
}
예제 #13
0
void fillAreaWithNumber(Point point, int number){
    stackIndex = -1;
    pushStack(point);
    while(stackIndex >= 0){
        point = popStack();
        map[point.x][point.y] = 0;
        sea[point.x][point.y] = number;
        if(visited[point.x][point.y]) continue;
        visited[point.x][point.y] = 1;
        int i;
        for(i = 0; i < 8; i++){
            Point next = nextPoint(point, i);
            if(isValidPoint(next) && map[next.x][next.y] < 0){
                pushStack(next);
            }
        }
    }
}
예제 #14
0
파일: Actor.cpp 프로젝트: numeroband/lage
void Actor::update()
{
    if (!_currentCostume || !_room)
    {
        return;
    }
    
    if (_textFramesPending > 0 && _textFramesPending-- == 1)
    {
        setAnimation(_talkStopAnimation);
    }
    
    if (_walkNumFrames == 0)
    {
        _currentCostume->update(&_pos, _scale, _light);
        return;
    }
    
    ++_walkFrame;

    if (_walkFrame >= _walkNumFrames)
    {
        nextPoint();
        _light = static_cast<uint8_t>(_pos.x);
        _currentCostume->update(&_pos, _scale, _light);
        if (_path.empty())
        {
            return;
        }
    }

    auto &next = _path.front();
    SDL_Point distance;
    distance.x = next.x - _walkOrigin.x;
    distance.y = next.y - _walkOrigin.y;
    
    _pos.x = _walkOrigin.x + (distance.x * (_walkFrame / static_cast<float>(_walkNumFrames)));
    _pos.y = _walkOrigin.y + (distance.y * (_walkFrame / static_cast<float>(_walkNumFrames)));
    updateBox();
    _scale = _box->getScale(_pos.y);
    _light = static_cast<uint8_t>(_pos.x);
    _currentCostume->update(&_pos, _scale, _light);
}
예제 #15
0
bool Linear::generatePath(){
    if(points.size() < 2) return false;
	visualisation.clear();
	visualisation.reserve(100);
	auto singleStepLengthTmp = singleStepLength;
	singleStepLength = 0.01;
	maxSections = points.size()-1;
	section = -1;
	step = 0;
	nextSection();
	finished = false;

	while(!finished){
		visualisation.push_back(nextPoint());
	}

	singleStepLength = singleStepLengthTmp;
    return true;
}
예제 #16
0
static ofTTFCharacter makeContoursForCharacter(FT_Face &face){

		//int num			= face->glyph->outline.n_points;
		int nContours	= face->glyph->outline.n_contours;
		int startPos	= 0;

		char * tags		= face->glyph->outline.tags;
		FT_Vector * vec = face->glyph->outline.points;

		ofTTFCharacter charOutlines;
		charOutlines.setUseShapeColor(false);

		for(int k = 0; k < nContours; k++){
			if( k > 0 ){
				startPos = face->glyph->outline.contours[k-1]+1;
			}
			int endPos = face->glyph->outline.contours[k]+1;

			if(printVectorInfo){
				ofLogNotice("ofTrueTypeFont") << "--NEW CONTOUR";
			}

			//vector <ofPoint> testOutline;
			ofPoint lastPoint;

			for(int j = startPos; j < endPos; j++){

				if( FT_CURVE_TAG(tags[j]) == FT_CURVE_TAG_ON ){
					lastPoint.set((float)vec[j].x, (float)-vec[j].y, 0);
					if(printVectorInfo){
						ofLogNotice("ofTrueTypeFont") << "flag[" << j << "] is set to 1 - regular point - " << lastPoint.x <<  lastPoint.y;
					}
					charOutlines.lineTo(lastPoint/64);

				}else{
					if(printVectorInfo){
						ofLogNotice("ofTrueTypeFont") << "flag[" << j << "] is set to 0 - control point";
					}

					if( FT_CURVE_TAG(tags[j]) == FT_CURVE_TAG_CUBIC ){
						if(printVectorInfo){
							ofLogNotice("ofTrueTypeFont") << "- bit 2 is set to 2 - CUBIC";
						}

						int prevPoint = j-1;
						if( j == 0){
							prevPoint = endPos-1;
						}

						int nextIndex = j+1;
						if( nextIndex >= endPos){
							nextIndex = startPos;
						}

						ofPoint nextPoint( (float)vec[nextIndex].x,  -(float)vec[nextIndex].y );

						//we need two control points to draw a cubic bezier
						bool lastPointCubic =  ( FT_CURVE_TAG(tags[prevPoint]) != FT_CURVE_TAG_ON ) && ( FT_CURVE_TAG(tags[prevPoint]) == FT_CURVE_TAG_CUBIC);

						if( lastPointCubic ){
							ofPoint controlPoint1((float)vec[prevPoint].x,	(float)-vec[prevPoint].y);
							ofPoint controlPoint2((float)vec[j].x, (float)-vec[j].y);
							ofPoint nextPoint((float) vec[nextIndex].x,	-(float) vec[nextIndex].y);

							//cubic_bezier(testOutline, lastPoint.x, lastPoint.y, controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, nextPoint.x, nextPoint.y, 8);
							charOutlines.bezierTo(controlPoint1.x/64, controlPoint1.y/64, controlPoint2.x/64, controlPoint2.y/64, nextPoint.x/64, nextPoint.y/64);
						}

					}else{

						ofPoint conicPoint( (float)vec[j].x,  -(float)vec[j].y );

						if(printVectorInfo){
							ofLogNotice("ofTrueTypeFont") << "- bit 2 is set to 0 - conic- ";
							ofLogNotice("ofTrueTypeFont") << "--- conicPoint point is " << conicPoint.x << conicPoint.y;
						}

						//If the first point is connic and the last point is connic then we need to create a virutal point which acts as a wrap around
						if( j == startPos ){
							bool prevIsConnic = (  FT_CURVE_TAG( tags[endPos-1] ) != FT_CURVE_TAG_ON ) && ( FT_CURVE_TAG( tags[endPos-1]) != FT_CURVE_TAG_CUBIC );

							if( prevIsConnic ){
								ofPoint lastConnic((float)vec[endPos - 1].x, (float)-vec[endPos - 1].y);
								lastPoint = (conicPoint + lastConnic) / 2;

								if(printVectorInfo){
									ofLogNotice("ofTrueTypeFont") << "NEED TO MIX WITH LAST";
									ofLogNotice("ofTrueTypeFont") << "last is " << lastPoint.x << " " << lastPoint.y;
								}
							}
						}

						//bool doubleConic = false;

						int nextIndex = j+1;
						if( nextIndex >= endPos){
							nextIndex = startPos;
						}

						ofPoint nextPoint( (float)vec[nextIndex].x,  -(float)vec[nextIndex].y );

						if(printVectorInfo){
							ofLogNotice("ofTrueTypeFont") << "--- last point is " << lastPoint.x << " " <<  lastPoint.y;
						}

						bool nextIsConnic = (  FT_CURVE_TAG( tags[nextIndex] ) != FT_CURVE_TAG_ON ) && ( FT_CURVE_TAG( tags[nextIndex]) != FT_CURVE_TAG_CUBIC );

						//create a 'virtual on point' if we have two connic points
						if( nextIsConnic ){
							nextPoint = (conicPoint + nextPoint) / 2;
							if(printVectorInfo){
								ofLogNotice("ofTrueTypeFont") << "|_______ double connic!";
							}
						}
						if(printVectorInfo){
							ofLogNotice("ofTrueTypeFont") << "--- next point is " << nextPoint.x << " " << nextPoint.y;
						}

						//quad_bezier(testOutline, lastPoint.x, lastPoint.y, conicPoint.x, conicPoint.y, nextPoint.x, nextPoint.y, 8);
						charOutlines.quadBezierTo(lastPoint.x/64, lastPoint.y/64, conicPoint.x/64, conicPoint.y/64, nextPoint.x/64, nextPoint.y/64);

						if( nextIsConnic ){
							lastPoint = nextPoint;
						}
					}
				}

			//end for
			}
			charOutlines.close();
		}

	return charOutlines;
}
예제 #17
0
void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
  //check if we operate on a vector layer
  QgsVectorLayer *vlayer = currentVectorLayer();
  if ( !vlayer )
  {
    notifyNotVectorLayer();
    return;
  }

  if ( !vlayer->isEditable() )
  {
    notifyNotEditableLayer();
    return;
  }

  bool isGeometryEmpty = false;
  QgsFeatureList selectedFeatures = vlayer->selectedFeatures();
  if ( !selectedFeatures.isEmpty() && selectedFeatures.at( 0 ).geometry().isNull() )
    isGeometryEmpty = true;

  if ( !checkSelection() )
  {
    stopCapturing();
    return;
  }

  int errorCode = 0;
  switch ( mode() )
  {
    case CapturePoint:
    {
      QgsPoint layerPoint;
      QgsPointXY mapPoint = e->mapPoint();

      if ( nextPoint( QgsPoint( mapPoint ), layerPoint ) != 0 )
      {
        QgsDebugMsg( "nextPoint failed" );
        return;
      }

      vlayer->beginEditCommand( tr( "Part added" ) );
      errorCode = vlayer->addPart( QgsPointSequence() << layerPoint );
    }
    break;

    case CaptureLine:
    case CapturePolygon:
    {
      //add point to list and to rubber band
      if ( e->button() == Qt::LeftButton )
      {
        int error = addVertex( e->mapPoint(), e->mapPointMatch() );
        if ( error == 1 )
        {
          QgsDebugMsg( "current layer is not a vector layer" );
          return;
        }
        else if ( error == 2 )
        {
          //problem with coordinate transformation
          emit messageEmitted( tr( "Coordinate transform error. Cannot transform the point to the layers coordinate system" ), Qgis::Warning );
          return;
        }

        startCapturing();
        return;
      }
      else if ( e->button() != Qt::RightButton )
      {
        deleteTempRubberBand();

        return;
      }

      if ( !isCapturing() )
        return;

      if ( mode() == CapturePolygon )
      {
        closePolygon();
      }

      //does compoundcurve contain circular strings?
      //does provider support circular strings?
      bool hasCurvedSegments = captureCurve()->hasCurvedSegments();
      bool providerSupportsCurvedSegments = vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::CircularGeometries;

      QgsCurve *curveToAdd = nullptr;
      if ( hasCurvedSegments && providerSupportsCurvedSegments )
      {
        curveToAdd = captureCurve()->clone();
      }
      else
      {
        curveToAdd = captureCurve()->curveToLine();
      }

      vlayer->beginEditCommand( tr( "Part added" ) );
      if ( mode() == CapturePolygon )
      {
        //avoid intersections
        QgsCurvePolygon *cp = new QgsCurvePolygon();
        cp->setExteriorRing( curveToAdd );
        QgsGeometry *geom = new QgsGeometry( cp );
        geom->avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers() );

        const QgsCurvePolygon *cpGeom = qgsgeometry_cast<const QgsCurvePolygon *>( geom->constGet() );
        if ( !cpGeom )
        {
          stopCapturing();
          delete geom;
          vlayer->destroyEditCommand();
          return;
        }

        errorCode = vlayer->addPart( cpGeom->exteriorRing()->clone() );
        delete geom;
      }
      else
      {
        errorCode = vlayer->addPart( curveToAdd );
      }
      stopCapturing();
    }
    break;
    default:
      Q_ASSERT( !"invalid capture mode" );
      errorCode = 6;
      break;
  }

  QString errorMessage;
  switch ( errorCode )
  {
    case 0:
    {
      // remove previous message
      emit messageDiscarded();

      //add points to other features to keep topology up-to-date
      bool topologicalEditing = QgsProject::instance()->topologicalEditing();
      if ( topologicalEditing )
      {
        addTopologicalPoints( points() );
      }

      vlayer->endEditCommand();

      vlayer->triggerRepaint();

      if ( ( !isGeometryEmpty ) && QgsWkbTypes::isSingleType( vlayer->wkbType() ) )
      {
        emit messageEmitted( tr( "Add part: Feature geom is single part and you've added more than one" ), Qgis::Warning );
      }

      return;
    }

    case 1:
      errorMessage = tr( "Selected feature is not multi part." );
      break;

    case 2:
      errorMessage = tr( "New part's geometry is not valid." );
      break;

    case 3:
      errorMessage = tr( "New polygon ring not disjoint with existing polygons." );
      break;

    case 4:
      errorMessage = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
      break;

    case 5:
      errorMessage = tr( "Several features are selected. Please select only one feature to which an island should be added." );
      break;

    case 6:
      errorMessage = tr( "Selected geometry could not be found" );
      break;
  }

  emit messageEmitted( errorMessage, Qgis::Warning );
  vlayer->destroyEditCommand();
}
예제 #18
0
static ofTTFCharacter makeContoursForCharacter(FT_Face &face){

		//int num			= face->glyph->outline.n_points;
		int nContours	= face->glyph->outline.n_contours;
		int startPos	= 0;

		char * tags		= face->glyph->outline.tags;
		FT_Vector * vec = face->glyph->outline.points;

		ofTTFCharacter charOutlines;

		for(int k = 0; k < nContours; k++){
			if( k > 0 ){
				startPos = face->glyph->outline.contours[k-1]+1;
			}
			int endPos = face->glyph->outline.contours[k]+1;

			if( printVectorInfo )printf("--NEW CONTOUR\n\n");

			vector <ofPoint> testOutline;
			ofPoint lastPoint;

			for(int j = startPos; j < endPos; j++){

				if( FT_CURVE_TAG(tags[j]) == FT_CURVE_TAG_ON ){
					lastPoint.set((float)vec[j].x, (float)-vec[j].y, 0);
					if( printVectorInfo )printf("flag[%i] is set to 1 - regular point - %f %f \n", j, lastPoint.x, lastPoint.y);
					testOutline.push_back(lastPoint);

				}else{
					if( printVectorInfo )printf("flag[%i] is set to 0 - control point \n", j);

					if( FT_CURVE_TAG(tags[j]) == FT_CURVE_TAG_CUBIC ){
						if( printVectorInfo )printf("- bit 2 is set to 2 - CUBIC\n");

						int prevPoint = j-1;
						if( j == 0){
							prevPoint = endPos-1;
						}

						int nextIndex = j+1;
						if( nextIndex >= endPos){
							nextIndex = startPos;
						}

						ofPoint nextPoint( (float)vec[nextIndex].x,  -(float)vec[nextIndex].y );

						//we need two control points to draw a cubic bezier
						bool lastPointCubic =  ( FT_CURVE_TAG(tags[prevPoint]) != FT_CURVE_TAG_ON ) && ( FT_CURVE_TAG(tags[prevPoint]) == FT_CURVE_TAG_CUBIC);

						if( lastPointCubic ){
							ofPoint controlPoint1((float)vec[prevPoint].x,	(float)-vec[prevPoint].y);
							ofPoint controlPoint2((float)vec[j].x, (float)-vec[j].y);
							ofPoint nextPoint((float) vec[nextIndex].x,	-(float) vec[nextIndex].y);

							cubic_bezier(testOutline, lastPoint.x, lastPoint.y, controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, nextPoint.x, nextPoint.y, 8);
						}

					}else{

						ofPoint conicPoint( (float)vec[j].x,  -(float)vec[j].y );

						if( printVectorInfo )printf("- bit 2 is set to 0 - conic- \n");
						if( printVectorInfo )printf("--- conicPoint point is %f %f \n", conicPoint.x, conicPoint.y);

						//If the first point is connic and the last point is connic then we need to create a virutal point which acts as a wrap around
						if( j == startPos ){
							bool prevIsConnic = (  FT_CURVE_TAG( tags[endPos-1] ) != FT_CURVE_TAG_ON ) && ( FT_CURVE_TAG( tags[endPos-1]) != FT_CURVE_TAG_CUBIC );

							if( prevIsConnic ){
								ofPoint lastConnic((float)vec[endPos - 1].x, (float)-vec[endPos - 1].y);
								lastPoint = (conicPoint + lastConnic) / 2;

								if( printVectorInfo )	printf("NEED TO MIX WITH LAST\n");
								if( printVectorInfo )printf("last is %f %f \n", lastPoint.x, lastPoint.y);
							}
						}

						//bool doubleConic = false;

						int nextIndex = j+1;
						if( nextIndex >= endPos){
							nextIndex = startPos;
						}

						ofPoint nextPoint( (float)vec[nextIndex].x,  -(float)vec[nextIndex].y );

						if( printVectorInfo )printf("--- last point is %f %f \n", lastPoint.x, lastPoint.y);

						bool nextIsConnic = (  FT_CURVE_TAG( tags[nextIndex] ) != FT_CURVE_TAG_ON ) && ( FT_CURVE_TAG( tags[nextIndex]) != FT_CURVE_TAG_CUBIC );

						//create a 'virtual on point' if we have two connic points
						if( nextIsConnic ){
							nextPoint = (conicPoint + nextPoint) / 2;
							if( printVectorInfo )printf("|_______ double connic!\n");
						}
						if( printVectorInfo )printf("--- next point is %f %f \n", nextPoint.x, nextPoint.y);

						quad_bezier(testOutline, lastPoint.x, lastPoint.y, conicPoint.x, conicPoint.y, nextPoint.x, nextPoint.y, 8);

						if( nextIsConnic ){
							lastPoint = nextPoint;
						}
					}
				}

			//end for
			}

			for(int g =0; g < (int)testOutline.size(); g++){
				testOutline[g] /= 64.0f;
			}

			charOutlines.contours.push_back(ofTTFContour());

			if( testOutline.size() ){
				charOutlines.contours.back().pts = ofSimplifyContour(testOutline, (float)TTF_SHAPE_SIMPLIFICATION_AMNT);
			}else{
				charOutlines.contours.back().pts = testOutline;
			}
		}

	return charOutlines;
}
예제 #19
0
void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
{
  //check if we operate on a vector layer
  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
  if ( !vlayer )
  {
    notifyNotVectorLayer();
    return;
  }

  if ( !vlayer->isEditable() )
  {
    notifyNotEditableLayer();
    return;
  }

  //inform user at the begin of the digitising action that the island tool only works if exactly one feature is selected
  int nSelectedFeatures = vlayer->selectedFeatureCount();
  QString selectionErrorMsg;
  if ( nSelectedFeatures < 1 )
  {
    selectionErrorMsg = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
  }
  else if ( nSelectedFeatures > 1 )
  {
    selectionErrorMsg = tr( "Several features are selected. Please select only one feature to which an part should be added." );
  }

  if ( !selectionErrorMsg.isEmpty() )
  {
    QMessageBox::critical( 0, tr( "Error. Could not add part." ), selectionErrorMsg );
    stopCapturing();
    return;
  }

  int errorCode;
  switch ( mode() )
  {
    case CapturePoint:
    {
      QgsPoint layerPoint;
      QgsPoint mapPoint;

      if ( nextPoint( e->pos(), layerPoint, mapPoint ) != 0 )
      {
        QgsDebugMsg( "nextPoint failed" );
        return;
      }

      vlayer->beginEditCommand( tr( "Part added" ) );
      errorCode = vlayer->addPart( QList<QgsPoint>() << layerPoint );
    }
    break;

    case CaptureLine:
    case CapturePolygon:
    {
      //add point to list and to rubber band
      if ( e->button() == Qt::LeftButton )
      {
        int error = addVertex( e->pos() );
        if ( error == 1 )
        {
          QgsDebugMsg( "current layer is not a vector layer" );
          return;
        }
        else if ( error == 2 )
        {
          //problem with coordinate transformation
          QMessageBox::information( 0,
                                    tr( "Coordinate transform error" ),
                                    tr( "Cannot transform the point to the layers coordinate system" ) );
          return;
        }

        startCapturing();
        return;
      }
      else if ( e->button() != Qt::RightButton )
      {
        deleteTempRubberBand();

        return;
      }

      if ( mode() == CapturePolygon )
      {
        //close polygon
        closePolygon();
        //avoid intersections
        QgsGeometry* geom = QgsGeometry::fromPolygon( QgsPolygon() << points().toVector() );
        if ( geom )
        {
          geom->avoidIntersections();
          QgsPolygon poly = geom->asPolygon();
          if ( poly.size() < 1 )
          {
            stopCapturing();
            delete geom;
            vlayer->destroyEditCommand();
            return;
          }
          setPoints( geom->asPolygon()[0].toList() );
          delete geom;
        }
      }

      vlayer->beginEditCommand( tr( "Part added" ) );
      errorCode = vlayer->addPart( points() );

      stopCapturing();
    }
    break;
    default:
      Q_ASSERT( !"invalid capture mode" );
      errorCode = 6;
      break;
  }

  QString errorMessage;
  switch ( errorCode )
  {
    case 0:
    {
      //add points to other features to keep topology up-to-date
      int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
      if ( topologicalEditing )
      {
        addTopologicalPoints( points() );
      }

      vlayer->endEditCommand();

      mCanvas->refresh();
      return;
    }

    case 1:
      errorMessage = tr( "Selected feature is not multi part." );
      break;

    case 2:
      errorMessage = tr( "New part's geometry is not valid." );
      break;

    case 3:
      errorMessage = tr( "New polygon ring not disjoint with existing polygons." );
      break;

    case 4:
      errorMessage = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
      break;

    case 5:
      errorMessage = tr( "Several features are selected. Please select only one feature to which an island should be added." );
      break;

    case 6:
      errorMessage = tr( "Selected geometry could not be found" );
      break;
  }

  QMessageBox::critical( 0, tr( "Error, could not add part" ), errorMessage );
  vlayer->destroyEditCommand();
}
예제 #20
0
int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator::Match &match )
{
  if ( mode() == CaptureNone )
  {
    QgsDebugMsg( QStringLiteral( "invalid capture mode" ) );
    return 2;
  }

  int res;
  QgsPoint layerPoint;
  res = fetchLayerPoint( match, layerPoint );
  if ( res != 0 )
  {
    res = nextPoint( QgsPoint( point ), layerPoint );
    if ( res != 0 )
    {
      return res;
    }
  }

  if ( !mRubberBand )
  {
    mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
  }

  if ( !mTempRubberBand )
  {
    mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
  }
  else
  {
    mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
  }

  bool traceCreated = false;
  if ( tracingEnabled() )
  {
    traceCreated = tracingAddVertex( point );
  }

  // keep new tracing start point if we created a trace. This is useful when tracing with
  // offset so that the user stays "snapped"
  mTracingStartPoint = traceCreated ? point : QgsPointXY();

  if ( !traceCreated )
  {
    // ordinary digitizing
    mRubberBand->addPoint( point );
    mCaptureCurve.addVertex( layerPoint );
    mSnappingMatches.append( match );
  }

  if ( mCaptureMode == CaptureLine )
  {
    mTempRubberBand->addPoint( point );
  }
  else if ( mCaptureMode == CapturePolygon )
  {
    const QgsPointXY *firstPoint = mRubberBand->getPoint( 0, 0 );
    mTempRubberBand->addPoint( *firstPoint );
    mTempRubberBand->movePoint( point );
    mTempRubberBand->addPoint( point );
  }

  validateGeometry();

  return 0;
}
예제 #21
0
int QgsMapToolCapture::nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint )
{
  mapPoint = QgsPoint( toMapCoordinates( p ) );
  return nextPoint( mapPoint, layerPoint );
}
예제 #22
0
bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
{
  QgsMapCanvasTracer *tracer = QgsMapCanvasTracer::tracerForCanvas( mCanvas );
  if ( !tracer )
    return false;  // this should not happen!

  if ( mCaptureCurve.numPoints() == 0 )
  {
    if ( !tracer->init() )
    {
      tracer->reportError( QgsTracer::ErrTooManyFeatures, true );
      return false;
    }

    // only accept first point if it is snapped to the graph (to vertex or edge)
    bool res = tracer->isPointSnapped( point );
    if ( res )
    {
      QgsPoint layerPoint;
      nextPoint( QgsPoint( point ), layerPoint ); // assuming the transform went fine earlier

      mRubberBand->addPoint( point );
      mCaptureCurve.addVertex( layerPoint );
      mSnappingMatches.append( QgsPointLocator::Match() );
    }
    return res;
  }

  QgsPointXY pt0 = tracingStartPoint();
  if ( pt0 == QgsPointXY() )
    return false;

  QgsTracer::PathError err;
  QVector<QgsPointXY> points = tracer->findShortestPath( pt0, point, &err );
  if ( points.isEmpty() )
    return false; // ignore the vertex - can't find path to the end point!

  if ( !mCaptureCurve.isEmpty() )
  {
    QgsPoint lp; // in layer coords
    if ( nextPoint( QgsPoint( pt0 ), lp ) != 0 )
      return false;
    QgsPoint last;
    QgsVertexId::VertexType type;
    mCaptureCurve.pointAt( mCaptureCurve.numPoints() - 1, last, type );
    if ( last == lp )
    {
      // remove the last point in the curve if it is the same as our first point
      if ( mCaptureCurve.numPoints() != 2 )
        mCaptureCurve.deleteVertex( QgsVertexId( 0, 0, mCaptureCurve.numPoints() - 1 ) );
      else
      {
        // there is a strange behavior in deleteVertex() that with just two points
        // the whole curve is cleared - so we need to do this little dance to work it around
        QgsPoint first = mCaptureCurve.startPoint();
        mCaptureCurve.clear();
        mCaptureCurve.addVertex( first );
      }
      // for unknown reasons, rubber band has 2 points even if only one point has been added - handle that case
      if ( mRubberBand->numberOfVertices() == 2 && *mRubberBand->getPoint( 0, 0 ) == *mRubberBand->getPoint( 0, 1 ) )
        mRubberBand->removeLastPoint();
      mRubberBand->removeLastPoint();
      mSnappingMatches.removeLast();
    }
  }

  // transform points
  QgsPointSequence layerPoints;
  QgsPoint lp; // in layer coords
  for ( int i = 0; i < points.count(); ++i )
  {
    if ( nextPoint( QgsPoint( points[i] ), lp ) != 0 )
      return false;
    layerPoints << lp;
  }

  for ( int i = 0; i < points.count(); ++i )
  {
    if ( i == 0 && !mCaptureCurve.isEmpty() && mCaptureCurve.endPoint() == layerPoints[0] )
      continue;  // avoid duplicate of the first vertex
    if ( i > 0 && points[i] == points[i - 1] )
      continue; // avoid duplicate vertices if there are any
    mRubberBand->addPoint( points[i], i == points.count() - 1 );
    mCaptureCurve.addVertex( layerPoints[i] );
    mSnappingMatches.append( QgsPointLocator::Match() );
  }

  tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error
  return true;
}
예제 #23
0
int QgsMapToolCapture::nextPoint( const QPoint &p, QgsPoint &layerPoint, QgsPoint &mapPoint )
{

  mapPoint = toMapCoordinates( p );
  return nextPoint( mapPoint, layerPoint );
}