Developer Documentation
MovePluginScript.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 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #include "MovePlugin.hh"
51 
52 #ifdef ENABLE_POLYLINE_SUPPORT
54 #endif
55 #ifdef ENABLE_TSPLINEMESH_SUPPORT
56 #include <ObjectTypes/TSplineMesh/TSplineMesh.hh>
57 #endif
59 
60 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
62 #endif
63 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
65 #endif
66 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
68 #endif
69 
74 
75  emit setSlotDescription("translate(int,Vector)",tr("Translate object by given vector."),
76  QString(tr("objectId,Vector")).split(","), QString(tr("ID of an object, translation vector")).split(","));
77 
78  emit setSlotDescription("translate(int,idList,Vector)",tr("Translate vertices by given vector."),
79  QString(tr("objectId,VertexHandles,Vector")).split(","),
80  QString(tr("ID of an object, List of vertex handles, translation vector")).split(","));
81 
82  emit setSlotDescription("translateVertexSelection(int,Vector)",tr("Translate current vertex selection of an object by given vector."),
83  QString(tr("objectId,Vector")).split(","), QString(tr("ID of an object, translation vector")).split(","));
84 
85  emit setSlotDescription("translateFaceSelection(int,Vector)",tr("Translate current face selection of an object by given vector."),
86  QString(tr("objectId,Vector")).split(","), QString(tr("ID of an object, translation vector")).split(","));
87 
88  emit setSlotDescription("translateEdgeSelection(int,Vector)",tr("Translate current edge selection of an object by given vector."),
89  QString(tr("objectId,Vector")).split(","), QString(tr("ID of an object, translation vector")).split(","));
90 
91  emit setSlotDescription("transformHandleRegion(int,Matrix4x4)",tr("Transform handle region using the specified matrix."),
92  QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));
93 
94  emit setSlotDescription("transform(int,Matrix4x4)",tr("transform object by given matrix."),
95  QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));
96 
97  emit setSlotDescription("transform(int,IdList,Matrix4x4)",tr("transform vertices by given matrix."),
98  QString(tr("objectId,VertexHandles,Matrix")).split(","),
99  QString(tr("ID of an object, List of vertex handles, transformation matrix")).split(","));
100 
101  emit setSlotDescription("transformSelection(int,Matrix4x4)",tr("transform current selection of an object by given matrix."),
102  QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));
103 
104  emit setSlotDescription("transformCellSelection(int,Matrix4x4)",tr("transform selected cells by given matrix."),
105  QString(tr("objectId,Matrix")).split(","),
106  QString(tr("ID of an object, transformation matrix")).split(","));
107 
108  emit setSlotDescription("transformVertexSelection(int,Matrix4x4)",tr("transform selected vertices by given matrix."),
109  QString(tr("objectId,Matrix")).split(","),
110  QString(tr("ID of an object, transformation matrix")).split(","));
111 
112  emit setSlotDescription("transformFaceSelection(int,Matrix4x4)",tr("transform selected faces by given matrix."),
113  QString(tr("objectId,Matrix")).split(","),
114  QString(tr("ID of an object, transformation matrix")).split(","));
115 
116  emit setSlotDescription("transformEdgeSelection(int,Matrix4x4)",tr("transform selected edges by given matrix."),
117  QString(tr("objectId,Matrix")).split(","),
118  QString(tr("ID of an object, transformation matrix")).split(","));
119 
120  emit setSlotDescription("setManipulatorPosition(int,Vector)",tr("Set the position of the manipulator."),
121  QString(tr("objectId,Position")).split(","), QString(tr("ID of an object, 3D point")).split(","));
122 
123  emit setSlotDescription("setManipulatorDirection(int,Vector, Vector)",tr("Set the direction of the manipulator."),
124  QString(tr("objectId,Direction, Direction")).split(","), QString(tr("ID of an object, x-direction, y-direction")).split(","));
125 
126  emit setSlotDescription("manipulatorPosition(int)",tr("Returns the position of an object's manipulator."),
127  QStringList(tr("objectId")), QStringList(tr("ID of an object")));
128 
129  emit setSlotDescription("manipulatorDirectionX(int)",tr("Returns the x-direction of an object's manipulator."),
130  QStringList(tr("objectId")), QStringList(tr("ID of an object")));
131 
132  emit setSlotDescription("manipulatorDirectionY(int)",tr("Returns the y-direction of an object's manipulator."),
133  QStringList(tr("objectId")), QStringList(tr("ID of an object")));
134 
135  emit setSlotDescription("manipulatorDirectionZ(int)",tr("Returns the z-direction of an object's manipulator."),
136  QStringList(tr("objectId")), QStringList(tr("ID of an object")));
137 
138 
139  emit setSlotDescription("objectRenderingMatrixIdentity(int)",tr("Resets the objects rendering matrix to identity."),
140  QStringList(tr("objectId")), QStringList(tr("ID of an object")));
141 
142 
143  emit setSlotDescription("objectRenderingMatrixScale(int,double)",tr("Adds a scaling factor to the Object rendering Matrix in the scenegraph."),
144  QStringList(tr("objectId;Scaling Factor").split(";")), QStringList(tr("ID of an object; Scaling factor").split(";")));
145 
146  emit setSlotDescription("objectRenderingMatrixTranslate(int,Vector)",tr("Adds a translation to the Object rendering Matrix in the scenegraph."),
147  QStringList(tr("objectId;translation vector").split(";")), QStringList(tr("ID of an object;Translation vector").split(";")));
148 
149  emit setSlotDescription("objectRenderingMatrixRotate(int,Vector,double)",tr("Adds a Rotation to the Object rendering Matrix in the scenegraph."),
150  QStringList(tr("objectId;rotation axis;angle").split(";")), QStringList(tr("ID of an object;Rotation axis;angle").split(";")));
151 
152  emit setSlotDescription("getObjectRenderingMatrix(int)",tr("Returns the current object transformation matrix from the scenegraph."),
153  QStringList(tr("objectId").split(";")), QStringList(tr("ID of an object").split(";")));
154 
155 
156 }
157 
158 
159 //------------------------------------------------------------------------------
160 
166 void MovePlugin::translate( int _objectId , Vector _vector) {
167 
168  BaseObjectData* object;
169  if ( ! PluginFunctions::getObject(_objectId,object) ) {
170  emit log(LOGERR,tr("translate : unable to get object") );
171  return;
172  }
173 
174  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
175 
176  TriMesh& mesh = (*PluginFunctions::triMesh(object));
177  TriMesh::VertexIter v_it = mesh.vertices_begin();
178  TriMesh::VertexIter v_end = mesh.vertices_end();
179  for (; v_it!=v_end; ++v_it)
180  mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
181 
182  } else if ( object->dataType( DATA_POLY_MESH ) ) {
183 
184  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
185  PolyMesh::VertexIter v_it = mesh.vertices_begin();
186  PolyMesh::VertexIter v_end = mesh.vertices_end();
187  for (; v_it!=v_end; ++v_it)
188  mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
189 
190  }
191 #ifdef ENABLE_TSPLINEMESH_SUPPORT
192  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
193 
194  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
195  TSplineMesh::VertexIter v_it = mesh.vertices_begin();
196  TSplineMesh::VertexIter v_end = mesh.vertices_end();
197  for (; v_it!=v_end; ++v_it)
198  mesh.set_point(v_it,mesh.point(v_it) + _vector );
199 
200  }
201 #endif
202 #ifdef ENABLE_POLYLINE_SUPPORT
203  else if ( object->dataType(DATA_POLY_LINE) ) {
204 
205  PolyLine& line = (* PluginFunctions::polyLine(object) );
206 
207  for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
208  line.point(i) = line.point(i) + _vector;
209  }
210 #endif
211 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
212  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
213 
215  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
216  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
217  for (; v_it != v_end; ++v_it)
218  mesh.set_vertex(*v_it, mesh.vertex(*v_it) + _vector );
219  }
220 #endif
221 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
222  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {
223 
224  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
225  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
226  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
227  for (; v_it != v_end; ++v_it)
228  mesh.set_vertex(*v_it, mesh.vertex(*v_it) + _vector );
229  }
230 #endif
231 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
232  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {
233 
235  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
236  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
237  for (; v_it != v_end; ++v_it)
238  mesh.set_vertex(*v_it, mesh.vertex(*v_it) + _vector );
239  }
240 #endif
241 #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
242  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
243  std::cerr << "Todo : translate BSplineCurve" << std::endl;
244  }
245 #endif
246 
247  emit updatedObject(_objectId, UPDATE_GEOMETRY);
248 
249  emit scriptInfo( "translate( ObjectId , Vector(" +
250  QString::number( _vector[0] ) + " , " +
251  QString::number( _vector[1] ) + " , " +
252  QString::number( _vector[2] ) + " ) )" );
253 }
254 
255 
256 //------------------------------------------------------------------------------
257 
264 void MovePlugin::translate( int _objectId , IdList _vHandles, Vector _vector ){
265  BaseObjectData* object;
266  if ( ! PluginFunctions::getObject(_objectId,object) ) {
267  emit log(LOGERR,tr("translate : unable to get object") );
268  return;
269  }
270 
271  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
272 
273  TriMesh& mesh = (*PluginFunctions::triMesh(object));
274 
275  for (uint i=0; i < _vHandles.size(); i++){
276  TriMesh::VertexHandle vh( _vHandles[i] );
277  mesh.set_point(vh ,mesh.point( vh ) + _vector );
278  }
279 
280  } else if ( object->dataType( DATA_POLY_MESH ) ) {
281 
282  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
283 
284  for (uint i=0; i < _vHandles.size(); i++){
285  PolyMesh::VertexHandle vh( _vHandles[i] );
286  mesh.set_point(vh ,mesh.point( vh ) + _vector );
287  }
288  }
289 #ifdef ENABLE_TSPLINEMESH_SUPPORT
290  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
291 
292  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
293 
294  for (uint i=0; i < _vHandles.size(); i++){
295  TSplineMesh::VertexHandle vh( _vHandles[i] );
296  mesh.set_point(vh ,mesh.point( vh ) + _vector );
297  }
298  }
299 #endif
300 #ifdef ENABLE_POLYLINE_SUPPORT
301  else if ( object->dataType(DATA_POLY_LINE) ) {
302 
303  PolyLine& line = (* PluginFunctions::polyLine(object) );
304 
305  const int max = line.n_vertices();
306 
307  for ( unsigned int i = 0 ; i < _vHandles.size(); ++i )
308  if ( (_vHandles[i] > 0) && ( _vHandles[i] < max ) )
309  line.point( _vHandles[i] ) = line.point( _vHandles[i] ) + _vector;
310  }
311 #endif
312 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
313  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
314 
316  for (unsigned int i = 0; i < _vHandles.size(); ++i) {
317  OpenVolumeMesh::VertexHandle v(_vHandles[i]);
318  mesh.set_vertex(v, mesh.vertex(v) + _vector );
319  }
320  }
321 #endif
322 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
323  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {
324 
325  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
326  for (unsigned int i = 0; i < _vHandles.size(); ++i) {
327  OpenVolumeMesh::VertexHandle v(_vHandles[i]);
328  mesh.set_vertex(v, mesh.vertex(v) + _vector );
329  }
330  }
331 #endif
332 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
333  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {
334 
336  for (unsigned int i = 0; i < _vHandles.size(); ++i) {
337  OpenVolumeMesh::VertexHandle v(_vHandles[i]);
338  mesh.set_vertex(v, mesh.vertex(v) + _vector );
339  }
340  }
341 #endif
342 #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
343  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
344  std::cerr << "Todo : translate BSplineCurve" << std::endl;
345  }
346 #endif
347 
348  emit updatedObject(_objectId, UPDATE_GEOMETRY);
349 
350  emit scriptInfo( "translate( ObjectId , Vector(" +
351  QString::number( _vector[0] ) + " , " +
352  QString::number( _vector[1] ) + " , " +
353  QString::number( _vector[2] ) + " ) )" );
354 
355 }
356 
357 
358 //------------------------------------------------------------------------------
359 
365 void MovePlugin::translateVertexSelection( int _objectId , Vector _vector) {
366 
367  BaseObjectData* object;
368  if ( ! PluginFunctions::getObject(_objectId,object) ) {
369  emit log(LOGERR,tr("translate : unable to get object" ));
370  return;
371  }
372 
373  bool noneSelected = true;
374 
375  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
376 
377  TriMesh& mesh = (*PluginFunctions::triMesh(object));
378  TriMesh::VertexIter v_it = mesh.vertices_begin();
379  TriMesh::VertexIter v_end = mesh.vertices_end();
380  for (; v_it!=v_end; ++v_it)
381  if ( mesh.status(*v_it).selected() ) {
382  noneSelected = false;
383  mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
384  }
385 
386  } else if ( object->dataType( DATA_POLY_MESH ) ) {
387 
388  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
389  PolyMesh::VertexIter v_it = mesh.vertices_begin();
390  PolyMesh::VertexIter v_end = mesh.vertices_end();
391  for (; v_it!=v_end; ++v_it)
392  if ( mesh.status(*v_it).selected() ) {
393  noneSelected = false;
394  mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
395  }
396  }
397 #ifdef ENABLE_TSPLINEMESH_SUPPORT
398  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
399 
400  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
401  TSplineMesh::VertexIter v_it = mesh.vertices_begin();
402  TSplineMesh::VertexIter v_end = mesh.vertices_end();
403  for (; v_it!=v_end; ++v_it)
404  if ( mesh.status(v_it).selected() ) {
405  noneSelected = false;
406  mesh.set_point(v_it,mesh.point(v_it) + _vector );
407  }
408  }
409 #endif
410 #ifdef ENABLE_POLYLINE_SUPPORT
411  else if ( object->dataType(DATA_POLY_LINE) ) {
412 
413  PolyLine& line = (* PluginFunctions::polyLine(object) );
414 
415  for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
416  if ( line.vertex_selection(i) ) {
417  noneSelected = false;
418  line.point(i) = line.point(i) + _vector;
419  }
420  }
421 #endif
422 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
423  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
424 
426  OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
427  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
428  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
429  for (; v_it != v_end; ++v_it)
430  if (statusAttrib[*v_it].selected()) {
431  noneSelected = false;
432  mesh.set_vertex(*v_it, mesh.vertex(*v_it) + _vector );
433  }
434  }
435 #endif
436 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
437  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {
438 
439  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
440  OpenVolumeMesh::StatusAttrib& statusAttrib = ((TetrahedralMeshObject*)object)->status();
441  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
442  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
443  for (; v_it != v_end; ++v_it)
444  if (statusAttrib[*v_it].selected()) {
445  noneSelected = false;
446  mesh.set_vertex(*v_it, mesh.vertex(*v_it) + _vector );
447  }
448  }
449 #endif
450 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
451  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {
452 
454  OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
455  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
456  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
457  for (; v_it != v_end; ++v_it)
458  if (statusAttrib[*v_it].selected()) {
459  noneSelected = false;
460  mesh.set_vertex(*v_it, mesh.vertex(*v_it) + _vector );
461  }
462  }
463 #endif
464 #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
465  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
466  std::cerr << "Todo : translate BSplineCurve" << std::endl;
467  }
468 #endif
469 
470  if (noneSelected)
471  return;
472 
473  emit updatedObject(_objectId, UPDATE_GEOMETRY);
474 
475  emit scriptInfo( "translate( ObjectId , Vector(" +
476  QString::number( _vector[0] ) + " , " +
477  QString::number( _vector[1] ) + " , " +
478  QString::number( _vector[2] ) + " ) )" );
479 }
480 
481 
482 //------------------------------------------------------------------------------
483 
489 void MovePlugin::translateFaceSelection( int _objectId , Vector _vector) {
490 
491  BaseObjectData* object;
492  if ( ! PluginFunctions::getObject(_objectId,object) ) {
493  emit log(LOGERR,tr("translate : unable to get object" ));
494  return;
495  }
496 
497  bool noneSelected = true;
498 
499  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
500 
501  TriMesh& mesh = (*PluginFunctions::triMesh(object));
502 
503  // clear tags
504  TriMesh::VertexIter v_it, v_end( mesh.vertices_end() );
505  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
506  mesh.status(*v_it).set_tagged(false);
507 
508  TriMesh::FaceIter f_it = mesh.faces_begin();
509  TriMesh::FaceIter f_end = mesh.faces_end();
510  for (; f_it!=f_end; ++f_it)
511  if ( mesh.status(*f_it).selected() )
512  {
513  for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it) {
514  noneSelected = false;
515  mesh.status(*fv_it).set_tagged(true);
516  }
517  }
518 
519  if (noneSelected)
520  return;
521 
522  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
523  if ( mesh.status(*v_it).tagged() )
524  mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
525 
526  } else if ( object->dataType( DATA_POLY_MESH ) ) {
527 
528  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
529 
530  // clear tags
531  PolyMesh::VertexIter v_it, v_end( mesh.vertices_end() );
532  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
533  mesh.status(*v_it).set_tagged(false);
534 
535  PolyMesh::FaceIter f_it = mesh.faces_begin();
536  PolyMesh::FaceIter f_end = mesh.faces_end();
537  for (; f_it!=f_end; ++f_it)
538  if ( mesh.status(*f_it).selected() )
539  {
540  for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it) {
541  noneSelected = false;
542  mesh.status(*fv_it).set_tagged(true);
543  }
544  }
545 
546  if (noneSelected)
547  return;
548 
549  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
550  if ( mesh.status(*v_it).tagged() )
551  mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
552  }
553 #ifdef ENABLE_TSPLINEMESH_SUPPORT
554  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
555 
556  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
557 
558  // clear tags
559  TSplineMesh::VertexIter v_it, v_end( mesh.vertices_end() );
560  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
561  mesh.status(*v_it).set_tagged(false);
562 
563  TSplineMesh::FaceIter f_it = mesh.faces_begin();
564  TSplineMesh::FaceIter f_end = mesh.faces_end();
565  for (; f_it!=f_end; ++f_it)
566  if ( mesh.status(f_it).selected() )
567  {
568  for(TriMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it) {
569  noneSelected = false;
570  mesh.status(fv_it).set_tagged(true);
571  }
572  }
573 
574  if (noneSelected)
575  return;
576 
577  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
578  if ( mesh.status(v_it).tagged() )
579  mesh.set_point(v_it,mesh.point(v_it) + _vector );
580  }
581 #endif
582 
583  #ifdef ENABLE_POLYLINE_SUPPORT
584  else if ( object->dataType(DATA_POLY_LINE) ) {
585 
586  PolyLine& line = (* PluginFunctions::polyLine(object) );
587 
588  for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
589  if ( line.vertex_selection(i) ) {
590  noneSelected = false;
591  line.point(i) = line.point(i) + _vector;
592  }
593 
594  if (noneSelected)
595  return;
596  }
597  #endif
598  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
599  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
600  std::cerr << "Todo : translate BSplineCurve" << std::endl;
601  }
602  #endif
603 
604  emit updatedObject(_objectId, UPDATE_GEOMETRY);
605 
606  emit scriptInfo( "translate( ObjectId , Vector(" +
607  QString::number( _vector[0] ) + " , " +
608  QString::number( _vector[1] ) + " , " +
609  QString::number( _vector[2] ) + " ) )" );
610 
611 }
612 
613 
614 //------------------------------------------------------------------------------
615 
621 void MovePlugin::translateEdgeSelection( int _objectId , Vector _vector) {
622 
623  BaseObjectData* object;
624  if ( ! PluginFunctions::getObject(_objectId,object) ) {
625  emit log(LOGERR,tr("translate : unable to get object" ));
626  return;
627  }
628 
629  bool noneSelected = true;
630 
631  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
632 
633  TriMesh& mesh = (*PluginFunctions::triMesh(object));
634 
635  // clear tags
636  TriMesh::VertexIter v_it, v_end( mesh.vertices_end() );
637  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
638  mesh.status(*v_it).set_tagged(false);
639 
640  TriMesh::EdgeIter e_it = mesh.edges_begin();
641  TriMesh::EdgeIter e_end = mesh.edges_end();
642  for (; e_it!=e_end; ++e_it)
643  if ( mesh.status(*e_it).selected() )
644  {
645  noneSelected = false;
646  TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
647 
648  mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
649  mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
650  }
651 
652  if (noneSelected)
653  return;
654 
655  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
656  if ( mesh.status(*v_it).tagged() ){
657  mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
658  }
659 
660  } else if ( object->dataType( DATA_POLY_MESH ) ) {
661 
662  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
663 
664  // clear tags
665  PolyMesh::VertexIter v_it, v_end( mesh.vertices_end() );
666  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
667  mesh.status(*v_it).set_tagged(false);
668 
669  PolyMesh::EdgeIter e_it = mesh.edges_begin();
670  PolyMesh::EdgeIter e_end = mesh.edges_end();
671  for (; e_it!=e_end; ++e_it)
672  if ( mesh.status(*e_it).selected() )
673  {
674  noneSelected = false;
675  PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
676 
677  mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
678  mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
679  }
680 
681  if (noneSelected)
682  return;
683 
684  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
685  if ( mesh.status(*v_it).tagged() ){
686  mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
687  }
688  }
689 #ifdef ENABLE_TSPLINEMESH_SUPPORT
690  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
691 
692  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
693 
694  // clear tags
695  TSplineMesh::VertexIter v_it, v_end( mesh.vertices_end() );
696  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
697  mesh.status(v_it).set_tagged(false);
698 
699  TSplineMesh::EdgeIter e_it = mesh.edges_begin();
700  TSplineMesh::EdgeIter e_end = mesh.edges_end();
701  for (; e_it!=e_end; ++e_it)
702  if ( mesh.status(e_it).selected() )
703  {
704  noneSelected = false;
705  PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( e_it, 0 );
706 
707  mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
708  mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
709  }
710 
711  if (noneSelected)
712  return;
713 
714  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
715  if ( mesh.status(v_it).tagged() ){
716  mesh.set_point(v_it,mesh.point(v_it) + _vector );
717  }
718  }
719 #endif
720 
721  #ifdef ENABLE_POLYLINE_SUPPORT
722  else if ( object->dataType(DATA_POLY_LINE) ) {
723 
724  PolyLine& line = (* PluginFunctions::polyLine(object) );
725 
726  for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
727  if ( line.vertex_selection(i) ) {
728  noneSelected = false;
729  line.point(i) = line.point(i) + _vector;
730  }
731 
732  if (noneSelected)
733  return;
734  }
735  #endif
736  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
737  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
738  std::cerr << "Todo : translate BSplineCurve" << std::endl;
739  }
740  #endif
741 
742  emit updatedObject(_objectId, UPDATE_GEOMETRY);
743 
744  emit scriptInfo( "translate( ObjectId , Vector(" +
745  QString::number( _vector[0] ) + " , " +
746  QString::number( _vector[1] ) + " , " +
747  QString::number( _vector[2] ) + " ) )" );
748 
749 }
750 //------------------------------------------------------------------------------
751 
752 void MovePlugin::transformHandleRegion(int _objectId, Matrix4x4 _matrix) {
753 
754  BaseObjectData* object = NULL;
755  if (!PluginFunctions::getObject(_objectId, object)) {
756  emit log(LOGERR, tr("transformHandleRegion: Unable to get object!"));
757  return;
758  }
759 
760  if(object->dataType(DATA_TRIANGLE_MESH)) {
761 
762  TriMesh& mesh = (*PluginFunctions::triMesh(object));
763 
765 
766  } else if(object->dataType(DATA_POLY_MESH)) {
767 
768  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
769 
771  }
772 
773  emit updatedObject(_objectId, UPDATE_GEOMETRY);
774 }
775 
776 //------------------------------------------------------------------------------
777 
783 void MovePlugin::transform( int _objectId , Matrix4x4 _matrix ){
784 
785  BaseObjectData* object;
786  if ( ! PluginFunctions::getObject(_objectId,object) ) {
787  emit log(LOGERR,tr("transform : unable to get object" ));
788  return;
789  }
790 
791  Matrix4x4 normalMatrix = _matrix;
792  normalMatrix.invert();
793  normalMatrix.transpose();
794 
795  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
796 
797  TriMesh& mesh = (*PluginFunctions::triMesh(object));
798  TriMesh::VertexIter v_it = mesh.vertices_begin();
799  TriMesh::VertexIter v_end = mesh.vertices_end();
800  for (; v_it!=v_end; ++v_it){
801  mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
802  mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
803  }
804 
805  } else if ( object->dataType( DATA_POLY_MESH ) ) {
806 
807  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
808  PolyMesh::VertexIter v_it = mesh.vertices_begin();
809  PolyMesh::VertexIter v_end = mesh.vertices_end();
810  for (; v_it!=v_end; ++v_it){
811  mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
812  mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
813  }
814  }
815 #ifdef ENABLE_TSPLINEMESH_SUPPORT
816  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
817 
818  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
819  TSplineMesh::VertexIter v_it = mesh.vertices_begin();
820  TSplineMesh::VertexIter v_end = mesh.vertices_end();
821  for (; v_it!=v_end; ++v_it){
822  mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
823  mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
824  }
825  }
826 #endif
827 #ifdef ENABLE_POLYLINE_SUPPORT
828  else if ( object->dataType(DATA_POLY_LINE) ) {
829 
830  PolyLine& line = (* PluginFunctions::polyLine(object) );
831 
832  for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
833  line.point(i) = _matrix.transform_point( line.point(i) );
834  }
835 #endif
836 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
837  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
838 
840  OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
841  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
842  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
843  for (; v_it != v_end; ++v_it) {
844  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
845  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
846  }
847  }
848 #endif
849 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
850  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {
851 
852  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
853  OpenVolumeMesh::NormalAttrib<TetrahedralMesh>& normalAttrib = ((TetrahedralMeshObject*)object)->normals();
854  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
855  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
856  for (; v_it != v_end; ++v_it) {
857  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
858  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
859  }
860  }
861 #endif
862 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
863  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {
864 
866  OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
867  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
868  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
869  for (; v_it != v_end; ++v_it) {
870  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
871  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
872  }
873  }
874 #endif
875 #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
876  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
877  std::cerr << "Todo : transform BSplineCurve" << std::endl;
878  }
879 #endif
880 
881  emit updatedObject(_objectId, UPDATE_GEOMETRY);
882 
883  QString matString;
884  for (int i=0; i < 4; i++)
885  for (int j=0; j < 4; j++)
886  matString += " , " + QString::number( _matrix(i,j) );
887 
888  matString = matString.right( matString.length()-3 );
889 
890  emit scriptInfo( "transform( ObjectId , Matrix4x4(" + matString + " ) )" );
891 }
892 
893 
894 //------------------------------------------------------------------------------
895 
902 void MovePlugin::transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix ){
903 
904  BaseObjectData* object;
905  if ( ! PluginFunctions::getObject(_objectId,object) ) {
906  emit log(LOGERR,tr("transform : unable to get object" ));
907  return;
908  }
909 
910  Matrix4x4 normalMatrix = _matrix;
911  normalMatrix.invert();
912  normalMatrix.transpose();
913 
914  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
915 
916  TriMesh& mesh = (*PluginFunctions::triMesh(object));
917 
918  for (uint i=0; i < _vHandles.size(); i++){
919  TriMesh::VertexHandle vh( _vHandles[i] );
920  mesh.set_point (vh, _matrix.transform_point ( mesh.point(vh) ) );
921  mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
922  }
923 
924  } else if ( object->dataType( DATA_POLY_MESH ) ) {
925 
926  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
927 
928  for (uint i=0; i < _vHandles.size(); i++){
929  PolyMesh::VertexHandle vh( _vHandles[i] );
930  mesh.set_point (vh, _matrix.transform_point ( mesh.point(vh) ) );
931  mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
932  }
933  }
934 #ifdef ENABLE_TSPLINEMESH_SUPPORT
935  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
936 
937  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
938 
939  for (uint i=0; i < _vHandles.size(); i++){
940  TSplineMesh::VertexHandle vh( _vHandles[i] );
941  mesh.set_point (vh, _matrix.transform_point ( mesh.point(vh) ) );
942  mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
943  }
944  }
945 #endif
946 #ifdef ENABLE_POLYLINE_SUPPORT
947  else if ( object->dataType(DATA_POLY_LINE) ) {
948 
949  PolyLine& line = (* PluginFunctions::polyLine(object) );
950 
951  const int max = line.n_vertices();
952 
953  for ( unsigned int i = 0 ; i < _vHandles.size(); ++i )
954  if ( (_vHandles[i] > 0) && ( _vHandles[i] < max ) )
955  line.point( _vHandles[i] ) = _matrix.transform_point( line.point( _vHandles[i] ) );
956 
957  }
958 #endif
959 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
960  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
961 
963  OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
964  for (unsigned int i = 0; i < _vHandles.size(); ++i) {
965  OpenVolumeMesh::VertexHandle v(_vHandles[i]);
966  mesh.set_vertex(v, _matrix.transform_point ( mesh.vertex(v) ) );
967  normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
968  }
969  }
970 #endif
971 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
972  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {
973 
974  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
975  OpenVolumeMesh::NormalAttrib<TetrahedralMesh>& normalAttrib = ((TetrahedralMeshObject*)object)->normals();
976  for (unsigned int i = 0; i < _vHandles.size(); ++i) {
977  OpenVolumeMesh::VertexHandle v(_vHandles[i]);
978  mesh.set_vertex(v, _matrix.transform_point ( mesh.vertex(v) ) );
979  normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
980  }
981  }
982 #endif
983 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
984  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {
985 
987  OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
988  for (unsigned int i = 0; i < _vHandles.size(); ++i) {
989  OpenVolumeMesh::VertexHandle v(_vHandles[i]);
990  mesh.set_vertex(v, _matrix.transform_point ( mesh.vertex(v) ) );
991  normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
992  }
993  }
994 #endif
995 #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
996  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
997  std::cerr << "Todo : transform BSplineCurve" << std::endl;
998  }
999 #endif
1000 
1001  emit updatedObject(_objectId, UPDATE_GEOMETRY);
1002 
1003  QString matString;
1004  for (int i=0; i < 4; i++)
1005  for (int j=0; j < 4; j++)
1006  matString += " , " + QString::number( _matrix(i,j) );
1007 
1008  matString = matString.right( matString.length()-3 );
1009 
1010  emit scriptInfo( "transform( ObjectId , Matrix4x4(" + matString + " ) )" );
1011 
1012 }
1013 
1014 
1015 //------------------------------------------------------------------------------
1016 
1024 bool MovePlugin::transformVertexSelection( int _objectId , Matrix4x4 _matrix ){
1025  BaseObjectData* object;
1026  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1027  emit log(LOGERR,tr("transform : unable to get object") );
1028  return false;
1029  }
1030 
1031  Matrix4x4 normalMatrix = _matrix;
1032  normalMatrix.invert();
1033  normalMatrix.transpose();
1034 
1035  bool noneSelected = true;
1036  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
1037 
1038  TriMesh& mesh = (*PluginFunctions::triMesh(object));
1039  TriMesh::VertexIter v_it = mesh.vertices_begin();
1040  TriMesh::VertexIter v_end = mesh.vertices_end();
1041  for (; v_it!=v_end; ++v_it)
1042  if ( mesh.status(*v_it).selected() )
1043  {
1044  noneSelected = false;
1045  mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1046  mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
1047  }
1048 
1049  } else if ( object->dataType( DATA_POLY_MESH ) ) {
1050 
1051  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
1052  PolyMesh::VertexIter v_it = mesh.vertices_begin();
1053  PolyMesh::VertexIter v_end = mesh.vertices_end();
1054  for (; v_it!=v_end; ++v_it)
1055  if ( mesh.status(*v_it).selected() )
1056  {
1057  noneSelected = false;
1058  mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1059  mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
1060  }
1061  }
1062 #ifdef ENABLE_TSPLINEMESH_SUPPORT
1063  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
1064 
1065  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
1066  TSplineMesh::VertexIter v_it = mesh.vertices_begin();
1067  TSplineMesh::VertexIter v_end = mesh.vertices_end();
1068  for (; v_it!=v_end; ++v_it)
1069  if ( mesh.status(v_it).selected() )
1070  {
1071  noneSelected = false;
1072  mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
1073  mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
1074  }
1075  }
1076 #endif
1077 #ifdef ENABLE_POLYLINE_SUPPORT
1078  else if ( object->dataType(DATA_POLY_LINE) ) {
1079 
1080  PolyLine& line = (* PluginFunctions::polyLine(object) );
1081 
1082  for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
1083  if ( line.vertex_selection(i) ) {
1084  noneSelected = false;
1085  line.point(i) = _matrix.transform_point( line.point(i) );
1086  }
1087  }
1088 #endif
1089 #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
1090  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
1091  std::cerr << "Todo : transform BSplineCurve" << std::endl;
1092  }
1093 #endif
1094 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
1095  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
1097  OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
1098  OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
1099  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
1100  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1101  for (; v_it!=v_end; ++v_it)
1102  if ( statusAttrib[*v_it].selected() )
1103  {
1104  noneSelected = false;
1105  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1106  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1107  }
1108  }
1109 #endif
1110 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
1111  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {
1112  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
1113  OpenVolumeMesh::NormalAttrib<TetrahedralMesh>& normalAttrib = ((TetrahedralMeshObject*)object)->normals();
1114  OpenVolumeMesh::StatusAttrib& statusAttrib = ((TetrahedralMeshObject*)object)->status();
1115  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
1116  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1117  for (; v_it!=v_end; ++v_it)
1118  if ( statusAttrib[*v_it].selected() )
1119  {
1120  noneSelected = false;
1121  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1122  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1123  }
1124  }
1125 #endif
1126 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
1127  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {
1129  OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
1130  OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
1131  OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
1132  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1133  for (; v_it!=v_end; ++v_it)
1134  if ( statusAttrib[*v_it].selected() )
1135  {
1136  noneSelected = false;
1137  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1138  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1139  }
1140  }
1141 #endif
1142 
1143  if (noneSelected)
1144  return false;
1145 
1146  emit updatedObject(_objectId, UPDATE_GEOMETRY);
1147 
1148  QString matString;
1149  for (int i=0; i < 4; i++)
1150  for (int j=0; j < 4; j++)
1151  matString += " , " + QString::number( _matrix(i,j) );
1152 
1153  matString = matString.right( matString.length()-3 );
1154 
1155  emit scriptInfo( "transformVertexSelection( ObjectId , Matrix4x4(" + matString + " ) )" );
1156 
1157  return true;
1158 }
1159 
1160 
1161 //------------------------------------------------------------------------------
1162 
1170 bool MovePlugin::transformFaceSelection( int _objectId , Matrix4x4 _matrix ){
1171  BaseObjectData* object;
1172  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1173  emit log(LOGERR,tr("transform : unable to get object") );
1174  return false;
1175  }
1176 
1177  Matrix4x4 normalMatrix = _matrix;
1178  normalMatrix.invert();
1179  normalMatrix.transpose();
1180 
1181  bool noneSelected = true;
1182  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
1183 
1184  TriMesh& mesh = (*PluginFunctions::triMesh(object));
1185 
1186  //init tags
1187  TriMesh::VertexIter v_it, v_end( mesh.vertices_end() );
1188  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1189  mesh.status(*v_it).set_tagged(false);
1190 
1191  TriMesh::FaceIter f_it = mesh.faces_begin();
1192  TriMesh::FaceIter f_end = mesh.faces_end();
1193  for (; f_it!=f_end; ++f_it)
1194  if ( mesh.status(*f_it).selected() )
1195  {
1196  noneSelected = false;
1197  for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1198  mesh.status(*fv_it).set_tagged(true);
1199  }
1200 
1201  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1202  if ( mesh.status(*v_it).tagged() ){
1203  mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1204  mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
1205  }
1206 
1207  } else if ( object->dataType( DATA_POLY_MESH ) ) {
1208 
1209  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
1210 
1211  //init tags
1212  PolyMesh::VertexIter v_it, v_end( mesh.vertices_end() );
1213  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1214  mesh.status(*v_it).set_tagged(false);
1215 
1216  PolyMesh::FaceIter f_it = mesh.faces_begin();
1217  PolyMesh::FaceIter f_end = mesh.faces_end();
1218  for (; f_it!=f_end; ++f_it)
1219  if ( mesh.status(*f_it).selected() )
1220  {
1221  noneSelected = false;
1222  for(PolyMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1223  mesh.status(*fv_it).set_tagged(true);
1224  }
1225 
1226  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1227  if ( mesh.status(*v_it).tagged() ){
1228  mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1229  mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
1230  }
1231  }
1232 #ifdef ENABLE_TSPLINEMESH_SUPPORT
1233  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
1234 
1235  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
1236 
1237  //init tags
1238  TSplineMesh::VertexIter v_it, v_end( mesh.vertices_end() );
1239  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1240  mesh.status(v_it).set_tagged(false);
1241 
1242  TSplineMesh::FaceIter f_it = mesh.faces_begin();
1243  TSplineMesh::FaceIter f_end = mesh.faces_end();
1244  for (; f_it!=f_end; ++f_it)
1245  if ( mesh.status(f_it).selected() )
1246  {
1247  noneSelected = false;
1248  for(TSplineMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it)
1249  mesh.status(fv_it).set_tagged(true);
1250  }
1251 
1252  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1253  if ( mesh.status(v_it).tagged() ){
1254  mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
1255  mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
1256  }
1257  }
1258 #endif
1259 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
1260  if ( object->dataType( DATA_HEXAHEDRAL_MESH ) ) {
1261 
1263  OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
1264  OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
1265  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1266  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1267 
1268  //init tags
1269  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1270  statusAttrib[*v_it].set_tagged(false);
1271 
1272  OpenVolumeMesh::FaceIter f_it = mesh.faces_begin();
1273  OpenVolumeMesh::FaceIter f_end = mesh.faces_end();
1274  for (; f_it!=f_end; ++f_it)
1275  if ( statusAttrib[*f_it].selected() )
1276  {
1277  noneSelected = false;
1278  for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = mesh.hfv_iter(mesh.halfface_handle(*f_it,0)); hfv_it.valid(); ++hfv_it)
1279  statusAttrib[*hfv_it].set_tagged(true);
1280  }
1281 
1282  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1283  if ( statusAttrib[*v_it].tagged() )
1284  {
1285  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1286  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1287  }
1288 
1289  }
1290 #endif
1291 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
1292  if ( object->dataType( DATA_TETRAHEDRAL_MESH ) ) {
1293 
1294  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
1295  OpenVolumeMesh::NormalAttrib<TetrahedralMesh>& normalAttrib = ((TetrahedralMeshObject*)object)->normals();
1296  OpenVolumeMesh::StatusAttrib& statusAttrib = ((TetrahedralMeshObject*)object)->status();
1297  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1298  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1299 
1300  //init tags
1301  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1302  statusAttrib[*v_it].set_tagged(false);
1303 
1304  OpenVolumeMesh::FaceIter f_it = mesh.faces_begin();
1305  OpenVolumeMesh::FaceIter f_end = mesh.faces_end();
1306  for (; f_it!=f_end; ++f_it)
1307  if ( statusAttrib[*f_it].selected() )
1308  {
1309  noneSelected = false;
1310  for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = mesh.hfv_iter(mesh.halfface_handle(*f_it,0)); hfv_it.valid(); ++hfv_it)
1311  statusAttrib[*hfv_it].set_tagged(true);
1312  }
1313 
1314  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1315  if ( statusAttrib[*v_it].tagged() )
1316  {
1317  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1318  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1319  }
1320 
1321  }
1322 #endif
1323 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
1324  else if ( object->dataType( DATA_POLYHEDRAL_MESH ) ) {
1325 
1327  OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
1328  OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
1329  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1330  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1331 
1332  //init tags
1333  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1334  statusAttrib[*v_it].set_tagged(false);
1335 
1336  OpenVolumeMesh::FaceIter f_it = mesh.faces_begin();
1337  OpenVolumeMesh::FaceIter f_end = mesh.faces_end();
1338  for (; f_it!=f_end; ++f_it)
1339  if ( statusAttrib[*f_it].selected() )
1340  {
1341  noneSelected = false;
1342  for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = mesh.hfv_iter(mesh.halfface_handle(*f_it,0)); hfv_it.valid(); ++hfv_it)
1343  statusAttrib[*hfv_it].set_tagged(true);
1344  }
1345 
1346  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1347  if ( statusAttrib[*v_it].tagged() )
1348  {
1349  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1350  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1351  }
1352  }
1353 #endif
1354 
1355  if (noneSelected)
1356  return false;
1357 
1358  emit updatedObject(_objectId, UPDATE_GEOMETRY);
1359 
1360  QString matString;
1361  for (int i=0; i < 4; i++)
1362  for (int j=0; j < 4; j++)
1363  matString += " , " + QString::number( _matrix(i,j) );
1364 
1365  matString = matString.right( matString.length()-3 );
1366 
1367  emit scriptInfo( "transformFaceSelection( ObjectId , Matrix4x4(" + matString + " ) )" );
1368 
1369  return true;
1370 }
1371 
1372 
1373 //------------------------------------------------------------------------------
1374 
1382 bool MovePlugin::transformEdgeSelection( int _objectId , Matrix4x4 _matrix ){
1383  BaseObjectData* object;
1384  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1385  emit log(LOGERR,tr("transform : unable to get object" ) );
1386  return false;
1387  }
1388 
1389  Matrix4x4 normalMatrix = _matrix;
1390  normalMatrix.invert();
1391  normalMatrix.transpose();
1392 
1393  bool noneSelected = true;
1394  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
1395 
1396  TriMesh& mesh = (*PluginFunctions::triMesh(object));
1397 
1398  //init tags
1399  TriMesh::VertexIter v_it, v_end( mesh.vertices_end() );
1400  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1401  mesh.status(*v_it).set_tagged(false);
1402 
1403  TriMesh::EdgeIter e_it = mesh.edges_begin();
1404  TriMesh::EdgeIter e_end = mesh.edges_end();
1405  for (; e_it!=e_end; ++e_it)
1406  if ( mesh.status(*e_it).selected() )
1407  {
1408  noneSelected = false;
1409  TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
1410 
1411  mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
1412  mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
1413  }
1414 
1415  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1416  if ( mesh.status(*v_it).tagged() ){
1417  mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1418  mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
1419  }
1420 
1421  } else if ( object->dataType( DATA_POLY_MESH ) ) {
1422 
1423  PolyMesh& mesh = (*PluginFunctions::polyMesh(object));
1424 
1425  //init tags
1426  PolyMesh::VertexIter v_it, v_end( mesh.vertices_end() );
1427  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1428  mesh.status(*v_it).set_tagged(false);
1429 
1430  PolyMesh::EdgeIter e_it = mesh.edges_begin();
1431  PolyMesh::EdgeIter e_end = mesh.edges_end();
1432  for (; e_it!=e_end; ++e_it)
1433  if ( mesh.status(*e_it).selected() )
1434  {
1435  noneSelected = false;
1436  PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
1437 
1438  mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
1439  mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
1440  }
1441 
1442  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1443  if ( mesh.status(*v_it).tagged() ){
1444  mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1445  mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
1446  }
1447  }
1448 #ifdef ENABLE_TSPLINEMESH_SUPPORT
1449  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
1450 
1451  TSplineMesh& mesh = (*PluginFunctions::tsplineMesh(object));
1452 
1453  //init tags
1454  TSplineMesh::VertexIter v_it, v_end( mesh.vertices_end() );
1455  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1456  mesh.status(v_it).set_tagged(false);
1457 
1458  TSplineMesh::EdgeIter e_it = mesh.edges_begin();
1459  TSplineMesh::EdgeIter e_end = mesh.edges_end();
1460  for (; e_it!=e_end; ++e_it)
1461  if ( mesh.status(e_it).selected() )
1462  {
1463  noneSelected = false;
1464  TSplineMesh::HalfedgeHandle hh = mesh.halfedge_handle( e_it, 0 );
1465 
1466  mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
1467  mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
1468  }
1469 
1470  for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
1471  if ( mesh.status(v_it).tagged() ){
1472  mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
1473  mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
1474  }
1475  }
1476 #endif
1477 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
1478  if ( object->dataType( DATA_HEXAHEDRAL_MESH ) ) {
1479 
1481  OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
1482  OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
1483  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1484  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1485 
1486  //init tags
1487  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1488  statusAttrib[*v_it].set_tagged(false);
1489 
1490  OpenVolumeMesh::EdgeIter e_it = mesh.edges_begin();
1491  OpenVolumeMesh::EdgeIter e_end = mesh.edges_end();
1492  for (; e_it!=e_end; ++e_it)
1493  if ( statusAttrib[*e_it].selected() )
1494  {
1495  noneSelected = false;
1496  OpenVolumeMesh::OpenVolumeMeshEdge e(mesh.edge(*e_it));
1497  statusAttrib[e.from_vertex()].set_tagged(true);
1498  statusAttrib[e.to_vertex()].set_tagged(true);
1499  }
1500 
1501  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1502  if ( statusAttrib[*v_it].tagged() )
1503  {
1504  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1505  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1506  }
1507 
1508  }
1509 #endif
1510 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
1511  if ( object->dataType( DATA_TETRAHEDRAL_MESH ) ) {
1512 
1513  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
1514  OpenVolumeMesh::NormalAttrib<TetrahedralMesh>& normalAttrib = ((TetrahedralMeshObject*)object)->normals();
1515  OpenVolumeMesh::StatusAttrib& statusAttrib = ((TetrahedralMeshObject*)object)->status();
1516  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1517  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1518 
1519  //init tags
1520  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1521  statusAttrib[*v_it].set_tagged(false);
1522 
1523  OpenVolumeMesh::EdgeIter e_it = mesh.edges_begin();
1524  OpenVolumeMesh::EdgeIter e_end = mesh.edges_end();
1525  for (; e_it!=e_end; ++e_it)
1526  if ( statusAttrib[*e_it].selected() )
1527  {
1528  noneSelected = false;
1529  OpenVolumeMesh::OpenVolumeMeshEdge e(mesh.edge(*e_it));
1530  statusAttrib[e.from_vertex()].set_tagged(true);
1531  statusAttrib[e.to_vertex()].set_tagged(true);
1532  }
1533 
1534  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1535  if ( statusAttrib[*v_it].tagged() )
1536  {
1537  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1538  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1539  }
1540 
1541  }
1542 #endif
1543 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
1544  if ( object->dataType( DATA_POLYHEDRAL_MESH ) ) {
1545 
1547  OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
1548  OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
1549  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1550  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1551 
1552  //init tags
1553  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1554  statusAttrib[*v_it].set_tagged(false);
1555 
1556  OpenVolumeMesh::EdgeIter e_it = mesh.edges_begin();
1557  OpenVolumeMesh::EdgeIter e_end = mesh.edges_end();
1558  for (; e_it!=e_end; ++e_it)
1559  if ( statusAttrib[*e_it].selected() )
1560  {
1561  noneSelected = false;
1562  OpenVolumeMesh::OpenVolumeMeshEdge e(mesh.edge(*e_it));
1563  statusAttrib[e.from_vertex()].set_tagged(true);
1564  statusAttrib[e.to_vertex()].set_tagged(true);
1565  }
1566 
1567  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1568  if ( statusAttrib[*v_it].tagged() )
1569  {
1570  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1571  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1572  }
1573 
1574  }
1575 #endif
1576 
1577  #ifdef ENABLE_POLYLINE_SUPPORT
1578  else if ( object->dataType(DATA_POLY_LINE) ) {
1579  std::cerr << "Todo : transform PolyLine" << std::endl;
1580  }
1581  #endif
1582  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
1583  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
1584  std::cerr << "Todo : transform BSplineCurve" << std::endl;
1585  }
1586  #endif
1587 
1588  if (noneSelected)
1589  return false;
1590 
1591  emit updatedObject(_objectId, UPDATE_GEOMETRY);
1592 
1593  QString matString;
1594  for (int i=0; i < 4; i++)
1595  for (int j=0; j < 4; j++)
1596  matString += " , " + QString::number( _matrix(i,j) );
1597 
1598  matString = matString.right( matString.length()-3 );
1599 
1600  emit scriptInfo( "transformEdgeSelection( ObjectId , Matrix4x4(" + matString + " ) )" );
1601 
1602  return true;
1603 }
1604 
1605 //------------------------------------------------------------------------------
1606 
1614 bool MovePlugin::transformCellSelection( int _objectId , Matrix4x4 _matrix ){
1615  BaseObjectData* object;
1616  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1617  emit log(LOGERR,tr("transform : unable to get object") );
1618  return false;
1619  }
1620 
1621  Matrix4x4 normalMatrix = _matrix;
1622  normalMatrix.invert();
1623  normalMatrix.transpose();
1624 
1625  bool noneSelected = true;
1626 
1627 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
1628  if ( object->dataType( DATA_HEXAHEDRAL_MESH ) ) {
1629 
1631  OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
1632  OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
1633  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1634  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1635 
1636  //init tags
1637  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1638  statusAttrib[*v_it].set_tagged(false);
1639 
1640  OpenVolumeMesh::CellIter c_it = mesh.cells_begin();
1641  OpenVolumeMesh::CellIter c_end = mesh.cells_end();
1642  for (; c_it!=c_end; ++c_it)
1643  if ( statusAttrib[*c_it].selected() )
1644  {
1645  noneSelected = false;
1646  for (OpenVolumeMesh::CellVertexIter cv_it = mesh.cv_iter(*c_it); cv_it.valid(); ++cv_it)
1647  statusAttrib[*cv_it].set_tagged(true);
1648  }
1649 
1650  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1651  if ( statusAttrib[*v_it].tagged() )
1652  {
1653  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1654  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1655  }
1656 
1657  }
1658 #endif
1659 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
1660  if ( object->dataType( DATA_TETRAHEDRAL_MESH ) ) {
1661 
1662  TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
1663  OpenVolumeMesh::NormalAttrib<TetrahedralMesh>& normalAttrib = ((TetrahedralMeshObject*)object)->normals();
1664  OpenVolumeMesh::StatusAttrib& statusAttrib = ((TetrahedralMeshObject*)object)->status();
1665  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1666  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1667 
1668  //init tags
1669  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1670  statusAttrib[*v_it].set_tagged(false);
1671 
1672  OpenVolumeMesh::CellIter c_it = mesh.cells_begin();
1673  OpenVolumeMesh::CellIter c_end = mesh.cells_end();
1674  for (; c_it!=c_end; ++c_it)
1675  if ( statusAttrib[*c_it].selected() )
1676  {
1677  noneSelected = false;
1678  for (OpenVolumeMesh::CellVertexIter cv_it = mesh.cv_iter(*c_it); cv_it.valid(); ++cv_it)
1679  statusAttrib[*cv_it].set_tagged(true);
1680  }
1681 
1682  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1683  if ( statusAttrib[*v_it].tagged() )
1684  {
1685  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1686  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1687  }
1688 
1689  }
1690 #endif
1691 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
1692  else if ( object->dataType( DATA_POLYHEDRAL_MESH ) ) {
1693 
1695  OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
1696  OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
1697  OpenVolumeMesh::VertexIter v_begin = mesh.vertices_begin();
1698  OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
1699 
1700  //init tags
1701  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1702  statusAttrib[*v_it].set_tagged(false);
1703 
1704  OpenVolumeMesh::CellIter c_it = mesh.cells_begin();
1705  OpenVolumeMesh::CellIter c_end = mesh.cells_end();
1706  for (; c_it!=c_end; ++c_it)
1707  if ( statusAttrib[*c_it].selected() )
1708  {
1709  noneSelected = false;
1710  for (OpenVolumeMesh::CellVertexIter cv_it = mesh.cv_iter(*c_it); cv_it.valid(); ++cv_it)
1711  statusAttrib[*cv_it].set_tagged(true);
1712  }
1713 
1714  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
1715  if ( statusAttrib[*v_it].tagged() )
1716  {
1717  mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
1718  normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1719  }
1720  }
1721 #endif
1722 
1723  if (noneSelected)
1724  return false;
1725 
1726  emit updatedObject(_objectId, UPDATE_GEOMETRY);
1727 
1728  QString matString;
1729  for (int i=0; i < 4; i++)
1730  for (int j=0; j < 4; j++)
1731  matString += " , " + QString::number( _matrix(i,j) );
1732 
1733  matString = matString.right( matString.length()-3 );
1734 
1735  emit scriptInfo( "transformCellSelection( ObjectId , Matrix4x4(" + matString + " ) )" );
1736 
1737  return true;
1738 }
1739 
1740 
1741 //------------------------------------------------------------------------------
1742 
1748 void MovePlugin::setManipulatorPosition( int _objectId , Vector _position ){
1749 
1750  BaseObjectData* object;
1751  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1752  emit log(LOGERR,tr("setManipulatorPosition : unable to get object") );
1753  return;
1754  }
1755 
1756 
1758 
1759 
1760  object->manipPlaced( true );
1761 
1762  object->manipulatorNode()->loadIdentity();
1763  object->manipulatorNode()->set_center(_position);
1764  object->manipulatorNode()->set_draw_cylinder(true);
1765  object->manipulatorNode()->set_size(manip_size_ * manip_size_modifier_);
1766  object->manipulatorNode()->show();
1767 
1768  connect(object->manipulatorNode() , SIGNAL(manipulatorMoved(QtTranslationManipulatorNode*,QMouseEvent*)),
1769  this , SLOT( manipulatorMoved(QtTranslationManipulatorNode*,QMouseEvent*)));
1770 
1771  connect(object->manipulatorNode() , SIGNAL(positionChanged(QtTranslationManipulatorNode*)),
1773 
1774  lastActiveManipulator_ = object->id();
1775 
1776  emit updateView();
1777 
1778  emit scriptInfo( "setManipulatorPosition( ObjectId , Vector(" +
1779  QString::number( _position[0] ) + " , " +
1780  QString::number( _position[1] ) + " , " +
1781  QString::number( _position[2] ) + " ) )" );
1782 }
1783 
1784 
1785 //------------------------------------------------------------------------------
1786 
1793 
1794  BaseObjectData* object;
1795  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1796  emit log(LOGERR,tr("manipulatorPosition : unable to get object" ));
1797  return Vector();
1798  }
1799 
1800  return (Vector) object->manipulatorNode()->center();
1801 }
1802 
1803 
1804 //------------------------------------------------------------------------------
1805 
1812 void MovePlugin::setManipulatorDirection( int _objectId , Vector _directionX, Vector _directionY ){
1813 
1814  BaseObjectData* object;
1815  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1816  emit log(LOGERR,tr("setManipulatorDirection : unable to get object") );
1817  return;
1818  }
1819 
1820  if ( !object->manipPlaced() ){
1821  emit log(LOGERR,tr("setManipulatorDirection : manipulator position has to be set first" ));
1822  return;
1823  }
1824 
1825  object->manipulatorNode()->set_direction(_directionX, _directionY);
1826 
1827  emit scriptInfo( "setManipulatorDirection( ObjectId , Vector(" +
1828  QString::number( _directionX[0] ) + " , " +
1829  QString::number( _directionX[1] ) + " , " +
1830  QString::number( _directionX[2] ) + " ), Vector(" +
1831  QString::number( _directionY[0] ) + " , " +
1832  QString::number( _directionY[1] ) + " , " +
1833  QString::number( _directionY[2] ) + " ) )" );
1834 }
1835 
1836 
1837 //------------------------------------------------------------------------------
1838 
1845 
1846  BaseObjectData* object;
1847  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1848  emit log(LOGERR,tr("manipulatorDirection : unable to get object" ));
1849  return Vector();
1850  }
1851 
1852  return (Vector) object->manipulatorNode()->directionX();
1853 }
1854 
1855 
1856 //------------------------------------------------------------------------------
1857 
1864 
1865  BaseObjectData* object;
1866  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1867  emit log(LOGERR,tr("manipulatorDirection : unable to get object" ));
1868  return Vector();
1869  }
1870 
1871  return (Vector) object->manipulatorNode()->directionY();
1872 }
1873 
1874 
1875 //------------------------------------------------------------------------------
1876 
1883 
1884  BaseObjectData* object;
1885  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1886  emit log(LOGERR,tr("manipulatorDirection : unable to get object" ));
1887  return Vector();
1888  }
1889 
1890  return (Vector) object->manipulatorNode()->directionZ();
1891 }
1892 
1893 //------------------------------------------------------------------------------
1894 
1896  BaseObjectData* object;
1897 
1898  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1899  emit log(LOGERR,tr("objectRenderingMatrixIdentity : unable to get object" ));
1900  return ;
1901  }
1902 
1903  object->manipulatorNode()->loadIdentity();
1904 
1905  emit updatedObject(_objectId,UPDATE_VISIBILITY);
1906 }
1907 
1908 //------------------------------------------------------------------------------
1909 
1910 void MovePlugin::objectRenderingMatrixScale(int _objectId, double _s) {
1911  BaseObjectData* object;
1912 
1913  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1914  emit log(LOGERR,tr("objectRenderingMatrixScale : unable to get object" ));
1915  return ;
1916  }
1917 
1918  object->manipulatorNode()->scale(_s);
1919 
1920  emit updatedObject(_objectId,UPDATE_VISIBILITY);
1921 }
1922 
1923 //------------------------------------------------------------------------------
1924 
1925 void MovePlugin::objectRenderingMatrixTranslate(int _objectId, Vector _translation) {
1926  BaseObjectData* object;
1927 
1928  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1929  emit log(LOGERR,tr("objectRenderingMatrixTranslate : unable to get object" ));
1930  return ;
1931  }
1932 
1933  object->manipulatorNode()->translate(_translation);
1934 
1935  emit updatedObject(_objectId,UPDATE_VISIBILITY);
1936 }
1937 
1938 //------------------------------------------------------------------------------
1939 
1940 void MovePlugin::objectRenderingMatrixRotate(int _objectId, Vector _axis, double _angle) {
1941  BaseObjectData* object;
1942 
1943  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1944  emit log(LOGERR,tr("objectRenderingMatrixRotate : unable to get object" ));
1945  return ;
1946  }
1947 
1948  object->manipulatorNode()->rotate(_angle,_axis);
1949 
1950  emit updatedObject(_objectId,UPDATE_VISIBILITY);
1951 }
1952 
1953 //------------------------------------------------------------------------------
1954 
1956  BaseObjectData* object;
1957 
1958  if ( ! PluginFunctions::getObject(_objectId,object) ) {
1959  emit log(LOGERR,tr("getObjectRenderingMatrix : unable to get object" ));
1960  return Matrix4x4();
1961  }
1962 
1963  return object->manipulatorNode()->matrix();
1964 }
1965 
void setDescriptions()
Set Descriptions for scriptable functions.
const VecT & vertex(const VertexHandle &_vh) const
Get point _vh&#39;s coordinates.
bool transformEdgeSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
void objectRenderingMatrixRotate(int _objectId, Vector _axis, double _angle)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
void transpose()
transpose matrix
Definition: Matrix4x4T.cc:272
Vector manipulatorPosition(int _objectId)
Get the position of the manipulator.
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x&#39;,y&#39;,z&#39;,1) = M * (x,y,z,1)
Definition: Matrix4x4T.cc:202
void transformHandleVertices(ACG::Matrix4x4d _matrix, MeshT &_mesh)
bool transformFaceSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
bool getObject(int _identifier, BSplineCurveObject *&_object)
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
bool transformVertexSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
void setManipulatorPosition(int _objectId, Vector _position)
Set the position of the manipulator.
#define DATA_POLYHEDRAL_MESH
void translateEdgeSelection(int _objectId, Vector _vector)
translate current edge selection of an Object by a given vector
ACG::Matrix4x4d Matrix4x4
Standard Type for a 4x4 Matrix used for scripting.
Definition: DataTypes.hh:194
double sceneRadius()
Returns the current scene radius from the active examiner widget.
void set_vertex(const VertexHandle &_vh, const VecT &_p)
Set the coordinates of point _vh.
QtTranslationManipulatorNode * manipulatorNode()
#define DATA_POLY_LINE
Definition: PolyLine.hh:70
void objectRenderingMatrixScale(int _objectId, double _s)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
void translate(int _objectId, Vector _vector)
translate an Object by a given vector
PolyLine * polyLine(BaseObjectData *_object)
Get a poly Line from an object.
bool transformCellSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
#define DATA_HEXAHEDRAL_MESH
Vector manipulatorDirectionZ(int _objectId)
Get the z-direction of the manipulator.
void manipulatorMoved(QtTranslationManipulatorNode *_node, QMouseEvent *_event)
move the object when its manipulator moves
Definition: MovePlugin.cc:776
const UpdateType UPDATE_VISIBILITY(UpdateTypeSet(1)<< 1)
This is the update identifier for global Object visibility ( show/hide )
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
Point & point(unsigned int _i)
Get a point of the polyline.
Definition: PolyLineT.hh:148
void setManipulatorDirection(int _objectId, Vector _directionX, Vector _directionY)
Set the direction of the manipulator.
void translateVertexSelection(int _objectId, Vector _vector)
translate current vertex selection of an Object by a given vector
void objectRenderingMatrixTranslate(int _objectId, Vector _translation)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
Definition: DataTypes.hh:187
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
Matrix4x4 getObjectRenderingMatrix(int _objectId)
Gets the Object Matrix in the scenegraph.
double manip_size_
Size for the manipulators.
Definition: MovePlugin.hh:407
void ManipulatorPositionChanged(QtTranslationManipulatorNode *_node)
update object when its manipulator changes position
Definition: MovePlugin.cc:834
Vector manipulatorDirectionX(int _objectId)
Get the x-direction of the manipulator.
double manip_size_modifier_
Modifier for the Size (changed by Mousewheel Events)
Definition: MovePlugin.hh:410
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.
#define DATA_BSPLINE_CURVE
Definition: BSplineCurve.hh:73
bool invert()
matrix inversion (returns true on success)
Definition: Matrix4x4T.cc:297
int lastActiveManipulator_
Stores the last manipulator which has been clicked ( used for the toolbox dialog) ...
Definition: MovePlugin.hh:413
Functions for modifying a Mesh.
bool manipPlaced()
Check if the manipulator has been placed.
void translateFaceSelection(int _objectId, Vector _vector)
translate current face selection of an Object by a given vector
void transform(int _objectId, Matrix4x4 _matrix)
transform an Object by a given matrix
size_t n_vertices() const
Get number of vertices.
Definition: PolyLineT.hh:122
void transformHandleRegion(int _objectId, Matrix4x4 _matrix)
Transform handle region using the given transformation matrix.
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
Vector manipulatorDirectionY(int _objectId)
Get the y-direction of the manipulator.
HexahedralMesh * hexahedralMesh(BaseObjectData *_object)
Get an HexahedralMesh from an object.
void objectRenderingMatrixIdentity(int _objectId)
Sets the Object Matrix in the scenegraph to identity.
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x&#39;,y&#39;,z&#39;,0) = A * (x,y,z,0)
Definition: Matrix4x4T.cc:225
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.