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