找到最接近圆圈内不规则形状边缘的点c ++

时间:2015-01-19 21:04:25

标签: c++ qt

bool cancelFlag = true;
   bool useUserSelectionForSubplugs = false;
   bool allowMultipleDevicesInOneDieFlag = false;
   int diesToSearchX, diesToSearchY; 
   diesToSearchX = diesToSearchY = 2;
   PBEdgeInterpolationWindow *edgeInterpolationWindow = new PBEdgeInterpolationWindow(&diesToSearchX, &diesToSearchY, &useUserSelectionForSubplugs, &allowMultipleDevicesInOneDieFlag, &cancelFlag);
   edgeInterpolationWindow->exec();

   if(cancelFlag) return;


   if(fSelectedDeviceList.empty())
   {
          QMessageBox::warning(this, tr("Edge Crown Creation"), tr("Nothing to create crown with: only the devices in Selected Devices List will be considered for this operation\nPlease add devices to the \"Selected Devices\" list"));
          return;
   }

   PBWaferMapRevision *pendingRevision = fData->fPending_Revision;
   if(!pendingRevision)
   {
          QMessageBox::warning(this, tr("Edge Crown Creation"), tr("Revision to be edited needs to be a PENDING revision"));
          return;
   }

   struct WMDeviceForCrown
   {
          double x, y;
          double wrtShotX, wrtShotY;
          int crownShotRow, crownShotCol;
          WaferDevice *WaferDevicePointer;
   };
   std::vector<WMDeviceForCrown> DeviceForCrownList;

   PBProductData *productData = static_cast<PBProductData*>(fData->Getparent()->Getparent());
   double offsetX = productData->fOffsetX;
   double offsetY = productData->fOffsetY;
   double diesizeX = productData->fDieSizeX;
   double diesizeY = productData->fDieSizeY;


   /* Collect all devices within the edges, assign them coordinates of their first probe */
   if(useUserSelectionForSubplugs )
   {
          qDebug()<<"inside if crown";
          bool noSubplugSelected = true;
          for(int i=0; i<pendingRevision->fShotList.size(); i++)
          {
                 for(int j=0; j<pendingRevision->fShotList[i].fSubPlugList.size(); j++)
                 {
                       if(pendingRevision->fShotList[i].fSubPlugList[j].fIsSelected)
                       {
                              noSubplugSelected = false;
                              PBSubPlug *subPlug = fCurrentRevision->fShotList[i].fSubPlugList[j].fSubPlug;
                              for(int k=0; k<pendingRevision->fShotList[i].fDeviceList.size(); k++)
                              {
                                     WaferDevice *dev = &(pendingRevision->fShotList[i].fDeviceList[k]);
                                     if(!dev->fIsOutsideEE)
                                     {
                                            if(std::find(fSelectedDeviceList.begin(), fSelectedDeviceList.end(), dev->fDevice) != fSelectedDeviceList.end())
                                            {
                                                   double probeX = dev->fDevice->fDevice->fMPFProbeList->fProbeList.front()->fProbe_pos_x; 
                                                   double probeY = dev->fDevice->fDevice->fMPFProbeList->fProbeList.front()->fProbe_pos_y;
                                                   double x = subPlug->fSubplgx;
                                                   double y = subPlug->fSubplgy;
                                                   double w = subPlug->fSubplgwidth;
                                                   double h = subPlug->fSubplgheight;
                                                   if((probeX > x-kDoubleTolerence) && (probeX < x+w+kDoubleTolerence) && (probeY > y-kDoubleTolerence) && (probeY < y+h+kDoubleTolerence))
                                                   {
                                                          WMDeviceForCrown devForCrown;
                                                          devForCrown.WaferDevicePointer = dev;

                                                          double shotX = pendingRevision->fShotList[i].fShot->fShotX;
                                                          double shotY = pendingRevision->fShotList[i].fShot->fShotY;

                                                          devForCrown.wrtShotX = probeX;
                                                          devForCrown.wrtShotY = probeY;

                                                          if(dev->fDevice->fDevice->fMPFProbeList->fProbeList.empty()) return;
                                                          double probe1X = shotX + devForCrown.wrtShotX;
                                                          double probe1Y = shotY + devForCrown.wrtShotY;

                                                          devForCrown.x = probe1X;
                                                          devForCrown.y = probe1Y;

                                                          devForCrown.crownShotRow= pendingRevision->fShotList[i].fShot->fShotRow;
                                                          devForCrown.crownShotCol= pendingRevision->fShotList[i].fShot->fShotCol;

                                                          DeviceForCrownList.push_back(devForCrown);
                                                          //break;
                                                   }
                                            }
                                     }
                              }
                       }
                 }
          }
          if(noSubplugSelected)
          {
                 QMessageBox::warning(this, tr("Edge Crown Creation"), tr("Nothing to create crown with: only the selected devices in selected subplugs will be considered for this operation\nPlease select one or more subplugs in the wafer map\nor uncheck option \"consider devices only in selected subplugs\""));
                 return;
          }
   }
   else
   {
          qDebug()<<"inside else crown";
          for(int i=0; i<pendingRevision->fShotList.size(); i++)
          {
                 if(pendingRevision->fShotList[i].fShot->fShotName == "Std shots")
                 {
                       for(int j=0; j<pendingRevision->fShotList[i].fDeviceList.size(); j++)
                       {
                              WaferDevice *dev = &(pendingRevision->fShotList[i].fDeviceList[j]);
                              if(std::find(fSelectedDeviceList.begin(), fSelectedDeviceList.end(), dev->fDevice)==fSelectedDeviceList.end()) continue;
                              if(!dev->fIsOutsideEE)
                              {


                                     WMDeviceForCrown devForCrown;
                                     devForCrown.WaferDevicePointer = dev;

                                     double shotX = pendingRevision->fShotList[i].fShot->fShotX;
                                     double shotY = pendingRevision->fShotList[i].fShot->fShotY;

                                     devForCrown.wrtShotX = dev->fDevice->fDevice->fMPFProbeList->fProbeList.front()->fProbe_pos_x;
                                     devForCrown.wrtShotY = dev->fDevice->fDevice->fMPFProbeList->fProbeList.front()->fProbe_pos_y;

                                     if(dev->fDevice->fDevice->fMPFProbeList->fProbeList.empty()) return;
                                     double probe1X = shotX + devForCrown.wrtShotX;
                                     double probe1Y = shotY + devForCrown.wrtShotY;

                                     devForCrown.x = probe1X;
                                     devForCrown.y = probe1Y;
                                     devForCrown.crownShotRow= pendingRevision->fShotList[i].fShot->fShotRow;
                                     devForCrown.crownShotCol= pendingRevision->fShotList[i].fShot->fShotCol;

                                     DeviceForCrownList.push_back(devForCrown);
                                     //     break; 

                              }
                       }
                 }
          }
   }

   if(DeviceForCrownList.empty())
   {
          QMessageBox::warning(this, tr("Edge Crown Creation"), tr("No valid devices for the crown operation. \nNo device from selected devices list could be found in the selected subplugs."));
          return;
   }

   std::vector<WMDeviceForCrown> DeviceOnEdgeList;

   for(int i=0; i<DeviceForCrownList.size(); i++)
   {
          WMDeviceForCrown dev = DeviceForCrownList[i];
          bool quadrantEmpty;


          /* Axes as thick as diesize */
          int xOffset = int(dev.wrtShotX)%int(diesizeX);
          int xReminder = diesizeX - xOffset;
          double xmin = dev.x - xOffset;
          double xmax = dev.x + xReminder;

          int yOffset = int(dev.wrtShotY)%int(diesizeY);
          int yReminder = diesizeY - yOffset;
          double ymin = dev.y - yOffset;
          double ymax = dev.y + yReminder;



          /* First Quadrant */
          quadrantEmpty = true;
          for(int j=0; j<DeviceForCrownList.size(); j++)
          {
                 if(i!=j)
                 {

                       if((DeviceForCrownList[j].x>xmax && DeviceForCrownList[j].y>ymax)  )
                       {
                              /*if((DeviceForCrownList[j].y>ymax &&  DeviceForCrownList[j].x>=xmin &&  DeviceForCrownList[j].x<=xmax))
                              {
                                     DeviceOnEdgeList.push_back(dev);
                                     continue;
                              }*/
                              /*qDebug()<<"xmin::"<<xmin;
                              qDebug()<<"xmax::"<<xmax;
                              qDebug()<<"ymin::"<<ymin;
                              qDebug()<<"ymax::"<<ymax;
                       */

                              quadrantEmpty = false;
                              break;



                       }

                 }
          }
          if(quadrantEmpty)
          {
                 DeviceOnEdgeList.push_back(dev);
                 continue;
          }


          //* Second Quadrant */
          quadrantEmpty = true;
          for(int j=0; j<DeviceForCrownList.size(); j++)
          {
                 if(i!=j)
                 {
                       if(DeviceForCrownList[j].x<xmin && DeviceForCrownList[j].y>ymax /*|| (DeviceForCrownList[j].x<xmin  && DeviceForCrownList[j].y>=ymin &&  DeviceForCrownList[j].y<=ymax*/)
                       {
                              quadrantEmpty = false;
                              break;
                       }
                 }
          }
          if(quadrantEmpty)
          {
                 DeviceOnEdgeList.push_back(dev);
                 continue;
          }


          //* Third Quadrant */
          quadrantEmpty = true;
          for(int j=0; j<DeviceForCrownList.size(); j++)
          {
                 if(i!=j)
                 {
                       if(DeviceForCrownList[j].x<xmin && DeviceForCrownList[j].y<ymin)
                       {
                              quadrantEmpty = false;
                              break;
                       }
                 }
          }
          if(quadrantEmpty)
          {
                 DeviceOnEdgeList.push_back(dev);
                 continue;
          }


          //


          /////* Fourth Quadrant */
                 quadrantEmpty = true;
          for(int j=0; j<DeviceForCrownList.size(); j++)
          {
                 if(i!=j)
                 {
                       if((DeviceForCrownList[j].x>xmax && DeviceForCrownList[j].y<ymin) /*|| (DeviceForCrownList[j].x<xmax && DeviceForCrownList[j].y>ymin)*/)
                       {
                              quadrantEmpty = false;
                              break;
                       }
                 }
          }
          if(quadrantEmpty)
          {
                 DeviceOnEdgeList.push_back(dev);
                 continue;
          }




                 //            /* Along X-Positive Axis */
          quadrantEmpty = true;
          for(int j=0; j<DeviceForCrownList.size(); j++)
          {
                 if(i!=j)
                 {
                       if(DeviceForCrownList[j].x>xmax  && DeviceForCrownList[j].y>=ymin &&  DeviceForCrownList[j].y<=ymax)
                       {
                              quadrantEmpty = false;
                              break;
                       }
                 }
          }
          if(quadrantEmpty)
          {
                 DeviceOnEdgeList.push_back(dev);
                 continue;
          }


          ////   ///* Along Y-Positive Axis */
          quadrantEmpty = true;
          for(int j=0; j<DeviceForCrownList.size(); j++)
          {
                 if(i!=j)
                 {
                       if((DeviceForCrownList[j].y>ymax &&  DeviceForCrownList[j].x>=xmin &&  DeviceForCrownList[j].x<=xmax) /*&& (DeviceForCrownList[j].x>xmax  && DeviceForCrownList[j].y>=ymin &&  DeviceForCrownList[j].y<=ymax)*/ )
                       {
                              quadrantEmpty = false;
                              break;
                       }
                 }
          }
          if(quadrantEmpty)
          {
                 DeviceOnEdgeList.push_back(dev);
                 continue;
          }

          ////



          //            ///* Along X-Negative Axis */
          quadrantEmpty = true;
          for(int j=0; j<DeviceForCrownList.size(); j++)
          {
                 if(i!=j)
                 {
                       if(DeviceForCrownList[j].x<xmin  && DeviceForCrownList[j].y>=ymin &&  DeviceForCrownList[j].y<=ymax)
                       {
                              quadrantEmpty = false;
                              break;
                       }
                 }
          }
          if(quadrantEmpty)
          {
                 DeviceOnEdgeList.push_back(dev);
                 continue;
          }

          ///////* Along Y-Negative Axis */
          quadrantEmpty = true;
          for(int j=0; j<DeviceForCrownList.size(); j++)
          {
                 if(i!=j)
                 {
                       if(DeviceForCrownList[j].y<ymin &&  DeviceForCrownList[j].x>=xmin &&  DeviceForCrownList[j].x<=xmax)
                       {
                              quadrantEmpty = false;
                              break;
                       }
                 }
          }
          if(quadrantEmpty)
          {
                 DeviceOnEdgeList.push_back(dev);
                 continue;
          }



   }

   if(DeviceForCrownList.empty())
   {
          QMessageBox::warning(this, tr("Edge Crown Creation"), tr("No valid devices found along the edge"));
          return;
   }

   /* Temporary code for visualization */
   //for(int i=0; i<DeviceOnEdgeList.size(); i++)
   //{
   //     QGraphicsEllipseItem *itm = new QGraphicsEllipseItem(DeviceOnEdgeList[i].x-150, -DeviceOnEdgeList[i].y-150, 300, 300);
   //     itm->setBrush(Qt::blue);
   //     fWaferMapView.scene()->addItem(itm);
   //}

我在2d平面上有一个圆圈,中心为0,0。 现在我已经在圆圈上绘制了固定大小的矩形,矩形0,0是包含圆心的那个,然后矩形0,1,02依次为x,轴和所有象限中的类似。

现在每个矩形都有一些设备,我为每个矩形打了那些设备的x,y。每个矩形都有相同的设备。

现在我按照这张图片选择灰色设备:

https://docs.google.com/file/d/0B_oYS4i7-wQMWldWdzRjcG1qekU/edit?usp=drive_web&pli=1

现在当我运行上面的代码时,我试图选择灰色选区边缘的设备,如下所示:

https://drive.google.com/file/d/0B_oYS4i7-wQMc0x2cFhSMWE0SmM/view?usp=sharing

但是,仍然没有根据此链接选择某些设备(请参阅红色圆圈)。

所以需要一些帮助/逻辑来实现同样的目标。

提前致谢!

0 个答案:

没有答案