Ejemplo n.º 1
0
void draw_streamlines() {
  
  glPushMatrix(); 

  glScalef(1/(float)len[0], 1/(float)len[0], 1/(float)len[0]); 
  glTranslatef(-len[0]/2.0, -len[1]/2.0, -len[2]/2.0); 

  std::list<vtListSeedTrace*>::iterator pIter; 

  for (int i=0; i<nproc; i++) {   // looping through all subdomains 
    pIter = sl_list[i].begin(); 
    for (; pIter!=sl_list[i].end(); pIter++) {
      vtListSeedTrace *trace = *pIter; 
      std::list<VECTOR3*>::iterator pnIter; 
      pnIter = trace->begin(); 
      glColor3f(0.3,0.3,0.3); 
      glBegin(GL_LINE_STRIP); 
      for (; pnIter!= trace->end(); pnIter++) {
	VECTOR3 p = **pnIter; 
	//printf(" %f %f %f ", p[0], p[1], p[2]); 
	glVertex3f(p[0], p[1], p[2]); 
      }
      glEnd(); 
    }
    volume_bounds_type vb = vb_list[i];     
    draw_bounds(vb.xmin, vb.xmax, vb.ymin, vb.ymax, vb.zmin, vb.zmax); 
  }
  glPopMatrix(); 
}
Ejemplo n.º 2
0
static void draw_bounds(const wtree<3>& t, std::array<std::array<float, 2>, 3> bounds, float depth)
{
	for(size_t i = 0; i < wtree<3>::node_count; i++)
		if(t.nodes[i].count > 0)
		{
			std::array<std::array<float, 2>, 3> tmp_bounds = bounds;
			wtree<3>& new_t = *t.nodes[i].wtree;
		
			for(size_t d = 0; d < wtree<3>::dimension; d++)
				if(new_t.element[d] >= t.element[d])
					tmp_bounds[d][0] = t.element[d];
				else
					tmp_bounds[d][1] = t.element[d];
		
			draw_bounds(new_t, tmp_bounds, depth*0.5);
		}
	
	glColor3f(0.9*depth, 0.9*depth, 0.9*depth);

	for(size_t i = 0; i < wtree<3>::dimension; i++)
	{
		std::array<std::array<float, 3>, 2> line;
		
		for(size_t j = 0; j < 2; j++)
			line[j] = t.element;
		
		for(size_t j = 0; j < 2; j++)
			line[j][i] = bounds[i][j];
		
		for(size_t j = 0; j < 2; j++)
			glVertex3f(line[j][0], line[j][1], line[j][2]);
	}
}
void Controller::output_status() const
{
    logger.stats(stats_);

    if( settings_.draw_bounds )
    {
        draw_bounds();
    }
}
Ejemplo n.º 4
0
void wtree3_viewer::draw()
{
	const wtree<3>& t = *tree_ptr;
	
	constexpr float dist = 2.0;
	float rad = in_range(i, 360, 0, 2.0 * M_PI);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0, 1.333, 1.0, 100.0); 
	gluLookAt(0.5+dist*std::cos(rad), 0.5, 0.5+dist*std::sin(rad), 0.5, 0.5, 0.5, 0.0, 1.0, 0.0);
	//glTranslatef(-0.5, -0.5, 0);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClear(GL_COLOR_BUFFER_BIT);
	
	glLineWidth(5.0);
	glBegin(GL_LINES);
	for(size_t i = 0; i < 3; i++)
	{
		glColor3f(i == 0, i == 1, i == 2);
		glVertex3f(0.0, 0.0, 0.0);
		glVertex3f(i == 0, i == 1, i == 2);
	}
	glEnd();
	
	glLineWidth(1.0);
	glBegin(GL_LINES);
	draw_bounds(t, {{{{0.0, 1.0}}, {{0.0, 1.0}}, {{0.0, 1.0}}}}, 1.0);
	glEnd();
	
	glPointSize(3.0);
	glBegin(GL_POINTS);
	draw_dots(t, 1.0);
	glEnd();

	glFlush();
	glutSwapBuffers();
	glutPostRedisplay();
	
	i++;
}
Ejemplo n.º 5
0
void draw_streamlines() {
  
  glPushMatrix(); 

  glScalef(1/(float)len[0], 1/(float)len[0], 1/(float)len[0]); 
  glTranslatef(-len[0]/2.0, -len[1]/2.0, -len[2]/2.0); 

  std::list<vtListSeedTrace*>::iterator pIter; 

  for (int proc = 0; proc<nproc; proc++)  {

    list<vtListSeedTrace*> *list = sl_list[proc]; 
    int np = num_partitions[proc]; 

    for (int i=0; i<np; i++) {   // looping through all subdomains 
      pIter = list[i].begin(); 
      for (; pIter!=list[i].end(); pIter++) {
	vtListSeedTrace *trace = *pIter; 
	std::list<VECTOR3*>::iterator pnIter; 
	pnIter = trace->begin(); 
	glColor3f(0.3,0.3,0.3); 
	glBegin(GL_LINE_STRIP); 
	for (; pnIter!= trace->end(); pnIter++) {
	  VECTOR3 p = **pnIter; 
	  glVertex3f(p[0], p[1], p[2]); 
	}
	glEnd(); 
      }
      int p = plist[proc][i]; 
      volume_bounds_type vb = vb_list[p];     
      glColor3f(1,1,0); 
      draw_bounds(vb.xmin, vb.xmax, vb.ymin, vb.ymax, vb.zmin, vb.zmax); 
    }
  }
  glPopMatrix(); 
}
Ejemplo n.º 6
0
/*!
* Main display function; called whenever the scene needs to be redrawn.
*/
static void
display(void)
{
  Lib3dsNode *c,*t;
  Lib3dsFloat fov, roll;
  float near, far, dist;
  float *campos;
  float *tgt;
  Lib3dsMatrix M;
  Lib3dsCamera *cam;
  Lib3dsVector v;
  Lib3dsNode *p;

  if( file != NULL && file->background.solid.use )
    glClearColor(file->background.solid.col[0],
    file->background.solid.col[1],
    file->background.solid.col[2], 1.);

  /* TODO: fog */

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  if( anti_alias )
    glEnable(GL_POLYGON_SMOOTH);
  else
    glDisable(GL_POLYGON_SMOOTH);


  if (!file) {
    return;
  }

  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, file->ambient);

  c=lib3ds_file_node_by_name(file, camera, LIB3DS_CAMERA_NODE);
  t=lib3ds_file_node_by_name(file, camera, LIB3DS_TARGET_NODE);

  if( t != NULL )
    tgt = t->data.target.pos;

  if( c != NULL ) {
    fov = c->data.camera.fov;
    roll = c->data.camera.roll;
    campos = c->data.camera.pos;
  }

  if ((cam = lib3ds_file_camera_by_name(file, camera)) == NULL)
    return;

  near = cam->near_range;
  far = cam->far_range;

  if (c == NULL || t == NULL) {
    if( c == NULL ) {
      fov = cam->fov;
      roll = cam->roll;
      campos = cam->position;
    }
    if( t == NULL )
      tgt = cam->target;
  }

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  /* KLUDGE alert:  OpenGL can't handle a near clip plane of zero,
  * so if the camera's near plane is zero, we give it a small number.
  * In addition, many .3ds files I've seen have a far plane that's
  * much too close and the model gets clipped away.  I haven't found
  * a way to tell OpenGL not to clip the far plane, so we move it
  * further away.  A factor of 10 seems to make all the models I've
  * seen visible.
  */
  if( near <= 0. ) near = far * .001;

  gluPerspective( fov, 1.0*gl_width/gl_height, near, far);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glRotatef(-90, 1.0,0,0);

  /* User rotates the view about the target point */

  lib3ds_vector_sub(v, tgt, campos);
  dist = lib3ds_vector_length(v);

  glTranslatef(0.,dist, 0.);
  glRotatef(view_rotx, 1., 0., 0.);
  glRotatef(view_roty, 0., 1., 0.);
  glRotatef(view_rotz, 0., 0., 1.);
  glTranslatef(0.,-dist, 0.);

  lib3ds_matrix_camera(M, campos, tgt, roll);
  glMultMatrixf(&M[0][0]);

  /* Lights.  Set them from light nodes if possible.  If not, use the
  * light objects directly.
  */
  {
    static const GLfloat a[] = {0.0f, 0.0f, 0.0f, 1.0f};
    static GLfloat c[] = {1.0f, 1.0f, 1.0f, 1.0f};
    static GLfloat p[] = {0.0f, 0.0f, 0.0f, 1.0f};
    Lib3dsLight *l;

    int li=GL_LIGHT0;
    for (l=file->lights; l; l=l->next) {
      glEnable(li);

      light_update(l);

      c[0] = l->color[0];
      c[1] = l->color[1];
      c[2] = l->color[2];
      glLightfv(li, GL_AMBIENT, a);
      glLightfv(li, GL_DIFFUSE, c);
      glLightfv(li, GL_SPECULAR, c);

      p[0] = l->position[0];
      p[1] = l->position[1];
      p[2] = l->position[2];
      glLightfv(li, GL_POSITION, p);

      if (l->spot_light) {
        p[0] = l->spot[0] - l->position[0];
        p[1] = l->spot[1] - l->position[1];
        p[2] = l->spot[2] - l->position[2];
        glLightfv(li, GL_SPOT_DIRECTION, p);
      }
      ++li;
    }
  }




  if( show_object )
  {
    for (p=file->nodes; p!=0; p=p->next) {
      render_node(p);
    }
  }

  if( show_bounds )
    draw_bounds(tgt);

  if( show_cameras )
  {
    for( cam = file->cameras; cam != NULL; cam = cam->next )
    {
      lib3ds_matrix_camera(M, cam->position, cam->target, cam->roll);
      lib3ds_matrix_inv(M);

      glPushMatrix();
      glMultMatrixf(&M[0][0]);
      glScalef(size/20, size/20, size/20);
      glCallList(cameraList);
      glPopMatrix();
    }
  }

  if( show_lights )
  {
    Lib3dsLight *light;
    for( light = file->lights; light != NULL; light = light->next )
      draw_light(light->position, light->color);
    glMaterialfv(GL_FRONT, GL_EMISSION, black);
  }


  glutSwapBuffers();
}