Ejemplo n.º 1
0
Vector3 PolyLine::interpolate(scalar_t t) const {
	if(t > 1.0) t = 1.0;
	if(t < 0.0) t = 0.0;

	if(control_points.size() < 2) return Vector3(0, 0, 0);

	// TODO: check if this is reasonable for polylines.
	if(arc_parametrize) {
		t = ease(parametrize(t));
	}

	// find the appropriate segment of the spline that t lies and calculate the piecewise parameter
	t = (scalar_t)(control_points.size() - 1) * t;
	int seg = (int)t;
	t -= (scalar_t)floor(t);
	if(seg >= get_segment_count()) {
		seg = get_segment_count() - 1;
		t = 1.0f;
	}

	Vector3 cp[2];
	ListNode<Vector3> *iter = const_cast<PolyLine*>(this)->control_points.begin();
	for(int i=0; i<seg; i++) {
		iter = iter->next;
	}

	cp[0] = iter->data;
	cp[1] = iter->next->data;

	return cp[0] + (cp[1] - cp[0]) * t;
}
Ejemplo n.º 2
0
GEdgeCompound::GEdgeCompound(GModel *m, int tag, std::vector<GEdge*> &compound,
                             std::vector<int> &orientation)
  : GEdge(m, tag, 0, 0), _compound(compound), _orientation(orientation)
{
  if(!looksOk(tag, compound)) return;

  int N = _compound.size();
  if(N == (int)_orientation.size()){
    v0 = _orientation[0] ? _compound[0]->getBeginVertex() : _compound[0]->getEndVertex();
    v1 = _orientation[N-1] ? _compound[N-1]->getEndVertex() : _compound[N-1]->getBeginVertex();
    v0->addEdge(this);
    v1->addEdge(this);
  }
  else{
    Msg::Error("Wrong input data for compound edge %d", tag);
    return;
  }

  for (unsigned int i = 0; i < _compound.size(); i++)
    _compound[i]->setCompound(this);

  for(std::vector<GEdge*>::iterator it = _compound.begin(); it != _compound.end(); ++it){
    if(!(*it)){
      Msg::Error("Incorrect edge in compound edge %d", tag);
      return;
    }
  }

  parametrize();
}
Ejemplo n.º 3
0
Vector3 BezierSpline::get_tangent(scalar_t t)
{	
	if (!get_segment_count()) return Vector3(0, 0, 0);

	if (arc_parametrize)
	{
		t = ease(parametrize(t));
	}
 
	t = (t * get_segment_count());
	int seg = (int) t;
	t -= (scalar_t) floor(t);
	if (seg >= get_segment_count())
	{
		seg = get_segment_count() - 1;
		t = 1.0f;
	}

	seg *= 4;
	ListNode<Vector3> *iter = const_cast<BezierSpline*>(this)->control_points.begin();
	for (int i = 0; i < seg; i++) iter = iter->next;
	
	Vector3 Cp[4];
	for (int i = 0; i < 4; i++)
	{
		Cp[i] = iter->data;
		iter = iter->next;
	}
	
	// interpolate
	return bezier_tangent(Cp[0], Cp[1], Cp[2], Cp[3], t);
}
Ejemplo n.º 4
0
Vector3 BSpline::interpolate(scalar_t t) const {
	if(t > 1.0) t = 1.0;
	if(t < 0.0) t = 0.0;

	if(control_points.size() < 4) return Vector3(0, 0, 0);

	if(arc_parametrize) {
		t = ease(parametrize(t));
	}

	// find the appropriate segment of the spline that t lies and calculate the piecewise parameter
	t = (scalar_t)(control_points.size() - 3) * t;
	int seg = (int)t;
	t -= (scalar_t)floor(t);
	if(seg >= get_segment_count()) {
		seg = get_segment_count() - 1;
		t = 1.0f;
	}
	
	ListNode<Vector3> *iter = const_cast<BSpline*>(this)->control_points.begin();
	for(int i=0; i<seg; i++) iter = iter->next;

	Vector3 Cp[4];
	for(int i=0; i<4; i++) {
        Cp[i] = iter->data;
		iter = iter->next;
	}

	Vector3 res;
	res.x = bspline(Cp[0].x, Cp[1].x, Cp[2].x, Cp[3].x, t);
	res.y = bspline(Cp[0].y, Cp[1].y, Cp[2].y, Cp[3].y, t);
	res.z = bspline(Cp[0].z, Cp[1].z, Cp[2].z, Cp[3].z, t);

	return res;
}
Ejemplo n.º 5
0
/* Given a parameter space "space", create a set of dimension "len"
 * of which the dimensions starting at "first" are equated to
 * freshly created parameters with identifiers "ids".
 */
