Equalizer  1.6.1
eVolve/frameData.cpp
1 
2 /* Copyright (c) 2006-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2007-2011, Maxim Makhinya <maxmah@gmail.com>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * - Neither the name of Eyescale Software GmbH nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "frameData.h"
31 
32 #ifndef M_PI_2
33 # define M_PI_2 1.57079632679489661923
34 #endif
35 
36 namespace eVolve
37 {
38 
39 FrameData::FrameData()
40  : _ortho( false )
41  , _colorMode( COLOR_MODEL )
42  , _bgMode( BG_BLACK )
43  , _normalsQuality(NQ_FULL )
44  , _statistics( false )
45  , _help( false )
46  , _quality( 1.0f )
47 {
48  reset();
49  LBINFO << "New FrameData " << std::endl;
50 }
51 
52 void FrameData::reset()
53 {
54  _translation = eq::Vector3f::ZERO;
55  _translation.z() = -2.f;
56  _rotation = eq::Matrix4f::IDENTITY;
57  _rotation.rotate_x( static_cast<float>( -M_PI_2 ));
58  _rotation.rotate_y( static_cast<float>( -M_PI_2 ));
59 
60  setDirty( DIRTY_CAMERA );
61 }
62 
63 void FrameData::toggleBackground()
64 {
65  _bgMode = static_cast< BackgroundMode >(( _bgMode + 1 ) % BG_ALL );
66  setDirty( DIRTY_FLAGS );
67 }
68 
69 void FrameData::toggleNormalsQuality()
70 {
71  _normalsQuality =
72  static_cast< NormalsQuality >(( _normalsQuality + 1 ) % NQ_ALL );
73  setDirty( DIRTY_FLAGS );
74 }
75 
76 
77 void FrameData::toggleColorMode()
78 {
79  _colorMode = static_cast< ColorMode >(( _colorMode + 1 ) % COLOR_ALL );
80  setDirty( DIRTY_FLAGS );
81 }
82 
83 void FrameData::toggleOrtho( )
84 {
85  _ortho = !_ortho;
86  setDirty( DIRTY_FLAGS );
87 }
88 
89 void FrameData::setOrtho( const bool ortho )
90 {
91  _ortho = ortho;
92  setDirty( DIRTY_FLAGS );
93 }
94 
95 void FrameData::toggleStatistics()
96 {
97  _statistics = !_statistics;
98  setDirty( DIRTY_FLAGS );
99 }
100 
101 void FrameData::toggleHelp()
102 {
103  _help = !_help;
104  setDirty( DIRTY_FLAGS );
105 }
106 
107 void FrameData::spinCamera( const float x, const float y )
108 {
109  _rotation.pre_rotate_x( x );
110  _rotation.pre_rotate_y( y );
111 
112  setDirty( DIRTY_CAMERA );
113 }
114 
115 void FrameData::moveCamera( const float x, const float y, const float z )
116 {
117  _translation.x() += x;
118  _translation.y() += y;
119  _translation.z() += z;
120 
121  setDirty( DIRTY_CAMERA );
122 }
123 
124 void FrameData::setTranslation( const eq::Vector3f& translation )
125 {
126  _translation = translation;
127  setDirty( DIRTY_CAMERA );
128 }
129 
130 void FrameData::setRotation( const eq::Vector3f& rotation )
131 {
132  _rotation = eq::Matrix4f::IDENTITY;
133  _rotation.rotate_x( rotation.x() );
134  _rotation.rotate_y( rotation.y() );
135  _rotation.rotate_z( rotation.z() );
136  setDirty( DIRTY_CAMERA );
137 }
138 
139 void FrameData::setCurrentViewID( const eq::uint128_t& id )
140 {
141  _currentViewID = id;
142  setDirty( DIRTY_VIEW );
143 }
144 
145 void FrameData::adjustQuality( const float delta )
146 {
147  _quality += delta;
148  _quality = LB_MAX( _quality, 0.1f );
149  _quality = LB_MIN( _quality, 1.0f );
150  setDirty( DIRTY_FLAGS );
151  LBINFO << "Set non-idle image quality to " << _quality << std::endl;
152 }
153 
154 void FrameData::serialize( co::DataOStream& os, const uint64_t dirtyBits )
155 {
156  co::Serializable::serialize( os, dirtyBits );
157  if( dirtyBits & DIRTY_VIEW )
158  os << _currentViewID;
159 
160  if( dirtyBits & DIRTY_CAMERA )
161  os << _rotation << _translation;
162 
163  if( dirtyBits & DIRTY_FLAGS )
164  os << _ortho << _colorMode << _bgMode << _normalsQuality
165  << _statistics << _quality << _help;
166 
167  if( dirtyBits & DIRTY_MESSAGE )
168  os << _message;
169 }
170 
171 void FrameData::deserialize( co::DataIStream& is, const uint64_t dirtyBits)
172 {
173  co::Serializable::deserialize( is, dirtyBits );
174  if( dirtyBits & DIRTY_VIEW )
175  is >> _currentViewID;
176 
177  if( dirtyBits & DIRTY_CAMERA )
178  is >> _rotation >> _translation;
179 
180  if( dirtyBits & DIRTY_FLAGS )
181  is >> _ortho >> _colorMode >> _bgMode >> _normalsQuality
182  >> _statistics >> _quality >> _help;
183 
184  if( dirtyBits & DIRTY_MESSAGE )
185  is >> _message;
186 }
187 
188 void FrameData::setMessage( const std::string& message )
189 {
190  if( _message == message )
191  return;
192 
193  _message = message;
194  setDirty( DIRTY_MESSAGE );
195 }
196 
197 }
virtual void deserialize(co::DataIStream &is, const uint64_t dirtyBits)
NormalsQuality
Definition: eVolve.h:80
virtual void serialize(co::DataOStream &os, const uint64_t dirtyBits)
Black background.
Definition: eVolve.h:74
BackgroundMode
Definition: eVolve.h:72
ColorMode
Definition: eqPly.h:76
Highest normals quality.
Definition: eVolve.h:82
Render using the colors defined in the ply file.
Definition: eVolve.h:66