Exemple #1
0
void
Clip::mediaMetadataUpdated()
{
    Q_ASSERT ( isRootClip() == true );
    if ( m_end == 0 )
    {
        m_begin = 0;
        m_end = m_media->source()->nbFrames();
        computeLength();
    }
}
Exemple #2
0
float parseSizesAttribute(StringView sizesAttribute, RenderView* view, Frame* frame)
{
    if (!view)
        return 0;
    RenderStyle& style = view->style();
    for (auto& sourceSize : CSSParser(CSSStrictMode).parseSizesAttribute(sizesAttribute)) {
        if (match(WTFMove(sourceSize.expression), style, frame))
            return computeLength(sourceSize.length.get(), style, view);
    }
    return defaultLength(style, view);
}
Exemple #3
0
void BaseFeather::computeTexcoord()
{
	Vector2F puv = m_uv;
	float *q = quilly();
	int i, j;
	for(i=0; i <= numSegment(); i++) {
		*segmentQuillTexcoord(i) = puv;
		if(i < numSegment()) {
			puv += Vector2F(0.f, *q);
			q++;
		}
	}
	
	q = quilly();
	puv = m_uv;
	
	Vector2F pvane;
	for(i=0; i <= numSegment(); i++) {
		
		pvane = puv;
		Vector2F * vanes = uvDisplaceAt(i, 0);
		
		for(j = 0; j < 3; j++) {
			pvane += vanes[j];
			*segmentVaneTexcoord(i, 0, j) = pvane;
		}

		pvane = puv;
		vanes = getUvDisplaceAt(i, 1);
		
		for(j = 0; j < 3; j++) {
			pvane += vanes[j];
			*segmentVaneTexcoord(i, 1, j) = pvane;
		}
		
		if(i < numSegment()) {
			puv += Vector2F(0.f, *q);
			q++;
		}
	}
	
	for(i = 0; i < numWorldP(); i++) {

		texcoord()[i] /= 32.f;
	}
		
	computeBounding();
	computeLength();
}
Exemple #4
0
void
MainWorkflow::startRender( quint32 width, quint32 height, double fps )
{
    //Reinit the effects in case the width/height has change
    m_renderStarted = true;
    m_width = width;
    m_height = height;
    if ( m_blackOutput != NULL )
        delete m_blackOutput;
    m_blackOutput = new Workflow::Frame( m_width, m_height );
    memset( m_blackOutput->buffer(), 0, m_blackOutput->size() );
    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
        m_tracks[i]->startRender( width, height, fps );
    computeLength();
}
Exemple #5
0
void
TrackWorkflow::addClip( ClipWorkflow* cw, qint64 start )
{
    QWriteLocker    lock( m_clipsLock );
    m_clips.insert( start, cw );
    connect( cw, SIGNAL( effectAdded( EffectHelper*, qint64 ) ),
             this, SLOT( __effectAdded( EffectHelper*, qint64 ) ) );
    connect( cw, SIGNAL( effectMoved( EffectHelper*, qint64 ) ),
             this, SLOT( __effectMoved( EffectHelper*, qint64) ) );
    connect( cw, SIGNAL( effectRemoved( QUuid ) ),
             this, SLOT( __effectRemoved( QUuid ) ) );
    connect( cw->getClipHelper(), SIGNAL( destroyed( QUuid ) ),
             this, SLOT( clipDestroyed( QUuid ) ) );
    emit clipAdded( this, cw->getClipHelper(), start );
    computeLength();
}
Exemple #6
0
void PolygonLine :: giveSubPolygon(std :: vector< FloatArray > &oPoints, const double &iXiStart, const double &iXiEnd) const
{
    double L = computeLength();
    double xSegStart = 0.0, xSegEnd = 0.0;
    double xiSegStart = 0.0, xiSegEnd = 0.0;
    size_t numSeg = mVertices.size() - 1;
    const double xiTol = 1.0e-9;
    if ( iXiStart < xiTol ) {
        // Add first point
        oPoints.push_back(mVertices [ 0 ]);
    }

    for ( size_t i = 0; i < numSeg; i++ ) {
        xSegEnd += mVertices [ i ].distance(mVertices [ i + 1 ]);

        xiSegStart = xSegStart / L;
        xiSegEnd        = xSegEnd / L;

        if ( iXiStart > xiSegStart-xiTol && iXiStart < xiSegEnd+xiTol ) {
            // Start point is within the segment
            FloatArray p;
            double elXi = ( iXiStart - xiSegStart ) / ( xiSegEnd - xiSegStart );
            p.beScaled( ( 1.0 - elXi ), mVertices [ i ] );
            p.add(elXi, mVertices [ i + 1 ]);
            oPoints.push_back(p);
        }


        if ( iXiEnd > xiSegStart && iXiEnd < xiSegEnd ) {
            // End point is within the segment
            FloatArray p;
            double elXi = ( iXiEnd - xiSegStart ) / ( xiSegEnd - xiSegStart );
            p.beScaled( ( 1.0 - elXi ), mVertices [ i ] );
            p.add(elXi, mVertices [ i + 1 ]);
            oPoints.push_back(p);
        }

        if ( xiSegEnd > iXiStart && xiSegEnd < iXiEnd + xiTol ) {
            // End point of the segment is within range
            oPoints.push_back(mVertices [ i + 1 ]);
        }

        xSegStart = xSegEnd;
    }
}
Exemple #7
0
Clip::Clip( Media *media, qint64 begin /*= 0*/, qint64 end /*= -1*/, const QString& uuid /*= QString()*/ ) :
        m_media( media ),
        m_begin( begin ),
        m_end( end ),
        m_parent( media->baseClip() )
{
    if ( end == -1 )
        m_end = media->source()->nbFrames();
    if ( uuid.isEmpty() == true )
        m_uuid = QUuid::createUuid();
    else
        m_uuid = QUuid( uuid );
    m_childs = new MediaContainer( this );
    m_rootClip = media->baseClip();
    computeLength();
    connect( media, SIGNAL( metaDataComputed() ),
             this, SLOT( mediaMetadataUpdated() ) );
}
Exemple #8
0
Clip::Clip( Clip *parent, qint64 begin /*= -1*/, qint64 end /*= -1*/,
            const QString &uuid /*= QString()*/ ) :
        m_media( parent->getMedia() ),
        m_begin( begin ),
        m_end( end ),
        m_rootClip( parent->rootClip() ),
        m_parent( parent )
{
    if ( begin < 0 )
        m_begin = parent->m_begin;
    if ( end < 0 )
        m_end = parent->m_end;
    if ( uuid.isEmpty() == true )
        m_uuid = QUuid::createUuid();
    else
        m_uuid = QUuid( uuid );
    m_childs = new MediaContainer( this );
    computeLength();
}
Exemple #9
0
void
TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
{
    QWriteLocker    lock( m_clipsLock );

    QMap<qint64, ClipWorkflow*>::iterator       it = m_clips.begin();
    QMap<qint64, ClipWorkflow*>::iterator       end = m_clips.end();

    while ( it != end )
    {
        if ( it.value()->getClipHelper()->uuid() == id )
        {
            ClipWorkflow* cw = it.value();
            m_clips.erase( it );
            m_clips[startingFrame] = cw;
            cw->requireResync();
            computeLength();
            emit clipMoved( this, cw->getClipHelper()->uuid(), startingFrame );
            return ;
        }
        ++it;
    }
}
Exemple #10
0
ClipWorkflow*
TrackWorkflow::removeClipWorkflow( const QUuid& id )
{
    QWriteLocker    lock( m_clipsLock );

    QMap<qint64, ClipWorkflow*>::iterator       it = m_clips.begin();
    QMap<qint64, ClipWorkflow*>::iterator       end = m_clips.end();

    while ( it != end )
    {
        if ( it.value()->getClipHelper()->uuid() == id )
        {
            ClipWorkflow*   cw = it.value();
            cw->disconnect();
            m_clips.erase( it );
            computeLength();
            cw->getClipHelper()->disconnect( this );
            emit clipRemoved( this, cw->getClipHelper()->uuid() );
            return cw;
        }
        ++it;
    }
    return NULL;
}
Exemple #11
0
void
GiLightObject::computePath(QList<Vec> points)
{
  Vec voxelScaling = Global::voxelScaling();
  Vec voxelSize = VolumeInformation::volumeInformation().voxelSize;

  // -- collect path points for length computation
  QList<Vec> lengthPath;
  lengthPath.clear();

  m_path.clear();

  int npts = points.count();
  if (npts == 1)
    {
      m_path << VECPRODUCT(points[0], voxelScaling);
      m_pathT << Vec(0,0,1);
      m_pathX << Vec(0,1,0);
      m_pathY << Vec(1,0,0);
      return;
    }

  Vec prevPt;
  if (m_segments == 1)
    {
      for(int i=0; i<npts; i++)
	{
	  Vec v = VECPRODUCT(points[i], voxelScaling);
	  m_path.append(v);

	  // for length calculation
	  v = VECPRODUCT(points[i], voxelSize);
	  lengthPath.append(v);
	}

      computePathVectors();
  
      computeLength(lengthPath);
      return;
    }

  // for number of segments > 1 apply spline-based interpolation
  for(int i=1; i<npts; i++)
    {
      for(int j=0; j<m_segments; j++)
	{
	  float frc = (float)j/(float)m_segments;
	  Vec pos = interpolate(i-1, i, frc);

	  Vec pv = VECPRODUCT(pos, voxelScaling);
	  m_path.append(pv);

	  // for length calculation
	  pv = VECPRODUCT(pos, voxelSize);
	  lengthPath.append(pv);
	}
    }

  // last point
  Vec pos = VECPRODUCT(points[points.count()-1],
		       voxelScaling);
  m_path.append(pos);

  // for length calculation
  pos = VECPRODUCT(points[points.count()-1],
		   voxelSize);
  lengthPath.append(pos);
  
  computePathVectors();

  computeLength(lengthPath);
}
Exemple #12
0
void PolygonLine :: computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinArcDist) const
{
    const int numSeg = this->giveNrVertices() - 1;

    double xi = 0.0, xiUnbounded = 0.0;

    if(numSeg == 1) {
        const FloatArray &crackP1 = giveVertex ( 1 );
        const FloatArray &crackP2 = giveVertex ( 2 );
        iPoint.distance(crackP1, crackP2, xi, xiUnbounded);

        if( xiUnbounded < 0.0 ) {
            oDist = xiUnbounded*crackP1.distance(crackP2);
            oMinArcDist = 0.0;
            return;
        }

        if( xiUnbounded > 1.0 ) {
            oDist = -(xiUnbounded-1.0)*crackP1.distance(crackP2);
            oMinArcDist = 1.0;
            return;
        }

        const double L = computeLength();
        double distToStart  = xi*L;

        oDist = std::min(distToStart, (L - distToStart) );
        oMinArcDist = distToStart/L;
        return;
    }

    bool isBeforeStart = false, isAfterEnd = false;
    double distBeforeStart = 0.0, distAfterEnd = 0.0;

    ///////////////////////////////////////////////////////////////////
    // Check first segment
    const FloatArray &crackP1_start = giveVertex ( 1 );
    const FloatArray &crackP2_start = giveVertex ( 2 );
    const double distSeg_start = iPoint.distance(crackP1_start, crackP2_start, xi, xiUnbounded);

    if( xiUnbounded < 0.0 ) {
        isBeforeStart = true;
        distBeforeStart = xiUnbounded*crackP1_start.distance(crackP2_start);
    }

    double arcPosPassed = crackP1_start.distance(crackP2_start);
    double distToStart  = xi*crackP1_start.distance(crackP2_start);

    double minGeomDist  = distSeg_start;




    ///////////////////////////////////////////////////////////////////
    // Check interior segments
    for ( int segId = 2; segId <= numSeg-1; segId++ ) {
        const FloatArray &crackP1 = giveVertex ( segId      );
        const FloatArray &crackP2 = giveVertex ( segId+1    );

        const double distSeg = iPoint.distance(crackP1, crackP2, xi, xiUnbounded);

        if(distSeg < minGeomDist) {
            isBeforeStart = false;
            minGeomDist = distSeg;
            distToStart = arcPosPassed + xi*crackP1.distance(crackP2);
        }

        arcPosPassed += crackP1.distance(crackP2);

    }



    ///////////////////////////////////////////////////////////////////
    // Check last segment
    const FloatArray &crackP1_end = giveVertex ( numSeg );
    const FloatArray &crackP2_end = giveVertex ( numSeg+1 );
    const double distSeg_end = iPoint.distance(crackP1_end, crackP2_end, xi, xiUnbounded);

    if(numSeg > 1) {
        if( xiUnbounded > 1.0 ) {
            arcPosPassed += xiUnbounded*crackP1_end.distance(crackP2_end);
        }
        else {
            arcPosPassed += xi*crackP1_end.distance(crackP2_end);
        }
    }

    if(distSeg_end < minGeomDist) {
        isBeforeStart = false;

        if( xiUnbounded > 1.0 ) {
            isAfterEnd = true;
            distAfterEnd = -(xiUnbounded-1.0)*crackP1_end.distance(crackP2_end);
        }

        distToStart = arcPosPassed;
    }

    ///////////////////////////////////////////////////////////////////
    // Return result

    if(isBeforeStart) {
        oDist = distBeforeStart;
        oMinArcDist = 0.0;
        return;
    }

    if(isAfterEnd) {
        oDist = distAfterEnd;
        oMinArcDist = 1.0;
        return;
    }

    const double L = computeLength();

    oDist = std::min(distToStart, (L - distToStart) );
    oMinArcDist = distToStart/L;
}
void Centerline::createBranches(int maxN)
{
  //sort colored lines and create edges
  std::vector<std::vector<MLine*> > color_edges;
  color_edges.resize(maxN);
  std::multiset<MVertex*> allV;
  std::map<MLine*, int>::iterator itl = colorl.begin();
  while (itl != colorl.end()){
    int color = itl->second;
    MLine* l = itl->first;
    allV.insert(l->getVertex(0));
    allV.insert(l->getVertex(1));
    color_edges[color-1].push_back(l);
    itl++;
  }

  //detect junctions
  std::multiset<MVertex*>::iterator it = allV.begin();
  for ( ; it != allV.end(); ++it){
    if (allV.count(*it) != 2) {
      junctions.insert(*it);
    }
  }

  //split edges
  int tag = 0;
  for(unsigned int i = 0; i < color_edges.size(); ++i){
    std::vector<MLine*> lines = color_edges[i];
    while (!lines.empty()) {
      std::vector<MLine*> myLines;
      std::vector<MLine*>::iterator itl = lines.begin();
      MVertex *vB = (*itl)->getVertex(0);
      MVertex *vE = (*itl)->getVertex(1);
      myLines.push_back(*itl);
      erase(lines, *itl);
      itl = lines.begin();
      while ( !( junctions.find(vE) != junctions.end() &&
		 junctions.find(vB) != junctions.end()) ) {
  	MVertex *v1 = (*itl)->getVertex(0);
  	MVertex *v2 = (*itl)->getVertex(1);
	bool goVE = (junctions.find(vE) == junctions.end()) ? true : false ;
	bool goVB = (junctions.find(vB) == junctions.end()) ? true : false;
      	if (v1 == vE && goVE){
    	  myLines.push_back(*itl);
  	  erase(lines, *itl);
	  itl = lines.begin();
  	  vE = v2;
  	}
  	else if ( v2 == vE && goVE){
    	  myLines.push_back(*itl);
  	  erase(lines, *itl);
	  itl = lines.begin();
  	  vE = v1;
  	}
  	else if ( v1 == vB && goVB){
    	  myLines.push_back(*itl);
  	  erase(lines, *itl);
	  itl = lines.begin();
  	  vB = v2;
  	}
  	else if ( v2 == vB && goVB){
   	  myLines.push_back(*itl);
	  erase(lines, *itl);
	  itl = lines.begin();
  	  vB = v1;
  	}
	else itl++;
      }
      if (vB == vE) {
        Msg::Error("Begin and end points branch are the same \n");
        break;
      }
      orderMLines(myLines, vB, vE);
      std::vector<Branch> children;
      Branch newBranch ={ tag++, myLines, computeLength(myLines), vB, vE,
                          children, 1.e6, 0.0};
      edges.push_back(newBranch) ;
    }
  }

  Msg::Info("Centerline: in/outlets =%d branches =%d ",
            (int)color_edges.size()+1, (int)edges.size());

  //create children
  for(unsigned int i = 0; i < edges.size(); ++i) {
    MVertex *vE = edges[i].vE;
    std::vector<Branch> myChildren;
    for (std::vector<Branch>::iterator it = edges.begin(); it != edges.end(); ++it){
      Branch myBranch = *it;
      if (myBranch.vB == vE) myChildren.push_back(myBranch);
    }
    edges[i].children = myChildren;
  }

  //compute radius
  distanceToSurface();
  computeRadii();

  //print for debug
  printSplit();

}
Exemple #14
0
void paperRegistration::detectFigures(cv::vector<cv::vector<cv::Point>>& squares, cv::vector<cv::vector<cv::Point>>& triangles,
	float minLength, float maxLength, int tresh_binary)
{
	if (currentDeviceImg.empty())
		return;
	
	//cv::Mat image = currentDeviceImg;
	//cv::Mat image = cv::imread("C:/Users/sophie/Desktop/meinz.png", CV_LOAD_IMAGE_GRAYSCALE);// cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE);  
	//resize(image, image, cv::Size(500,700));

	squares.clear();  
	triangles.clear();	
	
	cv::Mat gray;
	cv::Mat element = getStructuringElement(cv::MORPH_RECT, cv::Size(7,7));
	cv::vector<cv::vector<cv::Point> > contours;

	//compute binary image
	//use dilatation and erosion to improve edges
	threshold(currentDeviceImg, gray, tresh_binary, 255, cv::THRESH_BINARY_INV);	
	dilate(gray, gray, element, cv::Point(-1,-1));
	erode(gray, gray, element, cv::Point(-1,-1));
	
	// find contours and store them all as a list
	cv::findContours(gray, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
	
	//test each contour
	cv::vector<cv::Point> approx;
	cv::vector<cv::vector<cv::Point> >::iterator iterEnd = contours.end();
	for(cv::vector<cv::vector<cv::Point> >::iterator iter = contours.begin(); iter != iterEnd; ++iter)
	{
		// approximate contour with accuracy proportional
		// to the contour perimeter
		cv::approxPolyDP(*iter, approx, arcLength(*iter, true)*0.03, true);
	     
		//contours should be convex
		if (isContourConvex(approx))
		{
			// square contours should have 4 vertices after approximation and 
			// relatively large length (to filter out noisy contours)
			if( approx.size() == 4)
			{
				bool rectangular = true;	 
				for( int j = 3; j < 6; j++ )
				{
					// if cosines of all angles are small
					// (all angles are ~90 degree) then write
					// vertices to result
					 if (fabs(90 - fabs(computeAngle(approx[j%4], approx[j-3], approx[j-2]))) > 7)
					 {
						rectangular = false;
						break;
					 }
				}
				
				if (!rectangular)
					continue;
				
				float side1 = computeLength(approx[0], approx[1]);
				float side2 = computeLength(approx[1], approx[2]);
					
				if (side1 > minLength && side1 < maxLength && 
					side2 > minLength && side2 < maxLength)
					squares.push_back(approx);
			}		
			// triangle contours should have 3 vertices after approximation and 
			// relatively large length (to filter out noisy contours)
			else if ( approx.size() == 3)
			{
				float side1 = computeLength(approx[0], approx[1]);
				float side2 = computeLength(approx[1], approx[2]);
				float side3 = computeLength(approx[2], approx[0]);
				
				if (side1 > minLength && side1 < maxLength && 
					side2 > minLength && side2 < maxLength &&
					side3 > minLength && side3 < maxLength)
					triangles.push_back(approx);
			}
		}
	}
}
Exemple #15
0
eCodes WsEncoder::encodePlainPacket()
{
    eCodes code = eCodes::ST_Ok;

    switch (_writeState)
    {
        case eWriteState::None:
        {
            computeLength();
            _writeState  = eWriteState::Header;
            _firstPacket = true;
            _encodedLen  = 0;
        }
        // No break;

        case eWriteState::Header:
        {
            if ((_sendVecEndPtr - _currPtr) < _headerLen)
            {
                // Left space is not enough.
                return eCodes::ST_BufferFull;
            }

            bool fin = true;
            if (_fragmented)
            {
                if (_totalLen - _encodedLen <= _payloadLen)
                {
                    // The last packet. fin should be true.
                    _payloadLen = _totalLen - _encodedLen;
                }
                else
                {
                    fin = false;
                }
            }

            writeHeader(_firstPacket, fin);

            // Reset mask function related variables.
            _maskKeyIdx   = 0;
            _maskBeginPtr = _currPtr;

            if (_firstPacket)
            {
                _firstPacket = false;
                getMetaData(ePayloadItem::SysJson, _sysJsonStr.size());
                _writeState = eWriteState::SysJsonMeta;
                _srcPtr     = &(*_metaData.begin());
                _srcEndPtr  = &(*_metaData.end());
            }
            else
            {
                _writeState = _prevWriteState;
                return encodePlainPacket();
            }
        }
        // No break;

        case eWriteState::SysJsonMeta:
        {
            code = encodeMeta();
            if (code == eCodes::ST_BufferFull)
            {
                return code;
            }
        }
        // no break;

        case eWriteState::SysJson:
        {
            code = encodeData();
            if (code == eCodes::ST_BufferFull || code == eCodes::ST_Complete)
            {
                return code;
            }
        }
        // no break;

        case eWriteState::JsonMeta:
        {
            code = encodeMeta();
            if (code == eCodes::ST_BufferFull)
            {
                return code;
            }
        }
        // no break;

        case eWriteState::Json:
        {
            code = encodeData();
            if (code == eCodes::ST_BufferFull || code == eCodes::ST_Complete)
            {
                return code;
            }
        }
        // no break;

        case eWriteState::BinaryMeta:
        {
            code = encodeMeta();
            if (code == eCodes::ST_BufferFull)
            {
                return code;
            }
        }
        // no break;

        case eWriteState::Binary:
        {
            code = encodeData();
            if (code == eCodes::ST_BufferFull || code == eCodes::ST_Complete)
            {
                return code;
            }
        }
        break;

        default:
        {
            PARROT_ASSERT(false);
        }
    }

    return code;
}