SubdividerPlugin.cc 3.57 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

#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>

14
15
16
17
18
#include <OpenMesh/Tools/Subdivider/Uniform/LoopT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3T.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3InterpolatingSubdividerLabsikGreinerT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh>

Jan Möbius's avatar
 
Jan Möbius committed
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
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();
      }
64
      else if ( tool_->sqrt3_radioButton->isChecked() )
Jan Möbius's avatar
 
Jan Möbius committed
65
66
67
68
69
70
71
      {
        OpenMesh::Subdivider::Uniform::Sqrt3T<TriMesh,double> subdivider;
        
        subdivider.attach(*mesh);
        subdivider(steps);
        subdivider.detach();
      }
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
      else if ( tool_->LabsikGreiner_radioButton->isChecked()  )
      {
        OpenMesh::Subdivider::Uniform::InterpolatingSqrt3LGT<TriMesh,double> subdivider;
        
        subdivider.attach(*mesh);
        subdivider(steps);
        subdivider.detach();
      }
      else if ( tool_->modifiedButterfly_radioButton->isChecked()  )
      {
        OpenMesh::Subdivider::Uniform::ModifiedButterflyT<TriMesh,double> subdivider;
        
        subdivider.attach(*mesh);
        subdivider(steps);
        subdivider.detach();
      }

Jan Möbius's avatar
 
Jan Möbius committed
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

      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

138
Q_EXPORT_PLUGIN2( subdividerplugin , SubdividerPlugin );