Commit 77cfce27 authored by Mike Kremer's avatar Mike Kremer

Edge colors are now supported as standard property.

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@260 fdac6126-5c0c-442c-9429-916003d36597
parent 658c8ec1
......@@ -94,17 +94,18 @@ public:
/// Definitions of %Options for reading and writing. The options can be
/// or'ed.
enum Flag {
Default = 0x0000, ///< No options
Binary = 0x0001, ///< Set binary mode for r/w
MSB = 0x0002, ///< Assume big endian byte ordering
LSB = 0x0004, ///< Assume little endian byte ordering
Swap = 0x0006, ///< Swap byte order in binary mode
VertexNormal = 0x0010, ///< Has (r) / store (w) vertex normals
VertexColor = 0x0020, ///< Has (r) / store (w) vertex colors
VertexTexCoord = 0x0040, ///< Has (r) / store (w) texture coordinates
FaceNormal = 0x0100, ///< Has (r) / store (w) face normals
FaceColor = 0x0200, ///< Has (r) / store (w) face colors
ColorAlpha = 0x0400 ///< Has (r) / store (w) alpha values for colors
Default = 0x00000, ///< No options
Binary = 0x00001, ///< Set binary mode for r/w
MSB = 0x00002, ///< Assume big endian byte ordering
LSB = 0x00004, ///< Assume little endian byte ordering
Swap = 0x00006, ///< Swap byte order in binary mode
VertexNormal = 0x00010, ///< Has (r) / store (w) vertex normals
VertexColor = 0x00020, ///< Has (r) / store (w) vertex colors
VertexTexCoord = 0x00040, ///< Has (r) / store (w) texture coordinates
EdgeColor = 0x00100, ///< Has (r) / store (w) texture coordinates
FaceNormal = 0x01000, ///< Has (r) / store (w) face normals
FaceColor = 0x02000, ///< Has (r) / store (w) face colors
ColorAlpha = 0x04000 ///< Has (r) / store (w) alpha values for colors
};
public:
......@@ -195,6 +196,7 @@ public:
bool vertex_has_normal() const { return check(VertexNormal); }
bool vertex_has_color() const { return check(VertexColor); }
bool vertex_has_texcoord() const { return check(VertexTexCoord); }
bool edge_has_color() const { return check(EdgeColor); }
bool face_has_normal() const { return check(FaceNormal); }
bool face_has_color() const { return check(FaceColor); }
bool color_has_alpha() const { return check(ColorAlpha); }
......
......@@ -101,6 +101,10 @@ public:
virtual Vec3f normal(FaceHandle _fh) const = 0;
virtual Vec3uc color (FaceHandle _fh) const = 0;
virtual Vec4uc colorA(FaceHandle _fh) const = 0;
// get edge data
virtual Vec3uc color(EdgeHandle _eh) const = 0;
virtual Vec4uc colorA(EdgeHandle _eh) const = 0;
// get reference to base kernel
virtual const BaseKernel* kernel() { return 0; }
......@@ -116,7 +120,8 @@ public:
virtual bool is_triangle_mesh() const { return false; }
virtual bool has_vertex_normals() const { return false; }
virtual bool has_vertex_colors() const { return false; }
virtual bool has_vertex_texcoords() const { return false; }
virtual bool has_vertex_texcoords() const { return false; }
virtual bool has_edge_colors() const { return false; }
virtual bool has_face_normals() const { return false; }
virtual bool has_face_colors() const { return false; }
};
......
......@@ -128,6 +128,22 @@ public:
: Vec2f(0.0f, 0.0f));
#endif
}
// get edge data
Vec3uc color(EdgeHandle _eh) const
{
return (mesh_.has_edge_colors()
? color_cast<Vec3uc>(mesh_.color(_eh))
: Vec3uc(0, 0, 0));
}
Vec4uc colorA(EdgeHandle _eh) const
{
return (mesh_.has_edge_colors()
? color_cast<Vec4uc>(mesh_.color(_eh))
: Vec4uc(0, 0, 0, 0));
}
// get face data
......@@ -182,6 +198,7 @@ public:
bool has_vertex_normals() const { return mesh_.has_vertex_normals(); }
bool has_vertex_colors() const { return mesh_.has_vertex_colors(); }
bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); }
bool has_edge_colors() const { return mesh_.has_edge_colors(); }
bool has_face_normals() const { return mesh_.has_face_normals(); }
bool has_face_colors() const { return mesh_.has_face_colors(); }
......
......@@ -114,6 +114,12 @@ public:
// set vertex texture coordinate
virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord) = 0;
// set edge color
virtual void set_color(EdgeHandle _eh, const Vec3uc& _color) = 0;
// set edge color
virtual void set_color(EdgeHandle _eh, const Vec4uc& _color) = 0;
// set face normal
virtual void set_normal(FaceHandle _fh, const Vec3f& _normal) = 0;
......
......@@ -169,6 +169,19 @@ public:
mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
}
// edge attributes
virtual void set_color(EdgeHandle _eh, const Vec4uc& _color)
{
if (mesh_.has_edge_colors())
mesh_.set_color(_eh, color_cast<Color>(_color));
}
virtual void set_color(EdgeHandle _eh, const Vec3uc& _color)
{
if (mesh_.has_edge_colors())
mesh_.set_color(_eh, color_cast<Color>(_color));
}
// face attributes
......
......@@ -119,6 +119,7 @@ public:
refcount_htexcoords1D_(0),
refcount_htexcoords2D_(0),
refcount_htexcoords3D_(0),
refcount_ecolors_(0),
refcount_fnormals_(0),
refcount_fcolors_(0),
refcount_ftextureIndex_(0)
......@@ -157,6 +158,9 @@ public:
if (EAttribs & Attributes::Status)
Connectivity::request_edge_status();
if (EAttribs & Attributes::Color)
request_edge_colors();
if (FAttribs & Attributes::Normal)
request_face_normals();
......@@ -378,6 +382,17 @@ public:
void set_texcoord3D(HalfedgeHandle _heh, const TexCoord3D& _t) {
property(halfedge_texcoords3D_, _heh) = _t;
}
//------------------------------------------------------------- edge colors
const Color* edge_colors() const
{ return property(edge_colors_).data(); }
const Color& color(EdgeHandle _eh) const
{ return property(edge_colors_, _eh); }
void set_color(EdgeHandle _eh, const Color& _c)
{ property(edge_colors_, _eh) = _c; }
//-------------------------------------------------------------- face normals
......@@ -452,6 +467,12 @@ public:
if (!refcount_htexcoords3D_++)
add_property( halfedge_texcoords3D_, "h:texcoords3D" );
}
void request_edge_colors()
{
if (!refcount_ecolors_++)
add_property( edge_colors_, "e:colors" );
}
void request_face_normals()
{
......@@ -514,6 +535,12 @@ public:
if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
remove_property(halfedge_texcoords3D_);
}
void release_edge_colors()
{
if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
remove_property(edge_colors_);
}
void release_face_normals()
{
......@@ -543,6 +570,7 @@ public:
bool has_halfedge_texcoords1D() const { return halfedge_texcoords1D_.is_valid();}
bool has_halfedge_texcoords2D() const { return halfedge_texcoords2D_.is_valid();}
bool has_halfedge_texcoords3D() const { return halfedge_texcoords3D_.is_valid();}
bool has_edge_colors() const { return edge_colors_.is_valid(); }
bool has_face_normals() const { return face_normals_.is_valid(); }
bool has_face_colors() const { return face_colors_.is_valid(); }
bool has_face_texture_index() const { return face_texture_index_.is_valid(); }
......@@ -558,6 +586,7 @@ public:
typedef HPropHandleT<TexCoord1D> HalfedgeTexCoords1DPropertyHandle;
typedef HPropHandleT<TexCoord2D> HalfedgeTexCoords2DPropertyHandle;
typedef HPropHandleT<TexCoord3D> HalfedgeTexCoords3DPropertyHandle;
typedef EPropHandleT<Color> EdgeColorsPropertyHandle;
typedef FPropHandleT<Normal> FaceNormalsPropertyHandle;
typedef FPropHandleT<Color> FaceColorsPropertyHandle;
typedef FPropHandleT<TextureIndex> FaceTextureIndexPropertyHandle;
......@@ -591,6 +620,10 @@ public:
HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph() const
{ return halfedge_texcoords3D_; }
// standard edge properties
EdgeColorsPropertyHandle edge_colors_pph() const
{ return edge_colors_; }
//standard face properties
FaceNormalsPropertyHandle face_normals_pph() const
......@@ -638,6 +671,8 @@ private:
HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
// standard edge properties
EdgeColorsPropertyHandle edge_colors_;
//standard face properties
FaceNormalsPropertyHandle face_normals_;
FaceColorsPropertyHandle face_colors_;
......@@ -656,6 +691,7 @@ private:
unsigned int refcount_htexcoords1D_;
unsigned int refcount_htexcoords2D_;
unsigned int refcount_htexcoords3D_;
unsigned int refcount_ecolors_;
unsigned int refcount_fnormals_;
unsigned int refcount_fcolors_;
unsigned int refcount_ftextureIndex_;
......
......@@ -78,7 +78,7 @@ enum AttributeBits
{
None = 0, ///< Clear all attribute bits
Normal = 1, ///< Add normals to mesh item (vertices/faces)
Color = 2, ///< Add colors to mesh item (vertices/faces)
Color = 2, ///< Add colors to mesh item (vertices/faces/edges)
PrevHalfedge = 4, ///< Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Status = 8, ///< Add status to mesh item (all items)
TexCoord1D = 16, ///< Add 1D texture coordinates (vertices, halfedges)
......
......@@ -126,6 +126,7 @@ public:
refcount_vtexcoords_(0),
refcount_vstatus_(0),
refcount_estatus_(0),
refcount_ecolors_(0),
refcount_hstatus_(0),
refcount_fnormals_(0),
refcount_fcolors_(0),
......@@ -152,6 +153,9 @@ public:
if (EAttribs & Attributes::Status)
request_edge_status();
if (EAttribs & Attributes::Color)
request_edge_colors();
if (FAttribs & Attributes::Normal)
request_face_normals();
......@@ -188,6 +192,7 @@ public:
remove_property(vertex_status_);
remove_property(halfedge_status_);
remove_property(edge_status_);
remove_property(edge_colors_);
remove_property(face_normals_);
remove_property(face_colors_);
remove_property(face_status_);
......@@ -203,6 +208,7 @@ public:
vertex_status_ = _rhs.vertex_status_;
halfedge_status_ = _rhs.halfedge_status_;
edge_status_ = _rhs.edge_status_;
edge_colors_ = _rhs.edge_colors_;
face_normals_ = _rhs.face_normals_;
face_colors_ = _rhs.face_colors_;
face_status_ = _rhs.face_status_;
......@@ -214,6 +220,7 @@ public:
refcount_vstatus_ = _rhs.refcount_vstatus_;
refcount_hstatus_ = _rhs.refcount_hstatus_;
refcount_estatus_ = _rhs.refcount_estatus_;
refcount_ecolors_ = _rhs.refcount_ecolors_;
refcount_fnormals_ = _rhs.refcount_fnormals_;
refcount_fcolors_ = _rhs.refcount_fcolors_;
refcount_fstatus_ = _rhs.refcount_fstatus_;
......@@ -236,6 +243,11 @@ public:
typename GeoTexCoords::property_ptr_t osg_vtexcoords()
{ return vtexcoords(vertex_texcoords_).osg_ptr(); }
//------------------------------ edge property
typename GeoColors::property_ptr_t osg_ecolors()
{ return ecolors(edge_colors_).osg_ptr(); }
//------------------------------ face property
......@@ -333,7 +345,7 @@ public:
}
//---------------------------------------- edge status
//---------------------------------------- halfedge status
const StatusInfo& status(HalfedgeHandle _eh) const {
return property(halfedge_status_, _eh);
......@@ -353,6 +365,20 @@ public:
StatusInfo& status(EdgeHandle _eh) {
return property(edge_status_, _eh);
}
//---------------------------------------- edge colors
const Color* edge_colors() const {
return ecolors(edge_colors_).data();
}
const Color& color(EdgeHandle _eh) const {
return ecolors(edge_colors_, _eh);
}
void set_color(EdgeHandle _eh, const Color& _c) {
ecolors(edge_colors_, _eh) = _c;
}
//---------------------------------------- face status
......@@ -420,6 +446,11 @@ public:
if (!refcount_estatus_++)
add_property( edge_status_, "e:status" );
}
void request_edge_colors() {
if (!refcount_ecolors_++)
edge_colors_ = add_ecolors( Color(), "e:colors" );
}
void request_face_normals() {
if (!refcount_fnormals_++)
......@@ -469,6 +500,11 @@ public:
if ((refcount_estatus_ > 0) && (! --refcount_estatus_))
remove_property(edge_status_);
}
void release_edge_colors() {
if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
remove_property(edge_colors_);
}
void release_face_normals() {
if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
......@@ -518,6 +554,10 @@ public:
GenProg::Bool2Type<(bool)(EAttribs & Attributes::Status)>
HasEdgeStatus;
typedef
GenProg::Bool2Type<(bool)(EAttribs & Attributes::Color)>
HasEdgeColors;
typedef
GenProg::Bool2Type<(bool)(FAttribs & Attributes::Normal)>
......@@ -540,6 +580,7 @@ public:
bool has_vertex_status() const { return vertex_status_.is_valid(); }
bool has_edge_status() const { return edge_status_.is_valid(); }
bool has_halfedge_status() const { return halfedge_status_.is_valid(); }
bool has_edge_colors() const { return edge_colors_.is_valid(); }
bool has_face_normals() const { return face_normals_.is_valid(); }
bool has_face_colors() const { return face_colors_.is_valid(); }
bool has_face_status() const { return face_status_.is_valid(); }
......@@ -626,6 +667,7 @@ private:
FIndicesHandle face_indices_;
EPropHandleT<StatusInfo> edge_status_;
EPropHandleT<StatusInfo> edge_colors_;
HPropHandleT<StatusInfo> halfedge_status_;
FPropHandleT<Normal> face_normals_;
......@@ -637,6 +679,7 @@ private:
unsigned int refcount_vtexcoords_;
unsigned int refcount_vstatus_;
unsigned int refcount_estatus_;
unsigned int refcount_ecolors_;
unsigned int refcount_hstatus_;
unsigned int refcount_fnormals_;
unsigned int refcount_fcolors_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment