SubdividerPlugin.cc 2.74 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

#include <QtGui>

#include "SubdividerPlugin.hh"

#include <iostream>
#include <algorithm>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/INIFile/INIFile.hh>
#include <ACG/Scenegraph/PointNode.hh>

void SubdividerPlugin::initializePlugin() 
{
  if ( OpenFlipper::Options::gui() ) {
    tool_ = new subdividerToolbarWidget();
    QSize size(300, 300);
    tool_->resize(size);
    
    connect(tool_->subdivide_toolButton,    SIGNAL( clicked() ),  this, SLOT( slot_subdivide() ) );
    
    emit addToolbox( tr("Subdivider") , tool_ );
  }
}

void SubdividerPlugin::slotPickModeChanged( const std::string& /*_mode*/) 
{
}

void SubdividerPlugin::pluginsInitialized() 
{
}

//-----------------------------------------------------------------------------

void SubdividerPlugin::slot_subdivide()
{
  std::vector< int > ids;
  if ( PluginFunctions::getTargetIdentifiers( ids ) )
  {
    for (unsigned int i = 0; i < ids.size(); ++i)
    {
      BaseObjectData* object;
      if(!test_trimesh_object(ids[i], object))
        return;

      int steps  = tool_->subdivision_steps_spinBox->value();
      TriMesh* mesh = PluginFunctions::triMesh(object);

      if(tool_->loop_radioButton->isChecked())
      {
        OpenMesh::Subdivider::Uniform::LoopT<TriMesh,double> subdivider;
        
        subdivider.attach(*mesh);
        subdivider(steps);
        subdivider.detach();
      }
      else
      {
        OpenMesh::Subdivider::Uniform::Sqrt3T<TriMesh,double> subdivider;
        
        subdivider.attach(*mesh);
        subdivider(steps);
        subdivider.detach();
      }

      mesh->update_face_normals();
      mesh->update_vertex_normals();
      TriMeshObject* tmo = PluginFunctions::triMeshObject(object);
      tmo->update();
    
      // Create backup
      emit createBackup(object->id(), "Subdivider");
      emit updatedObject(object->id(), UPDATE_TOPOLOGY);
    }
  }
  emit updateView();
}


//-----------------------------------------------------------------------------


bool SubdividerPlugin::test_trimesh_object(int _identifier, BaseObjectData*& _object)
{
  if ( _identifier == -1)
    return false;

  if (! PluginFunctions::getObject(_identifier,_object) ) 
    return false;  

  if (!_object->dataType(DATA_TRIANGLE_MESH) )
    return false;
  return true;
}


//-----------------------------------------------------------------------------

void SubdividerPlugin::slotMouseEvent( QMouseEvent* /*_event*/ )
{
}

//-----------------------------------------------------------------------------

void SubdividerPlugin::slotKeyEvent( QKeyEvent* _event )
{
  switch (_event->key()) 
  {
    default:
      break;
  }
} // END slotKeyEvent

Q_EXPORT_PLUGIN2( subdividerplugin , SubdividerPlugin );