50 #include "TypePolyhedralMesh.hh"
54 TypePolyhedralMeshPlugin::TypePolyhedralMeshPlugin() :
56 translucency_factor_action_(NULL),
58 scalingFactorSpinBox_(NULL),
59 translucencyFactorSpinBox_(NULL),
60 renderBoundaryCheckBox_(NULL),
61 scalingFactorSettingName_(name() + QString(
"/CellScalingFactor")),
62 translucencyFactorSettingName_(name() + QString(
"/TranslucencyFactor")),
63 renderBoundarySettingName_(name() + QString(
"/RenderBoundaryOnly"))
67 bool TypePolyhedralMeshPlugin::registerType() {
69 addDataType(
"PolyhedralMesh", tr(
"Polyhedral Volume Mesh"));
70 setTypeIcon(
"PolyhedralMesh",
"PolyVolMeshType.png");
76 void TypePolyhedralMeshPlugin::pluginsInitialized() {
78 if(OpenFlipper::Options::nogui())
return;
80 emit
registerKey(Qt::Key_F8, Qt::ShiftModifier,
"Set scaling of cell shrinkage");
82 QMenu* menu =
new QMenu(
"Polyhedral Mesh Options");
85 QAction* act_scale_cells =
new QAction(tr(
"Scale cells (Shift-F8)"),
this);
86 act_scale_cells->setStatusTip(tr(
"Scale cells (Shift-F8)"));
87 connect(act_scale_cells, SIGNAL( triggered() ),
this, SLOT( slot_change_shrinkage() ));
88 menu->addAction(act_scale_cells);
91 render_switch_ =
new QAction(tr(
"Render Boundary Only"),
this);
92 render_switch_->setStatusTip(tr(
"Render Boundary Only"));
93 render_switch_->setCheckable(
true);
94 render_switch_->setChecked(
OpenFlipperSettings().value(renderBoundarySettingName_,
false).toBool());
95 connect(render_switch_, SIGNAL( triggered() ),
this, SLOT( switchRendering() ));
96 menu->addAction(render_switch_);
98 translucency_factor_action_ =
new QAction(tr(
"Set Translucency Factor"),
this);
99 translucency_factor_action_->setStatusTip(tr(
"Set Translucency Factor"));
100 translucency_factor_action_->setCheckable(
false);
101 connect(translucency_factor_action_, SIGNAL( triggered() ),
this, SLOT( setTranslucencyFactor() ));
102 menu->addAction(translucency_factor_action_);
109 int TypePolyhedralMeshPlugin::addEmpty() {
116 object->target(
true);
121 object->target(
true);
125 object->target(
true);
128 QString
name = QString(tr(
"New PolyHedral Mesh %1.ovm").arg( object->
id() ));
132 object->setName(f.fileName());
138 const QColor color = OpenFlipper::Options::defaultColor();
139 const ACG::Vec4f default_color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
140 object->materialNode()->set_color(default_color);
143 if(OpenFlipper::Options::gui())
145 object->meshNode()->set_scaling(
OpenFlipperSettings().value(scalingFactorSettingName_, 0.8).toDouble());
146 object->meshNode()->set_translucency_factor(
OpenFlipperSettings().value(translucencyFactorSettingName_, 0.1f).toFloat());
155 emit emptyObjectAdded(object->
id());
163 void TypePolyhedralMeshPlugin::slotKeyEvent(QKeyEvent* _event) {
165 switch (_event->key()) {
167 if (_event->modifiers() & Qt::ShiftModifier)
168 slot_change_shrinkage();
177 void TypePolyhedralMeshPlugin::slotObjectUpdated(
int _identifier,
const UpdateType& _type) {
184 slot_update_planes_in_scenegraph_node();
189 void TypePolyhedralMeshPlugin::objectDeleted(
int _identifier) {
193 slot_update_planes_in_scenegraph_node(_identifier);
199 void TypePolyhedralMeshPlugin::switchRendering() {
201 QVariant contextObject = render_switch_->data();
202 int objectId = contextObject.toInt();
214 polyMeshObject->
meshNode()->set_boundary_only(render_switch_->isChecked());
215 polyMeshObject->
meshNode()->set_geometry_changed(
true);
221 void TypePolyhedralMeshPlugin::setTranslucencyFactor() {
223 QVariant contextObject = translucency_factor_action_->data();
224 int objectId = contextObject.toInt();
238 float val = polyMeshObject->
meshNode()->translucency_factor();
239 double factor = QInputDialog::getDouble(0, tr(
"Set translucency factor"), tr(
"Factor [0, 1]:"), val,
243 polyMeshObject->
meshNode()->set_translucency_factor(static_cast<float>(factor));
249 void TypePolyhedralMeshPlugin::slot_update_planes_in_scenegraph_node(
int _deletedObject) {
252 std::vector<Plane> planes;
258 if(o_it->id() == _deletedObject)
continue;
267 planes.push_back(Plane(p, n, x, y));
275 for (
unsigned int i = 0; i < planes.size(); ++i) {
287 void TypePolyhedralMeshPlugin::slot_change_shrinkage() {
294 double scale = QInputDialog::getDouble(0, tr(
"Set singularity scaling for cell shrinkage"), tr(
"Size * :"), val,
308 if (!optionsWidget_) {
310 optionsWidget_ =
new QWidget;
311 QFormLayout* layout =
new QFormLayout;
313 scalingFactorSpinBox_ =
new QDoubleSpinBox;
314 scalingFactorSpinBox_->setRange(0.0, 1.0);
315 scalingFactorSpinBox_->setDecimals(2);
316 scalingFactorSpinBox_->setSingleStep(0.01);
318 translucencyFactorSpinBox_ =
new QDoubleSpinBox;
319 translucencyFactorSpinBox_->setRange(0.0, 1.0);
320 translucencyFactorSpinBox_->setDecimals(2);
321 translucencyFactorSpinBox_->setSingleStep(0.01);
323 renderBoundaryCheckBox_ =
new QCheckBox(tr(
"Render boundary only"), optionsWidget_);
325 layout->addRow(
new QLabel(tr(
"Default cell scaling factor")), scalingFactorSpinBox_);
326 layout->addRow(
new QLabel(tr(
"Default translucency factor")), translucencyFactorSpinBox_);
327 layout->addRow(renderBoundaryCheckBox_);
329 optionsWidget_->setLayout(layout);
336 scalingFactorSpinBox_->setValue(scalingFactor);
337 translucencyFactorSpinBox_->setValue(translucencyFactor);
338 renderBoundaryCheckBox_->setChecked(renderBoundary);
340 _widget = optionsWidget_;
347 void TypePolyhedralMeshPlugin::applyOptions()
354 #if QT_VERSION < 0x050000
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
ACG::Vec3d position()
get center position of the plane
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
const QStringList ALL_OBJECTS
Iterable object range.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
int targetCount()
Get the number of target objects.
#define DATA_POLYHEDRAL_MESH
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
virtual void updateView()
Update current view in Main Application.
bool getObject(int _identifier, BSplineCurveObject *&_object)
virtual void updatedObject(int _objectId)
An object has been changed or added by this plugin.
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
VectorT< double, 3 > Vec3d
const QStringList TARGET_OBJECTS("target")
Iterable object range.
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
QString name()
Return a name for the plugin.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
ACG::Vec3d xDirection()
local x direction (multiplied with width)
VolumeMeshObject< PolyhedralMesh > PolyhedralMeshObject
Typedef for a mesh object containing a polyhedral mesh.
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
bool initializeOptionsWidget(QWidget *&_widget)
Initialize the Options Widget.
PlaneNode * planeNode(BaseObjectData *_object)
Get a PlaneNode from an object.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
virtual void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse=false)
Register a key-combination for your plugin.
ACG::Vec3d normal()
get current normal
The Menu will be shown when an object was picked.
int objectCount()
Get the number of available objects.
ACG::Vec3d yDirection()
local y direction (multiplied with height)
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...