diff --git a/InteractionFields/InteractionFields.pro.user b/InteractionFields/InteractionFields.pro.user index 5a21ba9995b7b54fa870ef9c1329187ea3db3636..2e5799729403eb00d420ee7235493378138e07be 100644 --- a/InteractionFields/InteractionFields.pro.user +++ b/InteractionFields/InteractionFields.pro.user @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 4.11.1, 2022-02-24T18:48:22. --> +<!-- Written by QtCreator 4.11.1, 2022-02-25T13:11:09. --> <qtcreator> <data> <variable>EnvironmentId</variable> diff --git a/InteractionFields/layerviewer.cpp b/InteractionFields/layerviewer.cpp index 66062f8f892e3b942df89777ec174686796198c1..889e01b674578217c984b6a95ef446d5d07323ae 100644 --- a/InteractionFields/layerviewer.cpp +++ b/InteractionFields/layerviewer.cpp @@ -18,12 +18,19 @@ +/** + * @brief + * + * @param width_ + * @param height_ + * @param matrix_ + * @param parent + */ LayerViewer::LayerViewer(float width_, float height_, VectorMatrix *matrix_, QGraphicsItem *parent ) :QGraphicsItemGroup(parent) { setFlag(QGraphicsItem::ItemIsSelectable , true); - setFlag(ItemSendsGeometryChanges); setCacheMode(DeviceCoordinateCache); setFlag(QGraphicsItem::ItemIsMovable, false); @@ -33,8 +40,6 @@ LayerViewer::LayerViewer(float width_, float height_, VectorMatrix *matrix_, QGr border = QRectF(0,0, width_, height_); myPenWidth = std::min(border.width(), border.height())/10.0f * 0.05; zerosArea = std::vector<std::array<int,2>>(); - - } LayerViewer::LayerViewer(float width_, float height_, QGraphicsItem *parent) diff --git a/InteractionFields/renderarea.cpp b/InteractionFields/renderarea.cpp index c089147eb4516d640713138f773266782c7bb080..f7799b7f1eabce59507ad1c60a1f3a0c3835730a 100644 --- a/InteractionFields/renderarea.cpp +++ b/InteractionFields/renderarea.cpp @@ -34,6 +34,13 @@ using namespace std; +/** + * @brief constructor of RenderArea + * Canvas where Interactions Fields are sketched, central scene widget. + * + * @param itemMenu menu that is showed when right cliking on some items + * @param parent QGraphicsView parent + */ RenderArea::RenderArea(QMenu *itemMenu, QWidget *parent) : QGraphicsView(parent) @@ -76,6 +83,12 @@ RenderArea::RenderArea(QMenu *itemMenu, QWidget *parent) } +/** + * @brief + * + * @param fileName + * @return bool + */ bool RenderArea::openImage(const QString &fileName) // not used for now //! [1] //! [2] { @@ -91,6 +104,13 @@ bool RenderArea::openImage(const QString &fileName) // not used for now return true; } +/** + * @brief + * + * @param fileName + * @param fileFormat + * @return bool + */ bool RenderArea::saveImage(const QString &fileName, const char *fileFormat) { QImage visibleImage = image; @@ -105,6 +125,11 @@ bool RenderArea::saveImage(const QString &fileName, const char *fileFormat) } //! [2] +/** + * @brief load a field + * + * @param isContinuous if the field was saved as list of control curved or a matrix + */ void RenderArea::loadField(bool isContinuous)//load a field in txt format { const QString path = "../examples/interactionFields/matrix/"; @@ -123,17 +148,11 @@ void RenderArea::loadField(bool isContinuous)//load a field in txt format layers[layerID]->getCurrentLayer()->generateMatrix(brushIntensity); if(isContinuous) generateMatrixFromFileQuick(path+nameCv); - else generateMatrixFromFile(file); - - - } - layers[layerID]->setParameter(param); string a; - } else{ QString name = layers[layerID]->getName()+".txt"; @@ -147,7 +166,11 @@ void RenderArea::loadField(bool isContinuous)//load a field in txt format addLayerDisplayed(); drawComparingMatrix(); } - void RenderArea::generate()//nuild the matrix of the field and create each vectors accoding to the control curves + /** + * @brief generate matrix of the current layer viewer + *build the matrix of the field and create each vectors accoding to the control curves + */ + void RenderArea::generate() { for(auto &layer: getLayers()){ @@ -164,7 +187,12 @@ void RenderArea::loadField(bool isContinuous)//load a field in txt format //apply(); apply to the simulation scene } -bool RenderArea::apply()//save the field +/** + * @brief save the changes of the fields + * + * @return bool + */ +bool RenderArea::apply() { if (getLayers()[getLayerID()]->getHasSource()!=false ) @@ -203,6 +231,11 @@ bool RenderArea::apply()//save the field +/** + * @brief + * + * @param newColor + */ void RenderArea::setPenColor(const QColor &newColor) //! [5] //! [6] { @@ -211,6 +244,11 @@ void RenderArea::setPenColor(const QColor &newColor) //! [6] //! [7] +/** + * @brief + * + * @param newWidth + */ void RenderArea::setPenWidth(float newWidth) //! [7] //! [8] { @@ -219,6 +257,11 @@ void RenderArea::setPenWidth(float newWidth) //! [8] +/** + * @brief + * + * @param layer + */ void RenderArea::addLayer(LayerGroup *layer) { scene()->addItem(layer); @@ -228,6 +271,10 @@ void RenderArea::addLayer(LayerGroup *layer) } //! [9] +/** + * @brief clear the canvas + * + */ void RenderArea::clearImage()// clear the canvas //! [9] //! [10] { @@ -254,6 +301,13 @@ void RenderArea::clearImage()// clear the canvas //! [6] +/** + * @brief + * start scribble lines or curves + * insert an item + * use eraser or brush + * @param event + */ void RenderArea::mousePressEvent(QMouseEvent *event) { myPenWidth=layers[layerID]->getCurrentLayer()->getMyPenWidth(); @@ -351,9 +405,17 @@ void RenderArea::mousePressEvent(QMouseEvent *event) //! [9] //! [10] +/** + * @brief + * update the scribble line, the preview lines, moving item. + * update the vectors magntiude under the brush tool + * add the vectors to the zero area + * redraw the matrix + * @param event + */ void RenderArea::mouseMoveEvent(QMouseEvent *event) { - + //take into account only of the mouse is pressed and inseid the scene if(myMode!= MoveItem &&(!sceneRect().contains(mapToScene(event->pos()))|| !layers[layerID]->getCurrentLayer()->getBorder().contains((mapToScene(event->pos()))))){ //setCursor(Qt::ArrowCursor); return; @@ -443,6 +505,11 @@ void RenderArea::mouseMoveEvent(QMouseEvent *event) //! [10] //! [11] +/** + * @brief add control curves, lines or links and move items + * + * @param event + */ void RenderArea::mouseReleaseEvent(QMouseEvent *event) { if (event->button() != Qt::LeftButton){ @@ -464,7 +531,7 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *event) return; } - if (line != nullptr && myMode == InsertLink) { + if (line != nullptr && myMode == InsertLink) { //add the link to the scene QList<QGraphicsItem *> startItems = scene()->items(line->line().p1()); if (startItems.count() && startItems.first() == line) startItems.removeFirst(); @@ -512,11 +579,8 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *event) else if (myMode == InsertCurve){ if(scribbling==true){ - //drawLineTo(mapToScene(event->pos())); - endPoint = mapToScene(event->pos()); - - drawCurveTo(path); - + endPoint = mapToScene(event->pos());//change endPoint + drawCurveTo(path);//add control curve scene()->removeItem(scribbleLines); scene()->destroyItemGroup(scribbleLines); @@ -528,9 +592,7 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *event) } else if(line != nullptr && myMode == InsertLine) { - //scene()->addItem(new VectorLine(line().p1, line().p2, myPenWidth)); - drawCurveTo(1,line->shape()); - + drawCurveTo(1,line->shape());//add control line scene()->removeItem(line); delete line; //generate();to update the matrix each time we add an item @@ -574,6 +636,13 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *event) +/** + * @brief add a new pole to the scene + * + * @param pos position of the new pole + * @param type of the new pole: obstacle or agent + * @param source: tell if the pole is source or not + */ void RenderArea::insertPole(QPointF pos, Pole::Pole_Type type, bool source){ Pole *item = new Pole(type, myItemMenu, source); @@ -611,6 +680,16 @@ void RenderArea::insertPole(QPointF pos, Pole::Pole_Type type, bool source){ +/** + * @brief + * if key "escape": deselect all + * if key "arrow up": increase the number of nodes of the selected control curves or increase the height of the selected obstacles + * if key "arrow down": decrease the number of nodes of the selected control curves or decrease the height of the selected obstacles + * if key "arrow right": increase the width of the selected obstacles + * if key "arrow left": deccrease the width of the selected obstacles + * + * @param event + */ void RenderArea::keyPressEvent(QKeyEvent *event){ if(event->key()==Qt::Key_Escape){ @@ -716,6 +795,11 @@ void RenderArea::keyPressEvent(QKeyEvent *event){ //! [7] +/** + * @brief zoom in or zoom out + * + * @param scaleFactor + */ void RenderArea::scaleView(qreal scaleFactor) { scale(scaleFactor, scaleFactor); @@ -723,31 +807,6 @@ void RenderArea::scaleView(qreal scaleFactor) -/*QCursor RenderArea::cursorBrushUpdate() -{ - - float h =layers[layerID]->getCurrentLayer()->getWidth()/layers[layerID]->getCurrentLayer()->getMatrix()->getCols(); - QRect rect = QRect(mapFromScene(QPointF(0,0)),mapFromScene(QPointF(0,0)+QPointF(brushWidth/h,brushWidth/h))); - QGraphicsEllipseItem *ellipse =new QGraphicsEllipseItem(rect); - QColor color = QColor(); - color.setHsv(220,brushIntensity*100,250); - QPen pen = QPen(color, myPenWidth*80, Qt::SolidLine); - ellipse->setPen(pen); - QPixmap pixmap(ellipse->boundingRect().size().toSize()); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - - - painter.translate (-1 * (ellipse->boundingRect ().topLeft ())); - painter.setRenderHint(QPainter::Antialiasing); - QStyleOptionGraphicsItem option; - ellipse->paint(&painter, &option); - - - return QCursor(pixmap); - -}*/ - void RenderArea::wheelEvent(QWheelEvent *event) { @@ -757,6 +816,10 @@ void RenderArea::wheelEvent(QWheelEvent *event) +/** + * @brief show the grid of the matrix by creating lines + * + */ void RenderArea::gridShow() { QRectF border = layers[layerID]->getCurrentLayer()->getBorder(); @@ -784,6 +847,10 @@ void RenderArea::gridShow() } +/** + * @brief show the grid of the matrix by creating rectangles + * + */ void RenderArea::gridCreate(){ QRectF border = layers[layerID]->boundingRect(); float height = border.height(); @@ -807,6 +874,12 @@ void RenderArea::gridCreate(){ } } +/** + * @brief draw a matrix + * + * @param matrix: matrix to be drawn + * @param color: color in which to draw the vectors + */ void RenderArea::drawMatrix(VectorMatrix* matrix, QColor color){ QRectF border = layers[layerID]->getCurrentLayer()->getBorder(); gridShow(); @@ -856,6 +929,10 @@ void RenderArea::drawMatrix(VectorMatrix* matrix, QColor color){ } } +/** + * @brief draw the current matrix + * current matrix is the one of the current layer view of the current layergroup + */ void RenderArea::drawMatrix() { @@ -956,7 +1033,11 @@ void RenderArea::drawMatrix() } -void RenderArea::checkCombination(){ +/** + * @brief check if there are overlapping fields that need to be combined + * + */ +void RenderArea::checkCombination(){//not done yet if(layers.size()>1){ for(int i=0; i<layers.size(); i++){ for(int j=i+1 ; j<layers.size(); j++){ @@ -979,6 +1060,11 @@ void RenderArea::checkCombination(){ } +/** + * @brief read matrix from txt file + * + * @param fileName name of the txt file field + */ void RenderArea::generateMatrixFromFile(const QString &fileName) { @@ -994,7 +1080,7 @@ void RenderArea::generateMatrixFromFile(const QString &fileName) if (myfile.is_open()) { - cout << "FIle open"; + cout << "File open"; if (getline(myfile, line)) { size_t pos = 0; string token; @@ -1060,6 +1146,12 @@ void RenderArea::generateMatrixFromFile(const QString &fileName) } +/** + * @brief read matrix from txt file + * + * @param fileName fileName name of the txt file field + * @return VectorMatrix return the resulting matrix + */ VectorMatrix* RenderArea::getMatrixFromFile(const QString &fileName) { @@ -1135,7 +1227,11 @@ VectorMatrix* RenderArea::getMatrixFromFile(const QString &fileName) } -//read txt field files considering that only the control curves were seved (the continuous version) + +/** + * @brief read txt field files considering that only the control curves were saved (the continuous version) + * @param fileName fileName name of the txt file field + */ void RenderArea::generateMatrixFromFileQuick(const QString &fileName) { @@ -1279,6 +1375,10 @@ void RenderArea::generateMatrixFromFileQuick(const QString &fileName) } +/** + * @brief + * + */ void RenderArea::zoomIn() { @@ -1286,12 +1386,22 @@ void RenderArea::zoomIn() } +/** + * @brief + * + */ void RenderArea::zoomOut() { scaleView(1 / qreal(1.2)); } //! [6] +/** + * @brief + * + * @param painter + * @param rect + */ void RenderArea::drawBackground(QPainter *painter, const QRectF &rect) { Q_UNUSED(rect); @@ -1316,6 +1426,15 @@ void RenderArea::drawBackground(QPainter *painter, const QRectF &rect) +/** + * @brief update the field according to the source's size change + * the curve change according to the change of the obstacle's change + * @param center current center of the source obstacle + * @param height current height of the obstacle + * @param width current wdith of the obstacle + * @param offsetH difference between the new and old height + * @param offsetW difference between the new and old width + */ void RenderArea::updateObstacleSize(QPointF center, float height, float width, float offsetH, float offsetW) { //if the obstacle size change the control curve change accordingly @@ -1360,21 +1479,41 @@ void RenderArea::updateObstacleSize(QPointF center, float height, float width, f //} //! [16] +/** + * @brief + * + * @return float + */ float RenderArea::getBrushIntensity() const { return brushIntensity; } +/** + * @brief + * + * @param value + */ void RenderArea::setBrushIntensity(float value) { brushIntensity = value; } +/** + * @brief + * + * @return int + */ int RenderArea::getBrushWidth() const { return brushWidth; } +/** + * @brief + * + * @param value + */ void RenderArea::setBrushWidth(int value) { brushWidth = value; @@ -1384,6 +1523,11 @@ void RenderArea::setBrushWidth(int value) //! [17] +/** + * @brief draw a scrible to the finish point + * + * @param finishPoint end point of the new line + */ void RenderArea::drawLineTo(const QPointF &finishPoint) // draw a line to the previous position of the mouse to the next //! [17] //! [18] { @@ -1403,6 +1547,12 @@ void RenderArea::drawLineTo(const QPointF &finishPoint) // draw a line to the pr lastPoint = finishPoint; update(); } +/** + * @brief draw a control curve + * create a control curve, add it to the current layer viewer and add it to the scene + * @param l nodes number of the control curve + * @param p Qpainterpath, i.e the scribble lines drawn during the mouse press and move event. + */ void RenderArea::drawCurveTo(int l, QPainterPath p) // draw a control curve with l control points, and a path of points which the scribled line previously sketched //! [17] //! [18] @@ -1426,15 +1576,16 @@ void RenderArea::drawCurveTo(int l, QPainterPath p) // draw a control curve with } +/** + * @brief draw a control line + * create a control line, add it to the current layer viewer and add it to the scene + * @param QPainterpath to draw the line, i.e the preview line sketch from the first click mouse point to the current mouse move point + */ void RenderArea::drawCurveTo( QPainterPath p) //! [17] //! [18] //! { - // QPainter painter(&image); - // Qpen pen = QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap, - // Qt::RoundJoin); - // painter.drawLine(lastPoint, endPoint); scene()->clearSelection(); float lbis = p.length()/myPenWidth; @@ -1443,63 +1594,61 @@ void RenderArea::drawCurveTo( QPainterPath p) float sat = myPenColor.hsvSaturation() - 70; auto *curveLine = new VectorCurve(p,l, layers[layerID]->getCurrentLayer()->getMyPenWidth(), sat); - - - //LayerViewer *layer =new LayerViewer(*layers[layerID]->getCurrentLayer()); CA FE BEUGUE - layers[layerID]->getCurrentLayer()->addVectorCurve(curveLine); layers[layerID]->addInteractionFields(layers[layerID]->getParameter(),layers[layerID]->getCurrentLayer()); if(layers[layerID]->getInteractionFields().size()>1) layers[layerID]->setIsParametric(true); //layers[layerID]->addToGroup(curveLine); - scene()->addItem(curveLine); - //curveLine->setSelected(true); + curveLine->setSelected(true); curveLine->createNodes(); - - /* - for(int i =0; i<int(curveLine->getNodes().size()); i++){ - curveLine->getNodes()[i]->setPos(curveLine->getControlPts()[i]); - scene()->addItem(curveLine->getNodes()[i]); - - }*/ - for(auto &node : curveLine->getNodes() ){ scene()->addItem(node); } } - -// QList<QGraphicsItem *> items = scene()->items(); -// for (QGraphicsItem *item : qAsConst(items)) { -// if (item->type() == QLineF::Type()) { -// renderArea->scene()->removeItem(item); -// Link *link = qgraphicsitem_cast<Link *>(item); -// link->startItem()->removeLink(link); -// link->endItem()->removeLink(link); -// delete item; -// } } //! [4] +/** + * @brief + * + * @param mode + */ void RenderArea::setMode(Mode mode) { myMode = mode; } +/** + * @brief + * + * @param type + */ void RenderArea::setItemType(Pole::Pole_Type type) { myItemType = type; } +/** + * @brief + * + * @param type + */ void RenderArea::setLinkType(Link::LinkType type) { myLinkType = type; } //! [14] +/** + * @brief + * + * @param type + * @return bool + */ bool RenderArea::isItemChange(int type) const { const QList<QGraphicsItem *> items = scene()->selectedItems(); @@ -1507,56 +1656,92 @@ bool RenderArea::isItemChange(int type) const return std::find_if(items.begin(), items.end(), cb) != items.end(); } +/** + * @brief + * + * @return float + */ float RenderArea::getParameter() const { return parameter; } +/** + * @brief + * + * @param value + */ void RenderArea::setParameter(float value) { parameter = value; } -bool RenderArea::getPole() const -{ - return pole; -} - -void RenderArea::setPole(bool value) -{ - pole = value; -} +/** + * @brief + * + * @return bool + */ bool RenderArea::getScaling() const { return scaling; } +/** + * @brief + * + * @param value + */ void RenderArea::setScaling(bool value) { scaling = value; } +/** + * @brief + * + * @return bool + */ bool RenderArea::getTranslation() const { return translation; } +/** + * @brief + * + * @param value + */ void RenderArea::setTranslation(bool value) { translation = value; } +/** + * @brief + * + * @return bool + */ bool RenderArea::getRotation() const { return rotation; } +/** + * @brief + * + * @param value + */ void RenderArea::setRotation(bool value) { rotation = value; } +/** + * @brief + * + * @return QList<LayerGroup *> + */ QList<LayerGroup *> RenderArea::getLayers() const { return layers; @@ -1566,11 +1751,21 @@ QList<LayerGroup *> RenderArea::getLayers() const +/** + * @brief + * + * @return size_t + */ size_t RenderArea::getLayerID() const { return layerID; } +/** + * @brief + * + * @param value + */ void RenderArea::setLayerID(const size_t &value) { layerID = value; @@ -1579,6 +1774,11 @@ void RenderArea::setLayerID(const size_t &value) +/** + * @brief + * + * @param value + */ void RenderArea::setMyItemMenu(QMenu *value) { myItemMenu = value; @@ -1592,72 +1792,40 @@ void RenderArea::setMyItemMenu(QMenu *value) +/** + * @brief + * + * @return int + */ int RenderArea::getType() const { return type; } +/** + * @brief + * + * @param value + */ void RenderArea::setType(int value) { type = value; } - - -/* -QList<VectorLine *> RenderArea::getVectLines() const -{ - return vectLines; -} - -void RenderArea::removeVectorLine(VectorLine *line){ - for( QList<VectorLine*>::iterator iter = vectLines.begin(); iter != vectLines.end(); ++iter ) - { - if( *iter == line ) - { - vectLines.erase( iter ); - break; - } - } - //renderArea->getVectLines().erase(std::remove( renderArea->getVectLines().begin(), renderArea->getVectLines().end(), line), renderArea->getVectLines().end()); -} - -*/ - void RenderArea::showEvent(QShowEvent *event) { fitInView(sceneRect(), Qt::KeepAspectRatio); - QGraphicsView.showE -} - - - -bool RenderArea::getCurveOn() const -{ - return curveOn; } -void RenderArea::setCurveOn(bool value) -{ - curveOn = value; -} -void RenderArea::setAgentPlacement(bool value) -{ - agentOn=value; -} -bool RenderArea::getLineOn() const -{ - return lineOn; -} -void RenderArea::setLineOn(bool value) -{ - lineOn = value; -} +/** + * @brief shhow or hide the current layergroup items + * + */ void RenderArea::showLayer(){ if (layers[layerID]->isVisible()){ @@ -1680,6 +1848,10 @@ void RenderArea::showLayer(){ } +/** + * @brief show or hie the control curves/lines of the current layer group + * + */ void RenderArea::showVector(){ @@ -1704,6 +1876,10 @@ void RenderArea::showVector(){ +/** + * @brief clear the current layer group + * delete items, poles, curves etc... + */ void RenderArea::clearLayer(){ for (auto &curve : layers[layerID]->getCurrentLayer()->getVectCurves()){ scene()->removeItem(curve); @@ -1723,6 +1899,11 @@ void RenderArea::clearLayer(){ } +/** + * @brief add vertical symetrics control vectors of the selected control vectors + * + * + */ void RenderArea::verticalSymetry(){ for (auto &vect: layers[layerID]->getCurrentLayer()->getVectCurves()){ @@ -1762,6 +1943,11 @@ void RenderArea::verticalSymetry(){ } } +/** + * @brief add horizontal symetrics control vectors of the selected control vectors + * + * + */ void RenderArea::horizontalSymetry(){ for (auto &vect: layers[layerID]->getCurrentLayer()->getVectCurves()){ if(vect->isSelected()){ @@ -1796,6 +1982,12 @@ void RenderArea::horizontalSymetry(){ } } +/** + * @brief add angular symetrics control vectors of the selected control vectors + * + * + * @param angle angle to perform symetry from + */ void RenderArea::angularSymetry(double angle){ double theta = (360.-angle) * 3.14159265/180.; @@ -1841,6 +2033,12 @@ void RenderArea::angularSymetry(double angle){ } } +/** + * @brief way of visualizing the result of a fields + * show the trajectory of an agent using a fields using Umans csv outputs + * @param fileName the name of the trajectory csv field + * @param color color to show the particule trajectory + */ void RenderArea::getVisualTrajectory(const QString fileName, QColor color){ string line; @@ -1894,6 +2092,10 @@ void RenderArea::getVisualTrajectory(const QString fileName, QColor color){ } +/** + * @brief use the previous fuction to show the results of one matrix with several trajectories + * + */ void RenderArea::drawComparingMatrix(){ myPenWidth = layers[layerID]->getCurrentLayer()->getMyPenWidth(); LayerViewer *layer = layers[layerID]->getCurrentLayer(); @@ -1920,7 +2122,6 @@ void RenderArea::drawComparingMatrix(){ } varianceMatrix.push_back(row); } - int cols = layer->getMatrix()->getCols(); for(int k = 2; k<24; k++){ VectorMatrix matrixCompared = *getMatrixFromFile("C:\\Users\\acolas\\Documents\\Present\\papierSiggraph\\InteractionField_UserStudy\\Results\\Results_"+ QString::number(k)+"\\Task7\\matrix\\"+ layers[layerID]->getName()+".txt"); for (int i = 0; i*height/(float)layer->getMatrix()->getRows()< height; i++){ @@ -1947,14 +2148,8 @@ void RenderArea::drawComparingMatrix(){ float x = start.x()+ (float) j *width/(float)layer->getMatrix()->getCols(); float yf = y - height/(float)layer->getMatrix()->getRows(); float xf = x + width/(float)layer->getMatrix()->getCols(); - float xRect = x + width/(4*(float)layer->getMatrix()->getCols()); - float yRect = yf + height/(4*(float)layer->getMatrix()->getRows()); - QRectF rect = QRectF(QPointF(x,y), QPointF(xf,yf)); - //Vector2D vectorGD = GrandTruthMat->at(i,j); - Vector2D vector = matrixMean.at(i,j); - QColor color; /* if( vector.isZero()){ @@ -2052,6 +2247,10 @@ void RenderArea::drawComparingMatrix(){ //! [18] +/** + * @brief if a layergroup is parametric when the parameter changes the layer displayed must be removed to show the new one + * + */ void RenderArea::removeLayerDisplayed(){ if(!layers[layerID]->getInteractionFields().count(layers[layerID]->getParameter())){ @@ -2072,6 +2271,10 @@ void RenderArea::removeLayerDisplayed(){ scene()->removeItem(layers[layerID]->getCurrentLayer()); } +/** + * @brief if a layer group is parametric, add the new parametric field value to be displayed according to the parameter + * + */ void RenderArea::addLayerDisplayed(){ if(layers[layerID]->getInteractionFields().count(layers[layerID]->getParameter())){ diff --git a/InteractionFields/renderarea.h b/InteractionFields/renderarea.h index 4d0bae293072e8414ec65f9618a9fccbe557b6f8..6c91abf148bfe25253c500a16144981ada4b1ecb 100644 --- a/InteractionFields/renderarea.h +++ b/InteractionFields/renderarea.h @@ -202,10 +202,6 @@ private: bool modified = false; //if modification has been made sincelast save bool scribbling = false; // if we are in scribling mode - bool lineOn = true; //if we are on control line mode - bool curveOn = false; - bool agentOn = true; - bool pole =false; bool rotation = false; // the links bool translation = false; bool scaling = false; diff --git a/InteractionFields/view.cpp b/InteractionFields/view.cpp index a1e07816b8439df5c5d5ddbe54b4c6313505d6fc..6a91264a8cc36e40c731475ce514c39cc962499d 100644 --- a/InteractionFields/view.cpp +++ b/InteractionFields/view.cpp @@ -40,6 +40,12 @@ using namespace std; +/** + * @brief create main view + * add cener widget, tool bar, layer bar, object bar and matrix bar and paramtric slider + * + * @param parent + */ View::View(QWidget *parent) : QMainWindow(parent) , ui(new Ui::View) @@ -88,12 +94,21 @@ View::View(QWidget *parent) } +/** + * @brief + * + */ View::~View() { delete ui; } //! [1] +/** + * @brief close window + * + * @param event + */ void View::closeEvent(QCloseEvent *event) //! [1] //! [2] { @@ -103,6 +118,11 @@ void View::closeEvent(QCloseEvent *event) event->ignore(); } +/** + * @brief + * + * @param event + */ void View::resizeEvent(QResizeEvent *event) { @@ -112,6 +132,10 @@ void View::resizeEvent(QResizeEvent *event) //! [2] //! [3] +/** + * @brief + * + */ void View::open() //! [3] //! [4] { @@ -126,6 +150,11 @@ void View::open() } } +/** + * @brief save the current field + * + * @param isExpended + */ void View::save(bool isExpended) { saveFile("txt", isExpended); @@ -133,6 +162,10 @@ void View::save(bool isExpended) //! [4] //! [7] +/** + * @brief + * + */ void View::penColor() //! [7] //! [8] { @@ -143,6 +176,10 @@ void View::penColor() //! [8] //! [9] +/** + * @brief + * + */ void View::penWidth() //! [9] //! [10] { @@ -159,14 +196,12 @@ void View::penWidth() } +/** + * @brief create the central widget the velocity and orientation render Area + gui widget + * + */ void View::createCentralView() { - - - - - - // this->setContextMenuPolicy(Qt::CustomContextMenu); // connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), // this, SLOT(ShowContextMenu(const QPoint&))); @@ -193,27 +228,12 @@ void View::createCentralView() QPushButton *saveButt = new QPushButton("Save"); hlay->addWidget(saveButt); */ - - QWidget * wdg = new QWidget(this); - QBoxLayout *hrenderUp = new QHBoxLayout(); - - - - - - QBoxLayout *hlay = new QHBoxLayout(wdg); QBoxLayout *vlay = new QVBoxLayout(); vlay->addLayout(hrenderUp); vlay->addWidget(tabWidget); - - - - - - scaleLabel = new QLabel(this); scaleLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); @@ -242,6 +262,11 @@ void View::createCentralView() } //! [11] +/** + * @brief change the scale of the view (central widget) + * + * @param scale + */ void View::sceneScaleChanged(const QString &scale) { double newScale = scale.left(scale.indexOf(tr("%"))).toDouble() / 100.0; @@ -255,6 +280,12 @@ void View::sceneScaleChanged(const QString &scale) //! [1] +/** + * @brief activated when one button of the layer group is clicked + * + * select the group layer according to id and make it the current grouplayer + * @param id id of layer + */ void View::layerButtonGroupClicked(int id) { const QList<QAbstractButton *> buttons = layerButtonGroup->buttons(); @@ -275,6 +306,11 @@ void View::layerButtonGroupClicked(int id) } +/** + * @brief activated when one of the matrix button is cliked + * activate horizontal, vertical or angular symetry + * @param id: id of the symetry + */ void View::matrixButtonGroupClicked(int id) { const QList<QAbstractButton *> buttons = buttonGroup->buttons(); @@ -297,6 +333,11 @@ void View::matrixButtonGroupClicked(int id) //! [1] //! [2] +/** + * @brief activated when one of the object group is clicked + * obstalce or agent pole is selected to be added to the scene + * @param id id of the type of the pole + */ void View::buttonGroupClicked(int id) { const QList<QAbstractButton *> buttons = buttonGroup->buttons(); @@ -310,6 +351,11 @@ void View::buttonGroupClicked(int id) } //! [2] +/** + * @brief activated when one of the link group is clicked + * for now only the rotation link is working + * @param id of the type of link + */ void View::buttonGroupLinkClicked(int id) { // const QList<QAbstractButton*> buttonsPointer = pointerTypeGroup->buttons(); @@ -334,27 +380,40 @@ void View::buttonGroupLinkClicked(int id) static_cast<RenderArea *>(tabWidget->currentWidget())->setMode(RenderArea::InsertLink); } +/** + * @brief activated when one of the erase blank area button is clicked + * erase the blank area of the current layer group + * @param id id of the current layer group + */ void View::blankButtonGroupClicked(size_t id) { - for (auto &indices: static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[id]->getCurrentLayer()->getZerosArea()){ - - static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[id]->getCurrentLayer()->removeZeroArea(); - } - + static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[id]->getCurrentLayer()->removeZeroArea(); static_cast<RenderArea *>(tabWidget->currentWidget())->drawMatrix(); } +/** + * @brief activated when the hideVector group is clicked + * hide or show the control vectors of the current layer + */ void View::hideButtonGroupClicked() { static_cast<RenderArea *>(tabWidget->currentWidget())->showVector(); } +/** + * @brief clear the current group layer + * + */ void View::clearButtonGroupClicked() { static_cast<RenderArea *>(tabWidget->currentWidget())->clearImage(); } //! [3] +/** + * @brief delete the selected item + * items can be: poles, curves, lines or links + */ void View::deleteItem() { QList<QGraphicsItem *> selectedItems = static_cast<RenderArea *>(tabWidget->currentWidget())->scene()->selectedItems(); @@ -403,6 +462,10 @@ void View::deleteItem() //! [3] //! [3] +/** + * @brief make or unmake the selected pole the source of the field + * + */ void View::makeSource() { QList<QGraphicsItem *> selectedItems = static_cast<RenderArea *>(tabWidget->currentWidget())->scene()->selectedItems(); @@ -443,16 +506,31 @@ void View::makeSource() } +/** + * @brief show or hide the current layer + * + * @param id id of the layergroup + */ void View::showLayer(size_t id) { static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[id]->hideLayer(); } +/** + * @brief show or hide the control vector of a layergroup + * + * @param id of the layergroup + */ void View::showVector(size_t id) { static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[id]->hideVectors(); } +/** + * @brief show or hide the grid of a layer group + * + * @param id of the layer group + */ void View::showGrid(size_t id) { bool isGrid= !static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[id]->getIsGridVisible(); @@ -460,6 +538,11 @@ void View::showGrid(size_t id) static_cast<RenderArea *>(tabWidget->currentWidget())->drawMatrix(); } +/** + * @brief make possible or not to move a layer group + * + * @param id of the layer group + */ void View::moveLayer(size_t id) { if( static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[id]->flags()& static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[static_cast<RenderArea *>(tabWidget->currentWidget())->getLayerID()]->ItemIsMovable) @@ -472,6 +555,11 @@ void View::moveLayer(size_t id) //! [3] //! [4] +/** + * @brief activate when one button of the pointer group is clicked + * + * @param int id of the pointer selected + */ void View::pointerGroupClicked(int) { @@ -492,6 +580,10 @@ void View::pointerGroupClicked(int) //! [4] //! [5] +/** + * @brief put the slected layer up front + * + */ void View::bringToFront() { if (static_cast<RenderArea *>(tabWidget->currentWidget())->scene()->selectedItems().isEmpty()) @@ -510,6 +602,10 @@ void View::bringToFront() //! [5] //! [6] +/** + * @brief put the selected layer behind all the others + * + */ void View::sendToBack() { if (static_cast<RenderArea *>(tabWidget->currentWidget())->scene()->selectedItems().isEmpty()) @@ -528,6 +624,11 @@ void View::sendToBack() //! [6] //! [7] +/** + * @brief + * + * @param item + */ void View::itemInserted(Pole *item) { pointerTypeGroup->button(int(RenderArea::MoveItem))->setChecked(true); @@ -539,6 +640,17 @@ void View::itemInserted(Pole *item) //! [28] +/** + * @brief create a new layergroup buttons with its menu + * + * @param text name of the layergroup + * @param height height of the layergroup + * @param width width of the layergroup + * @param weight weight of the layer group (for later combination) + * @param id id of the layer + * @param render if the layer is in the orientation or the velocity renderarea + * @return QWidget return the Widget of the layer to be added to the menu + */ QWidget *View::createLayerCellWidget(const QString &text, const double height, const double width, const double weight,size_t id, RenderArea *render) { QToolButton *button = new QToolButton; @@ -647,6 +759,13 @@ QWidget *View::createLayerCellWidget(const QString &text, const double height, c //! [28] //! [29] +/** + * @brief create the pole buttons + * + * @param text name of the pole + * @param type type of the pole + * @return QWidget return the widget menu + */ QWidget *View::createCellWidget(const QString &text, Pole::Pole_Type type) { @@ -671,6 +790,12 @@ QWidget *View::createCellWidget(const QString &text, Pole::Pole_Type type) return widget; } //! [29] +/** + * @brief create the matrix buttons of the symetrical options + * + * @param id id of the option + * @return QWidget return the widget + */ QWidget *View::createMatrixCellWidget(int id ) { QToolButton *button = new QToolButton; @@ -708,6 +833,10 @@ QWidget *View::createMatrixCellWidget(int id ) return widget; } +/** + * @brief pop up to ask for the angle of the angular symetry + * + */ void View::angularSymetry(){ QDialog * d = new QDialog(); QVBoxLayout * vbox = new QVBoxLayout(); @@ -735,6 +864,10 @@ void View::angularSymetry(){ static_cast<RenderArea *>(tabWidget->currentWidget())->angularSymetry(angle->value()); } +/** + * @brief tool box with the matrix, pole and layer menus + * + */ void View::createToolBox() { buttonGroup = new QButtonGroup(this); @@ -820,6 +953,10 @@ void View::createToolBox() } +/** + * @brief create the slider tool box + * the slider allows to create parametric field and to check its value for different paramter + */ void View::createSliderToolBox() { @@ -867,6 +1004,11 @@ void View::createSliderToolBox() } +/** + * @brief create all the tools bars + * the pointer tool bar (eraser, brush, arrow), the link toolbar, the pole option tool bar (source) + * + */ void View::createToolbars() { //! [25] @@ -960,6 +1102,10 @@ void View::createToolbars() //! [27] } +/** + * @brief create the layer tool bar: all the grouplayer are listed in one menu + * + */ void View::createLayerbars() { @@ -983,6 +1129,11 @@ void View::createLayerbars() } //! [27] +/** + * @brief pop up to change the grouplayer current viewer matrix's size and resolution + * + * @param id of the grouplayer + */ void View::matrixSize(size_t id) { QDialog * d = new QDialog(); @@ -1063,6 +1214,10 @@ void View::matrixSize(size_t id) } +/** + * @brief pop up to change th size of the scene i.e of the render area + * + */ void View::sceneSize() { QDialog * d = new QDialog(); @@ -1129,6 +1284,11 @@ void View::sceneSize() +/** + * @brief brush tool pop up + * display a slider to choose a magnitude intensity (slow, medium, fast) to attribute to vectors + * + */ void View::colorMagnitude(){ QDialog * d = new QDialog(); @@ -1163,7 +1323,6 @@ void View::colorMagnitude(){ QObject::connect(colorValue, &QSlider::valueChanged, this, [=] (){ changeSliderColor(colorValue); - float v = colorValue->value(); }); QObject::connect(colorValue, &QSlider::valueChanged, this, [=] () { @@ -1209,19 +1368,15 @@ void View::colorMagnitude(){ if(result == QDialog::Accepted) { - // handle values from d - qDebug() << "The user clicked:" - << "color magnitude" << colorValue->value(); - - float v = colorValue->value(); - v = v - colorValue->minimum(); - qreal rv = qreal(v) / (colorValue->maximum() - colorValue->minimum()); - QColor c = QColor::fromHsl(205 - 205 * rv, 200, 135); - //static_cast<RenderArea *>(tabWidget->currentWidget())->setPenColor(c); static_cast<RenderArea *>(tabWidget->currentWidget())->setBrushIntensity(float(colorValue->value())/100.f); } } +/** + * @brief change the color of the rbush pop up slider + * + * @param s: the style of the slider + */ void View::changeSliderColor(QSlider *s){ QColor from(250, 0, 0); @@ -1234,6 +1389,10 @@ void View::changeSliderColor(QSlider *s){ s->setStyleSheet(QString("QSlider::handle:vertical {background-color: %1;}").arg(c.name())); } +/** + * @brief add a new groulayer to the group layer menu + * + */ void View::addLayer() { QDialog * d = new QDialog(); @@ -1312,6 +1471,10 @@ void View::addLayer() //! [10] //! [11] +/** + * @brief + * + */ void View::about() //! [11] //! [12] { @@ -1331,6 +1494,10 @@ void View::about() //! [12] //! [13] +/** + * @brief create all the actions + * + */ void View::createActions() //! [13] //! [14] { @@ -1367,11 +1534,11 @@ void View::createActions() connect(saveAct, &QAction::triggered, [this, expended] {save(expended);}); poleAct = new QAction(tr("Pole"), this); - connect(poleAct, &QAction::triggered, this, &View::on_actionPole_triggered); + connect(poleAct, &QAction::triggered, this, &View::makeSource); sourceAct = new QAction(tr("Source"), this); - connect(poleAct, &QAction::triggered, this, &View::on_actionAgent_triggered); + connect(poleAct, &QAction::triggered, this, &View::makeSource); exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcuts(QKeySequence::Quit); @@ -1466,6 +1633,10 @@ void View::createActions() //! [15] +/** + * @brief create all the menus + * + */ void View::createMenus() //! [15] //! [16] { @@ -1541,6 +1712,11 @@ void View::createMenus() //! [16] //! [17] +/** + * @brief if the field was modified after last saved, asked if user wants to save it before closing the window + * + * @return bool return if the user still wants to close the window or not + */ bool View::maybeSave() //! [17] //! [18] { @@ -1564,6 +1740,13 @@ bool View::maybeSave() //! [18] //! [19] +/** + * @brief save the field as a txt file + * + * @param fileFormat file format + * @param isExtended if we choose the path of the file "save as.." or if we use the previous name of the file "save" + * @return bool + */ bool View::saveFile(const QByteArray &fileFormat, bool isExtended) //! [19] //! [20] { @@ -1616,6 +1799,11 @@ bool View::saveFile(const QByteArray &fileFormat, bool isExtended) } //! [20] +/** + * @brief activated when the button "generate" of the matrix menu is clicked + * generate the matrix + * + */ void View::on_pushButtonMatrix_clicked() { //static_cast<RenderArea *>(tabWidget->currentWidget())->generateMatrixFromFile(); @@ -1636,6 +1824,11 @@ void View::on_pushButtonMatrix_clicked() } } +/** + * @brief save the field + * + * @return bool + */ bool View::saveSimple() //! [19] //! [20] { @@ -1686,42 +1879,22 @@ bool View::saveSimple() } -void View::on_actionLine_triggered() -{ - static_cast<RenderArea *>(tabWidget->currentWidget())->setLineOn(true); - static_cast<RenderArea *>(tabWidget->currentWidget())->setCurveOn(false); - static_cast<RenderArea *>(tabWidget->currentWidget())->setAgentPlacement(false); -} - -void View::on_actionCurve_triggered() -{ - static_cast<RenderArea *>(tabWidget->currentWidget())->setCurveOn(true); - static_cast<RenderArea *>(tabWidget->currentWidget())->setLineOn(false); - static_cast<RenderArea *>(tabWidget->currentWidget())->setAgentPlacement(false); -} - -void View::on_actionAgent_triggered() -{ - static_cast<RenderArea *>(tabWidget->currentWidget())->setAgentPlacement(true); - static_cast<RenderArea *>(tabWidget->currentWidget())->setLineOn(false); - static_cast<RenderArea *>(tabWidget->currentWidget())->setCurveOn(false); - static_cast<RenderArea *>(tabWidget->currentWidget())->setPole(false); -} - -void View::on_actionPole_triggered(){ - static_cast<RenderArea *>(tabWidget->currentWidget())->setPole(true); - static_cast<RenderArea *>(tabWidget->currentWidget())->setAgentPlacement(false); - static_cast<RenderArea *>(tabWidget->currentWidget())->setLineOn(false); - static_cast<RenderArea *>(tabWidget->currentWidget())->setCurveOn(false); -} +/** + * @brief + * + */ void View::on_agentRadButt_clicked() { static_cast<RenderArea *>(tabWidget->currentWidget())->setType(1); } +/** + * @brief + * + */ void View::on_obstacleRadButt_clicked() { static_cast<RenderArea *>(tabWidget->currentWidget())->setType(2); @@ -1729,21 +1902,37 @@ void View::on_obstacleRadButt_clicked() } +/** + * @brief + * + */ void View::on_rotationButton_clicked() { static_cast<RenderArea *>(tabWidget->currentWidget())->setRotation(!static_cast<RenderArea *>(tabWidget->currentWidget())->getRotation()); } +/** + * @brief + * + */ void View::on_translationButton_clicked() { static_cast<RenderArea *>(tabWidget->currentWidget())->setTranslation(!static_cast<RenderArea *>(tabWidget->currentWidget())->getTranslation()); } +/** + * @brief + * + */ void View::on_scaleButton_clicked() { static_cast<RenderArea *>(tabWidget->currentWidget())->setScaling(!static_cast<RenderArea *>(tabWidget->currentWidget())->getScaling()); } +/** + * @brief on the slider menu if the button "add or remover key frame" is clicked + * make the layergroup parametric, add a key frame for this parameter or remove it if already there. + */ void View::on_paramButton_clilcked(){ LayerViewer *layer =new LayerViewer(*static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[static_cast<RenderArea *>(tabWidget->currentWidget())->getLayerID()]->getCurrentLayer()); if(static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[static_cast<RenderArea *>(tabWidget->currentWidget())->getLayerID()]->getInteractionFields().count(static_cast<RenderArea *>(tabWidget->currentWidget())->getLayers()[static_cast<RenderArea *>(tabWidget->currentWidget())->getLayerID()]->getParameter())){ @@ -1781,6 +1970,10 @@ void View::on_paramButton_clilcked(){ } +/** + * @brief activated when the parametric slider changes its value + * when value changes, thedisplayer layerviewer must changed and the resulting vector matrix is the interpolated matrix of the surrounding keyframes matrix + */ void View::sliderValueChange(){