示例#1
0
void Stroke::Resample(float iSampling)
{
	//cerr << "old size :" << strokeVerticesSize() << endl;
	if (iSampling == 0)
		return;
	if (iSampling >= _sampling)
		return;

	_sampling = iSampling;
	// Resample...
	//real curvilinearLength = 0.0f;
	vertex_container newVertices;
	real t = 0.0f;
	const real limit = 0.99;
	StrokeVertex *newVertex = NULL;
	StrokeInternal::StrokeVertexIterator it = strokeVerticesBegin();
	StrokeInternal::StrokeVertexIterator next = it;
	++next;
	StrokeInternal::StrokeVertexIterator itend = strokeVerticesEnd();
	while ((it != itend) && (next != itend)) {
		newVertices.push_back(&(*it));
		Vec2r a((it)->getPoint());
		Vec2r b((next)->getPoint());
		Vec2r vec_tmp(b - a);
		real norm_var = vec_tmp.norm();
		if (norm_var <= _sampling) {
			//curvilinearLength += norm_var;
			++it;
			++next;
			continue;
		}

		//curvilinearLength += _sampling;
		t = _sampling / norm_var;
		while (t < limit) {
			newVertex = new StrokeVertex(&(*it), &(*next), t);
			//newVertex->setCurvilinearAbscissa(curvilinearLength);
			newVertices.push_back(newVertex);
			t = t + _sampling / norm_var;
		}
		++it;
		++next;
	}
	// add last:
	if ((it != itend) && (next == itend)/* && (t == 0.f)*/)
		newVertices.push_back(&(*it));

	_Vertices.clear();
	_Vertices = newVertices;
	newVertices.clear();

	if (_rep) {
		delete _rep;
		_rep = new StrokeRep(this);
	}
}
std::vector< GroupPtr > ServerConnection::getGoupList()
{
	FRL_EXCEPT_GUARD();
	boost::mutex::scoped_lock guard( scope_guard );
	if( ! isConnected() )
		FRL_THROW_S_CLASS( NotConnected );
	std::vector<GroupPtr> vec_tmp( group_list.size() );
	std::transform( group_list.begin(), group_list.end(), vec_tmp.begin(), boost::mem_fn(&GroupList::value_type::second ) );
	return vec_tmp;
}
示例#3
0
Smoother::Smoother(Stroke &ioStroke)
{
	_stroke = &ioStroke;

	_nbVertices = ioStroke.vertices_size();
	_vertex = new Vec2r[_nbVertices];
	_curvature = new real[_nbVertices];
	_normal = new Vec2r[_nbVertices];
	StrokeInternal::StrokeVertexIterator v, vend;
	int i = 0;
	for (v = ioStroke.strokeVerticesBegin(), vend = ioStroke.strokeVerticesEnd(); v != vend; ++v, ++i) {
		_vertex[i] = (v)->getPoint();
	}
	Vec2r vec_tmp(_vertex[0] - _vertex[_nbVertices - 1]);
	_isClosedCurve = (vec_tmp.norm() < M_EPSILON);

	_safeTest = (_nbVertices > 4);
}
示例#4
0
void TapCamera::Update()
{
    if( momentum_ )
    {
        float momenttum_steps = momemtum_steps_;

        //Momentum rotation
        Vec2 v = vec_drag_delta_;
        BeginDrag( Vec2() ); //NOTE:This call reset _VDragDelta
        Drag( v * vec_flip_ );

        //Momentum shift
        vec_offset_ += vec_offset_delta_;

        BallUpdate();
        EndDrag();

        //Decrease deltas
        vec_drag_delta_ = v * MOMENTUM_FACTOR_DECREASE;
        vec_offset_delta_ = vec_offset_delta_ * MOMENTUM_FACTOR_DECREASE_SHIFT;

        //Count steps
        momemtum_steps_ = momenttum_steps * MOMENTUM_FACTOR_DECREASE;
        if( momemtum_steps_ < MOMENTUM_FACTOR_THRESHOLD )
        {
            momentum_ = false;
        }
    }
    else
    {
        vec_drag_delta_ *= MOMENTUM_FACTOR;
        vec_offset_delta_ = vec_offset_delta_ * MOMENTUM_FACTOR;
        BallUpdate();
    }

    Vec3 vec = vec_offset_ + vec_offset_now_;
    Vec3 vec_tmp( TRANSFORM_FACTOR, -TRANSFORM_FACTOR, TRANSFORM_FACTORZ );

    vec *= vec_tmp * vec_pinch_transform_factor_;

    mat_transform_ = Mat4::Translation( vec );
}
示例#5
0
vector< pix > getComparatorOct(uint dim, double angle){
	vector< pix > vec;
	
	double dimension = dim - 1;
	
	uint counter = 0;
	for (uint i = 1; i < dimension + 1; i++){
		for (uint j = 1; j < dimension + 1; j++){
			if( pow(i - (dimension+1)/2,2) + pow(j - (dimension+1)/2,2) <= pow((dimension+1)/2,2) ){
				pix p;
				setPix(p,i-1,j-1,counter);
				vec.push_back(p);
				counter++;
			}
		}
	}
	
	vector< pix > vec_tmp(vec.begin(), vec.end());
	
	double x = 0;
	double xtemp = 0;
	double y = 0;
	double ytemp = 0;
	double r = (double)dimension / 2;
	
	angle = (360.0 - angle) / 180 * PI;
	
	for(uint d = 0; d < vec_tmp.size(); d++){
		pix p;
		x = (double)vec_tmp[d].x - r;
		y = (double)vec_tmp[d].y - r;
		xtemp = x*cos(angle) - y*sin(angle) + r;
		ytemp = x*sin(angle) + y*cos(angle) + r;
		setPix(p, xtemp, ytemp, vec_tmp[d].v);
		vec[ d ] = p;
	}
	
	return vec;
}
void HostVector<ValueType>::PermuteBackward(const BaseVector<int> &permutation) {

  assert(&permutation != NULL);

  const HostVector<int> *cast_perm = dynamic_cast<const HostVector<int>*> (&permutation);

  assert(cast_perm != NULL);
  assert(this->size_ == cast_perm->size_);

  HostVector<ValueType> vec_tmp(this->local_backend_);
  vec_tmp.Allocate(this->size_);
  vec_tmp.CopyFrom(*this);

  _set_omp_backend_threads(this->local_backend_, this->size_);

#pragma omp parallel for
  for (int i=0; i<this->size_; ++i) {
    assert_dbg(cast_perm->vec_[i] >= 0);
    assert_dbg(cast_perm->vec_[i] < this->size_);
    this->vec_[i] = vec_tmp.vec_[ cast_perm->vec_[i] ];
  }
}
示例#7
0
int Stroke::Resample(int iNPoints)
{
  int NPointsToAdd = iNPoints - strokeVerticesSize();
  if (NPointsToAdd <= 0)
    return 0;

  StrokeInternal::StrokeVertexIterator it = strokeVerticesBegin();
  StrokeInternal::StrokeVertexIterator next = it;
  ++next;
  StrokeInternal::StrokeVertexIterator itend = strokeVerticesEnd();

  vertex_container newVertices;
  real t = 0.0f;
  StrokeVertex *newVertex = NULL;
  vector<StrokeSegment> strokeSegments;
  int N = 0;
  float meanlength = 0;
  int nsegments = 0;
  while ((it != itend) && (next != itend)) {
    Vec2r a((it)->getPoint());
    Vec2r b((next)->getPoint());
    Vec2r vec_tmp(b - a);
    real norm_var = vec_tmp.norm();
    int numberOfPointsToAdd = (int)floor(NPointsToAdd * norm_var / _Length);
    float csampling = norm_var / (float)(numberOfPointsToAdd + 1);
    strokeSegments.push_back(StrokeSegment(it, next, norm_var, numberOfPointsToAdd, csampling));
    N += numberOfPointsToAdd;
    meanlength += norm_var;
    ++nsegments;
    ++it;
    ++next;
  }
  meanlength /= (float)nsegments;

  // if we don't have enough points let's resample finer some segments
  bool checkEveryone = false;
  bool resampled;
  while (N < NPointsToAdd) {
    resampled = false;
    for (vector<StrokeSegment>::iterator s = strokeSegments.begin(), send = strokeSegments.end();
         s != send;
         ++s) {
      if (s->_sampling == 0.0f)
        continue;

      if (s->_resampled == false) {
        if ((!checkEveryone) && (s->_length < meanlength))
          continue;
        // resample
        s->_n = s->_n + 1;
        s->_sampling = s->_length / (float)(s->_n + 1);
        s->_resampled = resampled = true;
        N++;
        if (N == NPointsToAdd)
          break;
      }
    }
    if (checkEveryone && !resampled)
      break;
    checkEveryone = true;
  }
  if (N < NPointsToAdd) {
    // fatal error, likely because _Length is inconsistent with the stroke length computed with the
    // vertices
    return -1;
  }
  // actually resample:
  for (vector<StrokeSegment>::iterator s = strokeSegments.begin(), send = strokeSegments.end();
       s != send;
       ++s) {
    newVertices.push_back(&(*(s->_begin)));
    if (s->_sampling < _sampling)
      _sampling = s->_sampling;

    t = s->_sampling / s->_length;
    for (int i = 0; i < s->_n; ++i) {
      newVertex = new StrokeVertex(&(*(s->_begin)), &(*(s->_end)), t);
      newVertices.push_back(newVertex);
      t += s->_sampling / s->_length;
    }
    it = s->_begin;
    next = s->_end;
  }

  // add last:
  ++it;
  ++next;
  if ((it != itend) && (next == itend) /* && (t == 0.0f)*/)
    newVertices.push_back(&(*it));

  int newsize = newVertices.size();
  if (newsize != iNPoints)
    cerr << "Warning: incorrect points number" << endl;

  _Vertices.clear();
  _Vertices = newVertices;
  newVertices.clear();

  return 0;
}
示例#8
0
static Stroke *createStroke(Interface1D& inter)
{
	Stroke *stroke = new Stroke;
	stroke->setId(inter.getId());

	float currentCurvilignAbscissa = 0.0f;

	Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
	Interface0DIterator itfirst = it;

	Vec2r current(it->getPoint2D());
	Vec2r previous = current;
	SVertex *sv;
	CurvePoint *cp;
	StrokeVertex *stroke_vertex = NULL;
	bool hasSingularity = false;

	do {
		cp = dynamic_cast<CurvePoint*>(&(*it));
		if (!cp) {
			sv = dynamic_cast<SVertex*>(&(*it));
			if (!sv) {
				cerr << "Warning: unexpected Vertex type" << endl;
				continue;
			}
			stroke_vertex = new StrokeVertex(sv);
		}
		else {
			stroke_vertex = new StrokeVertex(cp);
		}
		current = stroke_vertex->getPoint2D();
		Vec2r vec_tmp(current - previous);
		real dist = vec_tmp.norm();
		if (dist < 1.0e-6)
			hasSingularity = true;
		currentCurvilignAbscissa += dist;
		stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa);
		stroke->push_back(stroke_vertex);
		previous = current;
		++it;
	} while ((it != itend) && (it != itfirst));

	if (it == itfirst) {
		// Add last vertex:
		cp = dynamic_cast<CurvePoint*>(&(*it));
		if (!cp) {
			sv = dynamic_cast<SVertex*>(&(*it));
			if (!sv)
				cerr << "Warning: unexpected Vertex type" << endl;
			else
				stroke_vertex = new StrokeVertex(sv);
		}
		else {
			stroke_vertex = new StrokeVertex(cp);
		}
		current = stroke_vertex->getPoint2D();
		Vec2r vec_tmp(current - previous);
		real dist = vec_tmp.norm();
		if (dist < 1.0e-6)
			hasSingularity = true;
		currentCurvilignAbscissa += dist;
		stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa);
		stroke->push_back(stroke_vertex);
	}
	// Discard the stroke if the number of stroke vertices is less than two
	if (stroke->strokeVerticesSize() < 2) {
		delete stroke;
		return NULL;
	}
	stroke->setLength(currentCurvilignAbscissa);
	if (hasSingularity) {
		// Try to address singular points such that the distance between two subsequent vertices
		// are smaller than epsilon.
		StrokeInternal::StrokeVertexIterator v = stroke->strokeVerticesBegin();
		StrokeInternal::StrokeVertexIterator vnext = v;
		++vnext;
		Vec2r next((*v).getPoint());
		while (!vnext.isEnd()) {
			current = next;
			next = (*vnext).getPoint();
			if ((next - current).norm() < 1.0e-6) {
				StrokeInternal::StrokeVertexIterator vprevious = v;
				if (!vprevious.isBegin())
					--vprevious;

				// collect a set of overlapping vertices
				std::vector<StrokeVertex *> overlapping_vertices;
				overlapping_vertices.push_back(&(*v));
				do {
					overlapping_vertices.push_back(&(*vnext));
					current = next;
					++v;
					++vnext;
					if (vnext.isEnd())
						break;
					next = (*vnext).getPoint();
				} while ((next - current).norm() < 1.0e-6);

				Vec2r target;
				bool reverse;
				if (!vnext.isEnd()) {
					target = (*vnext).getPoint();
					reverse = false;
				}
				else if (!vprevious.isBegin()) {
					target = (*vprevious).getPoint();
					reverse = true;
				}
				else {
					// Discard the stroke because all stroke vertices are overlapping
					delete stroke;
					return NULL;
				}
				current = overlapping_vertices.front()->getPoint();
				Vec2r dir(target - current);
				real dist = dir.norm();
				real len = 1.0e-3; // default offset length
				int nvert = overlapping_vertices.size();
				if (dist < len * nvert) {
					len = dist / nvert;
				}
				dir.normalize();
				Vec2r offset(dir * len);
				// add the offset to the overlapping vertices
				StrokeVertex *sv;
				std::vector<StrokeVertex *>::iterator it = overlapping_vertices.begin();
				if (!reverse) {
					for (int n = 0; n < nvert; n++) {
						sv = (*it);
						sv->setPoint(sv->getPoint() + offset * (n + 1));
						++it;
					}
				}
				else {
					for (int n = 0; n < nvert; n++) {
						sv = (*it);
						sv->setPoint(sv->getPoint() + offset * (nvert - n));
						++it;
					}
				}

				if (vnext.isEnd())
					break;
			}
			++v;
			++vnext;
		}
	}
	{
		// Check if the stroke no longer contains singular points
		Interface0DIterator v = stroke->verticesBegin();
		Interface0DIterator vnext = v;
		++vnext;
		Vec2r next((*v).getPoint2D());
		bool warning = false;
		while (!vnext.isEnd()) {
			current = next;
			next = (*vnext).getPoint2D();
			if ((next - current).norm() < 1.0e-6) {
				warning = true;
				break;
			}
			++v;
			++vnext;
		}
		if (warning && G.debug & G_DEBUG_FREESTYLE) {
			printf("Warning: stroke contains singular points.\n");
		}
	}
	return stroke;
}
示例#9
0
void OclBM::getDepth(const cv::Mat& Disp,float*depth,int& dataSize){
	cv::Mat_<cv::Vec3f> XYZ(Disp.rows,Disp.cols);   // Output point cloud
	cv::Mat_<float> vec_tmp(4,1);
	cv::Mat_<float> vec_Qw(4,4);

	Qw.copyTo(vec_Qw);
	const double max_z = maxZ;
	int nonzero_num = 0;

	unsigned char*cannyMask = CannyMat.data;
	int i = 0;
	for(int y=0; y<Disp.rows; ++y) {
		for(int x=0; x<Disp.cols; ++x) {
			int masklabel = 1;
			if(edge_method == HAS_EDGE)
			{
				masklabel = (int)cannyMask[i];
			}
	        vec_tmp(0)=x; vec_tmp(1)=y; vec_tmp(2)=(float)Disp.at<uchar>(y,x); vec_tmp(3)=1;
	        vec_tmp = vec_Qw*vec_tmp;
	        vec_tmp /= vec_tmp(3);
	        cv::Vec3f &point = XYZ.at<cv::Vec3f>(y,x);
	        if(fabs(vec_tmp(2) - max_z) < FLT_EPSILON || fabs(vec_tmp(2)) > max_z|| masklabel == 0)
	        {
	        	point[0] = 0; point[1] = 0; point[2] = 0;
	        }
	        else
	        {
	        	point[0] = vec_tmp(0);point[1] = vec_tmp(1);point[2] = vec_tmp(2);
	            nonzero_num++;
	         }
	        i++;
		}
	}
	saveXYZ(XYZ,depth);
	dataSize = nonzero_num*3;
}