Developer Documentation

VolumeMeshObjectInfoScripting.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 #include "VolumeMeshObjectInfoPlugin.hh"
44
45 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
46
47 #include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
48 #include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
49
50 //------------------------------------------------------------------------------
51
55 void InfoVolumeMeshObjectPlugin::setDescriptions(){
56
57 emit setSlotDescription("vertexCount(int)",tr("get total number of vertices for a given object"),
58 QStringList(tr("objectID")), QStringList(tr("id of an object")));
59
60 emit setSlotDescription("edgeCount(int)",tr("get total number of edges for a given object"),
61 QStringList(tr("objectID")), QStringList(tr("id of an object")));
62
63 emit setSlotDescription("faceCount(int)",tr("get total number of faces for a given object"),
64 QStringList(tr("objectID")), QStringList(tr("id of an object")));
65
66 emit setSlotDescription("cellCount(int)",tr("get total number of cells for a given object"),
67 QStringList(tr("objectID")), QStringList(tr("id of an object")));
68 }
69
70
71 //------------------------------------------------------------------------------
72
78 int InfoVolumeMeshObjectPlugin::vertexCount(int _id)
79 {
80
81 BaseObjectData* object;
82 if ( ! PluginFunctions::getObject(_id,object) )
83 return -1;
84
85 if ( object == 0){
86 emit log(LOGERR, tr("Unable to get object"));
87 return -1;
88 }
89
90 if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
91 HexahedralMesh* mesh = PluginFunctions::hexahedralMesh(object);
92
93 if ( mesh == 0 ) {
94 emit log(LOGERR, tr("Unable to get mesh"));
95 return -1;
96 }
97
98 return mesh->n_vertices();
99
100 } else {
101 PolyhedralMesh* mesh = PluginFunctions::polyhedralMesh(object);
102
103 if ( mesh == 0 ) {
104 emit log(LOGERR, tr("Unable to get mesh"));
105 return -1;
106 }
107
108 return mesh->n_vertices();
109 }
110 }
111
112
113 //------------------------------------------------------------------------------
114
120 int InfoVolumeMeshObjectPlugin::edgeCount(int _id)
121 {
122
123 BaseObjectData* object;
124 if ( ! PluginFunctions::getObject(_id,object) )
125 return -1;
126
127 if ( object == 0){
128 emit log(LOGERR, tr("Unable to get object"));
129 return -1;
130 }
131
132 if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
133 HexahedralMesh* mesh = PluginFunctions::hexahedralMesh(object);
134
135 if ( mesh == 0 ) {
136 emit log(LOGERR, tr("Unable to get mesh"));
137 return -1;
138 }
139
140 return mesh->n_edges();
141
142 } else {
143 PolyhedralMesh* mesh = PluginFunctions::polyhedralMesh(object);
144
145 if ( mesh == 0 ) {
146 emit log(LOGERR, tr("Unable to get mesh"));
147 return -1;
148 }
149
150 return mesh->n_edges();
151 }
152 }
153
154
155 //------------------------------------------------------------------------------
156
162 int InfoVolumeMeshObjectPlugin::faceCount(int _id)
163 {
164
165 BaseObjectData* object;
166 if ( ! PluginFunctions::getObject(_id,object) )
167 return -1;
168
169 if ( object == 0){
170 emit log(LOGERR, tr("Unable to get object"));
171 return -1;
172 }
173
174 if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
175 HexahedralMesh* mesh = PluginFunctions::hexahedralMesh(object);
176
177 if ( mesh == 0 ) {
178 emit log(LOGERR, tr("Unable to get mesh"));
179 return -1;
180 }
181
182 return mesh->n_faces();
183
184 } else {
185 PolyhedralMesh* mesh = PluginFunctions::polyhedralMesh(object);
186
187 if ( mesh == 0 ) {
188 emit log(LOGERR, tr("Unable to get mesh"));
189 return -1;
190 }
191
192 return mesh->n_faces();
193 }
194 }
195
196
197 //------------------------------------------------------------------------------
198
204 int InfoVolumeMeshObjectPlugin::cellCount(int _id)
205 {
206
207 BaseObjectData* object;
208 if ( ! PluginFunctions::getObject(_id,object) )
209 return -1;
210
211 if ( object == 0){
212 emit log(LOGERR, tr("Unable to get object"));
213 return -1;
214 }
215
216 if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
217 HexahedralMesh* mesh = PluginFunctions::hexahedralMesh(object);
218
219 if ( mesh == 0 ) {
220 emit log(LOGERR, tr("Unable to get mesh"));
221 return -1;
222 }
223
224 return mesh->n_faces();
225
226 } else {
227 PolyhedralMesh* mesh = PluginFunctions::polyhedralMesh(object);
228
229 if ( mesh == 0 ) {
230 emit log(LOGERR, tr("Unable to get mesh"));
231 return -1;
232 }
233
234 return mesh->n_cells();
235 }
236 }
237
238 //------------------------------------------------------------------------------
239
240
PolyhedralMesh.hh
InfoVolumeMeshObjectPlugin::setDescriptions
void setDescriptions()
set scripting slot descriptions
Definition: VolumeMeshObjectInfoScripting.cc:55
HexahedralMesh.hh
PluginFunctions.hh
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
OpenVolumeMesh::GeometryKernel
Definition: GeometryKernel.hh:55
LOGERR
Definition: LoggingInterface.hh:96
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:294
PluginFunctions::polyhedralMesh
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.
Definition: PluginFunctionsPolyhedralMesh.cc:115
PluginFunctions::hexahedralMesh
HexahedralMesh * hexahedralMesh(BaseObjectData *_object)
Get an HexahedralMesh from an object.
Definition: PluginFunctionsHexahedralMesh.cc:114
InfoVolumeMeshObjectPlugin::faceCount
int faceCount(int _id)
get total number of faces for a given object
Definition: VolumeMeshObjectInfoScripting.cc:162
DATA_HEXAHEDRAL_MESH
#define DATA_HEXAHEDRAL_MESH
Definition: HexahedralMesh.hh:56
InfoVolumeMeshObjectPlugin::vertexCount
int vertexCount(int _id)
get total number of vertices for a given object
Definition: VolumeMeshObjectInfoScripting.cc:78
InfoVolumeMeshObjectPlugin::edgeCount
int edgeCount(int _id)
get total number of edges for a given object
Definition: VolumeMeshObjectInfoScripting.cc:120
BaseObjectData
Definition: BaseObjectData.hh:102
InfoVolumeMeshObjectPlugin::cellCount
int cellCount(int _id)
get total number of cells for a given object
Definition: VolumeMeshObjectInfoScripting.cc:204