50 #include "BSplineSurfaceSelectionPlugin.hh" 55 #define CONTROL_POINT_TYPE "bscontrolpointselection.png" 56 #define KNOT_TYPE "bsknotselection.png" 61 #define G_CP_MODE "Control Point Selection View" 62 #define G_K_MODE "Knot Selection View" 65 #define CP_SELECT_ALL "Select All Control Points" 66 #define CP_DESELECT_ALL "Deselect All Control Points" 67 #define CP_INVERT "Invert Control Point Selection" 72 #define K_SELECT_ALL "Select All Knots" 73 #define K_DESELECT_ALL "Deselect All Knots" 74 #define K_INVERT "Invert Knot Selection" 82 allSupportedTypes_(0) {
92 void BSplineSurfaceSelectionPlugin::initializePlugin() {
100 void BSplineSurfaceSelectionPlugin::pluginsInitialized() {
104 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
106 emit addSelectionEnvironment(
"B-Spline Surface Selections",
"Select B-Spline surface primitives.",
121 QStringList generalOperations;
122 generalOperations.append(G_CP_MODE);
123 generalOperations.append(G_K_MODE);
126 QStringList controlPointOperations;
127 controlPointOperations.append(CP_SELECT_ALL);
128 controlPointOperations.append(CP_DESELECT_ALL);
131 controlPointOperations.append(CP_INVERT);
133 QStringList knotOperations;
134 knotOperations.append(K_SELECT_ALL);
135 knotOperations.append(K_DESELECT_ALL);
138 knotOperations.append(K_INVERT);
140 emit addSelectionOperations(
environmentHandle_, generalOperations,
"Selection Operations");
147 emit registerKeyShortcut(Qt::Key_A, Qt::ControlModifier);
149 emit registerKeyShortcut(Qt::Key_C, Qt::NoModifier);
151 emit registerKeyShortcut(Qt::Key_I, Qt::NoModifier);
158 emit setSlotDescription(
"selectAllControlPoints(int)", tr(
"Select all control points of a B-spline surface"),
159 QStringList(
"objectId"), QStringList(
"Id of object"));
160 emit setSlotDescription(
"deselectAllControlPoints(int)", tr(
"Deselect all control points of a B-spline surface"),
161 QStringList(
"objectId"), QStringList(
"Id of object"));
162 emit setSlotDescription(
"invertControlPointSelection(int)", tr(
"Invert control point selection"),
163 QStringList(
"objectId"), QStringList(
"Id of object"));
164 emit setSlotDescription(
"deleteSelectedControlPoints(int)", tr(
"Delete selected control points"),
165 QStringList(
"objectId"), QStringList(
"Id of object"));
166 emit setSlotDescription(
"selectControlPoints(int,IdList)", tr(
"Select the specified control points"),
167 QString(
"objectId,control pointList").split(
","), QString(
"Id of object,List of control points").split(
","));
169 emit setSlotDescription(
"loadSelection(int,QString)", tr(
"Load selection from selection file"),
170 QString(
"objectId,filename").split(
","), QString(
"Id of an object,Selection file").split(
","));
172 emit setSlotDescription(
"selectAllKnots(int)", tr(
"Select all knots of a B-spline surface"),
173 QStringList(
"objectId"), QStringList(
"Id of object"));
174 emit setSlotDescription(
"deselectAllKnots(int)", tr(
"Deselect all knots of a B-spline surface"),
175 QStringList(
"objectId"), QStringList(
"Id of object"));
176 emit setSlotDescription(
"invertKnotSelection(int)", tr(
"Invert knot selection"),
177 QStringList(
"objectId"), QStringList(
"Id of object"));
178 emit setSlotDescription(
"deleteSelectedKnots(int)", tr(
"Delete selected knots"),
179 QStringList(
"objectId"), QStringList(
"Id of object"));
180 emit setSlotDescription(
"selectKnots(int,IdList)", tr(
"Select the specified knots"),
181 QString(
"objectId,knotList").split(
","), QString(
"Id of object,List of knots").split(
","));
188 SelectionInterface::PrimitiveType type = 0u;
189 emit getActivePrimitiveType(type);
195 bool targetsOnly =
false;
196 emit targetObjectsOnly(targetsOnly);
200 if(_operation == G_CP_MODE) {
203 }
else if(_operation == G_K_MODE) {
206 }
else if(_operation == CP_SELECT_ALL) {
210 if (o_it->visible()) {
215 emit createBackup(o_it->id(),
"Select All Controlpoints",
UPDATE_SELECTION);
217 }
else if (_operation == CP_DESELECT_ALL) {
221 if (o_it->visible()) {
226 emit createBackup(o_it->id(),
"Deselect All Controlpoints",
UPDATE_SELECTION);
228 }
else if (_operation == CP_INVERT) {
232 if (o_it->visible()) {
237 emit createBackup(o_it->id(),
"Invert Controlpoint Selection",
UPDATE_SELECTION);
259 }
else if(_operation == K_SELECT_ALL) {
263 if (o_it->visible()) {
270 }
else if (_operation == K_DESELECT_ALL) {
274 if (o_it->visible()) {
281 }
else if (_operation == K_INVERT) {
285 if (o_it->visible()) {
324 size_t node_idx, target_idx;
340 if ( target_idx < max) {
345 if (bsso->
splineSurface()->controlpoint_selected(idx_m, idx_n) || _deselect) {
361 size_t node_idx, target_idx;
389 double minu = knotvec_u->getKnot(bss->
degree_m());
390 double minv = knotvec_v->getKnot(bss->
degree_n());
391 double maxu = knotvec_u->getKnot(numKnots_m - order_m);
392 double maxv = knotvec_v->getKnot(numKnots_n - order_n);
394 double udiff = maxu - minu;
395 double vdiff = maxv - minv;
398 double curu = double (target_idx / texres) / double(texres) * udiff + minu;
399 double curv = double (target_idx % texres) / double(texres) * vdiff + minv;
407 int knotIdx_m = interval_m[0];
408 int knotIdx_n = interval_n[0];
440 if(_event->type() == QEvent::MouseButtonPress) {
443 QPoint p(_event->pos().x(), state.
viewport_height() - _event->pos().y());
449 }
else if(_event->type() == QEvent::MouseButtonDblClick) {
455 bool targetsOnly =
false;
456 emit targetObjectsOnly(targetsOnly);
464 if (o_it->visible()) {
483 QPoint p((
int)pc[0], (
int)pc[1]);
484 if(polygon.containsPoint(p, Qt::OddEvenFill)) {
486 surface->deselect_controlpoint(i,j);
488 surface->select_controlpoint(i,j);
506 int order_m = surface->
degree_m() + 1;
507 int order_n = surface->
degree_n() + 1;
514 if(surface->
degree_m() == 0)
return;
515 if(surface->
degree_n() == 0)
return;
517 if((
int)surface->
n_knots_m() <= ((numKnots_m - order_m) + 1))
return;
518 if((
int)surface->
n_knots_n() <= ((numKnots_n - order_n) + 1))
return;
520 for(
int i = surface->
degree_m()-1; i < (numKnots_m - order_m)-1; ++i) {
521 for(
int j = surface->
degree_n()-1; j < (numKnots_n - order_n)-1; ++j) {
523 double baseKnot_m = knotvec_m->getKnot(i+1);
524 double baseKnot_n = knotvec_n->getKnot(j+1);
526 double dhalfu = 0.5*(knotvec_m->getKnot(i+2) - baseKnot_m);
527 double dhalfv = 0.5*(knotvec_n->getKnot(j+2) - baseKnot_n);
529 double t_u = baseKnot_m + dhalfu;
530 double t_v = baseKnot_n + dhalfv;
535 QPoint p((
int)pcp[0], (
int)pcp[1]);
537 if(polygon.containsPoint(p, Qt::OddEvenFill)) {
539 knotvec_m->deselect(i+1);
540 knotvec_n->deselect(j+1);
542 knotvec_m->select(i+1);
543 knotvec_n->select(j+1);
563 void BSplineSurfaceSelectionPlugin::loadSelection(
int _objId,
const QString& _filename) {
568 if(!file.
connect(_filename,
false)) {
569 emit log(
LOGERR, QString(
"Could not read file '%1'!").arg(_filename));
574 loadIniFile(file, _objId);
579 void BSplineSurfaceSelectionPlugin::loadIniFile(
INIFile& _ini,
int _id) {
586 void BSplineSurfaceSelectionPlugin::saveIniFile(
INIFile& _ini,
int _id) {
602 QString section = QString(
"BSplineSurfaceSelection") +
"//" + o_it->name();
607 std::vector<int> ids;
609 _file.
get_entry(ids, section,
"ControlPointSelection");
613 std::vector<int> ids_u;
614 std::vector<int> ids_v;
616 _file.
get_entry(ids_u, section,
"KnotSelection_u");
617 _file.
get_entry(ids_v, section,
"KnotSelection_v");
639 QString section = QString(
"BSplineSurfaceSelection") +
"//" + o_it->name();
653 SelectionInterface::PrimitiveType type = 0u;
654 emit getActivePrimitiveType(type);
661 bool targetsOnly =
false;
662 emit targetObjectsOnly(targetsOnly);
666 if(_key == Qt::Key_A && _modifiers == Qt::ControlModifier) {
670 if (o_it->visible()) {
677 }
else if(_key == Qt::Key_C && _modifiers == Qt::NoModifier) {
681 if (o_it->visible()) {
688 }
else if(_key == Qt::Key_I && _modifiers == Qt::NoModifier) {
692 if (o_it->visible()) {
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
BSplineSurfaceObject * bsplineSurfaceObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineSurfaceObject if possible.
BSplineSurface * splineSurface(BaseObjectData *_object)
Get a Bspline Surface from an object.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
int degree_m() const
Returns the spline degree in m direction.
void selectControlPoints(int _objectId, const IdList &_ids, bool _deselect=false)
Delete selected control points.
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
IdList getKnotSelectionU(int _objectId)
Get current knot selection.
unsigned int n_control_points_n() const
Returns the number of controlpoints in n direction.
BSplineSurface * splineSurface()
return a pointer to the spline curve
void invertControlPointSelection(int _objectId)
Invert control point selection.
void selectKnots(int _objectId, const IdList &_ids_u, const IdList &_ids_v, bool _deselect=false)
Select specific knots of a curve.
void updateSlotDescriptions()
Set slot descriptions for scripting functions.
ACG::Vec2i interval_n(double _t)
Returns the index of the knots v and v+1 such that t in [v, v+1)
unsigned int n_control_points_m() const
Returns the number of controlpoints in m direction.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
const QStringList ALL_OBJECTS
Iterable object range.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
ACG::Vec2i interval_m(double _t)
Returns the index of the knots u and u+1 such that t in [u, u+1)
Point surfacePoint(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
QVector< QPoint > volumeLassoPoints_
Keep volume lasso points.
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode()
Return pointer to the bspline surface node.
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
void selectAllKnots(int _objectId)
Select all knots of a curve.
void deselectAllKnots(int _objectId)
Deselect all knots of a curve.
void deselectAllControlPoints(int _objectId)
Deselect all control points of a curve.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void setSelectionViewMode(const SelectionViewMode _mode)
Change selection view mode for every B-spline surface in the scene.
unsigned int n_knots_n()
Returns the number of knots in n direction.
#define DATA_BSPLINE_SURFACE
void selectAllControlPoints(int _objectId)
Select all control points of a curve.
bool controlpoint_selections_available() const
Check if control point selection property is available.
picks verices (may not be implemented for all nodes)
unsigned int n_knots_m()
Returns the number of knots in m direction.
void invertKnotSelection(int _objectId)
Invert knot selection.
int viewport_height() const
get viewport height
IdList getControlPointSelection(int _objectId)
Get current control point selection.
~BSplineSurfaceSelectionPlugin()
Default destructor.
IdList getKnotSelectionV(int _objectId)
Select all control points of a curve.
BSplineSurfaceSelectionPlugin()
Default constructor.
QStringList IteratorRestriction
Iterable object range.
void slotSelectionOperation(QString _operation)
A specific operation is requested.
SelectionViewMode
Change selection view mode for every B-spline surface in the scene.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
Class for the handling of simple configuration files.
unsigned int controlPointType_
Primitive type handles:
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
unsigned int allSupportedTypes_
Handle to selection environment.
Pick spline curve or surface (picks u or u,v coords respectively)
int degree_n() const
Returns the spline degree in n direction.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Point & get_control_point(unsigned int _m, unsigned int _n)
Returns a reference to the control point (m, n)
QString environmentHandle_
Handle to selection environment.
unsigned int knotType_
Handle to selection environment.
ACG::GLState & glState()
Get the glState of the Viewer.