Exemple #1
0
void TensorGlRep::render(const shared_ptr<Node>& node, const GLViewInfo* viewInfo){

	const int circDiv=20;
	static gleDouble circ[circDiv+2][3]={};

	if(circ[0][0]==0){
		gleSetNumSides(10);
		Real step=2*M_PI/circDiv;
		for(int i=-1; i<circDiv+1; i++){
			circ[i+1][0]=cos(i*step);
			circ[i+1][1]=sin(i*step);
			circ[i+1][2]=0;
		}
	}

	if(range && !skewRange) skewRange=range;

	Vector3r pos=node->pos+(node->hasData<GlData>()?node->getData<GlData>().dGlPos:Vector3r::Zero());

	for(int i:{0,1,2}){
		Vector3r color=(range?range->color(eigVal[i]):CompUtils::scalarOnColorScale(eigVal[i],-1,1));
		if(isnan(color.maxCoeff())) continue;
		Real mxNorm=(range?range->maxAbs(eigVal[i]):1);
		Real len=relSz*viewInfo->sceneRadius;
		len*=isnan(scaleExp)?abs(eigVal[i]/mxNorm):pow(abs(eigVal[i])/mxNorm,scaleExp);
		glColor3v(color);
		Vector3r dx(len*eigVec.col(i));
		// arrows which go towards each other for negative eigenvalues, and away from each other for positive ones
		GLUtils::GLDrawArrow(pos+(eigVal[i]>0?Vector3r::Zero():dx),pos+(eigVal[i]>0?dx:Vector3r::Zero()),color);
		GLUtils::GLDrawArrow(pos-(eigVal[i]>0?Vector3r::Zero():dx),pos-(eigVal[i]>0?dx:Vector3r::Zero()),color);

		// draw circular arrow to show skew components, in the half-height
		// compute it in the xy plane, transform coords instead
		Real maxSkew=(skewRange?skewRange->maxAbs(skew[i]):1);
		// if(abs(skew[i])<.05*maxSkew) continue;

		int nPts=int((abs(skew[i])/maxSkew)*circDiv*.5/* show max skew as .5*2π rad */-.5/*round evenly, but exclude one segment for arrow head*/);
		if(nPts>circDiv-2) nPts=circDiv-2;
		if(nPts<=0) continue;
		Real torRad1=(skewRelSz>0?skewRelSz:relSz)*viewInfo->sceneRadius*(abs(skew[i])/maxSkew);
		Real torDist=0*.3*torRad1; // draw both arcs in-plane
		Real torRad2=torRad1*.1;
		glColor3v(skewRange?skewRange->color(skew[i]):CompUtils::scalarOnColorScale(skew[i],-1,1));
		for(int j:{0,1,2}){
			glPushMatrix();
				Eigen::Affine3d T=Eigen::Affine3d::Identity();
				T.translate(pos+(j==0?1:-1)*eigVec.col(i)*torDist).rotate(Quaternionr().setFromTwoVectors(Vector3r::UnitZ(),eigVec.col(i)*(skew[i]>0?-1:1))).scale(torRad1);
				if(j==1) T.rotate(AngleAxisr(M_PI,Vector3r::UnitZ()));
				//GLUtils::setLocalCoords(pos+(j==0?1:-1)*eigVec.col(i)*torDist,
				glMultMatrixd(T.data());
				// since we scaled coords to transform unit circle coords to our radius, we will need to scale dimensions now by 1/torRad1
				glePolyCylinder(nPts+2,circ,/* use current color*/NULL,torRad2*(1/torRad1));
				gleDouble headRad[]={2*torRad2*(1/torRad1),2*torRad2*(1/torRad1),0,0,0};
				glePolyCone(4,(gleDouble(*)[3])&(circ[nPts-1]),/*use current color*/NULL,headRad);
			glPopMatrix();
		}
	}
}
void GLThread::DrawDownvecAtInd(int ind)
{
	glDisable(GL_TEXTURE_2D);
	glPushMatrix();
	glColor3d(0.8, 0.1, 0.0);


	const double radius = 0.20;
	const double radius_cone_max = 0.45;

  Vector3d diff_pos = _thread->vertex_at_ind(ind)-display_start_pos;
  double length_factor = 8.0;
	double cone_scale_factor = 0.07;
  Vector3d down_vec = -Vector3d::UnitZ()*length_factor;
	double pts[4][3];
	double pts_cone[4][3];

	double radius_cone[4];
	radius_cone[0] = radius_cone_max*2;
	radius_cone[1] = radius_cone_max;
	radius_cone[2] = 1e-3;
	radius_cone[3] = 0;


	for (int i=0; i < 3; i++)
	{
		pts[0][i] = diff_pos(i)-down_vec(i);
		pts[1][i] = diff_pos(i);

		pts[2][i] = diff_pos(i) + down_vec(i);
		pts[3][i] = diff_pos(i) + 2*down_vec(i);

		pts_cone[0][i] = diff_pos(i) + down_vec(i)*(1.0-cone_scale_factor);
		pts_cone[1][i] = diff_pos(i) + down_vec(i);
		pts_cone[2][i] = diff_pos(i) + down_vec(i)*(1.0+cone_scale_factor);
		pts_cone[3][i] = diff_pos(i) + down_vec(i)*(1.0+cone_scale_factor*2);

	}

	glePolyCylinder(4, pts, 0x0,radius);
	glePolyCone(4, pts_cone, 0x0, radius_cone);

	glPopMatrix();
	glEnable(GL_TEXTURE_2D);
}
Exemple #3
0
/* draw the polycone shape */
void DrawStuff (void) {

   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   /* set up some matrices so that the object spins with the mouse */
   glPushMatrix ();
   glTranslatef (0.0, 0.0, -80.0);
   glRotatef (lastx, 0.0, 1.0, 0.0);
   glRotatef (lasty, 1.0, 0.0, 0.0);
   glColor3f (0.5, 0.5, 0.2);

   /* Phew. FINALLY, Draw the polycone  -- */
   glePolyCone (idx, points, 0x0, radii);

   glPopMatrix ();

   glutSwapBuffers ();
}
/* draw the helix shape */
void DrawStuff (void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glColor3f (0.8, 0.3, 0.6);

	glPushMatrix ();

	/* set up some matrices so that the object spins with the mouse */
	glTranslatef (0.0,0.0,-300.0);
  glRotatef (rotate_frame[1], 1.0, 0.0, 0.0);
  glRotatef (rotate_frame[0], 0.0, 0.0, 1.0);


  //change thread, if necessary
  if (traj_mode == PLAYBACK)// && trajectory_play_back_ind < trajectory.size())
  {
    /*
    Thread_Motion nextMotion;
    traj_reader.get_next_motion(nextMotion);
    positions[1] += nextMotion.pos_movement;
    tangents[1] = nextMotion.tan_rotation*tangents[1];

    //change thread
    thread->setConstraints(positions, tangents);
    //thread->upsampleAndOptimize_minLength(0.065);

    thread->minimize_energy_fixedPieces();
    */
  }
   else if (move_end[0] != 0.0 || move_end[1] != 0.0 || tangent_end[0] != 0.0 || tangent_end[1] != 0.0)
  {
    GLdouble model_view[16];
    glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

    GLdouble projection[16];
    glGetDoublev(GL_PROJECTION_MATRIX, projection);

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);


    double winX, winY, winZ;

    //change end positions
    Vector3d new_end_pos;
    gluProject(positions[1](0), positions[1](1), positions[1](2), model_view, projection, viewport, &winX, &winY, &winZ);
    winX += move_end[0];
    winY += move_end[1];
    move_end[0] = 0.0;
    move_end[1] = 0.0;
    gluUnProject(winX, winY, winZ, model_view, projection, viewport, &new_end_pos(0), &new_end_pos(1), &new_end_pos(2));
//    std::cout << "X: " << positions[1](0) << " Y: " << positions[1](1) << " Z: " << positions[1](2) << std::endl;

    //change tangents
    Vector3d new_end_tan;
    gluProject(tangents[1](0), tangents[1](1), tangents[1](2), model_view, projection, viewport, &winX, &winY, &winZ);
    winX += tangent_end[0];
    winY += tangent_end[1];
    tangent_end[0] = 0.0;
    tangent_end[1] = 0.0;
    gluUnProject(winX, winY, winZ, model_view, projection, viewport, &new_end_tan(0), &new_end_tan(1), &new_end_tan(2));
    new_end_tan.normalize();




    if (traj_mode == RECORD)
    {
      traj_recorder.add_motion_to_list(positions[1], new_end_pos, tangents[1], new_end_tan);
    }

    positions[1] = new_end_pos;
    tangents[1] = new_end_tan;


    //change thread
    thread->setConstraints(positions, tangents);
    //thread->upsampleAndOptimize_minLength(0.065);

    thread->minimize_energy_fixedPieces();



    //std::cout << "objX: " <<objX << " objY: " << objY << " objZ: " << objZ << " winX: " << winX << " winY: " << winY << " winZ: " << winZ << std::endl;



  }


  //Draw Axes
	glBegin(GL_LINES);
	glEnable(GL_LINE_SMOOTH);
	glColor3d(1.0, 0.0, 0.0); //red
	glVertex3f(0.0f, 0.0f, 0.0f); //x
	glVertex3f(20.0f, 0.0f, 0.0f);
	glColor3d(0.0, 1.0, 0.0); //green
	glVertex3f(0.0f, 0.0f, 0.0f); //y
	glVertex3f(0.0f, 20.0f, 0.0f);
	glColor3d(0.0, 0.0, 1.0); //blue
	glVertex3f(0.0f, 0.0f, 0.0f); //z
	glVertex3f(0.0f, 0.0f, 20.0f);

	glColor3d(0.5, 0.5, 1.0);
	glVertex3f(positions[1](0)-positions[0](0), positions[1](1)-positions[0](1), positions[1](2)-positions[0](2)); //z
	glVertex3f(positions[1](0)-positions[0](0)+tangents[1](0)*4.0, positions[1](1)-positions[0](1)+tangents[1](1)*4.0, positions[1](2)-positions[0](2)+tangents[1](2)*4.0); //z


	glEnd( );



  //label axes
  void * font = GLUT_BITMAP_HELVETICA_18;
  glColor3d(1.0, 0.0, 0.0); //red
  glRasterPos3i(20.0, 0.0, -1.0);
  glutBitmapCharacter(font, 'X');
  glColor3d(0.0, 1.0, 0.0); //red
  glRasterPos3i(0.0, 20.0, -1.0);
  glutBitmapCharacter(font, 'Y');
  glColor3d(0.0, 0.0, 1.0); //red
  glRasterPos3i(-1.0, 0.0, 20.0);
  glutBitmapCharacter(font, 'Z');




  //Draw Thread
  glColor3f (0.5, 0.5, 0.2);

	thread->getPoints(points);
	double pts_cpy[NUM_PTS][3];

	for (int i=0; i < NUM_PTS; i++)
	{
		pts_cpy[i][0] = points(i,0)-(double)positions[0](0);
		pts_cpy[i][1] = points(i,1)-(double)positions[0](1);
		pts_cpy[i][2] = points(i,2)-(double)positions[0](2);
	}
	glePolyCone (NUM_PTS, pts_cpy, 0x0, radii);





	glPopMatrix ();

	glutSwapBuffers ();
}
void GLThread::DrawAxesAtPoint(const Vector3d& pt, const Matrix3d& rot_in, ColorCode color_axis, bool skipX)
{
	glDisable(GL_TEXTURE_2D);
	glPushMatrix();
	//Matrix3d rot = Eigen::AngleAxisd(M_PI/2.0, Vector3d::UnitX())*rot_in;
	
	Matrix3d rot = Eigen::AngleAxisd(M_PI/2.0, rot_in.col(0))*rot_in;


	const double radius = 0.15;
	const double radius_cone_max = 0.4;


  Vector3d diff_pos = pt-display_start_pos;
  double rotation_scale_factor = 6.0;
	double cone_scale_factor = 0.07;
  Matrix3d rotations_project = rot*rotation_scale_factor;
	double pts[4][3];
	double pts_cone[4][3];

	double radius_cone[4];
	radius_cone[0] = radius_cone_max*2;
	radius_cone[1] = radius_cone_max;
	radius_cone[2] = 1e-3;
	radius_cone[3] = 0;

	


	for (int i=0; i < 3; i++)
	{
		pts[0][i] = diff_pos(i)-rotations_project(i,0);
		pts[1][i] = diff_pos(i);
	}


	for (int coord=0; coord < 3; coord++)
	{
		if (coord == 0 && skipX)
			continue;
		for (int i=0; i < 3; i++)
		{
			pts[2][i] = diff_pos(i) + rotations_project(i,coord);
			pts[3][i] = diff_pos(i) + 2*rotations_project(i,coord);

			pts_cone[0][i] = diff_pos(i) + rotations_project(i,coord)*(1.0-cone_scale_factor);
			pts_cone[1][i] = diff_pos(i) + rotations_project(i,coord);
			pts_cone[2][i] = diff_pos(i) + rotations_project(i,coord)*(1.0+cone_scale_factor);
			pts_cone[3][i] = diff_pos(i) + rotations_project(i,coord)*(1.0+cone_scale_factor*2);

		}

		float thread_color_array[4][3];
		float stripe_color_array[4][3];
		for (int i=0; i < 4; i++)
		{
			for (int j=0; j < 3; j++)
			{
				thread_color_array[i][j] = thread_color_float[j];
				stripe_color_array[i][j] = stripe_color_float[j];
			}
		}

		const float alpha = 0.85;

			
	// gleTextureMode (GLE_TEXTURE_VERTEX_MODEL_CYL);
		if (color_axis == material)
		{
			if (coord == 0)
				glColor4f(0.7, 0.2, 0, alpha);
			else if (coord == 1)
				glColor4f((thread_color_float[0])*0.8, (thread_color_float[1])*0.8, (thread_color_float[2])*0.8, alpha);
			else
				glColor4f((stripe_color_float[0])*0.8, (stripe_color_float[1])*0.8, (stripe_color_float[2])*0.8, alpha);
		} else if (color_axis == bishop) {
			if (coord == 0)
				glColor4f(0.7, 0.2, 0, alpha);
			else if (coord == 1)
				glColor3d(0.5, 0.5, 0.5);
			else
				glColor3d(0.17, 0.17, 0.17);
		} else {
			if (coord == 0)
				glColor3d(1.0, 0.0, 0.0);
			else if (coord == 1)
				glColor3d(0.0, 1.0, 0.0);
			else
				glColor3d(0.0, 0.0, 1.0);
		}

		glePolyCylinder(4, pts, 0x0,radius);
		glePolyCone(4, pts_cone, 0x0, radius_cone);

	}
	glPopMatrix();
	glEnable(GL_TEXTURE_2D);
}