Skip to content

Commit

Permalink
fixed curve-skeleton structures to comply with the other updates of c…
Browse files Browse the repository at this point in the history
…inolib
  • Loading branch information
mlivesu committed Sep 11, 2024
1 parent 3080c4f commit 8174c95
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 45 deletions.
32 changes: 16 additions & 16 deletions include/cinolib/meshes/drawable_skel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void DrawableSkel::draw(const float scene_size) const
{
vec3d v = vertex(vid);
glDisable(GL_DEPTH_TEST);
sphere<vec3d>(v, max_sphere_radius(vid), std_bone_color);
draw_sphere(v, max_sphere_radius(vid), std_bone_color);
glEnable(GL_DEPTH_TEST);
}
}
Expand All @@ -119,11 +119,11 @@ void DrawableSkel::draw(const float scene_size) const
glDisable(GL_DEPTH_TEST);
if (draw_mode & DRAW_STD_COLOR)
{
sphere<vec3d>(v, bone_thickness, std_bone_color);
draw_sphere(v, bone_thickness, std_bone_color);
}
else if (draw_mode & DRAW_BONE_COLOR)
{
sphere<vec3d>(v, bone_thickness, vertex_color(vid));
draw_sphere(v, bone_thickness, vertex_color(vid));
}
glEnable(GL_DEPTH_TEST);
}
Expand All @@ -139,11 +139,11 @@ void DrawableSkel::draw(const float scene_size) const
glDisable(GL_DEPTH_TEST);
if (draw_mode & DRAW_STD_COLOR)
{
cylinder<vec3d>(v0, v1, bone_thickness, bone_thickness, std_bone_color);
draw_cylinder(v0, v1, bone_thickness, bone_thickness, std_bone_color);
}
else if (draw_mode & DRAW_BONE_COLOR)
{
cylinder<vec3d>(v0, v1, bone_thickness, bone_thickness, segment_color(sid));
draw_cylinder(v0, v1, bone_thickness, bone_thickness, segment_color(sid));
}
glEnable(GL_DEPTH_TEST);
}
Expand All @@ -158,11 +158,11 @@ void DrawableSkel::draw(const float scene_size) const
glDisable(GL_DEPTH_TEST);
if (draw_mode & DRAW_STD_COLOR)
{
sphere<vec3d>(v, sphere_radius, std_bone_color);
draw_sphere(v, sphere_radius, std_bone_color);
}
else if (draw_mode & DRAW_BONE_COLOR)
{
sphere<vec3d>(v, sphere_radius, vertex_color(vid));
draw_sphere(v, sphere_radius, vertex_color(vid));
}
glEnable(GL_DEPTH_TEST);
}
Expand All @@ -175,7 +175,7 @@ void DrawableSkel::draw(const float scene_size) const
if (vertex_is_bone(vid)) continue;
vec3d v = vertex(vid);
glDisable(GL_DEPTH_TEST);
sphere<vec3d>(v, sphere_radius, (vertex_is_leaf(vid) ? std_leaf_color : std_joint_color));
draw_sphere(v, sphere_radius, (vertex_is_leaf(vid) ? std_leaf_color : std_joint_color));
glEnable(GL_DEPTH_TEST);
}
}
Expand Down Expand Up @@ -249,17 +249,17 @@ void DrawableSkel::set_std_leaf_color(float r, float g, float b)
CINO_INLINE
void DrawableSkel::set_std_bone_color(float r, float g, float b)
{
std_bone_color[0] = r;
std_bone_color[1] = g;
std_bone_color[2] = b;
std_bone_color.r = r;
std_bone_color.g = g;
std_bone_color.b = b;
}

CINO_INLINE
void DrawableSkel::set_std_joint_color(float r, float g, float b)
{
std_joint_color[0] = r;
std_joint_color[1] = g;
std_joint_color[2] = b;
std_joint_color.r = r;
std_joint_color.g = g;
std_joint_color.b = b;
}

CINO_INLINE
Expand All @@ -269,7 +269,7 @@ void DrawableSkel::update_bone_colors()
for(int sid=0; sid<num_segments(); ++sid)
{
Color c = Color::scatter(num_bones(), segment_bone_id(sid));
set_segment_color(sid, c.rgba);
set_segment_color(sid, c);
}

