Developer Documentation
FileOfv.cc
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 
46 
47 #include <OpenMesh/Core/IO/IOManager.hh>
48 
49  #include <QtWidgets>
50 
51 #include "FileOfv.hh"
52 
53 
55 }
56 
58  return QString( tr("View definition files ( *.ofv )") );
59 }
60 
62  return QString( tr("View definition files ( *.ofv )") );
63 }
64 
66  return DataType();
67 }
68 
69 int FileViewPlugin::loadObject(QString _filename) {
70 
71  // Declare variables
72  ACG::Vec3d eye(1.0,1.0,1.0);
73  ACG::Vec3d center(0.0,0.0,0.0);
74  ACG::Vec3d up(1.0,0.0,0.0);
75  ACG::Vec4f background;
76 
77  bool e_eye = false;
78  bool e_center = false;
79  bool e_up = false;
80  bool e_background = false;
81 
82  QSettings settings(_filename, QSettings::IniFormat);
83  settings.beginGroup("VIEW");
84 
85  if(settings.contains("Width") && settings.contains("Height")) {
86  const int width = settings.value("Width").toInt();
87  const int height = settings.value("Height").toInt();
88  std::cerr << "Setting new viewport to " << width << "x" << height << std::endl;
89  }
90 
91  if(settings.contains("EyeX")) {
92  eye[0] = settings.value("EyeX").toDouble();
93  eye[1] = settings.value("EyeY").toDouble();
94  eye[2] = settings.value("EyeZ").toDouble();
95  std::cerr << "Setting new eye position to " << eye << std::endl;
96  e_eye = true;
97  }
98 
99  if(settings.contains("CenterX")) {
100  center[0] = settings.value("CenterX").toDouble();
101  center[1] = settings.value("CenterY").toDouble();
102  center[2] = settings.value("CenterZ").toDouble();
103  std::cerr << "Setting new scene center to " << center << std::endl;
104  e_center = true;
105  }
106 
107  if(settings.contains("UpX")) {
108  up[0] = settings.value("UpX").toDouble();
109  up[1] = settings.value("UpY").toDouble();
110  up[2] = settings.value("UpZ").toDouble();
111  std::cerr << "Setting new up vector to " << up << std::endl;
112  e_up = true;
113  }
114 
115 
116  if(settings.contains("BackgroundR")) {
117  background[0] = settings.value("BackgroundR").toDouble();
118  background[1] = settings.value("BackgroundG").toDouble();
119  background[2] = settings.value("BackgroundB").toDouble();
120  background[3] = settings.value("BackgroundA").toDouble();
121  std::cerr << "Setting new background color to " << background << std::endl;
122  e_background = true;
123  }
124 
125  settings.endGroup();
126 
127  // Now set new projection and view
128 
129  // LookAt
130  ACG::Vec3d new_eye = e_eye ? eye : PluginFunctions::eyePos();
131  ACG::Vec3d new_center = e_center ? center : PluginFunctions::sceneCenter();
132  ACG::Vec3d new_up = e_up ? up : PluginFunctions::upVector();
133 
134  PluginFunctions::lookAt(new_eye, new_center, new_up);
135 
136  // Background color
137  if(e_background) {
138  PluginFunctions::setBackColor(background);
139  }
140 
141  emit updateView();
142 
143  return 0;
144 }
145 
146 bool FileViewPlugin::saveObject(int /*_id*/, QString /*_filename*/) {
147 
148  return true;
149 }
150 
151 
152 
const ACG::Vec3d sceneCenter(int _viewer)
Get the current scene center.
ACG::Vec3d eyePos(int _viewer)
Get the current viewer position.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FileOfv.cc:65
void setBackColor(OpenMesh::Vec4f _color)
Set the background color of the examiner widget.
void initializePlugin()
Initialize Plugin.
Definition: FileOfv.cc:54
ACG::Vec3d upVector(int _viewer)
Get the current up vector.
Predefined datatypes.
Definition: DataTypes.hh:83
QString getLoadFilters()
Definition: FileOfv.cc:57
QString getSaveFilters()
Definition: FileOfv.cc:61
void lookAt(const ACG::Vec3d &_eye, const ACG::Vec3d &_center, const ACG::Vec3d &_up, int _viewer)
Set the look at transformation directly.