Bug Summary

File:OMEdit/OMEditLIB/Animation/ExtraShapes.cpp
Warning:line 422, column 26
Value stored to 'basePlane' during its initialization is never read

Annotated Source Code

[?] Use j/k keys for keyboard navigation

1/*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14 * ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the Open Source Modelica
17 * Consortium (OSMC) Public License (OSMC-PL) are obtained
18 * from OSMC, either from the above address,
19 * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20 * http://www.openmodelica.org, and in the OpenModelica distribution.
21 * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22 *
23 * This program is distributed WITHOUT ANY WARRANTY; without
24 * even the implied warranty of MERCHANTABILITY or FITNESS
25 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27 *
28 * See the full OSMC Public License conditions for more details.
29 *
30 */
31/*
32 * @author Volker Waurich <volker.waurich@tu-dresden.de>
33 */
34
35#include "ExtraShapes.h"
36#include <iostream>
37
38
39/*!
40 * \brief absoluteVector
41 * \param the input vector
42 * gets the length of a vector
43 * \return the length
44 */
45float absoluteVector(osg::Vec3f vec)
46{
47 return std::sqrt(std::pow(vec[0], 2) + std::pow(vec[1], 2) + std::pow(vec[2], 2));
48}
49
50/*!
51 * \brief normalize
52 * \param the input vector
53 * normalizes a vector
54 * \return the normalized vector
55 */
56osg::Vec3f normalizeVec(osg::Vec3f vec) {
57 float abs = absoluteVector(vec);
58 return osg::Vec3f(vec[0]/abs, vec[1] / abs, vec[2] / abs);
59}
60
61
62
63
64/*!
65 * \brief Pipecylinder::Pipecylinder
66 * creates a pipe or pipecylinder geometry
67 */
68Pipecylinder::Pipecylinder(float rI, float rO, float l) :
69 osg::Geometry()
70{
71 const int nEdges = 16;
72 double phi = 2 * M_PI3.14159265358979323846/nEdges;
73 int vertIdx = 0;
74 //VERTICES
75 osg::Vec3Array* vertices = new osg::Vec3Array;
76 osg::Vec3Array* normals = new osg::Vec3Array;
77 osg::Vec2Array* texcoords = new osg::Vec2Array;
78 float radiusRatioShift = rI/rO*0.5f;
79 //we need so set the vertices multiple times to have a unique set of vertices per facet.
80 //Thats needed for the normals which are assigned per vertex.
81 //Also keep in mind to normalize the normals
82
83 //THE BASE PLANE VERTICES
84 // inner base ring
85 for (int i = 0; i < nEdges; i++) {
86 vertices->push_back(osg::Vec3(sin(phi*i)*rI, cos(phi*i)*rI, 0));
87 normals->push_back(osg::Vec3(0.0f,0.0f,-1.0f));
88 texcoords->push_back(osg::Vec2((sin(phi*i)*radiusRatioShift)+0.5f, (cos(phi*i)*radiusRatioShift)+0.5f));
89 vertIdx++;
90 }
91 // outer base ring
92 for (int i = 0; i < nEdges; i++) {
93 vertices->push_back(osg::Vec3(sin(phi*i)*rO, cos(phi*i)*rO, 0));
94 normals->push_back(osg::Vec3(0.0f,0.0f,-1.0f));
95 texcoords->push_back((osg::Vec2((sin(phi*i)*0.5f)+0.5f, (cos(phi*i)*0.5f)+0.5f)));
96 vertIdx++;
97 }
98 //THE TOP PLANE VERTICES
99 // inner end ring
100 for (int i = 0; i < nEdges; i++) {
101 vertices->push_back(osg::Vec3(sin(phi*i)*rI, cos(phi*i)*rI, l));
102 normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
103 texcoords->push_back(osg::Vec2((sin(phi*i)*radiusRatioShift)+0.5f, (cos(phi*i)*radiusRatioShift)+0.5f));
104 vertIdx++;
105 }
106 // outer end ring
107 for (int i = 0; i < nEdges; i++) {
108 vertices->push_back(osg::Vec3(sin(phi*i)*rO, cos(phi*i)*rO, l));
109 normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
110 texcoords->push_back(osg::Vec2((sin(phi*i)*0.5f)+0.5f, (cos(phi*i)*0.5f)+0.5f));
111 vertIdx++;
112 }
113
114 //BASE AND TOP PLANES
115 // base plane bottom (since the planes share the same normals, we can use vertices multiple times to create planes)
116 osg::DrawElementsUInt* basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
117 basePlane->push_back(0);
118 basePlane->push_back(nEdges-1);
119 basePlane->push_back(2*nEdges-1);
120 basePlane->push_back(nEdges);
121 this->addPrimitiveSet(basePlane);
122
123 for (int i = 0; i < (nEdges-1); i++) {
124 basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
125 basePlane->push_back(0 + i);
126 basePlane->push_back(1 + i);
127 basePlane->push_back(nEdges +1 +i);
128 basePlane->push_back(nEdges + 0 + i);
129 this->addPrimitiveSet(basePlane);
130 }
131
132 // base plane top (since the planes share the same normals, we can use vertices multiple times to create planes)
133 basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
134 basePlane->push_back(0+2*nEdges);
135 basePlane->push_back(nEdges - 1 + 2 * nEdges);
136 basePlane->push_back(2 * nEdges - 1 + 2 * nEdges);
137 basePlane->push_back(nEdges + 2 * nEdges);
138 this->addPrimitiveSet(basePlane);
139
140 for (int i = (2 * nEdges); i < (nEdges - 1 + (2 * nEdges)); i++) {
141 basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
142 basePlane->push_back(0 + i);
143 basePlane->push_back(1 + i);
144 basePlane->push_back(nEdges + 1 + i);
145 basePlane->push_back(nEdges + 0 + i);
146 this->addPrimitiveSet(basePlane);
147 }
148
149 //AND AGAIN FOR THE OUTER LATERAL PLANES
150 for (int i = 0; i < nEdges; i++) {
151 int j = i+1;
152 // the vertices
153 vertices->push_back(osg::Vec3(sin(phi*i)*rO, cos(phi*i)*rO, 0));
154 vertices->push_back(osg::Vec3(sin(phi*j)*rO, cos(phi*j)*rO, 0));
155 vertices->push_back(osg::Vec3(sin(phi*j)*rO, cos(phi*j)*rO, l));
156 vertices->push_back(osg::Vec3(sin(phi*i)*rO, cos(phi*i)*rO, l));
157 // the normals
158 double phiN = phi*(i+0.5);
159 normals->push_back(normalizeVec(osg::Vec3(sin(phiN)*rO, cos(phiN)*rO, 0)));
160 normals->push_back(normalizeVec(osg::Vec3(sin(phiN)*rO, cos(phiN)*rO, 0)));
161 normals->push_back(normalizeVec(osg::Vec3(sin(phiN)*rO, cos(phiN)*rO, 0)));
162 normals->push_back(normalizeVec(osg::Vec3(sin(phiN)*rO, cos(phiN)*rO, 0)));
163 //the texture coordinates
164 texcoords->push_back(osg::Vec2(1.0f*i/(nEdges), 1.0f));
165 texcoords->push_back(osg::Vec2(1.0f*j/(nEdges), 1.0f));
166 texcoords->push_back(osg::Vec2(1.0f*j/(nEdges), 0.0f));
167 texcoords->push_back(osg::Vec2(1.0f*i/(nEdges), 0.0f));
168 //the planes
169 basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
170 basePlane->push_back(vertIdx);
171 basePlane->push_back(vertIdx+1);
172 basePlane->push_back(vertIdx+2);
173 basePlane->push_back(vertIdx+3);
174 this->addPrimitiveSet(basePlane);
175 vertIdx = vertIdx+4;
176 }
177
178 //AND AGAIN FOR THE INNER LATERAL PLANES
179 for (int i = 0; i < nEdges; i++) {
180 int j = i+1;
181 // the vertices
182 vertices->push_back(osg::Vec3(sin(phi*i)*rI, cos(phi*i)*rI, 0));
183 vertices->push_back(osg::Vec3(sin(phi*j)*rI, cos(phi*j)*rI, 0));
184 vertices->push_back(osg::Vec3(sin(phi*j)*rI, cos(phi*j)*rI, l));
185 vertices->push_back(osg::Vec3(sin(phi*i)*rI, cos(phi*i)*rI, l));
186 // the normals
187 double phiN = phi*(i+0.5);
188 normals->push_back(normalizeVec(osg::Vec3(-sin(phiN)*rI, -cos(phiN)*rI, 0)));
189 normals->push_back(normalizeVec(osg::Vec3(-sin(phiN)*rI, -cos(phiN)*rI, 0)));
190 normals->push_back(normalizeVec(osg::Vec3(-sin(phiN)*rI, -cos(phiN)*rI, 0)));
191 normals->push_back(normalizeVec(osg::Vec3(-sin(phiN)*rI, -cos(phiN)*rI, 0)));
192 //the texture coordinates
193 texcoords->push_back(osg::Vec2(1.0f*i/(nEdges), 0.0f));
194 texcoords->push_back(osg::Vec2(1.0f*j/(nEdges), 0.0f));
195 texcoords->push_back(osg::Vec2(1.0f*j/(nEdges), 1.0f));
196 texcoords->push_back(osg::Vec2(1.0f*i/(nEdges), 1.0f));
197 //the planes
198 basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
199 basePlane->push_back(vertIdx);
200 basePlane->push_back(vertIdx+1);
201 basePlane->push_back(vertIdx+2);
202 basePlane->push_back(vertIdx+3);
203 this->addPrimitiveSet(basePlane);
204 vertIdx = vertIdx+4;
205 }
206
207 this->setVertexArray(vertices);
208 this->setNormalArray(normals);
209 this->setTexCoordArray(0,texcoords);
210 this->setNormalBinding( osg::Geometry::BIND_PER_VERTEX);
211}
212
213/*!
214 * \brief Spring::getNormal
215 * \param the input vector
216 * \param the length of the out vector
217 * gets an arbitrary normal to the input vector
218 * \return the normal
219 */
220osg::Vec3f Spring::getNormal(osg::Vec3f vec, float length) {
221 osg::Vec3f vecN = normalizeVec(vec);
222 osg::Vec3f vecN_Abs = osg::Vec3f(std::abs(vecN[0]), std::abs(vecN[1]), std::abs(vecN[2]));
223
224 //Get max value in vec
225 float maxVal = std::fmaxf(std::fmaxf(vecN_Abs[0], vecN_Abs[1] ), vecN_Abs[2]);
226 int imax = 0;
227 if (vecN_Abs[0] == maxVal)
228 imax = 0;
229 else if (vecN_Abs[1] == maxVal)
230 imax = 1;
231 else
232 imax = 2;
233
234 int rest[2] = {0,0};
235
236 switch (imax) {
237 case(0) : rest[0] = 1; rest[1] = 2 ; break;
238 case(1) : rest[0] = 0; rest[1] = 2 ; break;
239 case(2) : rest[0] = 0; rest[1] = 1 ; break;
240 }
241 //calc a normal vector
242 osg::Vec3f n = osg::Vec3f(0, 0, 0);
243 n[rest[0]] = 1;
244 n[rest[1]] = 1;
245 n[imax] = -(vecN[rest[0]] + vecN[rest[1]]) / vecN[imax];
246 n = normalizeVec(n);
247 n[0] = n[0] * length;
248 n[1] = n[1] * length;
249 n[2] = n[2] * length;
250 return n;
251}
252
253
254/*!
255 * \brief Spring::angleBetweenVectors
256 * \param vector1
257 * \param vector2
258 * gets the angle between 2 vectors
259 * \return the angle
260 */
261float Spring::angleBetweenVectors(osg::Vec3f vec1, osg::Vec3f vec2)
262{
263 float scalarProduct = vec1[0] * vec2[0] + vec1[1] * vec2[1] + vec1[2] * vec2[2];
264 return (std::acos(scalarProduct/(absoluteVector(vec1)*absoluteVector(vec2)))/* / M_PI * 180*/);
265}
266
267/*!
268 * \brief Spring::rotateX
269 * \param vector1
270 * \param angle
271 * rotates the vector around the cartesian x axis with angle phi
272 * \return the rotated vector
273 */
274osg::Vec3f Spring::rotateX(osg::Vec3f vec, float phi)
275{
276 return osg::Vec3f( vec[0],
277 vec[1] * std::cos(phi) - vec[2] * std::sin(phi),
278 vec[1] * std::sin(phi) + vec[2] * std::cos(phi));
279}
280
281/*!
282 * \brief Spring::rotateY
283 * \param vector1
284 * \param angle
285 * rotates the vector around the cartesian y axis with angle phi
286 * \return the rotated vector
287 */
288osg::Vec3f Spring::rotateY(osg::Vec3f vec, float phi)
289{
290 return osg::Vec3f( vec[2] * std::sin(phi) + vec[0] * std::cos(phi),
291 vec[1],
292 vec[2] * std::cos(phi) - vec[0] * std::sin(phi));
293}
294
295/*!
296 * \brief Spring::rotateZ
297 * \param vector1
298 * \param angle
299 * rotates the vector around the cartesian z axis with angle phi
300 * \return the rotated vector
301 */
302osg::Vec3f Spring::rotateZ(osg::Vec3f vec, float phi)
303{
304 return osg::Vec3f( vec[0] * std::cos(phi) - vec[1] * std::sin(phi),
305 vec[0] * std::sin(phi) + vec[1] * std::cos(phi),
306 vec[2]);
307}
308
309/*!
310 * \brief Spring::rotateArbitraryAxis_expensive
311 * \param vector1
312 * \param rotation axis
313 * \param angle
314 * rotates the vector around the given axis with angle phi, this is a bit odd, use rotateArbitraryAxis
315 * \return the rotated vector
316 */
317osg::Vec3f Spring::rotateArbitraryAxis_expensive(osg::Vec3f vec, osg::Vec3f axis, float phi)
318{
319 //this is how I would do it by hand. Check out rotateArbitraryAxis, thats the shortest formula.
320 //There is also still something wrong in here
321 osg::Vec3f axisN = normalizeVec(axis);
322 osg::Vec3f aux = vec;
323 //angle between vec and x, rotate in xz-plane
324 float phiX = angleBetweenVectors(axisN, osg::Vec3f(1, 0, 0));
325 aux = rotateX(aux, phiX);
326 //angle between vec and x, rotate in z axis
327 float phiY = angleBetweenVectors(axisN, osg::Vec3f(0, 1, 0));
328 aux = rotateY(aux, phiY);
329 // rotate around z
330 aux = rotateZ(aux, phi);
331 // and reverse
332 aux = rotateY(aux, -phiY);
333 aux = rotateX(aux, -phiX);
334 return aux;
335}
336
337/*!
338 * \brief Spring::rotateArbitraryAxis
339 * \param vector1
340 * \param rotation axis
341 * \param angle
342 * rotates the vector around the given axis with angle phi
343 * \return the rotated vector
344 */
345osg::Vec3f Spring::rotateArbitraryAxis(osg::Vec3f vec, osg::Vec3f axis, float phi)
346{
347 osg::Vec3f axisN = normalizeVec(axis);
348 float M1_1 = (1 - std::cos(phi)) * axisN[0] * axisN[0] + std::cos(phi) * 1 + std::sin(phi) * 0;
349 float M1_2 = (1 - std::cos(phi)) * axisN[0] * axisN[1] + std::cos(phi) * 0 + std::sin(phi) * (-axisN[2]);
350 float M1_3 = (1 - std::cos(phi)) * axisN[0] * axisN[2] + std::cos(phi) * 0 + std::sin(phi) * (axisN[1]);
351 float M2_1 = (1 - std::cos(phi)) * axisN[0] * axisN[1] + std::cos(phi) * 0 + std::sin(phi) * (axisN[2]);
352 float M2_2 = (1 - std::cos(phi)) * axisN[1] * axisN[1] + std::cos(phi) * 1 + std::sin(phi) * 0;
353 float M2_3 = (1 - std::cos(phi)) * axisN[1] * axisN[2] + std::cos(phi) * 0 + std::sin(phi) * (-axisN[0]);
354 float M3_1 = (1 - std::cos(phi)) * axisN[0] * axisN[2] + std::cos(phi) * 0 + std::sin(phi) * (-axisN[1]);
355 float M3_2 = (1 - std::cos(phi)) * axisN[1] * axisN[2] + std::cos(phi) * 0 + std::sin(phi) * (axisN[0]);
356 float M3_3 = (1 - std::cos(phi)) * axisN[2] * axisN[2] + std::cos(phi) * 1 + std::sin(phi) * 0;
357 return osg::Vec3f(M1_1*vec[0]+ M1_2*vec[1]+ M1_3*vec[2], M2_1*vec[0] + M2_2*vec[1] + M2_3*vec[2], M3_1*vec[0] + M3_2*vec[1] + M3_3*vec[2]);
358}
359
360
361/*!
362 * \brief Spring::Spring
363 * \param center radius of the coil
364 * \param radius of the wire
365 * \param number of windings
366 * \param the length
367 * creates an osg spring geometry
368 */
369Spring::Spring(float r, float rWire, float nWindings, float l) :
370 osg::Geometry()
371{
372 float R = r;
373 float L = l;
374 float RWIRE = rWire;
375 float NWIND = nWindings;
376
377 const int ELEMENTS_WINDING = 10;
378 const int ELEMENTS_CONTOUR = 6;
379
380 this->getPrimitiveSetList().clear();
381
382 //the inner line points
383 int numSegments = (ELEMENTS_WINDING * NWIND) + 1;
384 mpSplineVertices = new osg::Vec3Array(numSegments);
385
386 for (int segIdx = 0; segIdx < numSegments; segIdx++)
387 {
388 float x = std::sin(2 * M_PI3.14159265358979323846 / ELEMENTS_WINDING * segIdx) * R;
389 float y = std::cos(2 * M_PI3.14159265358979323846 / ELEMENTS_WINDING * segIdx) * R;
390 float z = L / numSegments * segIdx;
391 (*mpSplineVertices)[segIdx].set(osg::Vec3(x,y,z));
392 }
393
394 //the outer points for the facettes
395 int numVertices = (numSegments + 1)*ELEMENTS_CONTOUR;
396 mpOuterVertices = new osg::Vec3Array(numVertices);
397 osg::Vec3f normal;
398 osg::Vec3f v1;
399 osg::Vec3f v2;
400 int vertIdx = 0;
401 for (int i = 0; i < numSegments-1; i++)
402 {
403 v1 = mpSplineVertices->at(i);
404 v2 = mpSplineVertices->at(i + 1);
405 normal = osg::Vec3f(v2[0] - v1[0], v2[1] - v1[1], v2[2] - v1[2]);
406 osg::Vec3f vec0 = normal;
407 normal = getNormal(normal, RWIRE);
408 for (int i1 = 0; i1 < ELEMENTS_CONTOUR; i1++)
409 {
410 float angle = M_PI3.14159265358979323846 * 2 / ELEMENTS_CONTOUR * i1;
411 osg::Vec3f a1 = rotateArbitraryAxis(normal, vec0, angle);
412 (*mpOuterVertices)[vertIdx].set(osg::Vec3f((v1[0] + a1[0]), (v1[1] + a1[1]), (v1[2] + a1[2])));
413 vertIdx++;
414 }
415 }
416
417 // pass the created vertex array to the points geometry object.
418 this->setVertexArray(mpOuterVertices);
419
420 //PLANES
421 // base plane bottom
422 osg::DrawElementsUInt* basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
Value stored to 'basePlane' during its initialization is never read
423 int numFacettes = ELEMENTS_CONTOUR * (numSegments - 2);
424 for (int i = 0; i < numFacettes; i++) {
425 basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
426 basePlane->push_back(i);
427 basePlane->push_back(i + 1);
428 basePlane->push_back(i + ELEMENTS_CONTOUR);
429 basePlane->push_back(i + ELEMENTS_CONTOUR-1);
430 this->addPrimitiveSet(basePlane);
431 }
432 //std::cout << "NUM " << mpOuterVertices->size() << std::endl;
433 //this->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, mpOuterVertices->size()));
434}
435
436
437/*!
438 * \brief getAutoCADRGB
439 * get rgb color values for AutoCAD colorcoding accoridng to: http://sub-atomic.com/~moses/acadcolors.html
440 * \param int colorCode
441 */
442osg::Vec4f getAutoCADRGB(int colorCode)
443{
444 const osg::Vec4f colorArray[] = {osg::Vec4f(0.0/255.0, 0.0/255.0, 0.0/255.0, 1.0),
445 osg::Vec4f(255.0/255.0, 0.0/255.0, 0.0/255.0, 1.0),
446 osg::Vec4f(255.0/255.0, 255.0/255.0, 0.0/255.0, 1.0),
447 osg::Vec4f(0.0/255.0, 255.0/255.0, 0.0/255.0, 1.0),
448 osg::Vec4f(0.0/255.0, 255.0/255.0, 255.0/255.0, 1.0),
449 osg::Vec4f(0.0/255.0, 0.0/255.0, 255.0/255.0, 1.0),
450 osg::Vec4f(255.0/255.0, 0.0/255.0, 255.0/255.0, 1.0),
451 osg::Vec4f(255.0/255.0, 255.0/255.0, 255.0/255.0, 1.0),
452 osg::Vec4f(65.0/255.0, 65.0/255.0, 65.0/255.0, 1.0),
453 osg::Vec4f(128.0/255.0, 128.0/255.0, 128.0/255.0, 1.0),
454 osg::Vec4f(255.0/255.0, 0.0/255.0, 0.0/255.0, 1.0),
455 osg::Vec4f(255.0/255.0, 170.0/255.0, 170.0/255.0, 1.0),
456 osg::Vec4f(189.0/255.0, 0.0/255.0, 0.0/255.0, 1.0),
457 osg::Vec4f(189.0/255.0, 126.0/255.0, 126.0/255.0, 1.0),
458 osg::Vec4f(129.0/255.0, 0.0/255.0, 0.0/255.0, 1.0),
459 osg::Vec4f(129.0/255.0, 86.0/255.0, 86.0/255.0, 1.0),
460 osg::Vec4f(104.0/255.0, 0.0/255.0, 0.0/255.0, 1.0),
461 osg::Vec4f(104.0/255.0, 69.0/255.0, 69.0/255.0, 1.0),
462 osg::Vec4f(79.0/255.0, 0.0/255.0, 0.0/255.0, 1.0),
463 osg::Vec4f(79.0/255.0, 53.0/255.0, 53.0/255.0, 1.0),
464 osg::Vec4f(255.0/255.0, 63.0/255.0, 0.0/255.0, 1.0),
465 osg::Vec4f(255.0/255.0, 191.0/255.0, 170.0/255.0, 1.0),
466 osg::Vec4f(189.0/255.0, 46.0/255.0, 0.0/255.0, 1.0),
467 osg::Vec4f(189.0/255.0, 141.0/255.0, 126.0/255.0, 1.0),
468 osg::Vec4f(129.0/255.0, 31.0/255.0, 0.0/255.0, 1.0),
469 osg::Vec4f(129.0/255.0, 96.0/255.0, 86.0/255.0, 1.0),
470 osg::Vec4f(104.0/255.0, 25.0/255.0, 0.0/255.0, 1.0),
471 osg::Vec4f(104.0/255.0, 78.0/255.0, 69.0/255.0, 1.0),
472 osg::Vec4f(79.0/255.0, 19.0/255.0, 0.0/255.0, 1.0),
473 osg::Vec4f(79.0/255.0, 59.0/255.0, 53.0/255.0, 1.0),
474 osg::Vec4f(255.0/255.0, 127.0/255.0, 0.0/255.0, 1.0),
475 osg::Vec4f(255.0/255.0, 212.0/255.0, 170.0/255.0, 1.0),
476 osg::Vec4f(189.0/255.0, 94.0/255.0, 0.0/255.0, 1.0),
477 osg::Vec4f(189.0/255.0, 157.0/255.0, 126.0/255.0, 1.0),
478 osg::Vec4f(129.0/255.0, 64.0/255.0, 0.0/255.0, 1.0),
479 osg::Vec4f(129.0/255.0, 107.0/255.0, 86.0/255.0, 1.0),
480 osg::Vec4f(104.0/255.0, 52.0/255.0, 0.0/255.0, 1.0),
481 osg::Vec4f(104.0/255.0, 86.0/255.0, 69.0/255.0, 1.0),
482 osg::Vec4f(79.0/255.0, 39.0/255.0, 0.0/255.0, 1.0),
483 osg::Vec4f(79.0/255.0, 66.0/255.0, 53.0/255.0, 1.0),
484 osg::Vec4f(255.0/255.0, 191.0/255.0, 0.0/255.0, 1.0),
485 osg::Vec4f(255.0/255.0, 234.0/255.0, 170.0/255.0, 1.0),
486 osg::Vec4f(189.0/255.0, 141.0/255.0, 0.0/255.0, 1.0),
487 osg::Vec4f(189.0/255.0, 173.0/255.0, 126.0/255.0, 1.0),
488 osg::Vec4f(129.0/255.0, 96.0/255.0, 0.0/255.0, 1.0),
489 osg::Vec4f(129.0/255.0, 118.0/255.0, 86.0/255.0, 1.0),
490 osg::Vec4f(104.0/255.0, 78.0/255.0, 0.0/255.0, 1.0),
491 osg::Vec4f(104.0/255.0, 95.0/255.0, 69.0/255.0, 1.0),
492 osg::Vec4f(79.0/255.0, 59.0/255.0, 0.0/255.0, 1.0),
493 osg::Vec4f(79.0/255.0, 73.0/255.0, 53.0/255.0, 1.0),
494 osg::Vec4f(255.0/255.0, 255.0/255.0, 0.0/255.0, 1.0),
495 osg::Vec4f(255.0/255.0, 255.0/255.0, 170.0/255.0, 1.0),
496 osg::Vec4f(189.0/255.0, 189.0/255.0, 0.0/255.0, 1.0),
497 osg::Vec4f(189.0/255.0, 189.0/255.0, 126.0/255.0, 1.0),
498 osg::Vec4f(129.0/255.0, 129.0/255.0, 0.0/255.0, 1.0),
499 osg::Vec4f(129.0/255.0, 129.0/255.0, 86.0/255.0, 1.0),
500 osg::Vec4f(104.0/255.0, 104.0/255.0, 0.0/255.0, 1.0),
501 osg::Vec4f(104.0/255.0, 104.0/255.0, 69.0/255.0, 1.0),
502 osg::Vec4f(79.0/255.0, 79.0/255.0, 0.0/255.0, 1.0),
503 osg::Vec4f(79.0/255.0, 79.0/255.0, 53.0/255.0, 1.0),
504 osg::Vec4f(191.0/255.0, 255.0/255.0, 0.0/255.0, 1.0),
505 osg::Vec4f(234.0/255.0, 255.0/255.0, 170.0/255.0, 1.0),
506 osg::Vec4f(141.0/255.0, 189.0/255.0, 0.0/255.0, 1.0),
507 osg::Vec4f(173.0/255.0, 189.0/255.0, 126.0/255.0, 1.0),
508 osg::Vec4f(96.0/255.0, 129.0/255.0, 0.0/255.0, 1.0),
509 osg::Vec4f(118.0/255.0, 129.0/255.0, 86.0/255.0, 1.0),
510 osg::Vec4f(78.0/255.0, 104.0/255.0, 0.0/255.0, 1.0),
511 osg::Vec4f(95.0/255.0, 104.0/255.0, 69.0/255.0, 1.0),
512 osg::Vec4f(59.0/255.0, 79.0/255.0, 0.0/255.0, 1.0),
513 osg::Vec4f(73.0/255.0, 79.0/255.0, 53.0/255.0, 1.0),
514 osg::Vec4f(127.0/255.0, 255.0/255.0, 0.0/255.0, 1.0),
515 osg::Vec4f(212.0/255.0, 255.0/255.0, 170.0/255.0, 1.0),
516 osg::Vec4f(94.0/255.0, 189.0/255.0, 0.0/255.0, 1.0),
517 osg::Vec4f(157.0/255.0, 189.0/255.0, 126.0/255.0, 1.0),
518 osg::Vec4f(64.0/255.0, 129.0/255.0, 0.0/255.0, 1.0),
519 osg::Vec4f(107.0/255.0, 129.0/255.0, 86.0/255.0, 1.0),
520 osg::Vec4f(52.0/255.0, 104.0/255.0, 0.0/255.0, 1.0),
521 osg::Vec4f(86.0/255.0, 104.0/255.0, 69.0/255.0, 1.0),
522 osg::Vec4f(39.0/255.0, 79.0/255.0, 0.0/255.0, 1.0),
523 osg::Vec4f(66.0/255.0, 79.0/255.0, 53.0/255.0, 1.0),
524 osg::Vec4f(63.0/255.0, 255.0/255.0, 0.0/255.0, 1.0),
525 osg::Vec4f(191.0/255.0, 255.0/255.0, 170.0/255.0, 1.0),
526 osg::Vec4f(46.0/255.0, 189.0/255.0, 0.0/255.0, 1.0),
527 osg::Vec4f(141.0/255.0, 189.0/255.0, 126.0/255.0, 1.0),
528 osg::Vec4f(31.0/255.0, 129.0/255.0, 0.0/255.0, 1.0),
529 osg::Vec4f(96.0/255.0, 129.0/255.0, 86.0/255.0, 1.0),
530 osg::Vec4f(25.0/255.0, 104.0/255.0, 0.0/255.0, 1.0),
531 osg::Vec4f(78.0/255.0, 104.0/255.0, 69.0/255.0, 1.0),
532 osg::Vec4f(19.0/255.0, 79.0/255.0, 0.0/255.0, 1.0),
533 osg::Vec4f(59.0/255.0, 79.0/255.0, 53.0/255.0, 1.0),
534 osg::Vec4f(0.0/255.0, 255.0/255.0, 0.0/255.0, 1.0),
535 osg::Vec4f(170.0/255.0, 255.0/255.0, 170.0/255.0, 1.0),
536 osg::Vec4f(0.0/255.0, 189.0/255.0, 0.0/255.0, 1.0),
537 osg::Vec4f(126.0/255.0, 189.0/255.0, 126.0/255.0, 1.0),
538 osg::Vec4f(0.0/255.0, 129.0/255.0, 0.0/255.0, 1.0),
539 osg::Vec4f(86.0/255.0, 129.0/255.0, 86.0/255.0, 1.0),
540 osg::Vec4f(0.0/255.0, 104.0/255.0, 0.0/255.0, 1.0),
541 osg::Vec4f(69.0/255.0, 104.0/255.0, 69.0/255.0, 1.0),
542 osg::Vec4f(0.0/255.0, 79.0/255.0, 0.0/255.0, 1.0),
543 osg::Vec4f(53.0/255.0, 79.0/255.0, 53.0/255.0, 1.0),
544 osg::Vec4f(0.0/255.0, 255.0/255.0, 63.0/255.0, 1.0),
545 osg::Vec4f(170.0/255.0, 255.0/255.0, 191.0/255.0, 1.0),
546 osg::Vec4f(0.0/255.0, 189.0/255.0, 46.0/255.0, 1.0),
547 osg::Vec4f(126.0/255.0, 189.0/255.0, 141.0/255.0, 1.0),
548 osg::Vec4f(0.0/255.0, 129.0/255.0, 31.0/255.0, 1.0),
549 osg::Vec4f(86.0/255.0, 129.0/255.0, 96.0/255.0, 1.0),
550 osg::Vec4f(0.0/255.0, 104.0/255.0, 25.0/255.0, 1.0),
551 osg::Vec4f(69.0/255.0, 104.0/255.0, 78.0/255.0, 1.0),
552 osg::Vec4f(0.0/255.0, 79.0/255.0, 19.0/255.0, 1.0),
553 osg::Vec4f(53.0/255.0, 79.0/255.0, 59.0/255.0, 1.0),
554 osg::Vec4f(0.0/255.0, 255.0/255.0, 127.0/255.0, 1.0),
555 osg::Vec4f(170.0/255.0, 255.0/255.0, 212.0/255.0, 1.0),
556 osg::Vec4f(0.0/255.0, 189.0/255.0, 94.0/255.0, 1.0),
557 osg::Vec4f(126.0/255.0, 189.0/255.0, 157.0/255.0, 1.0),
558 osg::Vec4f(0.0/255.0, 129.0/255.0, 64.0/255.0, 1.0),
559 osg::Vec4f(86.0/255.0, 129.0/255.0, 107.0/255.0, 1.0),
560 osg::Vec4f(0.0/255.0, 104.0/255.0, 52.0/255.0, 1.0),
561 osg::Vec4f(69.0/255.0, 104.0/255.0, 86.0/255.0, 1.0),
562 osg::Vec4f(0.0/255.0, 79.0/255.0, 39.0/255.0, 1.0),
563 osg::Vec4f(53.0/255.0, 79.0/255.0, 66.0/255.0, 1.0),
564 osg::Vec4f(0.0/255.0, 255.0/255.0, 191.0/255.0, 1.0),
565 osg::Vec4f(170.0/255.0, 255.0/255.0, 234.0/255.0, 1.0),
566 osg::Vec4f(0.0/255.0, 189.0/255.0, 141.0/255.0, 1.0),
567 osg::Vec4f(126.0/255.0, 189.0/255.0, 173.0/255.0, 1.0),
568 osg::Vec4f(0.0/255.0, 129.0/255.0, 96.0/255.0, 1.0),
569 osg::Vec4f(86.0/255.0, 129.0/255.0, 118.0/255.0, 1.0),
570 osg::Vec4f(0.0/255.0, 104.0/255.0, 78.0/255.0, 1.0),
571 osg::Vec4f(69.0/255.0, 104.0/255.0, 95.0/255.0, 1.0),
572 osg::Vec4f(0.0/255.0, 79.0/255.0, 59.0/255.0, 1.0),
573 osg::Vec4f(53.0/255.0, 79.0/255.0, 73.0/255.0, 1.0),
574 osg::Vec4f(0.0/255.0, 255.0/255.0, 255.0/255.0, 1.0),
575 osg::Vec4f(170.0/255.0, 255.0/255.0, 255.0/255.0, 1.0),
576 osg::Vec4f(0.0/255.0, 189.0/255.0, 189.0/255.0, 1.0),
577 osg::Vec4f(126.0/255.0, 189.0/255.0, 189.0/255.0, 1.0),
578 osg::Vec4f(0.0/255.0, 129.0/255.0, 129.0/255.0, 1.0),
579 osg::Vec4f(86.0/255.0, 129.0/255.0, 129.0/255.0, 1.0),
580 osg::Vec4f(0.0/255.0, 104.0/255.0, 104.0/255.0, 1.0),
581 osg::Vec4f(69.0/255.0, 104.0/255.0, 104.0/255.0, 1.0),
582 osg::Vec4f(0.0/255.0, 79.0/255.0, 79.0/255.0, 1.0),
583 osg::Vec4f(53.0/255.0, 79.0/255.0, 79.0/255.0, 1.0),
584 osg::Vec4f(0.0/255.0, 191.0/255.0, 255.0/255.0, 1.0),
585 osg::Vec4f(170.0/255.0, 234.0/255.0, 255.0/255.0, 1.0),
586 osg::Vec4f(0.0/255.0, 141.0/255.0, 189.0/255.0, 1.0),
587 osg::Vec4f(126.0/255.0, 173.0/255.0, 189.0/255.0, 1.0),
588 osg::Vec4f(0.0/255.0, 96.0/255.0, 129.0/255.0, 1.0),
589 osg::Vec4f(86.0/255.0, 118.0/255.0, 129.0/255.0, 1.0),
590 osg::Vec4f(0.0/255.0, 78.0/255.0, 104.0/255.0, 1.0),
591 osg::Vec4f(69.0/255.0, 95.0/255.0, 104.0/255.0, 1.0),
592 osg::Vec4f(0.0/255.0, 59.0/255.0, 79.0/255.0, 1.0),
593 osg::Vec4f(53.0/255.0, 73.0/255.0, 79.0/255.0, 1.0),
594 osg::Vec4f(0.0/255.0, 127.0/255.0, 255.0/255.0, 1.0),
595 osg::Vec4f(170.0/255.0, 212.0/255.0, 255.0/255.0, 1.0),
596 osg::Vec4f(0.0/255.0, 94.0/255.0, 189.0/255.0, 1.0),
597 osg::Vec4f(126.0/255.0, 157.0/255.0, 189.0/255.0, 1.0),
598 osg::Vec4f(0.0/255.0, 64.0/255.0, 129.0/255.0, 1.0),
599 osg::Vec4f(86.0/255.0, 107.0/255.0, 129.0/255.0, 1.0),
600 osg::Vec4f(0.0/255.0, 52.0/255.0, 104.0/255.0, 1.0),
601 osg::Vec4f(69.0/255.0, 86.0/255.0, 104.0/255.0, 1.0),
602 osg::Vec4f(0.0/255.0, 39.0/255.0, 79.0/255.0, 1.0),
603 osg::Vec4f(53.0/255.0, 66.0/255.0, 79.0/255.0, 1.0),
604 osg::Vec4f(0.0/255.0, 63.0/255.0, 255.0/255.0, 1.0),
605 osg::Vec4f(170.0/255.0, 191.0/255.0, 255.0/255.0, 1.0),
606 osg::Vec4f(0.0/255.0, 46.0/255.0, 189.0/255.0, 1.0),
607 osg::Vec4f(126.0/255.0, 141.0/255.0, 189.0/255.0, 1.0),
608 osg::Vec4f(0.0/255.0, 31.0/255.0, 129.0/255.0, 1.0),
609 osg::Vec4f(86.0/255.0, 96.0/255.0, 129.0/255.0, 1.0),
610 osg::Vec4f(0.0/255.0, 25.0/255.0, 104.0/255.0, 1.0),
611 osg::Vec4f(69.0/255.0, 78.0/255.0, 104.0/255.0, 1.0),
612 osg::Vec4f(0.0/255.0, 19.0/255.0, 79.0/255.0, 1.0),
613 osg::Vec4f(53.0/255.0, 59.0/255.0, 79.0/255.0, 1.0),
614 osg::Vec4f(0.0/255.0, 0.0/255.0, 255.0/255.0, 1.0),
615 osg::Vec4f(170.0/255.0, 170.0/255.0, 255.0/255.0, 1.0),
616 osg::Vec4f(0.0/255.0, 0.0/255.0, 189.0/255.0, 1.0),
617 osg::Vec4f(126.0/255.0, 126.0/255.0, 189.0/255.0, 1.0),
618 osg::Vec4f(0.0/255.0, 0.0/255.0, 129.0/255.0, 1.0),
619 osg::Vec4f(86.0/255.0, 86.0/255.0, 129.0/255.0, 1.0),
620 osg::Vec4f(0.0/255.0, 0.0/255.0, 104.0/255.0, 1.0),
621 osg::Vec4f(69.0/255.0, 69.0/255.0, 104.0/255.0, 1.0),
622 osg::Vec4f(0.0/255.0, 0.0/255.0, 79.0/255.0, 1.0),
623 osg::Vec4f(53.0/255.0, 53.0/255.0, 79.0/255.0, 1.0),
624 osg::Vec4f(63.0/255.0, 0.0/255.0, 255.0/255.0, 1.0),
625 osg::Vec4f(191.0/255.0, 170.0/255.0, 255.0/255.0, 1.0),
626 osg::Vec4f(46.0/255.0, 0.0/255.0, 189.0/255.0, 1.0),
627 osg::Vec4f(141.0/255.0, 126.0/255.0, 189.0/255.0, 1.0),
628 osg::Vec4f(31.0/255.0, 0.0/255.0, 129.0/255.0, 1.0),
629 osg::Vec4f(96.0/255.0, 86.0/255.0, 129.0/255.0, 1.0),
630 osg::Vec4f(25.0/255.0, 0.0/255.0, 104.0/255.0, 1.0),
631 osg::Vec4f(78.0/255.0, 69.0/255.0, 104.0/255.0, 1.0),
632 osg::Vec4f(19.0/255.0, 0.0/255.0, 79.0/255.0, 1.0),
633 osg::Vec4f(59.0/255.0, 53.0/255.0, 79.0/255.0, 1.0),
634 osg::Vec4f(127.0/255.0, 0.0/255.0, 255.0/255.0, 1.0),
635 osg::Vec4f(212.0/255.0, 170.0/255.0, 255.0/255.0, 1.0),
636 osg::Vec4f(94.0/255.0, 0.0/255.0, 189.0/255.0, 1.0),
637 osg::Vec4f(157.0/255.0, 126.0/255.0, 189.0/255.0, 1.0),
638 osg::Vec4f(64.0/255.0, 0.0/255.0, 129.0/255.0, 1.0),
639 osg::Vec4f(107.0/255.0, 86.0/255.0, 129.0/255.0, 1.0),
640 osg::Vec4f(52.0/255.0, 0.0/255.0, 104.0/255.0, 1.0),
641 osg::Vec4f(86.0/255.0, 69.0/255.0, 104.0/255.0, 1.0),
642 osg::Vec4f(39.0/255.0, 0.0/255.0, 79.0/255.0, 1.0),
643 osg::Vec4f(66.0/255.0, 53.0/255.0, 79.0/255.0, 1.0),
644 osg::Vec4f(191.0/255.0, 0.0/255.0, 255.0/255.0, 1.0),
645 osg::Vec4f(234.0/255.0, 170.0/255.0, 255.0/255.0, 1.0),
646 osg::Vec4f(141.0/255.0, 0.0/255.0, 189.0/255.0, 1.0),
647 osg::Vec4f(173.0/255.0, 126.0/255.0, 189.0/255.0, 1.0),
648 osg::Vec4f(96.0/255.0, 0.0/255.0, 129.0/255.0, 1.0),
649 osg::Vec4f(118.0/255.0, 86.0/255.0, 129.0/255.0, 1.0),
650 osg::Vec4f(78.0/255.0, 0.0/255.0, 104.0/255.0, 1.0),
651 osg::Vec4f(95.0/255.0, 69.0/255.0, 104.0/255.0, 1.0),
652 osg::Vec4f(59.0/255.0, 0.0/255.0, 79.0/255.0, 1.0),
653 osg::Vec4f(73.0/255.0, 53.0/255.0, 79.0/255.0, 1.0),
654 osg::Vec4f(255.0/255.0, 0.0/255.0, 255.0/255.0, 1.0),
655 osg::Vec4f(255.0/255.0, 170.0/255.0, 255.0/255.0, 1.0),
656 osg::Vec4f(189.0/255.0, 0.0/255.0, 189.0/255.0, 1.0),
657 osg::Vec4f(189.0/255.0, 126.0/255.0, 189.0/255.0, 1.0),
658 osg::Vec4f(129.0/255.0, 0.0/255.0, 129.0/255.0, 1.0),
659 osg::Vec4f(129.0/255.0, 86.0/255.0, 129.0/255.0, 1.0),
660 osg::Vec4f(104.0/255.0, 0.0/255.0, 104.0/255.0, 1.0),
661 osg::Vec4f(104.0/255.0, 69.0/255.0, 104.0/255.0, 1.0),
662 osg::Vec4f(79.0/255.0, 0.0/255.0, 79.0/255.0, 1.0),
663 osg::Vec4f(79.0/255.0, 53.0/255.0, 79.0/255.0, 1.0),
664 osg::Vec4f(255.0/255.0, 0.0/255.0, 191.0/255.0, 1.0),
665 osg::Vec4f(255.0/255.0, 170.0/255.0, 234.0/255.0, 1.0),
666 osg::Vec4f(189.0/255.0, 0.0/255.0, 141.0/255.0, 1.0),
667 osg::Vec4f(189.0/255.0, 126.0/255.0, 173.0/255.0, 1.0),
668 osg::Vec4f(129.0/255.0, 0.0/255.0, 96.0/255.0, 1.0),
669 osg::Vec4f(129.0/255.0, 86.0/255.0, 118.0/255.0, 1.0),
670 osg::Vec4f(104.0/255.0, 0.0/255.0, 78.0/255.0, 1.0),
671 osg::Vec4f(104.0/255.0, 69.0/255.0, 95.0/255.0, 1.0),
672 osg::Vec4f(79.0/255.0, 0.0/255.0, 59.0/255.0, 1.0),
673 osg::Vec4f(79.0/255.0, 53.0/255.0, 73.0/255.0, 1.0),
674 osg::Vec4f(255.0/255.0, 0.0/255.0, 127.0/255.0, 1.0),
675 osg::Vec4f(255.0/255.0, 170.0/255.0, 212.0/255.0, 1.0),
676 osg::Vec4f(189.0/255.0, 0.0/255.0, 94.0/255.0, 1.0),
677 osg::Vec4f(189.0/255.0, 126.0/255.0, 157.0/255.0, 1.0),
678 osg::Vec4f(129.0/255.0, 0.0/255.0, 64.0/255.0, 1.0),
679 osg::Vec4f(129.0/255.0, 86.0/255.0, 107.0/255.0, 1.0),
680 osg::Vec4f(104.0/255.0, 0.0/255.0, 52.0/255.0, 1.0),
681 osg::Vec4f(104.0/255.0, 69.0/255.0, 86.0/255.0, 1.0),
682 osg::Vec4f(79.0/255.0, 0.0/255.0, 39.0/255.0, 1.0),
683 osg::Vec4f(79.0/255.0, 53.0/255.0, 66.0/255.0, 1.0),
684 osg::Vec4f(255.0/255.0, 0.0/255.0, 63.0/255.0, 1.0),
685 osg::Vec4f(255.0/255.0, 170.0/255.0, 191.0/255.0, 1.0),
686 osg::Vec4f(189.0/255.0, 0.0/255.0, 46.0/255.0, 1.0),
687 osg::Vec4f(189.0/255.0, 126.0/255.0, 141.0/255.0, 1.0),
688 osg::Vec4f(129.0/255.0, 0.0/255.0, 31.0/255.0, 1.0),
689 osg::Vec4f(129.0/255.0, 86.0/255.0, 96.0/255.0, 1.0),
690 osg::Vec4f(104.0/255.0, 0.0/255.0, 25.0/255.0, 1.0),
691 osg::Vec4f(104.0/255.0, 69.0/255.0, 78.0/255.0, 1.0),
692 osg::Vec4f(79.0/255.0, 0.0/255.0, 19.0/255.0, 1.0),
693 osg::Vec4f(79.0/255.0, 53.0/255.0, 59.0/255.0, 1.0),
694 osg::Vec4f(51.0/255.0, 51.0/255.0, 51.0/255.0, 1.0),
695 osg::Vec4f(80.0/255.0, 80.0/255.0, 80.0/255.0, 1.0),
696 osg::Vec4f(105.0/255.0, 105.0/255.0, 105.0/255.0, 1.0),
697 osg::Vec4f(130.0/255.0, 130.0/255.0, 130.0/255.0, 1.0),
698 osg::Vec4f(190.0/255.0, 190.0/255.0, 190.0/255.0, 1.0),
699 osg::Vec4f(255.0/255.0, 255.0/255.0, 255.0/255.0, 1.0)};
700
701 osg::Vec4f col = colorArray[colorCode];
702 return col;
703}
704
705/*!
706 * \brief constructor for DXF3dFace
707 */
708DXF3dFace::DXF3dFace()
709 :
710 vec1(),
711 vec2(),
712 vec3(),
713 vec4(),
714 layer(""),
715 colorCode(0),
716 color()
717{
718}
719
720/*!
721 * \brief desctructor for DXF3dFace
722 */
723DXF3dFace::~DXF3dFace()
724{
725}
726
727/*!
728 * \brief DXF3dFace::dumpDXF3DFace
729 * dumps information aboput 3d face on stdout
730 */
731void DXF3dFace::dumpDXF3DFace()
732{
733 std::cout << "3-DFACE (" << vec1[0] <<", " << vec1[1]<<", "<< vec1[2]<<")"
734 <<"(" << vec2[0] <<", " << vec2[1]<<", "<< vec2[2]<<")"
735 << "("<< vec3[0] << ", "<< vec3[1]<<", "<< vec3[2] << ")"
736 <<"(" << vec4[0] << ", "<< vec4[1]<<", "<< vec4[2]<< ")" <<std::endl;
737
738}
739
740
741/*!
742 * \brief DXF3dFace::fill3dFace
743 * fills a 3d face object with information from the textstream
744 * \param QTextStream* stream
745 */
746QString DXF3dFace::fill3dFace(QTextStream* stream)
747{
748 QString line = "";
749 int done = 0;
750 int lineCode = 0;
751 while (!done)
752 {
753 line = stream->readLine();
754 if (!line.compare("3DFACE"))
755 {
756 done = 1;
757 }
758 lineCode = line.toInt();
759
760 switch (lineCode)
761 {
762 case (8) :
763 //layer name
764 layer = stream->readLine().toInt();
765 break;
766 case (62) :
767 //color number
768 colorCode = stream->readLine().toInt();
769 color = getAutoCADRGB(colorCode);
770 break;
771 case (10) :
772 //first corner x
773 vec1[0] = stream->readLine().toDouble();
774 break;
775 case (20) :
776 //first corner y
777 vec1[1] = stream->readLine().toDouble();
778 break;
779 case (30) :
780 //first corner z
781 vec1[2] = stream->readLine().toDouble();
782 break;
783 case (11) :
784 //second corner x
785 vec2[0] = stream->readLine().toDouble();
786 break;
787 case (21) :
788 //second corner y
789 vec2[1] = stream->readLine().toDouble();
790 break;
791 case (31) :
792 //second corner z
793 vec2[2] = stream->readLine().toDouble();
794 break;
795 case (12) :
796 //third corner x
797 vec3[0] = stream->readLine().toDouble();
798 break;
799 case (22) :
800 //third corner y
801 vec3[1] = stream->readLine().toDouble();
802 break;
803 case (32) :
804 //third corner z
805 vec3[2] = stream->readLine().toDouble();
806 break;
807 case (13) :
808 //fourth corner x
809 vec4[0] = stream->readLine().toDouble();
810 break;
811 case (23) :
812 //fourth corner y
813 vec4[1] = stream->readLine().toDouble();
814 break;
815 case (33) :
816 //fourth corner z
817 vec4[2] = stream->readLine().toDouble();
818 break;
819 case (70) :
820 //invisible edge flag
821 stream->readLine().toInt();
822 break;
823 default:
824 done = 1;
825 break;
826 }
827 }
828 return line;
829}
830
831/*!
832 * \brief DXF3dFace::calcNormals
833 * calculates normal vector for the facet
834 */
835osg::Vec3f DXF3dFace::calcNormals()
836{
837 osg::Vec3f v1 = osg::Vec3f(vec1[0]- vec2[0], vec1[1] - vec2[1], vec1[2] - vec2[2]);
838 osg::Vec3f v2 = osg::Vec3f(vec1[0] - vec3[0], vec1[1] - vec3[1], vec1[2] - vec3[2]);
839 osg::Vec3f normal = normalize(cross(normalize(v1), normalize(v2)));
840 return normal;
841}
842
843/*!
844 * \brief DXFile constructor
845 * \param std::string filename
846 */
847DXFile::DXFile(std::string filename)
848 : osg::Geometry()
849{
850 // parse dxf file and fill 3dface objects
851 fileName = filename;
852 QFile* dxfFile = new QFile(QString::fromStdString(filename));
853 if (dxfFile->open(QIODevice::ReadOnly))
854 {
855 QTextStream* in = new QTextStream(dxfFile);
856 //count all 3d faces
857 int num3dFaces = in->readAll().count(QString("3DFACE"));
858
859 //reset textstream
860 in->seek(0);
861
862 // prepare drawing objects
863 osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(num3dFaces * 4);
864 osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(num3dFaces * 4);
865 osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array(num3dFaces * 4);
866
867 // fill face objects
868 DXF3dFace* faces = new DXF3dFace[num3dFaces];
869 QString line = in->readLine();
870 int faceIdx = 0;
871
872 int done = 0;
873 while (!done)
874 {
875 if (!line.compare("SECTION")) {
876 //int secID = in->readLine().toInt();
877 //std::cout << "enter section" << secID << std::endl;
878 line = in->readLine();
879 }
880 else if (!line.compare("ENTITIES")) {
881 //int entityID = in->readLine().toInt();
882 //std::cout << "enter entity" << entityID << std::endl;
883 line = in->readLine();
884 }
885 else if (!line.compare("3DFACE")) {
886 //std::cout << "fill face entity" << std::endl;
887
888 //add vertices
889 line = faces[faceIdx].fill3dFace(in);
890 (*vertices)[(faceIdx*4) + 0] = faces[faceIdx].vec1;
891 (*vertices)[(faceIdx * 4) + 1] = faces[faceIdx].vec2;
892 (*vertices)[(faceIdx * 4) + 2] = faces[faceIdx].vec3;
893 (*vertices)[(faceIdx * 4) + 3] = faces[faceIdx].vec4;
894 //add colors
895 (*colors)[(faceIdx * 4) + 0] = faces[faceIdx].color;
896 (*colors)[(faceIdx * 4) + 1] = faces[faceIdx].color;
897 (*colors)[(faceIdx * 4) + 2] = faces[faceIdx].color;
898 (*colors)[(faceIdx * 4) + 3] = faces[faceIdx].color;
899 //add normals
900 (*normals)[(faceIdx * 4) + 0] = faces[faceIdx].calcNormals();
901 (*normals)[(faceIdx * 4) + 1] = faces[faceIdx].calcNormals();
902 (*normals)[(faceIdx * 4) + 2] = faces[faceIdx].calcNormals();
903 (*normals)[(faceIdx * 4) + 3] = faces[faceIdx].calcNormals();
904
905 faceIdx = faceIdx + 1;
906 }
907 else if (!line.compare("ENDSEC")) {
908 //std::cout << "close section" << std::endl;
909 line = in->readLine();
910 }
911 else if (!line.compare("EOF")) {
912 done = 1;
913 }
914 else {
915 line = in->readLine();
916 }
917 }
918 dxfFile->close();
919
920 //add planes
921 this->setVertexArray(vertices);
922 for (int i = 0; i < num3dFaces; i++)
923 {
924 if (faces[i].vec1 == faces[i].vec4) {
925 //std::cout << "its a triangle" << std::endl;
926 //faces[i].dumpDXF3DFace();
927 osg::ref_ptr<osg::DrawElementsUInt> facette = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 3);
928 (*facette)[0] = (i * 4) + 0;
929 (*facette)[1] = (i * 4) + 1;
930 (*facette)[2] = (i * 4) + 2;
931 this->addPrimitiveSet(facette);
932 }
933 else
934 {
935 //std::cout << "its a quad" << std::endl;
936 osg::ref_ptr<osg::DrawElementsUInt> facette = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 4);
937 (*facette)[0] = (i * 4) + 0;
938 (*facette)[1] = (i * 4) + 1;
939 (*facette)[2] = (i * 4) + 2;
940 (*facette)[3] = (i * 4) + 3;
941 this->addPrimitiveSet(facette);
942 }
943 }
944 //add normals
945 this->setNormalArray(normals);
946 this->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
947 //add colors
948 this->setColorArray(colors);
949 this->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
950 }
951}
952