Parcourir la source

Adding some functionlalites

Rémi Synave il y a 1 an
Parent
commit
d711be7da3

+ 16 - 0
StrengthLine/StrengthLine.cpp

@@ -288,3 +288,19 @@ StrengthLine* StrengthLine::getRandomLine (QImage * img)
     }
   return new StrengthLine( new QPoint(x1rand, y1rand), new QPoint(x2rand, y2rand) );
 }
+
+StrengthLine* StrengthLine::getRandomLine (int width, int height)
+{
+  srand (time(NULL));
+  
+  int x1rand = rand() % width;
+  int x2rand = rand() % width;
+  int y1rand = rand() % height;
+  int y2rand = rand() % height;
+  while ( x1rand == x2rand && y1rand==y2rand )
+    {
+      x2rand = rand() % width;
+      y2rand = rand() % height;
+    }
+  return new StrengthLine( new QPoint(x1rand, y1rand), new QPoint(x2rand, y2rand) );
+}

+ 1 - 0
StrengthLine/StrengthLine.hpp

@@ -46,6 +46,7 @@ public:
   std::pair < QPoint *, QPoint * > interpolateToEdge (QImage * img) const;
 
   static StrengthLine* getRandomLine (QImage * img);
+  static StrengthLine* getRandomLine (int width, int height);
 };
 
 #endif

+ 8 - 0
WorkArea/WorkArea.cpp

@@ -212,6 +212,14 @@ WorkArea::addSL (const StrengthLine *sl)
   liste_points << new QPoint((int)(sl->getP2()->x()*resizeFactor), (int)(sl->getP2()->y()*resizeFactor));
 }
 
+void
+WorkArea::addRandomSL ()
+{
+  StrengthLine *sl = StrengthLine::getRandomLine(original);
+  liste_points << new QPoint((int)(sl->getP1()->x()*resizeFactor), (int)(sl->getP1()->y()*resizeFactor));
+  liste_points << new QPoint((int)(sl->getP2()->x()*resizeFactor), (int)(sl->getP2()->y()*resizeFactor));
+}
+
 
 void
 WorkArea::paintEvent (QPaintEvent * event)

+ 1 - 0
WorkArea/WorkArea.hpp

@@ -88,6 +88,7 @@ public:
   int getNumberOfLines() const;
   
   void addSL(const StrengthLine *sl);
+  void addRandomSL();
 
 };
 

+ 2 - 1
csl/Experiment.cpp

@@ -159,7 +159,8 @@ Experiment::openC (QString image, QString leftSL, QString rightSL){
   waRight->loadImage (image.toStdString ());
   waLeft->loadSL(leftSL.toStdString());
   waRight->loadSL(rightSL.toStdString());
-  waRight->addSL(StrengthLine::getRandomLine(waRight->getOriginalImage()));
+  //waRight->addSL(StrengthLine::getRandomLine(waRight->getOriginalImage()));
+  waRight->addRandomSL();
   waLeft->setReadOnly(true);
   waRight->setReadOnly(true);
   waLeft->repaint();