SmallChange  1.0.0
A collection of extensions to Coin3D
Loading...
Searching...
No Matches
SmHQSphere.h
1#ifndef COIN_SMHQSPHERE_H
2#define COIN_SMHQSPHERE_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/nodes/SoSubNode.h>
37#include <Inventor/nodes/SoShape.h>
38#include <Inventor/fields/SoSFFloat.h>
39#include <Inventor/fields/SoSFInt32.h>
40#include <Inventor/SbLinear.h>
41#include <SmallChange/basic.h>
42
43class SmHQSphereP;
44class SbBSPTree;
45
47 typedef SoShape inherited;
48
49 SO_NODE_HEADER(SmHQSphere);
50
51public:
52 static void initClass(void);
53 SmHQSphere(void);
54
55 SoSFFloat radius;
56 SoSFInt32 level;
57
58 virtual void GLRender(SoGLRenderAction * action);
59 virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action);
60 virtual void rayPick(SoRayPickAction * action);
61
62protected:
63 virtual ~SmHQSphere();
64 virtual void generatePrimitives(SoAction * action);
65 virtual void computeBBox(SoAction * action, SbBox3f & box, SbVec3f & center);
66
67private:
68 SmHQSphereP * pimpl;
69};
70
72public:
73 HQSphereGenerator(void) {
74 this->orgobject = NULL;
75 this->init();
76 }
77 ~HQSphereGenerator(void) {
78 delete this->orgobject;
79 }
80
81 class triangle {
82 public:
83 triangle(void) { }
84 triangle(const SbVec3f & p0, const SbVec3f & p1, const SbVec3f & p2) {
85 pt[0] = p0;
86 pt[1] = p1;
87 pt[2] = p2;
88 }
89 public:
90 SbVec3f pt[3];
91 };
92
93 class object {
94 public:
95 object(int npoly, const triangle * poly) {
96 this->npoly = npoly;
97 this->poly = new triangle[npoly];
98 if (poly) {
99 memcpy(this->poly, poly, npoly*sizeof(triangle));
100 }
101 }
102 ~object() {
103 delete[] this->poly;
104 }
105 public:
106 int npoly; /* # of triangles in object */
107 triangle * poly; /* Triangles */
108 };
109
110 void generate(const int level, SbBSPTree & bsp, SbList <int> & idx);
111
112 SbVec3f normalize(const SbVec3f & p);
113 SbVec3f midpoint(const SbVec3f & a, const SbVec3f & b);
114
115private:
116 void convert(object * obj, SbBSPTree & bsp, SbList <int> & idx);
117 void init(void);
118 object * orgobject;
119};
120
121#endif // COIN_SMHQSPHERE_H
Definition SmHQSphere.h:93
Definition SmHQSphere.h:81
Definition SmHQSphere.h:71
Definition misc/SbList.h:69
Definition SmHQSphere.h:46
SoSFInt32 level
Definition SmHQSphere.h:56