v_colors.resize(num_vertices()*3);
Expand All @@ -278,7 +278,7 @@ void DrawableSkel::update_bone_colors()
if (vertex_is_feature(vid)) continue;

Color c = Color::scatter(num_bones(), segment_bone_id(vid));
set_vertex_color(vid, c.rgba);
set_vertex_color(vid, c);
}
}

Expand Down
38 changes: 14 additions & 24 deletions include/cinolib/meshes/drawable_skel.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,23 @@ class DrawableSkel : public Skel, public DrawableObject

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

inline const float * vertex_color (int vid) const { return &(v_colors[vid*3]); }
inline const float * segment_color(int sid) const { return &(s_colors[sid*3]); }
inline void bone_color(int bid, float * rgb) const
inline const Color & vertex_color (int vid) const { return v_colors.at(vid); }
inline const Color & segment_color(int sid) const { return s_colors.at(sid); }

inline void bone_color(int bid, Color & rgb) const
{
int first_segment = segment_bone(bid).front();
const float * c = segment_color(first_segment);
rgb[0] = c[0];
rgb[1] = c[1];
rgb[2] = c[2];
rgb = segment_color(first_segment);
}

inline void set_vertex_color(int vid, float * color)
inline void set_vertex_color(int vid, Color & color)
{
int vid_ptr = vid * 3;
CHECK_BOUNDS(v_colors, vid_ptr+2);
v_colors[vid_ptr + 0] = color[0];
v_colors[vid_ptr + 1] = color[1];
v_colors[vid_ptr + 2] = color[2];
v_colors[vid] = color;
}

inline void set_segment_color(int sid, float * color)
inline void set_segment_color(int sid, Color & color)
{
int sid_ptr = sid * 3;
CHECK_BOUNDS(s_colors, sid_ptr+2);
s_colors[sid_ptr + 0] = color[0];
s_colors[sid_ptr + 1] = color[1];
s_colors[sid_ptr + 2] = color[2];
s_colors[sid] = color;
}

inline void set_bone_thickness(float scalar)
Expand All @@ -153,12 +143,12 @@ class DrawableSkel : public Skel, public DrawableObject
float bone_thickness_modifier; // useful for rendering
float sphere_radius_modifier; // useful for rendering

float std_bone_color[3];
float std_leaf_color[3];
float std_joint_color[3];
Color std_bone_color;
Color std_leaf_color;
Color std_joint_color;

std::vector<float> s_colors;
std::vector<float> v_colors;
std::vector<Color> s_colors;
std::vector<Color> v_colors;
};

}
Expand Down
2 changes: 1 addition & 1 deletion include/cinolib/meshes/skel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void Skel::update_bbox()
bb.reset();
for(int vid=0; vid<num_vertices(); ++vid)
{
vec3<double> v = vertex(vid);
vec3d v = vertex(vid);
bb.min = bb.min.min(v);
bb.max = bb.max.max(v);
}
Expand Down
8 changes: 4 additions & 4 deletions include/cinolib/meshes/skel.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Skel
return length;
}

inline void set_vertex(int vid, const vec3<double> & v)
inline void set_vertex(int vid, const vec3d & v)
{
int vid_ptr = vid * 3;
CHECK_BOUNDS(coords, vid_ptr+2);
Expand All @@ -209,11 +209,11 @@ class Skel
coords[vid_ptr + 2] = v.z();
}

inline vec3<double> vertex(int vid) const
inline vec3d vertex(int vid) const
{
int vid_ptr = vid * 3;
CHECK_BOUNDS(coords, vid_ptr);
return vec3<double>(coords[vid_ptr+0], coords[vid_ptr+1], coords[vid_ptr+2]);
return vec3d(coords[vid_ptr+0], coords[vid_ptr+1], coords[vid_ptr+2]);
}

inline seg segment(int sid) const
Expand All @@ -230,7 +230,7 @@ class Skel
segments[sid_ptr + i] = vid;
}

inline vec3<double> segment_vertex(int sid, int i) const
inline vec3d segment_vertex(int sid, int i) const
{
return vertex(segment_vertex_id(sid,i));
}
Expand Down

0 comments on commit 8174c95

Please sign in to comment.