Developer Documentation
FaceSelection.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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 #include "MeshObjectSelectionPlugin.hh"
51 
53 
54 //=========================================================
55 //==== Face selections
56 //=========================================================
57 
58 void MeshObjectSelectionPlugin::selectFaces(int objectId , IdList _faceList) {
59 
60  if(_faceList.empty() ) return;
61 
62  BaseObjectData* object = 0;
63  if (! PluginFunctions::getObject(objectId,object)) {
64  emit log(LOGERR,tr("selectFaces : unable to get object"));
65  return;
66  }
67 
68  if (object->dataType() == DATA_TRIANGLE_MESH)
69  MeshSelection::selectFaces(PluginFunctions::triMesh(object), _faceList);
70  else if (object->dataType() == DATA_POLY_MESH)
71  MeshSelection::selectFaces(PluginFunctions::polyMesh(object), _faceList);
72  else {
73  emit log(LOGERR,tr("selectFaces : Unsupported object Type"));
74  return;
75  }
76 
77  QString selection = "selectFaces(ObjectId(" + QString::number(objectId) + ") , [ " + QString::number(_faceList[0]);
78 
79  for (uint i = 1 ; i < _faceList.size(); ++i) {
80  selection += " , " + QString::number(_faceList[i]);
81  }
82 
83  selection += " ])";
84 
85  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
86  emit scriptInfo(selection);
87 }
88 
89 //=========================================================
90 
91 bool MeshObjectSelectionPlugin::selectFace(int _objectId, int _idx, bool _fly_to_face)
92 {
93  return selectElement(_objectId, OpenMesh::FaceHandle(_idx), _fly_to_face);
94 }
95 
96 //=========================================================
97 
98 void MeshObjectSelectionPlugin::unselectFaces(int objectId , IdList _faceList) {
99 
100  if(_faceList.empty() ) return;
101 
102  BaseObjectData* object = 0;
103  if (! PluginFunctions::getObject(objectId,object)) {
104  emit log(LOGERR,tr("unselectFaces : unable to get object"));
105  return;
106  }
107 
108  if (object->dataType() == DATA_TRIANGLE_MESH)
109  MeshSelection::unselectFaces(PluginFunctions::triMesh(object), _faceList);
110  else if (object->dataType() == DATA_POLY_MESH)
111  MeshSelection::unselectFaces(PluginFunctions::polyMesh(object), _faceList);
112  else {
113  emit log(LOGERR,tr("unselectFaces : Unsupported object Type"));
114  return;
115  }
116 
117  QString selection = "unselectFaces(ObjectId(" + QString::number(objectId) + ") , [ " + QString::number(_faceList[0]);
118 
119  for (uint i = 1 ; i < _faceList.size(); ++i) {
120  selection += " , " + QString::number(_faceList[i]);
121  }
122 
123  selection += " ])";
124 
125  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
126  emit scriptInfo(selection);
127 }
128 
129 //=========================================================
130 
132 
133  BaseObjectData* object;
134  if (! PluginFunctions::getObject(objectId,object)) {
135  emit log(LOGERR,tr("selectAllFaces : unable to get object"));
136  return;
137  }
138 
139  if (object->dataType() == DATA_TRIANGLE_MESH)
140  MeshSelection::selectAllFaces(PluginFunctions::triMesh(object));
141  else if (object->dataType() == DATA_POLY_MESH)
142  MeshSelection::selectAllFaces(PluginFunctions::polyMesh(object));
143  else {
144  emit log(LOGERR,tr("selectAllFaces : Unsupported object Type"));
145  return;
146  }
147 
148  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
149  emit scriptInfo("selectAllFaces(ObjectId(" + QString::number(objectId) + "))");
150 }
151 
152 //=========================================================
153 
155 
156  BaseObjectData* object;
157  if (! PluginFunctions::getObject(objectId,object)) {
158  emit log(LOGERR,tr("clearFaceSelection : unable to get object"));
159  return;
160  }
161 
162  if (object->dataType() == DATA_TRIANGLE_MESH)
163  MeshSelection::clearFaceSelection(PluginFunctions::triMesh(object));
164  else if (object->dataType() == DATA_POLY_MESH)
165  MeshSelection::clearFaceSelection(PluginFunctions::polyMesh(object));
166  else {
167  emit log(LOGERR,tr("clearFaceSelection : Unsupported object Type"));
168  return;
169  }
170 
171  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
172  emit scriptInfo("clearFaceSelection(ObjectId(" + QString::number(objectId) + "))");
173 }
174 
175 //=========================================================
176 
178 
179  BaseObjectData* object;
180  if (! PluginFunctions::getObject(objectId,object)) {
181  emit log(LOGERR,tr("invertFaceSelection : unable to get object"));
182  return;
183  }
184 
185  if (object->dataType() == DATA_TRIANGLE_MESH)
186  MeshSelection::invertFaceSelection(PluginFunctions::triMesh(object));
187  else if (object->dataType() == DATA_POLY_MESH)
188  MeshSelection::invertFaceSelection(PluginFunctions::polyMesh(object));
189  else {
190  emit log(LOGERR,tr("invertFaceSelection : Unsupported object Type"));
191  return;
192  }
193 
194  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
195  emit scriptInfo("invertFaceSelection(ObjectId(" + QString::number(objectId) + "))");
196 }
197 
198 //=========================================================
199 
201 
202  BaseObjectData* object = 0;
203  if (!PluginFunctions::getObject(_objectId,object)) {
204  emit log(LOGERR,tr("deleteFaceSelection: unable to get object"));
205  return;
206  }
207 
208  if (object->dataType() == DATA_TRIANGLE_MESH)
210  else if (object->dataType() == DATA_POLY_MESH)
212  else {
213  emit log(LOGERR,tr("deleteFaceSelection: Unsupported object Type"));
214  return;
215  }
216 
217  emit updatedObject(object->id(), UPDATE_ALL);
218  emit scriptInfo("deleteFaceSelection(ObjectId(" + QString::number(_objectId) + "))");
219 }
220 
221 //=========================================================
222 
224  return createMeshFromSelection(_objectId, faceType_ );
225 }
226 
227 //=========================================================
228 
230 
231  BaseObjectData* object;
232  if (! PluginFunctions::getObject(objectId,object)) {
233  emit log(LOGERR,tr("selectBoundaryFaces : unable to get object"));
234  return;
235  }
236 
237  if (object->dataType() == DATA_TRIANGLE_MESH)
238  MeshSelection::selectBoundaryFaces(PluginFunctions::triMesh(object));
239  else if (object->dataType() == DATA_POLY_MESH)
240  MeshSelection::selectBoundaryFaces(PluginFunctions::polyMesh(object));
241  else {
242  emit log(LOGERR,tr("selectBoundaryFaces : Unsupported object Type"));
243  return;
244  }
245 
246  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
247  emit scriptInfo("selectBoundaryFaces(ObjectId(" + QString::number(objectId) + "))");
248 }
249 
250 
251 //=========================================================
252 
254 
255  BaseObjectData* object;
256  if (! PluginFunctions::getObject(objectId,object)) {
257  emit log(LOGERR,tr("shrinkFaceSelection : unable to get object"));
258  return;
259  }
260 
261  if (object->dataType() == DATA_TRIANGLE_MESH)
262  MeshSelection::shrinkFaceSelection(PluginFunctions::triMesh(object));
263  else if (object->dataType() == DATA_POLY_MESH)
264  MeshSelection::shrinkFaceSelection(PluginFunctions::polyMesh(object));
265  else {
266  emit log(LOGERR,tr("shrinkFaceSelection : Unsupported object Type"));
267  return;
268  }
269 
270  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
271  emit scriptInfo("shrinkFaceSelection(ObjectId(" + QString::number(objectId) + "))");
272 }
273 
274 //=========================================================
275 
277 
278  BaseObjectData* object;
279  if (! PluginFunctions::getObject(objectId,object)) {
280  emit log(LOGERR,tr("growFaceSelection : unable to get object"));
281  return;
282  }
283 
284  if (object->dataType() == DATA_TRIANGLE_MESH)
285  MeshSelection::growFaceSelection(PluginFunctions::triMesh(object));
286  else if (object->dataType() == DATA_POLY_MESH)
287  MeshSelection::growFaceSelection(PluginFunctions::polyMesh(object));
288  else {
289  emit log(LOGERR,tr("growFaceSelection : Unsupported object Type"));
290  return;
291  }
292 
293  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
294  emit scriptInfo("growFaceSelection(ObjectId(" + QString::number(objectId) + "))");
295 }
296 
297 //=========================================================
298 
300 
301  BaseObjectData* object;
302  if (! PluginFunctions::getObject(objectId,object)) {
303  emit log(LOGERR,tr("getFaceSelection : unable to get object"));
304  return IdList(0);
305  }
306 
307  emit scriptInfo("getFaceSelection(ObjectId(" + QString::number(objectId) + "))");
308 
309  if (object->dataType() == DATA_TRIANGLE_MESH)
310  return MeshSelection::getFaceSelection(PluginFunctions::triMesh(object));
311  else if (object->dataType() == DATA_POLY_MESH)
312  return MeshSelection::getFaceSelection(PluginFunctions::polyMesh(object));
313  else {
314  emit log(LOGERR,tr("getFaceSelection : Unsupported object Type"));
315  return IdList(0);
316  }
317 }
318 
319 //=========================================================
320 
322 void MeshObjectSelectionPlugin::colorizeFaceSelection(int objectId, int r, int g, int b, int a) {
323 
324  BaseObjectData* object;
325  if (! PluginFunctions::getObject(objectId,object)) {
326  emit log(LOGERR,"colorizeFaceSelection : unable to get object");
327  return;
328  }
329 
330  if (object->dataType() == DATA_TRIANGLE_MESH) {
332  } else if (object->dataType() == DATA_POLY_MESH) {
334  } else {
335  emit log(LOGERR,"colorizeFaceSelection : Unsupported object Type");
336  return;
337  }
338 
339 
340  emit scriptInfo("colorizeFaceSelection(ObjectId(" + QString::number(objectId) + "), "
341  + QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + ")");
342 
343  emit updatedObject(objectId, UPDATE_COLOR);
344 }
void selectBoundaryFaces(int objectId)
Select all boundary faces of the given object.
Handle for a face entity.
Definition: Handles.hh:141
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
void unselectFaces(int objectId, IdList _facesList)
Unselect given faces.
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
void invertFaceSelection(int objectId)
Invert the current face selection.
void growFaceSelection(int objectId)
Grow the current face selection.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
bool deleteSelection(MeshT *_mesh, PrimitiveType _primitiveType)
Delete all selected elements of a mesh.
bool selectFace(int _objectId, int _idx, bool _fly_to_face)
Select face with id _idx and maybe fly to it.
int id() const
Definition: BaseObject.cc:190
SelectionInterface::PrimitiveType faceType_
Handle to selection environment.
void deleteFaceSelection(int _objectId)
Delete face that are currently selected.
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:179
const UpdateType UPDATE_SELECTION_FACES(UpdateTypeSet(1)<< 8)
Face selection has changed.
Functions for selection on a mesh.
IdList getFaceSelection(int objectId)
Return a list of all selected faces.
void createMeshFromSelection(MeshT &_mesh, MeshT &_newMesh, PrimitiveType _primitiveType)
Create a new mesh from the selection.
void colorizeSelection(MeshT *_mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha)
Colorize the selection.
void selectFaces(int objectId, IdList _facesList)
Select given faces.
bool selectElement(int _objectId, HandleT _handle, bool _fly_to_element)
set dihedral angle threshold for edge selection
void shrinkFaceSelection(int objectId)
Shrink the current face selection.
int createMeshFromFaceSelection(int _objectId)
Create a mesh containing the face selection of the given mesh.
void selectAllFaces(int objectId)
Select all faces.
void clearFaceSelection(int objectId)
Unselect all faces.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
void colorizeFaceSelection(int objectId, int r, int g, int b, int a)
Colorize the face selection.