Beispiel #1
0
void
Boundary2D::SetupBdry2D(::Bdry2D &bdry) const {
  int i=0; 
  int  iBdryPatch = 0;


  std::cerr << "Before Set size\n";
  bdry.vSetSize (NumOfPatches(), NumOfPoints());

  std::cerr << "Set size\n";
  for (PointIterator p=FirstPoint(); 
       p != EndPoint(); ++p, ++i) {
       bdry.vAddPoint((*p).coords());
       bdry.vSetBdryPoint(i, false);
  }

  std::cerr << "Added points size\n";
  for (PolylineIterator p=FirstPolyline(); p !=EndPolyline(); ++p) {
    SetupPolyline(bdry, *p, iBdryPatch);
  }

  std::cerr << "Added polylines size\n";
  for (CircleIterator p=FirstCircle(); p !=EndCircle(); ++p) {
    SetupCircle(bdry, *p, iBdryPatch);
  }

  std::cerr << "Added circles size\n";
  for (ArcIterator p=FirstArc(); p !=EndArc(); ++p) {
    SetupArc(bdry, *p, iBdryPatch);
  }

  std::cerr << "Added arcs size\n";
  for (BezierIterator p=FirstBezier(); p !=EndBezier(); ++p) {
    SetupBezier(bdry, *p, iBdryPatch);
  }
 
  std::cerr << "Added  beziers size\n";
  for (SplineIterator p=FirstSpline(); p !=EndSpline(); ++p) {
    SetupSpline(bdry, *p, iBdryPatch);
  }
 
  std::cerr << "Added splines size\n";
  bdry.vOrderConnectivityInfo();
  // Find small angles
  bdry.vFindSmallAngles();

  std::cerr << "Finished setupe\n";
}
Beispiel #2
0
	void PolygonCollider::Init(std::vector<Vec2>& vec)
	{
		mType = PolygonType;

		FirstPoint(vec);
		PointAngle(vec);
		PointSort(vec, vertices);
		PointSearch(vec, vertices);

		Vec2 normal{};
		Vec2 u = vertices[1] - vertices[0];
		Vec2 v = vertices[2] - vertices[0];
		normal = Cross(u, v);
		Normalize(normal);
		for (unsigned i = 0; i < vertices.size(); i++)
		{
			vertices[i].nx = normal.x;
			vertices[i].ny = normal.y;
			vertices[i].nz = normal.z;
		}

		COPY_TO_VERTEXBUFFER();

		axes.reserve(getVertsNum());
		for (unsigned i = 0; i < getVertsNum(); i++) {
			// get the current vertex
			Vec2 p1 = vertices[i];
			// get the next vertex
			Vec2 p2 = vertices[i + 1 == getVertsNum() ? 0 : i + 1];
			// subtract thw two to get the edge vector
			Vec2 edge = Subtract(p1, p2);
			// get either perpendicular vector
			Vec2 normal = edge.Perpendicular();
			Normalize(normal);
			axes.emplace_back(normal);
		}
	}
