Commit 5421915b authored by Jan Möbius's avatar Jan Möbius

Moved some code to separate files, documentation

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3720 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ffef61d2
......@@ -138,14 +138,7 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
/// Update the values in the Dialog box to the current ones
void updateDialog();
/// For a given mesh compute the minimum and maximum values depending on texture settings (vertex based)
template< typename MeshT >
inline
void computeMinMaxScalar(int _textureid, MeshT& _mesh,OpenMesh::VPropHandleT< double > _texture,double& _min , double& _max);
/// For a given mesh compute the minimum and maximum values depending on texture settings (halfedge based)
template< typename MeshT >
inline
void computeMinMaxScalar(int _textureid, MeshT& _mesh,OpenMesh::HPropHandleT< double > _texture,double& _min , double& _max);
/// Take a scalar value and return a clamped,... depending on texture settings
inline
......@@ -169,6 +162,17 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
template< typename MeshT >
void copyTexture(int _textureid, MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp );
/// For a given mesh compute the minimum and maximum values depending on texture settings (vertex based)
template< typename MeshT >
inline
void computeMinMaxScalar(int _textureid, MeshT& _mesh,OpenMesh::VPropHandleT< double > _texture,double& _min , double& _max);
/// For a given mesh compute the minimum and maximum values depending on texture settings (halfedge based)
template< typename MeshT >
inline
void computeMinMaxScalar(int _textureid, MeshT& _mesh,OpenMesh::HPropHandleT< double > _texture,double& _min , double& _max);
/** @} */
//===========================================================================
......
......@@ -33,15 +33,79 @@
#include "TextureControl.hh"
template< typename MeshT >
void TextureControlPlugin::computeMinMaxScalar(int _textureid, MeshT& _mesh,OpenMesh::VPropHandleT< double > _texture,
double& _min , double& _max) {
const bool abs = textures_[_textureid].abs;
const bool clamp = textures_[_textureid].clamp ;
const double clamp_max = textures_[_textureid].clamp_max;
const double clamp_min = textures_[_textureid].clamp_min;
_max = FLT_MIN;
_min = FLT_MAX;
for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin() ; v_it != _mesh.vertices_end(); ++v_it) {
if ( abs ) {
_max = std::max( fabs(_mesh.property(_texture,v_it)) , _max);
_min = std::min( fabs(_mesh.property(_texture,v_it)) , _min);
} else {
_max = std::max( _mesh.property(_texture,v_it) , _max);
_min = std::min( _mesh.property(_texture,v_it) , _min);
}
}
if ( clamp ) {
if ( _max > clamp_max )
_max = clamp_max;
if (_min < clamp_min)
_min = clamp_min;
}
}
template< typename MeshT >
void TextureControlPlugin::computeMinMaxScalar(int _textureid, MeshT& _mesh,OpenMesh::HPropHandleT< double > _texture,
double& _min , double& _max) {
const bool abs = textures_[_textureid].abs;
const bool clamp = textures_[_textureid].clamp ;
const double clamp_max = textures_[_textureid].clamp_max;
const double clamp_min = textures_[_textureid].clamp_min;
_max = FLT_MIN;
_min = FLT_MAX;
for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin() ; h_it != _mesh.halfedges_end(); ++h_it) {
if ( abs ) {
_max = std::max( fabs(_mesh.property(_texture,h_it)) , _max);
_min = std::min( fabs(_mesh.property(_texture,h_it)) , _min);
} else {
_max = std::max( _mesh.property(_texture,h_it) , _max);
_min = std::min( _mesh.property(_texture,h_it) , _min);
}
}
if ( clamp ) {
if ( _max > clamp_max )
_max = clamp_max;
if (_min < clamp_min)
_min = clamp_min;
}
}
template< typename MeshT >
void TextureControlPlugin::copyTexture ( int _textureid, MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp )
{
// Compute some basic values for this texture
double max,min;
computeMinMaxScalar(_textureid, _mesh, _texProp, min, max);
for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
// Get the value of the property
double value = _mesh.property(_texProp, v_it);
// Mangle it with the predefined user options
computeValue(_textureid, min, max, value);
// Write result to the openmesh texture coordinates ( 2d accessing the diagonal of a 2d texture)
_mesh.set_texcoord2D( v_it, ACG::Vec2f(float(value), float(value) ) );
}
}
......@@ -49,12 +113,19 @@ void TextureControlPlugin::copyTexture ( int _textureid, MeshT& _mesh, OpenMesh:
template< typename MeshT >
void TextureControlPlugin::copyTexture ( int _textureid, MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp )
{
// Compute some basic values for this texture
double max,min;
computeMinMaxScalar(_textureid, _mesh, _texProp, min, max);
for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin(); h_it != _mesh.halfedges_end(); ++h_it) {
// Get the value of the property
double value = _mesh.property(_texProp, h_it);
// Mangle it with the predefined user options
computeValue(_textureid, min, max, value);
// Write result to the openmesh texture coordinates ( 2d accessing the diagonal of a 2d texture)
_mesh.set_texcoord2D( h_it, ACG::Vec2f(float(value), float(value) ) );
}
}
......
......@@ -37,7 +37,11 @@ template< typename MeshT >
void TextureControlPlugin::copyTexture ( int /*_textureid*/, MeshT& _mesh, OpenMesh::VPropHandleT< OpenMesh::Vec2d > _texProp )
{
for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
// Get the value of the property
OpenMesh::Vec2d value = _mesh.property(_texProp, v_it);
// Write result to the openmesh texture coordinates
_mesh.set_texcoord2D( v_it, ACG::Vec2f(float(value[0]), float(value[1]) ) );
}
}
......@@ -46,7 +50,11 @@ template< typename MeshT >
void TextureControlPlugin::copyTexture ( int /*_textureid*/, MeshT& _mesh, OpenMesh::HPropHandleT< OpenMesh::Vec2d > _texProp )
{
for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin(); h_it != _mesh.halfedges_end(); ++h_it) {
// Get the value of the property
OpenMesh::Vec2d value = _mesh.property(_texProp, h_it);
// Write result to the openmesh texture coordinates
_mesh.set_texcoord2D( h_it, ACG::Vec2f(float(value[0]), float(value[1]) ) );
}
}
......
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