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