Developer Documentation

TextureControl1DTextureHandlingT_impl.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44 #define TEXTURECONTROL_1D_TEXTURE_HANDLING_C
45
46 #include "TextureControl.hh"
47 #include "TextureMath.hh"
48
49 template< typename MeshT >
50 void TextureControlPlugin::copyTexture ( Texture& _texture , MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp )
51 {
52 // Compute the minimal and maximal values for this texture
53 double max = -FLT_MIN;
54 double min = FLT_MAX;
55
56
57 // Compute minimal and maximal value of the coordinates
58 // Keep track of absolute values!
59 for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin() ; v_it != _mesh.vertices_end(); ++v_it) {
60
61 max = std::max( _mesh.property(_texProp,*v_it) , max);
62 min = std::min( _mesh.property(_texProp,*v_it) , min);
63
64 }
65
66
67 if ( !_mesh.has_vertex_texcoords2D() )
68 _mesh.request_vertex_texcoords2D();
69
70 TextureMath convert(_texture.parameters,min,max);
71
72 for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
73 // Get the value of the property
74 double value = _mesh.property(_texProp, *v_it);
75
76 // Mangle it with the predefined user options (including absolute, clamping, ...)
77 value = convert.transform(value);
78
79 // Write result to the OpenMesh texture coordinates ( 2d accessing the diagonal of a 2d texture)
80 _mesh.set_texcoord2D( *v_it, ACG::Vec2f(float(value), float(value) ) );
81 }
82 }
83
84 template< typename MeshT >
85 void TextureControlPlugin::copyTexture ( Texture& _texture , MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp )
86 {
87 // Compute the minimal and maximal values for this texture
88 double max = -FLT_MIN;
89 double min = FLT_MAX;
90
91 // Compute minimal and maximal value of the coordinates
92 // Keep track of absolute values!
93 for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin() ; h_it != _mesh.halfedges_end(); ++h_it) {
94
95 max = std::max( _mesh.property(_texProp,*h_it) , max);
96 min = std::min( _mesh.property(_texProp,*h_it) , min);
97
98 }
99
100 if ( !_mesh.has_halfedge_texcoords2D() )
101 _mesh.request_halfedge_texcoords2D();
102
103 TextureMath convert(_texture.parameters,min,max);
104
105 for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin(); h_it != _mesh.halfedges_end(); ++h_it) {
106
107 // Get the value of the property
108 double value = _mesh.property(_texProp, *h_it);
109
110 // Mangle it with the predefined user options (including absolute, clamping, ...)
111 value = convert.transform(value);
112
113 // Write result to the OpenMesh texture coordinates ( 2d accessing the diagonal of a 2d texture)
114 _mesh.set_texcoord2D( *h_it, ACG::Vec2f(float(value), float(value) ) );
115 }
116 }
117
Texture::parameters
TexParameters parameters
Parameters of the texture.
Definition: TextureData.hh:138
Texture
Definition: TextureData.hh:68
TextureMath::transform
double transform(const double _input) const
Modify given values based on the specified parameters given to the constructor.
Definition: TextureMath.cc:89
TextureMath
Definition: TextureMath.hh:49
OpenMesh::HPropHandleT
Definition: Property.hh:496
OpenMesh::VectorT
Definition: Vector11T.hh:83
TextureControlPlugin::copyTexture
void copyTexture(Texture &_texture, MeshT &_mesh, OpenMesh::VPropHandleT< double > _texProp)
Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property...
Definition: TextureControl1DTextureHandlingT_impl.hh:50
OpenMesh::VPropHandleT
Definition: Property.hh:482