#include "temp_rts_glFilamentNetwork.h" void rts_glFilamentNetwork::RenderEdges() { //for each edge vector::iterator i; int a, b; point3D v_a, v_b; glBegin(GL_LINES); //start rendering lines for(i=m_edge_list.begin(); i!=m_edge_list.end(); i++) { v_a = (*i)->vertex_a->position; //get the positions of the two vertex edges v_b = (*i)->vertex_b->position; glVertex3f(v_a.x, v_a.y, v_a.z); //draw the vertices glVertex3f(v_b.x, v_b.y, v_b.z); } glEnd(); //finish drawing } void rts_glFilamentNetwork::RenderBranches() { //for each vertex vector::iterator i; point3D v; glBegin(GL_POINTS); for(i=m_vertex_list.begin(); i!=m_vertex_list.end(); i++) { if((*i)->v_neighbors.size() > 2) { v = (*i)->position; glVertex3f(v.x, v.y, v.z); } } glEnd(); } void rts_glFilamentNetwork::RenderFilaments() { vector::iterator i; int num_edges; point3D v_a, v_b; int e; glBegin(GL_LINES); for(i=m_filament_list.begin(); i!=m_filament_list.end(); i++) //for each filament { num_edges = (*i)->edges.size(); for(e=0; eedges[e]->vertex_a->position; v_b = (*i)->edges[e]->vertex_b->position; glVertex3f(v_a.x, v_a.y, v_a.z); glVertex3f(v_b.x, v_b.y, v_b.z); } } glEnd(); } void rts_glFilamentNetwork::RenderSelectedFilaments() { vector::iterator f; int num_edges; point3D v_a, v_b; int e; glBegin(GL_LINES); for(f=m_selected_list.begin(); f!=m_selected_list.end(); f++) { num_edges = m_filament_list[(*f)]->edges.size(); for(e=0; eedges[e]->vertex_a->position; v_b = m_filament_list[(*f)]->edges[e]->vertex_b->position; glVertex3f(v_a.x, v_a.y, v_a.z); glVertex3f(v_b.x, v_b.y, v_b.z); } } glEnd(); } void rts_glFilamentNetwork::RenderOrientationColor(double x, double y, double z, double r, double g, double b) { vector::iterator i; int num_edges; point3D v_a, v_b; //orientation variables vector3D orientation; double cos_a; vector3D A(x, y, z); A.Normalize(); int e; glBegin(GL_LINES); for(i=m_filament_list.begin(); i!=m_filament_list.end(); i++) //for each filament { //set the color of the filament based on orientation v_a = (*i)->vertex_a->position; v_b = (*i)->vertex_b->position; num_edges = (*i)->edges.size(); for(e=0; eedges[e]->vertex_a->position; v_b = (*i)->edges[e]->vertex_b->position; //determine color orientation = (v_a - v_b).Normalize(); cos_a = fabs(orientation*A); glColor3f(r*cos_a, g*cos_a, b*cos_a); glVertex3f(v_a.x, v_a.y, v_a.z); glVertex3f(v_b.x, v_b.y, v_b.z); } } glEnd(); } void rts_glFilamentNetwork::RenderEdgeDistanceColor(float r, float g, float b, float cutoff) { vector::iterator e; glBegin(GL_LINES); point3D p; double d; double exp = 3; for(e=m_edge_list.begin(); e!=m_edge_list.end(); e++) { d = (*e)->distance; if(d1.0) d=1.0; glColor3f(pow((1.0-d),exp)*r, pow((1.0-d),exp)*g, pow((1.0-d),exp)*b); p = (*e)->vertex_a->position; glVertex3f(p.x, p.y, p.z); p = (*e)->vertex_b->position; glVertex3f(p.x, p.y, p.z); } } glEnd(); } void rts_glFilamentNetwork::RenderFilamentDistanceColor(float r, float g, float b, float cutoff) { vector::iterator f; unsigned int e; unsigned int num_edges; double d; point3D v; double exp = 3.0; for(f = m_filament_list.begin(); f!=m_filament_list.end(); f++) { d = (*f)->distance; if(d1.0) d=1.0; if(d<0.0) d=0.0; //cout<<"d: "<edges.size(); glColor3f(pow((1.0-d), exp)*r, pow((1.0-d), exp)*g, pow((1.0-d), exp)*b); glBegin(GL_LINES); for(e=0; eedges[e]->vertex_a->position; glVertex3f(v.x, v.y, v.z); v = (*f)->edges[e]->vertex_b->position; glVertex3f(v.x, v.y, v.z); } glEnd(); } } } void rts_glFilamentNetwork::RenderRadiusColor(float min_r, float min_g, float min_b, float max_r, float max_g, float max_b, float min_radius, float max_radius) { /*Render each segment with a color based on the radius of the filament */ vector::iterator i; int e; int num_edges; point3D v; vector3D color_min(min_r, min_g, min_b); vector3D color_max(max_r, max_g, max_b); max_radius /= m_data_scale; min_radius /= m_data_scale; float diff = max_radius - min_radius; float p; //parameter value (position between min and max radii) vector3D color_p; for(i=m_filament_list.begin(); i!=m_filament_list.end(); i++) { glBegin(GL_LINES); num_edges = (*i)->edges.size(); for(e=0; eedges[e]->vertex_a->radius - min_radius)/diff; //cout<<"p: "<edges[e]->vertex_a->position; glVertex3f(v.x, v.y, v.z); //determine the second color p = ((*i)->edges[e]->vertex_b->radius - min_radius)/diff; color_p = (1.0 - p)*color_min + (p)*color_max; glColor3f(color_p.x, color_p.y, color_p.z); //determine the vertex position v = (*i)->edges[e]->vertex_b->position; glVertex3f(v.x, v.y, v.z); } glEnd(); } } void rts_glFilamentNetwork::RenderEdgeBoundingBoxes() { glMatrixMode(GL_MODELVIEW); //switch to the modelview matrix and store it vector::iterator e; point3D center; vector3D size; for(e=m_edge_list.begin(); e!=m_edge_list.end(); e++) { glPushMatrix(); size = (*e)->bounding_box.maximum - (*e)->bounding_box.minimum; center = (*e)->bounding_box.minimum + 0.5*(size); glTranslatef(center.x, center.y, center.z); glScalef(size.x, size.y, size.z); glutWireCube(1.0); glPopMatrix(); } } void rts_glFilamentNetwork::RenderFilamentBoundingBoxes() { glMatrixMode(GL_MODELVIEW); //switch to the modelview matrix and store it vector::iterator f; point3D center; vector3D size; for(f=m_filament_list.begin(); f!=m_filament_list.end(); f++) { glPushMatrix(); size = (*f)->bounding_box.maximum - (*f)->bounding_box.minimum; center = (*f)->bounding_box.minimum + 0.5*size; glTranslatef(center.x, center.y, center.z); glScalef(size.x, size.y, size.z); glutWireCube(1.0); glPopMatrix(); } } void rts_glFilamentNetwork::RenderCellSpheres() { glMatrixMode(GL_MODELVIEW); vector::iterator c; for(c=m_cell_list.begin(); c!=m_cell_list.end(); c++) { glPushMatrix(); glTranslatef((*c)->position.x, (*c)->position.y, (*c)->position.z); glutSolidSphere((*c)->radius, 10, 10); glPopMatrix(); } } void rts_glFilamentNetwork::RenderSelectedCells() { glMatrixMode(GL_MODELVIEW); vector::iterator f; vector::iterator c; for(f = m_selected_list.begin(); f!=m_selected_list.end(); f++) { for(c=m_filament_list[(*f)]->cells.begin(); c!=m_filament_list[(*f)]->cells.end(); c++) { glPushMatrix(); glTranslatef((*c)->position.x, (*c)->position.y, (*c)->position.z); glutSolidSphere((*c)->radius, 10, 10); glPopMatrix(); } } } void rts_glFilamentNetwork::p_ProcessPickHits(GLuint num_hits, GLuint* buffer, unsigned int start_filament, bool append, int max) { //cout<<"hits "< max) num_hits = max; unsigned int h, n; unsigned int num_names; unsigned int name; GLuint* ptr = buffer; //index into buffer array for(h=0; h v_a, v_b; int name = 0; unsigned int total_hits = 0; for(f=0; fedges.size(); for(e = 0; eedges[e]->vertex_a->position; v_b = m_filament_list[f]->edges[e]->vertex_b->position; glVertex3f(v_a.x, v_a.y, v_a.z); glVertex3f(v_b.x, v_b.y, v_b.z); } glEnd(); name++; //increment the name //We have to make sure that the name count doesn't exceed 64 if(name == 64) //if the name hits 64, check for and store hits, then reset the name { hits = glRenderMode(GL_RENDER); p_ProcessPickHits(hits, selection_buffer, f-63, append, max - total_hits); //process the hits (store selected fibers) total_hits += hits; if(total_hits >= max) //if we've reached the max, return { glPopMatrix(); return; } name = 0; //reset the selection queue glRenderMode(GL_SELECT); //change to selection mode glInitNames(); //start naming objects glPushName(0); //insert the first name } } glFlush(); //finish rendering hits = glRenderMode(GL_RENDER); //switch back to normal mode, get the number of hits p_ProcessPickHits(hits, selection_buffer, f/64, append, max - total_hits); //get any left-over hits total_hits += hits; glPopMatrix(); }