示例#1
0
void SplitPolygon(std::vector<pcs_polygon> &polygons, int polynum, vector3d plane_point, vector3d plane_normal, std::vector<pcs_polygon> &newpolys)
{
	std::vector<pcs_polygon> splitpolys(2); // 0 = front vert, 1 = back vert
	std::vector<int> pairs;
	std::vector<pcs_vertex> points;
	pairs.resize(polygons[polynum].verts.size() * 2);
	pcs_vertex temp;
	unsigned int i, j = 0;
	float uvdelta;

	for (i = 0; i < polygons[polynum].verts.size() * 2; i += 2)
	{
		pairs[i] = j % polygons[polynum].verts.size();
		pairs[i+1] = (j+1) % polygons[polynum].verts.size();
		j++;
	}

	float dtempa, dtempb;
	// compile the new list of points
	for (i = 0; i < pairs.size(); i += 2)
	{
		dtempa = DistanceToPlane(polygons[polynum].verts[pairs[i]].point, plane_point, plane_normal);
		dtempb = DistanceToPlane(polygons[polynum].verts[pairs[i+1]].point, plane_point, plane_normal);
		if ((dtempa <= 0.0001 && dtempa >= -0.0001) || (dtempb <= 0.0001 && dtempb >= -0.0001))
		// one of these points lays on the plane... add them both without modification
		{

			AddIfNotInList(points, polygons[polynum].verts[pairs[i]]);
			AddIfNotInList(points, polygons[polynum].verts[pairs[i+1]]);
		}
		else // neither of them was not on the plane.. are they on the same side?
		{

			if (InFrontofPlane(polygons[polynum].verts[pairs[i]].point, plane_point, plane_normal) == 
				InFrontofPlane(polygons[polynum].verts[pairs[i+1]].point, plane_point, plane_normal))
			// both on same side - add them
			{
				AddIfNotInList(points, polygons[polynum].verts[pairs[i]]);
				AddIfNotInList(points, polygons[polynum].verts[pairs[i+1]]);
			}
			else
			// different sides - cut and add
			{
				uvdelta = FindIntersection(temp.point, polygons[polynum].verts[pairs[i]].point, 
						polygons[polynum].verts[pairs[i+1]].point, plane_point, plane_normal);
				temp.norm = polygons[polynum].norm;
				temp.u = uvdelta * (polygons[polynum].verts[pairs[i]].u - polygons[polynum].verts[pairs[i+1]].u);
				temp.v = uvdelta * (polygons[polynum].verts[pairs[i]].v - polygons[polynum].verts[pairs[i+1]].v);

				AddIfNotInList(points, polygons[polynum].verts[pairs[i]]);
				AddIfNotInList(points, temp);
				AddIfNotInList(points, polygons[polynum].verts[pairs[i+1]]);
			}
		}
	}


	// split the polygons with the list we have

	int in = 0;
	for (i = 0; i < points.size(); i++)
	{
		dtempa = DistanceToPlane(points[i].point, plane_point, plane_normal) ;
		if (dtempa <= 0.0001 && dtempa >= -0.0001)
		// there WILL be two points in the list this is true for
		{
			AddIfNotInList(splitpolys[0].verts, points[i]);
			AddIfNotInList(splitpolys[1].verts, points[i]);
			
			if (in == 0)
				in = 1;
			else
				in = 0;
		}
		else
		{
			AddIfNotInList(splitpolys[in].verts, points[i]);
		}
	}

	// triangle our new polylist
	TriangulateMesh(splitpolys);

	// replace our current poly with polygon zero - add the others
	polygons[polynum] = splitpolys[0];
	in = newpolys.size();
	newpolys.resize(in+splitpolys.size());
	for (i = 1; i < splitpolys.size(); i++)
	{
		newpolys[in+i] = splitpolys[i];
	}
}
void MainWindow::createActions()
{
    /*
     File MENU
    */

    // New
    newAct = new QAction(QIcon(":/images/document-new.png"), tr("&New"), this);
    newAct->setShortcuts(QKeySequence::New);
    newAct->setStatusTip(tr("Create a new file"));
    connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));

    // Open
    openAct = new QAction(QIcon(":/images/folder-open.png"), tr("&Open..."), this);
    openAct->setShortcuts(QKeySequence::Open);
    openAct->setStatusTip(tr("Open an existing file"));
    connect(openAct, SIGNAL(triggered()), this, SLOT(open()));

    // Save
    saveAct = new QAction(QIcon(":/images/document-save.png"), tr("Save"), this);
    saveAct->setStatusTip(tr("Save file"));
    connect(saveAct, SIGNAL(triggered()), this, SLOT(OutputFoldedOBJ()));

    // Save As sub Menu
    saveAsFoldedOBJ = new QAction(tr("Folded OBJ"), this);
    saveAsFoldedOBJ->setStatusTip(tr("Save file as Folded OBJ"));
    connect(saveAsFoldedOBJ, SIGNAL(triggered()), this, SLOT(OutputFoldedOBJ()) );

    saveAsUnfoldedOBJ = new QAction(tr("Unfolded OBJ"), this);
    saveAsUnfoldedOBJ->setStatusTip(tr("Save file as Unfolded OBJ"));
    connect(saveAsUnfoldedOBJ, SIGNAL(triggered()), this, SLOT(OutputUnfoldedOBJ()) );

    saveAsFoldedINF= new QAction(tr("Folded INF"), this);
    saveAsFoldedINF->setStatusTip(tr("Save file as Folded INF"));
    connect(saveAsFoldedINF, SIGNAL(triggered()), this, SLOT(OutputFoldedINF()) );

    saveAsUnfoldedINF = new QAction(tr("Unfolded INF"), this);
    saveAsUnfoldedINF->setStatusTip(tr("Save file as Unfolded INF"));
    connect(saveAsUnfoldedINF, SIGNAL(triggered()), this, SLOT(OutputUnFoldedINF()) );

    // Export As
    exportAct = new QAction(tr("Export"), this);
    exportAct->setStatusTip(tr("Export file as"));
    connect(exportAct, SIGNAL(triggered()), this, SLOT(exportToFile()));

    // Print
    printAct = new QAction(tr("Print"), this);
    printAct->setStatusTip(tr("Print file "));
    connect(printAct, SIGNAL(triggered()), this, SLOT(print()));

    // Quit
    exitAct = new QAction(tr("Exit"), this);
    exitAct->setStatusTip(tr("Quit "));
    connect(exitAct, SIGNAL(triggered()), this, SLOT(quitApp()));

    /*
     Edit MENU
    */

    // Cut, copy and paste
    cutAct = new QAction(tr("Cut"), this);
    cutAct->setStatusTip(tr("Cut text"));
    cutAct->setEnabled(false);
    copyAct = new QAction(tr("Copy"), this);
    copyAct->setStatusTip(tr("Copy text"));
    copyAct->setEnabled(false);
    pasteAct = new QAction(tr("Paste"), this);
    pasteAct->setStatusTip(tr("Paste text"));
    pasteAct->setEnabled(false);
    connect(mainwidget, SIGNAL(copyAvailable(bool)),cutAct, SLOT(setEnabled(bool)));
    connect(mainwidget, SIGNAL(copyAvailable(bool)),copyAct, SLOT(setEnabled(bool)));
    connect(mainwidget, SIGNAL(copyAvailable(bool)),pasteAct, SLOT(setEnabled(bool)));

    /*
     * Mesh Operations Menu
     */
    triangulate = new QAction(tr("Triangulate mesh"), this);;
    triangulate->setStatusTip(tr("Triangulate mesh"));
    connect(triangulate, SIGNAL(triggered()), this, SLOT(TriangulateMesh()));

    /*
     Select Edges
    */
    selectAllEdges = new QAction(tr("Select All"), this);;
    selectAllEdges->setStatusTip(tr("Select All"));
    connect(selectAllEdges, SIGNAL(triggered()), this, SLOT(SelectAllEdges()));

    clearSelectionEdges = new QAction(tr("Clear Selected Edges"), this);;
    clearSelectionEdges->setStatusTip(tr("Clear Selected Edges"));
    connect(clearSelectionEdges, SIGNAL(triggered()), this, SLOT(ClearSelectionEdges()));

    selectInverseEdges = new QAction(tr( "Select Inverse Edges"), this);
    selectInverseEdges->setStatusTip(tr( "Select Inverse Edges"));
    connect(selectInverseEdges, SIGNAL(triggered()), this, SLOT(SelectInverseEdges()));

    selectMultipleEdges = new QAction(tr("Select Multiple Edges"), this);;
    selectMultipleEdges->setStatusTip(tr("Select Multiple Edges"));
    connect(selectMultipleEdges, SIGNAL(triggered()), this, SLOT(SelectMultipleEdges()));

    selectSimilarEdges = new QAction(tr("Select Similar Edges"), this);;
    selectSimilarEdges->setStatusTip(tr("Select Similar Edges"));
    connect(selectSimilarEdges, SIGNAL(triggered()), this, SLOT(SelectSimilarEdges()));

    selectWindowEdges = new QAction(tr("Select Window Edges"), this);;
    selectWindowEdges->setStatusTip(tr("Select Window Edges"));
    connect(selectWindowEdges, SIGNAL(triggered()), this, SLOT(SelectWindowEdges()));

    selectConnectedComponentEdges = new QAction(tr("Select Connected Component Edges"), this);;
    selectConnectedComponentEdges->setStatusTip(tr("Select Connected Component Edges"));
    connect(selectConnectedComponentEdges, SIGNAL(triggered()), this, SLOT(SelectConnectedComponentEdges()));

    selectShortestPathBetween2Vertices = new QAction(tr("Select Shortest Path Between 2 Vertices"), this);;
    selectShortestPathBetween2Vertices->setStatusTip(tr("Select Shortest Path Between 2 Vertices"));
    connect(selectShortestPathBetween2Vertices, SIGNAL(triggered()), this, SLOT(SelectShortestPathBetween2Vertices()));

    growSelectionEdges = new QAction(tr("Grow Selection Edges"), this);;
    growSelectionEdges->setStatusTip(tr("Grow Selection Edges"));
    connect(growSelectionEdges, SIGNAL(triggered()), this, SLOT(GrowSelectionEdges()));

    shrinkSelectionEdges = new QAction(tr("Shrink Selection Edges"), this);;
    shrinkSelectionEdges->setStatusTip(tr("Shrink Selection Edges"));
    connect(shrinkSelectionEdges, SIGNAL(triggered()), this, SLOT(ShrinkSelectionEdges()));

    selectEdgeLoop = new QAction(tr("Select Edge Loop"), this);;
    selectEdgeLoop->setStatusTip(tr("Select Edge Loop"));
    connect(selectEdgeLoop, SIGNAL(triggered()), this, SLOT(SelectEdgeLoop()));


    selectEdgeRing = new QAction(tr("Select Edge Ring"), this);;
    selectEdgeRing->setStatusTip(tr("Select Edge Ring"));
    connect(selectEdgeRing, SIGNAL(triggered()), this, SLOT(SelectEdgeRing()));

    selectEdgesFromFaces = new QAction(tr("Select Edges From Faces"), this);;
    selectEdgesFromFaces->setStatusTip(tr("Select Edges From Faces"));
    connect(selectEdgesFromFaces, SIGNAL(triggered()), this, SLOT(SelectEdgesFromFaces()));

    selectEdgesFromVertices = new QAction(tr("Select Edges From Vertices"), this);;
    selectEdgesFromVertices->setStatusTip(tr("Select Edges From Vertices"));
    connect(selectEdgesFromVertices, SIGNAL(triggered()), this, SLOT(SelectEdgesFromVertices()));


    /*
     Select Faces
    */
    selectAllFaces = new QAction(tr("Select All"), this);;
    selectAllFaces->setStatusTip(tr("Select All"));
    connect(selectAllFaces, SIGNAL(triggered()), this, SLOT(SelectAllFaces()));

    clearSelectionFaces = new QAction(tr("Clear Selected Faces"), this);;
    clearSelectionFaces->setStatusTip(tr("Clear Selected Faces"));
    connect(clearSelectionFaces, SIGNAL(triggered()), this, SLOT(ClearSelectionFaces()));

    selectInverseFaces = new QAction(tr( "Select Inverse Faces"), this);
    selectInverseFaces->setStatusTip(tr( "Select Inverse Faces"));
    connect(selectInverseFaces, SIGNAL(triggered()), this, SLOT(SelectInverseFaces()));

    selectMultipleFaces = new QAction(tr("Select Multiple Faces"), this);;
    selectMultipleFaces->setStatusTip(tr("Select Multiple Faces"));
    connect(selectMultipleFaces, SIGNAL(triggered()), this, SLOT(SelectMultipleFaces()));

    selectSimilarFaces = new QAction(tr("Select Similar Faces"), this);;
    selectSimilarFaces->setStatusTip(tr("Select Similar Faces"));
    connect(selectSimilarFaces, SIGNAL(triggered()), this, SLOT(SelectSimilarFaces()));

    selectWindowFaces = new QAction(tr("Select Window Faces"), this);;
    selectWindowFaces->setStatusTip(tr("Select Window Faces"));
    connect(selectWindowFaces, SIGNAL(triggered()), this, SLOT(SelectWindowFaces()));

    selectConnectedComponentFaces = new QAction(tr("Select Connected Component Faces"), this);;
    selectConnectedComponentFaces->setStatusTip(tr("Select Connected Component Faces"));
    connect(selectConnectedComponentFaces, SIGNAL(triggered()), this, SLOT(SelectConnectedComponentFaces()));

    selectFaceLoop = new QAction(tr("Select Face Loop"), this);;
    selectFaceLoop->setStatusTip(tr("Select Face Loop"));
    connect(selectFaceLoop, SIGNAL(triggered()), this, SLOT(SelectFaceLoop()));

    selectFacesFromVertices = new QAction(tr("Select Faces From Vertices"), this);;
    selectFacesFromVertices->setStatusTip(tr("Select Faces From Vertices"));
    connect(selectFacesFromVertices, SIGNAL(triggered()), this, SLOT(SelectFacesFromVertices()));

    selectFacesFromEdges= new QAction(tr("Select Faces From Edges"), this);;
    selectFacesFromEdges->setStatusTip(tr("Select Faces From Edges"));
    connect(selectFacesFromEdges, SIGNAL(triggered()), this, SLOT(SelectFacesFromEdges()));

    /*
     Select Vertices
    */

    /*
     Unfold MENU
    */

    onePiece = new QAction(tr("One Piece - Random"), this);
    onePiece->setStatusTip(tr("Unfold to one piece"));
    connect(onePiece, SIGNAL(triggered()), this, SLOT(createScaleDialog()));

    usingSelectionAsConnectors = new QAction(tr("Using Selection as connectors"), this);
    usingSelectionAsConnectors ->setStatusTip(tr("Using Selection as connectors"));
    connect(usingSelectionAsConnectors , SIGNAL(triggered()), this, SLOT(UseSelectionAsConnectors ()));
    usingSelectionAsFlaps= new QAction(tr("Using Selection as connectors"), this);
    usingSelectionAsFlaps->setStatusTip(tr("Using Selection as connectors"));
    connect(usingSelectionAsFlaps, SIGNAL(triggered()), this, SLOT(UseSelectionAsFlaps()));

    /*
     Display MENU
    */

    // show Original
    viewOriginal = new QAction(tr("Display Original"), this);
    viewOriginal->setStatusTip(tr("Display Original OBJ file"));
    viewOriginal->setCheckable(true);
    viewOriginal->setChecked(true);
    connect(viewOriginal, SIGNAL(triggered()), this, SLOT(ShowOriginal()));

    //Show Folded
    viewFolded = new QAction(tr("Display Folded"), this);
    viewFolded->setStatusTip(tr("Display Folded OBJ file"));
    viewFolded->setCheckable(true);
    viewFolded->setChecked(true);
    connect(viewFolded, SIGNAL(triggered()), this, SLOT(ShowFolded()));

    //Show unFolded
    viewUnfolded= new QAction(tr("Display UnFolded"), this);
    viewUnfolded->setStatusTip(tr("Display UnFolded OBJ file"));
    viewUnfolded->setCheckable(true);
    viewUnfolded->setChecked(true);
    connect(viewUnfolded, SIGNAL(triggered()), this, SLOT(ShowUnfolded()));

    //Show Triangle
    viewTriangle= new QAction(tr("Display UnFolded"), this);
    viewTriangle->setStatusTip(tr("Display UnFolded OBJ file"));
    viewTriangle->setCheckable(true);
    viewTriangle->setChecked(true);
    connect(viewTriangle, SIGNAL(triggered()), this, SLOT(ShowTriangle()));

    /*
     Flap Types MENU
    */

    // Use Flap type 1
    flapType1 = new QAction(QIcon(":/images/flapTypes/flapType1.png"), tr("Flap Type 1"), this);
    flapType1->setStatusTip(tr("Use Flap type 1"));
    flapType1->setCheckable(true);
    flapType1->setChecked(true);
    connect(flapType1, SIGNAL(triggered()), this, SLOT(FlapType1()));

    // Use Flap type 2
    flapType2 = new QAction(QIcon(":/images/flapTypes/flapType2.png"), tr("Flap Type 2"), this);
    flapType2->setStatusTip(tr("Use Flap type 2"));
    flapType2->setCheckable(true);
    flapType2->setChecked(true);
    connect(flapType2, SIGNAL(triggered()), this, SLOT(FlapType2()));

    // Use Flap type 3
    flapType3 = new QAction(QIcon(":/images/flapTypes/flapType3.png"), tr("Flap Type 3"), this);
    flapType3->setStatusTip(tr("Use Flap type 3"));
    flapType3->setCheckable(true);
    flapType3->setChecked(true);
    connect(flapType3, SIGNAL(triggered()), this, SLOT(FlapType3()));

    // Use Flap type 4
    flapType4 = new QAction(QIcon(":/images/flapTypes/flapType4.png"), tr("Flap Type 4"), this);
    flapType4->setStatusTip(tr("Use Flap type 4"));
    flapType4->setCheckable(true);
    flapType4->setChecked(true);
    connect(flapType4, SIGNAL(triggered()), this, SLOT(FlapType4()));

    /*
     Helps MENU
    */
    // About QT
    aboutQtAct = new QAction(tr("About &Qt"), this);
    aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
    connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(about()));



}