-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCurveCreation.cc
More file actions
127 lines (109 loc) · 3.73 KB
/
testCurveCreation.cc
File metadata and controls
127 lines (109 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "MeshSim.h"
#include "SimCreateModel.h"
#include "SimDisplay.h"
#include "SimInfo.h"
#include "SimModel.h"
#include "SimUtil.h"
#include <iostream>
#include <math.h>
#include <algorithm> //[min|max]element
#include <array>
#include <cassert>
#include <fstream>
#include <iostream>
#include <limits> //std::numeric_limits
#include <map>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
void messageHandler(int type, const char *msg);
int main(int argc, char **argv) {
pGImporter importer; // the importer object used to create the geometry
pGVertex *vertices; // array to store the returned model vertices
pGEdge *edges; // array to store the returned model edges
pGFace *faces; // array to store the returned model faces
pGModel model; // pointer to the complete model
const auto prefix = std::string("foo");
std::string modelFileName = prefix + ".smd";
std::string meshFileName = prefix + ".sms";
const auto debug = false;
// You will want to place a try/catch around all SimModSuite calls,
// as errors are thrown.
try {
Sim_logOn("simMeshGen.log");
SimModel_start(); // Call before Sim_readLicenseFile
// NOTE: Sim_readLicenseFile() is for internal testing only. To use,
// pass in the location of a file containing your keys. For a release
// product, use Sim_registerKey()
Sim_readLicenseFile(0);
// Tessellation of GeomSim geometry requires Meshing to have started
MS_init();
Sim_setMessageHandler(messageHandler);
pProgress progress = Progress_new();
Progress_setDefaultCallback(progress);
// Create the pGImporter object
importer = GImporter_new();
const auto numPts = 4;
std::vector<double> pts = {0., 0., 0., 4., 1., 0., 8., 1., 0., 12., 0., 0.};
auto curve = SCurve_createPiecewiseLinear(numPts, pts.data());
vertices = new pGVertex[2];
double startVtx[3] = {0, 0, 0};
vertices[0] = GImporter_createVertex(importer, startVtx);
double endVtx[3] = {12, 0, 0};
vertices[1] = GImporter_createVertex(importer, endVtx);
edges = new pGEdge[1];
edges[0] = GImporter_createEdge(importer, vertices[0], vertices[1], curve,
0, 1, 1);
// Now complete the model and delete the importer
model = GImporter_complete(importer);
auto isValid = GM_isValid(model, 2, NULL);
if (!isValid) {
fprintf(stderr, "ERROR: model is not valid... exiting\n");
exit(EXIT_FAILURE);
} else {
cout << "Model is valid.\n";
}
GImporter_delete(importer);
cout << "Number of vertices in model: " << GM_numVertices(model) << endl;
cout << "Number of edges in model: " << GM_numEdges(model) << endl;
cout << "Number of faces in model: " << GM_numFaces(model) << endl;
cout << "Number of regions in model: " << GM_numRegions(model) << endl;
GM_write(model, modelFileName.c_str(), 0, 0);
// cleanup
GM_release(model);
Progress_delete(progress);
MS_exit();
Sim_unregisterAllKeys();
SimModel_stop();
Sim_logOff();
} catch (pSimInfo err) {
cerr << "SimModSuite error caught:" << endl;
cerr << " Error code: " << SimInfo_code(err) << endl;
cerr << " Error string: " << SimInfo_toString(err) << endl;
SimInfo_delete(err);
return 1;
} catch (...) {
cerr << "Unhandled exception caught" << endl;
return 1;
}
return 0;
}
void messageHandler(int type, const char *msg) {
switch (type) {
case Sim_InfoMsg:
cout << "Info: " << msg << endl;
break;
case Sim_DebugMsg:
cout << "Debug: " << msg << endl;
break;
case Sim_WarningMsg:
cout << "Warning: " << msg << endl;
break;
case Sim_ErrorMsg:
cout << "Error: " << msg << endl;
break;
}
return;
}