example.h

来自「finite element mesh 参数化有限元网格划分」· C头文件 代码 · 共 165 行

H
165
字号
/*! \page example MeshMaker Documented Example
 *
 * The following is an example of how to use the MeshMaker API. This code shows how to load a file, change colors and highlights, rotate the model, remove a vertex, perform vertex split and edge collapse:

 * \code
//  load a VRML file
if (mesh->openVRMLFile("vrml\\demo.wrl")!=OK) {
	MessageBox(NULL, "Unable to open file demo.wrl", "Error", MB_OK);
	return 0;
}

// set render mode
renderer->setRenderMode(SOLID);

/** example of picking faces **/
	
// set label
renderer->displayText("Playing Demo: Pick a face with the left mouse click (it's color will change)");
	
// pick a face
FaceID pickedFace1, pickedFace2;
renderer->pickFace(pickedFace1);
Color pickedFaceColor1(1.0, 0.0, 1.0);
renderer->setFaceColor(pickedFace1, &pickedFaceColor1);
	
// set label
renderer->displayText("Playing Demo: Pick a second face (it's color will change)");
	
// pick a second face
renderer->pickFace(pickedFace2);
Color pickedFaceColor2(1.0, 1.0, 0.0);
renderer->setFaceColor(pickedFace2, &pickedFaceColor2);

/** getting the joined edge ID's of the picked faces (if they're incident to one another) **/
	
// set label
renderer->displayText("Playing Demo: Highlighting the joined edge between the picked faces");
	
Sleep(1000);
EdgeID edgeID1, edgeID2;
RESULT result = mesh->getJoinedFacesEdge(pickedFace1, pickedFace2, edgeID1, edgeID2);
if (result==OK)
	renderer->highlightEdge(edgeID1, true);
Sleep(1000);
	
/** example of highlighting vertices and edges, and changing colors **/
	
// set label
renderer->displayText("Playing Demo: Highlights and colors");
	
Sleep(2000);
	
// change background color
Color bgColor(0.8, 0.2, 0.7);
renderer->setBgColor(bgColor);
Sleep(1000);
	
renderer->highlightVertex(8,true);
renderer->highlightEdge(6,true);
Color edgeColor(0.5, 0.2, 0.7);
renderer->setEdgeColor(6,&edgeColor);  // set color
Sleep(1000);
renderer->setEdgeColor(6);   // set default color
Sleep(1000);
renderer->highlightEdge(6,false);
renderer->highlightVertex(8,false);
Sleep(1000);
	
renderer->setAutoRefresh(false);
// rotate (and translate) model
for (int i=0; i<10; i++) {
	renderer->rotate(AXIS_X, -1);
	renderer->rotate(AXIS_Y, -1);
	renderer->translate(1, 0, 0);
	renderer->refreshScreen();
}
renderer->setAutoRefresh();
	
/** example of removing a vertex **/ 
	
renderer->displayText("Playing Demo: Removing highlighted vertex and triangulating the hole");
	
renderer->highlightVertex(12,true);
	
Sleep(1000);
	
LinkedList<Face>* faces = new LinkedList<Face>();  // a list of the new faces to be created
VertexID faceVertices[] = {0, 1, 3};
Face face(faceVertices);
faces->push_back(face);
faceVertices[0] = 3;  faceVertices[1] = 1;  faceVertices[2] = 2;
face.set(faceVertices);
faces->push_back(face);
LinkedList<FaceID> *newFaces = new LinkedList<FaceID>();
// remove the vertex with ID number 12
mesh->removeVertexTriangulate(12, faces, newFaces);  
// 2 faces were added, we read their ID's and color them
FaceID newFace = newFaces->front();
Color color(1.0, 1.0, 0.0);
renderer->setFaceColor(newFace, &color);
newFace = newFaces->back();
color[R]=0.0;
renderer->setFaceColor(newFace, &color);

Sleep(2000);
	
// rotate again
	
for (i=0; i<40; i++) {
	renderer->rotate(AXIS_Y, 3);
}
	
/** example of splitting a vertex **/
	
renderer->displayText("Playing Demo: Splitting highlighted vertex");
renderer->highlightVertex(8,true);
	
Sleep(2000);
	
// splitting the vertex, moving it from {-0.6 1 -1} to {-0.8 1.1 -1.4}
newFaces->clear();
Coord coord(-0.8, 1.1, -1.4); // coordinate of the new vertex
VertexID newVertex;
mesh->vertexSplit(8, coord, 3, 4, newVertex, newFaces);
// color the new triangles
renderer->colorFaces(newFaces);
	
Sleep(2000);
	
// rotate again
	
for (i=0; i<30; i++) {
	renderer->rotate(AXIS_Y, 3);
}
	
/** example of edge collapse **/
	
renderer->displayText("Playing Demo: Edge Collapse between the highlighted vertices");
// highlighting the 2 vertices
renderer->highlightVertex(13,true);
renderer->highlightVertex(6,true);
	
Sleep(2000);
	
// this is just for demo purposes - move edge 6 closer and closer to 13
	
Coord coord13;
Coord coord6;
mesh->getCoord(13, coord13);
for (i=0; i<20; i++ ) {
	mesh->getCoord(6, coord6);
	for (int i=0; i<3; i++) {
		coord6[i] = coord6[i]*0.9 + coord13[i]*0.1;
	}
	mesh->setCoord(6, coord6);	
}
	
mesh->edgeCollapse(6, 13);  // the actual edge collapse operation
	
// this code has the same result as calling edgeCollapse(6, 13, 20)
	
renderer->displayText();

\endcode
 */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?