Developer Documentation
VolumeMeshConvert.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 "VolumeMeshConvert.hh"
52#include <QAction>
53#include <QActionGroup>
54
56{
57
58}
59
60
61void VolumeMeshConvertPlugin::pluginsInitialized()
62{
63 //populate scripting function
64 emit setSlotDescription("convertToHexMesh(int)",
65 "Convert a polyhedral Mesh to a hexahedral mesh."
66 " Does not check if input mesh actually has the right topology."
67 " Return the ID of the new mesh or -1 in case of error."
68 " The old mesh remains unchanged.",
69 QStringList("object_id"),
70 QStringList("id of an the input object"));
71 emit setSlotDescription("convertToTetMesh(int)",
72 "Convert a polyhedral Mesh to a tetrahedral mesh."
73 " Does not check if input mesh actually has the right topology."
74 " Return the ID of the new mesh or -1 in case of error."
75 " The old mesh remains unchanged.",
76 QStringList("object_id"),
77 QStringList("id of an the input object"));
78 emit setSlotDescription("convertToPolyhedralMesh(int)",
79 "Convert a hex or tet mesh to a PolyhedralMesh."
80 " Return the ID of the new mesh or -1 in case of error."
81 " The old mesh remains unchanged.",
82 QStringList("object_id"),
83 QStringList("id of an the input object"));
84
85 if(! OpenFlipper::Options::gui())
86 return;
87
88 // Create your toolbar
89 toolbar_ = new QToolBar(tr("Volume Mesh conversion"));
90
91 grp_ = new QActionGroup(toolbar_);
92
93 // Create an action for the toolbar
94 actionToHex_ = new QAction(tr("&Convert Polyhedral to Hexahedral mesh"), grp_);
95 actionToTet_ = new QAction(tr("&Convert Polyhedral to Tetrahedral mesh"), grp_);
96 actionToPoly_ = new QAction(tr("&Convert Tet or Hex mesh to Polyhedral mesh"), grp_);
97
98 // Create an icon which is shown for the action
99 // TODO
100 actionToHex_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"VolumeConvertToHex.png"));
101 actionToTet_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"VolumeConvertToTet.png"));
102 actionToPoly_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"VolumeConvertToPoly.png"));
103
104 // Add the action to the toolbar
105 toolbar_->addAction(actionToHex_);
106 toolbar_->addAction(actionToTet_);
107 toolbar_->addAction(actionToPoly_);
108
109 connect( grp_, SIGNAL( triggered(QAction*) ), this, SLOT(handleQAction(QAction*)) );
110
111 // Integrate the new toolbar into OpenFlipper
112 emit addToolbar( toolbar_ );
113}
114
116{
117 std::vector<int> _ids;
119 return;
120 for(const auto id: _ids)
121 {
122 int out_id = -1;
123 if (_action == actionToHex_)
124 out_id = convertToHexMesh(id);
125 else if (_action == actionToPoly_)
126 out_id = convertToPolyhedralMesh(id);
127 else if (_action == actionToTet_)
128 out_id = convertToTetMesh(id);
129 else {
130 assert(false);
131 }
132 if (out_id == -1) {
133 emit log(LOGERR, "VolumeMeshConvert: failed to convert object " + QString::number(id));
134 } else {
135 emit log(LOGINFO, "VolumeMeshConvert: successfully converted object"
136 + QString::number(id) + " to new object " + QString::number(out_id));
137 }
138 }
139}
140
141int VolumeMeshConvertPlugin::convertToHexMesh(int _id)
142{
144 if (!pmo)
145 return -1;
146
147 // TODO: here we should check that all cells are actually hexahedral
148
149 int newID = -1;
150 emit addEmptyObject(DATA_HEXAHEDRAL_MESH, newID);
152
153 *hmo->mesh() = *pmo->mesh();
154
155 hmo->setName("Tet conv. of " + pmo->name());
156
157 emit updatedObject(newID, UPDATE_ALL);
158 return newID;
159}
160
161int VolumeMeshConvertPlugin::convertToTetMesh(int _id)
162{
164 if (!pmo)
165 return -1;
166
167 // TODO: here we should check that all cells are actually tetrahedral
168
169 int newID = -1;
170 emit addEmptyObject(DATA_TETRAHEDRAL_MESH, newID);
172
173 // TetMesh have their own TetrahedralGeometryKernel, which only adds
174 // functionality, but should not influence assignment.
175 // Downcast it to a GeometryKernel<Vec, TetTopoKernel>:
176 auto *tm = static_cast<TetrahedralMesh::ParentT*>(tmo->mesh());
177
178 *tm = *pmo->mesh();
179
180 tmo->setName("Hex conv. of " + pmo->name());
181
182 emit updatedObject(newID, UPDATE_ALL);
183 return newID;
184}
185
186int VolumeMeshConvertPlugin::convertToPolyhedralMesh(int _id)
187{
190 if (!hmo && !tmo) {
191 return -1;
192 }
193 int newID = -1;
194 emit addEmptyObject(DATA_POLYHEDRAL_MESH, newID);
196 if (hmo) {
197 *pmo->mesh() = *hmo->mesh();
198 pmo->setName("Polyhedral conv. of " + hmo->name());
199 } else if (tmo) {
200 auto *tm = static_cast<TetrahedralMesh::ParentT*>(tmo->mesh());
201 *pmo->mesh() = *tm;
202 pmo->setName("Polyhedral conv. of " + tmo->name());
203 }
204
205 emit updatedObject(newID, UPDATE_ALL);
206
207 return newID;
208}
@ LOGERR
@ LOGINFO
#define DATA_HEXAHEDRAL_MESH
#define DATA_POLYHEDRAL_MESH
#define DATA_TETRAHEDRAL_MESH
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:728
void handleQAction(QAction *)
convert Converts polyhedralmesh to hex/tet mesh and vice versa depending on the Action that was calle...
void initializePlugin() override
BaseInterface.
MeshT * mesh()
return a pointer to the mesh
void setName(QString _name)
Set the name of the Object.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
HexahedralMeshObject * hexahedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an HexahedralMeshObject if possible.
TetrahedralMeshObject * tetrahedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an TetrahedralMeshObject if possible.
bool getTargetIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a target object.