__isl_give isl_set *parametrization(__isl_take isl_space *space,
                                    int len, int first, __isl_keep isl_id_list *ids)
{
    isl_set *set;

    space = isl_space_set_from_params(space);
    space = isl_space_add_dims(space, isl_dim_set, len);
    set = isl_set_universe(space);

    return parametrize(set, first, ids);
}
Ejemplo n.º 6
0
Vector3 CatmullRomSpline::interpolate(scalar_t t) const {
	if(t > 1.0) t = 1.0;
	if(t < 0.0) t = 0.0;

	if(control_points.size() < 2) return Vector3(0, 0, 0);

	if(arc_parametrize) {
		t = ease(parametrize(t));
	}

	// find the appropriate segment of the spline that t lies and calculate the piecewise parameter
	t = (scalar_t)(control_points.size() - 1) * t;
	int seg = (int)t;
	t -= (scalar_t)floor(t);
	if(seg >= get_segment_count()) {
		seg = get_segment_count() - 1;
		t = 1.0f;
	}

	Vector3 cp[4];
	ListNode<Vector3> *iter = const_cast<CatmullRomSpline*>(this)->control_points.begin();
	for(int i=0; i<seg; i++) {
		iter = iter->next;
	}

	cp[1] = iter->data;
	cp[2] = iter->next->data;
	
	if(!seg) {
		cp[0] = cp[1];
	} else {
		cp[0] = iter->prev->data;
	}
	
	if(seg == control_points.size() - 2) {
		cp[3] = cp[2];
	} else {
		cp[3] = iter->next->next->data;
	}

	Vector3 res;
	res.x = catmull_rom_spline(cp[0].x, cp[1].x, cp[2].x, cp[3].x, t);
	res.y = catmull_rom_spline(cp[0].y, cp[1].y, cp[2].y, cp[3].y, t);
	res.z = catmull_rom_spline(cp[0].z, cp[1].z, cp[2].z, cp[3].z, t);

	return res;
}
Ejemplo n.º 7
0
GEdgeCompound::GEdgeCompound(GModel *m, int tag, std::vector<GEdge*> &compound)
  : GEdge(m, tag, 0 , 0), _compound(compound)
{
  if(!looksOk(tag, compound)) return;

  orderEdges();
  int N = _compound.size();
  if(N == (int)_orientation.size()){
    v0 = _orientation[0] ? _compound[0]->getBeginVertex() : _compound[0]->getEndVertex();
    v1 = _orientation[N-1] ? _compound[N-1]->getEndVertex() : _compound[N-1]->getBeginVertex();
    v0->addEdge(this);
    v1->addEdge(this);
  }
  else{
    Msg::Error("Wrong input data for compound edge %d", tag);
    return;
  }

  for (unsigned int i = 0; i < _compound.size(); i++)
    _compound[i]->setCompound(this);
  parametrize();
}
Ejemplo n.º 8
0
/*
 *----------------------------------------------------------
 *      MainMenu
 *----------------------------------------------------------
 */
void mainMenu(int item)
{
	switch(item){
		case 0:
				/* HACK! Moves the camera back by globalScale amount */
				Prim[WORLD].trans[Z] *= Prim[WORLD].cosine.z;
				showLandMarks = FALSE;
				showPrimitives = FALSE;
				panSpeed *= 16.0;
				break;
		case 1:
				lightFlag = !lightFlag;
				break;
		case 2:
				windowSplitFlag = !windowSplitFlag;
				break;
		case 3:
				parametrize();
				break;
		case 4:
				textureFlag = !textureFlag;
				if ( textureFlag )
				{
						if ( !textCoordComputed )
						{
								compTextCoordinates();
						}
						glEnable(GL_TEXTURE_2D);
				}
				else
						glDisable(GL_TEXTURE_2D);
				break;
		case 5:
				computeVoronoi();
				optimizeVoronoiVertex();
				break;
		case 6:    /* added by Thompson 21/05/2002 */
				cellPicking = !cellPicking;
				if( cellPicking )
						glutSetCursor( GLUT_CURSOR_INFO );
				else
						glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
				break;
		case 7:{
				polygonPicking = !polygonPicking;
				if ( polygonPicking )
				{glutSetCursor( GLUT_CURSOR_INFO );}
				else {glutSetCursor( GLUT_CURSOR_LEFT_ARROW );}
		}
				break;
		case 8:
				drawCells = TRUE;
				createRandomCells( NumberCells, FALSE );
				break;
		case 9:
				duplicatePrimitive();
				break;
		case 10:
				growthFlag = !growthFlag;
				break;
		case 11:
				animFlag = !animFlag;
				break;
		case 12:
				exit(0);
		case 13:
				optimizeVoronoiPoligons2();
				break;
		default:
				break;
	}
	glutPostRedisplay();
}