예제 #1
0
void
PathBuilderCairo::QuadraticBezierTo(const Point &aCP1,
                                    const Point &aCP2)
{
  // We need to elevate the degree of this quadratic Bézier to cubic, so we're
  // going to add an intermediate control point, and recompute control point 1.
  // The first and last control points remain the same.
  // This formula can be found on http://fontforge.sourceforge.net/bezier.html
  Point CP0 = CurrentPoint();
  Point CP1 = (CP0 + aCP1 * 2.0) / 3.0;
  Point CP2 = (aCP2 + aCP1 * 2.0) / 3.0;
  Point CP3 = aCP2;

  cairo_path_data_t data;
  data.header.type = CAIRO_PATH_CURVE_TO;
  data.header.length = 4;
  mPathData.push_back(data);
  data.point.x = CP1.x;
  data.point.y = CP1.y;
  mPathData.push_back(data);
  data.point.x = CP2.x;
  data.point.y = CP2.y;
  mPathData.push_back(data);
  data.point.x = CP3.x;
  data.point.y = CP3.y;
  mPathData.push_back(data);

  mCurrentPoint = aCP2;
}
예제 #2
0
void
FlattenedPath::BezierTo(const Point &aCP1,
                        const Point &aCP2,
                        const Point &aCP3)
{
  MOZ_ASSERT(!mCalculatedLength);
  FlattenBezier(BezierControlPoints(CurrentPoint(), aCP1, aCP2, aCP3), this, kFlatteningTolerance);
}
예제 #3
0
void
FlattenedPath::QuadraticBezierTo(const Point &aCP1,
                                 const Point &aCP2)
{
  MOZ_ASSERT(!mCalculatedLength);
  // We need to elevate the degree of this quadratic Bézier to cubic, so we're
  // going to add an intermediate control point, and recompute control point 1.
  // The first and last control points remain the same.
  // This formula can be found on http://fontforge.sourceforge.net/bezier.html
  Point CP0 = CurrentPoint();
  Point CP1 = (CP0 + aCP1 * 2.0) / 3.0;
  Point CP2 = (aCP2 + aCP1 * 2.0) / 3.0;
  Point CP3 = aCP2;

  BezierTo(CP1, CP2, CP3);
}
예제 #4
0
void
PathBuilderCairo::QuadraticBezierTo(const Point &aCP1,
                                    const Point &aCP2)
{
  PrepareForWrite();
  CairoTempMatrix tempMatrix(*mPathContext, mTransform);

  // We need to elevate the degree of this quadratic Bézier to cubic, so we're
  // going to add an intermediate control point, and recompute control point 1.
  // The first and last control points remain the same.
  // This formula can be found on http://fontforge.sourceforge.net/bezier.html
  Point CP0 = CurrentPoint();
  Point CP1 = (CP0 + aCP1 * 2.0) / 3.0;
  Point CP2 = (aCP2 + aCP1 * 2.0) / 3.0;
  Point CP3 = aCP2;

  cairo_curve_to(*mPathContext, CP1.x, CP1.y, CP2.x, CP2.y, CP3.x, CP3.y);
}
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();
}
void CMeshCutting::Conver2DCurveTo3D(KW_Mesh& Mesh)
{
	if (this->CurvePoint2D.empty())
	{
		return;
	}

	CKWResearchWorkView* pView=(CKWResearchWorkView*)this->pDoc->GetView(RUNTIME_CLASS(CKWResearchWorkView));
	GLdouble* modelview=pView->GetModelview();
	GLdouble* projection=pView->GetProjection();
	GLint* viewport=pView->GetViewport();

	if (!this->hCuttingClosedCurveVertex3d.empty())
	{
		this->iDrawingCurveType=CUTTING_BITE_CURVE;
	}
	else
	{
		this->iDrawingCurveType=CUTTING_ACROSS_CURVE;
	}

	if (iDrawingCurveType==CUTTING_ACROSS_CURVE)
	{
		GeometryAlgorithm compute;
		compute.ProcessCurverPoint(this->CurvePoint2D,10.0);

		//convert UCP into opengl coordinate(on Znear) 
		vector<Point_3> UserCurvePoint;
		for (unsigned int i=0;i<this->CurvePoint2D.size();i++)
		{
			GLdouble  winX, winY, winZ; 
			GLdouble posX, posY, posZ; 

			winX =this->CurvePoint2D.at(i).x;
			winY = viewport[3] - (float)this->CurvePoint2D.at(i).y;
			glReadPixels((int)winX, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); 
			gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &posX, &posY, &posZ);
			Point_3 CurrentPoint(posX,posY,posZ);
			UserCurvePoint.push_back(CurrentPoint);
		}

		vector<Vertex_handle> CuttingClosedCurveVertex3d;
		CPaintingOnMesh Painting;
		if(Painting.PaintingClosedStrokeOnFrontalAndRearMesh(Mesh,UserCurvePoint,modelview,
			CuttingClosedCurveVertex3d))
		{
			this->hCuttingClosedCurveVertex3d=CuttingClosedCurveVertex3d;
			//get the plane for judging which part to cut
			Point_3 Point0=UserCurvePoint.front();
			Point_3 Point1=this->hCuttingClosedCurveVertex3d.front()->point();
			Point_3 Point2=this->hCuttingClosedCurveVertex3d.back()->point();
			this->SidePlane=Plane_3(Point0,Point1,Point2);
		}
	}
	else if (iDrawingCurveType==CUTTING_BITE_CURVE)
	{
		if (this->hCuttingClosedCurveVertex3d.empty())
		{
			this->CurvePoint2D.clear();
			return;
		}
		//convert UCP into opengl coordinate(on Znear) 
		GLdouble  winX, winY, winZ; 
		GLdouble posX, posY, posZ; 
		winX =this->CurvePoint2D.front().x;
		winY = viewport[3] - (float)this->CurvePoint2D.front().y;
		glReadPixels((int)winX, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); 
		gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &posX, &posY, &posZ);
		this->SidePoint=Point_3(posX,posY,posZ);

		CPaintingOnMesh Painting;
		Facet_handle temp;
		if(Painting.PaintingPointOnFrontalMesh(Mesh,this->SidePoint,temp,modelview))
		{
			CutMesh(Mesh);
			OBJHandle::UnitizeCGALPolyhedron(Mesh,false,false);
			Mesh.SetRenderInfo(true,true,true,true,true);
			this->hCuttingClosedCurveVertex3d.clear();
		}
		else
		{
			AfxMessageBox("Invalid Curve,could not judge which part to cut!");
		}
	}
	//else if (iDrawingCurveType==3)
	//{
	//	if (this->Tunel.GetTunVer().size()<2)
	//	{
	//		GeometryAlgorithm compute;
	//		compute.ProcessCurverPoint(this->CurvePoint2D);
	//		compute.MakeClosedStroke2d(this->CurvePoint2D);

	//		//convert UCP into opengl coordinate(on Znear) 
	//		vector<Point_3> UserCurvePoint;
	//		for (unsigned int i=0;i<this->CurvePoint2D.size();i++)
	//		{
	//			GLdouble  winX, winY, winZ; 
	//			GLdouble posX, posY, posZ; 

	//			winX =this->CurvePoint2D.at(i).x;
	//			winY = viewport[3] - (float)this->CurvePoint2D.at(i).y;
	//			glReadPixels((int)winX, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); 
	//			gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &posX, &posY, &posZ);
	//			Point_3 CurrentPoint(posX,posY,posZ);
	//			UserCurvePoint.push_back(CurrentPoint);
	//		}

	//		vector<Vertex_handle> TunnelCurve3d;
	//		CPaintingOnMesh Painting;
	//		if(Painting.PaintingClosedStrokeOnFrontalMesh(Mesh,UserCurvePoint,modelview,TunnelCurve3d))
	//		{
	//			if (this->Tunel.GetTunVer().size()==0)
	//			{
	//				this->Tunel.InputTunVer(TunnelCurve3d);
	//			}
	//			else if (this->Tunel.GetTunVer().size()==1)//remesh to get the two sketched circles
	//			{
	//				//the result curve is always ccw on screen,so reverse the second curve
	//				//and make it the same direction with the first one
	//				reverse(TunnelCurve3d.begin(),TunnelCurve3d.end());
	//				this->Tunel.InputTunVer(TunnelCurve3d);
	//				this->Tunel.CorrespondTunCircles();
	//				this->Tunel.SetRefPlane(this->BestFittingPlane,this->PlaneBoundaryPoints,
	//					this->RotateXAxisStartPoint,this->RotateXAxisEndPoint);
	//			}
	//			OBJHandle::UnitizeCGALPolyhedron(Mesh,false,false);
	//			Mesh.SetRenderInfo(true,true,true,true,true);
	//		}
	//	}
	//	else if (this->Tunel.GetTunVer().size()==2)//make tunnel along the sketched curve
	//	{
	//		GeometryAlgorithm compute;
	//		compute.ProcessCurverPoint(this->CurvePoint2D,15.0);

	//		vector<Point_3> vecTempPoints;
	//		CPaintingOnMesh PaintingOnMesh;
	//		int iResult=PaintingOnMesh.PaintingOnBFPlane(this->BestFittingPlane,modelview,projection,viewport,
	//			this->CurvePoint2D,vecTempPoints);
	//		if (iResult)
	//		{
	//			this->Tunel.SetTunnelDirectCurve(vecTempPoints);
	//		}

	//		//dig the hole
	//		this->Tunel.Tunnel(pDoc->GetMesh(),this->vecTestPoint);
	//		this->Tunel.clear();

	//		OBJHandle::UnitizeCGALPolyhedron(Mesh,false,false);
	//		Mesh.SetRenderInfo(true,true,true,true,true);
	//	}
	//}
	else
	{
		//do nothing
	}

	this->iDrawingCurveType=NONE_SELECTED;
	this->CurvePoint2D.clear();
}