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
virtual void updatedObject(int _objectId)
An object has been changed or added by this plugin.
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
ACG::Vec3d xDirection()
local x direction (multiplied with width)
bool getObject(int _identifier, BSplineCurveObject *&_object)
const QStringList TARGET_OBJECTS("target")
Iterable object range.
The Menu will be shown when an object was picked.
#define DATA_POLYHEDRAL_MESH
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
const QStringList ALL_OBJECTS
Iterable object range.
bool initializeOptionsWidget(QWidget *&_widget)
Initialize the Options Widget.
QString name()
Return a name for the plugin.
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
int objectCount()
Get the number of available objects.
PlaneNode * planeNode(BaseObjectData *_object)
Get a PlaneNode from an object.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
ACG::Vec3d position()
get center position of the plane
ACG::Vec3d normal()
get current normal
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
virtual void updateView()
Update current view in Main Application.
int targetCount()
Get the number of target objects.
decltype(std::declval< S >()*std::declval< S >()) sqrnorm() const
compute squared euclidean norm
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
VolumeMeshObject< PolyhedralMesh > PolyhedralMeshObject
Typedef for a mesh object containing a polyhedral mesh.
VectorT< double, 3 > Vec3d
ACG::Vec3d yDirection()
local y direction (multiplied with height)
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.