43 #include "TypePolyhedralMesh.hh" 49 #include <QInputDialog> 50 #include <QFormLayout> 53 TypePolyhedralMeshPlugin::TypePolyhedralMeshPlugin() :
55 translucency_factor_action_(NULL),
57 scalingFactorSpinBox_(NULL),
58 translucencyFactorSpinBox_(NULL),
59 renderBoundaryCheckBox_(NULL),
60 scalingFactorSettingName_(name() + QString(
"/CellScalingFactor")),
61 translucencyFactorSettingName_(name() + QString(
"/TranslucencyFactor")),
62 renderBoundarySettingName_(name() + QString(
"/RenderBoundaryOnly"))
66 bool TypePolyhedralMeshPlugin::registerType() {
68 addDataType(
"PolyhedralMesh", tr(
"Polyhedral Volume Mesh"));
69 setTypeIcon(
"PolyhedralMesh",
"PolyVolMeshType.png");
75 void TypePolyhedralMeshPlugin::pluginsInitialized() {
77 if(OpenFlipper::Options::nogui())
return;
79 emit
registerKey(Qt::Key_F8, Qt::ShiftModifier,
"Set scaling of cell shrinkage");
81 QMenu* menu =
new QMenu(
"Polyhedral Mesh Options");
84 QAction* act_scale_cells =
new QAction(tr(
"Scale cells (Shift-F8)"),
this);
85 act_scale_cells->setStatusTip(tr(
"Scale cells (Shift-F8)"));
86 connect(act_scale_cells, SIGNAL( triggered() ),
this, SLOT( slot_change_shrinkage() ));
87 menu->addAction(act_scale_cells);
90 render_switch_ =
new QAction(tr(
"Render Boundary Only"),
this);
91 render_switch_->setStatusTip(tr(
"Render Boundary Only"));
92 render_switch_->setCheckable(
true);
93 render_switch_->setChecked(
OpenFlipperSettings().value(renderBoundarySettingName_,
false).toBool());
94 connect(render_switch_, SIGNAL( triggered() ),
this, SLOT( switchRendering() ));
95 menu->addAction(render_switch_);
97 translucency_factor_action_ =
new QAction(tr(
"Set Translucency Factor"),
this);
98 translucency_factor_action_->setStatusTip(tr(
"Set Translucency Factor"));
99 translucency_factor_action_->setCheckable(
false);
100 connect(translucency_factor_action_, SIGNAL( triggered() ),
this, SLOT( setTranslucencyFactor() ));
101 menu->addAction(translucency_factor_action_);
108 int TypePolyhedralMeshPlugin::addEmpty() {
115 object->target(
true);
120 object->target(
true);
124 object->target(
true);
127 QString
name = QString(tr(
"New PolyHedral Mesh %1.ovm").arg( object->
id() ));
131 object->setName(f.fileName());
137 const QColor color = OpenFlipper::Options::defaultColor();
138 const ACG::Vec4f default_color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
139 object->materialNode()->set_color(default_color);
142 if(OpenFlipper::Options::gui())
144 object->meshNode()->set_scaling(
OpenFlipperSettings().value(scalingFactorSettingName_, 0.8).toDouble());
145 object->meshNode()->set_translucency_factor(
OpenFlipperSettings().value(translucencyFactorSettingName_, 0.1f).toFloat());
154 emit emptyObjectAdded(object->
id());
162 void TypePolyhedralMeshPlugin::slotKeyEvent(QKeyEvent* _event) {
164 switch (_event->key()) {
166 if (_event->modifiers() & Qt::ShiftModifier)
167 slot_change_shrinkage();
176 void TypePolyhedralMeshPlugin::slotObjectUpdated(
int _identifier,
const UpdateType& _type) {
183 slot_update_planes_in_scenegraph_node();
188 void TypePolyhedralMeshPlugin::objectDeleted(
int _identifier) {
192 slot_update_planes_in_scenegraph_node(_identifier);
198 void TypePolyhedralMeshPlugin::switchRendering() {
200 QVariant contextObject = render_switch_->data();
201 int objectId = contextObject.toInt();
213 polyMeshObject->
meshNode()->set_boundary_only(render_switch_->isChecked());
214 polyMeshObject->
meshNode()->set_geometry_changed(
true);
220 void TypePolyhedralMeshPlugin::setTranslucencyFactor() {
222 QVariant contextObject = translucency_factor_action_->data();
223 int objectId = contextObject.toInt();
237 float val = polyMeshObject->
meshNode()->translucency_factor();
238 double factor = QInputDialog::getDouble(0, tr(
"Set translucency factor"), tr(
"Factor [0, 1]:"), val,
242 polyMeshObject->
meshNode()->set_translucency_factor(static_cast<float>(factor));
248 void TypePolyhedralMeshPlugin::slot_update_planes_in_scenegraph_node(
int _deletedObject) {
250 std::vector<Plane> planes;
256 if(o_it->id() == _deletedObject)
continue;
265 planes.push_back(
Plane(p, n, x, y));
273 for (
unsigned int i = 0; i < planes.size(); ++i) {
285 void TypePolyhedralMeshPlugin::slot_change_shrinkage() {
292 double scale = QInputDialog::getDouble(0, tr(
"Set singularity scaling for cell shrinkage"), tr(
"Size * :"), val,
306 if (!optionsWidget_) {
308 optionsWidget_ =
new QWidget;
309 QFormLayout* layout =
new QFormLayout;
311 scalingFactorSpinBox_ =
new QDoubleSpinBox;
312 scalingFactorSpinBox_->setRange(0.0, 1.0);
313 scalingFactorSpinBox_->setDecimals(2);
314 scalingFactorSpinBox_->setSingleStep(0.01);
316 translucencyFactorSpinBox_ =
new QDoubleSpinBox;
317 translucencyFactorSpinBox_->setRange(0.0, 1.0);
318 translucencyFactorSpinBox_->setDecimals(2);
319 translucencyFactorSpinBox_->setSingleStep(0.01);
321 renderBoundaryCheckBox_ =
new QCheckBox(tr(
"Render boundary only"), optionsWidget_);
323 layout->addRow(
new QLabel(tr(
"Default cell scaling factor")), scalingFactorSpinBox_);
324 layout->addRow(
new QLabel(tr(
"Default translucency factor")), translucencyFactorSpinBox_);
325 layout->addRow(renderBoundaryCheckBox_);
327 optionsWidget_->setLayout(layout);
334 scalingFactorSpinBox_->setValue(scalingFactor);
335 translucencyFactorSpinBox_->setValue(translucencyFactor);
336 renderBoundaryCheckBox_->setChecked(renderBoundary);
338 _widget = optionsWidget_;
345 void TypePolyhedralMeshPlugin::applyOptions()
#define DATA_POLYHEDRAL_MESH
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
virtual void updateView()
Update current view in Main Application.
ACG::Vec3d yDirection()
local y direction (multiplied with height)
int objectCount()
Get the number of available objects.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
VolumeMeshObject< PolyhedralMesh > PolyhedralMeshObject
Typedef for a mesh object containing a polyhedral mesh.
ACG::Vec3d xDirection()
local x direction (multiplied with width)
const QStringList ALL_OBJECTS
Iterable object range.
PlaneNode * planeNode(BaseObjectData *_object)
Get a PlaneNode from an object.
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
ACG::Vec3d position()
get center position of the plane
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
int targetCount()
Get the number of target objects.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
QString name()
Return a name for the plugin.
virtual void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse=false)
Register a key-combination for your plugin.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
decltype(std::declval< S >() *std::declval< S >()) sqrnorm() const
compute squared euclidean norm
bool initializeOptionsWidget(QWidget *&_widget)
Initialize the Options Widget.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
ACG::Vec3d normal()
get current normal
VectorT< double, 3 > Vec3d