void CMeshEditing::Convert2DProfileTo3D()
{
	if (this->UserInput2DProfile.empty())
	{
		return;
	}

	//judge the type of curve: open/closed according to the distance of the first and last point
	//get the average length
	double dTotalLen=0;
	for (unsigned int i=0;i<this->UserInput2DProfile.size()-1;i++)
	{
		Point_2 CurrentPoint(this->UserInput2DProfile.at(i).x,this->UserInput2DProfile.at(i).y);
		Point_2 NextPoint(this->UserInput2DProfile.at(i+1).x,this->UserInput2DProfile.at(i+1).y);
		dTotalLen=dTotalLen+sqrt(CGAL::squared_distance(CurrentPoint,NextPoint));
	}
	double dAverageLen=dTotalLen/(double)(this->UserInput2DProfile.size()-1);

	//get length between the first and last point
	Point_2 FirstPoint(this->UserInput2DProfile.front().x,this->UserInput2DProfile.front().y);
	Point_2 FinalPoint(this->UserInput2DProfile.back().x,this->UserInput2DProfile.back().y);
	double dFinalLen=sqrt(CGAL::squared_distance(FirstPoint,FinalPoint));

	//judge
	if (dFinalLen>dAverageLen*3)//open curve
	{
		CKWResearchWorkView* pView=(CKWResearchWorkView*)this->pDoc->GetView(RUNTIME_CLASS(CKWResearchWorkView));
		GLdouble* modelview=pView->GetModelview();
		GLdouble* projection=pView->GetProjection();
		GLint* viewport=pView->GetViewport();

		Point_3 StartPoint,EndPoint;
		Facet_handle FhPaintFacet;
		CPaintingOnMesh Painting;
		bool bResultStart=Painting.PaintingScrPointOnFrontalMesh(pDoc->GetMesh(),this->UserInput2DProfile.front(),StartPoint,
			FhPaintFacet,modelview,projection,viewport);
		bool bResultEnd=Painting.PaintingScrPointOnFrontalMesh(pDoc->GetMesh(),this->UserInput2DProfile.back(),EndPoint,
			FhPaintFacet,modelview,projection,viewport);
		
		if (bResultStart&&bResultEnd)//two points on mesh,deformation
		{
			DBWindowWrite("Deformation Handle Curve...\n");
			pDoc->GetMeshDeformation().SetDrawingCurveType(DEFORMATION_HANDLE_CURVE);//handle curve, if more than one point
			pDoc->GetMeshDeformation().SetCurvePoint2D(this->UserInput2DProfile);
			pDoc->GetMeshDeformation().Conver2DCurveTo3D(pDoc->GetMesh());
			pDoc->OnModeDeformation();
		}
		else if (!bResultStart && !bResultEnd)//two points not on mesh,cutting
		{
			DBWindowWrite("Cutting Curve...\n");
			pDoc->GetMeshCutting().SetDrawingCurveType(CUTTING_ACROSS_CURVE);
			pDoc->GetMeshCutting().SetCurvePoint2D(this->UserInput2DProfile);
			pDoc->GetMeshCutting().Conver2DCurveTo3D(pDoc->GetMesh());
			pDoc->OnModeCutting();
		}
		else
		{
			AfxMessageBox("Invalid Input!");
		}
	}
	else//closed curve
	{
		DBWindowWrite("Extrusion Curve...\n");
		pDoc->GetMeshExtrusion().SetDrawingCurveType(EXTRUSION_CLOSED_CURVE);
		pDoc->GetMeshExtrusion().SetCurvePoint2D(this->UserInput2DProfile);
		pDoc->GetMeshExtrusion().Conver2DCurveTo3D(pDoc->GetMesh());
		pDoc->OnModeExtrusion();
	}
	this->UserInput2DProfile.clear();
}
Beispiel #4
0
bool CCurviDetect2D::SuiviFreeman(utls::BAry *Image)
{
   // init tableau
   byte FreemanHoraire[] = {0, 2, 4, 6, 1, 3, 5, 7};

   // par sécurité
   BordAZero(Image->el[0],Image->cols(),Image->rows());

   /////////////////////////////////////////////////////////////////////////////////////
   //////////////////////////////////recherche du premier point/////////////////////////
   /////////////////////////////////////////////////////////////////////////////////////
   utls::BAry::pointer ptr=Image->first(), size=Image->last();
   IPoint2D FirstPoint(0,0);
   do 
   {  
      // find first unvisited point in the image
      for (; ptr<size && (*ptr)!=255; ptr++) ;

      // still in the image?
      if (ptr<size)
      {
         // translate offset to x,y
         FirstPoint.y = (ptr - Image->first()         ) / Image->cols();
         FirstPoint.x = (ptr - Image->el[FirstPoint.y]);
         /////////////////////////////////////////////////////////////////////////////////////
         //////////////////////////Etude de la connexité du premier point/////////////////////
         /////////////////////////////////////////////////////////////////////////////////////

         IPoint2D CurrentPoint = FirstPoint;
         bool Rebouclage = false, ConditionArret=true;   

         //allocation d'un pointeur pour ajouter une nouvelle liste à l'array
         ConnexityDegreeAFreemanCode ConnexityFirstPoint;
         ConnexityFirstPoint.ConnexityDegree = 0;
         for(int i=0;i<8;i++)
         {
            IPoint2D NewPoint = CurrentPoint;
            switch (i)
            {
            case 0 : NewPoint.x++; break;
            case 1 :
               {
                  NewPoint.x++;
                  NewPoint.y++;
               } 
               break;		
            case 2 : NewPoint.y++; break;
            case 3 : 
               {
                  NewPoint.x--;
                  NewPoint.y++;
               }
               break;
            case 4 : NewPoint.x--; break;
            case 5 : 
               {
                  NewPoint.x--;
                  NewPoint.y--; 
               }
               break;
            case 6 : NewPoint.y--; break;
            case 7 : 
               {
                  NewPoint.x++;
                  NewPoint.y--;
               }
               break;
            } // switch
            if (Image->el[NewPoint.y][NewPoint.x]==255)
            {
               ConnexityFirstPoint.ConnexityDegree++;
               ConnexityFirstPoint.FreemanCode[i]=true;
            }
            else
               ConnexityFirstPoint.FreemanCode[i]=false;
         } // for i - les 8 directions 

         /////////////////////////////////////////////////////////////////////////////////////
         //////////////////////////////////Parcours pour le suivi Freeman/////////////////////
         /////////////////////////////////////////////////////////////////////////////////////
         if(ConnexityFirstPoint.ConnexityDegree!=0)
         {
            PointList *ListePointContour = new PointList;
            ListePointContour->push_back(FirstPoint);
            CurrentPoint = FirstPoint;
            do
            {		
               int  CodeFreeman = 0, NbZero = 0, NbMoinsUn = 0;
               bool bFinFreeman = false, BoolRetour=false, CandidatTrouve = false;
               ConditionArret=true;
               do	
               {
                  IPoint2D NewPoint = CurrentPoint;
                  switch (FreemanHoraire[CodeFreeman])
                  {
                  case 0 : NewPoint.x++; break;
                  case 1 :
                     {
                        NewPoint.x++;
                        NewPoint.y++;
                     } 
                     break;		
                  case 2 : NewPoint.y++; break;
                  case 3 : 
                     {
                        NewPoint.x--;
                        NewPoint.y++;
                     }
                     break;
                  case 4 : NewPoint.x--; break;
                  case 5 : 
                     {
                        NewPoint.x--;
                        NewPoint.y--; 
                     }
                     break;
                  case 6 : NewPoint.y--; break;
                  case 7 : 
                     {
                        NewPoint.x++;
                        NewPoint.y--;
                     }
                     break;
                  } // fin switch
                  utls::BAry::value v = Image->el[NewPoint.y][NewPoint.x];
                  if (v == 0)            NbZero++;
                  if (v == MARKED_PIXEL) NbMoinsUn++;
                  if (v == 255)
                  {
                     ListePointContour->push_back(NewPoint);
                     CurrentPoint = NewPoint;
                     CandidatTrouve = true;
                     Image->el[NewPoint.y][NewPoint.x] = MARKED_PIXEL;
                     if (CurrentPoint == FirstPoint)
                     {
                        ConditionArret = false; //on sort si la tete = la queue
                        Rebouclage = true; // pas la peine de traiter la connexité
                     }
                     bFinFreeman=true; // pas la peine de continuer				
                  }
                  else// si on a pas trouvé de point blanc
                  {
                     if (CodeFreeman == 7)// et qu'on a balayé tous les freemans alors on sort
                     {
                        if (BoolRetour)
                           ConditionArret = false;
                        else
                        {
                           if(ListePointContour->size() > 1)
                           {                                 
                              BoolRetour=true;
                              Image->el[CurrentPoint.y][CurrentPoint.x] = MARKED_PIXEL;
                              PointList::iterator PositionQueue = ListePointContour->end();// ListePointContour->GetTailPosition();
                              PositionQueue--;
                              PositionQueue--;
                              CurrentPoint = *PositionQueue;
                              CodeFreeman = -1;
                              NbZero=0;
                              NbMoinsUn=0;
                           }
                           else
                           {	
                              ConditionArret = false;
                           }
                        } // fin else
                     }
                  }
                  CodeFreeman++;
                  if (CodeFreeman > 7) bFinFreeman=true;			
               } while (!bFinFreeman);

               if ((NbZero==7) && (CandidatTrouve==false))//extremité
               {
                  Image->el[CurrentPoint.y][CurrentPoint.x] = MARKED_PIXEL;
                  ConditionArret=false;
               }

               if ((NbZero<=7)&&(NbMoinsUn<=7)&&(CandidatTrouve==false))//cas d'un point emprisonné
               {
                  Image->el[CurrentPoint.y][CurrentPoint.x] = MARKED_PIXEL;
                  ConditionArret=false;
               }

               if ((NbZero==8)&&(CandidatTrouve==false))//cas d'un point isolé
               {
                  Image->el[CurrentPoint.y][CurrentPoint.x] = MARKED_PIXEL;
                  ConditionArret=false;
               }
            } while (ConditionArret); //condition d'arrêt

            if (ConnexityFirstPoint.ConnexityDegree>1 && !Rebouclage)
            {
               CurrentPoint = FirstPoint;
               do
               {
                  int  CodeFreeman = 0, NbZero = 0, NbMoinsUn = 0;
                  bool bFinFreeman = false, BoolRetour=false, CandidatTrouve = false;
                  ConditionArret=true;
                  do	
                  {
                     IPoint2D NewPoint = CurrentPoint;
                     switch (FreemanHoraire[CodeFreeman])
                     {
                     case 0 : NewPoint.x++; break;
                     case 1 :
                        {
                           NewPoint.x++;
                           NewPoint.y++;
                        } 
                        break;		
                     case 2 : NewPoint.y++; break;
                     case 3 : 
                        {
                           NewPoint.x--;
                           NewPoint.y++;
                        }
                        break;
                     case 4 : NewPoint.x--; break;
                     case 5 : 
                        {
                           NewPoint.x--;
                           NewPoint.y--; 
                        }
                        break;
                     case 6 : NewPoint.y--; break;
                     case 7 : 
                        {
                           NewPoint.x++;
                           NewPoint.y--;
                        }
                        break;
                     } // fin switch
                     utls::BAry::value v = Image->el[NewPoint.y][NewPoint.x];
                     if (v == 0)            NbZero++;
                     if (v == MARKED_PIXEL) NbMoinsUn++;
                     if (v == 255)
                     {
                        ListePointContour->push_front(NewPoint);
                        CurrentPoint = NewPoint;
                        CandidatTrouve = true;
                        Image->el[NewPoint.y][NewPoint.x] = MARKED_PIXEL;
                        if(CurrentPoint == FirstPoint)
                        {
                           Image->el[FirstPoint.y][FirstPoint.x] = MARKED_PIXEL;
                           ConditionArret = false; //on sort si la tete = la queue
                           Rebouclage = true; // pas la peine de traiter la connexité
                        }
                        bFinFreeman=true; // pas la peine de continuer
                     }
                     else// si on a pas trouvé de point blanc
                     {
                        if(CodeFreeman == 7)// et qu'on a balayé tous les freemans alors on sort
                        {
                           if(BoolRetour)
                              ConditionArret = false;
                           else
                           {
                              if(ListePointContour->size() > 1)
                              {
                                 BoolRetour=true;
                                 Image->el[CurrentPoint.y][CurrentPoint.x] = MARKED_PIXEL;
                                 PointList::iterator PositionQueue = ListePointContour->begin();   
                                 PositionQueue++;
                                 CurrentPoint = *PositionQueue;
                                 CodeFreeman = -1;
                                 NbZero=0;
                                 NbMoinsUn=0;
                              }
                              else
                                 ConditionArret = false;
                           }
                        }
                     }
                     CodeFreeman++;
                     if (CodeFreeman >7) bFinFreeman=true;
                  } while (!bFinFreeman);

                  if ((NbZero==7) && (CandidatTrouve==false))//extremité -- end of the edge
                  {
                     Image->el[CurrentPoint.y][CurrentPoint.x] = MARKED_PIXEL;
                     ConditionArret=false;
                  }

                  if ((NbZero<=7)&&(NbMoinsUn<=7)&&(CandidatTrouve==false))//cas d'un point emprisonné  -- problem blocked poimt
                  {
                     Image->el[CurrentPoint.y][CurrentPoint.x] = MARKED_PIXEL;
                     ConditionArret=false;
                  }

                  if ((NbZero==8)&&(CandidatTrouve==false))//cas d'un point isolé -- just one point
                  {
                     Image->el[CurrentPoint.y][CurrentPoint.x] = MARKED_PIXEL;
                     ConditionArret=false;
                  }
               }while (ConditionArret); //condition d'arrêt; //condition d'arrêt

            }//fin traitement cas U

            TabListePoint.push_back(ListePointContour);
         }// fin if point isolé
         else
            Image->el[FirstPoint.y][FirstPoint.x] = MARKED_PIXEL;
      }// fin if (ptr<size)
   } while (ptr<size);
   return true;
}