Debian Codegraph @

07p/plaut04/src/createLegend.c++

raw
1 #include "createLegend.h"
2
3 #include <Inventor/nodes/SoDirectionalLight.h>
4 #include <Inventor/nodes/SoSeparator.h>
5 #include <Inventor/nodes/SoTransform.h>
6 #include <Inventor/nodes/SoTexture2.h>
7 #include <Inventor/nodes/SoMaterial.h>
8 #include <Inventor/nodes/SoMaterialBinding.h>
9 #include <Inventor/nodes/SoCoordinate3.h>
10 #include <Inventor/nodes/SoTriangleStripSet.h>
11 #include <Inventor/nodes/SoShapeHints.h>
12 #include <Inventor/nodes/SoText3.h>
13 #include <Inventor/nodes/SoText2.h>
14 #include <Inventor/nodes/SoFont.h>
15
16 #include <Inventor/nodes/SoPerspectiveCamera.h>
17
18 #define FONT_SIZE 12
19
20 ///////////////////////////////////////////////////////////////////////////////
21 //
22 SoSeparator *
23 printScaleAt(SbVec3f position, double size, double value)
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26 {
27 SoSeparator * textSep = new SoSeparator;
28
29 SoMaterial * txtMtl = new SoMaterial;
30 txtMtl->diffuseColor.setValue(1, 1, 1);
31 textSep->addChild(txtMtl);
32
33 SoFont * txtFont = new SoFont;
34 txtFont->size = size;
35 textSep->addChild(txtFont);
36
37 SoTransform * txtXform = new SoTransform;
38 txtXform->translation.setValue(position);
39 textSep->addChild(txtXform);
40
41 char strScale[10];
42 sprintf(strScale, "%8.3e", value);
43
44 SoText2 * txt = new SoText2;
45 txt->string.setValue(strScale);
46 textSep->addChild(txt);
47 return textSep;
48 }
49
50 ////////////////////////////////////////////////////////////////////////////////
51 //
52 SoSeparator *
53 printScaleAt(SbVec3f position, double size, const char* strScale)
54 //
55 ////////////////////////////////////////////////////////////////////////////////
56 {
57 SoSeparator * textSep = new SoSeparator;
58
59 SoMaterial * txtMtl = new SoMaterial;
60 txtMtl->diffuseColor.setValue(1, 1, 1);
61 textSep->addChild(txtMtl);
62
63 SoFont * txtFont = new SoFont;
64 txtFont->size = size;
65 textSep->addChild(txtFont);
66
67 SoTransform * txtXform = new SoTransform;
68 txtXform->translation.setValue(position);
69 textSep->addChild(txtXform);
70
71 //SoText3 * txt = new SoText3;
72 SoText2 * txt = new SoText2;
73 txt->string.setValue(strScale);
74 textSep->addChild(txt);
75 return textSep;
76 }
77
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 SoSeparator *
81 createLegend(SbVec3f pos, double values[5])
82 //
83 ////////////////////////////////////////////////////////////////////////////////
84 {
85 SoSeparator *legend= new SoSeparator;
86 SoMaterial *legendMaterial = new SoMaterial;
87 SoTransform *legendXform = new SoTransform;
88
89 // SoOrthographicCamera *legendCamera = new SoOrthographicCamera;
90 // legend->addChild(legendCamera);
91
92 legendXform->translation.setValue(pos);
93 legendXform->scaleFactor.setValue(0.2,0.5,1);
94 // legendXform->rotation.setValue(-1,0,0,M_PI_2);
95 legend->addChild(legendXform);
96
97 static float vertexPositions[6][3]=
98 {
99 {
100 0.25, -0.5, 0
101 }
102 ,
103 {
104 -0.25, -0.5, 0
105 }
106 ,
107 {
108 0.25, 0.0, 0
109 },
110 {-0.25, 0.0,0},
111 {
112 0.25,0.5,0
113 }
114 ,
115 {
116 -0.25, 0.5,0
117 }
118 };
119
120 static float colors[6][3] =
121 {
122 {
123 0,0,1
124 }
125 ,
126 {
127 0,0,1
128 }
129 ,
130 {
131 0,1,0
132 }
133 ,
134 {
135 0,1,0
136 }
137 ,
138 {
139 1,0,0
140 }
141 ,
142 {
143 1,0,0
144 }
145 };
146 static int32_t numVertices[1]={6};
147
148 SoShapeHints * legendHints = new SoShapeHints;
149 legendHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
150 legend->addChild(legendHints);
151
152 legendMaterial->diffuseColor.setValues(0, 6, colors);
153 //legendMaterial->transparency = 0.8;
154 legend->addChild(legendMaterial);
155
156 SoMaterialBinding *legendMtlBinding = new SoMaterialBinding;
157 legendMtlBinding->value = SoMaterialBinding::PER_VERTEX;
158 legend->addChild(legendMtlBinding);
159
160 SoCoordinate3 *legendCoords = new SoCoordinate3;
161 legendCoords->point.setValues(0,6,vertexPositions);
162 legend->addChild(legendCoords);
163
164 SoTriangleStripSet * legendStripSet = new SoTriangleStripSet;
165 legendStripSet->numVertices.setValues(0, 1, numVertices);
166 legend->addChild(legendStripSet);
167
168 SbVec3f vec;
169 for(int i=0; i<5; ++i)
170 {
171 vec.setValue(0.30, i*0.25-0.55, 0);
172 legend->addChild(printScaleAt(vec, FONT_SIZE, values[i]));
173 }
174 return legend;
175 }
176
177
178 ///////////////////////////////////////////////////////////////////////////////
179 //
180 SoSeparator *
181 createDiscreteLegend(SbVec3f pos, SbColor lineColors[13])
182 ///////////////////////////////////////////////////////////////////////////////
183 {
184 const char *tyNames[13]=
185 {
186 "None","BP Alg", "Fold Alg", "Hopf Bif",
187 "Reg UZ","UZ Par","Fold Dif", "BP Dif",
188 "Pd DBL","Torus","End Pt","No Conv","OTHERS"
189 };
190 SoSeparator *legend= new SoSeparator;
191 SoMaterial *legendMaterial = new SoMaterial;
192 SoTransform *legendXform = new SoTransform;
193
194
195 legendXform->translation.setValue(pos);
196 legendXform->scaleFactor.setValue(0.2,0.5,1);
197 legend->addChild(legendXform);
198
199 static float vertexPositions[13*4][3];
200
201 static SbColor colors[13];
202 static int32_t numVertices[13]={4,4,4,4,4,4,4,4,4,4,4,4,4};
203 float tcolor[3];
204
205 int j;
206 for(int i = 0; i < 13; ++i)
207 {
208 j = i*4;
209 vertexPositions[j][0]= 0.25;
210 vertexPositions[j][1]= -0.5 + i/13.0;
211 vertexPositions[j][2]= 0;
212
213 vertexPositions[j+1][0]= -0.25;
214 vertexPositions[j+1][1]= vertexPositions[j][1];
215 vertexPositions[j+1][2]= 0;
216
217 vertexPositions[j+2][0]= 0.25;
218 vertexPositions[j+2][1]= -0.5 + (i+1)/13.0;
219 vertexPositions[j+2][2]= 0;
220
221 vertexPositions[j+3][0]= -0.25;
222 vertexPositions[j+3][1]= vertexPositions[j+2][1];
223 vertexPositions[j+3][2]= 0;
224
225 lineColors[i].getValue(tcolor[0],tcolor[1], tcolor[2]);
226 colors[i].setValue(tcolor);
227 }
228
229 SoShapeHints * legendHints = new SoShapeHints;
230 legendHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
231 legend->addChild(legendHints);
232
233 legendMaterial->diffuseColor.setValues(0, 13, colors);
234 legend->addChild(legendMaterial);
235
236 SoMaterialBinding *legendMtlBinding = new SoMaterialBinding;
237 legendMtlBinding->value = SoMaterialBinding::PER_PART;
238 legend->addChild(legendMtlBinding);
239
240 SoCoordinate3 *legendCoords = new SoCoordinate3;
241 legendCoords->point.setValues(0,52,vertexPositions);
242 legend->addChild(legendCoords);
243
244 SoTriangleStripSet * legendStripSet = new SoTriangleStripSet;
245 legendStripSet->numVertices.setValues(0, 13, numVertices);
246 legend->addChild(legendStripSet);
247
248 SbVec3f vec;
249 for(int i=0; i<13; ++i)
250 {
251 vec.setValue(0.28, -0.5+i/13.0, 0);
252 legend->addChild(printScaleAt(vec, FONT_SIZE, tyNames[i]));
253 }
254 return legend;
255 }
256
257
258 ///////////////////////////////////////////////////////////////////////////////
259 //
260 SoSeparator *
261 createBranchLegend(SbVec3f pos, SbColor lineColors[13])
262 //
263 ///////////////////////////////////////////////////////////////////////////////
264 {
265 char tyNames[13][10]=
266 {
267 "BR 1","BR 2", "BR 3", "BR 4",
268 "BR 5","BR 6","BR 7", "BR 8",
269 "BR 9","BR 10","BR 11","BR 12","BR 13"
270 };
271 SoSeparator *legend= new SoSeparator;
272 SoMaterial *legendMaterial = new SoMaterial;
273 SoTransform *legendXform = new SoTransform;
274
275 legendXform->translation.setValue(pos);
276 legendXform->scaleFactor.setValue(0.2,0.5,1);
277 legend->addChild(legendXform);
278
279 static float vertexPositions[13*4][3];
280
281 static SbColor colors[13];
282 static int32_t numVertices[13]={4,4,4,4,4,4,4,4,4,4,4,4,4};
283 float tcolor[3];
284
285 int j;
286 for(int i = 0; i < 13; ++i)
287 {
288 j = i*4;
289 vertexPositions[j][0]= 0.25;
290 vertexPositions[j][1]= -0.5 + i/13.0;
291 vertexPositions[j][2]= 0;
292
293 vertexPositions[j+1][0]= -0.25;
294 vertexPositions[j+1][1]= vertexPositions[j][1];
295 vertexPositions[j+1][2]= 0;
296
297 vertexPositions[j+2][0]= 0.25;
298 vertexPositions[j+2][1]= -0.5 + (i+1)/13.0;
299 vertexPositions[j+2][2]= 0;
300
301 vertexPositions[j+3][0]= -0.25;
302 vertexPositions[j+3][1]= vertexPositions[j+2][1];
303 vertexPositions[j+3][2]= 0;
304
305 lineColors[i].getValue(tcolor[0],tcolor[1], tcolor[2]);
306 colors[i].setValue(tcolor);
307 }
308
309 SoShapeHints * legendHints = new SoShapeHints;
310 legendHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
311 legend->addChild(legendHints);
312
313 legendMaterial->diffuseColor.setValues(0, 13, colors);
314 legend->addChild(legendMaterial);
315
316 SoMaterialBinding *legendMtlBinding = new SoMaterialBinding;
317 legendMtlBinding->value = SoMaterialBinding::PER_PART;
318 legend->addChild(legendMtlBinding);
319
320 SoCoordinate3 *legendCoords = new SoCoordinate3;
321 legendCoords->point.setValues(0,52,vertexPositions);
322 legend->addChild(legendCoords);
323
324 SoTriangleStripSet * legendStripSet = new SoTriangleStripSet;
325 legendStripSet->numVertices.setValues(0, 13, numVertices);
326 legend->addChild(legendStripSet);
327
328 SbVec3f vec;
329 for(int i=0; i<13; ++i)
330 {
331 vec.setValue(0.28, -0.5+i/13.0, 0);
332 legend->addChild(printScaleAt(vec, FONT_SIZE, tyNames[i]));
333 }
334 return legend;
335 }
336
337 ///////////////////////////////////////////////////////////////////////////////
338 //
339 SoSeparator *
340 createStabilityLegend(SbVec3f pos, SbColor lineColors[2])
341 //
342 ///////////////////////////////////////////////////////////////////////////////
343 {
344 char tyNames[][10]={"UNSTB","STB"};
345 SoSeparator *legend= new SoSeparator;
346 SoMaterial *legendMaterial = new SoMaterial;
347 SoTransform *legendXform = new SoTransform;
348
349
350 legendXform->translation.setValue(pos);
351 legendXform->scaleFactor.setValue(0.2,0.5,1);
352 legend->addChild(legendXform);
353
354 static float vertexPositions[2*4][3];
355
356 static SbColor colors[2];
357 static int32_t numVertices[2]={4,4};
358 float tcolor[3];
359
360 int j;
361 for(int i = 0; i < 2; ++i)
362 {
363 j = i*4;
364 vertexPositions[j][0]= 0.26;
365 vertexPositions[j][1]= -0.5 + i/2.0;
366 vertexPositions[j][2]= 0;
367
368 vertexPositions[j+1][0]= -0.24;
369 vertexPositions[j+1][1]= vertexPositions[j][1];
370 vertexPositions[j+1][2]= 0;
371
372 vertexPositions[j+2][0]= 0.26;
373 vertexPositions[j+2][1]= -0.5 + (i+1)/2.0;
374 vertexPositions[j+2][2]= 0;
375
376 vertexPositions[j+3][0]= -0.24;
377 vertexPositions[j+3][1]= vertexPositions[j+2][1];
378 vertexPositions[j+3][2]= 0;
379
380 lineColors[i].getValue(tcolor[0],tcolor[1], tcolor[2]);
381 colors[i].setValue(tcolor);
382 }
383
384 SoShapeHints * legendHints = new SoShapeHints;
385 legendHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
386 legend->addChild(legendHints);
387
388 legendMaterial->diffuseColor.setValues(0, 2, colors);
389 legend->addChild(legendMaterial);
390
391 SoMaterialBinding *legendMtlBinding = new SoMaterialBinding;
392 legendMtlBinding->value = SoMaterialBinding::PER_PART;
393 legend->addChild(legendMtlBinding);
394
395 SoCoordinate3 *legendCoords = new SoCoordinate3;
396 legendCoords->point.setValues(0,52,vertexPositions);
397 legend->addChild(legendCoords);
398
399 SoTriangleStripSet * legendStripSet = new SoTriangleStripSet;
400 legendStripSet->numVertices.setValues(0, 2, numVertices);
401 legend->addChild(legendStripSet);
402
403 SbVec3f vec;
404 for(int i=0; i<2; ++i)
405 {
406 vec.setValue(0.28, -0.5+i/2.0, 0);
407 legend->addChild(printScaleAt(vec, FONT_SIZE, tyNames[i]));
408 }
409 return legend;
410 }