Developer Documentation

VertexSelection.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 //================================================================
51 //
52 // CLASS SplatCloudObjectSelectionPlugin - IMPLEMENTATION (continued)
53 //
54 //================================================================
55
56
57 //== INCLUDES ====================================================
58
59
60 #include "SplatCloudObjectSelectionPlugin.hh"
61 #include "SplatCloudSelection.hh"
62
63
64 //== IMPLEMENTATION ==============================================
65
66
67 //=========================================================
68 //==== Vertex selections
69 //=========================================================
70
71
72 void SplatCloudObjectSelectionPlugin::selectVertices(int _objectId, IdList _vertexList) {
73
74 if( _vertexList.empty() ) return;
75
76 BaseObjectData* object = 0;
77 if (!PluginFunctions::getObject(_objectId,object)) {
78 emit log(LOGERR,tr("selectVertices: unable to get object"));
79 return;
80 }
81
82 if (object->dataType() == DATA_SPLATCLOUD)
83 SplatCloudSelection::selectVertices(PluginFunctions::splatCloud(object), _vertexList);
84 else {
85 emit log(LOGERR,tr("selectAllVertices: Unsupported object Type"));
86 return;
87 }
88
89 QString selection = "selectVertices(ObjectId, [ " + QString::number(_vertexList[0]);
90
91 for (uint i = 1 ; i < _vertexList.size(); ++i) {
92 selection += ", " + QString::number(_vertexList[i]);
93 }
94
95 selection += " ])";
96
97 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
98 emit scriptInfo(selection);
99 }
100
101
102 //----------------------------------------------------------------
103
104
105 void SplatCloudObjectSelectionPlugin::unselectVertices(int _objectId, IdList _vertexList) {
106
107 if( _vertexList.empty() ) return;
108
109 BaseObjectData* object = 0;
110 if (!PluginFunctions::getObject(_objectId,object)) {
111 emit log(LOGERR,tr("unselectVertices: unable to get object"));
112 return;
113 }
114
115 if (object->dataType() == DATA_SPLATCLOUD)
116 SplatCloudSelection::unselectVertices(PluginFunctions::splatCloud(object), _vertexList);
117 else {
118 emit log(LOGERR,tr("unselectVertices: Unsupported object Type"));
119 return;
120 }
121
122 QString selection = "unselectVertices(ObjectId, [ " + QString::number(_vertexList[0]);
123
124 for (uint i = 1 ; i < _vertexList.size(); ++i) {
125 selection += ", " + QString::number(_vertexList[i]);
126 }
127
128 selection += " ])";
129
130 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
131 emit scriptInfo(selection);
132 }
133
134
135 //----------------------------------------------------------------
136
137
138 void SplatCloudObjectSelectionPlugin::selectAllVertices(int _objectId) {
139
140 BaseObjectData* object;
141 if (!PluginFunctions::getObject(_objectId,object)) {
142 emit log(LOGERR,tr("selectAllVertices: unable to get object"));
143 return;
144 }
145
146 if (object->dataType() == DATA_SPLATCLOUD)
147 SplatCloudSelection::selectAllVertices(PluginFunctions::splatCloud(object));
148 else {
149 emit log(LOGERR,tr("selectAllVertices: Unsupported object Type"));
150 return;
151 }
152
153 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
154 emit scriptInfo("selectAllVertices(ObjectId)");
155 }
156
157
158 //----------------------------------------------------------------
159
160
161 void SplatCloudObjectSelectionPlugin::clearVertexSelection(int _objectId) {
162
163 BaseObjectData* object;
164 if (!PluginFunctions::getObject(_objectId,object)) {
165 emit log(LOGERR,tr("clearVertexSelection: unable to get object"));
166 return;
167 }
168
169 if (object->dataType() == DATA_SPLATCLOUD)
170 SplatCloudSelection::clearVertexSelection(PluginFunctions::splatCloud(object));
171 else {
172 emit log(LOGERR,tr("clearVertexSelection: Unsupported object Type"));
173 return;
174 }
175
176 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
177 emit scriptInfo("clearVertexSelection(ObjectId)");
178 }
179
180
181 //----------------------------------------------------------------
182
183
184 void SplatCloudObjectSelectionPlugin::invertVertexSelection(int _objectId) {
185
186 BaseObjectData* object;
187 if (!PluginFunctions::getObject(_objectId,object)) {
188 emit log(LOGERR,tr("invertVertexSelection: unable to get object"));
189 return;
190 }
191
192 if (object->dataType() == DATA_SPLATCLOUD)
193 SplatCloudSelection::invertVertexSelection(PluginFunctions::splatCloud(object));
194 else {
195 emit log(LOGERR,tr("invertVertexSelection: Unsupported object Type"));
196 return;
197 }
198
199 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
200 emit scriptInfo("invertVertexSelection(ObjectId)");
201 }
202
203
204 //----------------------------------------------------------------
205
206
207 IdList SplatCloudObjectSelectionPlugin::getVertexSelection(int _objectId) {
208
209 BaseObjectData* object;
210 if (!PluginFunctions::getObject(_objectId,object)) {
211 emit log(LOGERR,tr("getVertexSelection: unable to get object"));
212 return IdList(0);
213 }
214
215 emit scriptInfo("getVertexSelection(ObjectId)");
216
217 if (object->dataType() == DATA_SPLATCLOUD)
218 return SplatCloudSelection::getVertexSelection(PluginFunctions::splatCloud(object));
219 else {
220 emit log(LOGERR,tr("getVertexSelection: Unsupported object Type"));
221 return IdList(0);
222 }
223
224 return IdList(0);
225 }
226
227
228 //----------------------------------------------------------------
229
230
231 void SplatCloudObjectSelectionPlugin::deleteVertexSelection(int _objectId) {
232
233 BaseObjectData* object;
234 if (!PluginFunctions::getObject(_objectId,object)) {
235 emit log(LOGERR,tr("deleteVertexSelection: unable to get object"));
236 return;
237 }
238
239 if (object->dataType() == DATA_SPLATCLOUD)
240 splatCloudDeleteSelection(PluginFunctions::splatCloud(object), vertexType_);
241 else {
242 emit log(LOGERR,tr("deleteVertexSelection: Unsupported object Type"));
243 return;
244 }
245
246 emit updatedObject(object->id(), UPDATE_ALL);
247 emit scriptInfo("deleteVertexSelection(ObjectId)");
248 }
249
250
251 //----------------------------------------------------------------
252
253
254 void SplatCloudObjectSelectionPlugin::colorizeVertexSelection(int _objectId, int r, int g, int b, int a) {
255
256 BaseObjectData* object;
257 if (!PluginFunctions::getObject(_objectId, object)) {
258 emit log(LOGERR,"colorizeVertexSelection: unable to get object");
259 return;
260 }
261
262 if (object->dataType() == DATA_SPLATCLOUD) {
263 splatCloudColorizeSelection(PluginFunctions::splatCloud(object), vertexType_, r, g, b, a);
264 } else {
265 emit log(LOGERR,"colorizeVertexSelection: Unsupported object Type");
266 return;
267 }
268
269 emit scriptInfo("colorizeVertexSelection(ObjectId, "
270 + QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + ")");
271
272 emit updatedObject(_objectId, UPDATE_COLOR);
273 }
LOGERR
Definition: LoggingInterface.hh:96
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
UPDATE_SELECTION_VERTICES
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
SplatCloudObjectSelectionPlugin::vertexType_
SelectionInterface::PrimitiveType vertexType_
Primitive type handle.
Definition: SplatCloudObjectSelectionPlugin.hh:260
SplatCloudObjectSelectionPlugin::splatCloudColorizeSelection
void splatCloudColorizeSelection(SplatCloud *_splatCloud, PrimitiveType _primitiveTypes, int _r, int _g, int _b, int _a)
Colorize the selection.
Definition: SplatCloudObjectSelectionPlugin2.cc:272
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
DATA_SPLATCLOUD
#define DATA_SPLATCLOUD
Definition: SplatCloud.hh:59
SplatCloudObjectSelectionPlugin::deleteVertexSelection
void deleteVertexSelection(int _objectId)
Delete vertices that are currently selected.
Definition: VertexSelection.cc:231
SplatCloudObjectSelectionPlugin::colorizeVertexSelection
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int _a)
Colorize the vertex selection.
Definition: VertexSelection.cc:254
SplatCloudObjectSelectionPlugin::selectAllVertices
void selectAllVertices(int _objectId)
Select all vertices.
Definition: VertexSelection.cc:138
BaseObject::id
int id() const
Definition: BaseObject.cc:190
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
IdList
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:179
SplatCloudObjectSelectionPlugin::invertVertexSelection
void invertVertexSelection(int _objectId)
Invert the current vertex selection.
Definition: VertexSelection.cc:184
SplatCloudObjectSelectionPlugin::getVertexSelection
IdList getVertexSelection(int _objectId)
Return a list of all selected vertices.
Definition: VertexSelection.cc:207
PluginFunctions::splatCloud
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
Definition: PluginFunctionsSplatCloud.cc:136
BaseObjectData
Definition: BaseObjectData.hh:102
SplatCloudObjectSelectionPlugin::selectVertices
void selectVertices(int _objectId, IdList _vertexList)
Select given vertices.
Definition: VertexSelection.cc:72
SplatCloudObjectSelectionPlugin::splatCloudDeleteSelection
bool splatCloudDeleteSelection(SplatCloud *_splatCloud, PrimitiveType _primitiveType)
Delete all selected elements of a SplatCloud.
Definition: SplatCloudObjectSelectionPlugin2.cc:74
SplatCloudObjectSelectionPlugin::unselectVertices
void unselectVertices(int _objectId, IdList _vertexList)
Unselect given vertices.
Definition: VertexSelection.cc:105
SplatCloudObjectSelectionPlugin::clearVertexSelection
void clearVertexSelection(int _objectId)
Unselect all vertices.
Definition: VertexSelection.cc:161
SplatCloudSelection.hh
Functions for selection on a SplatCloud.
UPDATE_COLOR
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.