Developer Documentation
MeshConvert.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
44
45
46#include "MeshConvert.hh"
52#include <OpenFlipper/libs_required/OpenMesh/src/OpenMesh/Core/Mesh/Casts.hh>
53
54#include <QActionGroup>
55#include <QAction>
56
57
59{
60
61}
62
63
64void MeshConvertPlugin::pluginsInitialized()
65{
66 //populate scripting function
67 emit setSlotDescription("convert(int,bool)", "Convert a mesh to PolyMesh or to TriMesh. returns the ID of the new mesh or -1 in case of error. The old mesh remains unchanged.",
68 QString("object_id,toTriMesh").split(","),
69 QString(" id of an object to convert, flag to convert to a TriMesh, if not set creates a new PolyMesh").split(","));
70
71 if(! OpenFlipper::Options::gui())
72 return;
73
74 // Create your toolbar
75 toolbar = new QToolBar(tr("Mesh conversion"));
76
77 grp = new QActionGroup(toolbar);
78
79 // Create an action for the toolbar
80 bidirectionalConversion = new QAction(tr("&Convert Meshes"), grp);
81 polyConversion = new QAction(tr("&Convert to PolyMesh"), grp);
82 triConversion = new QAction(tr("&Convert to TriMesh"), grp);
83
84 // Create an icon which is shown for the action
85 bidirectionalConversion->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"Mesh-Convert.png"));
86 polyConversion->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"Mesh-Convert-Poly.png"));
87 triConversion->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"Mesh-Convert-Tri.png"));
88
89 // Add the action to the toolbar
90 toolbar->addAction(bidirectionalConversion);
91 toolbar->addAction(polyConversion);
92 toolbar->addAction(triConversion);
93
94
95
96 connect( grp, SIGNAL( triggered(QAction*) ), this, SLOT(convert(QAction*)) );
97
98 // Integrate the new toolbar into OpenFlipper
99 emit addToolbar( toolbar );
100
101
102
103}
104
105MeshConvertPlugin::MeshConvertPlugin() :
106 toolbar(nullptr),
107 grp(nullptr),
108 bidirectionalConversion(nullptr),
109 polyConversion(nullptr),
110 triConversion(nullptr)
111{
112
113}
114
115MeshConvertPlugin::~MeshConvertPlugin()
116{
117
118}
119
120int MeshConvertPlugin::convert(int _id, bool _toTriMesh)
121{
122 int newID = -1;
123 PolyMesh* p;
124 TriMesh* t;
125 if(_toTriMesh && PluginFunctions::getMesh(_id,p))
126 {
127 TriMesh converted = static_cast<TriMesh>(*p);
128 emit addEmptyObject(DATA_TRIANGLE_MESH, newID);
129 if(PluginFunctions::getMesh(newID,t))
130 {
131 *t = converted;
132 emit updatedObject(newID,UPDATE_ALL);
133 }
134 }
135 else
136 {
137 if(!_toTriMesh && PluginFunctions::getMesh(_id,t))
138 {
139 PolyMesh converted = static_cast<PolyMesh>(*t);
140 emit addEmptyObject(DATA_POLY_MESH, newID);
141 if(PluginFunctions::getMesh(newID,p))
142 {
143 *p = converted;
144 emit updatedObject(newID,UPDATE_ALL);
145 }
146 }
147 }
148 return newID;
149}
150
151void MeshConvertPlugin::convert(QAction* _action)
152{
153 std::vector<int> _ids;
155 return;
156 for(std::vector<int>::iterator id = _ids.begin(); id != _ids.end(); ++id)
157 {
158 if((_action == bidirectionalConversion || _action == polyConversion))
159 {
160 convert(*id,false);
161 }
162 if((_action == bidirectionalConversion || _action == triConversion))
163 {
164 convert(*id,true);
165 }
166 }
167}
168
169
170
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
void initializePlugin()
BaseInterface.
Definition: MeshConvert.cc:58
void convert(QAction *)
convert Converts trimesh to poly and vice versa depending on the Action that was called.
Definition: MeshConvert.cc:151
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
bool getTargetIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a target object.