Commit a990d6e4 authored by Jan Möbius's avatar Jan Möbius
Browse files

Switched color type to vec4f for triangle and poly meshes

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12486 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 004cd2f6
......@@ -426,21 +426,21 @@ DrawMeshT<Mesh>::readVertex(Vertex* _pV,
unsigned int byteCol[2];
for (int col = 0; col < 2; ++col)
{
typename Mesh::Color vecCol(255, 255, 255);
typename Mesh::Color vecCol(255, 255, 255, 255);
if (col == 0 && mesh_.has_vertex_colors()) vecCol = mesh_.color(_vh);
if (col == 0 && mesh_.has_vertex_colors()) vecCol = OpenMesh::color_cast<Vec4uc,typename Mesh::Color>(mesh_.color(_vh));
if ((_fh != (typename Mesh::FaceHandle)(-1)))
{
if (col == 1 && mesh_.has_face_colors() && _fh.idx() >= 0)
vecCol = mesh_.color(_fh);
vecCol = OpenMesh::color_cast<Vec4uc,typename Mesh::Color>(mesh_.color(_fh));
}
// OpenGL color format: A8B8G8R8
byteCol[col] = (unsigned char)(vecCol[0]);
byteCol[col] |= ((unsigned char)(vecCol[1])) << 8;
byteCol[col] |= ((unsigned char)(vecCol[2])) << 16;
// byteCol[col] |= ((unsigned char)(floatCol[3])) << 24; // no alpha channel in OpenMesh
byteCol[col] |= 0xFF << 24;
byteCol[col] |= ((unsigned char)(vecCol[3])) << 24;
//byteCol[col] |= 0xFF << 24; // if no alpha channel
}
_pV->vcol = byteCol[0];
......
......@@ -74,11 +74,9 @@ struct PolyTraits : public OpenMesh::DefaultTraits
typedef OpenMesh::Vec3d Point;
/// Use double precision Normals
typedef OpenMesh::Vec3d Normal;
/// Use double precision rgba Color
// typedef OpenMesh::Vec4f Color;
/// Use double precision rgba Color
// typedef OpenMesh::Vec4f Color;
/// Use RGBA Color
typedef OpenMesh::Vec4f Color;
};
/// Simple Name for Mesh
......
......@@ -74,8 +74,8 @@ struct TriTraits : public OpenMesh::DefaultTraits
/// Use double precision Normals
typedef OpenMesh::Vec3d Normal;
/// Use double precision rgba Color
// typedef OpenMesh::Vec4f Color;
/// Use RGBA Color
typedef OpenMesh::Vec4f Color;
};
......
......@@ -86,9 +86,8 @@ bool FileOBJPlugin::writeMaterial(QString _filename, MeshT& _mesh, int _objId )
typename MeshT::FaceIter f_it;
typename MeshT::FaceIter f_end = _mesh.faces_end();
// Prepare materials ( getMaterial handles a list that is set up by this call)
for (f_it = _mesh.faces_begin(); f_it != f_end; ++f_it){
c = OpenMesh::color_cast<OpenMesh::Vec4f> (_mesh.color( f_it.handle() ));
getMaterial(_mesh, f_it.handle(), _objId);
}
......@@ -142,7 +141,7 @@ Material& FileOBJPlugin::getMaterial(MeshT& _mesh, const OpenMesh::FaceHandle& _
optionColorAlpha = saveAlpha_->isChecked();
// \TODO Fetch options from ini states if dialog box is not available
OpenMesh::Vec4f c = OpenMesh::color_cast<OpenMesh::Vec4f> (_mesh.color( _fh ));
OpenMesh::Vec4f c = _mesh.color( _fh );
// First off, try to fetch texture index of current face/object...
if(!textureIndexPropFetched_) {
......
......@@ -576,7 +576,17 @@ void OBJImporter::addMaterial(std::string _materialName){
bool colorAllowed = ! ( objectOptions_[ currentObject() ] & FORCE_NOCOLOR );
if ( currentTriMesh()->has_face_colors() && colorAllowed ){
currentTriMesh()->set_color(addedFacesTri_[currentGroup_][i], OpenMesh::color_cast< TriMesh::Color >(mat.Kd() ) );
TriMesh::Color color = OpenMesh::color_cast< OpenMesh::Vec4f >(mat.Kd() );
// Get alpha if available
if (mat.has_Tr() ) {
color[3] = mat.Tr();
} else {
color[3] = 1.0;
}
currentTriMesh()->set_color(addedFacesTri_[currentGroup_][i], color );
objectOptions_[ currentObject() ] |= FACECOLOR;
}
}
......@@ -624,7 +634,17 @@ void OBJImporter::addMaterial(std::string _materialName){
bool colorAllowed = ! ( objectOptions_[ currentObject() ] & FORCE_NOCOLOR );
if ( currentPolyMesh()->has_face_colors() && colorAllowed && addedFacePoly_.is_valid() ){
currentPolyMesh()->set_color(addedFacePoly_, OpenMesh::color_cast< PolyMesh::Color >(mat.Kd() ));
TriMesh::Color color = OpenMesh::color_cast< OpenMesh::Vec4f >(mat.Kd() );
// Get alpha if available
if (mat.has_Tr() ) {
color[3] = mat.Tr();
} else {
color[3] = 1.0;
}
currentPolyMesh()->set_color(addedFacePoly_, color );
objectOptions_[ currentObject() ] |= FACECOLOR;
}
}
......
......@@ -837,7 +837,7 @@ bool FileOFFPlugin::parseBinary(std::istream& _in, OFFImporter& _importer, DataT
unsigned int nV, nF, dummy;
float dummy_f;
OpenMesh::Vec3f v, n;
OpenMesh::Vec3f c;
OpenMesh::Vec4f c;
float alpha = 1.0f;
OpenMesh::Vec2f t;
std::vector<VertexHandle> vhandles;
......@@ -895,9 +895,10 @@ bool FileOFFPlugin::parseBinary(std::istream& _in, OFFImporter& _importer, DataT
readValue(_in, c[0]);
readValue(_in, c[1]);
readValue(_in, c[2]);
c[3] = 1.0;
if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
int cidx = _importer.addColor( OpenMesh::color_cast<OpenMesh::Vec3uc, OpenMesh::Vec3f>(c) );
int cidx = _importer.addColor( c );
_importer.setVertexColor(vh, cidx);
}
}
......@@ -1023,11 +1024,11 @@ bool FileOFFPlugin::parseBinary(std::istream& _in, OFFImporter& _importer, DataT
if(userReadOptions_ & OFFImporter::FACECOLOR) {
if(userReadOptions_ & OFFImporter::COLORALPHA) {
int cidx = _importer.addColor(OpenMesh::color_cast<OpenMesh::Vec4uc, OpenMesh::Vec4f>(OpenMesh::Vec4f(c[0], c[1], c[2], alpha)));
int cidx = _importer.addColor(OpenMesh::Vec4f(c[0], c[1], c[2], alpha));
_importer.setFaceColor( fh, cidx );
_importer.addOption(OFFImporter::COLORALPHA);
} else {
int cidx = _importer.addColor(OpenMesh::color_cast<OpenMesh::Vec3uc, OpenMesh::Vec3f>(c));
int cidx = _importer.addColor(OpenMesh::color_cast<OpenMesh::Vec4f>(c));
_importer.setFaceColor( fh, cidx );
}
}
......
......@@ -129,7 +129,7 @@ bool FileOFFPlugin::writeASCIIData(std::ostream& _out, MeshT& _mesh ) {
if(_mesh.has_vertex_colors() && (userWriteOptions_ & OFFImporter::VERTEXCOLOR)) {
c = OpenMesh::color_cast<OpenMesh::Vec4f> (_mesh.color(vit.handle()));
_out.precision(6);
_out << " " << std::showpoint << c[0] << " " << std::showpoint << c[1] << " " << std::showpoint << c[2];
_out << " " << std::showpoint << c[0] << " " << std::showpoint << c[1] << " " << std::showpoint << c[2] << " " << std::showpoint << c[3];
}
// Write vertex texcoords
......@@ -163,7 +163,7 @@ bool FileOFFPlugin::writeASCIIData(std::ostream& _out, MeshT& _mesh ) {
if(_mesh.has_face_colors() && userWriteOptions_ & OFFImporter::FACECOLOR) {
c = OpenMesh::color_cast<OpenMesh::Vec4f> (_mesh.color(fit.handle()));
_out.precision(6);
_out << " " << std::showpoint << c[0] << " " << std::showpoint << c[1] << " " << std::showpoint << c[2];
_out << " " << std::showpoint << c[0] << " " << std::showpoint << c[1] << " " << std::showpoint << c[2] << " " << std::showpoint << c[3];
if(userWriteOptions_ & OFFImporter::COLORALPHA) _out << " " << std::showpoint << c[3];
}
......@@ -259,9 +259,9 @@ bool FileOFFPlugin::writeBinaryData(std::ostream& _out, MeshT& _mesh ){
if(userWriteOptions_ & OFFImporter::COLORALPHA) writeValue(_out, c[3]);
} else {
// There are no face colors
writeValue(_out, (uint)0);
writeValue(_out, c[3]);
}
}
return true;
}
\ No newline at end of file
}
......@@ -119,7 +119,7 @@ int OFFImporter::addNormal(const Vec3f& _normal){
//-----------------------------------------------------------------------------
/// add a color
int OFFImporter::addColor(const Vec4uc& _color) {
int OFFImporter::addColor(const Vec4f& _color) {
colors_.push_back( _color );
return colors_.size()-1;
......@@ -127,15 +127,6 @@ int OFFImporter::addColor(const Vec4uc& _color) {
//-----------------------------------------------------------------------------
/// add a color
int OFFImporter::addColor(const Vec3uc& _color) {
colors_.push_back( Vec4uc(_color[0], _color[1], _color[2], 255) );
return colors_.size()-1;
}
//-----------------------------------------------------------------------------
/// get mesh as polyMesh
PolyMesh* OFFImporter::polyMesh(){
if (polyMesh_ == 0)
......@@ -544,9 +535,7 @@ void OFFImporter::setObjectName(QString _name){
/// set RGBA color of vertex
void OFFImporter::setVertexColor(VertexHandle _vh, int _colorIndex) {
// TODO Implement color alpha
if ( isTriangleMesh() ){
//handle triangle meshes
......@@ -555,8 +544,7 @@ void OFFImporter::setVertexColor(VertexHandle _vh, int _colorIndex) {
if ( _colorIndex < (int) colors_.size() ){
if ( vertexMapTri_.find( _vh ) != vertexMapTri_.end() ){
Vec4uc c = colors_[_colorIndex];
triMesh()->set_color( vertexMapTri_[_vh], TriMesh::Color(c[0], c[1], c[2]) );
triMesh()->set_color( vertexMapTri_[_vh], colors_[_colorIndex] );
objectOptions_ |= VERTEXCOLOR;
}
......@@ -572,8 +560,7 @@ void OFFImporter::setVertexColor(VertexHandle _vh, int _colorIndex) {
if ( _colorIndex < (int) colors_.size() ){
if ( vertexMapPoly_.find( _vh ) != vertexMapPoly_.end() ){
Vec4uc c = colors_[_colorIndex];
polyMesh()->set_color( vertexMapPoly_[_vh], PolyMesh::Color(c[0], c[1], c[2]) );
polyMesh()->set_color( vertexMapPoly_[_vh], colors_[_colorIndex] );
objectOptions_ |= VERTEXCOLOR;
}
......@@ -597,8 +584,7 @@ void OFFImporter::setFaceColor(FaceHandle _fh, int _colorIndex) {
if ( _colorIndex < (int) colors_.size() ){
if ( _fh < (int)faceMapTri_.size() ) {
Vec4uc c = colors_[_colorIndex];
triMesh()->set_color( faceMapTri_[_fh], TriMesh::Color(c[0], c[1], c[2]) );
triMesh()->set_color( faceMapTri_[_fh],colors_[_colorIndex] );
objectOptions_ |= FACECOLOR;
}
......@@ -614,8 +600,7 @@ void OFFImporter::setFaceColor(FaceHandle _fh, int _colorIndex) {
if ( _colorIndex < (int) colors_.size() ){
if ( _fh < (int)faceMapPoly_.size() ) {
Vec4uc c = colors_[_colorIndex];
polyMesh()->set_color( faceMapPoly_[_fh], PolyMesh::Color(c[0], c[1], c[2]) );
polyMesh()->set_color( faceMapPoly_[_fh], colors_[_colorIndex] );
objectOptions_ |= FACECOLOR;
}
......@@ -624,4 +609,4 @@ void OFFImporter::setFaceColor(FaceHandle _fh, int _colorIndex) {
}
}
}
\ No newline at end of file
}
......@@ -64,6 +64,7 @@ typedef int VertexHandle;
typedef int FaceHandle;
typedef std::vector<VertexHandle> VHandles;
typedef std::vector<OpenMesh::VertexHandle> OMVHandles;
typedef OpenMesh::Vec4f Vec4f;
typedef OpenMesh::Vec3f Vec3f;
typedef OpenMesh::Vec2f Vec2f;
typedef OpenMesh::Vec4uc Vec4uc;
......@@ -111,11 +112,8 @@ class OFFImporter
int addTexCoord(const Vec2f& _coord);
/// add a color
int addColor(const Vec4uc& _color);
/// add a color
int addColor(const Vec3uc& _color);
int addColor(const Vec4f& _color);
/// add a normal
int addNormal(const Vec3f& _normal);
......@@ -191,7 +189,7 @@ class OFFImporter
std::vector< Vec3f > vertices_;
std::vector< Vec3f > normals_;
std::vector< Vec2f > texCoords_;
std::vector< Vec4uc > colors_;
std::vector< Vec4f > colors_;
// file path
QString path_;
......
......@@ -155,9 +155,11 @@ bool FilePLYPlugin::readMeshFileAscii(QString _filename, MeshT* _mesh, const PLY
if(_header.hasVertexColorAlpha) {
sstr >> alpha;
propIndex++;
} else {
alpha = 1.0;
}
// Set color
if ( vColors ) _mesh->set_color(currentVertex, typename MeshT::Color(dx, dy, dz));
if ( vColors ) _mesh->set_color(currentVertex, typename MeshT::Color(dx, dy, dz,alpha));
// Go over to next property
propIndex += 3;
......@@ -243,7 +245,7 @@ bool FilePLYPlugin::readMeshFileAscii(QString _filename, MeshT* _mesh, const PLY
// Parse face colors
sstr >> dx >> dy >> dz;
// Set color
if (fColors) _mesh->set_color(currentFace, typename MeshT::Color(dx, dy, dz));
if (fColors) _mesh->set_color(currentFace, typename MeshT::Color(dx, dy, dz,1.0));
// Go over to next property
propIndex += 3;
} else if (_header.fProps[propIndex].first == "a_rgb" && fColors) {
......
......@@ -264,7 +264,7 @@ IdList MeshObjectSelectionPlugin::getEdgeSelection( int objectId ) {
//=========================================================
void MeshObjectSelectionPlugin::colorizeEdgeSelection(int objectId, int r, int g, int b ) {
void MeshObjectSelectionPlugin::colorizeEdgeSelection(int objectId, int r, int g, int b, int a ) {
BaseObjectData* object;
if ( ! PluginFunctions::getObject(objectId,object) ) {
......@@ -273,9 +273,9 @@ void MeshObjectSelectionPlugin::colorizeEdgeSelection(int objectId, int r, int g
}
if ( object->dataType() == DATA_TRIANGLE_MESH ) {
colorizeSelection(PluginFunctions::triMesh(object), edgeType_, r, g, b);
colorizeSelection(PluginFunctions::triMesh(object), edgeType_, r, g, b, a);
} else if ( object->dataType() == DATA_POLY_MESH ) {
colorizeSelection(PluginFunctions::polyMesh(object), edgeType_, r, g, b);
colorizeSelection(PluginFunctions::polyMesh(object), edgeType_, r, g, b, a);
} else {
emit log(LOGERR,"colorizeEdgeSelection : Unsupported object Type" );
return;
......
......@@ -310,7 +310,7 @@ IdList MeshObjectSelectionPlugin::getFaceSelection(int objectId) {
//=========================================================
/// colorize the face selection
void MeshObjectSelectionPlugin::colorizeFaceSelection(int objectId, int r, int g, int b) {
void MeshObjectSelectionPlugin::colorizeFaceSelection(int objectId, int r, int g, int b, int a) {
BaseObjectData* object;
if (! PluginFunctions::getObject(objectId,object)) {
......@@ -319,9 +319,9 @@ void MeshObjectSelectionPlugin::colorizeFaceSelection(int objectId, int r, int g
}
if (object->dataType() == DATA_TRIANGLE_MESH) {
colorizeSelection(PluginFunctions::triMesh(object), faceType_, r, g, b);
colorizeSelection(PluginFunctions::triMesh(object), faceType_, r, g, b, a);
} else if (object->dataType() == DATA_POLY_MESH) {
colorizeSelection(PluginFunctions::polyMesh(object), faceType_, r, g, b);
colorizeSelection(PluginFunctions::polyMesh(object), faceType_, r, g, b, a);
} else {
emit log(LOGERR,"colorizeFaceSelection : Unsupported object Type");
return;
......
......@@ -242,7 +242,7 @@ IdList MeshObjectSelectionPlugin::getHalfedgeSelection(int objectId) {
//=========================================================
/// colorize the halfedge selection
void MeshObjectSelectionPlugin::colorizeHalfedgeSelection(int objectId, int r, int g, int b) {
void MeshObjectSelectionPlugin::colorizeHalfedgeSelection(int objectId, int r, int g, int b, int a) {
BaseObjectData* object;
if (! PluginFunctions::getObject(objectId,object)) {
......@@ -251,9 +251,9 @@ void MeshObjectSelectionPlugin::colorizeHalfedgeSelection(int objectId, int r, i
}
if (object->dataType() == DATA_TRIANGLE_MESH) {
colorizeSelection(PluginFunctions::triMesh(object), halfedgeType_, r, g, b);
colorizeSelection(PluginFunctions::triMesh(object), halfedgeType_, r, g, b, a);
} else if (object->dataType() == DATA_POLY_MESH) {
colorizeSelection(PluginFunctions::polyMesh(object), halfedgeType_, r, g, b);
colorizeSelection(PluginFunctions::polyMesh(object), halfedgeType_, r, g, b, a);
} else {
emit log(LOGERR,"colorizeHalfedgeSelection: Unsupported object Type");
return;
......@@ -263,4 +263,4 @@ void MeshObjectSelectionPlugin::colorizeHalfedgeSelection(int objectId, int r, i
+ QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + ")");
emit updatedObject(object->id(), UPDATE_COLOR);
}
\ No newline at end of file
}
......@@ -597,21 +597,21 @@ void MeshObjectSelectionPlugin::slotSelectionOperation(QString _operation) {
void MeshObjectSelectionPlugin::setColorForSelection(const int _objectId, const PrimitiveType _primitiveTypes) {
QColor c = QColorDialog::getColor(Qt::red, 0);
QColor c = QColorDialog::getColor(Qt::red, 0, tr("Choose color"),QColorDialog::ShowAlphaChannel);
if(c.isValid()) {
if(_primitiveTypes & vertexType_) {
// Vertex colorization
colorizeVertexSelection(_objectId, c.red(), c.green(), c.blue());
colorizeVertexSelection(_objectId, c.red(), c.green(), c.blue(), c.alpha());
} else if (_primitiveTypes & edgeType_) {
// Edge colorization
colorizeEdgeSelection(_objectId, c.red(), c.green(), c.blue());
colorizeEdgeSelection(_objectId, c.red(), c.green(), c.blue(), c.alpha());
} else if (_primitiveTypes & halfedgeType_) {
// Edge colorization
colorizeHalfedgeSelection(_objectId, c.red(), c.green(), c.blue());
colorizeHalfedgeSelection(_objectId, c.red(), c.green(), c.blue(), c.alpha());
} else if (_primitiveTypes & faceType_) {
// Edge colorization
colorizeFaceSelection(_objectId, c.red(), c.green(), c.blue());
colorizeFaceSelection(_objectId, c.red(), c.green(), c.blue(), c.alpha());
}
}
}
......
......@@ -269,7 +269,7 @@ public slots:
void deleteVertexSelection(int _objectId);
/// Colorize the vertex selection
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b);
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int a);
//==========================================
......@@ -340,7 +340,7 @@ public slots:
IdList getEdgeSelection(int objectId);
/// Colorize the edge selection
void colorizeEdgeSelection(int objectId, int r, int g, int b);
void colorizeEdgeSelection(int objectId, int r, int g, int b, int a);
//==========================================
// HALFEDGE OPERATIONS
......@@ -368,7 +368,7 @@ public slots:
IdList getHalfedgeSelection(int objectId);
/// Colorize the edge selection
void colorizeHalfedgeSelection(int objectId, int r, int g, int b);
void colorizeHalfedgeSelection(int objectId, int r, int g, int b, int a);
//==========================================
// FACE OPERATIONS
......@@ -405,7 +405,7 @@ public slots:
IdList getFaceSelection(int objectId);
/// Colorize the face selection
void colorizeFaceSelection(int objectId, int r, int g, int b);
void colorizeFaceSelection(int objectId, int r, int g, int b, int a);
//===========================================================================
......@@ -458,7 +458,7 @@ private:
/// Colorize the selection
template<class MeshT>
void colorizeSelection(MeshT* _mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue);
void colorizeSelection(MeshT* _mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha);
/** @} */
......
......@@ -779,12 +779,19 @@ void MeshObjectSelectionPlugin::componentsMeshSelection(MeshT* _mesh, uint _fh,
* @param _blue rgb color
*/
template< typename MeshT >
void MeshObjectSelectionPlugin::colorizeSelection(MeshT* _mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue) {
typename MeshT::Color color;
color[0] = _red;
void MeshObjectSelectionPlugin::colorizeSelection(MeshT* _mesh,
PrimitiveType _primitiveTypes,
int _red,
int _green,
int _blue,
int _alpha) {
typename MeshT::Color color = OpenMesh::color_cast<OpenMesh::Vec4f,OpenMesh::Vec4uc>(OpenMesh::Vec4uc(_red,_green,_blue,_alpha));
/*color[0] = _red;
color[1] = _green;
color[2] = _blue;
color[3] = _alpha;
*/
if (_primitiveTypes & vertexType_) {
typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
......
......@@ -337,7 +337,7 @@ void MeshObjectSelectionPlugin::deleteVertexSelection(int _objectId) {
//=========================================================
/// colorize the vertex selection
void MeshObjectSelectionPlugin::colorizeVertexSelection(int _objectId, int r, int g, int b) {
void MeshObjectSelectionPlugin::colorizeVertexSelection(int _objectId, int r, int g, int b, int a) {
BaseObjectData* object;
if (!PluginFunctions::getObject(_objectId, object)) {
......@@ -346,9 +346,9 @@ void MeshObjectSelectionPlugin::colorizeVertexSelection(int _objectId, int r, in
}
if (object->dataType() == DATA_TRIANGLE_MESH) {
colorizeSelection(PluginFunctions::triMesh(object), vertexType_, r, g, b);
colorizeSelection(PluginFunctions::triMesh(object), vertexType_, r, g, b, a);
} else if (object->dataType() == DATA_POLY_MESH) {
colorizeSelection(PluginFunctions::polyMesh(object), vertexType_, r, g, b);
colorizeSelection(PluginFunctions::polyMesh(object), vertexType_, r, g, b, a);
} else {
emit log(LOGERR,"colorizeVertexSelection: Unsupported object Type");
return;
......
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